function setCookieForSurvey(name, value, expires) {
	document.cookie = name + '=' + escape(value) + '; path=/'
		+ ((expires == null) ? '' : '; expires='
		+ expires.toGMTString());
}
function getSurveyCookie(c_name){
	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
		    return unescape(document.cookie.substring(c_start,c_end));
   		 }
  	}
	return ""
}
function hasCookie(name){
	surveyname=getSurveyCookie(name);
	if (surveyname!=null && surveyname!="")	  {
	 	return 1;
	  }
}
function surveyPopup(id) {
		// set all the arguments to variables for better readability
	
	var cookieValue1 = 'surveyId' ;
	var cookieValue = cookieValue1 + "," + "US_en" + "," + document.title;
	var cookieName = 'AllyCanadaSurveyCookie';
	var redirectURL1 = "http://survey.confirmit.com/wix/p" +id+ ".aspx?ver=1";
	var URLParameters = '&locale=' + 'US_en'	+ '&wn=' + document.title;

	var redirectURL = redirectURL1 + URLParameters;
	var windowName = 'Ally Canada Survey';
	var expiryDate = new Date();
	var URLString1 = 'toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,';
	var URLString2 = 'copyhistory=no,scrollbars=yes,height=300,width=700';
	var URLString = URLString1 + URLString2;
	var cookieValue = getSurveyCookie(cookieName);
	if(cookieValue.indexOf(id) == -1) {
		if (Math.random() < 0.2) {
			expiryDate.setTime(expiryDate.getTime() + (180 * 24 * 60 * 60* 1000));
			setCookieForSurvey(cookieName, id, expiryDate);

			if(navigator.appName == "Microsoft Internet Explorer") {
				// IE browser expects a different second argument
				// and hence the browser check
					window.open(redirectURL, '', windowName, URLString);
			} else {
				window.open(redirectURL, windowName, URLString);
			}
		}
	return 'Created new Cookie';
	}
	else {
	return 'Survey already taken';
	}
	
}



