//Last updated Timestamp:  04/18/2008

 //materswitch controls whether entire survey should run or not
 var masterswitch = false;
 //surveyswitch controls whether the pages survey should run or not
 var surveyswitch = "";
 var frequency = "";
 var rnd = "";
 var pageid = "";
 var surveyurl = "";
 var pagetitle = "";
 var leftvalue = 0;
 var topvalue = 0;
 var leftpx = "";
 var toppx = "";
 
 function surveycontroller(){
 
 //Based on the master switch - whether it is on or off which can be set here.
 if (masterswitch)
	{
		//Get the page title of page you're on.
 		//Through webAnalyticsPageTitle  variable 
		pagetitle = unescape(webAnalyticsPageTitle);	
				
		var surveydata = new Array();
		
		//Format of the array table is:
 		//switch to tell if this survey is on or not - random frequency - the page name - the URL of the survey
		
		//Booking confirmation - booking path
		surveydata[surveydata.length] = new Array(true,"20","United US-  Confirmation Page","http://www.surveymonkey.com/s.aspx?sm=60Db4G2rIEFbA51jse9MEQ_3d_3d");
		//Award
		//surveydata[surveydata.length] = new Array(true,"20","United US- Award  Award Purchase Confirmation");
		//My itineraries
		surveydata[surveydata.length] = new Array(true,"20","United US-  My Itineraries","http://www.surveymonkey.com/s.aspx?sm=FV7q_2b8P9JK8LaVPo3Q6nQg_3d_3d");
		//My mileage summary
		surveydata[surveydata.length] = new Array(true,"20","United US-  Mileage Plus Summary","http://www.surveymonkey.com/s.aspx?sm=ocWvwG5WqWi10juyZjBWGQ_3d_3d");
		
		//Planning and Booking landing page
		surveydata[surveydata.length] = new Array(true,"20","Planning booking landing","http://www.surveymonkey.com/s.aspx?sm=siYRkhLC9z_2bECZP8qDTg3w_3d_3d");
		//I&C landing page
		surveydata[surveydata.length] = new Array(true,"20","Itineraries checkin landing","http://www.surveymonkey.com/s.aspx?sm=siYRkhLC9z_2bECZP8qDTg3w_3d_3d");
		//MP landing page
		surveydata[surveydata.length] = new Array(true,"20","MP landing","http://www.surveymonkey.com/s.aspx?sm=siYRkhLC9z_2bECZP8qDTg3w_3d_3d");
		//S&I landing page
		surveydata[surveydata.length] = new Array(true,"20","Service info landing","http://www.surveymonkey.com/s.aspx?sm=siYRkhLC9z_2bECZP8qDTg3w_3d_3d");
		
		
		for(j=0;j<surveydata.length;j++)
		{
			if ((surveydata[j][2] == pagetitle )  && (surveydata[j][0] ))
				{ 
					//Uncomment following two lines for production. Controls how often survey pops up.
					frequency = surveydata[j][1];
					rnd = Math.floor(Math.random() * frequency) + 1;
					//frequency = 1;
					//rnd = 1;
					if (frequency == rnd) {
						surveyurl = surveydata[j][3];
						popupinvite();
					}
						
					return;
				}
		}
		
	} 
   
 }
 
function popitup(showhide){
    if(showhide == "show"){
        document.getElementById('popupbox').style.display="block"; /* If the function is called with the variable 'show', show the popup invite box */
		document.getElementById('hideformelements').style.display="block";
    }else 
	if(showhide == "hide"){
        document.getElementById('popupbox').style.display="none"; /* If the function is called with the variable 'hide', hide the popup invite box */
		document.getElementById('hideformelements').style.display="none"; /* If the function is called with the variable 'hide', hide the hide form elements box */
    }
 } 
 
function launchsurvey(surveyurl){
	// hides the survey invite and opens survey page
	popitup('hide');
	window.open(surveyurl, '','location=0,status=0,scrollbars=1,menubar=1,width=850,height=650,top=10,left=10,resizable=0'); 

}
 
function popupinvite(){ 

	var surveydiv = '<table border=0 width=100% id="tablepopup">' +
					'<tr><td colspan=2 style="padding-left:10px;"><img src="/ual/asset/unitedsurvey.gif" border=0></td>   <td align=right style="padding-right:10px;"><a href="javascript:popitup(\'hide\');"><img src="/ual/asset/closesurvey.gif" border=0></a> </td></tr>'  +
					'<tr><td colspan=3 style="padding-left:10px;"><img src="/ual/asset/surveyinvite.gif"></td></tr>'  +
					'<tr><td colspan=3 class=surveytext>United wants to continue to improve the online service we provide you. Do you have <br>a few minutes to respond to a survey about your experience on united.com?</td></tr>' +
					'<tr><td colspan=3>&nbsp</td></tr>' +   
					'<tr><td style="padding-left:45px;"><a href="javascript:popitup(\'hide\');"><img src="/ual/asset/nothankyou.gif" border=0></a> </td><td></td><td style="padding-right:35px;"><A HREF="javascript:launchsurvey( surveyurl ) "><IMG SRC="/ual/asset/takethesurvey.gif" border=0></a></td></tr>' +
					'<tr><td colspan=3>&nbsp</td></tr>' +
					'</table>';				

	//Determine centering for survey popup 
	//490 is the width of the survey popup
	//185 is the height of the survey popup
	leftvalue = (((screen.width)/2) - (485/2)); 
	leftpx =  leftvalue + "px"; 
	topvalue = (((screen.height)/2) - (185/2)); 
	toppx =  topvalue + "px"; 
	
	//Set popupbox top and left
	document.getElementById("popupbox").style.left = leftpx; 
	document.getElementById("popupbox").style.top = "190px";
	
	//Set hideformelements top and left same as popupbox 
	document.getElementById("hideformelements").style.left = leftpx; 
	document.getElementById("hideformelements").style.top = "200px";
	
	document.getElementById('popupbox').innerHTML = surveydiv;
	// 3 second delay popping up iframe to hide ie form elements, and the survey invite.
	window.setTimeout('document.getElementById("hideformelements").style.display="block";', 2000);
	window.setTimeout('document.getElementById("popupbox").style.display="block";', 2000);
	
}

