/*
Author: Anjeeta Manish Bhatti
Creation Date: 13th Feb, 2009
Purpose: Create persistent cookie for marking the survey being viewed for once only. 
Implemented for home, products, company, careers, investors, b2b section landing pages.
*/

// This function sets the cookie for a defined name value pair for specific no. of days.
function createSurveyCookie(c_name,value,expiredays)
	{
		survey = "true";
		//alert("Inside createSurveyCookie");
		var exdate = new Date();
		exdate.setDate(parseInt(exdate.getDate())+parseInt(expiredays));
		var expValue = ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
		document.cookie = c_name+ "=" +escape(value)+ expValue + "; path=/";
	}

// This function reads the cookie value for the name attribute provided.
	function readSurveyCookie(c_name)
	{
		//alert("Inside readSurveyCookie");
		if (document.cookie.length>0)
		{
			c_start=document.cookie.indexOf(c_name + "=");
			if (c_start!=-1)
			{ 
				c_start=c_start + c_name.length+1; 
				c_end=document.cookie.indexOf(";",c_start);
				if (c_end==-1) 
					c_end=document.cookie.length;
				
				//alert ("Cookie Retrieved >>"+ unescape(document.cookie.substring(c_start,c_end)));
				return unescape(document.cookie.substring(c_start,c_end));
			} 
		  }
		  else
			  return "";
	}

// This function checks whether the cookie for the survey being viewed has been exists or not.
	function checkSurveyCookie()
	{
		
		survey = readSurveyCookie("ipsos_survey_09");
		//alert("Inside checkSurveyCookie \n Cookie Value >>" + survey);
		if ((survey!=null && survey!="") || (survey == "true"))
		{
			// do nothing	
		}
		else 
		{
			// set the cookie if the survey is being viewed for the first time.
			//survey = "true";
			//createSurveyCookie("ipsos_survey_09", survey, "30");
			survey_popup_window("/common/survey_popup/survey_popup.shtml","500","300"); //open survey popup
		}
	}
// This function deletes the cookie by setting the expiry 1 sec prior to the current time. (Currently not in use)
/*	function deleteSurveyCookie(c_name)
	{
	  var c_date = new Date ();  // current date & time
	  c_date.setTime ( c_date.getTime() - 1 );
	  document.cookie = c_name += "=; expires=" + c_date.toGMTString();
	}*/

// This function opens a new window that contains link to the third party survey being implemented.
function survey_popup_window(url,width,height) {
	window.open(url,'newwin','menubar=no,scrollbars=yes,status=no,width='+width+',height='+height+',resizable=no,left=0,top=0');
	return;

}

checkSurveyCookie();
