// JavaScript Document

function valid(evt, ln) {
	var interdit = "\`\²\%\*\,\.\?\;\:\§\!\#\$\£\¤\(\)\~\/\\\'\=\+\{\}\[\]|^@&\"\"\<\>©®ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ°-";
    Result = true;
	if (ln == "0") {
		var keyCode = evt.which ? evt.which : evt.keyCode;
		if (keyCode==9) return true;
		if (interdit.indexOf(String.fromCharCode(keyCode)) >= 0) {
			return false;
		}
	}
	else
	{
      strValidChars= interdit
      ElemV   = ln.value.toUpperCase();
      var blnResult= true;
          for (i = 0; i < ElemV.length && blnResult == true; i++)
          {
                strChar = ElemV.charAt(i);
                  if (strValidChars.indexOf(strChar) >=0)              
                    {    blnResult = false;
                     alert("Detected Speechless character");
                      ln.value = ln.value.substr(0,i);    
					  ln.focus();      
                    }
          }  
   }
}

function verif_formulaire()
{
 var reg_session = /^[a-zA-Z0-9\s-]+$/;

if(!(reg_session.test(document.forms[0].txtName.value))) {
   alert("The name of session contains not valid characters!");
   return false;
  }
if(document.form0.txtName.value == "") {
   alert("Please give a name to session!");
   return false;
  }
if(document.form0.txtDate.value == "") {
   alert("Please give the day of start of session one!");
   return false;
  }
var date_session=/^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$/;
if(!(date_session.test(document.forms[0].txtDate.value))) {
   alert("Invalid date of start of session one!");
   return false;
  }
if(document.form0.txtHour.value == "") {
   alert("Please give the hour of start of session one!");
   return false;
  }
var heure_session= /^(([0-1][0-9])|([2][0-3])):([0-5][0-9]):([0-5][0-9])$/;
if(!(heure_session.test(document.forms[0].txtHour.value))) {
   alert("Invalid hour of start of session one!");
   return false;
  }
if(document.form0.txtHour.value == "00:00:00") {
   alert("00:00:00 is invalid hour of start of session one!");
   return false;
  }
if(document.form0.txtHour.value == "##:##:##") {
   alert("##:##:## is invalid hour of start of session one!");
   return false;
  }
if(document.form0.cmbPays1.value == "-1") {
   alert("Please fill all the fields of the first stage one !");
   return false;
  }
if(document.form0.cmbES1.value == "-1") {
   alert("Please fill all the fields of the first stage one !");
   return false;
  }
if(document.form0.checkConfirm.checked == false) {
   alert("Please confirm all your selections !");
   return false;
  }
}

