
function isBlank(s){
	for(var i=0; i<s.length; i++){
		var c=s.charAt(i);
		if((c!='')&&(c!='\n')&&(c!='\t'));
			return false;
	}
	return true;
}

function getCountry(fname) {
	var i = 0;
	i = fname.country.selectedIndex;
//	alert(" slected index="+i+"\n value="+ fname.country.options[i].value +"\n text = "+ fname.country.options[i].text);
	fname.cunt.value = "" + fname.country.options[i].text;
	}	

function valid(formName){

<!-- all were going to test here is the basics, null entries etc for all mandatory fields this is not specific to this form -->
var errMsg="";
var emptyFields="";
var errors="";
var emailmsg="";
var dateerrors="";
var selectErr="";
var eFlag=false;

<!-- check that at least one interest has been selected on the freebook form -->
	
	if(formName.id=="freebook"){

		if (	!formName.int1.checked && 
			!formName.int2.checked && 
			!formName.int3.checked && 
			!formName.int4.checked && 
			!formName.int5.checked && 
			!formName.int6.checked && 
			!formName.int7.checked       ) 
			
		errors += "- Please choose at least one interest";
	}
		

for(var i=0;i<formName.length;i++){
	var e=formName.elements[i];
	
		
	//alert("the type is "+e.type+"\n optional : "+!e.optional);
	<!-- check for empty fields -->
	if(((e.type=="text") || (e.type=="textarea")) && e.required != "false"){
		if((e.value==null) || (e.value=="") || isBlank(e.value)){
		emptyFields += "\n    "+e.message;
		continue;
		}
	}
	
	<!-- check any select comboboxes etc are not "0" -->
		if(e.type=="select-one"){
		if(e.options[e.selectedIndex].value == "0"){
		eFlag=true;
		selectErr += "Please make a selection for "+e.message+"\n";
		}
			else {}
	
		}
	
	
	<!-- check email field contains an @ symbol and a '.' after the '@'-->
	if (e.email){
		if((e.type=="text") || (e.type=="textarea") && (!isBlank(e.value))){			
			//check for presence of @ returns -1 if not in string
			strEmailAddress = e.value;
			var positionAT=strEmailAddress.indexOf("@");
			var positionDot=strEmailAddress.lastIndexOf(".");
						
			if (positionAT<1 || positionDot <1 || (positionDot < positionAT)){
				emailmsg+="- Invalid email address";	
				eFlag=true;

			}
		}
	}
	
	<!-- check numeric fields -->
		if (e.numeric || (e.min !=null) || (e.max !=null)){
			// chop spaces and '-' from telephone numbers
			var tmp = e.value.replace(/ /g,"");
			tmp = tmp.replace(/-/g,"");
			var v = parseFloat(tmp);
			var num = isFinite(tmp);
			//alert (tmp+":"+v);
			if((num==false) || ((e.min != null) && (v < e.min)) || ((e.max != null) && (v > e.max))) {
				eFlag=true; //this if is tru if any error
				errors += "- The field "+ e.name + " must be a number";
				
				if (e.min != null)
					errors += "that is greater than " + e.min;
				if ((e.max != null) && (e.min != null))
					errors += " and less than " + e.max;
				else if(e.max != null)
					errors += " that is less than " + e.max;
					errors += ".\n";
			}
		}
	
		if (e.datefield){
		 //check for length of string to allow yyyy    mm/yy    m/yy  yy date formats as well as dd/mm/yy & dd/mm/yyyy
		    if (e.value){
				strLength = (e.value).length
				strdate = e.value
				switch(strLength){
						case 2:
							strdate = '01/01/' + e.value;
						break;
						case 4:
							if (strdate.indexOf('/')>-1){
								strdate = '01/' + e.value;
							}else{
								strdate = '01/01/' + e.value;
							}
						break;
						case 5:
							strdate = '01/' + e.value;
						break;
					}   
    
				    // NaN is never equal to itself.
					if (Date.parse(strdate) != Date.parse(strdate)){
					    if(dateerrors){
							dateerrors+="\n    "+e.message
						}else{
							eFlag=true;
							dateerrors+='\n-Invalid date format in the following field(s)'
							dateerrors+="\n    "+e.message
						}
					}else{
					    invdate = true; 
					}
			}else{
				invdate = true; //
			}	
	//alert(strdate);
	
		}

}


if(!emptyFields && !errors && !emailmsg && !eFlag) {
	
	alert ('Thank you, your form has been submitted. We will be in touch with you as soon as possible') ;
	return true;

}

   msg="" ;
// msg+="------------------------------------------------------------------------------------------------\n";
// msg+="The form was not submitted because of the following error(s).\n";
   msg+="Please correct these errors and re-submit:\n";
// msg+="------------------------------------------------------------------------------------------------\n";

if(emptyFields){
//	msg+="-The following required field(s) are empty:" 
	msg+= emptyFields +"\n";
	if(errors) msg +="\n";
}
errors += dateerrors

if(errors){	msg += errors}

if(emailmsg !=""){msg += "\n"+emailmsg}

if(selectErr !=""){msg += "\n"+selectErr}

alert(msg);
return false;
}

