// 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();
var jsdivtop = '';
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 = "block";
        }
      }
	  
}

// ==========================================================
function displayAdd() {
	if(document.contactform.strChk3.checked) {
		document.getElementById('additional').style.display='';
	}
	else {
		document.getElementById('additional').style.display='none';
	}
}

var oHTMLWinPic;
var oHTMLWinMov;
function centerTvPicWindow()
{
		if(oHTMLWinMov){ oHTMLWinMov.close(); }
        var name     = 'tvprintads';
		var w            = 615;
		var h             = 801;
		var scroll      = 'yes';
		var menu      = 'no';
		var resizable = 'no';
		var chasm = screen.availWidth;
		var mount = screen.availHeight;
		var winprops = 'width=' + w + ',height=' + h + ',left=' + ((chasm - w - 10) * .5) + ',top=' + ((mount - h - 30) * .5) + 
			',scrollbars=' + scroll + ',menubar=' + menu + ',resizable=' + resizable+',margin=0';
		
		oHTMLWinPic = window.open('../tv_and_print_ads_img.html', name, winprops);
		oHTMLWinPic.window.focus();
}

function centerTvMovWindow()
{
		if(oHTMLWinPic){ oHTMLWinPic.close(); }
        var name     = 'tvprintads1';
		var w            = 372;
		var h             = 330;
		var scroll      = 'yes';
		var menu      = 'no';
		var resizable = 'no';
		var chasm = screen.availWidth;
		var mount = screen.availHeight;
		var winprops = 'width=' + w + ',height=' + h + ',left=' + ((chasm - w - 10) * .5) + ',top=' + ((mount - h - 30) * .5) + 
			',scrollbars=' + scroll + ',menubar=' + menu + ',resizable=' + resizable+',margin=0';
		
		oHTMLWinMov = window.open('../tv_and_print_ads_mov.html', name, winprops);
		oHTMLWinMov.window.focus();
}

function goWithFlow(fName)
{
		if(oHTMLWinPic){ oHTMLWinPic.close(); }
        var name     = 'tvprintads1';
		var w            = 305;
		var h             = 269;
		var scroll      = 'yes';
		var menu      = 'no';
		var resizable = 'no';
		var chasm = screen.availWidth;
		var mount = screen.availHeight;
		var winprops = 'width=' + w + ',height=' + h + ',left=' + ((chasm - w - 10) * .5) + ',top=' + ((mount - h - 30) * .5) + 
			',scrollbars=' + scroll + ',menubar=' + menu + ',resizable=' + resizable+',margin=0';
		if(fName=="video_1.swf")
		{
			popUpPageName = "../go_with_the_flow_mov1.html";
		}
		if(fName=="video_2.swf")
		{
			popUpPageName = "../go_with_the_flow_mov2.html";
		}
		if(fName=="video_3.swf")
		{
			popUpPageName = "../go_with_the_flow_mov3.html";
		}
		if(fName=="video_4.swf")
		{
			popUpPageName = "../go_with_the_flow_mov4.html";
		}
		

		oHTMLWinMov = window.open(popUpPageName, name, winprops);
		oHTMLWinMov.window.focus();
}


function SetJSDiv(){
  var top = document.getElementById('leftcallouts').offsetTop + 5;
  var mydiv = document.getElementById('jsdiv_show');
  mydiv.setAttribute("style","position: absolute; top:"+top+"px;left: 5px");
  mydiv.style.cssText = "position: absolute; top:"+top+"px;left: 5px";
  document.getElementById('jsdiv_show').style.display = "block"; 
  DisplayJsDiv();  
}

function SetJSDiv_Something_To_Add(){
  var winX = (document.all)?window.screenLeft:window.screenX;
  var winY = document.documentElement.scrollTop; 
  var top = winY - 150;
  var mydiv = document.getElementById('jsdiv_show');
  mydiv.setAttribute("style","position: absolute; top:"+top+"px;left: 5px");
  mydiv.style.cssText = "position: absolute; top:"+top+"px;left: 5px";
  document.getElementById('jsdiv_show').style.display = "block"; 
  DisplayJsDiv();  
}