function MC(PAYS,MOD,ES,METEO,NUIT){
var pays = MM_findObj(PAYS);
var mod = MM_findObj(MOD);
var es = MM_findObj(ES);
var meteo=MM_findObj(METEO);
var nuit=MM_findObj(NUIT);
var info="";
i = mod.selectedIndex;
j = pays.selectedIndex;
k = es.selectedIndex;
m = meteo.selectedIndex;
n = nuit.selectedIndex;


//RallySchool 1 et 2
if (j==2 && (k==7 || k==8) && (m==1 || m==2 || m==3)){
	meteo.selectedIndex=5;
	info=info+"Stage Rallychool : weather modified, Covered 'Damp' selected !\n"; 
}

//Australie
if (j==3 && m==1){
	meteo.selectedIndex=0;
	info=info+"Country Australie : Bad conditions unavailable, Good Conditions selected !\n"; 
}

//Monte-Carlo
if (i==5 && j!=4 && j!=0){
	mod.selectedIndex=0;
	info=info+"Monte-Carlo Mod unavailable, Tarmac Mod selected !\n"; 
}

//Rallysprint
if (j==7 && k==4 && i!=3){
	mod.selectedIndex=3;
	info=info+"Stage Rallysprint : Mod unavailable, Normal Mod selected !\n"; 
}

//Paddys
if (j==7 && k==5 && i!=3){
	mod.selectedIndex=3;
	info=info+"Stage Paddys : Mod unavailable, Normal Mod selected !\n"; 
}
if (j==7 && k==5 && m==1){
	meteo.selectedIndex=0;
	info=info+"Stage Paddys : Bad conditions unavailable, Good Conditions selected !\n"; 
}

//Jourdain
if (j==7 && k==6 && i!=1){
	mod.selectedIndex=1;
	info=info+"Stage Jourdain : Mod unavailable, Gravel Mod selected !\n"; 
}
if (j==7 && k==6 && m==1){
	meteo.selectedIndex=0;
	info=info+"Stage Jourdain : Bad conditions unavailable, Good Conditions selected !\n"; 
}

//Canyon
if (j==7 && k==2 && i==2){
	mod.selectedIndex=0;
	info=info+"Stage Canyon : Snow Mod unavailable, Tarmac Mod selected !\n"; 
}

if (j==7 && k==2 && m==1){
	meteo.selectedIndex=0;
	info=info+"Stage Canyon : Bad conditions unavailable, Good Conditions selected !\n"; 
}

// Fraizer 2

	if (j==6 && k==8 && (m>0 && m<6)){
	meteo.selectedIndex=0;
	info=info+"Stage Fraizer Wells 2 : Bad, Damp and Fog unavailable, Good Conditions selected !\n"; 
}


// Sipirkakim 2
if (j==5 && k==7 && (m>0 && m<6)){
	meteo.selectedIndex=0;
	info=info+"Stage Sipirkakim 2 : Bad, Damp and Fog unavailable, Good Conditions selected !\n"; 
}


//SS18
if (j==9 && k==4 && i!=3){
	mod.selectedIndex=3;
	info=info+"Stage SS18 : Mod unavailable, Normal Mod selected !\n"; 
}
if (j==9 && k==4 && m!=0){
	meteo.selectedIndex=0;
	info=info+"Stage SS18 : Weather unavailable, Good Conditions selected !\n"; 
}

//slalom plp
if (j==9 && k==5 && i!=3){
	mod.selectedIndex=3;
	info=info+"Stage Slalom PLP : Mod unavailable, Normal Mod selected !\n"; 
}
if (j==9 && k==5 && m!=0){
	meteo.selectedIndex=0;
	info=info+"Stage Slalom PLP : Weather unavailable, Good Conditions selected !\n"; 
}

//Lyon Gerland
if (j==9 && k==6 && i!=3){
	mod.selectedIndex=3;
	info=info+"Stage Lyon Gerland : Mod unavailable, Normal Mod selected !\n"; 
}
if (j==9 && k==6 && m!=6){
	meteo.selectedIndex=6;
	info=info+"Stage Lyon Gerland : Weather unavailable, Cloudy 'Dry' selected !\n"; 
}

//Ireland 
if (j==10 && i!=3){
	mod.selectedIndex=3;
	info=info+"Country Ireland : Mod unavailable, Normal Mod selected !\n"; 
}
if (j==10 && m!=0){
	meteo.selectedIndex=0;
	info=info+"Country Ireland : Weather unavailable, Good Conditions selected !\n"; 
}

//BTB
if ((j==11 || j==12 || j==14) && i!=3){
	mod.selectedIndex=3;
	info=info+"BTB Stages : Mod unavailable, Normal Mod selected !\n";
}
if ((j==11 || j==12 || j==14) && m!=0){
	meteo.selectedIndex=0;
	info=info+"BTB Stages : Weather Good Conditions only !\n";
}
if ((j==11 || j==12 || j==14) && n!=0){
	nuit.selectedIndex=0;
	info=info+"BTB Stages : Night Mod unavailable !\n";
}

//Finland Autiovaara et Autiovaara 2
if (j==1 && n==2 && (k==4 || k==8)){
	nuit.selectedIndex=0;
	info=info+"Autiovaara and Autiovaara II, not in Dusk Mod, Daylight selected !\n";
}

//Slovakia
if (j==13 && i!=3){
	mod.selectedIndex=3;
	info=info+"Country Slovakia : Mod unavailable, Normal Mod selected !\n"; 
}

	Choix(PAYS,ES);
	
	if (info.length!=0) alert(info);
}

