
//----------  This file makes use of the file driversLicense.js, irp.js, licenseTheft.js, vehicleLicensePlate.js, and generalJava.js  -----------------//
  
  var theRoot_Path = '/dmv/';
  
  officearray= new Array();  //office names
  addressarray= new Array(); //office addresses
  
  document.write('<script src="'+theRoot_Path+'java/offices/categories/vehicleLicensePlate.js"></' + 'script>');
  document.write('<script src="'+theRoot_Path+'java/offices/categories/licenseTheft.js"></' + 'script>');
  document.write('<script src="'+theRoot_Path+'java/offices/categories/irp.js"></' + 'script>');
  document.write('<script src="'+theRoot_Path+'java/offices/categories/driversLicense.js"></' + 'script>');
  document.write('<script src="'+theRoot_Path+'java/offices/categories/stateOffices.js"></' + 'script>');


//-------------------------------------------------------------------------//
  
  function verifyDisable(obj,message){
    disableOfficeSubmit();
    if(obj.disabled && message)alert(message);
    return !obj.disabled;
  }

//-------------------------------------------------------------------------//
  
  var org_Choice;  //global used to retain previous county selection
  
  function disableOfficeSubmit(xceptValue){
	if(document.forms['determineOffice'].pickCounty[document.forms['determineOffice'].pickCounty.selectedIndex].value != 0 && document.forms['determineOffice'].pickCounty.selectedIndex > 0){
	  document.forms['determineOffice'].elements[document.forms['determineOffice'].elements.length - 1].disabled = false;
	}else{
	  document.forms['determineOffice'].pickCounty.selectedIndex = 0;
      document.forms['determineOffice'].elements[document.forms['determineOffice'].elements.length - 1].disabled = true;
    }
	
	if(xceptValue)org_Choice = document.forms['determineOffice'].pickCounty.options[document.forms['determineOffice'].pickCounty.selectedIndex].text;
  }
  
//-------------------------------------------------------------------------//

  
  //-- Limits Counties, Dependent upon Office Type
  function limitCounties(officeType){
    
    var arraySection;
    var recordErrors;
    var write_Option;
    var tempValue;
    
    var increment = 0;
    
    //sets the previous county selected if it isn't "Select-A-County"
    if(document.forms['determineOffice'].pickCounty.selectedIndex > 0){
      org_Choice = document.forms['determineOffice'].pickCounty.options[document.forms['determineOffice'].pickCounty.selectedIndex].text;
    }
    
    //deletes the previous drop-down list
    if(document.forms['determineOffice'].pickCounty.options.length>1){
      for(var i=document.forms['determineOffice'].pickCounty.options.length; i>0; i--){document.forms['determineOffice'].pickCounty.options[i] = null;}
    }
    
    
    if(officeType==1)arraySection = 0;
    if(officeType==2)arraySection = 100;
    if(officeType==3)arraySection = 200;
    if(officeType==4)arraySection = 300;
	if(officeType==5)arraySection = 400;
    
    
    //create a new drop-down list and preSelects a county if one was already chosen
    for(var i=arraySection; i<arraySection+100; i++){     
      if(addressarray[i]){
        if(addressarray[i][0] && addressarray[i][1] && addressarray[i][2]){
          write_Option = trim_String(addressarray[i][0]).split(" ");
          
          tempValue = "";
          
          for(var j=0; j<write_Option.length-1; j++){tempValue += " "+write_Option[j];}
          write_Option = tempValue;
          
          recordErrors = 0;

          if(!write_Option)recordErrors+=1;
      
          tempValue = i+1-recordErrors;
          increment = increment+1-recordErrors;
          document.forms['determineOffice'].pickCounty.options[increment] = new Option(write_Option,tempValue,false,false);
          
		  
          if(document.forms['determineOffice'].pickCounty.options[increment].text==org_Choice){
            document.forms['determineOffice'].pickCounty.options[increment].selected = true;
          }else{
            document.forms['determineOffice'].pickCounty.options[increment].selected = false;
            //disableOfficeSubmit();
          }
          disableOfficeSubmit();
	    }
      }
	}  
  }

