﻿/* 
================================================

Original Author: Ayoosh Joshi.
Creation Date: September 2007.
Modified by: Surabhi Gupta, Anuj Arora, Rajesh Parbat, Tejveer Singh, Rahul Tyagi, Vipin Bhardwaj, Ayoosh Joshi.
Purpose: Serves as a common repository for all Online related JS. (or atleast, that was intended!) 
Copyright ©: QuadLabs Technologies Ltd. All Rights Reserved.

================================================
*/

var bType = new BrowserSniffer().GetBrowserType();


/******** GENERAL AJAX FUNCTIONS *************/
/****************************************/

//function GetXmlHttpObject()
//{
//  var ajax = null;
//	if (window.XMLHttpRequest)
//	{
//		// If IE7, Mozilla, Safari, and so on: Use native object
//		ajax = new XMLHttpRequest();
//	}
//	else
//	{
//		if (window.ActiveXObject)
//		{
//			 // ...otherwise, use the ActiveX control for IE5.x and IE6
//			 ajax = new ActiveXObject('MSXML2.XMLHTTP.3.0');
//		}
//	}
//	return ajax;
//}


/******** GENERAL PAGE FUNCTIONS *************/
/****************************************/

// Function used to show/hide DIV's. Used on Payment page to toggle Delivery address DIV.
function CopyAddress(srcField, srcType)
{
 	var optBillEqualsDel = getElement("optBillEqualsDel", false);
	if (optBillEqualsDel)
	{
	
		if (optBillEqualsDel.checked == true)
		{
			if ((srcField == null) && (srcType == null))
			{
			  var bTitile=getElement("ddlBTitle",false).value;
				var bFName = getElement("txtBFName", false).value;
				var bLName = getElement("txtBLName", false).value;
				var bAddy = getElement("txtBAddress", false).value;
				var bCity = getElement("txtBCity", false).value;
				var bCode=getElement("txtBPostCode",false).value;
				var bEmail=getElement("txtBEmailId",false).value;
				
				
				var bCountry = getElementWithSeparator("ddlCountry", true, "BCountry", "$").value;
				//var bState =getElementWithSeparator("ddlState", true, "BCountry", "$").value;
				var bOtherState=getElementWithSeparator("txtOtherState", true, "BCountry", "$").value;
				
				var dTitile=getElement("ddlDTitle",false);
				dTitile.style.background = "#eee";
				dTitile.disabled = true;
				dTitile.value = bTitile;
				
				var txtDFName = getElement("txtDFName", false);
				txtDFName.style.background = "#eee";
				txtDFName.disabled = true;
				txtDFName.value = bFName;
				
				var txtDLName = getElement("txtDLName", false);
				txtDLName.style.background = "#eee";
				txtDLName.disabled = true;
				txtDLName.value = bLName;
				
				
				var txtDAddress = getElement("txtDAddress", false);
				txtDAddress.style.background = "#eee";
				txtDAddress.disabled = true;
				txtDAddress.value = bAddy;
				
				var txtDCity = getElement("txtDCity", false);
				txtDCity.style.background = "#eee";
				txtDCity.disabled = true;
				txtDCity.value = bCity;

				var txtDPostCode = getElement("txtDPostCode", false);
				txtDPostCode.style.background = "#eee";
				txtDPostCode.disabled = true;
				txtDPostCode.value = bCode;
				
				var txtDMail = getElement("txtDMailId", false);
				txtDMail.style.background = "#eee";
				txtDMail.disabled = true;
				txtDMail.value = bEmail;
				
				var txtCountry = getElementWithSeparator("ddlCountry", true, "DCountry", "$");
				txtCountry.disabled = true;
				txtCountry.style.background = "#eee";
				txtCountry.value = bCountry;
				
	//			var txtState=getElementWithSeparator("ddlState", true, "DCountry", "$");
	//			txtState.disabled=true;
	//			txtState.value=bState
				
				var txtOther_State=getElementWithSeparator("txtOtherState", true, "DCountry", "$");
				txtOther_State.disabled=true;
				txtOther_State.style.background = "#eee";
				txtOther_State.value=bOtherState
			}
			else
			{
				switch (srcType)
				{
			      case "title":
						var btitle = srcField.value;
						getElement("ddlDTitle", false).value = btitle;
						 
						break;
					case "Fname":
						var bFName = srcField.value;
						getElement("txtDFName", false).value = bFName;
						 
						break;
					case "Lname":
					var bLName = srcField.value;
 
					getElement("txtDLName", false).value = bLName;
					break;
					case "address":
						var bAddy = srcField.value;
						getElement("txtDAddress", false).value = bAddy;
						break;
					case "city":
						var bCity = srcField.value;
						getElement("txtDCity", false).value = bCity;
						break;
					case "postcode":
						var bCode = srcField.value;
						getElement("txtDPostCode", false).value = bCode;
						break;
					case "mail":
						var bmail = srcField.value;
						getElement("txtDMailId", false).value = bmail;
						break;
					case "country":
						var bCountry = srcField.value;
						getElementWithSeparator("ddlCountry", true, "DCountry", "$").value = bCountry;
						break;
						// Added by rajesh
					case "state":
	//					var bState = srcField.value;
	//					getElementWithSeparator("ddlState", true, "DCountry", "$").value = bState;
	//					break;
					case "otherState":
					var bOtherState=srcField.value;
						getElementWithSeparator("txtOtherState", true, "DCountry", "$").value = bOtherState;
					break;
				}
			}
		}
		else
		{
		  var dTitle=getElement("ddlDTitle",false);
			dTitle.style.background = "#fff";
			dTitle.disabled = false;
			dTitle.value = "Mr";
		//getElement("txtBFName", false).value;
		
		
			var txtDFName = getElement("txtDFName", false);
			txtDFName.style.background = "#fff";
			txtDFName.disabled = false;
			txtDFName.value = getElement("txtDFName", false).value;
			
			var txtDLName = getElement("txtDLName", false);
			txtDLName.style.background = "#fff";
			txtDLName.disabled = false;
			//txtDLName.value = "";
			txtDLName.value =getElement("txtDLName", false).value;
			
			var txtDAddress = getElement("txtDAddress", false);
			txtDAddress.style.background = "#fff";
			txtDAddress.disabled = false;
			//txtDAddress.value = "";
			txtDAddress.value =getElement("txtDAddress", false).value;
			
			
			var txtDCity = getElement("txtDCity", false);
			txtDCity.style.background = "#fff";
			txtDCity.disabled = false;
			//txtDCity.value = "";
            txtDCity.value =getElement("txtDCity", false).value;
            
			var txtDPostCode = getElement("txtDPostCode", false);
			txtDPostCode.style.background = "#fff";
			txtDPostCode.disabled = false;
			//txtDPostCode.value = "";
			txtDPostCode.value =getElement("txtDPostCode",false).value;
			
			var txtDmail = getElement("txtDMailId", false);
			txtDmail.style.background = "#fff";
			txtDmail.disabled = false;
			//txtDmail.value = "";
			txtDmail.value =getElement("txtDMailId",false).value;
			
			
			var txtCountry = getElementWithSeparator("ddlCountry", true, "DCountry", "$");
			txtCountry.disabled = false;
			txtCountry.style.background = "#fff";
			//txtCountry.value = "IN";
			
			txtCountry.value=getElementWithSeparator("ddlCountry", true, "DCountry", "$").value;
			
//			//Added by rajesh
//			var txtState = getElementWithSeparator("ddlState", true, "DCountry", "$");
//			txtState.disabled = false;
//			txtState.value = "";
//			
			var txtState = getElementWithSeparator("txtOtherState", true, "DCountry", "$");
			txtState.disabled = false;
			txtState.style.background = "#fff";
			//txtState.value = "";
			txtState.value =getElementWithSeparator("txtOtherState", true, "DCountry", "$").value;
		}
	}
}


