﻿//------------------------------------------------------------------------------
// Javascript functions used globally within the web app.
		function PopupCalendar(calendarImage)
	{
		if (calendarImage.style.overflow == "hidden") 
		{
			calendarImage.style.overflow = "visible";
		}
		else
		{
			calendarImage.style.overflow = "hidden";
		}
	}
//----------------------------------------------------------------------	
	function ShowCreditCardInfo()
	{
		var show = "visible";
		var showWesternUnion = "hidden";
		var lblCreditCardInfo = document.getElementById("ctlPayerInfo_lblCreditCardInformation");
		var rbCreditCard = document.getElementById("ctlPayerInfo_rbCreditCard");
		var divCreditCardInfo = document.getElementById("ctlPayerInfo_divCreditCardInfo");
		var divWesternUnion = document.getElementById("ctlPayerInfo_divWesternUnion");
		
		if (rbCreditCard.checked)
		{
			show = "visible";
			showWesternUnion = "hidden";
			divCreditCardInfo.style.display = "block";
			divWesternUnion.style.display = "none";
		}
		else
		{
			showWesternUnion = "visible";
			show = "hidden";
			divCreditCardInfo.style.display = "none";
			divWesternUnion.style.display = "block";
		}
		
		lblCreditCardInfo.style.visibility = show;
		divCreditCardInfo.style.overflow = show;
		divWesternUnion.style.overflow = showWesternUnion;
	}
	
//----------------------------------------------------------------------------------------		
	function DateCheck()
	{
		var isValid = true;
		var departureDay = document.getElementById("ctlAvailCriteria_cboDepDay");
		var departureMonth = document.getElementById("ctlAvailCriteria_cboDepMon");
		var returnDay = document.getElementById("ctlAvailCriteria_cboRetDay");
		var returnMonth = document.getElementById("ctlAvailCriteria_cboRetMon");
		var departureYear = now.getYear();
		var returnYear = now.getYear();
		
		if(departureMonth.Month < now.getMonth())
		{
			departureYear += 1;
		}
		
		if(returnMonth.Month < now.getMonth())
		{
			returnYear += 1;
		}
		
		var departureDate = departureDay + '/' + departureMonth + '/' + departureYear;
		var returnDate = returnDay + '/' + returnMonth + '/' + returnYear;
		
		if (Date.parse(departureDate))
		{
			alert("No dice.");
			isValid = false;
		}
		
		if (Date.parse(returnDate))
		{
			alert("No dice.");
			isValid = false;
		}
		
		return isValid;
	}
//-------------------------------------------------------------------------------------------	
	function AdultInfantCheck()
	{
		if (document.getElementById("ctlAvailCriteria_cboInfants")){
			var isValid = true;
			var cboInfant = document.getElementById("ctlAvailCriteria_cboInfants");
			var cboAdult = document.getElementById("ctlAvailCriteria_cboAdults");

			if (parseInt(cboAdult.value) < parseInt(cboInfant.value))
			{
				alert("There must be at least one adult passenger for every infant.");
				isValid = false;
			}		
			return isValid;
		}
	}

//-----------------------------------------------------------------------------------

   //function to limit the characters and also send them to uppercase
	function k(i, objEvent)
	{
		var keyObjCode = (objEvent.which) ? objEvent.which:objEvent.keyCode;
		var key = String.fromCharCode(keyObjCode);
		var re = new Array(	/[a-zA-Z\s]/,  // Letters
							/[0-9\n\r\t\b\d]/,      // Numbers
							/[\-\/a-zA-Z0-9\n\r\t\s\b\d]/,  //Letters and Numbers
							/[0123456789A-Za-z\.\!\+\-\_\@\b\t\r\n\d]/);  //E-mail
		i = (i < 0 || i >= re.length)?0:i;
		if (!re[i].test(key))
			return false;
		else
		{
			key = key.toUpperCase();
			if(Browser.Engine.trident) 
                objEvent.keyCode = key.charCodeAt();
            //Firefox and other browsers do not allow to change the keycode or keyChar
            //the only way is to delete the whole event and create a new one and 
            //that is too much, so instead we do this for Ie and for others we
            //use the changeEvent and change it on exit. 
			return true;
		}	
	}
//-------------------------------------------------------------------------------------------	
	//function to change the passed textbox element to uppercase. this needs to go
	function c(o)
	{
		if (!document.all)
			o.value = o.value.toUpperCase();
	}
	
//------------------------------------------------------------------------	





