﻿var endHeight = new Array();

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 ShowContent(sItem)
{    
    document.getElementById(sItem).style.overflow = 'auto' ;
}

function HideContent(sItem)
{    
    document.getElementById(sItem).style.overflow = 'hidden' ;
}

function ParseUSNumber(sender, args)
{
   var num = args.Value.replace(/[^\d]/g,'');

   if(num.length != 10) {
        args.IsValid = false;
        return;                    

   } else 
   {
        args.IsValid = true;
        return;   
   }

}

function CheckAreaCode(sender, args)
{
    var num = args.Value.replace(/[^\d]/g,'');
    
   if( sAreaCodes.indexOf(num.substr(0,3)) >= 0 ) 
   {
        args.IsValid = true;
        return;                    

   } else 
   {
     args.IsValid = false;
     return;   
   }

}

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 BuildArrivalCity(value)
{
    // cleardown current options and add select
    document.getElementById('ctl00_quote_form_ArrivalCity').length = 0;
    appendOption('ctl00_quote_form_ArrivalCity',"City","City") ;

    var sCity = '';
    var sCityCode = '';
    
    startfrom = sCityStates.indexOf('|' + value + '|') + value.length + 2;
            
    endat = sCityStates.indexOf('|',startfrom);
    
    sStateCities = sCityStates.substr(startfrom,endat - startfrom);
    
    startfrom = 0 ;
    
    while(startfrom<sStateCities.length)
    {
    
      if ( startfrom > 0 )
      {
      startfrom = sStateCities.indexOf('/',startfrom) + 1 ;
      }
      
      endat =  sStateCities.indexOf('/',startfrom) - 1 ; 
      
      if ( endat == -2 )
      {
            endat = sStateCities.length ;
      }
      
      if ( sCity.length == 0 )
      {
        sCity  = sStateCities.substr(startfrom,endat - startfrom + 1);
      } else
      {
        sCityCode = sStateCities.substr(startfrom,endat - startfrom + 1);
      }
      
      if ( sCityCode.length > 0 )
      {
        appendOption('ctl00_quote_form_ArrivalCity',sCity,sCityCode) ;
        sCityCode = '' ;
        sCity = '' ;
      }     
   
      startfrom = endat;
       
    } 

}  

function ConfirmWorkNumber(value)
{

    if ( value == 'Work' )
    {
        if ( !confirm('Please confirm that you are happy for us to call you at work by clicking OK. If you would not like us to call you at work click CANCEL ans select another option') )
        {
            document.getElementById('ctl00_quote_form_Tel_Number_Type').selectedIndex = 0 ;
        }
    }
}

function BuildMakeSelect()
{    
    // clear down the existing select and add a defaul of select
    document.getElementById('ctl00_quote_form_VehicleMake').length = 0;
    appendOption('ctl00_quote_form_VehicleMake',"Make","Make") ;
    
    startfrom = 0 ;
    sValue = 0 ;
    
    while(startfrom<arrAutoMM.length)
    {

        // if his is the first pass we ignoire start from as the array does no start with a |
        if ( startfrom != 0 )
        {
            startfrom = arrAutoMM.indexOf('|',startfrom) + 1 ;
            
            // if startfrom = 0 we've reached the end of file
            if ( startfrom == 0 )
            {
                break;
            }
        }
        

      
        endat =  arrAutoMM.indexOf('|',startfrom) - 1 ;
        
     
        // this should never happen but if it does we exit
        if ( endat == -2 )
        {
           break;
        } 
           
        sAuto  = arrAutoMM.substr(startfrom,endat - startfrom + 1);

        sValue = sValue + 1 ;
             
        appendOption('ctl00_quote_form_VehicleMake',sAuto,sValue) ;
   
        startfrom = endat + 2;
               
    } 
}

function BuildModelSelect(value)
{
    // cleardown current options and add select
    document.getElementById('ctl00_quote_form_VehicleModel').length = 0;
    appendOption('ctl00_quote_form_VehicleModel',"Model","Model") ;

    var sModel = '';
    var sModelCode = 0 ;
    
    startfrom = ("|" + arrAutoMM).indexOf('|' + value + '|') + value.length + 1;
            
    endat = arrAutoMM.indexOf('|',startfrom);
    
    sModels = arrAutoMM.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('ctl00_quote_form_VehicleModel',sModel,sModelCode) ;
 
   
      startfrom = endat;
       
    } 

}  

function ClearTextBox(sElement,sValue)
{
   if   ( sElement.value.length == 0 )
        {
          sElement.value = sValue ;
        }
   else {
       
   // the textbox onclick event calls this to clear down a textbox when it is first clicked on
        if ( sElement.value == sValue )
            {
             sElement.value = "" ;
            }
        }
}

function ToggleContent(sItem,sHeight)
{    
    if  ( sHeight == '0' ) {
    // removeattribute doesn't seem to work in anything other than IE
    if  ( document.getElementById(sItem).style.removeAttribute ) 
    {
        document.getElementById(sItem).style.removeAttribute('height');
        }
        else
        { 
            document.getElementById(sItem).style.overflow = 'auto' ; }
    }
    else {
        endHeight[sItem] = document.getElementById(sItem).offsetHeight;
        document.getElementById(sItem).style.height = sHeight; }
}

