function Set_Cookie( name, value, expires, path, domain, secure )
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain )
{
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

// this function gets the cookie, if it exists
function Get_Cookie( name )
{
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
	return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function checkEmail(str) {
///// function for validating email address
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)

		if (str.indexOf(at)==-1){
		    return false
		} else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		    return false
		} else 	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		} else  if (str.indexOf(at,(lat+1))!=-1){
		    return false
		} else 	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   return false
		} else  if (str.indexOf(dot,(lat+2))==-1){
		    return false
		} else if (str.indexOf(" ")!=-1){
		     return false
		} else {
 		 	return true
 		}
}

function checkMultipleEmail(emails, split_char)
{
	emails_array = emails.split(split_char);
	checkStatus = true;
	for (e in emails_array)
	{
		if (trim(emails_array[e]) != "" && !checkEmail(trim(emails_array[e])))
			checkStatus =false;
	}
	return checkStatus;
}

function checkML(emailValue)
{
	if(!checkEmail(emailValue))
	{
		alert (_tpl_emailNotValid);
		document.joinML.focus();
		return false;
	} else {
		var url = "xmlJoinML.php?joinML_email="+emailValue+"&siteLang="+siteLang;
		var xml = LoadXML(url);
		if(xml != null)
		{
			var message = xml.getElementsByTagName('rsp')[0].firstChild.data;
			alert(message);
			var response = xml.getElementsByTagName('rsp_stat')[0].firstChild.data;
			if (response)
				document.joinML.reset();
			else
				document.joinML.focus();
		}
		return false;
	}
}

function getHTTPObject()
{
	try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
	try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
	try { return new XMLHttpRequest(); } catch(e) {}
	alert("XMLHttpRequest not supported");
	return null;
 }

function LoadHTML(url)
{

	var xmlHttp = getHTTPObject();
	xmlHttp.open("GET",url, false);
	xmlHttp.onreadystatechange = function()
	{
		   if (xmlHttp.readyState != 4)  { return; }
		   var serverResponse = xmlHttp.responseText;

	}
	xmlHttp.send(null);
	return xmlHttp.responseText;
}

function LoadXML(url)
{
	var xmlHttp = getHTTPObject();
	xmlHttp.open("GET",url, false);
	xmlHttp.onreadystatechange = function()
	{
		   if (xmlHttp.readyState != 4)  { return; }
		   var serverResponse = xmlHttp.responseText;
	};
	xmlHttp.send(null);
	return xmlHttp.responseXML.documentElement;
}

// bulid string with the form values, fobj the form object, valFunc is validate function
function getFormValues(fobj)
{
   var str = "";
   var valueArr = null;
   var val = "";
   var cmd = "";

   for(var i = 0;i < fobj.elements.length;i++)
   {
       switch(fobj.elements[i].type)
       {
      	case "text":
           case "hidden":
           case "textarea":
           	str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
           break;

           case "radio":
           case "checkbox":
               if(fobj.elements[i].checked)
               		str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
           break;

           case "select-one":
                str += fobj.elements[i].name + "=" + fobj.elements[i].options[fobj.elements[i].selectedIndex].value + "&";
           break;
       }
   }

   str = str.substr(0,(str.length - 1));
   return str;
}

// validate is got the validate function, if false then skip the validation
function submitAjaxForm(f,url)
{
   var str = getFormValues(f);
   xmlReq = postAjaxForm(url ,str);

 }

 function postAjaxForm(url,str)
{
   var doc = null
   if (typeof window.ActiveXObject != 'undefined' )
   {
       doc = new ActiveXObject("Microsoft.XMLHTTP");

   }
   else
   {
       doc = new XMLHttpRequest();
       doc.onload = displayState;
   }

   doc.open( "POST", url, true );
   doc.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
   doc.send(str);
   return doc.responseXML.documentElement;
}

function showMessage(message, elementID)
{
	document.getElementById(elementID).innerText=message;
}

function clearMessage(elementID)
{
	document.getElementById(elementID).innerText="";
}


function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;


   for (i = 0; i < sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }
   return IsNumber;
 }

function trim(strText) {
/// TRIM STRING FUNCTION
    // this will get rid of leading spaces
    while (strText.substring(0,1) == ' ')
        strText = strText.substring(1, strText.length);
    // this will get rid of trailing spaces
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);
   return strText;
}

function escapeString(sString)
{
// DETECT WHAT TO PUT STRING IN FOR HTML FORM ( ' OR " ) DEPANDING ON STRING CONTENTS
	if (sString.indexOf("'") == -1)
		valSep = "'";
	else
		valSep = '"';
	return valSep+sString+valSep;
}

function replaceSubstring(inputString, fromString, toString) {
 // GOES THROUGH THE INPUTSTRING AND REPLACES EVERY OCCURRENCE OF FROMSTRING WITH TOSTRING
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
}

function popupWin(popUrl, width, height)
{
	if (!navigator.appName.indexOf("Microsoft")) width+=20;
	height+=5;
	topVar=((screen.height / 2)-(height/2));
	leftVar=((screen.width / 2)-(width/2));
	window.open(popUrl, "PopUp", "height="+height+", width="+width+", top="+topVar+", left="+leftVar+", scrollbars=yes, status=no, location=no, resize=yes, menubar=no, titlebar=no, toolbar=no");
}

function switchElementDisplay(elementID){
// SWITCH SELECTED ELEMENT DISPLAY: NONE/INLINE
	if (document.getElementById(elementID).style.display=="none")
		document.getElementById(elementID).style.display="inline";
	else
		document.getElementById(elementID).style.display="none";
}

function ShowDiv(elementID, show)
{
	var div_elem = document.getElementById(elementID);
	if(show == "")
	{
		if(div_elem.style.display == "block")
			div_elem.style.display = "none";
		else
			div_elem.style.display = "block";
	}
	else
		div_elem.style.display = show;
}

function submit_joinML(email_field){
	if (email_field.value==""){
	 	alert (_joinML_empty);
	 	email_field.focus();
	} else if (!checkEmail(email_field.value)){
	 	alert (_joinML_invalid);
	 	email_field.focus();
	} else {
		var url = "xml_joinML.php?joinML_email="+email_field.value;
		var xml = LoadXML(url);
		if(xml != null)
		{
			var response = xml.getElementsByTagName('rsp_stat')[0].firstChild.data;
			if (response=="ok")
			{
				email_field.value="";
				alert (_joinML_confirm);
			}
		}
	}
	return false;
}

