
  function setcheckOutDate()
  {
  	 var dd,mm,yy;
     var pickupDate = document.Search.checkInDate.value;
    
     dd = pickupDate.split("/")[0];
     mm = pickupDate.split("/")[1] - 1;
     yy = pickupDate.split("/")[2];
  
     var objPickupDate = new Date( yy, mm, dd);
  	objPickupDate = new Date( objPickupDate.getTime() + 7 * 24*3600 *1000);	
  	if (objPickupDate.getDate() < 10 )
  		dd = "0" + objPickupDate.getDate();
  	else
  		dd = objPickupDate.getDate();		
  	if( objPickupDate.getMonth() < 9 )
  		mm = "0" + (objPickupDate.getMonth() + 1);	
  	else
  		mm = objPickupDate.getMonth() + 1;
  		
     document.Search.checkOutDate.value= dd +"/" + mm +"/"  + objPickupDate.getFullYear();
     document.Search.selNoOfNights.value= 7;
}


function stCtCnt( val )
{
	var tokens = val.split(",");

	document.Search.countryCodeSelected.value = tokens[3];
	document.Search.countrySelected.value = tokens[2];

	document.Search.destinationCodeSelected.value = tokens[1];
	document.Search.destinationSelected.value = tokens[0];

	document.Search.selCity.value = document.Search.destinationSelected.value;

	var cntEle = document.Search.selCountry;

	var optCount;
	var tempCode;

    for (optCount= 0; optCount < cntEle.length; optCount++ )
    {
    	tempCode = cntEle.options[optCount].value;
    	if ( tempCode == tokens[3] )
    	{
			cntEle.selectedIndex = optCount;
			break;
    	}
    }
}

function validateInputData ()
{
	var valid = false;

	//1. validating input dates, check in and check out

	var fromDateValid = validateFromDate( document.Search.selCheckIn_DD.value ,
						  document.Search.selCheckIn_MM.value ,
						  document.Search.selCheckIn_YY.value );

	var	toDateValid   = validateToDate( document.Search.selCheckOut_DD.value ,
						  document.Search.selCheckOut_MM.value ,
						  document.Search.selCheckOut_YY.value );

	if ( fromDateValid == true && toDateValid == true )
	{
		valid = true;
	}
	else
	{
		valid = false;
	}

	return valid;
}

function redirect()
{
	var browserName=navigator.appName;
	var noOfRooms = document.Search.noOfRooms .value;
	
	if (browserName=="Netscape")
	{
		hideBoxesNetscape();
	}
	else
	{
		if (browserName=="Microsoft Internet Explorer")
		{
			hideBoxesNetscape();
			//hideBoxes();
		}
		else
		{
			hideBoxesNetscape();
			//hideBoxes();
		}
	}
}

function checkNumeric( field ,message )
{
  var valid = "0123456789"
  var ok = "yes";
  var temp;
  var status=true;

  if(field.value!="")
  {
      for (var i=0; i<field.value.length; i++)
      {
         temp = "" + field.value.substring(i, i+1);
         if (valid.indexOf(temp) == "-1") ok = "no";
      }
      if( ok == "no" )
      {
         alert("Invalid entry for the  "+message+"!. Only numbers are accepted!");
		 //field.value = "0";
         field.focus();
         status = false;
       }
   }
   else
   {
       alert("Please enter the "+message+" ." );
       field.focus();
       status = false;
   }
   if (status == true)
   {
      setCheckoutDateByNights();
   }

   return status;
}

function replaceSpaces()
{
	var cityName = document.Search.selCity.value;
	var len = cityName.length;
	var i =0;
	var count = 0;

	for(i=0;i<len;i++)
	{
		var tempChar = cityName.charAt(i);
		if(tempChar != " ")
		{
			count++;
		}
	}

	return true;
}