// Function used to disable entry in text fields. Used on Flight Search page to disable return date and city for One-way trip.
function LockField(fieldNames, fieldStatus)
{
	if (fieldNames)
	{
		var f;
		for (f in fieldNames)
		{
	    f = parseFloat(f);
			var field = fieldNames[f];
			if (field.substr(0,3) == "txt")
			{
				field = getElement(field, true);
			}
			else
				field = document.getElementById(field);
			if (fieldStatus == true)
			{
				if(field != null)
			  {
					if ((field.tagName.toLowerCase() == "input") && (field.type == "image"))
						field.style.cursor = "default";
					else
					{
						field.style.background = "#ccc";
						field.style.bordercolor = "#869DB2";
						field.style.borderwidth = "1px";
						field.style.borderstyle = "solid"; 
					}
			  }
			}
			else
			{
				if(field != null)
			  {
					if (field.tagName == "IMG")
						field.style.cursor = "hand";
					else
					{
						field.style.background = "#efefef";
						field.style.bordercolor = "#869DB2";
						field.style.borderwidth = "1px";
						field.style.borderstyle = "solid"; 
					}
			  }
			}
			if(field != null)
			{
				field.disabled = fieldStatus;
			}
		}
	}
}

function closediv()
{

//document.all.Iframe1.style.visibility="hidden";
document.getElementById('Iframe1').style.visibility="hidden";

	document.getElementById('maindiv1').style.visibility="hidden";
	document.getElementById('NavBar1').style.visibility="hidden";
	//document.getElementById('Calendar1').style.visibility="hidden";
	document.getElementById('Calendar1').style.visibility="hidden";
	//self.close(); 
}