function submit_infoForm(f)
{
	f_array = new Array ("fName","lName","email","freeText");
	for (c in f_array)
	{
		key = f_array[c];
		if (f['order_'+key].value == "")
		{
			alert (eval("_infoForm_"+key));
			f['order_'+key].focus();
			return false;
		}
		else if (key == "email" && !checkEmail(f['order_'+key].value))
		{
			alert (_joinML_invalid);
			f['order_'+key].focus();
			return false;
		}
	}
	return confirm (_infoForm_confirm);
}

function populateTable(a,b,c)
{
	for (i=0; i<flightHtls[a][b][c].length; i++)
	{
		curElement = flightHtls[a][b][c][i];
		curBgColor=((i%2)==1)?_colors_fourth:_colors_white;

		htlTable.AddLine(curElement[0], curElement[2], curElement[3], curElement[4],curElement[8], curElement[5],curElement[7], '');
		htlTable.AddLineSortData(curElement[1], '', '', '', '', curElement[6], '', '');
		htlTable.AddLineProperties("bgcolor="+curBgColor);
	}
	if (flightHtls[a][b][c].length < maxHtls)
	{
		for (i=0; i < (maxHtls - flightHtls[a][b][c].length); i++)
			htlTable.AddLine("","","","","", "", "","");
	}
}

function populateCarTable(curFlt)
{
	curDuration=document.pckSelect["flt"+curFlt+"_duration"].value;
	curOutBound=document.pckSelect.curOutBound.value;
	for (i=0; i<flightHtls[curFlt][curOutBound][curDuration].length; i++)
	{
		curElement = flightHtls[curFlt][curOutBound][curDuration][i];
		curBgColor=((i%2)==1)?_colors_fourth:_colors_white;

		carTable.AddLine(curElement[7],curElement[1],curElement[2],curElement[3],curElement[4],curElement[5],curElement[6]);
		carTable.AddLineSortData('',curElement[0],'','','','',"");
		carTable.AddLineProperties("bgcolor="+curBgColor);
	}
	if (flightHtls[curFlt][curOutBound][curDuration].length < maxCars)
	{
		for (i=0; i < (maxCars - flightHtls[curFlt][curOutBound][curDuration].length); i++)
			carTable.AddLine("","","","","", "");
	}
}

function changePckHotels(fltNum,a,b,c,numoflights)
{
	totalFlights=numoflights;
	for (i=0; i<totalFlights; i++)
		document.getElementById("TR_"+i).style.backgroundColor="";
	document.getElementById("TR_"+fltNum).style.backgroundColor=_colors_fourth;
	if (document.pckSelect.selectedFlight[fltNum] != null)
		document.pckSelect.selectedFlight[fltNum].checked=true;
	document.pckSelect.curFlt.value=fltNum;
	if (maxHtls)
	{
		htlTable.Lines = null;
		htlTable.Lines = new Array();
		htlTable.Lines.length=0;
		populateTable(a,b,c);
		SortRows(htlTable, document.pckSelect.tableSort.value);
	}
	else if (maxCars)
	{
		carTable.Lines = null;
		carTable.Lines = new Array();
		carTable.Lines.length=0;
		populateCarTable(a,b,c);
		SortRows(carTable, document.pckSelect.tableSort.value);
	}
}

function replaceFltDuration(curInBound, curFlt)
{
	curOutBound=document.pckSelect.curOutBound.value;
	document.pckSelect["flt"+curFlt+"_FL_DATE_dow2"].value=fltData[curFlt]['outBound'][curOutBound]['inBound'][curInBound][0]['FL_DATE_dow2'];
	document.pckSelect["flt"+curFlt+"_FL_DATE2"].value=fltData[curFlt]['outBound'][curOutBound]['inBound'][curInBound][0]['FL_DATE2'];
	document.pckSelect["flt"+curFlt+"_FL_Dep_Hour2"].value=fltData[curFlt]['outBound'][curOutBound]['inBound'][curInBound][0]['FL_Dep_Hour2'];
	document.pckSelect["flt"+curFlt+"_FL_AIRLINE_Name2"].value=fltData[curFlt]['outBound'][curOutBound]['inBound'][curInBound][0]['FL_AIRLINE_Name2'];
	document.pckSelect["flt"+curFlt+"_FL_Airline_Number2"].value=fltData[curFlt]['outBound'][curOutBound]['inBound'][curInBound][0]['FL_Airline_Number2'];
	document.pckSelect["flt"+curFlt+"_flightDate2"].value=fltData[curFlt]['outBound'][curOutBound]['inBound'][curInBound][0]['flightDate2'];
	document.pckSelect["flt"+curFlt+"_pck_id"].value=fltData[curFlt]['outBound'][curOutBound]['inBound'][curInBound][0]['pck_id'];
	hourField="flt"+curFlt+"_flightHour2";
	document.pckSelect[hourField].options.length=0;
	for (i=0; i<fltData[curFlt]['outBound'][curOutBound]['inBound'][curInBound].length; i++)
	{
		curOption=fltData[curFlt]['outBound'][curOutBound]['inBound'][curInBound][i]['flightHour2'];
		document.pckSelect[hourField][i]=new Option(curOption, i);
	}
	changePckHotels(curFlt, location.protocol);
}

function changeOutHour(curOutBound, curFlt)
{
	changeArr=new Array("FL_DATE_dow","FL_DATE","FL_Dep_Hour", "FL_AIRLINE_Name","FL_Airline_Number","flightDate");
	for (dir=1; dir<=2; dir++)
	{
		for (i=0; i<changeArr.length; i++)
		{
			curArrField=changeArr[i]+dir;
			curValue=(dir==1)?fltData[curFlt]['outBound'][curOutBound]['data'][curArrField]:fltData[curFlt]['outBound'][curOutBound]['inBound'][0][0][curArrField];
			curField="flt"+curFlt+"_"+changeArr[i]+dir;
			document.pckSelect[curField].value=curValue;
		}
	}
	// change return hour options
	document.pckSelect["flt"+curFlt+"_flightHour2"].options.length=0;
	for (i=0; i<fltData[curFlt]['outBound'][curOutBound]['inBound'][0].length; i++)
	{
		curOption=fltData[curFlt]['outBound'][curOutBound]['inBound'][0][i]['flightHour2'];
		document.pckSelect["flt"+curFlt+"_flightHour2"][i]=new Option(curOption, i);
	}

	document.pckSelect.curOutBound.value=curOutBound;
	// update duration options
	document.pckSelect["flt"+curFlt+"_duration"].options.length=0;
	for (i=0; i<fltData[curFlt]['outBound'][curOutBound]['inBound'].length; i++)
	{
		curOption=fltData[curFlt]['outBound'][curOutBound]['inBound'][i][0]['duration'];
		document.pckSelect["flt"+curFlt+"_duration"][i]=new Option(curOption, i);
	}
	changePckHotels(curFlt, location.protocol);
}

