var BVisLoaded = false;
function BVcheckLoadState() {
    	if(!BVisLoaded) {
    	var page = document.getElementById('BVFrame').src;
		document.getElementById('BVFrame').src='http://reviews.cascadeclean.com/logging?page=' + escape(page);
    	document.getElementById('BVReviewsContainer').innerHTML = '<!-- Review retrieval timed out -->';
       }
    }

function ReadCookie (CookieName) {
  var CookieString = document.cookie;
  var CookieSet = CookieString.split (';');
  var SetSize = CookieSet.length;
  var CookiePieces
  var ReturnValue = "";
  var x = 0;

  for (x = 0; ((x < SetSize) && (ReturnValue == "")); x++) {
    CookiePieces = CookieSet[x].split ('=');
//          alert("cookie pieces :: " + CookiePieces);
    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 WriteCookie (cookieName, cookieValue, expiry)
{
            var cookieExpireDate = new Date();
            var timeSinceEpoch = cookieExpireDate.getTime();
            if(!isNaN(expiry)){
                        expiry = parseInt(expiry);
            }
            if(expiry) {
                        expiry += timeSinceEpoch;
            }else{
                        expiry = timeSinceEpoch;
            }
            cookieExpireDate.setTime(expiry);
            document.cookie = cookieName + "=" + escape (cookieValue) + "; expires=" + cookieExpireDate.toGMTString() + "; path=/";
		//	alert("setting cookie... done");
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function randomPopup(){ 

var id = ReadCookie("cproductid");

//alert("2   "+id);
var cookievalue=ReadCookie("cascadepollsubmit")
var cookievalue1=ReadCookie("cascadereadreview")
var bar = cookievalue.split("A");
var sdone = ReadCookie("surveyDone");
var cookie = false;

for(i = 0; i < bar.length; i++)
{
	if(id==bar[i]) 	cookie=true;
}

var bar1 = cookievalue1.split("A");
var cookie1 = false;

	for(i = 0; i < bar1.length; i++)
	{
		if(id==bar1[i])
			cookie1=true;
	}

if(cookie1===true)
	{
		if(cookie == false)
		{//alert("popup");
		   if(sdone!="yes"){
			
			//Uncomment the below two lines to enable BV poll/survey.
			//initPopUp();
			//showPopWin("/en_US/poll.do?productid="+id, 400 ,408, null);

			WriteCookie("surveyDone","yes",315360000000);
			setcookie(id);
		   }
		}
	}
}

//Function to display a div in the Popup poll.
function showq2() {   		
		if (document.pollform.question1[0].checked) {			
			document.getElementById("1").style.cssText="display:block";
			document.getElementById("2").style.cssText="display:none";						
		} else if (document.pollform.question1[1].checked) {
			document.getElementById("1").style.cssText="display:none";
			document.getElementById("2").style.cssText="display:block";	
		}
}
	
//Function to set a cookie that not to repeat the popup again for 'productid' passing into it.
function setcookie(productid) { //alert("setting cookie...");
		var cookievalue=ReadCookie("cascadepollsubmit") + productid + "A";//alert("setting cookie...1");
		WriteCookie("cascadepollsubmit",cookievalue,315360000000);	//alert("setting cookie...2");
}
	
//Function to submit poll.
function pollsubmit() {
		document.pollform.submit();
}