// Function used to Toggle the Domestic and International DIV's on the Flight Search page.
function ToggleFlightMode(mode)
{
//debugger
	if (mode == "FlightIntl")
	{
	closediv();
	  if (document.getElementById("ctl00_contentMain_ctl00_FlightDom"))
	  {
		document.getElementById("ctl00_contentMain_ctl00_FlightDom").style.display = "none";
	  }
		//document.getElementById("spnIntlI").className = "FlightModeActive";
		if (document.getElementById("ctl00_contentMain_ctl00_TdIntlI"))
		{
		document.getElementById("ctl00_contentMain_ctl00_TdIntlI").className = "ActiveTab";
		}
		//document.getElementById("spnDomI").className = "FlightModeInactive";
		  if (document.getElementById("ctl00_contentMain_ctl00_TdDomI"))
		  {
		document.getElementById("ctl00_contentMain_ctl00_TdDomI").className = "InactiveTab";
		  }
		  if (document.getElementById("ctl00_contentMain_ctl00_hdnFlightMode"))
		  {
		document.getElementById("ctl00_contentMain_ctl00_hdnFlightMode").value = "I";
		}
		document.getElementById("hdnDisabledDate").value = document.getElementById("ctl00_contentMain_ctl00_hdnDisabledDateInt").value;
	}
	//TdInt
	//TdDomI
	else if (mode == "FlightDom")
	{
	closediv();
	  if (document.getElementById("ctl00_contentMain_ctl00_FlightIntl"))
	  {
		document.getElementById("ctl00_contentMain_ctl00_FlightIntl").style.display = "none";
	  }
		//document.getElementById("spnIntlD").className = "FlightModeInactive";
		  if (document.getElementById("ctl00_contentMain_ctl00_TdInt"))
		  {
		document.getElementById("ctl00_contentMain_ctl00_TdInt").className = "InactiveTab";
		  }
		//document.getElementById("spnDomD").className = "FlightModeActive";
		if (document.getElementById("ctl00_contentMain_ctl00_TdDom"))
		{
		document.getElementById("ctl00_contentMain_ctl00_TdDom").className = "ActiveTab";
		}
		if (document.getElementById("ctl00_contentMain_ctl00_hdnFlightMode"))
		{
		document.getElementById("ctl00_contentMain_ctl00_hdnFlightMode").value = "D";
		}
		document.getElementById("hdnDisabledDate").value = document.getElementById("ctl00_contentMain_ctl00_hdnDisabledDateDom").value;
	}else if(mode=="FlightMultiCity")
	{
	    document.getElementById("hdnDisabledDate").value = document.getElementById("ctl00_contentMain_ctl00_hdnDisabledDateInt").value;
	}
	
	document.getElementById("ctl00_contentMain_ctl00_"+mode).style.display = "block";
}


function FlightModeToggle(mode)
{
	if (mode == "FlightIntl")
	{
		document.getElementById("hdnDisabledDate").value = document.getElementById("ctl00_contentMain_ctl00_hdnDisabledDateInt").value;
	}
	else if (mode == "FlightDom")
	{
		document.getElementById("hdnDisabledDate").value = document.getElementById("ctl00_contentMain_ctl00_hdnDisabledDateDom").value;
	}
}

/******** CALENDAR SPECIFIC *************/
/****************************************/

// No. of millisecs in a single day.
var DAY = 24 * 60 * 60 * 1000;

