


var hParent = null;

function setParent ( hPops )
{
hParent = hPops;
}

function getCookieValue(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}




function goToSurvey ()
{
   serveInvitation();
   //window.close ();
}

function serveInvitation()  {
		
		 var country_percent = 55;
		 //var country_percent = 100;
         var random_number = Math.random()*100;
		 //random_number=0;
		 
		 
		    // Set cookie for where the person came from
            setCookie("Survey4Location", location.pathname);
            var sPageVisited;
            sPageVisited = "";
            sPageVisited = getCookieValueString("sPageVisited2");
			//alert ("sPageVisited "+ sPageVisited );
			//alert("Random: "+random_number );
			//alert(window.location.href.search("surveytest2.html") >0);
           if ((sPageVisited==null && random_number < country_percent && random_number > country_percent-6) )	//&& random_number > country_percent-6 
				{  
				   setCookie("sPageVisited2", "true");	
				   //alert("Visited first time");
				   strURL1=location.href;
				   strURL = "http://www.amdsurveys.com/se.ashx?s=5A1E27D21293647B&refurl=" + strURL1;
				   //alert(strURL); 
				   newWin = window.open ( strURL, "", "toolbar=no,toolbar=0,location=no,location=0,status=no,status=0,menubar=no,menubar=0,scrollbars=yes,scrollbars=1,resizable=yes,resizable=1,height=600,width=800" );
window.focus();

				}
			//else
			
			//	{
					//alert("Already filled survey");
					//strURL = "http://www.amd.com";
					

			//	}
	 
//        var countryURL = getCookieValue("Survey2Location");
//		alert("countryURL:"+countryURL);
//         if (countryURL.search("surveytest2.html") > 0) 
//         {
//           strURL = "http://www.amdsurveys.com/se.ashx?s=5A1E27D211A7AD10";
//         }
//         else 
//         {
//           strURL = "http://www.amd.com";
//         }

}

function showSurvey ()
{
   window.close ();
}

function excludedpages() 
{
  if ((window.opener.location.href.search("wwwsecure") < 0)) 
  {
    var countryURL = getCookieValue("Survey4Location");
	alert(countryURL);
    if ((countryURL.search("us-en")) || (countryURL.search("us%2Den")))
    {
      return;
    }
  }

  window.close();

}



function errortrap(msg,url,line)
{
	alert("error"+msg+url+line);
  setTimeout ( "goToSurvey();", 1000, "JavaScript" );
  return true;
}

onerror=errortrap;