var on_color   = "#FDAB63";
var off_color  = "#FFFFFF";
var blinkspeed = 500;
//var myOldAge   = -1;

function blink(s)
{
	var o = document.all(s);
	
	if( o.blink_onoff == 1)
	{
		o.style.color = on_color;
		o.blink_onoff = 0;
	}
	else
	{
		o.style.color = off_color;
		o.blink_onoff = 1;
	}
}

function COMPASS_GetDateFromCalendar(params)
{
	var qString = "";
	
	for(var x in params)
	{
		if(params[x] != "") {qString += ("&" + x + "=" + params[x])};
	}
	
	//qString += ("&rand=" + Math.random());
	
	var sURL = CLVAR.COMPASS_SE_CALENDAR_FLIGHTS_CALENDAR_URL + qString;
	//alert(sURL)
	
	CopyTextIntoClipboard(sURL);
	//window.open(sURL);
	return ShowModalDialog(sURL, params, 410, 320); 
} 

function CopyTextIntoClipboard(s)
{
	return;
	try{window.clipboardData.setData("Text",s);}catch(e){};
}

function ShowHotelPictures(sHotelName,id)
{	
	var xmlIsland = document.getElementById(id+"HotelPictures")
	
	if(!xmlIsland) return false;
	
	var sURL = CLVAR.COMPASS_SHOW_HOTEL_PICTURES_URL + "&HotelName=" + escape(sHotelName);	
	//alert(sURL); //Remove This
	return ShowModalDialog(sURL, xmlIsland, 510, 459);
    //return window.open(sURL,"test", 'toolbar,width=510,height=459');
}

function ShowHotelPicturesIL(sHotelName,id)
{	
	var xmlIsland = document.getElementById(id+"HotelPictures")
	
	if(!xmlIsland) return false;
	
	var sURL = CLVAR.COMPASS_SHOW_HOTEL_PICTURESIL_URL + "&HotelName=" + escape(sHotelName);	
	return ShowModalDialog(sURL, xmlIsland, 510, 459);
    //return window.open(sURL,"test", 'toolbar,width=510,height=459');
}

function ShowIsraelPictures(id, obj)
{
	var sHotelName	= obj.Hotel;
	var xmlIsland	= document.getElementById(id);
	
	if(!xmlIsland) return false;
	
	var sURL		= CLVAR.ISRAEL_SHOW_HOTEL_PICTURES_URL + "&HotelName=" + escape(sHotelName);
	
	return ShowModalDialog(sURL, xmlIsland, 510, 459);
}


function GetListboxIndexByValue(oListbox, sValue)
{
	var oOptions = oListbox.options;
	var ListCount = oOptions.length;

	for(var i = 0; i < ListCount; i++)
	{
		if(oOptions(i).value == sValue)
		{
			return i;
		}
	}
	for(var i = 0; i < ListCount; i++)
	{
		if(oOptions(i).value == parseInt(sValue))
		{
			return i;
		}
	}
	for(var i = 0; i < ListCount; i++)
	{
		if(oOptions(i).text == sValue)
		{
			return i;
		}
	}
	for(var i = 0; i < ListCount; i++)
	{
		if(oOptions(i).text == parseInt(sValue))
		{
			return i;
		}
	}

	return -1;
}

function ListBox_SetItemsSelected1(oListbox, sValue)
{
	oOptions = oListbox.options;
	iCount = oOptions.length - 1;	
	iIndex = GetListboxIndexByValue(oListbox, sValue);
	
	if(iIndex <= iCount && iIndex > -1)
	{
		oOptions(iIndex).selected = true;
		oListbox.fireEvent('onChange');
		return;
	}
	else{
		var ind = oOptions.length;
		oListbox.options[ind] = new Option(sValue,sValue)
		//oListbox.options[ind].text = sValue;
		//oListbox.options[ind].value = sValue;
		oListbox.options[ind].selected = true;
		
		oListbox.fireEvent('onChange');
		return;
	}
}
function ListBox_SetItemsSelected(oListbox, sValue)
{
	//alert(oListbox.id);
	oOptions = oListbox.options;
	iCount = oOptions.length - 1;	

	iIndex = GetListboxIndexByValue(oListbox, sValue);
	
	if(iIndex <= iCount && iIndex > -1)
	{
		oOptions(iIndex).selected = true;
		oListbox.fireEvent('onChange');
		return;
	}
	
}
function TextBox_SetText(oTextBox, sValue)
{
	oTextBox.value = sValue;
	oTextBox.fireEvent("onChange");	
}

function ListBox_GetValue(o)
{
	return o.options[o.options.selectedIndex].value;
}

function ListBox_GetText(o)
{
	return o.options[o.options.selectedIndex].text;
}

function ListBox_GetAttribute(o,sAttributeName)
{
	var s = "";
	try{s = o.options[o.options.selectedIndex].attributes[sAttributeName].value}catch(e){} 
	return s;
}

function swapDisplay(id)  
{
	try
	{
		var section = document.getElementById(id);
		var s		= section.style.display;
		
		if (s=='none')
		{
			section.style.display = 'inline';
		}
		else
		{
			section.style.display = 'none';
		}
	}
	catch(e){window.status=e.description}
	
	try
	{
		var icon	= document.getElementById(id+"Icon");
		var src = icon.src;
		
		if (src.indexOf("_plus")>0)
		{
		
			icon.src = src.replace("_plus","_minus");
		}
		else
		{
		
			icon.src = src.replace("_minus","_plus");
		}
	}
	catch(e)
	{
		//window.status=e.description				
	}
}

function swapDisplay3_paymentForm(id1, id2, id3)
{
	swapDisplay(payment_form_Prefix + "_" + id1);
	swapDisplay(payment_form_Prefix + "_" + id2);
	swapDisplay(payment_form_Prefix + "_" + id3);
}

function swapDisplay3(id1, id2, id3)
{
	var sPrefix = order_traveler_papers_Prefix + "_";
	
	try
	{
		var section1 = document.getElementById(sPrefix + id1);
		var s = section1.style.display;
		var section2 = document.getElementById(sPrefix + id2);
		var section3 = document.getElementById(sPrefix + id3);
		
		if (s=='none')
		{
			section1.style.display = 'inline';
			if(document.getElementById(sPrefix + "inpRadioButtonsFlag").value == 'show')
			{
				section2.style.display = 'inline';
				section3.style.display = 'inline';
			}
			else
			{
				section2.style.display = 'none';
				section3.style.display = 'none';
			}
		}
		else
		{
			section1.style.display = 'none';
			section2.style.display = 'none';
			section3.style.display = 'none';
		}
	}
	catch(e)
	{
		//alert(e);
	}
}

function swapDisplay4(sourceID, targetID)  
{
	var prefix	=	sourceID.substring(0,sourceID.indexOf("_")+1);
	var	fullTargetID	=	"";
	if (prefix.substring(0,2) == "tr")
	{
		fullTargetID	=	targetID;
	}
	else
	{
		fullTargetID	=	prefix + targetID;
	}	
	
	swapDisplay(fullTargetID);
}

function swapDisplay5(sourceID, targetID)  
{
	var prefix	=	sourceID.substring(0,sourceID.lastIndexOf("_")+1);
	var	fullTargetID	=	"";
	if (prefix.indexOf("Title_") != -1)
	{
		prefix	=	prefix.substring(0,prefix.indexOf("Title_"));
	}
	
	fullTargetID	=	prefix + targetID;
		
	swapDisplay(fullTargetID);
}

function DisplayOrNo(prefix, id, flag)  
{
	//var sPrefix = "CompassModuleControl_ucTravelPapers_";
	
	try
	{
		var section = document.getElementById(prefix + id);
		if (flag=='inline')
		{
			section.style.display = 'inline';
			document.getElementById(prefix + "inpRadioButtonsFlag").value	= 'show';
		}
		else
		{
			section.style.display = 'none';
			document.getElementById(prefix + "inpRadioButtonsFlag").value	= 'dont_show';
		}
	}
	catch(e){}
}


function swapDisplayControl ( id )
{
	var sPrefix = abroad_passengers_form_Prefix + "_";
	
	var section = document.getElementById(sPrefix + id);
	if ( section.style.display == 'inline' )
	{
		section.style.display = 'none';
	}
	else
	{
		section.style.display = 'inline'
	}
}

function DisplayOrNo2(id1, id2, flag, code)
{
	var sPrefix = order_traveler_papers_Prefix + "_";
	
	DisplayOrNo(sPrefix, id1, flag);
	DisplayOrNo(sPrefix, id2, flag);
	
	document.getElementById(sPrefix + "inpRadioButtonCode").value = code;	
}


function TravelerFormAlert ( str )
{
		//alert(str);
}


// FLOATING POPUP FOR COMPASS CHARTER TERMS AND CONDITIONS
// htmlTemplateID	  = the HTML template for the content 
// contentItemID	  = the object holding the content
// displayItemID	  = the container in which to display the content 
var lastViewedItemID = 0;

