﻿function OnSubmitHotelSearchForm( DestinationUrlHotel ) 
{
    var retVal = DoSearchValidations('hotel');
	if( retVal != 1 )
		return false;

	if(document.all)//qd é IE
    {
        if (document.getElementById("__VIEWSTATE") != null)
	        document.getElementById("__VIEWSTATE").disabled = true;
    }
    else //qd nao é IE
    {
        if (document.getElementById("__VIEWSTATE") != null)
		{
			var obj = document.getElementById("__VIEWSTATE");
            obj.parentNode.removeChild(obj);							
		}
    } 
		
	//ATENÇÃO!- Muda o valor a ser submitido.
    changeHotelCountryCodeByDesc();	
	
	document.getElementById("op").value = "hotelSearch";
	//
	document.forms[0].action = DestinationUrlHotel;
    document.forms[0].submit();	
}


function OnSubmitAirSearchForm( DestinationUrlAir ) {
    //document.getElementById('op').value = "airSearch";
    var retVal = DoSearchValidations('air');
    if( retVal == 1 )
    {
        if(document.all)//qd é IE
        {
	        if (document.getElementById("__VIEWSTATE") != null)
		        document.getElementById("__VIEWSTATE").disabled = true;
        }
        else //qd nao é IE
        {
	        if (document.getElementById("__VIEWSTATE") != null)
			{
				var obj = document.getElementById("__VIEWSTATE");
                obj.parentNode.removeChild(obj);							
			}
        }  
        
        document.getElementById('op').value = "airSearch";
        //
        document.forms[0].action = DestinationUrlAir;
        document.forms[0].submit();
        //document.getElementById("vt_vendaMotores").action = DestinationUrlAir;
        //document.getElementById("vt_vendaMotores").submit();        
    }
    else     
        return false;    
}

function OnSubmitValidationsSearchForm() {
	var retVal = DoSearchValidations('vacations');

	if( retVal == 1 )
		return true;
	else 
		return false;
}

function DoSearchValidations( aSearchType ) {
	var retVal = 1;
		
	switch( aSearchType ) {
		case "air" :
			retVal &= ValidateAirSearch();
		break;
		case "hotel" :
			retVal &= ValidateHotelSearch();
		break;		
		default:
		// report error
			retVal = 0;
		break;
	}
		
	return retVal;
}

function ValidateAirSearch() {
	var retVal = 1;
	
	retVal &= ValidateAirFields();
	if( !retVal )
		return retVal;

	retVal &= ValidateAirDate();
	
return retVal;
}

function ValidateHotelSearch() {
	var retVal = 1;
	retVal &= ValidateHotelDate();
	if( !retVal )
		return retVal;
	
	
	if( document.getElementById('Country') != null )
	{
	    objCity = document.getElementById('City');
	    //
	    if( (objCity[objCity.selectedIndex].text).lastIndexOf('-', 0) != -1 )
	    {
	        objCity.focus();
	        alert("Seleccione uma cidade."); 
	        retVal = 0;
	        return retVal;
	    }    
	}    
	
	//validate number of room. At least one room have to be selected.
	for (var i=1; i <= 2; i++)
	{	
	  var NumberRooms = document.getElementById('Room' + i).value;
	  if ( NumberRooms != 0  )
	    return retVal;	  
	}
	retVal = 0;
	alert("Seleccione o número de quartos pretendidos.");
		
	return retVal;
}

function ValidateAirFields(){
  var retVal = 1;
  
  // Validate Country
	retVal &= Validate( "De", "onde", K_TEXT, 2, 50, null, true, null, "onde" );	          
	if( !retVal )
		return retVal;

	// Validate City
	retVal &= Validate( "Para", "para", K_TEXT, 2, 50, null, true, null, "para" );	                   
	if( !retVal )
		return retVal;

	return retVal;	
}


function ValidateAirDate(){
  var retVal = 1;
  
  // Validade Date  
  if ( document.getElementById("dtIda") != null )
    retVal &= ValidadeDate( "Data Ida", "Data Volta", 4, "dtIda", null, null, "dtVolta", null, null, null );
  else
	retVal &= ValidadeDate( "Data Ida", "Data Volta", 4, "AirStartDateYear", "AirStartDateMonth", "AirStartDateDay", null, null, "AirRetStartDateYear", "AirRetStartDateMonth", "AirRetStartDateDay", null, null, null ); 
  
return retVal;
}

function ValidateHotelDate(){
  var retVal = 1;
  
  if ( document.getElementById("checkINDate") != null )
	retVal &= ValidadeDate( "Data", null, 3, "checkINDate", null, null, null, null, null, null );
  
return retVal;
}

function OnSubmitHotelHomePage( destinationURL ) 
{
	var retVal = DoSearchValidations('hotel');
	if( retVal != 1 )
		return false;
	
	if(document.all)//qd é IE
    {
        if (document.getElementById("__VIEWSTATE") != null)
	        document.getElementById("__VIEWSTATE").disabled = true;
    }
    else //qd nao é IE
    {
        if (document.getElementById("__VIEWSTATE") != null)
		{
			var obj = document.getElementById("__VIEWSTATE");
            obj.parentNode.removeChild(obj);
		}
    } 
		
	//ATENÇÃO!- Muda o valor a ser submitido.
    changeHotelCountryCodeByDesc();
	
	document.getElementById("op").value = "hotelHP";
	//
	document.forms[0].action = destinationURL;
    document.forms[0].submit();	
}


function OnSubmitAirHomePage( destinationURL ) 
{
	var retVal = ValidateAirDate();
	if( retVal != 1 )
		return false;
	
	if(document.all)//qd é IE
    {
        if (document.getElementById("__VIEWSTATE") != null)
	        document.getElementById("__VIEWSTATE").disabled = true;
    }
    else //qd nao é IE
    {
        if (document.getElementById("__VIEWSTATE") != null)
		{
			var obj = document.getElementById("__VIEWSTATE");
            obj.parentNode.removeChild(obj);
		}
    } 
	
	document.getElementById("op").value = "airHP";
	//
	document.forms[0].action = destinationURL;
    document.forms[0].submit();
}