//-------------------------------------------------------------------------//

  
  //-- Write the Office Address
  function writeOffices(){
    
    detectQueryString();
    
    var writeString;
    
    function create_TableCell(classType,columnSpan,cellContents){writeString += '<tr><td class="'+classType+'" colspan="'+columnSpan+'" valign="top">'+cellContents+'</td></tr>';}
    
    if(location.search){
      var    officeType = queryArray[0]-1;
      var    whatCounty = queryArray[1]-1;
      var addressLength = addressarray[whatCounty].slice(1);
      var  officeNumber = 0;
      var     tempValue;
      
      
      writeString ='<table class="displayoffice" width="100%" cellpadding="15" cellspacing="0" border="1">' //Starts Outer Table
	              +'<tr><td align="center">'
	              +'<table width="100%" cellpadding="0" cellspacing="1" border="0">';                       //Starts Inner Table
      
      
      create_TableCell('f17darkblue',2,'<b>'+trim_String(officearray[officeType])+'</b>');    //Officetype
	  create_TableCell('f16orange',2,'<b>'+trim_String(addressarray[whatCounty][0])+'</b>');  //County
	  create_TableCell('',2,'<br>&nbsp;');
      
  
      for(var i=1; i<addressLength.length+1; i++){
        
        tempValue = trim_String(addressarray[whatCounty][i]);
        
        if(tempValue.replace(/ */g,"")){
        
          //- writes office name
          if((i%5)==1)create_TableCell('f12darkblue',1,'<b>'+(officeNumber+=1)+'.&nbsp;</b></td><td class="f12darkblue" width="270" align="left"><b>'+tempValue+'</b>');


          //- writes address and mapquest link 
          if((i%5)==2){
            
            tempValue = tempValue.split(",");    
            tempValue[0] = trim_String(tempValue[0]);                        //trims blanks after split  
            if(tempValue[1])tempValue[1] = tempValue[1].replace(/ */g,"");   //replace all blanks

            create_TableCell('',2,'<p class="indent"><a href="http://www.mapquest.com/maps/map.adp?city=&state=NC&address='+tempValue[0].split(" ").join("+")+'&zipcode='+tempValue[1]+'&country=us&zoom=6" target="_blank">For driving directions try MapQuest!</a></p>');
            create_TableCell('',2,'<img src="../graphics/pixel.gif" width="1" height="5" border="0" alt="spacer">');
            
            if(tempValue[1] && tempValue[0]){
              create_TableCell('',2,'<p class="indent"><font class="f12darkblue">'+tempValue[0]+', '+tempValue[1]+'</font></p>');
            }else{
              create_TableCell('',2,'<p class="indent"><font class="f12darkblue">'+tempValue[0]+'</font></p>');
            }
          }
        

          //- writes phone numbers, fax numbers, and hours of operation
          if((i%5)==3||(i%5)==4)create_TableCell('',2,'<p class="indent"><font class="f12darkblue">'+tempValue+'</font></p>');
        
        
          //- writes the photo link, if there is one
          if((i%5)==0){
            create_TableCell('',2,'<img src="../graphics/pixel.gif" width="1" height="5" border="0" alt="spacer">');
            create_TableCell('',2,'<p class="indent"><a href="'+tempValue+'" target="_blank">To see a photo of this office, click here.</a></p>');
            create_TableCell('',2,'<br>&nbsp;');  
          }
        }else{
          create_TableCell('',2,'<br><img src="../graphics/pixel.gif" width="1" height="7" border="0" alt="spacer">');
        }
      }
      
      writeString +='</table></td></tr></table>';
      document.write(writeString);
    }
  }
  
  

//-------------------------------------------------------------------------//
