﻿function Show(sElement) {
if ( document.getElementById(sElement) != null ) {
    document.getElementById(sElement).style.display = 'block' ; }
}
    
function Hide(sElement) {
if ( document.getElementById(sElement) != null ) {
    document.getElementById(sElement).style.display = 'none' ; }
}
    
function Focus(sElement) {
if ( document.getElementById(sElement) != null ) {
        document.getElementById(sElement).focus() ; }
} 
function hideModel()
{
 var x = document.getElementById('quote_form_Model');
    x.style.display = 'none';
}
   
function changeHiddenInput_Textbox()
{
    var objHidden = document.getElementById('quote_form_Description_of_Goods'); 
    var make = document.getElementById("quote_form_Description_of_Goods_textbox").value; 
    objHidden.value = make;
}

function changeHiddenInput () 
{ 
    var objHidden = document.getElementById('quote_form_Description_of_Goods'); 
    
    var make = document.getElementById("quote_form_Make"); 
    var strMake = make.options[make.selectedIndex].text;

    var model = document.getElementById("quote_form_Model"); 
    var strModel = model.options[model.selectedIndex].text;
    
    objHidden.value = strMake + ':' + strModel;  
} 


function NotPersonalEffects() {

    notpersonaleffects = false ;

    if (document.getElementById('quote_form_Packing_Section') == null)  
        {
            notpersonaleffects = true ;
        }
    
    return notpersonaleffects

} 
function appendOption(selement,stext,svalue)
{
  var elOptNew = document.createElement('option');
    
  elOptNew.text = stext;

  elOptNew.value = svalue;
   
  var elSel = document.getElementById(selement);

  try {
    elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
  }
  catch(ex) {
    try {
        elSel.add(elOptNew); // IE only
        }
        catch(ex) {
        
        alert(ex.description + elOptNew.text + elOptNew.value);
        }
  }
}
function BuildMakeSelect()
{    // clear down the existing select and add a defaul of select
    document.getElementById('quote_form_Make').length = 0;
    appendOption('quote_form_Make',"Make","Make") ;
  
    startfrom = 0 ;
    sValue = 0 ;
    
    while(startfrom<arrAutoMMIntl.length)
    {

        // if his is the first pass we ignoire start from as the array does no start with a |
        if ( startfrom != 0 )
        {
            startfrom = arrAutoMMIntl.indexOf('|',startfrom) + 1 ;
            
            // if startfrom = 0 we've reached the end of file
            if ( startfrom == 0 )
            {
                break;
            }
        }
        

      
        endat =  arrAutoMMIntl.indexOf('|',startfrom) - 1 ;
        
     
        // this should never happen but if it does we exit
        if ( endat == -2 )
        {
           break;
        } 
           
        sAuto  = arrAutoMMIntl.substr(startfrom,endat - startfrom + 1);

        sValue = sValue + 1 ;
             
        appendOption('quote_form_Make',sAuto,sValue) ;
   
        startfrom = endat + 2;
               
    } 

}

function BuildModelSelect(value)
{
    // cleardown current options and add select
    document.getElementById('quote_form_Model').length = 0;
    appendOption('quote_form_Model',"Model","Model") ;

    var sModel = '';
    var sModelCode = 0 ;
    
    startfrom = ("|" + arrAutoMMIntl).indexOf('|' + value + '|') + value.length + 1;
            
    endat = arrAutoMMIntl.indexOf('|',startfrom);
    
    sModels = arrAutoMMIntl.substr(startfrom,endat - startfrom);
    
    startfrom = 0 ;
    
    while(startfrom<sModels.length)
    {
    
      if ( startfrom > 0 )
      {
      startfrom = sModels.indexOf('^',startfrom) + 1 ;
      }
      
      endat =  sModels.indexOf('^',startfrom) - 1 ; 
      
      if ( endat == -2 )
      {
            endat = sModels.length ;
      }
      
      sModel  = sModels.substr(startfrom,endat - startfrom + 1);

      sModelCode = sModelCode + 1 ;

      appendOption('quote_form_Model',sModel,sModelCode) ;
 
   
      startfrom = endat;
       
    }
        

} 
function ShowHideDepartState(DepartureCountry) {

	if (DepartureCountry == 'United States of America') {
	    Hide('Normal_Description');
	    Show('USA_Description') ;
	    Show('quote_form_DepartStateSection') ;
	    Hide('quote_form_Departure_City_Section') ;
	    }	
	else {
	    Show('Normal_Description');
	    Hide('USA_Description') ;
	    Show('quote_form_Name_Section') ;
	    Hide('quote_form_DepartStateSection') ;
	    Show('quote_form_Departure_City_Section') ;
	     }

	Show('quote_form_Tel_Number_Section') ;
}

function ShowHidePackingDescription(PackingOption) {

	if (PackingOption == 'Other') {
		Show('quote_form_Packing_Description_Section') ;
	    Focus('quote_form_Packing_Description'); 
	    }	
	else {
	    Hide('quote_form_Packing_Description_Section') ;
	    Focus('quote_form_Moving_Month');	
	     }
}

