// The Central Randomizer 1.3 (C) 1997 by Paul Houle (paul@honeylocust.com)
// See:  http://www.honeylocust.com/javascript/randomizer.html
rnd.today=new Date();
rnd.seed=rnd.today.getTime();
function rnd() {
	rnd.seed = (rnd.seed*9301+49297) % 233280;
	return rnd.seed/(233280.0);
};
function rand(number) {
	return Math.ceil(rnd()*number);
};
// end central randomizer. -->


function centerWindow(url, name, w, h, scroll, menu, resizable)
{
	if (window.screen)
	{
		var chasm = screen.availWidth;
		var mount = screen.availHeight;
		
		winprops = 'width=' + w + ',height=' + h + ',left=' + ((chasm - w - 10) * .5) + ',top=' + ((mount - h - 30) * .5) + 
			',scrollbars=' + scroll + ',menubar=' + menu + ',resizable=' + resizable;
		
		oHTMLWin = window.open(url, name, winprops);
		oHTMLWin.window.focus();
	}
}

function selectOptionLink(oProdLineSelect)
{
	newLocation = oProdLineSelect.options[oProdLineSelect.selectedIndex].value;
	if ( newLocation.indexOf("http")==0 ) {
		selRetailer = newLocation; 
		newUrl = '/popup/leavingsite.jsp?retailerURL=' + selRetailer;
		callRetailerWindow(newUrl);
	}
	else
		window.location = newLocation;
}
function compareSubmit(oProdLineCHK)
{
	argv = document.forms["formCompareProduct"];
	checkedvalues="";
	noofchecks=0;
	for(i=0;i < argv.length;i++ ){
		if(document.formCompareProduct.elements[i].checked){
			noofchecks=noofchecks+1;
			if(noofchecks>5){
				alert('You can select only five products to compare');
				return false;
			}
			if(checkedvalues.length >0){
				checkedvalues=checkedvalues+","+"'"+document.formCompareProduct.elements[i].value+"'";
			}else{
				checkedvalues="'"+document.formCompareProduct.elements[i].value+"'";
			}
			//alert("checkedvalues  "+checkedvalues);
		}
	}
	//newLocation = "/products/results.jsp?productcodes="+checkedvalues;
	document.formCompareProduct.checkedvalues.value=checkedvalues;
	submitForm("formCompareProduct");
	
}
function updateMessage(){
	document.URL="/iris/askiristhanks.jsp";
}

function changeCssClass (someid, clsname)
{
	obj = document.getElementById(someid);
	if (obj)
	{
		obj.className = clsname;
	}
}

function clearIt(formName)
{
	eval("document."+formName).srch_query.value = "";
}

function submitForm(formName) 
{
	eval("document."+formName).submit();
}

function callRetailerWindow(page)
{
	//centerWindow(url, "popupWndName", width, height, scroll, menu, resizeable);
	//var url="/popup/onlineretailer.jsp";
	centerWindow(page, "onlineretailer", 470, 400, "no", "no", "no");
}

function setDivDisplay(divid, disp)
{
	d = document.getElementById(divid);
	if (d && d.style)
	{
		d.style.display = disp;
	}
}

function submitPidList(formName, inputPageNum)
{
	inPidList = 'pidlist' + inputPageNum;
	objInPidList = document.getElementById(inPidList);

	objPageNum = document.getElementById("pagenum");
	objPidList = document.getElementById("pidlist");

	if (objPageNum && objPidList)
	{
		objPidList.value = objInPidList.value ;
		objPageNum.value = inputPageNum ;
	}

	eval("document."+formName).submit();
}

function chInputValue(formName,inputName,inputValue)
{
	obj = document.getElementById(inputName);
	if (obj)
	{
		obj.value = inputValue;
	}
	eval("document."+formName).submit();
}