function isValidDestination()
{
	var cityName = document.Search.cityselect.value;
	var countryName = document.Search.selCountry.value;
	var selCity=document.Search.selCity.value;
	if( (!cityName || cityname=="") && selCity=="")
	{
		alert("Please Select a Destination");
		return false;
	}
	else
	{
		if(cityName)
		{
			if(cityName.length < 2)
			{
				alert("City Name should be at least 3 characters");
				return false;
			}

		}
		if(countryName)
		{
			if(countryName.length <2 && selCity=="")
			{
				alert("Country Name should be at least 3 characters");
				return false;
			}

		}
	}

	return true;
}

function submitHome()
{	/*
	for ( i = 0 ; i < document.getElementsByName("destRB").length; i ++ )
	{
			document.getElementsByName("destRB")[i].checked = false;
	}*/

    if ( document.Search.selNoOfNights.value == "0")
    {
		alert("select valid number of nights");
        document.Search.selNoOfNights.focus();
    }
    else
    {
    	if ( !checkDateFormat( document.Search.checkInDate) )
    	{
			alert("Please enter the check in date.");
	        document.Search.checkInDate.focus();
	        return;
    	}
    	else if ( !checkDateFormat( document.Search.checkOutDate ))
    	{
			alert("Please enter the check out date");
	        document.Search.checkOutDate.focus();
	        return;
    	}

    	else if ( !isValidDestination() )
    	{
	        document.Search.selCity.focus();
	        return;
    	}

    	else if ( !validateRWP() )
    	{
    		return;
    	}
        else
        {
        	setSelectedParameters();//added on 24-08-2004 remove in case of an ERROR
    	    //document.Search.action ="ValidateSearch.php";
    	    document.Search.submit();
        }
    }
}

function ignoreSpaces(string) {
    var temp = "";
    string = '' + string;
    splitstring = string.split(" ");
    for(i = 0; i < splitstring.length; i++)
       temp += splitstring[i];
  return temp;
}

function loadCountries ()
{
	var countryArr = countryList.split(",");
	var arrLength = countryArr.length;

	var country = document.Search.selCountry;
	country.options.length = 1;

	var countryCode = "";
	var countryText = "";

	for (var i=0; i < arrLength; i++)
	{
		countryCode = countryArr[i];
		i++;
		countryText =  countryArr[i];

		var opt = new Option(countryText,countryCode);
		country.options[country.options.length] = opt;
  	}

	document.Search.selCountry.selectedIndex = 0;
}


function showme (me)
{
alert (me.value);
}

function showCityDropDown()
{
	cityselectdiv.className="showdiv";
	cityTextdiv.className="hiddendiv";
	document.Search.citysource.value="fromlist";
}

function HideSearchBox()
{
	searchlink.className="showdiv";
	SearchTable.className="hiddendiv tablerow "
}


function showSearchBox()
{
	searchlink.className="hiddendiv";
	SearchTable.className="showdiv tablerow"
}


function showCityTextBox()
{
	document.Search.citysource.value="fromtext";
	cityselectdiv.className="hiddendiv";
	cityTextdiv.className="showdiv"
}


function populateCities (SelectedCountry,City)
{
	//alert (SelectedCountry);
	if(SelectedCountry != ""){
	var cityArrayname =SelectedCountry;
	cityArray= eval (cityArrayname);
	document.Search.cityselect.options.length = 0;
    document.Search.cityselect.options[0] = new Option("Please Select","");
	for(i=0;i<cityArray.length;i++)
	{
		if (cityArray!="")
		{
			var code=cityArray[i].split("^")
			cityname=code[1];
			citycode=code[0];
	//   	alert (cityname);
	//   	alert (document.Search.cityselect);
 			document.Search.cityselect.options[i+1] = new Option(cityname,citycode);
 			if (City==citycode)
 			{
 				document.Search.cityselect.selectedIndex=i+1;
 			}
      	}
	}
}
    //changeCity(document.Search.selCity);
}