// Function disables ALL dates before the current date in the Calendar. The parameter represents each date rendered by the calendar.
function DisableDates(theDate, calendarType)
{
	var disabledDiff;
	if (calendarType == "dom")
	{
		var hdn = getElement("hdnDisabledDateDom", true);
		if (hdn)
			disabledDiff = hdn.value;
	}
	else if (calendarType == "int")
	{
		var hdn = getElement("hdnDisabledDateInt", true);
		if (hdn)
			disabledDiff = hdn.value;
	}
	else
	{
	    var hdn = getElement("hdnDisabledDate", true);
		if (hdn)
			disabledDiff = hdn.value;
		if(document.getElementById("ctl00_contentMain_Modify_hdnDisabledDate"))
		    {
		      disabledDiff = document.getElementById("ctl00_contentMain_Modify_hdnDisabledDate").value
		    }
	}
	var today = new Date();
	today.setDate(today.getDate() + parseInt(disabledDiff) + 1);
	var currTime = Math.abs(today.getTime());
	var theTime = Math.abs(theDate.getTime());
	if ((currTime - theTime) / DAY >= 1)
		return true;
	else
		return false;
}

function GetYear(type)
{
	var today = new Date();
	var thisYear = today.getFullYear();
	if (type == "curr")
		return thisYear;
	else if (type == "next")
		return (thisYear + 1);
}

function setupCalendar(txtFieldName, imgFieldName, calType)
{
////debugger
	var txtField = getElementName(txtFieldName, true);
	Calendar.setup({inputField:txtField, button:imgFieldName, range:[GetYear("curr"), GetYear("next")], calendarType:calType});
}

function setupModifyCalendar(txtField, imgFieldName, calType)
{
	Calendar.setup({inputField:txtField, button:imgFieldName, range:[GetYear("curr"), GetYear("next")], calendarType:calType});
}

/******** ELEMENT RETRIEVAL *************/
/****************************************/

// Function returns an ELEMENT, when supplied the id and a boolean indicating whether the element is contained in a UserControl.
// contentMain is the name of the Content container defined in the Master page.
// This function assumes the default separator "$".
function getElement(elName, prefixCtrl)
{
////debugger;
  var modify,modifyInt;
	var prefix = "ctl00_contentMain_";
	if(document.getElementById("ctl00_contentMain_ModifyFlightSearch1_hndModify")!=null)
	{
	modify=document.getElementById("ctl00_contentMain_ModifyFlightSearch1_hndModify").value;
	}
	 if(document.getElementById("ctl00_contentMain_ModifyIntFlightSearch1_hndModifyInt")!=null)
	{
	modifyInt=document.getElementById("ctl00_contentMain_ModifyIntFlightSearch1_hndModifyInt").value;
	}
	
	if(prefixCtrl==true)
	{
	if(modifyInt=="true")
	{
	 prefix +="ModifyIntFlightSearch1_"
	}
	else
	{
	if(modify=="true")
	{
	 prefix +="ModifyFlightSearch1_"
	}
	
	else
	{
	    prefix += "ctl00_";
    }
    }
	}
	else if(prefixCtrl=="dob")
	{
	    prefix += "dob1_";
	}
    else if(prefixCtrl=="dob4")
	{
	    prefix += "dob4_";
	}
	//
	elName = prefix + elName;
	// Modify the elName to the ID if this is Mozilla.
	if (bType != "ie")
	{
		elName = elName.replace(/[\$]/g,'_');
	}
	return new DOM().$(elName);
}

// Function returns an Element Name, when supplied the id and a boolean indicating whether the element is contained in a UserControl.
// contentMain is the name of the Content container defined in the Master page.
function getElementName(elName, prefixCtrl)
{
	var prefix = "ctl00$contentMain$";
	if(prefixCtrl==true)
	{
	    prefix += "ctl00$";
	}
	
	elName = prefix + elName;
	return elName;
}

function getElementWithSeparator(elName, prefixCtrl, ctrlName, separator)
{
	var prefix = "ctl00" + separator + "contentMain" + separator;
	
	if(prefixCtrl==true)
	{
	    prefix = prefix + ctrlName + separator;
	}
	//
	elName = prefix + elName;
	var chkVar = new DOM().$(elName);
	if (chkVar == null)
	{
		elName = elName.replace(/[\$]/g,'_');
	}
	return new DOM().$(elName);
	//return document.getElementById(elName);
}

function getDDLNameWithSeparator(elName, prefixCtrl, ctrlName, separator)
{
	var prefix = "ctl00" + separator + "contentMain" + separator;
	
	if(prefixCtrl==true)
	{
	    prefix = prefix + ctrlName + separator;
	}
	//
	elName = prefix + elName;
	
	return elName;
}

