
/*----------  This file makes use of the files standard.js, specialInterests.js, military.js, government.js, collegiate.js, civicClubs.js, and generalJava.js --------*/

  
  var theRoot_Path = '/dmv/';
  
  platearray= new Array();          //plate categories
  spclzedPlatesArray = new Array(); //plate descriptions
  
  document.write('<script src="'+theRoot_Path+'java/spclzedPlates/categories/standard.js"></' + 'script>');
  document.write('<script src="'+theRoot_Path+'java/spclzedPlates/categories/specialInterests.js"></' + 'script>');
  document.write('<script src="'+theRoot_Path+'java/spclzedPlates/categories/military.js"></' + 'script>');
  document.write('<script src="'+theRoot_Path+'java/spclzedPlates/categories/government.js"></' + 'script>');
  document.write('<script src="'+theRoot_Path+'java/spclzedPlates/categories/collegiate.js"></' + 'script>');
  document.write('<script src="'+theRoot_Path+'java/spclzedPlates/categories/civicClubs.js"></' + 'script>');
  document.write('<script src="'+theRoot_Path+'java/spclzedPlates/categories/nascar.js"></' + 'script>');

//-------------------------------------------------------------------------//
  
  function verifyDisable(obj,message){
    disablePlateSubmit();
    if(obj.disabled && message)alert(message);
    return !obj.disabled;
  }

//-------------------------------------------------------------------------//
  
  var org_Choice;  //global used to retain previous plate selection
  
  function disablePlateSubmit(xceptValue){
    
	if(document.forms['determinePlate'].pickPlate[document.forms['determinePlate'].pickPlate.selectedIndex].value != 0 && document.forms['determinePlate'].pickPlate.selectedIndex > 0){
	  document.forms['determinePlate'].elements[document.forms['determinePlate'].elements.length - 1].disabled = false;
    }else{
	  document.forms['determinePlate'].pickPlate.selectedIndex = 0;
      document.forms['determinePlate'].elements[document.forms['determinePlate'].elements.length - 1].disabled = true;
    }
	
	if(xceptValue)org_Choice = document.forms['determinePlate'].pickPlate.options[document.forms['determinePlate'].pickPlate.selectedIndex].text;
	
  }
  
//-------------------------------------------------------------------------//


  //special sort for "goofy" dmv nascar second word alphabetizing, who alphabetizes by the second word? who?
	function sortBySecondWord(a, b){
	  var ABlength;
	  a+="";b+="";//convert a and b to strings
	  
	  if(a.length>b.length)ABlength=a.length;
	  if(b.length>a.length)ABlength=b.length;
	  if(a.length==b.length)ABlength=a.length;
	  
	  for(var i=1; i<ABlength+1; i++){
	      A=a.charAt(a.indexOf(" ")+i);
	      B=b.charAt(b.indexOf(" ")+i);
		  if(A!=B)break;
		
		  if(i==ABlength){
		    for(var j=0; j<ABlength; j++){
		      if(a.charAt(j)==a.charAt(a.indexOf(" "))||b.charAt(j)==b.charAt(b.indexOf(" "))){
				//return 0;
				//break;
			  }else{
			    A=a.charAt(j);
	            B=b.charAt(j);
			    if(A!=B)break;
	            if(j==ABlength-1)return 0;
			  }
		    }
		  }
	  }
	  
	  if(A>B)return 1;
	  if(A<B)return -1;
	}

