//preload images
imgList= [
	"/images/bilo.jpg",
	"/images/messagetomom/bi-lo_bg_pin_w597.gif" 
];
imgs= new Array();
for( c= 0; c < imgList.length; c++ ) {
	imgs[c]= new Image();
	imgs[c].src= imgList[c];
}//## TODO: CREATE METHODS/FUNCTIONS TO PRELOAD IMAGES IN SPECIFIC PAGES



/* padleft ; padright = pads a string with a another string ; left & right methods
 *	Arguments:
 *		val	=	the string to concatenate to
 *		ch	=	string that will be concatenated
 *		num	=	amount of characters that the string must have
 */
function padleft(val, ch, num) {
	var re = new RegExp(".{" + num + "}$");
	var pad = "";

	do  {
		pad += ch;
	}while(pad.length < num)

	return re.exec(pad + val);
}
function padright(val, ch, num){
	var re = new RegExp("^.{" + num + "}");
	var pad = "";

	do {
		pad += ch;
	} while (pad.length < num)

	return re.exec(val + pad);
}


/*
 *  COOKIE FUNCTIONS THANKS TO: http://www.quirksmode.org/js/cookies.html
 * Create Cookie
 */
/*
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
*/
/*
 * Read from Cookie
 */
/*
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
*/
/*
 * Erase Cookie
 */
/*
function eraseCookie(name) {
	createCookie(name,"",-1);
}
*/


//set the height attribute in a tag by its corrissponding id attribute
function doVerticalResize( elemId, newHeight ) {
	if( newHeight <= -1 ) return;
	var elem= document.getElementById(elemId);
	elem.height= newHeight;
}


function divIsVisible( divId ) {
	if( document.getElementById(divId).style.display == 'none' )
		return false; 
	else return true;
}


function divSetVisible( divId, visible ) {
	if( visible )
		document.getElementById(divId).style.display = 'inline';		
	else
		document.getElementById(divId).style.display = 'none';
	
}


//toggle the display attribute in a DIV tag from 'none' to 'inline' or from 'inline' to 'none'
function toggleHide( elemId ) {
	if( !divIsVisible(elemId) ) {
		document.getElementById(elemId).style.display = 'inline';
		return false;
	} else {
		document.getElementById(elemId).style.display = 'none';
		return true;
	}
}


/*
 *	TOGGLES TEXT BOLD OR NORMAL
 */
function toggleBold( elemId ) {
	if( document.getElementById(elemId).style.fontWeight == '' ) {
		document.getElementById(elemId).style.fontWeight = 'bold';
	} else {
		document.getElementById(elemId).style.fontWeight = '';
	}
}


/*
 *	SHOWS 1 EVENT IN EVENT AREA ON CLICK
 */
function toggleBetweenEvents( NewlySelectedEventId, CurDisplayEventId ) {
	//Get the currently display event ID from the hidden input tag
	var cur= document.getElementById( CurDisplayEventId ).value;
	
	//if there is an event Id present check to see if the 2 events 
	//are the same else hide it the old
	if( cur && cur != "" && cur != "NoValue" ) {
//		alert("CurDisplayEventId has a value.");//## DEBUG
		if( NewlySelectedEventId == cur ) {
//			alert("Same event selected!");//## DEBUG
			return;//same event
		}
		else {
//			alert("New event selected.");//## DEBUG
			try {
				document.getElementById( cur ).style.display = 'none';//new event selected hide current
			}
			catch( e ) {
				//do nothing
			}
		}
	}
//	else {
//		alert("CurDisplayEventId DOES NOT a value!");//## DEBUG
//	}
	
	//set the new selected event ID in the hidden tag
	document.getElementById( CurDisplayEventId ).value = NewlySelectedEventId;
	//show the new event 
	document.getElementById( NewlySelectedEventId ).style.display = 'inline';
}


/*
 *	WORKS LIKE toggleBetweenEvents TO TOGGLE LINK CLICKED BOLD AND TO UNBOLD PREVIOUS
 */
function toggleBoldBetweenItems( NewlySelectedItemId, CurItemId ) {
	//Get the currently SELECTED ITEM ID from the hidden input tag
	var cur= document.getElementById( CurItemId ).value;
	
	//if there is an ITEM Id present check to see if the 2 ITEMS 
	//are the same, else hide it
	if( cur && cur != "" && cur != "NoValue" ) {
//		alert("CurDisplayEventId has a value.");//## DEBUG
		if( NewlySelectedItemId == cur ) {
//			alert("Same event selected!");//## DEBUG
			return;//same event
		}
		else {
//			alert("New event selected.");//## DEBUG
			try {
				document.getElementById( cur ).style.fontWeight = '';//new ITEM selected UNBOLD current
			}
			catch( e ) {
				//do nothing
			}
		}
	}
//	else {
//		alert("CurDisplayEventId DOES NOT a value!");//## DEBUG
//	}
	
	//set the new BOLDED ITEM ID in the hidden tag
	document.getElementById( CurItemId ).value = NewlySelectedItemId;
	//BOLD the new ITEM 
	document.getElementById( NewlySelectedItemId ).style.fontWeight = 'bold';
}


