var submitted = 0;

function checkSubmit()
{
  if ( submitted == 0 )
  {
    submitted = 1;
    return true;
  }
  return false;
}

function setSousCat() {
    drawPlaque();
    sbox=document.forms[0].cat;
    tbox=document.forms[0].sousCat;
    var tsel=0;
    for(var i=0;i< tbox.options.length ; i++) {
      if(tbox.options[i].selected) tsel=tbox.options[i].value;
    }
    if(sbox.options[0].selected){
	copyAllOptions(document.forms[0].sousCatAll,tbox);
      }
    if(sbox.options[1].selected){
	setBox4(tbox);
      }
    if(sbox.options[2].selected){
	setBox4(tbox);
      }
    if(sbox.options[3].selected){
	setBox2(tbox);
      }
    if(sbox.options[4].selected){
	setBox1(tbox);
      }
    if(sbox.options[5].selected){
	setBox1(tbox);
      }
    if(sbox.options[6].selected){
	setBox1(tbox);
      }

    for(var i=0;i< tbox.options.length;i++){
      if(tsel==tbox.options[i].value) tbox.options[i].selected=true;
    }
    focusLost();
}

function focusLost(){
//    document.form.cat.blur();
//    document.form.sousCat.blur();
}

function setBox4(tbox) {
var f = document.forms[0];
removeAllOptions(f.sousCat);
f.sousCatAll.options[0].selected = true;
f.sousCatAll.options[1].selected = true;
f.sousCatAll.options[2].selected = true;
f.sousCatAll.options[3].selected = true;
copySelectedOptions(f.sousCatAll,f.sousCat);
sortSelectValue(f.sousCat);
}


function setBox2(tbox) {
var f = document.forms[0];
f.sousCatAll.options[0].selected = true;
f.sousCatAll.options[2].selected = true;
removeAllOptions(f.sousCat);
copySelectedOptions(f.sousCatAll,f.sousCat);
sortSelectValue(f.sousCat);
}

function setBox1(tbox) {
var f = document.forms[0];
f.sousCatAll.options[0].selected = true;
removeAllOptions(f.sousCat);
copySelectedOptions(f.sousCatAll,f.sousCat);
}

function drawPlaque() {
  // following code was temporarily removed because plaque displayed was hard-coded for Valais - but was reinstated on 28/06/2007
  if (typeof query != "undefined"){               // test added to avoid javascript error on results screen 
    if((!isNaN(query.no.value)) && (query.cat)){
       var n=document.forms[0].no.value;
       var c="0";
       for(var i=0;i< document.forms[0].cat.options.length;i++)
           if(document.forms[0].cat.options[i].selected) c=document.forms[0].cat.options[i].value;
       var s="N";
       for(var i=0;i< document.forms[0].sousCat.options.length;i++)
           if(document.forms[0].sousCat.options[i].selected) s=document.forms[0].sousCat.options[i].value;
       drawPlaqueArg(n,c,s);
    }
  }
}

