var arr=[];


/* START EDITABLE ONE - RIVER/AREAS */
arr['IS']=['-- Now choose a Section -- ','ALL','North','East','West','South'];
arr['NO']=['-- Now choose a Section -- ','ALL'];
arr['KO']=['-- Now choose a Section -- ','ALL'];
arr['AA']=['-- Now choose a Section -- ','ALL'];
arr['MF']=['-- Now choose a Section -- ','ALL'];
arr['AY']=['-- Now choose a Section -- ','ALL','Ayr','Doon','Girvan','Stinchar'];
arr['AN']=['-- Now choose a Section -- ','ALL','Lower Annan','Middle Annan','Upper Annan','Tributaries'];
arr['BE']=['-- Now choose a Section -- ','ALL'];
arr['BO']=['-- Now choose a Section -- ','ALL'];
arr['CH']=['-- Now choose a Section -- ','ALL'];
arr['DE']=['-- Now choose a Section -- ','ALL','Lower Dee','Middle Dee','Upper Dee','Feugh'];
arr['BB']=['-- Now choose a Section -- ','ALL'];
arr['DO']=['-- Now choose a Section -- ','ALL','Lower Don','Middle Don','Upper Don'];
arr['ES']=['-- Now choose a Section -- ','ALL','North Esk','South Esk','Other'];
arr['FI']=['-- Now choose a Section -- ','ALL','Lower Findhorn','Middle Findhorn','Upper Findhorn'];
arr['FN']=['-- Now choose a Section -- ','ALL'];
arr['HE']=['-- Now choose a Section -- ','ALL','Lewis','Harris','North Uist','South Uist','Barra'];
arr['GA']=['-- Now choose a Section -- ','ALL','Luce','Bladnoch','Tarf (Bladnoch)','Cree','Minnoch (Cree)','Fleet','Dee','Urr'];
arr['NI']=['-- Now choose a Section -- ','ALL','Lower Nith','Middle Nith','Upper Nith','Tributaries'];
arr['SP']=['-- Now choose a Section -- ','ALL','Lower Spey','Middle Spey','Upper Spey','Avon','Other tributaries'];
arr['TA']=['-- Now choose a Section -- ','ALL','Lower Tay','Middle Tay','Upper Tay','Loch Tay','Earn','Eden','Isla/Ericht','Tummel/Garry','Dochart/Lyon'];
arr['TM']=['-- Now choose a Section -- ','ALL'];
arr['TO']=['-- Now choose a Section -- ','ALL'];
arr['TW']=['-- Now choose a Section -- ','ALL','Bottom Tweed','Lower Tweed','Middle Tweed','Upper Tweed','Whiteadder','Till','Teviot','Ettrick'];
arr['TY']=['-- Now choose a Section -- ','ALL'];
arr['US']=['-- Now choose a Section -- ','ALL'];
arr['BA']=['-- Now choose a Section -- ','ALL'];
arr['FO']=['-- Now choose a Section -- ','ALL'];
/* END EDITABLE ONE */


/* START EDITABLE TWO - ERROR MESSAGES */
	var msgSurname          = "Please enter your Surname";
	var msgSurname_s        = "Please check your Surname. Only alpha characters and spaces are allowed";

	var msgPostcodeA        = "Please enter your Postcode";
	var msgPostcodeB        = "Sorry, but the Postcode you entered is either invalid, or you have omitted the central space";

	var msgriver            = "Please select a River/area";
	var msgsection          = "Please select a Section";

	var msgNoDate           = "Please select both \"Fishing From\" and \"Fishing To\" dates";
	var msgPreDate          = "Your chosen \"Fishing From\" date has already passed. Please adjust your entry and resubmit";
	var msgdiffStrA         = "\"Fishing To\" date must be later than \"Fishing From\" date. Please check your entry and resubmit";
	var msgdiffStrB         = "The maximum registration period is one year. Please adjust your entry and resubmit";
/* END EDITABLE TWO */