function SetNoJSDiv(){
  //document.getElementById('jsdiv').innerHTML = "";
  document.getElementById('jsdiv_show').style.display = "none";   
  DisplayJsDiv();    
}

function SetQuestion() {
	
	  rem_blank_lines(document.getElementById('question'));	
	  if(document.getElementById('form_ready').value == "1")
	  {
		  document.getElementById('form_ready').value="0"; // not ready .. to handle multiple simultaneous requests 
	  
		  http_request = false;
		  if (window.XMLHttpRequest) { // Mozilla, Safari,...
			 http_request = new XMLHttpRequest();
			 if (http_request.overrideMimeType) {
				// set type accordingly to anticipated content type
				//http_request.overrideMimeType('text/xml');
				http_request.overrideMimeType('text/html');
			 }
		  } else if (window.ActiveXObject) { // IE
			 try {
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
			 } catch (e) {
				try {
				   http_request = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			 }
		  }
		  if (!http_request) {
			 //alert('Cannot create XMLHTTP instance');
			 return false;
		  }
		  http_request.onreadystatechange = alertContentsQ;
		  http_request.open('POST', '/check_question.php', true);
		  http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');  
		  http_request.send('name=' + escape(document.getElementById('name').value) + '&email=' + (document.getElementById('email').value) + '&question=' + urlencode(document.getElementById('question').value) + '&qcat=' + escape(document.getElementById('lstQcat').value) + '&share=' + escape(document.getElementById('share').checked) + '&language=' + escape(document.getElementById('hdnLanguage').value) + '&country=' + escape(document.getElementById('hdnCountry').value) + '&opt1=' + escape(document.getElementById('opt1').checked) + '&age=' + escape(document.getElementById('lstAge').value) + '&opt2=' + escape(document.getElementById('opt2').checked) );	
	  }
   }
   
   function alertContentsQ() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText.split("|");
            if(result[0]){ document.getElementById('jsdiv').innerHTML   = result[0]; }else
			{
				if(result[1]){ document.getElementById('err_msg_name').style.display ="block"; document.getElementById('err_msg_name').innerHTML = result[1]; } 			else { document.getElementById('err_msg_name').innerHTML = ''; document.getElementById('err_msg_name').style.display ="none";} 
				if(result[2]){ document.getElementById('err_msg_email').style.display ="block"; document.getElementById('err_msg_email').innerHTML = result[2]; } 		else { document.getElementById('err_msg_email').innerHTML = '';  document.getElementById('err_msg_email').style.display ="none"; }
				if(result[3]){ document.getElementById('err_msg_qcat').style.display ="block"; document.getElementById('err_msg_qcat').innerHTML = result[3]; } 			else {  document.getElementById('err_msg_qcat').innerHTML = ''; document.getElementById('err_msg_qcat').style.display ="none"; }
				if(result[4]){ document.getElementById('err_msg_question').style.display ="block"; document.getElementById('err_msg_question').innerHTML = result[4]; } 	else { document.getElementById('err_msg_question').innerHTML = ''; document.getElementById('err_msg_question').style.display ="none";  }
				if(result[5]){ document.getElementById('err_msg_age').style.display ="block"; document.getElementById('err_msg_age').innerHTML = result[5]; } else { document.getElementById('err_msg_age').style.display ="none"; document.getElementById('err_msg_age').innerHTML = ''; }
				if(document.getElementById('form_ready')) { document.getElementById('form_ready').value="1";	 } // ready now  			
			}
         } else {
            //alert('There was a problem with the request.');
         }
      }
   }

   
function ShowMessage(id_message){
	if(document.getElementById('message_content_'+id_message).style.display == "block"){
		document.getElementById('message_content_'+id_message).style.display = "none";
	}
	else{
		document.getElementById('message_content_'+id_message).style.display = "block";
	}
}