function changeInHour(curInBound, curFlt)
{
	curOutBound=document.pckSelect.curOutBound.value;
	curDuration=document.pckSelect["flt"+curFlt+"_duration"].value;
	document.pckSelect["flt"+curFlt+"_FL_Dep_Hour2"].value=fltData[curFlt]['outBound'][curOutBound]['inBound'][curDuration][curInBound]['FL_Dep_Hour2'];
	document.pckSelect["flt"+curFlt+"_FL_AIRLINE_Name2"].value=fltData[curFlt]['outBound'][curOutBound]['inBound'][curDuration][curInBound]['FL_AIRLINE_Name2'];
	document.pckSelect["flt"+curFlt+"_FL_Airline_Number2"].value=fltData[curFlt]['outBound'][curOutBound]['inBound'][curDuration][curInBound]['FL_Airline_Number2'];
}

function selectPck(curHotel, htlClub, pck_id, basic_fare)
{
	// FUNCTION FOR SELECTING PACKAGE FROM SEARCH RESULTS LIST
	curFlight=document.pckSelect.curFlt.value;
	document.pckSubmit.hotelID.value=curHotel;
	document.pckSubmit.basic_fare.value=basic_fare;
	document.pckSubmit.htlClub.value=htlClub;
	document.pckSubmit.curFlt.value=curFlight;
	document.pckSubmit.pck_id.value=pck_id;
	document.pckSubmit.curDepHour1.value=document.pckSelect["flt"+curFlight+"_FL_Dep_Hour1"].value;
	document.pckSubmit.curDepHour2.value=document.pckSelect["flt"+curFlight+"_FL_Dep_Hour2"].value;
	document.pckSubmit.curFlightNum1.value=document.pckSelect["flt"+curFlight+"_FL_Airline_Number1"].value;
	document.pckSubmit.curFlightNum2.value=document.pckSelect["flt"+curFlight+"_FL_Airline_Number2"].value;
	document.pckSubmit.submit();
}


/////////////// ROOM SELECTION FUNCTIONS //////////////////
function changeRoomNum(roomCount, curForm, roomNum)
{
	// check selected room class against current
	curPckID = curForm["room_"+roomCount+"_pck_id"].value;
	curDiscount = curForm["room_"+roomCount+"_discount"].value;
	selPckID = curPckID;
	for (i=0; i<roomTypesCount; i++)
	{
		if (i == roomCount) continue;
		if (parseFloat(curForm["room_"+i+"_numRooms"].value) > 0)
		{
			selPckID = curForm["room_"+i+"_pck_id"].value;
		}
	}

	if (selPckID != curPckID)
	{
		curForm["room_"+roomCount+"_numRooms"].selectedIndex = 0;
		alert (_roomClassError);
		return false;
	}
	else
	{
		curForm["pck_id"].value = curPckID;
		curForm["discAmount"].value = curDiscount;
	}

	newPrice=(parseFloat(curForm["room_"+roomCount+"_curPrice"].value)*parseFloat(roomNum));
	curForm["room_"+roomCount+"_totalPrice"].value=newPrice;
	rebuildBabyNum(curForm);
	changeBabyPrice(curForm);
}

/////////////// ROOM SELECTION FUNCTIONS //////////////////
function changeRoomNum_hotelOnly(roomCount, curForm, roomNum)
{
	// check selected room class against current
	curClass = curForm["room_"+roomCount+"_class"].value;
	selClass = curClass;
	for (i=0; i<roomTypesCount; i++)
	{
		if (i == roomCount) continue;
		if (parseFloat(curForm["room_"+i+"_numRooms"].value) > 0)
		{
			selClass = curForm["room_"+i+"_class"].value;
		}
	}

	if (selClass != curClass)
	{
		curForm["room_"+roomCount+"_numRooms"].selectedIndex = 0;
		alert (_roomClassError);
		return false;
	}

	curForm["hotel_class"].value = curClass;

	newPrice=(parseFloat(curForm["room_"+roomCount+"_defPrice"].value)*parseFloat(roomNum));
	curForm["room_"+roomCount+"_totalPrice"].value=newPrice;
	rebuildBabyNum(curForm);
	changeBabyPrice(curForm);
}

function rebuildBabyNum(curForm)
{
	curBabyNum=curForm.numBabys.selectedIndex;
	totalRms=0;
	for (i=0; i<roomTypesCount; i++)
		totalRms+=parseFloat(curForm["room_"+i+"_numRooms"].value);

	totalRms*=2;
	curForm.numBabys.options.length=0;
	curForm.numBabys[0]=new Option('', 0);
	for (i=1; i<=totalRms; i++)
		curForm.numBabys[i]=new Option(i, i);

	curForm.numBabys.selectedIndex=curBabyNum;
}

function changeBabyPrice(curForm)
{
	totalBabyPrice=parseFloat(curForm.babyPrice.value)*curForm.numBabys.value;
	curForm.baby_totalPrice.value=totalBabyPrice;
	calcTotalRPrice(curForm);
}

function calcTotalRPrice(curForm)
{
	newPrice=0;
	for (i=0; i<roomTypesCount; i++)
		newPrice+=parseFloat(curForm["room_"+i+"_totalPrice"].value);

	// add baby price
	newPrice+=parseFloat(curForm.babyPrice.value)*curForm.numBabys.value;
	discount=curForm.discAmount.value;
	discPrice=Math.round(newPrice*((100-discount)/100));
//	discPrice=(newPrice*((100-discount)/100));
	curForm.totalPrice.value=newPrice;
	curForm.totalDiscPrice.value=discPrice;
}