function getElementNameWithSeparator(elName, prefixCtrl, separator)
{
	var prefix = "ctl00" + separator + "contentMain" + separator;
	
	if(prefixCtrl==true)
	{
	    prefix += "ctl00" + separator;
	}
	//
	elName = prefix + elName;
	return elName;
}

function getElementShortName(elFullName, separator)
{
	var elName;
	var idx = elFullName.lastIndexOf(separator);
	if (idx != -1)
	{
		elName = elFullName.slice(idx + 1);
	}
	return elName;
}


/******** CALENDAR DATE VALIDATION ********/
/****************************************/

// Function validates the date set for a particular calendar by comparing it with the date set for the paired field.
// This function is called by the onSelect event of the Calendar.
function checkDate(calendar, selDate)
{
	////debugger
	if (calendar.dateClicked)
	{
		// Get the date set by the current field.
		var thisDate = calendar.date;
		
		// Get name of input field attached to this Calendar.
		var thisField = calendar.params.inputField;
		var thisFieldName = thisField.id;
		
		// Get name of other input field related to this one.
		// Create an object variable so that it can be passed ByRef
		var thisFieldNameIsPrevious = new Object();
		var otherField = getOtherField(thisFieldName, thisFieldNameIsPrevious);
		
		// Get the value in the other field.
		var otherValue = otherField.value;
		var otherDefaultValue = otherField.defaultValue;
		
		// If the otherField has been set OR is not blank OR is not equal to the selected date in the Calendar.
		if (!((otherValue == otherDefaultValue) || (otherValue == "") || (otherValue == selDate)))
		{
			// Convert the value (dd-mmm-yyyy) to an acceptable date object.
			var du = new DateUtils();
			var otherDate = du.convertStringToDate(otherValue, "-");
			
			if (thisFieldNameIsPrevious.value == false)
			{
				// This field should have a date later than the other field.
				if (thisDate > otherDate)
				{
					thisField.value = selDate;
				}
				else
				{
					alert("~Translate~(Commons_ArrivalbeforeDepr)");//The Arrival date cannot be before the Departure date.
					
					// Set field to present date.
					thisField.value = otherValue;
				}
			}
			else
			{
				// This field should have a date earlier than the other field.
				if (thisDate < otherDate)
				{
					thisField.value = selDate;
				}
				else
				{
					alert("~Translate~(Commons_DeprAftrArrival)");//The Departure date cannot be after the Arrival date.
					
					// Set field to present date.
					thisField.value = otherValue;
				}
			}
			if (calendar.dateClicked)
				calendar.callCloseHandler();
		}
		else
			// If the other is blank, simply set the Date.
			thisField.value = selDate;
			if (calendar.dateClicked)
				calendar.callCloseHandler();
	}
}


// Returns the paired text field as well as the order of succession, when passed a field Name.
function getOtherField(thisField, thisFieldIsPrevious)
{
	var otherFieldName;
	
	thisField = getElementShortName(thisField, "_");

	switch(thisField)
	{
		case "txtFLDepDate":
			otherFieldName = "txtFLRetDate";
			thisFieldIsPrevious.value = true;
			break;
		case "txtFLRetDate":
			otherFieldName = "txtFLDepDate";
			thisFieldIsPrevious.value = false;
			break;
		case "txtFLDDepDate":
			otherFieldName = "txtFLDRetDate";
			thisFieldIsPrevious.value = true;
			break;
		case "txtFLDRetDate":
			otherFieldName = "txtFLDDepDate";
			thisFieldIsPrevious.value = false;
			break;
		case "txtHTCheckIn":
			otherFieldName = "txtHTCheckOut";
			thisFieldIsPrevious.value = true;
			break;
		case "txtHTCheckOut":
			otherFieldName = "txtHTCheckIn";
			thisFieldIsPrevious.value = false;
			break;
		case "txtCRPickupDate":
			otherFieldName = "txtCRDropDate";
			thisFieldIsPrevious.value = true;
			break;
		case "txtCRDropDate":
			otherFieldName = "txtCRPickupDate";
			thisFieldIsPrevious.value = false;
			break;
		case "txtINDepartDate":
			otherFieldName = "txtINRetDate";
			thisFieldIsPrevious.value = true;
			break;
		case "txtINRetDate":
			otherFieldName = "txtINDepartDate";
			thisFieldIsPrevious.value = false;
			break;
	}
	var otherField
	if (document.getElementById("ctl00_contentMain_Modify_hndModifyCal") != null)
	{
	otherField = "ctl00$contentMain$Modify$" + otherFieldName
	}
	else
	{
	otherField = getElement(otherFieldName, true);	
	}
	return otherField;
}

