// DW Javascripts
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// printPage
function printpage() {
	if (window.print) {
		window.print();
	} else {
		alert('To print this page, select Print from the file menu.');
	}
}

// Collapsable "toggle" block
function toggle(e)
{
if (e.style.display == "none")
  {e.style.display = "";}
else
  {e.style.display = "none";}
}

// Print this page
function printWindow(){
   bV = parseInt(navigator.appVersion)
   if (bV >= 4) window.print()
}

// Centered popup window
function popupper(theURL, Name, popW, popH, scroll) {
      var winleft = (screen.width - popW) / 2;
      var winUp = (screen.height - popH) / 2;
      winProp = 'width='+popW+',height='+popH+',left='+winleft+',top='+winUp+',scrollbars='+scroll //+',resizable'
      Win = window.open(theURL, Name, winProp)
      if (parseInt(navigator.appVersion) >= 4) { Win.window.focus(); }        
}

//Highlight link backgrounds
function highlight(obj) {
var oA=document.getElementsByTagName('a');
for(var i=0; i<oA.length; i++) {
	oA[i].style.backgroundColor='transparent';
	}
if(typeof(obj)=='string') {
	for(var i=0; i<oA.length; i++) {
    	if(obj==oA[i].firstChild.data) {
        	obj=oA[i];
            break;
            }
    	}
    }
obj.style.backgroundColor='#ccf';
}

function loadparentpage() {     
  parent.location.href='/program_profile.jsf';
}
				
function numbersonly(myfield, e, dec)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) ||
    (key==9) || (key==13) || (key==27) )
   return true;
// numbers
else if ((("0123456789").indexOf(keychar) > -1))
   return true;
else
   return false;
}
function lettersonly(e)
{
var key;
var keychar;
if (window.event)
	key = window.event.keyCode;
else if (e)
	key = e.which;
else
	return true;
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();
// control keys
if ((key==null) || (key==0) || (key==8) || 
(key==9) || (key==13) || (key==27) )
	return true;
// alphas and some special characters only
else if ((("abcdefghijklmnopqrstuvwxyz.,' ").indexOf(keychar) > -1))
	return true;
else
	return false;
}
function alphanumericonly(e)
{
var key;
var keychar;
if (window.event)
	key = window.event.keyCode;
else if (e)
	key = e.which;
else
	return true;
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();
// control keys
if ((key==null) || (key==0) || (key==8) || 
(key==9) || (key==13) || (key==27) )
	return true;
// alphas and some special characters only
else if ((("abcdefghijklmnopqrstuvwxyz.,'1234567890 ").indexOf(keychar) > -1))
	return true;
else
	return false;
}
function hideshow(which){
	if (!document.getElementById)
	return
	if (which.style.display=="none")
	which.style.display=""
	else
	which.style.display="none"
	}
	function hide(which){
	if (!document.getElementById)
	return
	if (which.style.display=="")
	which.style.display="none"
}
// Collapsable content
//<![CDATA[
	function expand(element){if(document.getElementById('t'+element).style.display!='block'){
		document.getElementById('t'+element).style.display='block';
		document.getElementById('imgExpand'+element).src='/www.riteaid.com/w-content/images/myriteaid/generic/expander_expanded.png';}
			else{document.getElementById('t'+element).style.display='none';
		document.getElementById('imgExpand'+element).src='/www.riteaid.com/w-content/images/myriteaid/generic/expander_collapsed.png';}}
//]]>
function expandDirectionMap(element){
		if(document.getElementById('t'+element).style.display!='block') {
			document.getElementById('t'+element).style.display='block';
			document.getElementById('form1:lnkExpand'+element).src='/www.riteaid.com/w-content/images/stores/locator/btn_HideMap.png';
			}
		else{
			document.getElementById('t'+element).style.display='none';
			document.getElementById('form1:lnkExpand'+element).src='/www.riteaid.com/w-content/images/stores/locator/btn_ShowMap_center.png';
			}
}
function ChgImg(sId, imgSrc) {
	if(document.getElementById) {
		GEid = document.getElementById(sId);
		GEid.src=imgSrc;
	}
}
function check(thisObj, thisEvent) {
		if(window.parent.frames[0]){
			window.parent.document.forms[0].submit();
		}
}

