﻿function $get(id)
{
	if (document.getElementById)
	    var returnVar = document.getElementById(id);
	else if (document.all)
	    var returnVar = document.all[id];
	else if (document.layers)
	    var returnVar = document.layers[id];
	return returnVar;
}
function ValidateForm(oButton, sType){
    var sMessage, bError, sLocation;
    bError = false;
    bSkipError = false;
    sMessage = "No error";	
    
    document.getElementById("lblLocationError").innerHTML = ""
    document.getElementById("lblLocationErrorSC").innerHTML = ""
    
    switch(sType){
    case 'QuickHotel':
      if(document.getElementById("strTLocID").value==""){
        sMessage="Hotel town is required";
        bError=true;			
    	}
    	break;

    case 'QuickSC':
      if(document.getElementById("strTLocIDSC").value==""){
        sMessage="Self-catering town is required";
        bError=true;			
    	}
    	break;    	
    	
    case 'Go0':		
        if(document.getElementById("strTLocID").value==""){
	        sMessage="Town is required";
	        bError=true;			
        } else {
        
            bSkipError = true;
            // IRC added else
            // validate the location
            ValidateLocation_GeoCoder(document.getElementById("strTLocID").value, FormSubmit, LocationError, oButton, document.getElementById("lblLocationError"))  ;
        }
	
        break;	
    case 'Go0SC':		
        if(document.getElementById("strTLocIDSC").value==""){
	        sMessage="Town is required";
	        bError=true;			
        } else {
        
            bSkipError = true;
            // IRC added else
            // validate the location
            ValidateLocation_GeoCoder(document.getElementById("strTLocIDSC").value, FormSubmit, LocationError, oButton, document.getElementById("lblLocationErrorSC"))  ;
        }
	
        break;	
    case 'Go1':	

        	
        if(document.getElementById("strLocID").value==""){
	        sMessage="City or town is required";
	        bError=true;			
        } 		
        break;
    case 'Go2':

        if(document.getElementById("strStartLocID").value==""){
	        sMessage="Start city or town is required";
	        bError=true;
        }		
        if(document.getElementById("strDestLocID").value=="" && !bError){		
	        sMessage="Destination city or town is required";
	        bError=true;
        }
        if (!bError) {
            //validate it
            // from...
          
            bSkipError = true;
            
            sLocation = document.getElementById("strStartAddress").value + " " 
                        + document.getElementById("strStartLocID").value + " " 
                        + document.getElementById("strStartCP").value + ", "
                        + document.getElementById("strStartCityCountry").value;
						                        
            document.getElementById("lblGoingFromError").innerHTML = "";
            document.getElementById("lblGoingToError").innerHTML = "";
            
            //tb 2009-03-20 problem here.. This element may not exist depending on which form displayed?
            //document.getElementById("RouteControlObjects").style.display = "inline";            
            //tb 2009-03-20 this might work..
            if(document.getElementById("RouteControlObjects")!=null){
							document.getElementById("RouteControlObjects").style.display = "inline";
            }            
            
            ValidateLocation_GLocal(sLocation, ValidateDestination, LocationError, oButton, document.getElementById("lblGoingFromError"));
        }
        		
        break;	
    }
    
    if (!bSkipError) {
        if(bError){
            alert (sMessage);
            return false;
        }	
        else{
            oButton.form.submit();
            return true; 
        }
    }

    return false;

}     

function ValidateDestination (oButton, oLabel){
    var sLocation;

    sLocation = document.getElementById("strDestAddress").value + " " 
                + document.getElementById("strDestLocID").value + " " 
                + document.getElementById("strDestCP").value + ", "
                + document.getElementById("strDestCityCountry").value;

    ValidateLocation_GLocal(sLocation, FormSubmit, LocationError, oButton, document.getElementById("lblGoingToError"))  ;

}

function LocationError(oButton, oLabel) {

//    document.getElementById("lblLocationError").innerHTML = "Sorry.  We were unable to find the location you requested.";
    oLabel.innerHTML = "Sorry.  We were unable to find the location you requested.";

}

function FormSubmit(oButton, oLabel) {
//    document.getElementById("lblLocationError").innerHTML = "Please wait while the map is loaded...";
    oLabel.innerHTML = "Please wait while the map is loaded...";

    oButton.form.submit();
    return true; 
} 

//tb 2009-03-20 added oButton parameter and changed the way the form value is set (was causing an error)
function ResetMapPage(oButton)
{        		
    //document.getElementById("FormAction").value = "";
		oButton.form.FormAction.value = "";
    oButton.form.submit();
}

function fnReturnHotelSearch(){
	$get('frmPropertyTypes').action='/hotels.asp';
	$get('frmPropertyTypes').submit();
}

function fnReturnSelfCateringSearch(){
	$get('frmPropertyTypes').FormAction.value='';
	$get('frmPropertyTypes').action='/self_catering.asp';
	$get('frmPropertyTypes').submit();
}

