// JavaScript Document

function vanNo(char,target){
	var char = char.toLowerCase();
	if(element('pref').value==''){
		element('pref').value=''+element('pre').value+'';
	}
	string = char.replace( /[\.\~\^\&\+\=\`\%,;!@*#\$\/:\?'\(\)\[\]_\-\\]/g," ");
	string = string.replace( /[a|b|c]/g,"2");
	string = string.replace( /[d|e|f]/g,"3");
	string = string.replace( /[g|h|i]/g,"4");
	string = string.replace( /[j|k|l]/g,"5");
	string = string.replace( /[m|n|o]/g,"6");
	string = string.replace( /[p|q|r|s]/g,"7");
	string = string.replace( /[t|u|v]/g,"8");
	string = string.replace( /[w|x|y|z]/g,"9");
	target.innerHTML = string;
}
function element(id){
	return document.getElementById(id);
}

function navOn(id){
	element(id).className='nav2';
}
function navOff(id){
	element(id).className='nav1';
}
function valWN(no){
	str = element(no).value;
	str = str.replace(' ','');
	nolen = str.length;
	
	if(element(no).value && trim(element(no).value) != '' && nolen > 5){
		return true; } else { 
		if(!element(no).value || trim(element(no).value) == ''){
			alert('Please enter your desired Word Number');
		}
		if(nolen < 6){
			alert('Please enter at least 6 characters');
		}
		return false; }
	
}

function checkContact(theform){

var error = "";
/*//*/
error += dropdown(theform.title,"Please select your Title");
error += isBlank(theform.name.value,"Please enter your Name");
error += isBlank(theform.surname.value,"Please enter your Surname");
error += isEmptyNum(theform.tel.value,"Please enter a valid Phone Number");
error += checkEmail(theform.email.value,"Please enter a valid Email Address");
error += isBlank(theform.city.value,"Please enter your Nearest City");
error += isBlank(theform.comments.value,"Please enter your Comments / Questions");

if(error != ""){ alert(error); return false; }  // else { return true; }
}
function checkApp(theform){

var error = "";
/*//*/
//alert(theform.regions.length);
error += isBlank(theform.word.value,"Please enter your desired Word Number");
//error += boxedArr(theform.regions,"Please select at least one Region");
error += dropdown(theform.title,"Please select your Title");
error += isBlank(theform.name.value,"Please enter your Name");
error += isBlank(theform.surname.value,"Please enter your Surname");
error += isBlank(theform.company.value,"Please enter your Company Name");
error += isEmptyNum(theform.tel.value,"Please enter a valid Phone Number");
error += checkEmail(theform.email.value,"Please enter a valid Email Address");
error += checkChecked('terms',"You must agree to the Terms and Conditions.");
if(error != ""){ alert(error); return false; } // { return false; }
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
 
function checkChecked(field,message){
	var error = "";
	if(!element(field).checked){
		error = message + "\n";
	}
	return error;
	
}function boxedArr(field,message){
	 field = new Array();
	 
	var error = "";
		var total=0
		for(var i=0; i < field.length; i++){
		if(field[i].checked)
		total++;
		}
		if(total=="" || !total) { error = message+"\n"; }
	 
	return error;
	 
 }
function isBlank(str,msg){
	var error = "";
	str = trim(str)
	if(str.length == 0){ error = msg +'\n'; }
	return error;
	}

function fieldmatch(str1,str2,msg){
	var error = "";
	if(str1 != str2){
	error = msg +'\n';
	}
	return error;

}



function checkEmail (strng,msg) {
var error="";
	if (isBlank(strng)) { error = msg + "\n"; }
	
		var emailFilter=/^.+@.+\..{2,3}$/;
		if (!(emailFilter.test(strng))) { error = msg + "\n"; }
		else {
		   var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
			 if (strng.match(illegalChars)) { error = msg + "\n"; }
		}
	return error;    
}

function isEmptyNum(strng,msg) {
var error = "";
	if (isBlank(strng)) { error = msg + "\n"; } else {
		   var illegalChars= /[\@\<\>\,\;\:\\\"\[\]]/
			 if (strng.match(illegalChars)) { error = msg + "\n"; }
		}
	return error;	  
}
function valNum(strng,msg) {
var error = "";
	if(strng.length != 0){
		   var illegalChars= /[\@\<\>\,\;\:\\\"\[\]]/
			 if (strng.match(illegalChars)) { error = msg + "\n"; }
	}
	return error;	  
}


function radio(radiobut,strng){
var error = "";
var radio_choice = false;
for (i = 0; i < radiobut.length; i++){
if (radiobut[i].checked)
radio_choice = true; 
}
if (!radio_choice){ error = ""+strng+"\n"; }
return error; }

function dropdown(menu,strng){
var error = "";
 if ( menu.selectedIndex == 0 )
    {
        error = strng+" \n";
        valid = false;
    }
	return error; }
	


function toggleLayer(whichLayer){
if (document.getElementById) {
	// this is the way the standards work
	var style2 = document.getElementById(whichLayer).style;
	style2.display = style2.display? "":"block";
}
else if (document.all){
	// this is the way old msie versions work
	var style2 = document.all[whichLayer].style;
	style2.display = style2.display? "":"block";
} else if (document.layers) {
	// this is the way nn4 works
	var style2 = document.layers[whichLayer].style;
	style2.display = style2.display? "":"block"; }
}

function dropother(menu,layer){
 if ( menu.selectedIndex == 1 ){
 	toggleLayer(layer); } else { 	
	if(document.getElementById(layer).style.display == "block"){
 	toggleLayer(layer); } }

}