// attach event listener to the document mouse click
document.onmousedown = fireDisplayFloatingPopup;

function fireDisplayFloatingPopup()
{
	try
	{
		if (lastViewedItemID==0) return;
		var o = document.getElementById(lastViewedItemID);
		if (o.style.display=="inline")
		{
			o.style.display = "none";
		}	
	}
	catch(e){}
}

function displayFloatingPopup(htmlTemplateID, contentItemID, displayItemID)
{
	try
	{
		var _htmlTemplate = document.getElementById(htmlTemplateID);
		var _contentItem = document.getElementById(contentItemID);
		var _displayItem = document.getElementById(displayItemID);
		if (lastViewedItemID==displayItemID && _displayItem.style.display=='inline')
		{
			_displayItem.style.display = 'none';
		}
		else
		{
			if (lastViewedItemID!=0)
			{
				var _displayItemPrev = document.getElementById(lastViewedItemID);
				_displayItemPrev.style.display = 'none';	
			}
			var templateHTML = _htmlTemplate.innerHTML;
			templateHTML = templateHTML.replace("_REPLACE_CONTENT_",_contentItem.innerHTML);
			_displayItem.innerHTML = templateHTML;
			_displayItem.style.display = 'inline';
			lastViewedItemID = displayItemID;
		}
	}	
	catch(e){} 
}


function isnull(s)
{
	s = String(s);
	if (s=='' || s==null || s=='undefined') return true;
	else return false;
}

// array to track number of rooms in each group
var groupRowsCount = [];
function setCompassRooms(groupID, selectListObj, bBaby)
{	
	if (isnull(bBaby)) bBaby=0;
	var table				= document.getElementById("roomsParent");
	var totalRowsCount		= table.rows.length;
	var imgCell				= document.getElementById("roomsSideImage");
	var TotalItemPriceInput	= document.getElementById("TotalItemPriceInput_"+groupID);
	var TotalItemPriceInputSymbol	= document.getElementById("TotalItemPriceInputSymbol_"+groupID);
	var requestNumberOfRooms = Number(selectListObj.selectedIndex);
	var GlobalPriceInput		 = document.getElementById("GlobalPriceInput");
	var groupFirstRow		= document.getElementById(groupID);
	var groupNumber			= groupFirstRow.getAttribute("group");
	var groupStartRowIndex	= groupFirstRow.rowIndex;
	var roomPrice			= Number(groupFirstRow.getAttribute("roomPrice"));
	var infPrice			= Number(groupFirstRow.getAttribute("infPrice"));
	var groupID_base		= groupID.substring(0,groupID.lastIndexOf("_")+1);
	
	if (isnull(groupRowsCount[groupID])) groupRowsCount[groupID] = 1;
	
	if (requestNumberOfRooms == 0)
	{
		// multiple rows
		if (Number(bBaby)>0)
		{
			var infants = document.getElementById("inf_"+groupID);
			infants.selectedIndex = 0;
			infants.disabled = true;
		}
		// Reset the room price
		var New_TotalRoomPrice = 0;
	} 
	else
	{
		if (Number(bBaby)>0)
		{
			var infants = document.getElementById("inf_"+groupID);
			infants.disabled = false;
			
			// MULTIPLE ROWS GROUP: total price for current room with infants
			var New_TotalRoomPrice = roomPrice;
		}
		else
		{
			// SINGLE ROW GROUP: total rooms price for room type without infants
			var New_TotalRoomPrice = roomPrice * requestNumberOfRooms;
		}
		
		// set first row room price
		
	}
	TotalItemPriceInput.value = New_TotalRoomPrice;
	
	
	// add rooms rows
	// update price for each room
	// update total price for all rooms
	if (Number(bBaby)>0) 
	{
		// SET ACTION
		var action = "add";
		if (requestNumberOfRooms==groupRowsCount[groupID]) 
		{
			action="skip";
		}		
		else if (groupRowsCount[groupID]>requestNumberOfRooms)
		{
			action = "remove";
		}
		// ADD or REMOVE rooms rows
		if (action!="skip")
		{
			var td2_HTML = groupFirstRow.cells[1].innerHTML;
			var td2_className = groupFirstRow.cells[1].className;
			var td3_HTML = groupFirstRow.cells[2].innerHTML;
			var td3_className = groupFirstRow.cells[2].className;
			var td4_HTML = groupFirstRow.cells[3].innerHTML;
			var td4_className = groupFirstRow.cells[3].className;
			
			var nextRowIndex = Number(groupStartRowIndex)+Number(groupRowsCount[groupID]);
			var range = Math.abs(Number(groupRowsCount[groupID]) - requestNumberOfRooms);
			
			for (var i=0;i<range;i++)
			{
				if (action == "add")
				{
					// set new row id 
					newID = groupID_base + Number(groupRowsCount[groupID]);
					
					// set new id on copied HTML
					var td5_HTML = groupFirstRow.cells[4].innerHTML;
					td5_HTML = td5_HTML.replace(groupID, newID);
					var td5_className = groupFirstRow.cells[4].className;
					
					var td6_HTML = groupFirstRow.cells[5].innerHTML;
					td6_HTML = td6_HTML.replace(groupID, newID);
					var td6_className = groupFirstRow.cells[5].className;
					
					// add room row
					var newRow		= table.insertRow(nextRowIndex);
					newRow.id		= newID;
					newRow.group	= groupNumber;
					
					// side image rowspan
					imgCell.rowSpan += 1;
					
					// paste HTML into new row 
					var td1 = newRow.insertCell(0);
	 				td1.innerHTML = "<img src='../../images/trans.gif'>";
	 				var td2 = newRow.insertCell(1);
	 				td2.innerHTML = td2_HTML;
	 				td2.className = td2_className;
	 			
	 				var td3 = newRow.insertCell(2);
	 				td3.innerHTML = td3_HTML;
	 				td3.className = td3_className;
	 				
	 				var td4 = newRow.insertCell(3);
	 				td4.innerHTML = td4_HTML;
	 				td4.className = td4_className;
	 				
	 				var td5 = newRow.insertCell(4);
	 				td5.innerHTML = td5_HTML;
	 				td5.className = td5_className;
	 				
	 				var td6 = newRow.insertCell(5);
	 				td6.innerHTML = td6_HTML;
	 				td6.className = td6_className;
	 				
					// set room price
			 		var TotalItemPriceInput	= document.getElementById("TotalItemPriceInput_"+newID);
					TotalItemPriceInput.value = roomPrice;
					
			 		// set infant select list id and value 
			 		var infants = document.all("inf_"+newID);
			 		infants.disabled = false;
					infants.selectedIndex = 0;
					
					// update global variables
	 				groupRowsCount[groupID] += 1;
					nextRowIndex++;	
				}
				else // remove row
				{
					var lastRowIndex = Number(nextRowIndex)-1;
					if (lastRowIndex > groupStartRowIndex)
					{
						var deletedRow	= table.deleteRow(lastRowIndex);
						if (i<Number(range)-2)	imgCell.rowSpan -= 1;
						groupRowsCount[groupID] -= 1;
						nextRowIndex--;
					}
				}
			}	
		}
	} 
	
	//////////////////////
	setGlobalTotalPrice();
	//////////////////////
	
	// set global total price 
	function setGlobalTotalPrice()
	{
		var total = 0;
		for (var x in groupRowsCount)
		{
			var rows = groupRowsCount[x];
			//alert(x+" : "+rows);
			
			var _baseID = x.substring(0,x.lastIndexOf("_")+1);
			if (rows==1)
			{
				var inputTotal = document.getElementById("TotalItemPriceInput_"+x);
				total += Number(inputTotal.value);	
			}
			else
			{
				for (var i=0;i<rows;i++)
				{
					var inputTotal = document.getElementById("TotalItemPriceInput_"+_baseID+i);
					total += Number(inputTotal.value);	
				}
			}
		}
		GlobalPriceInput.value = total;
	}
}


function setTotalPricesWithInf(groupID, selectListObj)
{	
	
	var groupFirstRow	= document.getElementById(groupID);
	var infPrice		=  Number(groupFirstRow.getAttribute("infPrice"));
	var roomPrice		=  Number(groupFirstRow.getAttribute("roomPrice"));
	var GlobalPriceInput = document.getElementById("GlobalPriceInput");
	var itemID = selectListObj.id;
	var itemID_base = itemID.replace("inf_","");
	var TotalItemPriceInput = document.getElementById("TotalItemPriceInput_"+itemID_base);
	var infNumber = Number(selectListObj.selectedIndex);
	var infTotalPrice = Number(infPrice * infNumber);
	// total for this room
	var currentRoomTotal = Number(TotalItemPriceInput.value);
	var newRoomTotal = roomPrice + infTotalPrice;
	TotalItemPriceInput.value = newRoomTotal;
	// total for all rooms
	var globalTotal = Number(GlobalPriceInput.value);
	if (!isnull(globalTotal) && globalTotal>0)
	{
		globalTotal = globalTotal - currentRoomTotal;
	}
	GlobalPriceInput.value = globalTotal + newRoomTotal;
}