/*
 *
 */
function toggleProductRecallData( divId, imgId /*, spanId */) {
	if( divIsVisible(divId) ) {
		//HIDE
		img = new Image();
		img.src = "/images/show_wText_sm.gif";
		document.getElementById(imgId).src = img.src;
//		document.getElementById(spanId).value = "show";
		divSetVisible(divId, false);
	}
	else {
		//SHOW
		img = new Image();
		img.src = "/images/hide_wText_sm.gif";
		document.getElementById(imgId).src = img.src;
//		document.getElementById(spanId).value = "hide";
		divSetVisible(divId, true);
	}
}


// OPEN NEW WINDOW
function open_win( url, target, attr ) {
	window.open(url,target,attr);
}

/*
 *	OUTPUT CURRENT DAY AND TIME - EX: Monday 2:21 P.M.
 */
function getCurrentDayAndTime() {
	//create date object
	var d   = new Date();
	//get current hr
	var hrs = d.getHours();
	var min = padleft(d.getMinutes()+"",'0',2);//pad 0 to minutes if needed ; USES padleft FUNCTION AT TOP
	
	//get am/pm value
	if (hrs >= 12) amPm = "P.M.";
	else amPm = "A.M.";
	
	//get 12hr day hrs value
	if (hrs > 12) hrs -= 12;
	if (hrs == 0) hrs = 12;
	
	//get the named/text form of the day
	var day;
	switch(d.getDay()) {
		case 0:
			day="Sunday";
			break;
		case 1:
			day="Monday";
			break;					
		case 2:
			day="Tuesday";
			break;
		case 3:
			day="Wednesday";
			break;
		case 4:
			day="Thursday";
			break;
		case 5:
			day="Friday";
			break;
		case 6:
			day="Saturday";
			break;
	}
	
	//create current day and time string for output
	var str = day + " " + hrs + ":" + min + " " + amPm;
	//output to document the current day and time
	document.write(str);
}



//Get a URL parameter by its name
function getURLParam(strParamName) {
	var strReturn = "";
	var strHref = window.location.href;
	//alert(strHref);
	if ( strHref.indexOf("&") > -1 ) {
		var strQueryString = strHref.substr(strHref.indexOf("&")).toLowerCase();
		var aQueryString = strQueryString.split("&");
		for ( var iParam = 0; iParam < aQueryString.length; iParam++ ) {
			if ( aQueryString[iParam].indexOf(strParamName + "=") > -1 ) {
				var aParam = aQueryString[iParam].split("=");
				alert(aParam);
				strReturn = aParam[1];
				break;
			}
		}
	}
	
	//alert(strReturn);
	
	return strReturn;
}



//Input the IDs of the IFRAMES you wish to dynamically resize to match its content height:
//Separate each ID with a comma. Examples: ["myframe1", "myframe2"] or ["myframe"] or [] for none:
var iframeids=["myframe"]


var iframehide="yes"

var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers

function resizeCaller() {
var dyniframe=new Array()
for (i=0; i<iframeids.length; i++){
if (document.getElementById)
resizeIframe(iframeids[i])
//reveal iframe for lower end browsers? (see var above):
if ((document.all || document.getElementById) && iframehide=="no"){
var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
tempobj.style.display="block"
}
}
}

function resizeIframe(frameid){
var currentfr=document.getElementById(frameid)
if (currentfr && !window.opera){
currentfr.style.display="block"
if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight;
else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
currentfr.height = currentfr.Document.body.scrollHeight;
if (currentfr.addEventListener)
currentfr.addEventListener("load", readjustIframe, false)
else if (currentfr.attachEvent){
currentfr.detachEvent("onload", readjustIframe) 
currentfr.attachEvent("onload", readjustIframe)
}
}
}

function readjustIframe(loadevt) {
var crossevt=(window.event)? event : loadevt
var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
if (iframeroot)
resizeIframe(iframeroot.id);
}

function loadintoIframe(iframeid, url){
if (document.getElementById)
document.getElementById(iframeid).src=url
}

if (window.addEventListener)
window.addEventListener("load", resizeCaller, false)
else if (window.attachEvent)
window.attachEvent("onload", resizeCaller)
else
window.onload=resizeCaller