// function for password field to not allow for extraneous characters
//can be used to block any combination of characters by just including it 
//in the array and then passing the value in the array of the wanted combination
function PasswordCharsCheck(i,objEvent)
{
	var keyCode = objEvent.keyCode ? objEvent.keyCode : objEvent.which;
		var key = String.fromCharCode(keyCode);
		var re = new Array(/[0123456789A-Za-z\.\!\+\-\_\@]/);
		i = (i < 0 || i >= re.length)?0:i;
		if (!re[i].test(key))
			return false;
		else
		{
			event.keyCode = key.charCodeAt();
			return true;
		}	
}
// -------------------------------------------------------------------------

	function unCheckINSUTermsAndConditions(o)
	{
		var p_element = document.getElementById("ctlInsurance_chkInsuranceTermsAndConditions");
		if (p_element != null) 
		{
			document.getElementById("ctlInsurance_chkInsuranceTermsAndConditions").checked=false;
		}
		/*var element = o.name;
		var the_length=element.length;
		var last_two_char=element.charAt(the_length-2) + element.charAt(the_length-1);
		document.getElementById("ctlPaxInfo_lblValidateBirth" + last_two_char).innerText = ""; */
	}	
//----------------------------------------------------------------------------------	
	function unCheckInsuranceTermsAndConditions()
	{
		document.getElementById("ctlInsurance_chkInsuranceTermsAndConditions").checked=false;
		
	}
//-------------------------------------------------------------------------------------------
function ShowHideElement(p_elemID,p_show)
  // function to show or hide any element. p_elemID = Id of element, p_show = True to show, false to hide
					{
						var elem;
						if (document.getElementById)
						{
							elem = document.getElementById(p_elemID)
						}
						else if (document.all){
							elem = document.all[p_elemID];
						}
					if (p_show == true)
					{
					    elem.style.display = "block";
					    elem.style.visibility = "visible";
					    
						}
						if (p_show == false)
						{
						    elem.style.visibility ="hidden"
							elem.style.display = "none";
						}
	 				}
//----------------------------------------------------------------------------------------	 				
	 				function changeClass(Elem, myClass) {
	 				// function will change the class of the element Elem = element id 
	 				//myClass = Class to change to
						var elem;
						if(document.getElementById) {
							var elem = document.getElementById(Elem);
						} else if (document.all){
							var elem = document.all[Elem];
						}
						elem.className = myClass;
					}
					
//----------------------------------------------------------------------------------------	 				
	function ShowModalPopup(UrlAndQString, WindowName, Width, Height) {
	    // function will open a new window with the given width and height displaying the given URL
		
		//showModalDialog is only supported by IE so we first check to see if we can use showModalDialog			
		if (typeof window.showModalDialog != 'undefined')
		{
		    window.showModalDialog(UrlAndQString, WindowName, 'dialogWidth:' + Width + ';dialogHeight:'+ Height +';menubar:no;scrollbars:no;resizable:no;status:no;');
		}
		else
		{
		    window.open(UrlAndQString, WindowName, 'Width=' + Width + ', Height='+ Height +', menubar=no, scrollbars=no, resizable=no, status=no, modal=yes');
		}
					
	}	
//-------------------------------------------------------------------------------------------
//Function to check for caplocks and give an alert if that is the case.  Used when entering a password to warn the user.
  function checkCapsLock( e ) {
	var myKeyCode=0;
	var myShiftKey=false;
	var myMsg='<%= ControlResourceManager.GetString("profileEdit-CapsLockOn")%>';

	// Internet Explorer 4+
	if ( document.all ) {
		myKeyCode=e.keyCode;
		myShiftKey=e.shiftKey;

	// Netscape 4
	} else if ( document.layers ) {
		myKeyCode=e.which;
		myShiftKey=( myKeyCode == 16 ) ? true : false;

	// Netscape 6
	} else if ( document.getElementById ) {
		myKeyCode=e.which;
		myShiftKey=( myKeyCode == 16 ) ? true : false;

	}

	// Upper case letters are seen without depressing the Shift key, therefore Caps Lock is on
	if ( ( myKeyCode >= 65 && myKeyCode <= 90 ) && !myShiftKey ) {
		alert( myMsg );

	// Lower case letters are seen while depressing the Shift key, therefore Caps Lock is on
	} else if ( ( myKeyCode >= 97 && myKeyCode <= 122 ) && myShiftKey ) {
		alert( myMsg );

	}
}	

//-------------------------------------------------------------------------------------------

function SecureLink(NameOfPage){
  var strBaseUrl = window.location.href;
  //strBaseUrl = strBaseUrl.replace("http:", "https:");
  strBaseUrl = strBaseUrl.substring(0, strBaseUrl.lastIndexOf("/")+1);
  strBaseUrl = strBaseUrl + NameOfPage;
  window.location.href = strBaseUrl;
}
//---------------------------------------------------------------------------------------------
function SecurePages(){
 // this function will change the page to secure if is listed in the array below and 
 // the page is not secured already.
 // You may add here any pages that we need to make sure they are secure.
 
 var arrSecurePages = ['Main.aspx',
					'login.aspx',
					'TAChangePassword.aspx',
					'Checkout.aspx',
					'AgencyCreate.aspx',
					'ModifyAgency.aspx',
					'NewAgent.aspx',
					'Register.aspx',
					'ProfileLogin.aspx',
					'ProfileChangePassword.aspx',
					'ProfileModify.aspx']
					
var strUrl = window.location.href

	for (var i=0;i < arrSecurePages.length;i++){
		if (strUrl.search(arrSecurePages[i]) != -1){
			if (window.location.protocol != "https:")
				window.location.protocol= "https:";
			break;
		}
	}
}
			

