<!--
function fvJumpToFrames(){
if (window == top) {top.location.href= "./default.asp?pg=" + getDocName() ;}
}
function getDocName() {
	var docName;var docPath = document.location.pathname;var i = docPath.length - 1;	
	while ((i >= 0) && (docPath.charAt(i) != "/")) {i--;} docName = docPath.substring(i + 1,docPath.length);return docName;
} 
function InitRequiredFormValues(frm) {
	frm.txtSurname.req=true; frm.txtForename.req=true;
	frm.txtPermanentAddress1.req=true;frm.txtPermanentAddress2.req=true;frm.txtPermanentTelephone.req=true;
	frm.txtReferee1Name.req=true;frm.txtReferee1Address1.req=true;frm.txtReferee1Address2.req=true;
	frm.txtReferee2Name.req=true;frm.txtReferee2Address1.req=true;frm.txtReferee2Address2.req=true;
}
function ddjump(folder) {
parent.frames[0].location.href="../" + folder + "/topbar.htm"
}
// -->

strError='';

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 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 fieldErrors="";
var errors="";
var dateerrors="";

for(var i=0;i<formName.length;i++){
	var e=formName.elements[i];
	if (e.req) {
		//<!-- check for empty fields -->
		if((((e.type=="text") || (e.type=="textarea"))||(e.type=="password")) && !e.optional){
			if((e.value==null) || (e.value=="") || isBlank(e.value)){
			emptyFields += "\n    " + e.name.substr(3);
			continue;
			}
		}
	
		//-- 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)){
					errors+="- Invalid email address \n";	

				}
			}
		}
	
		//check for invalid chars
		if(!e.invalidchars){
			charErrors=0;
			temp=e.value
				found = temp.search(/\&/i)
				if (found != -1){
					charErrors = 1;
				}
				found = temp.search(/\*/i)
				if (found != -1){
					charErrors = 1;
				}
				found = temp.search(/\%/i)
				if (found != -1){
					charErrors = 1;
				}
				found = temp.search(/\#/i)
				if (found != -1){
					charErrors = 1;
				}

			if (charErrors ==1){
				fieldErrors += "\n     "+e.name;
				}
		}
	
		//check for an exact field length
		if (e.exactlength){
			if (((e.value).length) != (e.exactlength)){
				errors += "- The field "+ e.name + " must be "+e.exactlength+" characters in length\n";
			}
		}
	
		//minimum field length
		if (e.minlength){
			if (((e.value).length) < (e.minlength)){
				errors += "- The field "+ e.name + " must be at least "+e.minlength+" characters in length\n";
			}
		}	
		//compare 2 fields for equality
		if (e.checkEqual){
			if (((e.checkEqual)) != (e.value)){
				errors += "- "+e.name+" confirmation failed"
			}
		}

		//<!-- check numeric fields -->
			if (e.numeric || (e.min !=null) || (e.max !=null)){
				
					//var v= parseFloat(e.value);
				var v = parseFloat(e.value);
				var num = isFinite(e.value);
				//alert (v);
				if((num==false) || ((e.min != null) && (v < e.min)) || ((e.max != null) && (v > e.max))) {
					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.name
							}else{
								dateerrors+='\n-Invalid date format in the following field(s)'
								dateerrors+="\n    "+e.name
							}
						}else{
						    invdate = true; 
						}
				}else{
					invdate = true;  
				}	
	
	
			}
	}
}


if(!emptyFields && !errors && !fieldErrors) return true;
	msg="------------------------------------------------------------------------------------------------\n";
	msg+="The form was not submitted because of the following error(s).\n";
	msg+="Please correct these error(s) and re-submit.\n";
	msg+="------------------------------------------------------------------------------------------------\n";
if(emptyFields){
	msg+="-The following required field(s) are empty:" + emptyFields +"\n";
	if(errors) msg +="\n";
}
if(fieldErrors){
	msg+="-The following field(s)contain one or more invalid characters:" + fieldErrors + "\n";
   if(errors) msg +="\n";
}
//**********************************
if(errors){
	errors+=dateerrors
}else{
	errors=dateerrors
}

if(errors){
	msg+=errors;
}

//msg+=position;
//alert('**'+invdate);

alert(msg);

return false;
}
      
//====================================================================