/*
 * Clear Default Text: functions for clearing and replacing default text in
 * <input> elements.
 */
 
 function addEvent(element, eventType, lamdaFunction, useCapture) {
    if (element.addEventListener) {
        element.addEventListener(eventType, lamdaFunction, useCapture);
        return true;
    } else if (element.attachEvent) {
        var r = element.attachEvent('on' + eventType, lamdaFunction);
        return r;
    } else {
        return false;
    }
}

addEvent(window, 'load', init, false);

function init() {
    var formInputs = document.getElementsByTagName('input');
    for (var i = 0; i < formInputs.length; i++) {
        var theInput = formInputs[i];
        
        if (theInput.type == 'text' && theInput.className.match(/\bcleardefault\b/)) {  
            /* Add event handlers */          
            addEvent(theInput, 'focus', clearDefaultText, false);
            addEvent(theInput, 'blur', replaceDefaultText, false);
            
            /* Save the current value */
            if (theInput.value != '') {
                theInput.defaultText = theInput.value;
            }
        }
    }
}

function clearDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == target.defaultText) {
        target.value = '';
    }
}

function replaceDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == '' && target.defaultText) {
        target.value = target.defaultText;
    }
}
/*
 * End Clear Default Text: functions for clearing and replacing default text in
 * <input> elements.
 */
 
/*
 * Methods to setup and redirect pages using our redir servlet.
 
 * Usage:
 * <a href="javascript:return false;" onclick="window.open(redirect('http://www.riteaiddiabetes.com')); 
 * return false;" target="_blank"> etc...
 */
function redirect(url) {
   var encodedTo = url;
   var encodedFrom = location.href;		
   var newUrl = "/redir/?go=" + encodedTo + "&from=" + encodedFrom;
   return newUrl;
}

/*

 //Encodes data to Base64 format
function base64Encode(data){
	if (typeof(btoa) == 'function') return btoa(data);//use internal base64 functions if available (gecko only)
	var b64_map = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
	var byte1, byte2, byte3;
	var ch1, ch2, ch3, ch4;
	var result = new Array();
	var j=0;
	for (var i=0; i<data.length; i+=3) {
		byte1 = data.charCodeAt(i);
		byte2 = data.charCodeAt(i+1);
		byte3 = data.charCodeAt(i+2);
		ch1 = byte1 >> 2;
		ch2 = ((byte1 & 3) << 4) | (byte2 >> 4);
		ch3 = ((byte2 & 15) << 2) | (byte3 >> 6);
		ch4 = byte3 & 63;
		
		if (isNaN(byte2)) {
			ch3 = ch4 = 64;
		} else if (isNaN(byte3)) {
			ch4 = 64;
		}

		result[j++] = b64_map.charAt(ch1)+b64_map.charAt(ch2)+b64_map.charAt(ch3)+b64_map.charAt(ch4);
	}

	return result.join('');
}

*/

/*

//Decodes Base64 formated data
function base64Decode(data){
	data = data.replace(/[^a-z0-9\+\/=]/ig, '');// strip none base64 characters
	if (typeof(atob) == 'function') return atob(data);//use internal base64 functions if available (gecko only)
	var b64_map = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
	var byte1, byte2, byte3;
	var ch1, ch2, ch3, ch4;
	var result = new Array();
	var j=0;
	while ((data.length%4) != 0) {
		data += '=';
	}
	
	for (var i=0; i<data.length; i+=4) {
		ch1 = b64_map.indexOf(data.charAt(i));
		ch2 = b64_map.indexOf(data.charAt(i+1));
		ch3 = b64_map.indexOf(data.charAt(i+2));
		ch4 = b64_map.indexOf(data.charAt(i+3));

		byte1 = (ch1 << 2) | (ch2 >> 4);
		byte2 = ((ch2 & 15) << 4) | (ch3 >> 2);
		byte3 = ((ch3 & 3) << 6) | ch4;

		result[j++] = String.fromCharCode(byte1);
		if (ch3 != 64) result[j++] = String.fromCharCode(byte2);
		if (ch4 != 64) result[j++] = String.fromCharCode(byte3);	
	}

	return result.join('');
}

*/
/*
 * End of Methods to setup and redirect pages using our redir servlet.
 */
function MM_openBrWindow(theURL,winName,features) {
	window.open(theURL,winName,features);
} 
/*
 * used for flash captcha
 */
function EvalSound(soundobj) {
  var thissound= eval("document."+soundobj);
  thissound.Play();
  //soundobj.controls.play();
}