function setSelectedParameters()
{
	var countryText = document.Search.selCountry.value;
	if( countryText )
	{
		if(countryText.indexOf("-") > -1 )
		{
			document.Search.countryCodeSelected.value = countryText.substring(countryText.indexOf('-')+2,countryText.length);
			document.Search.countrySelected.value = countryText.substring(0,countryText.indexOf('-'))
		}
		else
		{
			document.Search.countrySelected.value = countryText;
		}
	}

	var destinationText = document.Search.selCity.value;
	if( destinationText )
	{
		if(destinationText.indexOf("-") > -1 )
		{
			document.Search.destinationCodeSelected.value  = destinationText.substring(destinationText.indexOf('-')+2,destinationText.length);
			document.Search.destinationSelected.value  = destinationText.substring(0,destinationText.indexOf('-'))
		}
		else
		{
			document.Search.destinationSelected.value  = destinationText;
		}

	}
	//document.Search.hotelNameEntered.value = document.Search.selHotel.value ;
	//document.Search.currencySelected.value = document.Search.selCurrency.value;
	//document.Search.promCodeEntered.value = document.Search.promotionalCode.value;
	document.Search.noOfRoomsSelected.value = document.Search.noOfRooms.value;
	document.Search.noOfNightsSelected.value = document.Search.selNoOfNights.value;
	document.Search.checkInDateEntered.value = document.Search.checkInDate.value;
	document.Search.checkOutDateEntered.value = document.Search.checkOutDate.value;

	//document.Search.currencyCodeSelected.value = document.Search.selCurrency.value;
	//document.Search.currencySelected.value = document.Search.selCurrency.options[document.Search.selCurrency.selectedIndex].text;

	document.Search.selectedRadioId.value = getSelectedRadio( document.getElementsByName("destRB") );
	document.Search.isSearchedOnce.value = "yes";
}

function setPreviousSearchParas()
{

	if (document.Search.isSearchedOnce.value == "yes")
	{
		//Country
		var selectedCountryCode = document.Search.countryCodeSelected.value;

		//Room Wise Pax
		redirect();

		//Currency Code
		var selectedCurrencyCode = document.Search.currencyCodeSelected.value;
		selectIndex = 0;
		var currencyCode = "";

		//var arrLength = document.Search.selCurrency.options.length;

		//for ( i=0; i < arrLength; i++)
		//{
		//	currencyCode = document.Search.selCurrency.options[i].value;

		//	if (currencyCode == selectedCurrencyCode )
		//	{
			//	selectIndex = i;
			//	break;
			//}
  		//}
		//document.Search.selCurrency.selectedIndex = selectIndex;

		//Checkin date
		document.Search.checkInDate.value = document.Search.checkInDateEntered.value;

		//Checkout date
		document.Search.checkOutDate.value = document.Search.checkOutDateEntered.value;

		//Destination
		document.Search.selCity.value = document.Search.destinationSelected.value;

		//Nights
		document.Search.selNoOfNights.value = document.Search.noOfNightsSelected.value;

		//Hotel Name
		document.Search.selHotel.value = document.Search.hotelNameEntered.value;

		//Seleted Radio
		var id = document.Search.selectedRadioId.value;
		if ( id != null && id != "" && id != -1 )
		{
			for ( i = 0 ; i < document.getElementsByName("destRB").length; i ++ )
			{
				if ( i == id )
					document.getElementsByName("destRB")[i].checked = true;
			}
		}
	}
}

function replaceHifen(code)
{
    var tempCode = code.replace("-","_");
    return tempCode;
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

var focusedField = null;
var imgElement = null;
var imgSrc = "images/rotating_bullet.gif";

var countryName = null;
var cityName = null;

function install ( frame , field , imgEle, fieldNo )
{

    if ( focusedField && focusedField.name == ( document.getElementById( field ) ).name )
    {
        return true;
    }

	countryName = document.Search.selCountry;
	cityName = document.Search.selCity;
    focusedField = document.getElementById( field );
    imgElement = document.getElementById( imgEle );

    installAC( document.getElementById( frame ) , focusedField,fieldNo,countryName,cityName,'http://192.168.0.72:3000/XMLHttpRequestHandler.php','en');

    return true;
}

function startAnimation()
{
    if ( imgElement && imgSrc )
    {
        imgElement.src = imgSrc;
    }
}

function stopAnimation ()
{
    if ( imgElement )
    {
        imgElement.src = "";
    }
}

function focusDefault ()
{
    document.getElementById ("selDepartingFrom").focus();
}