function reCalcChild(age_from, curForm, roomCount, childNum, lineCount)
{
	roomType=curForm["room_"+roomCount+"_type"].value;
	// check if room has more then one child
	if (parseFloat(curForm["room_"+roomCount+"_numChild"].value)>1){
		secChildNum=(childNum>1)?1:2;
		secChildAge=curForm["room_"+roomCount+"_childAge_"+secChildNum].value;
		if (secChildAge != age_from)
		{
			newPrice=parseFloat(curForm["room_"+roomCount+"_defPrice"].value)+parseFloat(htlRms[roomType]['child'][age_from]['Price'][1])+parseFloat(htlRms[roomType]['child'][secChildAge]['Price'][1]);
		} else {
			//check for second child price
		}
	}
	else
	{
		// only one child in room
		newPrice=parseFloat(curForm["room_"+roomCount+"_defPrice"].value)+parseFloat(htlRms[roomType]['child'][age_from]['Price'][1]);
	}
	curForm["room_"+roomCount+"_curPrice"].value=newPrice;
}

function checkHotelSelection(cAction)
{
	curForm = document.getElementById("roomSelect");
	if (parseFloat(curForm.totalPrice.value)==0)
	{
		alert (_alert_selectRoomType);
		return false;
	}
	else
	{
		curForm.action = cAction;
		show_preload();
		curForm.submit();
		return false;
	}
}

function checkRoomSelection()
{
	curForm = document.getElementById("roomSelect");
	if (parseFloat(curForm.totalPrice.value)==0)
	{
		alert (_alert_selectRoomType);
		return false;
	}
	else
	{
		show_preload();
		curForm.submit();
		return false;
	}
}

