var confirmWin ;
var mywindow;
window.onbeforeunload =function(){ HandleOnClose();}
window.onload=function(){ PopUpAndInactive();}
function PopUpAndInactive()
{
	/*if(confirmWin!=null)
	{
		alert("Null");*/
		confirmWin = window.open("/StaTravel/WinClose.aspx","STATravel","width=375px,height=375px");
		confirmWin.moveTo(0,0);
		window.focus();
	/*}
	else
	{
		alert("Not Null");
	}*/
}
function HandleOnClose() 
{ 
	if (event.clientY < 0) 
	{
		PopUp();
		
	}
}
function PopUp()
{
	try
	{
		/*
		mywindow = window.showModalDialog("/StaTravel/WinClose.aspx","STATravel","dialogWidth:360px;dialogHeight:340px;scroll:no");
		mywindow.moveTo(0,0);
		if (confirmWin!=null)
		{*/
			confirmWin = window.open("/StaTravel/WinClose.aspx","STATravel","width=375px,height=375px");
			confirmWin.moveTo(0,0);
			confirmWin.focus();
		/*
		}
		else
		{
			confirmWin = window.open("/StaTravel/WinClose.aspx","STATravel","width=320px,height=280px");
			confirmWin.moveTo(0,0);
			confirmWin.focus();
		}*/
	}
	catch(ex)
	{
	}
}
document.onkeydown = checkKeyCode;
// global variables used by checkKeyCode and checkForBrowserClose functions
var oldKeyCode;
var closingKey;
// what key was pressed?
function checkKeyCode(key) 
{
	var keyCode;
	if (window.event) 
	{
		keyCode = window.event.keyCode;
	}
	else if (key) 
	{
		keyCode = key.which;
	}
	// If the user pressed the Alt key(18) and then F4(115), they are trying to close the browser
	if((keyCode == 115) && (oldKeyCode == 18))
	{
		closingKey = true;
		PopUp();
	}
	oldKeyCode = keyCode;
}

			//**********http to https and vise versa code starts here****************
			
			//Get the target Protocol changed URL.
			var strProtocol=GetProtocol(location.pathname);
			var loc = strProtocol + "//"+ location.hostname + location.pathname + location.search ;
			
			//used to change the protocol, if any changes in the protocol redirection, else do nothing.
			if(strProtocol.toUpperCase() != location.protocol.toUpperCase())
			{
				//alert("Now chaging to https");
				location.href = loc ;
				location.replace(loc);
			}			
			
			//HTTPS Page list. When ever the new HTTPS page added or removed, that has to be updated here.
			function IsHttpsPage(path)
			{
				var HttpsPages = new Array()

				HttpsPages[0] = "/Statravel/ShoppingCart/OrderExtendedDetails.aspx";
				HttpsPages[1] = "/Statravel/ShoppingCart/OrderCustomerDetails.aspx";
				HttpsPages[2] = "/Statravel/ShoppingCart/OrderConfirmation.aspx";
				HttpsPages[3] = "/Statravel/ShoppingCart/OrderCreationResult.aspx";
				HttpsPages[4] = "/Statravel/shoppingcart/CreditCardInfo.aspx";

				
				//Loop through the list of the pages in the above list.
				for (x in HttpsPages)
				{
					if (HttpsPages[x].toUpperCase()==path.toUpperCase())
					{
						return(true);
					}
				}
				return(false);
			}
			
			//used to find out the page Protocol type and returns that.
			function GetProtocol(PagePath)
			{
				if (IsHttpsPage(PagePath))
					return "HTTPS:";
				else
					return "HTTP:";
			}
			//***************Http to Https and viseversa code end****************