function show_div_msg(divname,msgstring){if(divname.length<=0){return false;}if(document.layers){divlayer=document.layers[divname];if(!divlayer){return;}divlayer.document.open();divlayer.document.write(msgstring);divlayer.document.close();}else if(document.all){divlayer=document.all[divname];if(!divlayer){return;}divlayer.innerHTML=msgstring;}else if(document.getElementById){divlayer=document.getElementById(divname);if(!divlayer){return;}divlayer.innerHTML=msgstring;}divlayer.style.visibility="visible";return false;}
function create(s){var root=document.getElementById('section');while(root.hasChildNodes()){root.removeChild(root.childNodes[0]);}if(s.selectedIndex>0){var v=s.value;for(var i=0;i<arr[v].length;i++){var oOpt=document.createElement('option');oOpt.setAttribute('value',[i-1]);oOpt.appendChild(document.createTextNode(arr[v][i]));root.appendChild(oOpt);}}else{var oOpt=document.createElement('option');oOpt.setAttribute('value','');oOpt.appendChild(document.createTextNode('-- 1st choose a river --'));root.appendChild(oOpt);}}
function trimXS(strXS){while(strXS.charAt(0)==(" ")){strXS=strXS.substring(1)}while(strXS.charAt(strXS.length-1)==" "){strXS=strXS.substring(0,strXS.length-1)}return strXS;}
function getCheckedSelectOptions(select){var arr=new Array();for(var i=0,j=0;i<select.length;i++)if(select.options[i].selected)arr[j++]=i;if(arr.length>0)return arr;else return-1;}
function resetStyles(){show_div_msg('Form1_errorloc','');optSN.className="";optPC.className="";optRV.className="";optSC.className="";document.getElementById('popup_container1').className="";document.getElementById('popup_container2').className="";}
function checkForm(){testNumeric=/[0-9]/;testAlpha_s=/[A-Za-z\s]/;testPostcodeUK=/^([A-PR-UWYZ0-9][A-HK-Y0-9][ABCDEFGHJKSTUW0-9]?[ABEHMNPRVWXY0-9]? {1,2}[0-9][ABD-HJLNP-UW-Z]{2}|GIR 0AA)$/;testEmail=/^\+?[a-z0-9](([-+.]|[_]+)?[a-z0-9]+)*@([a-z0-9]+(\.|\-))+[a-z]{2,6}$/;testTel=/[A-Za-z_.@'!"£$%^&*()-]/;
/* " */
optSN=document.Form1.Surname;optPC=document.Form1.Postcode;optRV=document.Form1.river;optSC=document.Form1.section;optDS=document.Form1.date1.value;optDF=document.Form1.date2.value;dfSD=optDS.substring(0,2);dfSM=optDS.substring(3,5);dfSY="20"+optDS.substring(8,optDS.length);dfFD=optDF.substring(0,2);dfFM=optDF.substring(3,5);dfFY="20"+optDF.substring(8,optDF.length);Today_Date=new Date();cDay=Today_Date.getDate();cMth=Today_Date.getMonth()+1;cYer=Today_Date.getYear();Current_Date=new Date(cYer,cMth,cDay);Start_Date=new Date(dfSY,dfSM,dfSD);Finish_Date=new Date(dfFY,dfFM,dfFD);one_day=1000*60*60*24;diffStr=Math.ceil((Finish_Date.getTime()-Start_Date.getTime())/(one_day));preDate=0;preVal=Math.ceil((Start_Date.getTime()-Current_Date.getTime())/(one_day));if(preVal<1){preDate=1}resetStyles();optSN.value=trimXS(optSN.value);strSN=optSN.value;optPC.value=trimXS(optPC.value);strPC=optPC.value.toUpperCase();strRV=optRV.value;strSC=optSC.value;var msg="<ul>\n";var Flag=0,FlagNoDate=0;
if((getCheckedSelectOptions(optRV)==-1)||(getCheckedSelectOptions(optRV)==0)){Flag+=1;msg+="<li>"+msgriver+"</li>\n";optRV.className="badValue";}if((getCheckedSelectOptions(optSC)==-1)||(getCheckedSelectOptions(optSC)==0)){Flag+=1;msg+="<li>"+msgsection+"</li>\n";optSC.className="badValue";}if((optDS=="")||(optDF=="")){FlagNoDate=1;Flag+=1;msg+="<li>"+msgNoDate+"</li>\n";document.getElementById('popup_container1').className="badValue";document.getElementById('popup_container2').className="badValue";}if((FlagNoDate==0)&&(preDate==1)){Flag+=1;msg+="<li>"+msgPreDate+"</li>\n";document.getElementById('popup_container1').className="badValue";}if((FlagNoDate==0)&&(diffStr<=0)){Flag+=1;msg+="<li>"+msgdiffStrA+"</li>\n";document.getElementById('popup_container2').className="badValue";}if((FlagNoDate==0)&&(diffStr>365)){FlagdiffStr=1;Flag+=1;msg+="<li>"+msgdiffStrB+"</li>\n";document.getElementById('popup_container2').className="badValue";}if(strSN==""){Flag+=1;msg+="<li>"+msgSurname+"</li>\n";optSN.className="badValue";}if((strSN!="")&&((!testAlpha_s.test(strSN))||(testNumeric.test(strSN)))){Flag+=1;msg+="<li>"+msgSurname_s+"</li>\n";optSN.className="badValue";}if(strPC==""){Flag+=1;msg+="<li>"+msgPostcodeA+"</li>\n";optPC.className="badValue";}

//msg+= "</ul>";
//msg = "<div id='polishDiv'>" + msg + "</ul></div>";
msg = "<div class='msg_outer'><div class='msg_inner'>" + msg + "</ul></div></div>";


	if(Flag>=1){

	show_div_msg('Form1_errorloc',msg);


//		alert(msg);
	}else{

//		alert("validation passed OK");

//		alert("section No = " + document.Form1.section.value + "selected");

		document.Form1.submit();
	}
}