//////////////////// PASSANGER AND PAYMENT FORM FUNCTIONS ///////////////////
function validateFormName(c)
{
	c.value=c.value.toUpperCase().replace(/([^A-Z \-'"])/g,"");
}

function validateFormNum(c)
{
	newValue=c.value.toUpperCase().replace(/([^0-9])/g,"");
	shortValue=newValue.substr(0,10);
	c.value = shortValue;
}
function ChangePayment(f, crType)
{
	f.Nopayment.options.length = 0;
	if(crType ==3 || crType == 4)
	{
		f.Nopayment.options[0] = new Option (_orderForm_selectPayments, "");
		for (i=1; i<36; i++)
			f.Nopayment.options[i] = new Option (i, i);
	}
	else if(crType == 2)
	{
		f.Nopayment.options[0] = new Option (_orderForm_selectPayments, "");
		for (i=1; i<=3; i++)
			f.Nopayment.options[i] = new Option (i, i);
	}
	else
	{
		f.Nopayment.options[0] = new Option (1, 1);
	}
}

function click_terms(term_code, check_id, check_link)
{
	c_check = document.getElementById(check_id)
	if (check_link)
		c_check.checked = true;
	if (c_check.checked)
		popupWin('Popup Information.php?id='+term_code, 600, 450);
}

function showSubMes()
{
	pageScroll = getPageScroll();
	pageSize = getPageSize();

	overlay = document.createElement("DIV");
	overlay.id = "pageOverlay";
	overlay.style.top = pageScroll[1];
	document.body.appendChild(overlay);

	preload = document.createElement("DIV");
	preload.id = "orderSubmission";
	preload.style.top = (parseFloat(pageSize[1])/2) + pageScroll[1];
	preload.style.zIndex = "999";

	document.body.appendChild(preload);
}

function subOrder(fName)
{
	var button = document.getElementById('submit_button');
	var sendMessage = document.getElementById('submit_message');
	if (button.style.display != "none")
	{
		button.style.display = "none";
		sendMessage.style.display = "block";
		setTimeout("subOrder('"+fName+"')", 20);
	}
	else
	{
		var curForm = document[fName];
		var id, orderType = 'int';
		var radioOrder = curForm['order_type'];
		for(i = 0;i < radioOrder.length; i++)
		{
			if(radioOrder[i].checked == true)
				orderType = radioOrder[i].value;
		}
		var checkPassForm = subPackage(curForm);

		if(!checkPassForm)
		{
			button.style.display = "block";
			sendMessage.style.display = "none";
			return false;
		}

		var checkCstData = subCstOrder(curForm);
		if(!checkCstData)
		{
			button.style.display = "block";
			sendMessage.style.display = "none";
			return false;
		}

		if(!curForm.basicTerms.checked)
		{
			alert(_alert_confirm_genTerms);
			curForm.basicTerms.focus();
			button.style.display = "block";
			sendMessage.style.display = "none";
			return false;
		}

		if(!curForm.cancelTerms.checked)
		{
			alert(_alert_confirm_cancTerms);
			curForm.cancelTerms.focus();
			button.style.display = "block";
			sendMessage.style.display = "none";
			return false;
		}
		if(checkPassForm && checkCstData)
		{

			curForm.postConfirm.value = "true";
			if (orderType == 'int')
			{
				// CHECK CREDIT CARD FORM FOR INTERNET BASED ORDERS
				if (Submit_CreditCard(curForm))
				{
					curForm.action="Order Submit.php?orderType=int";
					if (confirm(_alert_confirmOrder))
					{
						showSubMes();
						document.orderForm.submit();
					}
				}
			}
			else
			{
				curForm.action="Order Submit.php?orderType=tel";
				if (confirm(_alert_confirmOrder))
				{
					showSubMes();
					document.orderForm.submit();
				}
			}
		}

		button.style.display = "block";
		sendMessage.style.display = "none";
		curForm.postConfirm.value = 0;
		return false;
	}
}

function subPackage(curForm)
{
//	 CHECK IF PRIVATE INFORMATION WAS INSERTED
	passCheck=true;
	if (curForm['pckPrice_IS'].value=="0")
	{
//	 GO BACK TO PREVIOUS PAGE IF PRICES WERE LOST WITH SESSION
		alert (_alert_noPriceError);
		window.history.back();
		return false;
	}
	//	CHECK BIRTH DATE VS. PASSTYPE AND AVAILABLE AGES
	//	current date variables are taken from flight date on parent page itself.
	passForm_array = new Array ("passTitle_","passFName_","passLName_","passPassNum_","passBirthDay_","passBirthMonth_","passBirthYear_");

	id_array=new Array();
	for (i=1; i<passNum; i++)
	{
		for(j=0;j<i-1;j++)
		{
			if(curForm["passPassNum_"+i].value==id_array[j])
			{
				alert(_alert_duplicateId);
				curForm["passPassNum_"+i].focus();
				return false;
			}
		}
		id_array[i-1]=curForm["passPassNum_"+i].value;


		for (f in passForm_array)
		{
			cField = passForm_array[f]+i;
			if (curForm[cField].value == "")
			{
				alert (_alert_fillAllPassInfo);
				curForm[cField].focus();
				return false;
			}
		}
		ageError=false;
		passType=curForm["passTitle_"+i].value;
		// dateYear etc. are set on PackageOrder.php, and taken from the package due date rather then current date!
		curAge = calcAge (curForm["passBirthYear_"+i].value, curForm["passBirthMonth_"+i].value, curForm["passBirthDay_"+i].value, dateYear, dateMonth, dateDay);

		if (passType=="CHD")
		{
			ageFrom=parseFloat(curForm["ageFrom_"+i].value);
			ageTo=parseFloat(curForm["ageTo_"+i].value);
			if (ageFrom > curAge || ageTo < curAge)
				ageError = true;
		}
		else if ( (passType=="INF") && (curAge > 2 || curAge < 0))
			ageError = true;

		if (ageError)
		{
			alert (_alert_ageError);
			curForm["passBirthYear_"+i].focus();
			return false;
		}
		else if (!checkidnum(curForm["passPassNum_"+i].value))
		{
			alert (_alert_IdError);
			curForm["passPassNum_"+i].focus();
			return false;
		}
	}
	return true;
}

function calcAge(birthYear, birthMonth, birthDay, curYear, curMonth, curDay)
{
	// 	FUNCTION FOR CALCULATING AGE FROM BIRTH DATE\
	// 	RETURNS AGE IN YEARS ACCORDING TO MONTHS

	age_months = (((parseFloat(curYear)*12)+parseFloat(curMonth) - (parseFloat(birthYear)*12)+parseFloat(birthMonth)));
	age_year = Math.floor(age_months/12);

	return age_year;


	/*calcYear=parseFloat(curYear)-parseFloat(birthYear);
	calcMonth=parseFloat(curMonth)-parseFloat(birthMonth);
	calcDay=parseFloat(curDay)-parseFloat(birthDay);

	if (calcYear <= 0) return 0;

	if (calcMonth>0){
		return calcYear;
	} else if (calcMonth<=0){
		return (calcYear-1);
	} else if (calcDay>0){
		return calcYear;
	} else {
		return (calcYear-1);
	}*/
}

function checkidnum(idnum)
{
	// FUNCTION FOR VALIDATING ID NUMBER
    while (idnum.length<9)
    {
        idnum="0"+idnum;
    }

    idnum1=idnum.substr(0,1)*1;
    idnum2=idnum.substr(1,1)*2;
    idnum3=idnum.substr(2,1)*1;
    idnum4=idnum.substr(3,1)*2;
    idnum5=idnum.substr(4,1)*1;
    idnum6=idnum.substr(5,1)*2;
    idnum7=idnum.substr(6,1)*1;
    idnum8=idnum.substr(7,1)*2;
    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;
    if(sumval == 0)
    	return false;
    sumval=sumval%10
    if (sumval>0)
    {
        return false;
    }
  return true;
}

function subCstOrder(f)
{

	f_array = new Array ("FName","LName","Tel", "Email");
	for (c in f_array)
	{
		key = f_array[c];
		if (f['order_'+key].value == "")
		{
			alert (eval("_orderForm_"+key));
			f['order_'+key].focus();
			return false;
		}
		else if (key == "Email" && !checkEmail(f['order_'+key].value))
		{
			alert (_joinML_invalid);
			f['order_'+key].focus();
			return false;
		}
	}
	return true;
}
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: David Leppek :: https://www.azcode.com/Mod10

Basically, the alorithum takes each digit, from right to left and muliplies each second
digit by two. If the multiple is two-digits long (i.e.: 6 * 2 = 12) the two digits of
the multiple are then added together for a new number (1 + 2 = 3). You then add up the
string of numbers, both unaltered and new values and get a total sum. This sum is then
divided by 10 and the remainder should be zero if it is a valid credit card. Hense the
name Mod 10 or Modulus 10. */
function Mod10(ccNumb) {  // v2.0
var valid = "0123456789"  // Valid digits in a credit card number
var len = ccNumb.length;  // The length of the submitted cc number
var iCCN = parseInt(ccNumb);  // integer of ccNumb
var sCCN = ccNumb.toString();  // string of ccNumb
sCCN = sCCN.replace (/^\s+|\s+$/g,'');  // strip spaces
var iTotal = 0;  // integer total set at zero
var bNum = true;  // by default assume it is a number
var bResult = false;  // by default assume it is NOT a valid cc
var temp;  // temp variable for parsing string
var calc;  // used for calculation of each digit

// Determine if the ccNumb is in fact all numbers
for (var j=0; j<len; j++) {
  temp = "" + sCCN.substring(j, j+1);
  if (valid.indexOf(temp) == "-1"){bNum = false;}
}

// if it is NOT a number, you can either alert to the fact, or just pass a failure
if(!bNum){
  /*alert("Not a Number");*/bResult = false;
}

// Determine if it is the proper length
if((len == 0)&&(bResult)){  // nothing, field is blank AND passed above # check
  bResult = false;
} else{  // ccNumb is a number and the proper length - let's see if it is a valid card number
  if(len >= 15){  // 15 or 16 for Amex or V/MC
    for(var i=len;i>0;i--){  // LOOP throught the digits of the card
      calc = parseInt(iCCN) % 10;  // right most digit
      calc = parseInt(calc);  // assure it is an integer
      iTotal += calc;  // running total of the card number as we loop - Do Nothing to first digit
      i--;  // decrement the count - move to the next digit in the card
      iCCN = iCCN / 10;                               // subtracts right most digit from ccNumb
      calc = parseInt(iCCN) % 10 ;    // NEXT right most digit
      calc = calc *2;                                 // multiply the digit by two
      // Instead of some screwy method of converting 16 to a string and then parsing 1 and 6 and then adding them to make 7,
      // I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple.
      switch(calc){
        case 10: calc = 1; break;       //5*2=10 & 1+0 = 1
        case 12: calc = 3; break;       //6*2=12 & 1+2 = 3
        case 14: calc = 5; break;       //7*2=14 & 1+4 = 5
        case 16: calc = 7; break;       //8*2=16 & 1+6 = 7
        case 18: calc = 9; break;       //9*2=18 & 1+8 = 9
        default: calc = calc;           //4*2= 8 &   8 = 8  -same for all lower numbers
      }
    iCCN = iCCN / 10;  // subtracts right most digit from ccNum
    iTotal += calc;  // running total of the card number as we loop
  }  // END OF LOOP
  if ((iTotal%10)==0){  // check to see if the sum Mod 10 is zero
    bResult = true;  // This IS (or could be) a valid credit card number.
  } else {
    bResult = false;  // This could NOT be a valid credit card number
    }
  }
}
// change alert to on-page display or other indication as needed.
  return bResult; // Return the results
}
// -->

function Submit_CreditCard(f)
{
	f_array = new Array ("IdNum","CardType","CreditCardNum", "ExpirationMonth", "ExpirationYear");
	for (c in f_array)
	{
		key = f_array[c];
		if (f[key].value == "" || f[key].value == 0)
		{
			alert (eval("_orderForm_"+key));
			f[key].focus();
			return false;
		}
		else if (key == "IdNum" && !checkidnum(f[key].value))
		{
			alert (_alert_IdError);
			f[key].focus();
			return false;
		}
	}
	if(f.MethodOfPayment.value == "3" && f.Nopayment.value == "")
	{
		alert (_orderForm_NumberPayments);
		f.Nopayment.focus();
		return false;
	}
	if(Mod10(f["CreditCardNum"].value) || (f("CardType").value==1 && f["CreditCardNum"].value.length==8))
		return true;
	else
	{
		alert(_alert_CreditCardNotValid);
		return false;
	}
}

function selectHotel(HotelID)
{
	if(confirm(_alert_confirmOrder))
	{
		LaId=document.getElementById("LaId");
		LaId.value=HotelID;
		document.getElementById("Summ").value=document.getElementById(HotelID+"_summ").value;
		document.getElementById("pckPrice_IS").value=document.getElementById(HotelID+"_pckPrice_IS").value;
		document.getElementById("pckPrice_cur").value=document.getElementById(HotelID+"_pckPrice_cur").value;
		document.showAlternitive.submit();
	}
}


function force_RQ(skipConfirm)
{
	if(skipConfirm || confirm(_alert_confirmOrder))
	{
		force_rq=document.getElementById("forceRQ");
		force_rq.value="true";
		document.showAlternitive.submit();
	}
}

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.com
//
function getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;
	}

	arrayPageScroll = new Array(xScroll,yScroll)
	return arrayPageScroll;
}

function getPageSize() {
  size_arr = new Array();
  size_arr[0] = 0;
  size_arr[1] = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    size_arr[0] = window.innerWidth;
    size_arr[1] = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    size_arr[0] = document.documentElement.clientWidth;
    size_arr[1] = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    size_arr[0] = document.body.clientWidth;
    size_arr[1] = document.body.clientHeight;
  }
  return size_arr;
}