function WN(WEATHER,NIGHT){
var weather = MM_findObj(WEATHER);
var night = MM_findObj(NIGHT);
i=weather.selectedIndex;
j=night.selectedIndex;
if (i>1 && j>0) {
	weather.selectedIndex=0;
	alert("Night and Dusk Mod: Night and Dusk Mod in Good, Bad Conditions only, Good Conditions selected !");
}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function Choix(form1,objName) {
var cmb = MM_findObj(form1);
var obj = MM_findObj(objName);
i = cmb.selectedIndex;
if (i == 0) {
for (i=0;i<15;i++) {
obj.options[i].text="";
obj.options[i].value="";
}
return;
}
switch (i) {
case 1 : var txt = new Array ('Kaihuavaara','Mustaselka','Sikakama','Autiovaara','Kaihuavaara II','Mustaselka II','Sikakama II','Autiovaara II','-- select --','-- select --','-- select --','-- select --'); break;
case 2 : var txt = new Array ('Harwood Forest','Falstone','Chirdonhead','Shepherds Shield','Harwood Forest II','Chirdonhead II','Rally School','Rally School II','Falstone II','Shepherds Shield II','-- select --','-- select --'); break;
case 3 : var txt = new Array ('New Bobs','Greenhills','Mineshaft','East-West','New Bobs II','East-West II','Mineshaft II','Greenhills II','-- select --','-- select --','-- select --','-- select --'); break;
case 4 : var txt = new Array ("Cote d'Arbroz",'Joux Verte','Bisanne','Joux Plane','Joux Verte II',"Cote d'Arbroz II",'Bisanne II','Joux Plane II','-- select --','-- select --','-- select --','-- select --'); break;
case 5 : var txt = new Array ("Noiker",'Sipirkakim','Pirka Menoko','Tanner','Noiker II',"Tanner II",'Sipirkakim II','Pirka Menoko II','-- select --','-- select --','-- select --','-- select --'); break;
case 6 : var txt = new Array ("Fraizer Wells",'Prospect Ridge','Diamond Creek','Hualapai Nation','Prospect Ridge II',"Diamond Creek II",'Hualapai Nation II','Fraizer Wells II','-- select --','-- select --','-- select --','-- select --'); break;
case 7 : var txt = new Array ("Pribram",'Canyon','Pribram R','PTD Rallysprint 1.1','Paddys',"Jourdain",'-- select --','-- select --','-- select --','-- select --','-- select --','-- select --'); break;
case 8 : var txt = new Array ("Cote d'Arbroz v.1",'Joux Verte v.1','Bisanne v.1','Joux Plane v.1','Bisanne v.2',"Joux Verte v.2",'Diamond Creek v.1','Prospect Ridge v.1','Joux Plane v.2','Bisanne v.3','Fraizer Wells v.1','Joux Verte v.3'); break;
case 9 : var txt = new Array ("Pribram S1",'Pribram S2','-- select --','Portugal SS18','RSI - Slalom PLP','Lyon-Gerland','-- select --','-- select --','-- select --','-- select --','-- select --','-- select --'); break;
case 10 : var txt = new Array ("-- select --",'RSI 1','RSI 2','RSI 3','-- select --','-- select --','-- select --','-- select --','-- select --','-- select --','-- select --','-- select --'); break;
case 11 : var txt = new Array ("La Iglesuela",'Casar de Palomero','Pikes Peak','Saint Agreve','San Marcial','Tervaniemi 3KM','Las Majadas','Malaga A7000','Mont Herman','Sweet Lamb','Tervaniemi 15Km','Casar de Palomero Reverse'); break;
case 12 : var txt = new Array ("Olocau-Gatova",'ACCT Ivato','ACCT Ivato Reverse','Arteara-Artedara','Cenovio Valeron Reverse','Sibiu Superspecial','Cercados de Espino','Noidant','Noidant Reverse','Piornal','Voisines','Voisines Reverse'); break;
case 13 : var txt = new Array ("Mlynky Tarmac",'Mlynky Snow','-- select --','-- select --','-- select --','-- select --','-- select --','-- select --','-- select --','-- select --','-- select --','-- select --'); break;
case 14 : var txt = new Array ("Alpes",'Ambrosian Hills','Col de Vaux','Perrogney','ROC','ROC Reverse','Subida a la Manzana','-- select --','-- select --','-- select --','-- select --','-- select --'); break;
}
obj.options[0].text="-- select --";
obj.options[0].value=-1;
for (i=0;i<14;i++) {
obj.options[i+1].text=txt[i];
obj.options[i+1].value=i;
if (txt[i]=="-- select --") {
	obj.options[i+1].value=-1;
}
}
}