//-------------------------------------------------------------------------//
  
  
  //-- Limits Plates, Dependent upon Plate Type
  function limitPlates(plateType){
    
	   sortedArray = new Array();
	presortedArray = new Array();
	    valueArray = new Array();
	
	var abbreviate;
	
    var arraySection;
    var recordErrors;
    var write_Option;
    var tempValue;
    
    var increment = 0;
    
    //sets the previous plate selected if it isn't "Select-A-Plate"
    if(document.forms['determinePlate'].pickPlate.selectedIndex > 0){
      org_Choice = document.forms['determinePlate'].pickPlate.options[document.forms['determinePlate'].pickPlate.selectedIndex].text;
    }
    
    //deletes the previous drop-down list
    if(document.forms['determinePlate'].pickPlate.options.length>1){
      for(var i=document.forms['determinePlate'].pickPlate.options.length; i>0; i--){document.forms['determinePlate'].pickPlate.options[i] = null;}
    }
    
    
    if(plateType==1)arraySection = 0;
    if(plateType==2)arraySection = 100;
    if(plateType==3)arraySection = 200;
    if(plateType==4)arraySection = 300;
    if(plateType==5)arraySection = 400;
    if(plateType==6)arraySection = 500;
	if(plateType==7)arraySection = 600;
    
    
    //create a new drop-down list and preSelects a plate if one was already chosen
    for(var i=arraySection; i<arraySection+100; i++){     
      if(spclzedPlatesArray[i]){
        if(spclzedPlatesArray[i][0]){
		  
		 sortedArray[i] = trim_String(spclzedPlatesArray[i][0]);

		 //sortedArray[i] += "^"+i;
		 
		 tempValue = "";
		
		 //---- abbreviates North Carolina and United States ----//
		  abbreviate = sortedArray[i].split(" ");
		  
		  for(var j=0; j<abbreviate.length; j++){		
			if(abbreviate[j]=="North" && abbreviate[j+1]=="Carolina"){	  
			  abbreviate[j] = "N.C.";
			  abbreviate[j+1] = "";
			}
			if(abbreviate[j]=="United" && abbreviate[j+1]=="States"){
			  abbreviate[j] = "U.S.";
			  abbreviate[j+1] = "";
			}
		  }

		  presortedArray[i] = trim_String(abbreviate.join(" "));
		     sortedArray[i] = presortedArray[i];
         //-----------------------------------------------------//

		}
	  }
	}
	
	
	if(document.layers){sortedArray.sort();
    }else{
	  if(plateType!=7){sortedArray.sort();
	  }else{sortedArray.sort(sortBySecondWord);}//uses the function sortBySecondWord to define sort parameters
	}
	
	
	for(var i=0; i< sortedArray.length; i++){
	  if(sortedArray[i]){  
        for(var j=arraySection; j<presortedArray.length; j++){
		  if(sortedArray[i]==presortedArray[j])tempValue=j+1;
		}
		  
		increment = i+1;
	    document.forms['determinePlate'].pickPlate.options[increment] = new Option(sortedArray[i],tempValue,false,false);
	  
	    if(document.forms['determinePlate'].pickPlate.options[increment].text==org_Choice){
          document.forms['determinePlate'].pickPlate.options[increment].selected = true;  
        }else{
          document.forms['determinePlate'].pickPlate.options[increment].selected = false;
        }
		  
	    disablePlateSubmit();
	  }
	}
  }