function show_preload()
{
	pageScroll = getPageScroll();
	pageSize = getPageSize();

	overlay = document.createElement("DIV");
	overlay.id = "pageOverlay";
	overlay.style.top = pageScroll[1];
	document.body.appendChild(overlay);

	preload = document.createElement("DIV");
	preload.id = "preloader";
	preload.style.display = "block";
	preload.style.top = (parseFloat(pageSize[1])/2) + pageScroll[1];
	preload.style.zIndex = "999";

	document.body.appendChild(preload);
}

function hide_preload()
{
	if (document.getElementById("preloader"))
	{
		document.body.removeChild(document.getElementById("preloader"));
	}
	if (document.getElementById("pageOverlay"))
	{
		document.body.removeChild(document.getElementById("pageOverlay"));
	}
}

function checkIfLoged()
{
		var url = "xml_checkConnectedCst.php";
		var xml = LoadXML(url);
		if(xml==null)
			return false;
		else
		{
			var loged = xml.getElementsByTagName('login')[0].firstChild.data;
			if(loged=="true")
				return true;
			else
				return false;
		}
}

function addToAgent(curHotel, htlClub, pck_id, url)
{

	isLoged=checkIfLoged();


	if(!isLoged)
	{
		alert(_alert_connectToAddToAgent);
		encodedURL=escape(url);
		window.location="Members Join.php?redirect="+encodedURL;
	}

	splited=url.split("?");
	param=splited[1];


	curFlight=document.pckSelect.curFlt.value;
	curDepHour1=document.pckSelect["flt"+curFlight+"_FL_Dep_Hour1"].value;
	curDepHour2=document.pckSelect["flt"+curFlight+"_FL_Dep_Hour2"].value;
	curFlightNum1=document.pckSelect["flt"+curFlight+"_FL_Airline_Number1"].value;
	curFlightNum2=document.pckSelect["flt"+curFlight+"_FL_Airline_Number2"].value;

	param+="&curFlight="+curFlight;
	param+="&curHotel="+curHotel;
	param+="&htlClub="+htlClub;
	param+="&pck_id="+pck_id;
	param+="&curDepHour1="+curDepHour1;
	param+="&curDepHour2="+curDepHour2;
	param+="&curFlightNum1="+curFlightNum1;
	param+="&curFlightNum2="+curFlightNum2;


	var url="xml_addToAgent.php?"+param;
	var xml = LoadXML(url);
	var added = xml.getElementsByTagName('add')[0].firstChild.data;
	if(added)
		alert(_alert_addToAgent);
	else
		alert(_alert_errorAddToAgent);
}

function checkNewUserForm(curForm)
{

	ReqFields=new Array("PRM_firstName",
					  "PRM_lastName",
					  "PRM_email",
					  "PRM_phone",
					  "PRM_userName",
					  "PRM_password",
					  "PRM_pwValidation");
	for (i=0;i<ReqFields.length; i++)
	{
		fieldName = ReqFields[i];
		if (curForm[fieldName].value=="")
		{
			cMessage = eval("_alert_"+fieldName);
			alert(cMessage);
			curForm[fieldName].focus();
			return false;
		 }
	}
	if(!checkEmail(curForm["PRM_email"].value))
	{
		alert(_alert_emailValid);
		curForm["PRM_email"].focus();
		return false;

	}
	if(curForm["PRM_password"].value.length<4)
	{
		alert(_alert_pwLength);
		curForm["PRM_password"].focus();
		return false;

	}
	if(curForm["PRM_password"].value != curForm["PRM_pwValidation"].value)
	{
		alert(_alert_noPwValidation);
		curForm["PRM_pwValidation"].focus();
		return false;
	}
	if(confirm(_confirm_addNewUser))
		return true;
	else
		return false;
}

function showReminder()
{
	tr=document.getElementById("pwReminder");
	if(tr.style.display=="none")
		tr.style.display=(navigator.appName == "Microsoft Internet Explorer") ? "inline":"table-row";
	else
		tr.style.display="none"
}

function gotoPack(formID)
{
	curForm=document.getElementById(formID);
	curForm.submit();

}