//-------------------------------------------------------------------------------------
//function to get the name of the current page eg. checkout.aspx
  	function getPage() {
		    var strUrl = new String();
		    strUrl = window.location.href;
		    strPage = strUrl.substring(strUrl.lastIndexOf("/") + 1, strUrl.lastIndexOf("?"));
		    return strPage;
		}
//-------------------------------------------------------------------------------------------
// function that will set the element passed to the cursor position - used for floating divs
 var cX = 0; var cY = 0; var rX = 0; var rY = 0;function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;}function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;}if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; }else { document.onmousemove = UpdateCursorPosition; }
    function AssignPosition(d) {if(self.pageYOffset) {	rX = self.pageXOffset;	rY = self.pageYOffset;	}else if(document.documentElement && document.documentElement.scrollTop) {	rX = document.documentElement.scrollLeft;	rY = document.documentElement.scrollTop;	}else if(document.body) {	rX = document.body.scrollLeft;	rY = document.body.scrollTop;	}if(document.all) {	cX += rX; 	cY += rY;	}d.style.left = (cX-100) + "px";d.style.top = (cY-100) + "px";}
//-------------------------------------------------------------------------------------------

// function that will move a passed optionvalue in the select to the requested position
// used to move the countries requested by client to the first positions
  function moveSelectOption(selectId, optionValue, position ) {
        var selectList = $(selectId);
        var blnFound = false;
        //alert(selectList.getSelected().get('value'));
        var selectOptions = selectList.getElementsByTagName('option');
        $$('option[value=' + optionValue +']').each(function(ele){
           blnFound=true
   		   selectList.insertBefore(ele, selectOptions[position]);
		});
		if (!blnFound){
		   var newoption = new Option(optionValue,"");
		   $(selectList).add(newoption, position);
		}
    }




//SecurePages();
  // Jairo - 12/19/2007 - OverRiding of the DOM Alert Method 
/*var ALERT_TITLE = "Alert!";
var ALERT_BUTTON_TEXT = "Ok";

// over-ride the alert method only if this a newer browser.
// Older browser will see standard alerts
if(document.getElementById) {
	window.alert = function(txt) {
		setTimeout("createCustomAlert('" + txt + "');",1000);
	}
}

function createCustomAlert(txt) {
	// shortcut reference to the document object
	d = document;

	// if the modalContainer object already exists in the DOM, bail out.
	if(d.getElementById("modalContainer")) return;

	// create the modalContainer div as a child of the BODY element
	mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
	mObj.id = "modalContainer";
	 // make sure its as tall as it needs to be to overlay all the content on the page
	mObj.style.height = document.documentElement.scrollHeight + "px";

	// create the DIV that will be the alert 
	alertObj = mObj.appendChild(d.createElement("div"));
	alertObj.id = "alertBox";
	// MSIE doesnt treat position:fixed correctly, so this compensates for positioning the alert
	if(d.all && !window.opera) alertObj.style.top = document.documentElement.scrollTop + "px";
	// center the alert box
	alertObj.style.left = (d.documentElement.scrollWidth - alertObj.offsetWidth)/2 + "px";

	// create an H1 element as the title bar
	h1 = alertObj.appendChild(d.createElement("h2"));
	h1.appendChild(d.createTextNode(ALERT_TITLE));

	// create a paragraph element to contain the txt argument
	msg = alertObj.appendChild(d.createElement("p"));
	msg.appendChild(d.createTextNode(txt));

	// create an anchor element to use as the confirmation button.
	btn = alertObj.appendChild(d.createElement("a"));
	btn.id = "closeBtn";
	var strButtonGuid = "<div class='RoundButtonRaised'><b class='b1'></b><b class='b2'></b><b class='b3'></b><b class='b4'></b>";
	strButtonGuid += "<div class='roundboxcontent'>";
	strButtonGuid += "<h1><b>" + ALERT_BUTTON_TEXT + "</b></h1></div>";
	strButtonGuid += "<b class='b4b'></b><b class='b3b'></b><b class='b2b'></b><b class='b1b'></b></div>"
		
	//btn.appendChild(d.createTextNode(strButtonGuid));
	btn.innerHTML = strButtonGuid;
	btn.href = "#";
	// set up the onclick event to remove the alert when the anchor is clicked
	btn.onclick = function() { removeCustomAlert();return false; }


}

// removes the custom alert from the DOM
function removeCustomAlert() {
	document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer"));
}*/