// type = F		= Flights
// type = FD	= FlyAndDrive
// type = P		= Packages
function compassBooking(type,numberOfRows)
{
	// validate form
	var checkResult = false;
	switch(type.toUpperCase())
	{
		case "F":
			checkResult = validateFlightsPassengers();
			break;
		case "FD":
			checkResult = validateFlyAndDrivePassengers();
			break;
		case "S":
			checkResult = validatePackagesPassengers();
			break;
		case "P":
			checkResult = validatePackagesPassengers();
			break;
	}
	
	if(!checkResult) return;
	
	var params = ""
	switch(type.toUpperCase())
	{
		case "F":
			var passengersLists = document.all("passengersLists");
			var isSingleRow = (numberOfRows==1?true:false)
			if(isSingleRow){
				var passengerGroup = passengersLists;
				passengers = passengerGroup.selectedIndex;
				if(params!="") params+=";"
				params += (passengerGroup.PassngerType+":"+passengerGroup.value)
			}
			else{
				for (var i=0;i<passengersLists.length;i++)
				{
					var passengerGroup = passengersLists[i];
					passengers = passengerGroup.selectedIndex;
					if (passengers==0) continue;
					if(params!="") params+=";"
					params += (passengerGroup.PassngerType+":"+passengerGroup.value)
				}
			}
		
			break;
		case "FD":
			var passengerGroup = document.all("passengersLists");
			passengers = passengerGroup.selectedIndex;
			params += (passengerGroup.TemplateID+":"+passengerGroup.value)
			for(var j = 0; j < Number(passengerGroup.value); j++){
				var inf = document.all("inf_priceTemplate_"+passengerGroup.TemplateID+"_"+j);
				if(inf){
					if(j == 0) params+=":"
					else params+=","
					params += inf.value
				}
			}
			
			checkResult = validatePackagesPassengers();
			break;
		case "P":
			var cont = document.all("CompassModuleControl_Packages_RM_Container");
			var isSingleRow = (numberOfRows==1?true:false)
			
			if(isSingleRow){
				var passengerGroup = document.all("passengersLists");
				passengers = passengerGroup.selectedIndex;
				params += (passengerGroup.TemplateID+":"+passengerGroup.value)
				for(var j = 0; j < Number(passengerGroup.value); j++){
					var inf = document.all("inf_priceTemplate_"+passengerGroup.TemplateID+"_"+j);
					if(inf){
						if(j == 0) params+=":"
						else params+=","
						params += inf.value
					}
				}
			}
			else{
				var passengersLists = document.all("passengersLists");
				for (var i=0;i<passengersLists.length;i++)
				{
					var passengerGroup = passengersLists[i];
					passengers = passengerGroup.selectedIndex;
					if (passengers==0) continue;
					if(params!="") params+=";"
					params += (passengerGroup.TemplateID+":"+passengerGroup.value)
					for(var j = 0; j < Number(passengerGroup.value); j++){
						var inf = document.all("inf_priceTemplate_"+passengerGroup.TemplateID+"_"+j);
						if(inf){
							if(j == 0) params+=":"
							else params+=","
							params += inf.value
						}
					}
				}
			}
			checkResult = validatePackagesPassengers();
			break;
		case "S":
			var cont = document.all("CompassModuleControl_Packages_RM_Container");
			var isSingleRow = (numberOfRows==1?true:false)
			
			if(isSingleRow){
				var passengerGroup = document.all("passengersLists");
				passengers = passengerGroup.selectedIndex;
				params += (passengerGroup.TemplateID+":"+passengerGroup.value)
				for(var j = 0; j < Number(passengerGroup.value); j++){
					var inf = document.all("inf_priceTemplate_"+passengerGroup.TemplateID+"_"+j);
					if(inf){
						if(j == 0) params+=":"
						else params+=","
						params += inf.value
					}
				}
			}
			else{
				var passengersLists = document.all("passengersLists");
				for (var i=0;i<passengersLists.length;i++)
				{
					var passengerGroup = passengersLists[i];
					passengers = passengerGroup.selectedIndex;
					if (passengers==0) continue;
					if(params!="") params+=";"
					params += (passengerGroup.TemplateID+":"+passengerGroup.value)
					for(var j = 0; j < Number(passengerGroup.value); j++){
						var inf = document.all("inf_priceTemplate_"+passengerGroup.TemplateID+"_"+j);
						if(inf){
							if(j == 0) params+=":"
							else params+=","
							params += inf.value
						}
					}
				}
			}
			checkResult = validatePackagesPassengers();
			break;
	}
	//sergey
	//alert(params)
	//return
	document.getElementById("CompassModuleControl_inpOrderDetails").value=params
	
	
	//document.getElementById("CompassModuleControl_inpOrderDetails").value=escape(xml.xml)
	
	COMPASS_Go_To_OrderPages();
}

function validateFlightsPassengers(type)
{
	var passengersLists = document.all("passengersLists");
		
	var noPassengers = true;
	var escorted=0;
	for (var i=0;i<passengersLists.length;i++)
	{
		var passengerGroup = passengersLists[i];
		passengers = passengerGroup.selectedIndex;
		if (passengers==0) continue;
		noPassengers = false;
		
		var _adultEscortRequired = passengerGroup.getAttribute("AdultEscortRequired");
		if (_adultEscortRequired.toUpperCase()=="TRUE")
			escorted += passengers;
		else
			escorted -= passengers;
	}
	if (noPassengers) 
	{
		alert(CLDIC.COMPASS_DV_SELECT_PASSENGERS);
		return false;
	}
	if (escorted>0) 
	{
		alert(CLDIC.COMPASS_DV_INVALID_PASSENGERS);
		return false;
	}

	
	return true;
}

function validatePackagesPassengers()
{
	var passengersLists = document.all("passengersLists");
		
	var noPassengers = true;
	var escorted=0;
	for (var i=0;i<passengersLists.length;i++)
	{
		var passengerGroup = passengersLists[i];
		passengers = passengerGroup.selectedIndex;
		if (passengers==0) continue;
		noPassengers = false;
	}
	if (noPassengers) 
	{
		alert(CLDIC.COMPASS_DV_SELECT_PASSENGERS);
		return false;
	}

	
	return true;
}

// single select list
function validateFlyAndDrivePassengers()
{
	var passengersLists = document.getElementById("passengersLists");
	passengers = passengersLists.selectedIndex;
	if (passengers==0)
	{
		alert(CLDIC.COMPASS_DV_SELECT_PASSENGERS);
		return false;
	}

	
	return true;
}







function COMPASS_SR_GetAdditionalProducts(obj,ind, url,sameRowsCount){
	//alert(sameRowsCount)
	if(obj.opened){
		obj.src = (obj.src).replace("minus","plus")
		document.getElementById("CompassModuleControl_SearchResults_sr_tr3_"+ind).style.display="none"
		obj.opened = false;
	}
	else{
		if(obj.AddFlightsExist){
			obj.src = (obj.src).replace("plus","minus")
			document.getElementById("CompassModuleControl_SearchResults_sr_tr3_"+ind).style.display=""
			obj.opened = true
		}
		else{
			var url = url
			url+=("&FolderID="+obj.FolderID)
			url+=("&DestCode="+obj.DestCode)
			url+=("&OutboundDate="+obj.OutboundDate)
			url+=("&Nights="+obj.Nights)
			//url+=("&Rand="+String(Math.random()))
			url+=("&Index="+String(ind))
			url+=("&SameRowsCount="+String(sameRowsCount))
			//CopyTextIntoClipboard(url);
			
			var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
			//alert(url);
			xmlhttp.open("GET",url, false)
			xmlhttp.send()
			if(xmlhttp.status=="200"){
				CopyTextIntoClipboard(xmlhttp.responseText)
				document.getElementById("CompassModuleControl_SearchResults_sr_td3_"+ind).innerHTML = xmlhttp.responseText
				document.getElementById("CompassModuleControl_SearchResults_sr_tr3_"+ind).style.display=""
				obj.AddFlightsExist = true
				obj.src = (obj.src).replace("plus","minus")
				obj.opened = true
			}
			else{
				//alert(xmlhttp.statusText)
			}
		}
	}
}
function GetFlightReturnDateParamsFromPromotion(obj,sType)
{
	var oCalendarParams = {};
	oCalendarParams.Type = sType;	
	oCalendarParams.OutFlightID=obj.OutFlightID;			
	oCalendarParams.Takeofftime=obj.Takeofftime;			
	oCalendarParams.Fare=obj.Fare;			
	oCalendarParams.InboundDate_Start=obj.InboundDate_Start;			
	oCalendarParams.CurrencyCode=obj.CurrencyCode;	
	oCalendarParams.DestLabel=escape(obj.DestLabel);
	oCalendarParams.Nights=obj.Nights;	
	
	var oCalendarReturnParams = COMPASS_GetDateFromCalendar(oCalendarParams);
	//var oCalendarReturnParams = {}
	//oCalendarReturnParams.FlightID=122
	//oCalendarReturnParams.DepartureTime="sss"
	
	if(oCalendarReturnParams)
	{		
		//document.getElementById("CompassModuleControl_SearchResults_sr_divcalendar_"+ind).innerHTML = oCalendarReturnParams.DepartureDate + "<br>" + oCalendarReturnParams.DepartureTime
		obj.href=obj.orig_href + "&InFlightID=" + oCalendarReturnParams.FlightID + "&InTakeofftime=" + oCalendarReturnParams.DepartureTime
	}
}