function hide_jambo()
{
	/*if (document.getElementById("jambo_mc"))
	{
		document.getElementById("jambo_mc").style.display="none";
		Set_Cookie("jambo_banner","true",0);
	}*/
}

function removeObject(obj)
{
	if (document.getElementById(obj))
	{
		document.getElementById(obj).style.display="none";
	}
}

function flt_changeInBound(outID, row_num)
{
	// function for changing inBound flights according to selected outBound restrictions
	in_count = 0;
	first_inBound = 0;
	flt_selectRow("outBound", row_num);
	for (inID in flt_restrictions[outID])
	{
		fl_display = (flt_restrictions[outID][inID]) ? (navigator.appName == "Microsoft Internet Explorer") ? "inline":"table-row" : "none";
		document.getElementById("inBound_"+in_count).style.display = fl_display;
		if (document.getElementById("inBound_sep_"+in_count)) document.getElementById("inBound_sep_"+in_count).style.display = fl_display;
		// check and select first available inBound flight
		if (flt_restrictions[outID][inID] && !first_inBound)
		{
			first_inBound = 1;
			// check if current selected inBound is restricted or not
			flt_radio = document.fltSelect.inBound;
			checked_flt = 0;
			if (flt_radio.length)
			{
				for (i=0; i<total_inBound; i++)
					if (flt_radio[i].checked)
						checked_flt = i;
			}

			inBound_id = (flt_radio[checked_flt]) ? flt_radio[checked_flt].value:flt_radio.value; // used to override error when radio has one item only and is not then an array

			inBound_row = (flt_restrictions[outID][inBound_id]) ? checked_flt : in_count;
			flt_selectRow("inBound",inBound_row);
		}
		in_count++;
	}
	if (total_inBound && !first_inBound)
	{
		alert(_alert_noInboundOptions);
		flt_radio = document.fltSelect.inBound;
		if (flt_radio.length)
		{
			for (i=0; i<total_inBound; i++)
				flt_radio[i].checked = false;
		}
		else if (flt_radio)
			flt_radio.checked = false;
	}
}

function flt_selectRow(flt_type, row_num)
{
	totalFlights = eval("total_"+flt_type);
	for (i=0; i<totalFlights; i++)
		document.getElementById(flt_type+"_"+i).style.backgroundColor="";
	document.getElementById(flt_type+"_"+row_num).style.backgroundColor=_colors_fourth;

	flt_radio = document.fltSelect[flt_type];
	if (flt_radio[row_num] != null)
		flt_radio[row_num].checked=true;
	else if (flt_radio.type == "radio")
		flt_radio.checked = true;
}

function flt_changePassNum(fid, fValue)
{
	if (fValue > 0)
	{
		fid.num_children.disabled = false;
		fid.num_babys.disabled = false;
	}
	else
	{
		fid.num_children.selectedIndex = 0;
		fid.num_babys.selectedIndex = 0;
		fid.num_children.disabled = true;
		fid.num_babys.disabled = true;
	}

}

function check_radioSelection(fid, radio_id)
{
	// function for checking if flight is selected
	flt_radio = fid[radio_id];
	checked_flt = 0;
	if (!flt_radio)
		return 0;
	if (flt_radio.length)
	{
		for (i=0; i<flt_radio.length; i++)
			if (flt_radio[i].checked)
				checked_flt = 1;
	}
	else if (flt_radio.checked)
		checked_flt = 1;

	return checked_flt;
}

function flightSelect(cAction)
{
	// submit flt search selection form
	fid = document.fltSelect;
	if (cAction != "Hotel Search Results.php" && fid.num_adults.value == 0) // check passanger selection if not adding hotel
	{
		alert (_flt_selectPassangers);
	}
	else if (total_inBound && !check_radioSelection(fid, "inBound"))
	{
		alert (_alert_noInbound);
	}
	else
	{
		fid.action = cAction;
		if (cAction == "Hotel Search Results.php") fid.method = "GET";
		show_preload();
		fid.submit();
	}
}

function carSelect()
{
	fid = document.pckSelect;
	total_pax = parseFloat(fid.num_adults.value)+parseFloat(fid.num_children.value);
	if (!check_radioSelection(fid, "car_select"))
		alert (_alert_noCarSelected);
	else if (total_pax < 2)
		alert (_car_minPax);
	else
	{
		curFlight=document.pckSelect.curFlt.value;
		fid.pck_id.value=document.pckSelect["flt"+curFlight+"_pck_id"].value;
		fid.curFlightNum1.value=document.pckSelect["flt"+curFlight+"_FL_Airline_Number1"].value;
		fid.curFlightNum2.value=document.pckSelect["flt"+curFlight+"_FL_Airline_Number2"].value;
		fid.submit();
	}
}

function nightsSelect(nights,numoflights){
	cnt=0;
	for(i=0;i<numoflights;i++){
		if(document.getElementById('TD_'+i).getAttribute('duration')==nights){
			document.getElementById('TR_'+i).style.display=(navigator.appName == "Microsoft Internet Explorer") ? "inline":"table-row";
			document.getElementById('TD_'+i).style.display=(navigator.appName == "Microsoft Internet Explorer") ? "inline":"table-cell";
			document.getElementById('BORDER'+i).style.display='';
			if(cnt==0){
				curFlt = i ;
				cnt = 1;
			}

		}
		else{
			document.getElementById('TR_'+i).style.display='none';
			document.getElementById('TD_'+i).style.display='none';
			document.getElementById('BORDER'+i).style.display='none';
		}
	}

		changePckHotels(curFlt,document.getElementById('a'+curFlt).value,document.getElementById('b'+curFlt).value,document.getElementById('c'+curFlt).value,numoflights);

}


/************ NEWS ROTATOR ************/
// Author: Eytan Chen, Tyco Interactive ltd.
// Create on: October 2009


// DO NOT CHANGE THIS SCRIPT! ALL SETTINGS ARE FROM THE PHP RENDER FUNCTION //

function tyco_nr_switch(nr_id)
{
	for (var a = 0; a < nr_total; a ++) {
		cb = document.getElementById("nr_b_"+a);
		cb.className  = (a != nr_id) ? "" : "nr_scriptthis";
	}

	c = document.getElementById("nr_contents");
	d = nr_data[nr_id];
	if (d != null) c.innerHTML = d;

	nrc++;
	if (nrc >= nr_total) nrc = 0;
	clearTimeout (nr_int);
	if (autoSwitch) nr_int = setTimeout ( "tyco_nr_switch(nrc)", nr_delay );
}