/******** DATE UTILITY CLASS *************/
/*********************************************/

function DateUtils()
{

	// Function converts a string in any format, separated by a specified symbol, into a Date object and returns that Date object.
	this.convertStringToDate = function(strDate, dateSeparator)
	{
		var dateParts = strDate.split(dateSeparator);
		
		var day = parseInt(dateParts[0], 10);
		var month = this.getMonthNum(dateParts[1]);
		var year = parseInt(dateParts[2]);
		var theDate = new Date(year, month, day);
		return theDate;
	}

	// Function converts a date object into a string in the format dd<separator>MMM<separator>yyyy and returns that string.
	this.convertDateToString = function(thisDate, dateSeparator)
	{
		var day = thisDate.getDate();
		var month = this.getMonthName(thisDate.getMonth());
		var year = thisDate.GetYear();
		var theDateString = day + dateSeparator + month + dateSeparator + year;
		return theDateString;
	}

	// Utility function used by convertDateToString(). Returns Month name in "MMM" format.
	this.getMonthName = function(monthNum)
	{
		switch (monthNum)
		{
			case 0:
				return "Jan"; break;
			case 1:
				return "Feb"; break;
			case 2:
				return "Mar"; break;
			case 3:
				return "Apr"; break;
			case 4:
				return "May"; break;
			case 5:
				return "Jun"; break;
			case 6:
				return "Jul"; break;
			case 7:
				return "Aug"; break;
			case 8:
				return "Sep"; break;
			case 9:
				return "Oct"; break;
			case 10:
				return "Nov"; break;
			case 11:
				return "Dec"; break;
		}
	}

	// Utility function used by convertStringToDate(). Returns Month number(base 0) when supplied a month name in "MMM" format.
	this.getMonthNum = function(monthName)
	{
		switch (monthName)
		{
			case "Jan":
				return 0; break;
			case "Feb":
				return 1; break;
			case "Mar":
				return 2; break;
			case "Apr":
				return 3; break;
			case "May":
				return 4; break;
			case "Jun":
				return 5; break;
			case "Jul":
				return 6; break;
			case "Aug":
				return 7; break;
			case "Sep":
				return 8; break;
			case "Oct":
				return 9; break;
			case "Nov":
				return 10; break;
			case "Dec":
				return 11; break;
		}
	}
	
	// Get Day of Week using a Date in format ddMMyy.
	this.getDayOfWeek = function(strDate)
	{
		var day = strDate.substring(0, 2);
		var month = parseInt(strDate.substring(2, 4),10) - 1;
		var year = "20" + strDate.substring(4, 6);

		var theDate = new Date(year, month, day);
		
		return theDate.getDay();
	}
	
	// Adds a date to a date in ddMMyy format and returns the new date in same format.
	this.AddDate = function(startDate, dateDiff)
	{
		var startDay = startDate.substring(0, 2);
		var startMonth = parseInt(startDate.substring(2, 4)) - 1;
		var startYear = "20" + startDate.substring(4, 6);
		
		var newDate = new Date(startYear, startMonth, startDay);
		newDate.setDate(newDate.getDate() + dateDiff);
		
		var newDay = newDate.getDate();
		newDay = newDay.toString().length < 2 ? "0" + newDay : newDay;
		
		var newMonth = newDate.getMonth();
		newMonth = newMonth.toString().length < 2 ? "0" + (newMonth + 1) : newMonth + 1;
		
		var newYear = newDate.getFullYear().toString();
		newYear = newYear.substring(2);

		var nd = newDay.toString() + newMonth.toString() + newYear.toString();
		return nd;
	}
}


/*********** WEB SERVICE UTILITY FUNCTIONS **********/
/****************************************************/

// Set the service URL's before page loads.
//fnSetServiceURL();


function fnSetServiceURL()
{
  xmlHttp = new GetXmlHttpObject();

  if (xmlHttp)
  {
    var webServiceURL;
    var httpMethod = "GET";

    webServiceURL="GetServiceName.aspx"
    xmlHttp.onreadystatechange = fnServiceResponseHandler;
    xmlHttp.open("GET", webServiceURL, true);
    //xmlHttp.send(null);
  }
}