function GetFlightReturnDateParams(obj,ind)
{	
	//document.getElementById("CompassModuleControl_SearchResults_sr_divcalendar_"+ind).innerHTML = obj.InboundDate_Start + "<br>" + obj.Takeofftime
	
	var oCalendarParams = {};
	oCalendarParams.Type=obj.Type;			
	oCalendarParams.OutFlightID=obj.OutFlightID;			
	oCalendarParams.Takeofftime=obj.Takeofftime;			
	oCalendarParams.Fare=obj.Fare;			
	oCalendarParams.InboundDate_Start=obj.InboundDate_Start;			
	oCalendarParams.CurrencyCode=obj.CurrencyCode;	
	oCalendarParams.DestLabel=escape(obj.DestLabel);
	oCalendarParams.Nights=obj.Nights;	
	
	
	var oCalendarReturnParams = COMPASS_GetDateFromCalendar(oCalendarParams);
	if(!oCalendarReturnParams)
	{
		
	}
	else
	{	
		document.getElementById("CompassModuleControl_SearchResults_sr_divcalendar_"+ind).innerHTML = oCalendarReturnParams.DepartureDate + "<br>" + oCalendarReturnParams.DepartureTime
		var anc = document.getElementById("CompassModuleControl_SearchResults_sr_ancsubmit_"+ind);
		anc.href = anc.orig_href + "&InFlightID=" + oCalendarReturnParams.FlightID + "&InTakeofftime=" + oCalendarReturnParams.DepartureTime
	}
}
function RequestReturnFlight(){
	alert(CLDIC.COMPASS_SR_CHOOSE_RETURN_FLIGHT)
}

function changeAction(){
	//var act = String(Form1.action)
	//Form1.action = act.substring(0,act.indexOf("&url="))
}
function COMPASS_Go_To_OrderPages(){
	OrderEnable=false;
	document.getElementById("CompassModuleControl_btnSubmit").click();
}

function COMPASS_Go_To_OrderStep2(){
	if(!COMPASS_OrderStep1_Form()) return;
		COMPASS_Go_To_OrderPages();
	
}

function COMPASS_OrderStep1_Form(){
	
	if ( document.getElementById(order_traveler_papers_Prefix + "_trRadioButtonsArea").style.display == 'none' )
	{
		document.getElementById(order_traveler_papers_Prefix + "_trRadioButtonsArea").style.display == 'inline'
	}
	if( !COMPASS_OrderStep1_AddressForm_Valid() )
	{
		//alert(CLDIC.EMPTY_DELIVERY_FIELDS);
		return false;
	}
	if( !COMPASS_OrderStep1_PassengersForm_Valid('COMPASS') )
	{
		//alert("COMPASS_OrderStep1: Passengers Form not valid.");
		return false;
	}
	
	return true;
}