function tyco_nr_init(nr_id)
{
	nrc = nr_id;
	clearTimeout (nr_int);
	origSwitch = autoSwitch;
	autoSwitch = false;
	tyco_nr_switch(nrc);
	mc = document.getElementById("nr_script");
	if (origSwitch) {
		mc.onmouseout = function () {
			autoSwitch = true;
			nr_int = setTimeout ( "tyco_nr_switch(nrc)", nr_delay );
			mc.onmouseout = null;
		}
	}
	return false;
}

//ie6 link fixer - for activating onclick for tabs on rotator for explorer 6
function tyco_nr_ie6_fix() {
	//find menu
	var elms = document.getElementById("nr_scriptmenu");
	if (!elms)
		return;

	//get li's
	var lis = elms.getElementsByTagName("li");
	for (var i=0; i<lis.length; i++) {
		lis[i].onclick = function() {
			//find link
			var hrefs = this.getElementsByTagName("a");
			if (hrefs.length == 0)
				return;

			//activate onclick
			hrefs[0].onclick();
		};
	}
}

/*********** END NEWS ROTATOR **************/

function updateVideobox(videobox_id, video_src) {
	if (video_src == "" || video_src == null) return;
	
	player = document.getElementById(videobox_id);
	var youtube_url = /(?:http:\/\/)?(?:www\d*\.)?(youtube\.(?:[a-z]+))\/(?:v\/|(?:watch(?:\.php)?)?\?(?:.+&)?v=)([^&]+).*/;
	var _match = video_src.match(youtube_url);
	if (!_match) return;
      var domain = _match[1];
      var id = _match[2];
	var html = '<div><object width="316" height="266"><param name="movie" value="http://www.' + domain + '/v/' + id + '&hl=en&rel=0&ap=%2526fmt%3D18"/><param name="wmode" value="transparent"/><embed src="http://www.' + domain + '/v/' + id + '&hl=en&rel=0&ap=%2526fmt%3D18" type="application/x-shockwave-flash" wmode="transparent" width="316" height="266"></embed></object></div>';
	
	player.innerHTML = html;
}

/************ NEWS ROTATOR 2 ************/
// Author: Eytan Chen, Tyco Interactive ltd.
// Create on: October 2009

// we have 2 news rotators pointing to different variables and ids, because they need to be shown on same screen

// DO NOT CHANGE THIS SCRIPT! ALL SETTINGS ARE FROM THE PHP RENDER FUNCTION //

function tyco_nrs_switch(nrs_id)
{
	for (var a = 0; a < nrs_total; a ++) {
		cb = document.getElementById("nrs_b_"+a);
		cb.className  = (a != nrs_id) ? "" : "nrs_scriptthis";
	}

	c = document.getElementById("nrs_contents");
	d = nrs_data[nrs_id];
	if (d != null) c.innerHTML = d;

	nrsc++;
	if (nrsc >= nrs_total) nrsc = 0;
	clearTimeout (nrs_int);
	if (autoSwitch) nrs_int = setTimeout ( "tyco_nrs_switch(nrsc)", nrs_delay );
}

function tyco_nrs_init(nrs_id)
{
	nrsc = nrs_id;
	clearTimeout (nrs_int);
	origSwitch = autoSwitch;
	autoSwitch = false;
	tyco_nrs_switch(nrsc);
	mc = document.getElementById("nrs_script");
	if (origSwitch) {
		mc.onmouseout = function () {
			autoSwitch = true;
			nrs_int = setTimeout ( "tyco_nrs_switch(nrsc)", nrs_delay );
			mc.onmouseout = null;
		}
	}
	return false;
}

//ie6 link fixer - for activating onclick for tabs on rotator for explorer 6
function tyco_nrs_ie6_fix() {
	//find menu
	var elms = document.getElementById("nrs_scriptmenu");
	if (!elms)
		return;

	//get li's
	var lis = elms.getElementsByTagName("li");
	for (var i=0; i<lis.length; i++) {
		lis[i].onclick = function() {
			//find link
			var hrefs = this.getElementsByTagName("a");
			if (hrefs.length == 0)
				return;

			//activate onclick
			hrefs[0].onclick();
		};
	}
}

/*********** END NEWS ROTATOR **************/

var nrsc;
var nrs_total;
var nrs_data = new Array();
var nrs_delay;
var autoSwitch;
var nrs_int;

function reload_salesRotator(subject, dst, tab) {

	if (tab != null) {
		tab_tr = tab.parentNode.parentNode;
		for (a=0; a < tab_tr.childNodes.length; a++) {
			tab_td = tab_tr.childNodes[a];
			
			if (tab_td && tab_td.tagName == "TD")
			{
				tab_td.childNodes[0].className="";
			}
		}
		tab.className = "selected";		
	}
	
	var url = "xml_getSalesRotator.php?subject="+subject+"&dst="+dst;
	var xml = LoadXML(url);
	if(xml != null)
	{
		if (!xml.getElementsByTagName('html') || !xml.getElementsByTagName('html')[0] || !xml.getElementsByTagName('html')[0].firstChild) {
			document.getElementById("salesRotator_mc").innerHTML = "";
			return false;
		}
		var rotator_html = xml.getElementsByTagName('html')[0].firstChild.data;
		var rotator_javascript = xml.getElementsByTagName('javascript')[0].firstChild.data;
		document.getElementById("salesRotator_mc").innerHTML = rotator_html;
		nrs_data.splice(0,nrs_data.length);
		eval (rotator_javascript);
	}
	
	return false;
}

function show_durationPackages(duration, tab) {

	if (tab != null) {
		tab_tr = tab.parentNode.parentNode;
		for (a=0; a < tab_tr.childNodes.length; a++) {
			tab_td = tab_tr.childNodes[a];
			
			if (tab_td && tab_td.tagName == "TD")
			{
				tab_td.childNodes[0].className="";
			}
		}
		tab.className = "selected";		
	}
	
	dataContainer = document.getElementById("hotelTabsRotator");
	for (a=0; a < dataContainer.childNodes.length; a++) {
		mc = dataContainer.childNodes[a];
		if (mc && mc.id && mc.id.indexOf("tabsRotator_") > -1)
		{
			mc.style.display = "none";
		}
	}
	
	dataTarget = document.getElementById("tabsRotator_"+duration);
	if (dataTarget) dataTarget.style.display = "block";
	
	return false;
}