function fnServiceResponseHandler()
{
   if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
	{
		if (xmlHttp.status == 200)
		{
      var strReply=(xmlHttp.responseText).split("||~~||")

      //BE_Service=strReply[0]
      //XChangeOnlineService=strReply[1]
      //mainService=strReply[2]
		}
	}
}

function openfarerules(fareref,airlinesno,currCode,ROE)
{//debugger

	var hdnFareRuleRedirect = (dom.$("ctl00$contentMain$Basket1$hdnFareRuleRedirect") != null ? dom.$("ctl00$contentMain$Basket1$hdnFareRuleRedirect") : dom.$("ctl00$contentMain$hdnFareRuleRedirect"));
	
	if ((ObjectExists(hdnFareRuleRedirect)) && (hdnFareRuleRedirect.value == "True"))
	{
		if(airlinesno.indexOf("SGP") != -1)
		{
			window.open("http://www.spicejet.com/tnc.asp","FareRules","width=800,height=400,top=50,left=60,scrollbars=yes,resizable=no");
		}
		else if(airlinesno.indexOf("SSP") != -1)
		{
			window.open("http://www.spicejet.com/tnc.asp","FareRules","width=800,height=400,top=50,left=60,scrollbars=yes,resizable=no");
		}
		else if(airlinesno.indexOf("DNP") != -1)
		{
			window.open("http://airdeccan.net/data/helpdesk/terms_cons.html","FareRules","width=800,height=400,top=50,left=60,scrollbars=yes,resizable=no");
		}
		else if(airlinesno.indexOf("INP") != -1)
		{
			window.open("http://book.goindigo.in/skylights/images/html/COC.html","FareRules","width=800,height=400,top=50,left=60,scrollbars=yes,resizable=no");
		}
		else if(airlinesno.indexOf("ISP") != -1)
		{
			window.open("http://book.goindigo.in/skylights/images/html/COC.html","FareRules","width=800,height=400,top=50,left=60,scrollbars=yes,resizable=no");
		}
		else
		{
			path="FareRules.aspx?airlinesno=" + airlinesno + "&fareref=" + fareref + "&CurrCode=" + currCode + "&ROE=" + ROE;
			window.open(path,"FareRules","width=550,height=400,top=50,left=120,scrollbars=yes,resizable=no");
		}
	}
	else
	{
		path="FareRules.aspx?airlinesno=" + airlinesno + "&fareref=" + fareref + "&CurrCode=" + currCode + "&ROE=" + ROE;
		window.open(path,"FareRules","width=550,height=400,top=50,left=120,scrollbars=yes,resizable=no");
	}
}

function changeSAMarkup(fareref,airlinesno)
{
	path="updSAMarkup.aspx?fareref="+fareref+"&airlinesno=" + airlinesno
  window.open(path,"UpdateSAMarkup","width=570,height=275,top=50,left=120,scrollbars=yes,resizable=no,toolbar=no,menubar=no,titlebar=no");
}

function openfareBreakup(fareref,airlinesno)
{
	path="FareBreakup.aspx?fareref="+fareref+"&airlinesno=" + airlinesno
    window.open(path,"FareBreakup","width=575,height=575,top=50,left=120,scrollbars=yes,resizable=no");
} 
function openDynamicSearchfareBreakup(fareref,airlinesno)
{
	path="DynamicSearchfarebreakup.aspx?fareref="+fareref+"&airlinesno=" + airlinesno
    window.open(path,"FareBreakup","width=575,height=575,top=50,left=120,scrollbars=yes,resizable=no");
}
function openTermsConditions()
{  

window.open("TermsConditions.aspx","TermsConditions","width=550,height=400,top=50,left=120,scrollbars=yes,resizable=no");
}

function fnPrintEticket(BookingRef,FlightId,WebServiceurl,compID)
{
////debugger;
var tempxml='<Root><BookingRef>'+ BookingRef+'</BookingRef><CompanyId>'+compID+'</CompanyId><FlightId><Id>'+FlightId+'</Id></FlightId></Root>';
var webUrl=WebServiceurl+ "ETICKET/ETICKET.ASMX/fnEticket?tempxml="+ tempxml;
 xmlHttp = new GetXmlHttpObject();
 xmlHttp.open("GET", webUrl, true)
   xmlHttp.onreadystatechange = fnFetchResult;
   xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
   xmlHttp.send(null)
 
        
}