function drawPlaqueArg(n,c,s) {
    if(c=="A" || c=="C" || c=="D") c="1";
    var browser=new Object();
    var agent=navigator.userAgent.toLowerCase();
    browser.msie=(agent.indexOf("msie") != -1);
    browser.nav=(agent.indexOf("mozilla") != -1);
    var doc;
      chiffre=new Array("","","","","","");
      for(var i=5;i>=0;i--){
    	chiffre[i]=(n%10).toString();
	    n=Math.floor(n/10);
	    if(n==0) break;
      }
      var max=0;
      var format="G";
      if(c=="2" || c=="3" || c=="7") {
        format="P";
        max=1;
        }
      if(c=="4"){
        format="L";
        max=1;
      }
      if (c=="21") {
          format="L";
      }
      if(s=="3" || s=="5") max+=2;
      if(s=="2") max+=1;

      // Adaptation nouvelle codification cari
      var ic="";
      if(c=="1") ic="0";
      if(c=="2") ic="1";
      if(c=="3") ic="2";
      if(c=="4") ic="3";
      if(c=="5") ic="4";
      if(c=="6") ic="5";
      if(c=="7") ic="7";
      if(c=="21") ic="8";
      var is="";
      if(s=="1") is="N";
      if(s=="2") is="T";
      if(s=="3") is="U";
      if(s=="5") is="Z";
      if(s=="8") {format="L";ic=8;}
      if(s=="7") {format="L";ic=8;}
      if(s=="6") {format="L";ic=8;}

// <!-- plaque -->
      var h="<HTML><HEAD></HEAD><BODY>";
      if(format=="G") h+="<TABLE width=\"172\" border=\"0\" height=\"92\">";
      if(format=="P") h+="<TABLE width=\"105\" border=\"0\" height=\"78\">";
      if(format=="L") h+="<TABLE width=\"172\" border=\"0\" height=\"44\">";
      h+="<TR>";
      if(format!="L"){
          h+="<td width='30%' height="
          if(format=="G") h+="36";
          if(format=="P") h+="40";
          h+=">&nbsp;</td>" +
             "<td width='30%' align=center style='font-size:32px;font-weight: bold;font-family:Arial Narrow;'>"+cantonCode+"</td>" +
             "<td width='30%' align=center><img src='/cari-online/images/cantons/"+cantonCode.toLowerCase()+".gif'></td>";
          h+="</TR><TR>";
          h+="<TD ALIGN=CENTER colspan=3>";
      }

      if(format=="L") {
          var signColour;
          if (cantonCode=="BE") {
            signColour="green"
          } else {
            signColour="blue"
          }
          switch (s){
          case "8":
              h+="<TR>";
              h+="<td width='20%' align=center><img src='/cari-online/images/special/CD_"+signColour+".gif'></td>";
              h+="<td width='20%' align=center style='font-size:32px;font-weight: bold;font-family:Arial Narrow;'>"+cantonCode+"</td>";
              h+="<TD width='60%' ALIGN=left>";
          break

          case "7":
              h+="<TR>";
              h+="<td width='20%' align=center><img src='/cari-online/images/special/CC_"+signColour+".gif'></td>";
              h+="<td width='20%' align=center style='font-size:32px;font-weight: bold;font-family:Arial Narrow;'>"+cantonCode+"</td>";
              h+="<TD width='60%' ALIGN=left>";
          break

          case "6":
              h+="<TR>";
              h+="<td width='20%' align=center><img src='/cari-online/images/special/AT_"+signColour+".gif'></td>";
              h+="<td width='20%' align=center style='font-size:32px;font-weight: bold;font-family:Arial Narrow;'>"+cantonCode+"</td>";
              h+="<TD width='60%' ALIGN=left>";
          break

          default:
              h+="<TR>";
              h+="<td width='20%' align=center style='font-size:32px;font-weight: bold;font-family:Arial Narrow;'>"+cantonCode+"</td>";
              h+="<TD width='80%' ALIGN=left>";
          break
          }    
      }

// <!-- digits -->
      h+="<table border=0 height=33 cellpadding=0 cellspacing=0><TR>";

      if(format=="L") {
          h+=   "<TD align=left><IMG SRC=\"/cari-online/images/special/N"+ic+"P.gif\"></TD>";
          }
      for(var i=max;i<6;i++){
	  if(chiffre[i]!=""){
//    h+="<TD><IMG SRC=\"/cari-online/images/N"+ic+chiffre[i]+".gif\"></td>";
      h+="<TD align=center style='font-size:32px;font-weight: bold;font-family:Arial Narrow;'>"+chiffre[i]+"</td>";
	  if(i==2) h+="<TD width=\""+((format=="P")?"4":"6")+"\"></td>";
	}
      }
      if(is=="U" || is=="Z") h+="<TD><IMG SRC=\"/cari-online/images/special/N"+ic+"P.gif\"></TD>";
//    if(is=="U" )  h+="<TD><IMG SRC=\"/cari-online/images/N"+ic+is+".gif\"></TD>";
      if(is=="U" )  h+="<TD style='font-size:32px;font-weight: bold;font-family:Arial Narrow;'>"+is+"</TD>";
      if(is=="T" || is=="Z") h+="<TD><IMG SRC=\"/cari-online/images/special/N"+ic+"R.gif\"></TD>";

      h+="</TR></TABLE>";

      h+="</TD>";
      h+="</TR>";
      h+="</TABLE>";

      h+="</BODY></HTML>";

//      alert("cari-online/images/fond"+ic+".gif")
      var hBG="<HTML><HEAD></HEAD><BODY><IMG SRC=\"/cari-online/images/fond"+ic+".gif\" >";
      hBG+="</BODY></HTML>";

/*      if(c=="A" || c=="C" || c=="D" || c=="1" || c=="2" || c=="3" || c=="7" ) {
	 h="<HTML><HEAD></HEAD><BODY></BODY></HTML>";
	 hBG="<HTML><HEAD></HEAD><BODY></BODY></HTML>";
      } */
/*      if((s=="T" || s=="U" || s=="V" || s=="Z") && (c=="4" || c=="5" )) {
	 h="<HTML><HEAD></HEAD><BODY></BODY></HTML>";
	 hBG="<HTML><HEAD></HEAD><BODY></BODY></HTML>";
      } */



   //   if(document.all)               document.all test not valid for Firefox and certain other modern browsers
      if(document.getElementById || document.all)         
    {
	plaqueBG.innerHTML=hBG;
	plaqueFG.innerHTML=h;
	}
      else
	{
	document.plaqueBG.document.open();
	document.plaqueBG.document.write(hBG);
	document.plaqueBG.document.close();
	document.plaqueFG.document.open();
	document.plaqueFG.document.write(h);
	document.plaqueFG.document.close();
	}
}