//-------------------------------------------------------------------------//

  
  //-- Write the Plate Information
  function writePlates(){
    
    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    plateType = queryArray[0]-1;
      var    whatPlate = queryArray[1]-1;
	  
	  if(spclzedPlatesArray[whatPlate]){
	  
      var plateDescription = spclzedPlatesArray[whatPlate].slice(1);
      var  plateNumber = 0;
      var     tempValue;
      
      
      writeString ='<table class="displayoffice" width="284" cellpadding="8" cellspacing="0" border="1">'   //Starts Outer Table
	              +'<tr><td align="center">'
	              +'<table width="100%" cellpadding="0" cellspacing="1" border="0">';                       //Starts Inner Table
      
      //Plate Category
      create_TableCell('f16darkblue',2,'<b>'+trim_String(platearray[plateType])+'</b>');
      
      //Plate Name
	  create_TableCell('f16orange',2,'<b>'+trim_String(spclzedPlatesArray[whatPlate][0])+'</b>');
	  create_TableCell('',2,'&nbsp;');
      
      
      //------------------------------  Plate Picture  ------------------------------//
      if(spclzedPlatesArray[whatPlate][12]){
        create_TableCell('',2,'<p align="center"><img src="'+spclzedPlatesArray[whatPlate][12]+'" alt="'+trim_String(platearray[plateType])+'-'+trim_String(spclzedPlatesArray[whatPlate][0])+' Plate" border="0"/></p>');
        create_TableCell('',2,'&nbsp;');
      }
	  if(plateType==2){
	    create_TableCell('',2,'<p align="center"><font class="f12darkblue"><b>Plate not displayed because availability excludes general public.</b></font></p>');
        create_TableCell('',2,'&nbsp;');
	  }
      //------------------------------  End Plate Picture  ------------------------------//
	  
	  writeString +='<tr><td>';
	  
	  //-- Application link
	  if(spclzedPlatesArray[whatPlate][11]){
	    writeString +='<p align="center"><a href="'+trim_String(spclzedPlatesArray[whatPlate][11])+'"><img src="'+theRoot_Path+'graphics/pdf.gif" width="21" height="21" alt="pdf icon" border="0"> <b>Download the Plate Application Here</b></a>';
		writeString +='<br><img src="'+theRoot_Path+'graphics/pixel.gif" width="1" height="7" alt="spacer" border="0"><br>';
		writeString +='<font class="f12darkblue">Need Acrobat?</font> <a href="http://www.adobe.com/prodindex/acrobat/readstep.html" target=_blank>Download it here</a>';
	    writeString +='</p>';
	  }
	  
	  
      
	  //----------------------------------  Fee(s)  ----------------------------------//
	  writeString +='<table align="center" width="100%" cellpadding="3" cellspacing="0" border="1">';
	  writeString +='<tr><td class="color6" colspan="2"><font class="f12darkblue"><b>Yearly Fee(s) in addition to regular fees:</b></font></td></tr>';
	  
	  //-- Regular Fee
	  if(spclzedPlatesArray[whatPlate][2]) writeString +='<tr><td class="" valign="top"><font class="f12darkblue">Regular:</font></td> <td class=""><font class="f12darkblue">'+trim_String(spclzedPlatesArray[whatPlate][2])+'</font></td></tr>';
	  
	  //--  Special Fee
	  if(spclzedPlatesArray[whatPlate][1]) writeString +='<tr><td class="" valign="top"><font class="f12darkblue">Special:</font></td> <td class=""><font class="f12darkblue">'+trim_String(spclzedPlatesArray[whatPlate][1])+'</font></td></tr>';
      
	  //--  Additional/Personalize Fee
	  if(spclzedPlatesArray[whatPlate][7])  writeString +='<tr><td class="" valign="top"><font class="f12darkblue">Personalize:</font></td> <td class=""><font class="f12darkblue">'+trim_String(spclzedPlatesArray[whatPlate][7])+'</font></td></tr>';
	  writeString +='</table>';
	  //----------------------------------  End Fee(s)  ----------------------------------//
	  writeString +='&nbsp;';
	  
	  
	  
	  
	  //---------------------- Returned Portion of Special Fee  --------------------------//
	  if(spclzedPlatesArray[whatPlate][3]){
	    writeString +='<table align="center" width="100%" cellpadding="3" cellspacing="0" border="1">';
	    writeString +='<tr><td class="color6" ><font class="f12darkblue"><b>Returned Portion of Special Fee:</b></font></td></tr>';  
	    writeString +='<tr><td class=""><font class="f12darkblue">'+trim_String(spclzedPlatesArray[whatPlate][3])+'</font></td></tr>';
	    writeString +='</table>';
	  }
	  //---------------------- End Returned Portion of Special Fee  --------------------------//
	  writeString +='&nbsp;';
	  
	  
	  
	  
	  //---------------------------------  Requirements  ---------------------------------//
	  
	  writeString +='<table align="center" width="100%" cellpadding="3" cellspacing="0" border="1">';
	  writeString +='<tr><td class="color6" colspan="2"><font class="f12darkblue"><b>Plate Requirements:</b></font></td></tr>';
	  
	  //-- Prefix/Suffix
	  if(spclzedPlatesArray[whatPlate][4]) writeString +='<tr><td class="" valign="top"><font class="f12darkblue">Prefix/Suffix:</font></td> <td class=""><font class="f12darkblue">'+trim_String(spclzedPlatesArray[whatPlate][4])+'</font></td></tr>';

	  //--  Issued to Whom
	  if(spclzedPlatesArray[whatPlate][8])  writeString +='<tr><td class="" valign="top"><font class="f12darkblue">Issued&nbsp;to Whom:</font></td> <td class=""><font class="f12darkblue">'+trim_String(spclzedPlatesArray[whatPlate][8])+'</font></td></tr>';
	  writeString +='</table>';
	  
	  //---------------------------------  End Requirements  ---------------------------------//  
	  writeString +='&nbsp;';
	  
	  
	  
	  
	  //---------------------------------  Personalized  ---------------------------------//
	  
	  writeString +='<table align="center" width="100%" cellpadding="3" cellspacing="0" border="1">';
	  writeString +='<tr><td class="color6" colspan="2"><font class="f12darkblue"><b>Personalize:</b></font></td></tr>';

	  //--  Special Fee
	  if(spclzedPlatesArray[whatPlate][5]) writeString +='<tr><td class="" valign="top"><font class="f12darkblue">Personalized:</font></td> <td class=""><font class="f12darkblue">'+trim_String(spclzedPlatesArray[whatPlate][5])+'</font></td></tr>';
      
	  //--  Additional Fee
	  if(spclzedPlatesArray[whatPlate][6])  writeString +='<tr><td class="" valign="top"><font class="f12darkblue">Number of Personalized Characters Allowed:</font></td> <td class=""><font class="f12darkblue">'+trim_String(spclzedPlatesArray[whatPlate][6])+'</font></td></tr>';
	  writeString +='</table>';
	  
	  //---------------------------------  End Personalized  ---------------------------------// 
	  writeString +='&nbsp;';
	  
	  
	  
	  
	  //---------------------------------  Description  ---------------------------------//
	  if(spclzedPlatesArray[whatPlate][10]){
	    writeString +='<table align="center" width="100%" cellpadding="3" cellspacing="0" border="1">';
	    writeString +='<tr><td class="color6" ><font class="f12darkblue"><b>Plate Description:</b></font></td></tr>';  
	    writeString +='<tr><td class=""><font class="f12darkblue">'+trim_String(spclzedPlatesArray[whatPlate][10])+'</font></td></tr>';
	    writeString +='</table>';
	  }
	  //---------------------------------  End Description  ---------------------------------//
	  writeString +='&nbsp;';
	  
	  
	  
	  
	  //-------------------------------------  Renewal  -------------------------------------//
	  if(spclzedPlatesArray[whatPlate][9]){
	    writeString +='<table align="center" width="100%" cellpadding="3" cellspacing="0" border="1">';
	    writeString +='<tr><td class="color6" ><font class="f12darkblue"><b>Plate Renewal:</b></font></td></tr>';  
	    writeString +='<tr><td class=""><font class="f12darkblue">'+trim_String(spclzedPlatesArray[whatPlate][9])+'</font></td></tr>';
	    writeString +='</table>';
	  }
	  //-------------------------------------  End Renewal  -------------------------------------//
	  
	  writeString +='<br><br></td></tr>';
      
      writeString +='</table></td></tr></table>';
      document.write(writeString);
    }
	}
  }
  
  

//-------------------------------------------------------------------------//