function DisplayJsDiv() {
	  http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         //alert('Cannot create XMLHTTP instance');
         return false;
      }
	  http_request.onreadystatechange = alertDisplayJsDiv;
      http_request.open('GET', '/set_jsdiv.php', true);
      http_request.send(null);
   }
   
   function alertDisplayJsDiv() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
			document.getElementById('jsdiv').innerHTML   = result;
			fn_Show_Qcat('0');
         } else {
            //alert('There was a problem with the request.');
         }
      }
   }
	function  fn_Reset_Talk_To_Us()
	{
		document.getElementById('err_msg_name').innerHTML = ''; document.getElementById('err_msg_name').style.display ="none";
		document.getElementById('err_msg_email').innerHTML = '';document.getElementById('err_msg_email').style.display ="none";
		document.getElementById('err_msg_qcat').innerHTML = '';document.getElementById('err_msg_qcat').style.display ="none";
		document.getElementById('err_msg_question').innerHTML = '';document.getElementById('err_msg_question').style.display ="none";
		document.getElementById('err_msg_age').innerHTML = '';document.getElementById('err_msg_age').style.display ="none";
		fn_Show_Qcat('0');
		document.getElementById('share_tips').reset();
		
	}
	
	function urlencode( str ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: travc
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Lars Fischer
    // %          note 1: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // *     example 1: urlencode('Kevin van Zonneveld!');
    // *     returns 1: 'Kevin+van+Zonneveld%21'
    // *     example 2: urlencode('http://kevin.vanzonneveld.net/');
    // *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
    // *     example 3: urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
    // *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'
                             
    var histogram = {}, unicodeStr='', hexEscStr='';
    var ret = (str+'').toString();
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The histogram is identical to the one in urldecode.
    histogram["'"]   = '%27';
    histogram['(']   = '%28';
    histogram[')']   = '%29';
    histogram['*']   = '%2A';
    histogram['~']   = '%7E';
    histogram['!']   = '%21';
    histogram['%20'] = '+';
    histogram['\u00DC'] = '%DC';
    histogram['\u00FC'] = '%FC';
    histogram['\u00C4'] = '%D4';
    histogram['\u00E4'] = '%E4';
    histogram['\u00D6'] = '%D6';
    histogram['\u00F6'] = '%F6';
    histogram['\u00DF'] = '%DF';
    histogram['\u20AC'] = '%80';
    histogram['\u0081'] = '%81';
    histogram['\u201A'] = '%82';
    histogram['\u0192'] = '%83';
    histogram['\u201E'] = '%84';
    histogram['\u2026'] = '%85';
    histogram['\u2020'] = '%86';
    histogram['\u2021'] = '%87';
    histogram['\u02C6'] = '%88';
    histogram['\u2030'] = '%89';
    histogram['\u0160'] = '%8A';
    histogram['\u2039'] = '%8B';
    histogram['\u0152'] = '%8C';
    histogram['\u008D'] = '%8D';
    histogram['\u017D'] = '%8E';
    histogram['\u008F'] = '%8F';
    histogram['\u0090'] = '%90';
    histogram['\u2018'] = '%91';
    histogram['\u2019'] = '%92';
    histogram['\u201C'] = '%93';
    histogram['\u201D'] = '%94';
    histogram['\u2022'] = '%95';
    histogram['\u2013'] = '%96';
    histogram['\u2014'] = '%97';
    histogram['\u02DC'] = '%98';
    histogram['\u2122'] = '%99';
    histogram['\u0161'] = '%9A';
    histogram['\u203A'] = '%9B';
    histogram['\u0153'] = '%9C';
    histogram['\u009D'] = '%9D';
    histogram['\u017E'] = '%9E';
    histogram['\u0178'] = '%9F';
    
    // Begin with encodeURIComponent, which most resembles PHP's encoding functions
    ret = encodeURIComponent(ret);
 
    for (unicodeStr in histogram) {
        hexEscStr = histogram[unicodeStr];
        ret = replacer(unicodeStr, hexEscStr, ret); // Custom replace. No regexing
    }
    
    // Uppercase for full PHP compatibility
    return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
        return "%"+m2.toUpperCase();
    });
}




function rem_blank_lines(txtfld){
var text;
text = txtfld.value;
text = text.replace(/\r/g,'');
text = text.split('\n');
count1 = text.length;
text = text.clean('');
text = text.clean(' ');
count2 = text.length;
text = text.join('\n');
txtfld.value = text;
count3 = count1 - count2;
}


Array.prototype.clean = function(remove_item){
var a;
for (a = 0; a < this.length; a++){
if (this[a] == remove_item){
this.splice(a,1);a--;}
}return this;}