function fnFetchResult()
{

                
                if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
	{
		if (xmlHttp.status == 200)
		{
              var xmlResult=new ActiveXObject("Msxml2.DOMDocument")
 var strResult = xmlHttp.responseXML.text;
 xmlResult.loadXML(strResult);
  var xslt = new ActiveXObject("Msxml2.XSLTemplate");
  var xslProc;
  var htmlResult;
   var xsltPassengerResult = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
                xsltPassengerResult.async = false;
                xsltPassengerResult.resolveExternals = false;

                xsltPassengerResult.load("../XSLT/EticketXSL1.xsl");
                xslt.stylesheet = xsltPassengerResult;
                xslProc = xslt.createProcessor();
                xslProc.input = xmlResult;
                xslProc.transform();
                htmlResult=xslProc.output;
              var win=  window.open('ETicket.aspx','eTicket','width=800,height=800,top=10,left=50,scrollbars=yes,resizable=no');
              win.document.write(htmlResult);
              win.document.close();
              win.print();
           }
      }
}
function replaceSeparator(strInput)
{
        var hdnDecSeparator = document.getElementById("ctl00_hdnDecSeparator").value;
        var textSeparator = "";
        if(hdnDecSeparator == ",")
            textSeparator = /\./g  ///[^\d,]/g;
        else
            textSeparator = /,/g;
     return strInput.replace(textSeparator,'').replace(hdnDecSeparator,'.');
}

/******** LAYER FUNCTIONS *************/
/****************************************/

function ToggleLayer(hide)
{
var dom = new DOM();
  var shadow = dom.$("Shadow");
  var msg = dom.$("Message");
  var results = dom.$("tblResults");
  
  PositionLayers(shadow, msg);

	if (hide == true)
	{
		
		shadow.style.display = "block";
		msg.style.display = "block";
		//results.style.display = "none";
	}
	else
	{
 
	shadow.style.display = "none";
		msg.style.display = "none";
		//results.style.display = "block";
	}
}

function PositionLayers(shadowLayer, msgLayer)
{
	var divWidth = 400;
	var divHeight = 350;
    
    //var divWidth = 200;
	//var divHeight = 175;

	// Get Inner height and width.
	var dimension = GetInnerDimensions();
	var h = dimension.Height;
	var w = dimension.Width;
	
	// Shadow layer needs to cover entire area.
	shadowLayer.style.width = w + "px";
  shadowLayer.style.height = h + "px";
	
	// Get Scroll offset.
	var scrollY = GetVerticalScrollPosition();
	
	var left = (w - divWidth) * 0.5;
	var top = ((h - divHeight) * 0.5);
	// Message layer needs to be centered.
  msgLayer.style.left = left + "px";
  msgLayer.style.top = top + "px";
}

function GetInnerDimensions()
{
	w = 0;
	h = 0;
	
  if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) 
  {
    //IE 6+ in 'standards compliant mode'
    w = document.documentElement.clientWidth;
    h = document.documentElement.clientHeight;
  }
  else if(document.body && (document.body.clientWidth || document.body.clientHeight))
  {
    //IE 4 compatible
    w = document.body.clientWidth;
    h = document.body.clientHeight;
  }
  else if(typeof(window.innerWidth) == 'number')
  {
    //Non-IE
    w = window.innerWidth;
    h = window.innerHeight;
  } 
  
  return {"Width": w, "Height": h};
}

function GetVerticalScrollPosition()
{
	var scrollY = 0;
  if(typeof(window.pageYOffset) == 'number') 
  {
    //Netscape compliant
    scrollY = window.pageYOffset;
  }
  else if(document.body && (document.body.scrollLeft || document.body.scrollTop)) 
  {
    //DOM compliant
    scrollY = document.body.scrollTop;
  }
  else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) 
  {
    //IE6 standards compliant mode
    scrollY = document.documentElement.scrollTop;
  }
  return scrollY;
}

function chkSpecialFare_no()
{
////debugger;
    var trLCC = document.getElementById('trLCCRT');
    var chkLCC = document.getElementById('ctl00_contentMain_ModifyFlightSearch1_chkLCCRT');
      if (ObjectExists(trLCC))
        {
                chkLCC.checked = false ;
        }
}