function COMPASS_OrderStep1_AddressForm_Valid ()
{
	var sPrefix = order_traveler_papers_Prefix + "_";
	
	if ( document.getElementById(sPrefix + "inpRadioButtonsFlag").value	== 'false' )
	{
		alert(CLDIC.NO_DELIVERY_TYPE);
		return false;
	}
	
	var valid = true;
	if ( document.getElementById(sPrefix + "divDocsDeliveryForm").style.display == 'inline' )
	{	
		if( document.getElementById(sPrefix + "inpAddrSecondName").value == "" ) 
		{
			valid = false;
		}
		if ( document.getElementById(sPrefix + "inpAddrFirstName").value == "" )
		{
			valid = false;
		}
		if ( document.getElementById(sPrefix + "inpAddrCity").value == "" )
		{ 
			valid = false;
		}
		if ( document.getElementById(sPrefix + "inpAddrStreet").value == "" ) 
		{
			valid = false;	
		}
		if ( document.getElementById(sPrefix + "inpAddrHouseNo").value == "" )
		{ 
			valid = false;
		}
	}
	
	if( valid == false )
	{
		alert(CLDIC.EMPTY_DELIVERY_FIELDS);
	}
	
	return valid;
}

	function COMPASS_OrderStep1_PassengersForm_Valid(moduleType)
	{
		var str_fields_count	= document.getElementById(abroad_passengers_form_Prefix + "_inputNumberOfPassengers").value;
	
		var psngrs = new Array();
		psngrs     = str_fields_count.split(",");
		var i;
		var j;
		var cnt;
		var prefix;
		var psg_name;
		var psg_title;
		var age;
		var psg_birthday_yyyy;
		var psg_birthday_mm;
		var psg_birthday_dd;
		var age_range;
		var ins_value;
		var ins_count=0;
		
		for( i=0; i<psngrs.length; i++ )
		{
			cnt = CInt( psngrs[i] );
			
			for( j=0; j<cnt; j++ )
			{
				prefix = "_" + i + "_" + j;
				
				if (ins_count != -1)
				{
					try
					{
						ins_value	= document.getElementById(abroad_passengers_form_Prefix + "_inputInsuranceType" + prefix);
						ins_count   = ins_count + CInt(ins_value.value);
					}
					catch (e) 
					{
						ins_count	= -1;   // there is no insurance section in the current form
					}					
				}
				
				try{
					psg_title = document.getElementById(abroad_passengers_form_Prefix + "_inputSalutation" + prefix);
					if( (psg_title.value == "") )
					{
						alert(CLDIC.EMPTY_PASSENGER_TYPE);
						focusObj(psg_title, psg_title); 	
						return;
					}
				}
				catch(e){}
				
				psg_name = document.getElementById(abroad_passengers_form_Prefix + "_inputSecondName" + prefix);
				if( (psg_name.value == "") )
				{
					alert(CLDIC.EMPTY_LAST_NAME);
					focusObj(psg_name, psg_name); 	
					return;
				}
				
				if (moduleType != "ISRAEL")
				{
					if( (isEnAlphabet(psg_name.value) != true) )
					{
						alert(CLDIC.NO_VALID_LAST_NAME);
						focusObj(psg_name, psg_name); 	
						return;
					}
				}
				else{
					if( (isHeAlphabet(psg_name.value) != true) )
					{
						alert(CLDIC.NO_VALID_LAST_NAME_HE);
						focusObj(psg_name, psg_name); 	
						return;
					}
				}			
				
				psg_name = document.getElementById(abroad_passengers_form_Prefix + "_inputFirstName" + prefix);
				if( (psg_name.value == "") )
				{
					alert(CLDIC.EMPTY_FIRST_NAME);
					focusObj(psg_name, psg_name); 	
					return;
				}
				
				if (moduleType != "ISRAEL")
				{
					if( (isEnAlphabet(psg_name.value) != true) )
					{
						alert(CLDIC.NO_VALID_FIRST_NAME);
						focusObj(psg_name, psg_name); 						
						return;
					}
				}
				else{
					if( (isHeAlphabet(psg_name.value) != true) )
					{
						alert(CLDIC.NO_VALID_FIRST_NAME_HE);
						focusObj(psg_name, psg_name); 						
						return;
					}
				}
				
				
				psg_birthday_yyyy = document.getElementById(abroad_passengers_form_Prefix + "_inputBirthdayYear" + prefix);
				psg_birthday_mm = document.getElementById(abroad_passengers_form_Prefix + "_inputBirthdayMonth" + prefix);
				psg_birthday_dd = document.getElementById(abroad_passengers_form_Prefix + "_inputBirthdayDay" + prefix);
				
				if (!checkPassengerTypeAgeValid(psg_birthday_yyyy, prefix))
				{
					return;
				}
			}
		}
		
		if (ins_count != -1)
		{
			var _4kbox = document.getElementById(abroad_passengers_form_Prefix + "_inputClientAgree");
			if( (_4kbox.checked == false) && (ins_count!=0) )
			{
				alert(CLDIC.NO_AGREETMENT);
				return false;
			}
		}
		
		return true;
	}	
	
	function CInt(vle,dflt)
	{
		var str		= trim(vle);
		var strd	= trim(dflt);
	    
		var intg	= parseInt(str,10);
		var intd	= parseInt(strd,10);
		
			intd	= (isNaN(intd)?0:intd);
	    
		return (isNaN(intg)?intd:intg);
	}
	
	function isEnAlphabet( data )
	{
		var dt				= data;
		var vle				= trim(dt);
		if(vle=="")							return true;

		var newvle			= vle.replace(/[a-z ']*/g,"");
			newvle			= newvle.replace(/[A-Z]*/g,"");
		
		return	(newvle.length=="");
	}
	function isHeAlphabet( data )
	{
		var res = true;
		var dt				= data;
		var vle				= trim(dt);
		if(vle=="")			return true;
		for (var i=0 ; i<vle.length ; i++){
			var ch = vle.charAt(i);
			if (ch.charCodeAt(0) < 1488 || ch.charCodeAt(0) > 1514)
			{
				if(ch!="-" && ch!=" " && ch!="'"){
					res = false;
					break;
				}
			}
		}

		return res;
	}
	
	
	function isNumber(data)// +,-, 0-9.0-9
	{
		var dt				= data;
	   
		if(trim(dt).indexOf(" ")>0)				return false;
	       
		var vle				= trim(dt).replace(/ /gim,"");
	    
		if(vle=="")								return true;
	    
		return(vle.match(/^[ ]*[+-]?\d+[ ]*[\.]?([0-9]*)?$/)!=null); // number||null
	}
	
	function isDate(date) // xx/xx/xxxx
	{
		var dt				= date;
		var vle				= trim(dt);
		if(vle=="")								return false;
	    
			vle				= vle.replace(/\./gim,"/");
			vle				= vle.replace(/-/gim,"/");
		var arr				= vle.split("/");
			
		if(arr.length!=3)						return false;	
		
		var	dd				= CInt(arr[0]);
		var	mm				= CInt(arr[1]);
		var	yyyy			= CInt(arr[2]);
			
		if(dd   <1    || dd > 31)				return false;
		if(mm   <1    || mm   > 12)				return false;
		if(yyyy <1900 || yyyy > 2100)			return false;
		if(yyyy%4==0 & mm==2 & dd>29)			return false;
		if(yyyy%4!=0 & mm==2 & dd>28)			return false;
		if((mm==4||mm==6||mm==9||mm==11)&dd>30)	return false;
	    
		try{var d	= new Date(vle);}catch(e){	return false;}

        return true;
	}
	
	function isAge( age )
	{
		if ( CInt(age) < 0 )	return false;
		
		if ( CInt(age) > 120 )  return false;
		
		return true;
	}
	
	function getAge( day, month, year )
	{
	    var related_to = (document.getElementById(abroad_passengers_form_Prefix + "_inputDealStartDate")).value;
	    related_to  = related_to.substring( 0, related_to.indexOf(" ") );
    
		if( related_to.indexOf("/") != -1 )
		{
			var arr				= related_to.split("/");
					
			var	mm				= CInt(arr[0]);
			var	dd				= CInt(arr[1]);
			var	yyyy			= CInt(arr[2]);
		}
		else if ( related_to.indexOf("-") != -1 )
		{
			var arr				= related_to.split("-");
			
			var	yyyy			= CInt(arr[0]);
			var	mm				= CInt(arr[1]);
			var	dd				= CInt(arr[2]);
		}
		
		var age = yyyy - CInt(year);
		
		if ( CInt(month) > mm )
		{
			age = (age-1);
		}
		
		if ( CInt(month) == mm )
		{
			if ( CInt(day) >= dd )
			{
				age = (age-1);
			}
		}
		
		return age;
	}
	
	function checkPassengerTypeAge(obj, age, prefix)
	{
		age_range = new Array();
		age_range = (document.getElementById(abroad_passengers_form_Prefix + "_inputHAgeGroup" + prefix)).value.split(",");
				
		if( (CInt(age) < CInt(age_range[0])) || (CInt(age) > CInt(age_range[1])) )
		{
			alert(CLDIC.NO_VALID_BIRTHDAY_AND_PASSENGER_TYPE);
			focusObj(obj,obj);
			return false;
		}
		else
		{
			return true;
		}
	}
	
	function setInsuranceOptions( prefix, age, selected_value ){
		
		if( age < 0 ) 
		{
			return;
		}
		
		
		var insXML = document.getElementById(abroad_passengers_form_Prefix + "_xmlInsurancesData");
		
		if(insXML!=null && !isnull(insXML)){
			var ins_select = document.getElementById(abroad_passengers_form_Prefix + "_inputInsuranceType" + prefix);
			var xml_rows   = insXML.selectNodes("//ROW");
			var start_age;
			var end_age;
			var code;
			var curr_age = CInt(age);
			var op_text;
			var op_value;
			var op_code;
			var i;
			
			
			//remove options if exist
			try
			{
				while( ins_select.options.length != 0 )
				{
					ins_select.remove(ins_select.options[ins_select.options.length]);
				}
				
				
				//add options
				ins_select.options[ins_select.options.length] = new Option(CLDIC.NO_INSURANSE,'0');
				
				//alert(insXML.xml)
				for( i=0; i<insXML.selectNodes("//ROW").length; i++ )
				{
					start_age = CInt(xml_rows[i].getAttribute("insurancestartage"));
					end_age   = CInt(xml_rows[i].getAttribute("insuranceendage"));
					
					if( (curr_age >= start_age) && (curr_age <= end_age) )
					{
						op_text  = xml_rows[i].getAttribute("insurancetitle");
						op_value = xml_rows[i].getAttribute("insurance_code");
						op_code = xml_rows[i].getAttribute("insurancetype");
						
						ins_select.options[ins_select.options.length] = new Option(op_text, op_value);
						if( (selected_value != "") && (selected_value == op_value) )
						{
							ins_select.options[ins_select.options.length-1].selected = true;
						}
						else{
							if(op_code == "REGULAR"){
								ins_select.options[ins_select.options.length-1].selected = true;
								saveParameters(ins_select)
							}
						}
					}
				}
			}
			catch(e)
			{
				//alert(e.description);
			}
		}
		else{
			//alert("empty insurances xml data");
		}
	}
	
	function saveParameters (obj)
	{
		var sCurrentId	= obj.id;

		var tmp = sCurrentId.substring(0, sCurrentId.lastIndexOf("_"));

		var seq_prefix	= sCurrentId.substring(tmp.lastIndexOf("_"), sCurrentId.length);

		var type_prefix	= sCurrentId.substring(0, tmp.lastIndexOf("_"));

		var type	= type_prefix.substring(type_prefix.lastIndexOf("_")+1, type_prefix.length);
		
		var control_prefix = type_prefix.substring(0, type_prefix.lastIndexOf("_"));
		
		var lable_val	= document.getElementById(control_prefix + "_inpSelectedInsuranceLable" + seq_prefix);
		var code_val	= document.getElementById(control_prefix + "_inpSelectedInsuranceCode" + seq_prefix);

		
		lable_val.value = obj.options[obj.options.selectedIndex].text;
		code_val		= obj.options[obj.options.selectedIndex].text;
	}
	
	function checkDates4Assurance(obj)
	{
		//field id
		var sCurrentId	= obj.id;
		
		var tmp = sCurrentId.substring(0, sCurrentId.lastIndexOf("_"));
				
		// dinamic sequence prefix
		var seq_prefix	= sCurrentId.substring(tmp.lastIndexOf("_"), sCurrentId.length);
		
		var myAge	=	checkBirthDate(obj);
		if ((myAge > -1) && (checkPassengerTypeAgeValid(obj,"")))
		{
			//ALL IS OK.
			setInsuranceOptions( seq_prefix, myAge, "" );
		}
		else
		{
			return false;
		}
	}
	
	function checkPassengerTypeAgeValid(obj, prefix)
	{
		//field id
		var sCurrentId	= obj.id;
				
		var myAge	=	checkBirthDate(obj);
				
		if (myAge >= 0)
		{
			if (prefix == "")		// we have to find it.
			{
				var tmp = sCurrentId.substring(0, sCurrentId.lastIndexOf("_"));
				prefix	= sCurrentId.substring(tmp.lastIndexOf("_"), sCurrentId.length);
			}
			
			return checkPassengerTypeAge(obj,  myAge, prefix );			
		}
		else
		{
			return false;
		}
	}
	
	// checks if input Date is a valid birth date & computes the passenger age relating to the deal start date.
	// returns:
	// if valid = the age of the passenger related to the deal start date.
	// if not valid = -1
	// if not all the fields are full yet = -2.
	function checkBirthDate(obj)
	{
		//field id
		var sCurrentId	= obj.id;
		
		var tmp = sCurrentId.substring(0, sCurrentId.lastIndexOf("_"));
		
		// dinamic sequence prefix
		var seq_prefix	= sCurrentId.substring(tmp.lastIndexOf("_"), sCurrentId.length);
		
		// field full name
		var type_prefix	= sCurrentId.substring(0, tmp.lastIndexOf("_"));
		
		//field type ( part of it's name )
		var type	= type_prefix.substring(type_prefix.lastIndexOf("_")+1, type_prefix.length);
		
		var control_prefix = type_prefix.substring(0, type_prefix.lastIndexOf("_"));
		
		// get row year id
		var y_val	= document.getElementById(control_prefix + "_inputBirthdayYear" + seq_prefix).value;
		
		// get row month id
		var m_val	= document.getElementById(control_prefix + "_inputBirthdayMonth" + seq_prefix).value;
		
		// get row day id
		var d_val	= document.getElementById(control_prefix + "_inputBirthdayDay" + seq_prefix).value;
		
		// validation variable
		var valid	= false;
		var field;
				
		// if year : check year OK
		if ( type == "inputBirthdayYear" )
		{
			valid = isDate("10/10/" + y_val);
			field = "year";
		}
		// if month : check month ok (1--12)
		if ( type == "inputBirthdayMonth" )
		{
			valid = isDate("10/" + m_val + "/2000");
			field = "month";
		}
		// if day :  check month ok (1--12)
		if ( type == "inputBirthdayDay" )
		{
			valid = isDate(d_val + "/10/2000");
			filed = "day";
		}
		
		// if not ok
		if ( valid == false )
		{
			alert(CLDIC.NO_VALID_BIRTHDAY);
			focusObj(this,obj);
			return -1;
		}
		
		// check the date 

		if ( (trim(d_val)!="") && (trim(m_val)!="") && (trim(y_val)!="") )
		{
			if ( isDate(d_val + "/" + m_val + "/" + y_val)!= true )
			{
				alert(CLDIC.NO_VALID_BIRTHDAY);
				return -1;
			}
		}
		else return -2;			// not all fields are full yet.
		
		// what is the age in years 
		var myAge = getAge( d_val, m_val, y_val );
		if( isAge(myAge) == false )
		{
			alert(CLDIC.NO_VALID_BIRTHDAY);
			return -1;
		}	
					
		return myAge;	
	}
	
	function checkNameField(obj, checkEnglish)
	{
		//field id
		var sCurrentId	= obj.id;
		var value		= obj.value;
		
		var tmp = sCurrentId.substring(0, sCurrentId.lastIndexOf("_"));

		var seq_prefix	= sCurrentId.substring(tmp.lastIndexOf("_"), sCurrentId.length);

		var type_prefix	= sCurrentId.substring(0, tmp.lastIndexOf("_"));

		var type	= type_prefix.substring(type_prefix.lastIndexOf("_")+1, type_prefix.length);
		
		var control_prefix = type_prefix.substring(0, type_prefix.lastIndexOf("_"));
		
		var field_type;
		
		if (checkEnglish != "false")
		{
			if ( isEnAlphabet( value ) == false ) 
			{
				if( type=="inputSecondName" )
				{
					//field_type  = "Last Name";
					alert(CLDIC.NO_VALID_LAST_NAME);
				}
				if( type=="inputFirstName" )
				{
					//field_type  = "First Name";
					alert(CLDIC.NO_VALID_FIRST_NAME);
				}

				focusObj(this, obj); 	
				return;
			}	
		}		
	}

/********* Submit Functions ****************/

var OrderEnable = true;


function SIMPLE_ABROAD_Go_To_OrderConfirmStep(){
	if(!OrderEnable) return;

	var obj = document.getElementById(order_traveler_papers_Prefix + "_trRadioButtonsArea");
	if(obj){
		if(obj.style.display=='none') obj.style.display=='inline';
		if(!COMPASS_OrderStep1_AddressForm_Valid()) return;
	}
	if(!COMPASS_OrderStep2_Payment()) return;
	if(!CheckIfConfirmTermsApproved()) return;
	
	COMPASS_Go_To_OrderPages();
	
}

function COMPASS_Go_To_OrderConfirmStep(){
	if(!OrderEnable) return;
	if(!COMPASS_OrderStep2_Form()) return;
	COMPASS_Go_To_OrderPages();
	
}
function COMPASS_OrderStep2_Form(){
	//alert("COMPASS_OrderStep2");
	if( !COMPASS_OrderStep2_Payment() ) return false;
	if( !CheckIfConfirmTermsApproved())	return false;
	
	return true;
}

function COMPASS_OrderStep2_Payment()
{
	var prefix			= payment_form_Prefix + "_";
	var select_field	= document.getElementById(prefix + "selectCardType");
	if ( select_field.options.selectedIndex == 0 )
	{
		alert(CLDIC.PAYMENT_EMPTY_CREDIT_CARD_TYPE);
		setFocus(select_field);
		return false;
	}
	var input_field 	= document.getElementById(prefix + "inputCardNumber");
	if ( trim(input_field.value) == "" )
	{
		alert(CLDIC.PAYMENT_EMPTY_CREDIT_CARD_NUMBER);
		setFocus(input_field);
		return false;
	}
	if( (trim(input_field.value)).length == 16 )
	{
		// set value 1 to input hidden field for secure number check
		input_field = document.getElementById(prefix + "inputHSecurityNumberMustFlag");
		input_field.value = 1;
	}
	
	input_field  = document.getElementById(prefix + "inputHSecurityNumberMustFlag");
	if( input_field.value == 1 )
	{
		input_field  = document.getElementById(prefix + "inputCardSecurityNumber");
		if( trim(input_field.value) == "" )
		{
			alert(CLDIC.PAYMENT_EMPTY_CREDIT_CARD_SECURITY_NUMBER);
			setFocus(input_field);
			return false;
		}
	}
	
	select_field	= document.getElementById(prefix + "selectCardExpirationMonth");
	var select_field1	= document.getElementById(prefix + "selectCardExpirationYear");
	if ( (select_field.options.selectedIndex == 0) || (select_field1.options.selectedIndex == 0) )
	{
		alert(CLDIC.PAYMENT_EMPTY_CREDIT_CARD_EXPIRATION);
		setFocus(select_field);
		return false;
	}
	var date = new Date();
	var c_year = CInt(date.getYear());
	var c_month = CInt( date.getMonth() + 1 );
	var i_year = CInt( select_field1.value );
	var i_month = CInt( select_field.value );
	if( (c_year == i_year) && (i_month<c_month) )
	{
		alert(CLDIC.PAYMENT_WRONG_CREDIT_CARD_EXPIRATION);
		setFocus(select_field);
		return false;
	}
	
	select_field	= document.getElementById(prefix + "selectPayments");
	if ( select_field.options.selectedIndex == 0 )
	{
		alert(CLDIC.PAYMENT_NO_PAYMENT_TYPE_SELECTED);
		setFocus(select_field);
		return false;
	}
	
	input_field	= document.getElementById(prefix + "inputLastName");
	if ( trim(input_field.value) == "" )
	{
		alert(CLDIC.PAYMENT_EMPTY_LAST_NAME);
		setFocus(input_field);
		return false;
	}
	
	input_field	= document.getElementById(prefix + "inputFirstName");
	if ( trim(input_field.value) == "" )
	{
		alert(CLDIC.PAYMENT_EMPTY_FIRST_NAME);
		setFocus(input_field);
		return false;
	}
	
	input_field	= document.getElementById(prefix + "inputPassportNumber");
	if ( trim(input_field.value) == "" )
	{
		alert(CLDIC.PAYMENT_EMPTY_PASSPORT_NUMBER);
		setFocus(input_field);
		return false;
	}
	else{
	
		if(input_field.value.length < 9){
			
			input_field.value = String(1000000000 + Number(input_field.value)).replace("1","")
		}
	}
	if ( !isId(input_field.value) )
	{
		alert(CLDIC.PAYMENT_WRONG_PASSPORT_NUMBER);
		setFocus(input_field);
		return false;
	}
	
	input_field	= document.getElementById(prefix + "inputCity");
	if ( trim(input_field.value) == "" )
	{
		alert(CLDIC.PAYMENT_EMPTY_CITY);
		setFocus(input_field);
		return false;
	}
	
	input_field	= document.getElementById(prefix + "inputStreet");
	if ( trim(input_field.value) == "" )
	{
		alert(CLDIC.PAYMENT_EMPTY_STREET);
		setFocus(input_field);
		return false;
	}
	
	input_field	= document.getElementById(prefix + "inputHouse");
	if ( trim(input_field.value) == "" )
	{
		alert(CLDIC.PAYMENT_EMPTY_HOUSE);
		setFocus(input_field);
		return false;
	}
	
	input_field	= document.getElementById(prefix + "inputZipCode");
	if ( !isZipCode(input_field.value) )
	{
		alert(CLDIC.PAYMENT_WRONG_ZIP_CODE);
		setFocus(input_field);
		return false;
	}
	
	input_field	= document.getElementById(prefix + "inputPhoneAtHome");
	select_field	= document.getElementById(prefix + "selectPhoneAtHome");
	if ( (trim(input_field.value) == "") && (select_field.options.selectedIndex == 0) )
	{
		alert(CLDIC.PAYMENT_EMPTY_PHONE);
		setFocus(input_field);
		return false;
	}
	if ( !isPhone( (input_field.value) + (select_field.options[select_field.options.selectedIndex].text) ) )
	{
		alert(CLDIC.PAYMENT_WRONG_PHONE);
		setFocus(input_field);
		return false;
	}
	
	input_field	= document.getElementById(prefix + "inputPhoneAtWork");
	select_field	= document.getElementById(prefix + "selectPhoneAtWork");
	if ( !isPhone((input_field.value) + (select_field.options[select_field.options.selectedIndex].text)) && 
		 ((input_field.value != "" ) || (select_field.options.selectedIndex != 0)) )
	{
		alert(CLDIC.PAYMENT_WRONG_PHONE);
		setFocus(input_field);
		return false;
	}
	
	input_field	= document.getElementById(prefix + "inputCellularPhone");
	select_field	= document.getElementById(prefix + "selectCellularPhone");
	if ( !isPhone( (input_field.value) + (select_field.options[select_field.options.selectedIndex].text) ) && 
		 ((input_field.value != "" ) || (select_field.options.selectedIndex != 0)) )
	{
		alert(CLDIC.PAYMENT_WRONG_CELLULAR_PHONE);
		setFocus(input_field);
		return false;
	}
	
	input_field	= document.getElementById(prefix + "inputEmail");
	if ( trim(input_field.value) == "" )
	{
		alert(CLDIC.PAYMENT_EMPTY_EMAIL);
		setFocus(input_field);
		return false;
	}
	if ( !isEMail(input_field.value) )
	{
		alert(CLDIC.PAYMENT_WRONG_EMAIL);
		setFocus(input_field);
		return false;
	}
	
	input_field	= document.getElementById(prefix + "inputFax");
	select_field	= document.getElementById(prefix + "selectFax");
	if ( !isPhone( (input_field.value) + (select_field.options[select_field.options.selectedIndex].text) ) && 
		 ((input_field.value != "" ) || (select_field.options.selectedIndex != 0)) )
	{
		alert(CLDIC.PAYMENT_WRONG_FAX);
		setFocus(input_field);
		return false;
	}
	return true;
}

function isEMail(dt)
{
    var vle				= trim(dt);
	
	if(vle=="")	return true;
	
	var re1				= /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	var re2				= /^[\w-]+@[\w-]+\.([a-zA-Z]+|[a-zA-Z]+\.[a-zA-Z]+)$/;
	
	return (vle.match(re1)!=null);
}

function isPhone(dt)
{
    var vle				= trim(dt);
   
    if(vle=="")							return true;
    if(vle.length<=3)					return false;
	
	if(vle.replace(/[0-9 -]*/g,"")=="") return true;
	                                    return false;
}

function isZipCode(dt)
{
    var vle				= trim(dt);
    
    if(vle=="")							return true;

	return (vle.match(/^\d{5}$/)!=null);
}

function isId(dt)
{
    	var vle				= trim(dt);
   
        if(vle=="")			return true;
        return				checkIdNum(vle);
}

function checkIdNum(idnum)
{
    while(idnum.length<9){idnum="0"+idnum;}
    
    var re = /^\d{9}$/
    if(!re.test(idnum)){
		return false
    }
    
    if(idnum == "000000000") return false;

    var idnum1				= idnum.substr(0,1)*1;
    var idnum2				= idnum.substr(1,1)*2;
    var idnum3				= idnum.substr(2,1)*1;
    var idnum4				= idnum.substr(3,1)*2;
    var idnum5				= idnum.substr(4,1)*1;
    var idnum6				= idnum.substr(5,1)*2;
    var idnum7				= idnum.substr(6,1)*1;
    var idnum8				= idnum.substr(7,1)*2;
    var idnum9				= idnum.substr(8,1)*1;

    if (idnum1>9) idnum1	= (idnum1%10) + 1;
    if (idnum2>9) idnum2	= (idnum2%10) + 1;
    if (idnum3>9) idnum3	= (idnum3%10) + 1;
    if (idnum4>9) idnum4	= (idnum4%10) + 1;
    if (idnum5>9) idnum5	= (idnum5%10) + 1;
    if (idnum6>9) idnum6	= (idnum6%10) + 1;
    if (idnum7>9) idnum7	= (idnum7%10) + 1;
    if (idnum8>9) idnum8	= (idnum8%10) + 1;
    if (idnum9>9) idnum9	= (idnum9%10) + 1;

    var sumval				= idnum1+idnum2+idnum3+idnum4+idnum5+idnum6+idnum7+idnum8+idnum9;
    sumval					= sumval%10;
    
   // return false
		
		
    if(sumval>0)			return false;
    else					return true;
}

/* Some date function - START */

//get date as dd/MM/yy
//return date object
function D_GetDateObj(sValue)
{
	// eliran, 2008.08.31 - i've changed the order of the lines so the day in the month will be set first.
	var arr = sValue.split("/");	
	var d = new Date();		
	d.setDate(arr[0]);
	d.setMonth(arr[1]-1);	
	d.setFullYear("20" + arr[2]);
	//alert(d);
	return d;
	
}

//get date object
//return dd/MM/yy
function D_GetDateString(dDate)
{
	return dDate.getDate() + "/" + (dDate.getMonth()+1) + "/" + dDate.getFullYear().toString().substring(2);
}

//get today date as dd/MM/yy
function D_GetTodayDateString()
{
	var dDate = new Date();
	
	return dDate.getDate() + "/" + (dDate.getMonth() + 1) +"/" + dDate.getFullYear().toString().substring(2);
}

//get sFromDate & sToDate as string
//return days diff
function D_GetDaysDiff(sFromDate, sToDate)
{
	var arr = sFromDate.split("/");
	var dFrom = D_GetDateObj(sFromDate);
	var dTo = D_GetDateObj(sToDate);
	return Math.round((dTo-dFrom)/1000/60/60/24);
}

//get date object & number of days
//return string as D_GetDateString returned value (dd/MM/yy)
function D_AddDaysToDateObj(dDate, iDays)
{
	//alert("D_AddDaysToDateObj : dDate : " + dDate)
	//alert("D_AddDaysToDateObj : iDays : " + iDays)	
	dDate.setDate(Number(dDate.getDate()) + (iDays * 1));				
	//alert("D_AddDaysToDateObj : dDate : " + dDate)
	return D_GetDateString(dDate);	
}

//get date as dd/MM/yy & number of days
//return D_AddDaysToDateObj returned value (dd/MM/yy)
function D_AddDaysToDateString(sDate, iDays)
{
	//alert("D_AddDaysToDateString : sDate : " + sDate)
	//alert("D_AddDaysToDateString : iDays : " + iDays)
	var dDate = D_GetDateObj(sDate);	
	//alert("D_AddDaysToDateString : dDate : " + dDate)
	return D_AddDaysToDateObj(dDate, iDays);
}

/* Some date function - END */








// action = 0 = hide
// action = 1 = display
function preloader(action)
{
	if (isnull(action)) action = 1;
	var p = document.getElementById("preloader");
	p.style.display = (action==1)?"inline":"none";
	
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
// israel hotels
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
israelSortBy.counter	= 0;
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function israelSortBy(o)
{
	if(document.getElementById("israelABC").checked)
	{
		xmlBubbleSort(xmldso.documentElement, 'name', 'product', 'string');	
		xmlBubbleSort(xmldso.documentElement, 'name', 'product', 'string');	
	}
	else if(document.getElementById("israelPrice").checked)
	{
		xmlBubbleSort(xmldso.documentElement, 'priceTotal', 'product', 'float');
		xmlBubbleSort(xmldso.documentElement, 'priceTotal', 'product', 'float');
	}
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function ahSortBy(o)
{
	var currentUrl					= document.getElementById("CompassModuleControl_ahCurrentUrl").value;

	if(document.getElementById("CompassModuleControl_ahABCButton").checked)
	{
		window.location.href		= currentUrl+"&orderby=abc&first=1";
	}
	else
	{
		window.location.href		= currentUrl+"&orderby=price&first=1";
	}
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function sapCalc(select)
{
	var all					= window.document.all;
	var radio				= window.document.getElementsByTagName("INPUT");
	var sapSumOne			= window.document.all.sapSumOne;
	var sapSum				= window.document.all.CompassModuleControl_ucOrderAddition_sapSum;
		
	sapSum.innerText		= CFloat(sapSumOne.innerText, 0)*CInt(select.value, 0);
	
	for(var j=0; j<radio.length; j++)
	{
		if(radio[j].type!="radio")	continue;
		if(!radio[j].checked)		continue;
		
		sapSum.innerText	=  CFloat(sapSum.innerText) + CFloat(all[radio[j].value+"_price"].innerText, 0);
	}
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function sapChangeCount(o)
{
	var all					= window.document.all;
	
	var ea = false

	for(var j=1; j<=CInt(o.value); ++j)
	{
		var ao = all["CompassModuleControl_ucOrderAddition_sapTbl_"+j]
		if(ao){
		
			block(ao);
			
			ea = true;
		}
	}
	if(ea){
		for(var j=o.length; j>CInt(o.value); --j)
		{
			all["CompassModuleControl_ucOrderAddition_sapRadio_"+j+"_0"].checked	= true;		
		
			none(all["CompassModuleControl_ucOrderAddition_sapTbl_"+j]);
		} 
	}
	
	sapCalc(o);
}


//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function sapClickRadio(o)
{
//	dbg(window.document.all[o.value+"_price"]);
	
	sapCalc(window.document.all.CompassModuleControl_ucOrderAddition_sapLookup);
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function moreAbroadHotelDetailes(id, source, catid, sid, destination_code, contract,contract_IncomingOffice, incoming_contract, check_in_date, check_out_date, board_type_code, room_data,room_data_with_ch,availToken)
{
	var url							= "../TemplatesInPopup/AbroadHotelDetails.aspx";
		url						   += "?id="+id;
		url						   += "&source="+source;
		url						   += "&catId="+catid;
		url						   += "&sId="+sid;
		
	if(!isnull(destination_code)) url+="&destination_code=" + destination_code
	if(!isnull(contract)) url+="&contract=" + contract
	if(!isnull(contract_IncomingOffice)) url+="&contract_IncomingOffice=" + contract_IncomingOffice
	if(!isnull(incoming_contract)) url+="&incoming_contract=" + incoming_contract
	if(!isnull(check_in_date)) url+="&check_in_date=" + check_in_date
	if(!isnull(check_out_date)) url+="&check_out_date=" + check_out_date
	if(!isnull(board_type_code)) url+="&board_type_code=" + board_type_code
	if(!isnull(room_data)) url+="&room_data=" + room_data
	if(!isnull(room_data_with_ch)) url+="&room_data_with_ch=" + room_data_with_ch
	if(!isnull(availToken)) url+="&availToken=" + availToken.replace(/\+/g,"~!@");
	
	
	
			
	openPopUpWindow(url, 635, 555, "no", "no");
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function ahOrderSubmit(hotelCode, bbCode)
{
	var all							= window.document.all;

	all.ahHotelCodeSelected.value	= hotelCode;
	all.ahBBCodeSelected.value		= bbCode;

	Form1.submit();
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function ahdCollapsing(id)
{
	var all							= window.document.all;
	var img							= id+"Img";
	
	blocknone(all[id]);
	imageOnOff(all[img]);
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function ahdOpenImage(o)
{
	var win	=	window.open(o.src, "newwin");
}

function ahdOpenWindowByAttribute(o, attr)
{
	var win =	window.open(o.getAttribute(attr), "newwin");
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

function ElementDimensions(obj){
	
      this.objOffLeft=0;
      
      this.objOffTop=0;
      
      this.objOffWidth=0;
      
      this.objOffHeight=0;

      this.objOffWidth=obj.offsetWidth;

      this.objOffHeight=obj.offsetHeight;

      this.objOffLeft=obj.offsetLeft;

      this.objOffTop=obj.offsetTop;

      var objPar=obj.offsetParent;

      while(objPar){

            obj=objPar;

            this.objOffLeft+=obj.offsetLeft;

            this.objOffTop+=obj.offsetTop;

            objPar=obj.offsetParent;

      }


}

var openedHotelDiv = null;
function showMore(id,srcID)
{
	var div					= window.document.all[id];
	var src					= window.document.all[srcID];
	
	src = new ElementDimensions(src)
	
	if(div) 
	{
		if(openedHotelDiv != null) hideMore(openedHotelDiv)
		
		div.style.display	= "";
		div.style.left = src.objOffLeft + src.objOffWidth - div.offsetWidth
		div.style.top = src.objOffTop + src.objOffHeight
		openedHotelDiv = div
	}
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function hideMore(o)
{
		o.style.display		= "none";
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


function OpenGeneralPopup(docid){
	var sURL = CLVAR.GENERAL_POPUP_URL.replace("%1",docid)
	var POPUP_H = 510
	var POPUP_W = 460
	//var res = ShowModalDialog(sURL, self, 510, 460); 
	//window.open(url,null,'height=' + height + ',width=' + width + ',menubar=no,status=yes,scrollbars=' + scroll + ',resizable=' + resizable);
	var top=window.screen.availHeight/2-POPUP_H/2
	var left=window.screen.availWidth/2-POPUP_W/2
	window.open(sURL,null,'top=' + top + ',left=' + left + ',height=' + POPUP_H + ',width=' + POPUP_W + ',menubar=no,status=yes,scrollbars=yes,resizable=yes');
}

/**********************************************************/
/*  Israel Functions									  */
/**********************************************************/
function ISRAEL_Go_To_OrderConfirmStep()
{
	if(!OrderEnable) return;
	if(!ISRAEL_OrderStep1_Form()) return;
	COMPASS_Go_To_OrderPages();	
}

function ISRAEL_OrderStep1_Form()
{
	if( !COMPASS_OrderStep1_PassengersForm_Valid('ISRAEL') )
	{
		return false;
	}
	
	if( !COMPASS_OrderStep1_AddressForm_Valid() )
	{
		return false;
	}
	if( !COMPASS_OrderStep2_Payment() )
	{
		return false;
	}
	if( !CheckIfConfirmTermsApproved() )
	{
		return false;
	}
	
	return true;	
}

function COMPASS_OrderStep2_OrderRules()
{
	var prefix = "";
	var field	= document.getElementById(prefix + "inpOrderRules");
	if ( field.checked == false )
	{
		alert(CLDIC.NO_ORDER_RULES_AGREEMENT);
		return false;
	}
}

function CheckIfConfirmTermsApproved()
{
	var prefix = OrderConfirmationBoxes_Prefix + "_";
	var field	= document.getElementById(prefix + "chkConfirmSiteTerms");
	if ( field.checked == false )
	{
		alert(CLDIC.NO_ORDER_RULES_AGREEMENT);
		return false;
	}
			
	return true;
}

function setFocus(obj)
{
	try
	{
		obj.focus(); 
	}
	catch (e)
	{}
}

function focusObj(objFocus, objSelect)
{
	try
	{
		objFocus.focus();
		objSelect.select();
	}
	catch(e)
	{}
}

function forwardDatesFocus(obj){
	if(obj.value.length != 2) return
	var objid = obj["id"]
	var nextid = ""
	if(objid.indexOf("inputBirthdayDay") > -1){
		nextid = objid.replace("inputBirthdayDay","inputBirthdayMonth")
		document.getElementById(nextid).focus()
	}
	else{
		if(objid.indexOf("inputBirthdayMonth") > -1){
			nextid = objid.replace("inputBirthdayMonth","inputBirthdayYear")
			document.getElementById(nextid).focus()
		}
	}
	//dbg(obj)
	
	//inputBirthdayMonth
}
function OpenMailingListWindow(bChechForValidEmail,initEmailInputId)
{
	//var _FrameWorkPrefix = "ucSide_";
	
	//var sEMail = document.all(_FrameWorkPrefix + "InitEmailInput").value;
	var sEMail = document.getElementById(initEmailInputId).value;
	
	if(bChechForValidEmail)
	{
		if(!mailing_validEmail(sEMail))
		{
			alert(CLDIC.MAILINGLISTREGIST_ERR_NOTVALIDEMAIL);
			//document.all(_FrameWorkPrefix + "InitEmailInput").focus();
			document.getElementById(initEmailInputId).focus();
			return false;
		}
	}
	else
	{
		sEMail = "";
	}

	var iWidth = 330;
	var iHeight = 450;
	var iTop = (screen.availHeight - iHeight) / 2;
	var iLeft = (screen.availWidth - iWidth) / 2;
	 
	var oWindow = window.open(CLVAR.MAILING_REGISTRATION_URL + "?Email=" + sEMail, 'MailingListRegist_openWindow', 'top=' + iTop + ',left=' + iLeft + ',width=' + iWidth + ',height=' + iHeight + ',toolbar=no');
	oWindow.focus();
	
	return true;
}

var arrNotValidEMailChars = ["/",":",";"," ","^","$","(",")","[","]","{","}","+","=","|","\\","*","~","`","'","#","!",",","?"];
function mailing_validEmail(strValue)
{
	var strValue = new String (strValue);
	
	// check if '@' is exist
	arrValue = strValue.split("@");
		
	if (arrValue.length != 2)
	{
		return false;
	}
	
	var strLeftSection = arrValue[0];
	var strRightSection = arrValue[1];
	
	if (strLeftSection == "")
	{
		return false;
	}	
			
	if (strRightSection == "")
	{
		return false;	
	}
	
	// check if there is one dot or two dots in the second section
	arrRightSection = strRightSection.split(".");
	if (arrRightSection.length != 2 && arrRightSection.length != 3)
	{
		return false;	
	}	
			
	// check there 	are no two dots one beside other
	for (var i=0 ; i<arrRightSection.length ; i++)
	{
		if (arrRightSection[i] == "")
		{
			return false;
		}
	}
	
	// check all chars are valid
	for (var i=0 ; i<arrNotValidEMailChars.length ; i++)
	{
		if (strValue.indexOf(arrNotValidEMailChars[i]) > -1)
		{
			return false;
		}
	}		
	
	if (strValue.indexOf('"') > -1)
	{
		return false;
	}
	
	for (var i=0 ; i<strValue.length ; i++)
	{
		// 1488 = 'à', 1514 = 'ú', 
		
		var ch = strValue.charAt(i);
		if (ch.charCodeAt(0) >= 1488 && ch.charCodeAt(0) <= 1514)
		{
			return false
		}
	}
	
	return true;	
}