//Call this to build the date list for the specified month
function rebuildDays(oForm,sDateName) {
	monthselect = oForm[sDateName + "mm"];
	dayselect = oForm[sDateName + "dd"];
	yearselect = oForm[sDateName + "yyyy"];
	
	month = monthselect.options[monthselect.selectedIndex].value;
	dayindex = dayselect.selectedIndex;
	year = yearselect.options[yearselect.selectedIndex].value;
	
	if (year == "") year = 0;

	if (month > 0) {
		if (month==4 || month==6 || month==9 || month==11) {
			daysinmonth = 30;
		} else if (month==2) {
			if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) {
				daysinmonth = 29;
			} else {
				daysinmonth = 28;
			}
		} else {
			daysinmonth = 31;
		}
		
		//Set the length of the select list
		dayselect.length = daysinmonth + 1;
		dayselect.options[0] = new Option("Day",0);
		for(i=1; i <= daysinmonth; i++) {
			strDayValue = i<10 ? "0"+i : ""+i;
			dayselect.options[i] = new Option(i,strDayValue);
		}
		
		//Select the picked date
		if (dayindex <= daysinmonth) {
			dayselect.selectedIndex = dayindex;
		} else {
			dayselect.selectedIndex = 0;
		}
	}
}



/*********************************************************************************************
	Show and Hide Divs
*********************************************************************************************/
function showDiv(divid)
{
   document.getElementById(divid).style.display="";
}

function hideDiv(divid)
{
	document.getElementById(divid).style.display="none";
}

var calloutImg= new Array(2);
var topCallout = "";
var secNavCallout = "";
for(i=1;i<=2;i++) {
	calloutImg[i]=rand(10);
	if (i>1){
		while (calloutImg[1]==calloutImg[i]) {
			calloutImg[i]=rand(10);
		}
	}
	topCallout = "Callout-Bars-top_image-"+calloutImg[1];
	secNavCallout = "Secondary-Nav-Images-"+calloutImg[2];
}

function writeCookie (cookieName, cookieValue, expiry)
{
   var expDate = new Date();
   if(expiry) {	 
     expDate.setTime(eval(expDate.getTime() + expiry));
     document.cookie = cookieName + "=" + escape (cookieValue) + "; expires=" + expDate.toGMTString();
    }
    else {
		document.cookie = cookieName + "=" + escape (cookieValue);
   }
}

function readCookie (CookieName) {
  var returnValue = "";
  var CookieString = document.cookie;
  var CookieSet = CookieString.split (';');
  var SetSize = CookieSet.length;
  var CookiePieces
  var x = 0;
  for (x = 0; ((x < SetSize) && (returnValue == "")); x++)
  {
    CookiePieces = CookieSet[x].split ('=');
    if (CookiePieces[0].substring (0,1) == ' ') {
      CookiePieces[0] = CookiePieces[0].substring (1, CookiePieces[0].length);
      returnValue="";
    }
    if (CookiePieces[0] == CookieName) {
      returnValue = CookiePieces[1];
    }
  }
  return(returnValue);
}

function popExercise(imgName) {
		newUrl = 'popexercise.jsp?imgName=' + imgName;
		centerWindow(newUrl, "exercise", 350, 350, "no", "no", "no");
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//=======================================================
     //detect browser settings for showing and hiding DIVs
     isNS4 = (document.layers) ? true : false;
     isIE4 = (document.all && !document.getElementById) ? true : false;
     isIE5 = (document.all && document.getElementById) ? true : false;
     isNS6 = (!document.all && document.getElementById) ? true : false;
//=======================================================

function switchDiv(strDivName,bolVisible){
 //identify the element based on browser type
 if (isNS4) {
   objElement = document.layers[strDivName];
 } else if (isIE4) {
   objElement = document.all[strDivName].style;
 } else if (isIE5 || isNS6) {
   objElement = document.getElementById(strDivName).style;
 }
 
 if(isNS4){
     if(!bolVisible) {
       objElement.visibility ="hidden"
     } else {
       objElement.visibility ="visible"
     }     
 }else if(isIE4){
     if(!bolVisible) {
       objElement.visibility = "hidden";
     } else {
       objElement.visibility = "visible";
     }
 } else if (isIE5 || isNS6) {
      if(!bolVisible){
         objElement.display = "none";
      } else {
        objElement.display = "";
        }
      }
}

// ==========================================================
function displayAdd() {
	if(document.contactform.strChk3.checked) {
		document.getElementById('additional').style.display='';
	}
	else {
		document.getElementById('additional').style.display='none';
	}
}