function ShowHideArriveState(ArrivalCountry,DepartureCountry) {

	if (ArrivalCountry == 'United States of America') 
	    {  Show('quote_form_ArriveStateSection') ;
	        
	        if ( NotPersonalEffects()) {
	            Hide('quote_form_Arrival_City_Section') ; }
        }
	else {
		Hide('quote_form_ArriveStateSection') ;
		Show('quote_form_Arrival_City_Section') ;
	    
	    if (DepartureCountry == 'United States of America' && 
	        NotPersonalEffects()) 
	        {
	        /* Add Tel Number 250209 */
	        /* Start 
	        Hide('quote_form_Tel_Number_Section') ;
	        End */
	        Hide('quote_form_Name_Section') ; 
	        }
	    else {
	    	Show('quote_form_Tel_Number_Section') ;
	        Show('quote_form_Name_Section') ; 
	        }	       
	    }
}

function GoToInterstate(ArrivalCountry,DepartureCountry) {

	if (ArrivalCountry == 'United States of America' && 
        DepartureCountry == 'United States of America' &&
	    window.location.href.indexOf('uote.aspx') == -1 ) {
        if ( confirm('Ooops! This form is for International Car Shipping only. If you are shipping within the US click OK to go to our Interstate quote form or CANCEL to continue with your overseas enquiry.') ) {
                     window.location='Car_Movers_Auto_Transport_USA.html'; }
	    } 
}

function HideSections(theValue) {
   
    if (theValue != 'United States of America') {
     Show('Normal_Description');
	    Hide('USA_Description') ;
        Hide('quote_form_DepartStateSection') ; 
        Show('quote_form_Departure_City_Section') ; 
        }
    else {
      Hide('Normal_Description');
	    Show('USA_Description') ;
        Show('quote_form_DepartStateSection') ; 
        if ( NotPersonalEffects() ) {
            Hide('quote_form_Departure_City_Section') ; } 
        }            
 
    if ( document.getElementById('quote_form_Arrive_Country_Section') != null ) {
      Hide('quote_form_ArriveStateSection') ; 
      }
   
    if (NotPersonalEffects()) {
        Hide('quote_form_Arrival_City_Section') ;
        Hide('quote_form_Confirm_Email_Section') ; }
 
    /* If the arrive country section is there this is not an interstate lead so
    we hide the name and telephone number unless this is
    a personal effects lead so we show them */
   
    if ( document.getElementById('quote_form_Arrive_Country_Section') != null &&
        NotPersonalEffects() )
    {
        Hide('quote_form_Name_Section') ;
        Hide('quote_form_Tel_Number_Section') ; 
        }
      
    Focus('quote_form_Shipment_Type') ;
}

function ValidatePage() {

    message = '';
    progress = true ;
    
    if (document.getElementById('quote_form_Shipment_Type').selectedIndex==0) {
           progress = false;
            message = 'Please tell us what you are shipping';
        }

    if (document.getElementById('USA_Description').style.display != 'none' ) {
   if (document.getElementById('quote_form_Make').selectedIndex==0) {
           progress = false;
            message = 'Please tell us the Make';
        }
        
           if (document.getElementById('quote_form_Model').selectedIndex==0) {
           progress = false;
            message = 'Please tell us the Model';
        }
        }
        
    if (document.getElementById('quote_form_Description_of_Goods').value=='') {
           progress = false;
            message = message + '\nPlease enter a Make/Model or Description';
        }

    if (document.getElementById('quote_form_Moving_Month').selectedIndex==0) {
           progress = false;
            message = message + '\nPlease tell us when you are moving';
        }

    if (document.getElementById('quote_form_Depart_Country').selectedIndex==0) {
           progress = false;
            message = message + '\nPlease tell us where you are shipping from';
        }

    if (document.getElementById('quote_form_DepartStateSection').style.display != 'none' ) {
        if (document.getElementById('quote_form_Depart_State').selectedIndex==0) {
            progress = false;
            message = message + '\nPlease select a departure state';
            }
        }

    if (document.getElementById('quote_form_Arrive_Country').selectedIndex==0) {
           progress = false;
            message = message + '\nPlease tell us where you are shipping to';
        }

    if (document.getElementById('quote_form_ArriveStateSection').style.display != 'none') {
        if (document.getElementById('quote_form_Arrive_State').selectedIndex==0) {
            progress = false;
            message = message + '\nPlease select an arrival state';
            }
        }

    if (document.getElementById('quote_form_Email').value=='') {
           progress = false;
            message = message + '\nPlease enter an email address';
        }

    if (document.getElementById('quote_form_Confirm_email').value=='') {
           progress = false;
            message = message + '\nPlease confirm your email address';
        }

    if (document.getElementById('quote_form_Email').value != document.getElementById('quote_form_Confirm_email').value) {
           progress = false;
            message = message + '\nThe email addresses you entered do not match, please re-enter';
        }

          
    if (progress == false) {alert(message);}
    return progress;
}

function OpenCalculator() {
    openWindow = window.open("calculator.htm","Calculator","width=600,height=600,scrollbars=yes");
}

function updateVolume(volume) {
    document.getElementById('quote_form_Size').value=volume;
    document.getElementById('quote_form_Measurement').selectedIndex=1;
    Focus('quote_form_Moving_Month');
}

function updateItemsString(items) {
    document.getElementById('quote_form_Extra_Information').value= items ;
}

