// EM scripting : converted validation function 1

// Validate all input for callback form
  function EMvalidate1(formnum) {
    var t_or_f = true ;
    if (t_or_f) t_or_f = vl(formnum,"EMname",6,"Your name") ;
    if (t_or_f) t_or_f = vp(formnum,"postcode","Y","post code") ;
    if (t_or_f) t_or_f = vt(formnum,"EMphone","Y","telephone") ;
    if (t_or_f) t_or_f = ve(formnum,"EMemail","Y") ;
    if (t_or_f) t_or_f = vd(formnum,"subjt","default","Subject") ;
    if (t_or_f) t_or_f = vd(formnum,"EMsource","default","How did you hear about our website") ;
   return t_or_f ;
  }

// Validate all input for brochure form
  function validate2(formnum) {
    var t_or_f = true ;
    if (t_or_f) t_or_f = vl(formnum,"name",6,"Your name") ;
    if (t_or_f) t_or_f = vl(formnum,"address",20,"Your address") ;
    if (t_or_f) t_or_f = vt(formnum,"telno","N","telephone") ;
    if (t_or_f) t_or_f = ve(formnum,"email","N") ;
    return t_or_f ;
  }

// Validate all input for links form
  function EMlinkRequest(formnum) {
    var t_or_f = true ;
    if (t_or_f) t_or_f = vl(formnum,"EMname",6,"Your name") ;
    if (t_or_f) t_or_f = vl(formnum,"EMcompany",3,"Your company name") ;
    if (t_or_f) t_or_f = ve(formnum,"EMemail","Y") ;
    if (t_or_f) t_or_f = vx(formnum,"siteURL","Y","website URL") ;
    if (t_or_f) t_or_f = vl(formnum,"siteURL",16,"Your website URL") ;
    if (t_or_f) t_or_f = vx(formnum,"linkURL","Y","link page URL") ;
    if (t_or_f) t_or_f = vl(formnum,"linkURL",16,"Your link page URL") ;
    if (t_or_f) t_or_f = vl(formnum,"title",3,"Your link title") ;
    if (t_or_f) t_or_f = vm(formnum,"title",50,"Your link title") ;
    if (t_or_f) t_or_f = vl(formnum,"description",10,"Your link description") ;
    if (t_or_f) t_or_f = vm(formnum,"description",200,"Your link description") ;
     if (t_or_f) t_or_f = vd(formnum,"EMsource","default","How did you hear about our website") ;
    return t_or_f ;
  }

// Validate all input for order (booking) form
  function validate4(formnum) {
    var t_or_f = true ;
    if (t_or_f) t_or_f = vl(formnum,"name",6,"Your name") ;
    if (t_or_f) t_or_f = vl(formnum,"address",20,"Your address") ;
    if (t_or_f) t_or_f = vt(formnum,"telno","Y","telephone") ;
    if (t_or_f) t_or_f = ve(formnum,"email","N") ;
    return t_or_f ;
  }

// Validate all input for checkout
  function EMvalidate5(formnum) {
    var t_or_f = true ;
    if(document.Frmcheckout.valPayment.value == 'y'){
    	if (t_or_f) t_or_f = vr(formnum,"paymethod",5,"payment method") ;
    }
    if (t_or_f) t_or_f = vl(formnum,"EMname",2,"Your first name");
    if (t_or_f) t_or_f = vl(formnum,"surname",2,"Your last name");
    if (t_or_f) t_or_f = vl(formnum,"address1",6,"The first line of your address") ;
    if (t_or_f) t_or_f = vl(formnum,"address3",3,"Your town/city") ;
    if (t_or_f) t_or_f = vp(formnum,"postcode","Y","post code") ;
    if (t_or_f) t_or_f = vt(formnum,"EMphone","Y","telephone") ;
    if (t_or_f) t_or_f = ve(formnum,"EMemail","Y") ;
     if (t_or_f) t_or_f = vd(formnum,"EMsource","default","How did you hear about our website") ;
   return t_or_f ;
  }

// Validate all input for skills appraisal
  function EMvalidate6(formnum) {
    var t_or_f = true ;
    if (t_or_f) t_or_f = vl(formnum,"EMname",6,"The contact name") ;
    if (t_or_f) t_or_f = vt(formnum,"EMphone","Y","telephone") ;
    if (t_or_f) t_or_f = ve(formnum,"EMemail","Y") ;
    if (t_or_f) t_or_f = vd(formnum,"EMsource","default","How did you hear about our website") ;
    return t_or_f ;
  }

// Validate all input for e-learning
  function validate7(formnum) {
    var t_or_f = true ;
    if (t_or_f) t_or_f = vl(formnum,"name",6,"Your name") ;
    if (t_or_f) t_or_f = ve(formnum,"email","Y") ;
    if (t_or_f) t_or_f = vd(formnum,"courseType","default","Course type") ;
    if (t_or_f) t_or_f = vl(formnum,"courseName",6,"The course name") ;
    return t_or_f ;
  }

  function EMvalidate8(formnum) {
    var t_or_f = true ;
    if (t_or_f) t_or_f = vl(formnum,"EMname",6,"Your name") ;
    if (t_or_f) t_or_f = vl(formnum,"address",10,"Your address") ;
    if (t_or_f) t_or_f = vp(formnum,"postcode","Y","post code") ;
    if (t_or_f) t_or_f = vt(formnum,"EMphone","N","telephone") ;
    if (t_or_f) t_or_f = ve(formnum,"EMemail","Y") ;
    if (t_or_f) t_or_f = vd(formnum,"EMsource","default","How did you hear about our website") ;
    return t_or_f ;
  }

  // Validate input for bespoke course maker
  function EMvalidate9(formnum) {
    var t_or_f = true ;
    if (t_or_f) t_or_f = vl(formnum,"EMname",6,"Your name") ;
    if (t_or_f) t_or_f = vt(formnum,"EMphone","Y","telephone") ;
    if (t_or_f) t_or_f = ve(formnum,"EMemail","Y") ;
    if (t_or_f) t_or_f = vd(formnum,"EMsource","default","How did you hear about our website") ;
    if (t_or_f) document.contact01.EMcompany.disabled = false
    return t_or_f ;
  }

  // Validate input for price promise
  function EMvalidateA(formnum) {
    var t_or_f = true ;
    if (t_or_f) t_or_f = vl(formnum,"EMname",6,"Your name") ;
    if (t_or_f) t_or_f = vt(formnum,"EMphone","Y","telephone") ;
    if (t_or_f) t_or_f = ve(formnum,"EMemail","N") ;
    if (t_or_f) t_or_f = vd(formnum,"EMsource","default","How did you hear about our website") ;
    if (t_or_f) t_or_f = vl(formnum,"training",5,"Your training needs") ;
    if (t_or_f) t_or_f = vl(formnum,"TPname",3,"The Training Provider's name") ;
    if (t_or_f) t_or_f = vv(formnum,"TPprice",95,"Their price") ;
    if (t_or_f) t_or_f = vd(formnum,"TPsource","default","How did you hear about them") ;
    return t_or_f ;
  }
  
  // Train to Gain Form
  function EMvalidateLSC(formnum) {
    var t_or_f = true ;
    if (t_or_f) t_or_f = vl(formnum,"title",2,"Your title") ;
    if (t_or_f) t_or_f = vl(formnum,"EMname",6,"Your name") ;
    if (t_or_f) t_or_f = vl(formnum,"position",3,"Your position") ;
    if (t_or_f) t_or_f = vt(formnum,"EMphone","Y","telephone") ;
    if (t_or_f) t_or_f = vt(formnum,"mob","Y","mobile") ;
    if (t_or_f) t_or_f = ve(formnum,"EMemail","Y") ;
    if (t_or_f) t_or_f = vt(formnum,"altphone","N","preferred contact telephone") ;
    if (t_or_f) t_or_f = vt(formnum,"altmob","N","preferred contact mobile") ;
    if (t_or_f) t_or_f = ve(formnum,"altemail","N") ;
    if (document.forms[formnum].eu[1].checked){
    	if (t_or_f) t_or_f = vl(formnum,"eudetails",4,"non EU details") ;
    }
     if (document.forms[formnum].gain[0].checked){
    	if (t_or_f) t_or_f = vl(formnum,"gaindetails",4,"details of prior government funding") ;
    }
    if (t_or_f) t_or_f = vl(formnum,"EMcompany",5,"Your company name") ;
    if (t_or_f) t_or_f = vl(formnum,"address1",5,"Your company address") ;
    if (t_or_f) t_or_f = vp(formnum,"postcode","Y","post code") ;
    if (t_or_f){
    	if (document.lsc.turnover.value.length == "" || isNaN(document.lsc.turnover.value)){
		document.lsc.turnover.value = 0;
	}
    }
    if (t_or_f){
    	if (document.lsc.fulltime.value.length == "" || isNaN(document.lsc.fulltime.value)){
		document.lsc.fulltime.value = 0;
	}
    }
    if (t_or_f){
    	if (document.lsc.parttime.value.length == "" || isNaN(document.lsc.parttime.value)){
		document.lsc.parttime.value = 0;
	}
    }
    if (t_or_f){
    	if (document.lsc.vol.value.length == "" || isNaN(document.lsc.vol.value)){
		document.lsc.vol.value = 0;
	}
    }
    if (t_or_f) t_or_f = vd(formnum,"EMsource","-","How did you hear about this scheme") ;
    if (t_or_f) t_or_f = vd(formnum,"sector","-","Business Sector") ;
    if (t_or_f) t_or_f = vd(formnum,"ethnicity","-","Beneficiary Ethnicity") ;
    if (t_or_f) t_or_f = vd(formnum,"disability","-","Beneficiary Disability") ;
    return t_or_f ;
  }
  
// Validate all input for T2G form
  function EMvalidateEnq(formnum) {
    var t_or_f = true ;
    if (t_or_f) t_or_f = vl(formnum,"EMname",6,"Your name") ;
    if (t_or_f) t_or_f = vl(formnum,"EMcompany",3,"Your company name") ;
    if (t_or_f) t_or_f = vp(formnum,"postcode","Y","post code") ;
    if (t_or_f) t_or_f = vt(formnum,"EMphone","Y","telephone") ;
    if (t_or_f) t_or_f = ve(formnum,"EMemail","Y") ;
    if (t_or_f) t_or_f = vd(formnum,"EMsource","default","How did you hear about this scheme") ;
   return t_or_f ;
  }

// Validate More Info form
  function EMvalidateINFO(formnum){
  	var t_or_f = true ;
	if (t_or_f) t_or_f = vl(formnum,"EMname",6,"Your name") ;
    	if (t_or_f) t_or_f = vp(formnum,"postcode","Y","post code") ;
    	if (t_or_f) t_or_f = vt(formnum,"EMphone","Y","telephone") ;
    	if (t_or_f) t_or_f = ve(formnum,"EMemail","Y");
    	if (t_or_f) t_or_f = vd(formnum,"EMsource","default","How did you hear about our website") ;
	if(!document.forms[formnum].classType[0].checked && !document.forms[formnum].classType[1].checked && !document.forms[formnum].classType[2].checked){
		t_or_f = false;
		alert('Please select at least one class type.');
	}
	if (t_or_f) t_or_f = vl(formnum,"message",10,"Your message") ;
   	return t_or_f ;
  }
  
// Validate all input for referral form
  function EMvalidateEnq(formnum) {
    var t_or_f = true ;
    if (t_or_f) t_or_f = vl(formnum,"EMname",6,"Your name") ;
    if (t_or_f) t_or_f = vl(formnum,"EMcompany",3,"Your company name") ;
    if (t_or_f) t_or_f = vp(formnum,"postcode","Y","post code") ;
    if (t_or_f) t_or_f = vt(formnum,"EMphone","Y","telephone") ;
    if (t_or_f) t_or_f = ve(formnum,"EMemail","Y") ;
    if (t_or_f) t_or_f = vd(formnum,"EMsource","default","How did you hear about this scheme") ;
   return t_or_f ;
  }
  
// for forms that do not require validating
function nocheck(n){
	return true
}

// Remove all blanks from a string
function blankout(strname) {
  var i = 1 ;
  do {
    if (strname.charAt(i)==" " ) {
      strname = strname.substring(0,i) + strname.substring(i+1,strname.length) ;
      i-- ;
    }
    i++ ;
  }
  while (i<strname.length) ;
  return strname ;
}

// Validate telephone/fax number
function vt(formnum,fieldname,needed,inputtext) {
  var minlength = 9 ;
  var valid = true ;
  var vble = eval("document.forms[formnum]."+fieldname+".value")
  if (needed.toUpperCase() == "N" && vble == "") return true ;  // Allow blank telephone/fax number
  if (vble.length < minlength) {

    valid=false ;
    window.alert("Your "+inputtext+" number must be at least "+minlength+" characters long") ;
    val = eval("document.forms[formnum]."+fieldname+".focus()") ;
    return false ;
  }
  if (vble.charAt(0) != "0" && vble.charAt(0) != "+") {
    valid=false ;
    window.alert("Your "+inputtext+" number must begin with a '0' (zero) or '+' (plus)") ;
    val = eval("document.forms[formnum]."+fieldname+".focus()") ;
    return false ;
  }
  return true ;
}

// Validate e-mail address
/* CODE REPLACED
function ve(formnum,fieldname,needed) {
	var val 	= eval("document.forms[formnum]."+fieldname+".value");
	var newVal	= val.replace(/,/g,".");
	var val		= eval("document.forms[formnum]."+fieldname+'.value="' + newVal +'"');
	var email 	= eval("document.forms[formnum]."+fieldname+".value");
	
	email = blankout(email) ;
	email = email.toLowerCase() ;
	//window.alert("E-Mail is ("+email+")") ;
	if (needed.toUpperCase() == "N" && email == "") return true ;  // Allow blank e-mail address
	if ((email>="0" && email<="9z") || (email>="a" && email<="zz")) {
		val = 0
	}else {
		window.alert("Invalid email address : must begin with a letter or number") ;
		val = eval("document.forms[formnum]."+fieldname+".focus()") ;
		return false ;
	}
	if (email.indexOf("@")<0) {
		window.alert("Invalid email address : must contain a '@' within your email address") ;
		val = eval("document.forms[formnum]."+fieldname+".focus()") ;
		return false ;
	}else {
		e1 = email.indexOf("@") ;
		if (email.indexOf("@",e1+1) > 0 ) {
			window.alert("Invalid email address : must only contain one '@' within your email address") ;
			val = eval("document.forms[formnum]."+fieldname+".focus()") ;
			return false ;
		}
	}
	if ((email.indexOf("@")>=0 && email.indexOf("@")<2) || email.indexOf("@")>email.length-3) {
		window.alert("Invalid position for '@' within your email address") ;
		val = eval("document.forms[formnum]."+fieldname+".focus()") ;
		return false ;
	}
	if (email.indexOf(".")<0) {
		window.alert("Must contain a '.' within your email address") ;
		val = eval("document.forms[formnum]."+fieldname+".focus()") ;
		return false ;
	}
	if ((email.indexOf(".")>=0 && email.indexOf(".")<1) || email.lastIndexOf(".")>email.length-3) {
	window.alert("Invalid position for '.' within  your email address") ;
	val = eval("document.forms[formnum]."+fieldname+".focus()")
	return false ;
	}
	if (email.indexOf("@") > email.lastIndexOf(".")) {
	window.alert("Must contain a '.' after the '@' in  your email address") ;
	val = eval("document.forms[formnum]."+fieldname+".focus()")
	return false ;
	}
	return true ;
}
*/
function ve(formnum,fieldname,needed) {
  var t_or_f = true;
  var val    = eval("document.forms[formnum]."+fieldname+".value");
  var regEx  = new RegExp(/,/g);
  var newVal = val.replace(regEx,'.'); // Replace commas with dots
  var val    = eval("document.forms[formnum]."+fieldname+'.value="' + newVal +'"');
  var email  = eval("document.forms[formnum]."+fieldname+".value");
  
  email = blankout(email);
  email = email.toLowerCase();
  
  if(needed.toUpperCase() == 'N' && email == ''){
  	t_or_f = true;
  }else{
  	// Step One (Does it look like an email?)
  	 var regEx  = new RegExp(/^([a-zA-Z0-9])+([\.'a-zA-Z0-9_-])*@([\.'a-zA-Z0-9_-])+\.[a-z\.]{2,6}$/);
	 if(!regEx.exec(email)){
	  	t_or_f = false;
		if(email == '' || email == null){
			alert('Please enter an email address.');
		}else{
			alert(email + ' is an invalid email address.');
		}
	 }
	
	// Step Two (Check for common mistakes)
	if(t_or_f){
		// Dual dot domains (co.uk, org.uk, me.uk) not beginning with a '.' (Still valid email format but we know it's wrong)
		// Example: admin@emarketers-co.uk, admin@emarketers_org.uk, admin@emarketersco.uk
		// Check 3rd character from the left, is it a dot and does it end in 'uk' 
		// (There are no single dot domains ending in .uk so we can safley validate)
		if(email.charAt(email.length-3) == '.' && (email.charAt(email.length-2) == 'u' && email.charAt(email.length-1) == 'k')){
			// Now two character domain extentions do exist so as far as we are concerned, the email is still valid
			// So are the next two characters to the left 'co'?
			if((email.charAt(email.length-5) == 'c' && email.charAt(email.length-4) == 'o')){
				// We now know that the domain ends in co.uk 
				// So is the next character to the left a dot?
				if(email.charAt(email.length-6) != '.'){
					t_or_f = false;
					alert(email + ' is invalid, there is no dot detected before co.uk');
				}
			}
			if((email.charAt(email.length-5) == 'm' && email.charAt(email.length-4) == 'e')){
				// We now know that the domain ends in me.uk 
				// So is the next character to the left a dot?
				if(email.charAt(email.length-6) != '.'){
					t_or_f = false;
					alert(email + ' is invalid, there is no dot detected before me.uk');
				}
			}
			// Alright are the next three characters to the left 'org'?
			if(email.charAt(email.length-6) == 'o' && email.charAt(email.length-5) == 'r' && email.charAt(email.length-4) == 'g'){
				// We now know that the domain ends in org.uk
				// So is the next character to the left a dot?
				if(email.charAt(email.length-7) != '.'){
					t_or_f = false;
					alert(email + ' is invalid, there is no dot detected before org.uk');
				}
			}
		}
		// Note: There are many more that we could try to solve but the more we do the more danger some valid domains
		// 	 Will not pass either! (for example if we try to fix me.com, legitimate domains like somthing@some.com would be rejected!) 
	}
  }
  return t_or_f;
}
		
// Ensure string has minimum length
function vl(formnum,fieldname,minlength,inputtext) {
  var valid = true ;
  var vble = eval("document.forms[formnum]."+fieldname+".value")
  cleanString(formnum,fieldname);
//window.alert("Value is >"+vble+"<   Length is >"+vble.length+"<") ;

  if (vble.length < minlength) {
    valid=false ;
    var char1 = (minlength == 1) ? " character" : " characters" ;
    window.alert(inputtext+" must be at least "+minlength+char1+" long") ;
  }
  if (!valid) val = eval("document.forms[formnum]."+fieldname+".focus()") ;
  return valid ;
}

// Ensure string does not exceed maximum length
function vm(formnum,fieldname,maxlength,inputtext) {
  var valid = true ;
  var vble = eval("document.forms[formnum]."+fieldname+".value")
  cleanString(formnum,fieldname);
//window.alert("Value is >"+vble+"<   Length is >"+vble.length+"<") ;

  if (vble.length > maxlength) {
    valid=false ;
    var char1 = (maxlength == 1) ? " character" : " characters" ;
    window.alert(inputtext+" must be at no more than "+maxlength+char1+" long") ;
  }
  if (!valid) val = eval("document.forms[formnum]."+fieldname+".focus()") ;
  return valid ;
}

// Ensure variable has minimum value
function vv(formnum,fieldname,minvalue,inputtext) {
  var valid = true ;
  var vble  = eval("document.forms[formnum]."+fieldname+".value")

//window.alert("Value is >"+vble+"<") ;
  if (vble < minvalue) {
    valid=false ;
    window.alert(inputtext+" must be at least "+minvalue) ;
  }
  if (!valid) val = eval("document.forms[formnum]."+fieldname+".focus()") ;
  return valid ;
}


// Validate drop-down list
function vd(formnum,fieldname,defaultval,inputtext) {
  var valid = true ;
  var vble  = eval("document.forms[formnum]."+fieldname+".value")
//window.alert("Value is >"+vble+"<") ;
  if (vble == defaultval) {
    valid=false ;
    window.alert("Please choose an option from the '"+inputtext+"' list") ;
  }
  return valid ;
}
  
// Validate radio buttons
function vr(formnum,fieldname,buttons,inputtext) {
  var check = false ;
//window.alert("Validating buttons") ;
  for (var i=0 ; i<buttons ; i++) {
    var vble  = eval("document.forms[formnum]."+fieldname+"["+i+"].checked") ;
    if (vble) check = true ;
//window.alert("Value is >"+vble+"<") ;
  }
  if (!check) window.alert("Please check one of the "+inputtext+" buttons") ;
  valid=check
  return valid ;
}

// Validate checkboxes
function vc(formnum,fieldname,totboxes,minboxes,maxboxes,inputtext) {
  var check = 0 ;
//window.alert("Validating boxes") ;
  for (var i=0 ; i<totboxes ; i++) {
    var vble  = eval("document.forms[formnum]."+fieldname+"["+i+"].checked") ;
    if (vble) check++ ;
//window.alert("Value is >"+vble+"<") ;
  }
  if (check<minboxes) window.alert("Please check at least "+minboxes+" of the "+inputtext+" boxes") ;
  if (check>maxboxes) window.alert("Please check no more than "+maxboxes+" of the "+inputtext+" boxes") ;
  valid = (check<minboxes || check>maxboxes) ? false : true ;
  return valid ;
}

// Confirm Web Site address begins with 'www.' or 'http://www.'
function vx(formnum,fieldname,needed,inputtext) {
  var valid = true ;

  var vble = eval("document.forms[formnum]."+fieldname+".value")
  vble = blankout(vble) ;
  vble = vble.toLowerCase() ;
  if (needed.toUpperCase() == "N" && vble == "") return true ;  // Allow blank web site address

  var valid = (vble.substring(0,4)  == "www.") ? true : false ;
  var valid = (vble.substring(0,11) == "http://www.") ? true : valid ;
  if (!valid) {
    window.alert("please enter a valid "+inputtext) ;
    val = eval("document.forms[formnum]."+fieldname+".focus()")
  }
  return valid ;
}

// Validate and format postcode
function vp(formnum,fieldname,needed,inputtext) {
  var valid = true ;

  var pcode = eval("document.forms[formnum]."+fieldname+".value")
  pcode = blankout(pcode) ;
  pcode = pcode.toUpperCase() ;
  if (needed.toUpperCase() == "N" && pcode == "") return true ;  // Allow blank postcode
  if (pcode == "IRELAND") return true ;  // Allow Ireland
  if (pcode.length<5) {
    window.alert("INVALID POSTCODE : must be at least 5 digits long") ;
    val = eval("document.forms[formnum]."+fieldname+".focus()")
    return false ;
  }
  if (pcode<"A" || pcode>"Z") {
    window.alert("INVALID POSTCODE : must begin with a letter") ;
    val = eval("document.forms[formnum]."+fieldname+".focus()")
    return false ;
  }
  var strg1 = pcode.charAt(pcode.length-3) ;
  if (strg1<"0" || strg1>"9") {
    window.alert("INVALID POSTCODE : third character from the end is >"+strg1+"< : must be a number") ;
    val = eval("document.forms[formnum]."+fieldname+".focus()")
    return false ;
  }
  var strg2 = pcode.charAt(pcode.length-2) ;
  var strg3 = pcode.charAt(pcode.length-1) ;
  if (strg2<"A" || strg2>"Z" || strg3<"A" || strg3>"Z") {
    window.alert("INVALID POSTCODE : must end with two letters") ;
    val = eval("document.forms[formnum]."+fieldname+".focus()")
    return false ;
  }
  if (pcode.length<5) {
    window.alert("INVALID POSTCODE : must be more than 4 characters long") ;
    val = eval("document.forms[formnum]."+fieldname+".focus()")
    return false ;
  }
  pcode = pcode.substring(0,pcode.length-3) + " " + pcode.substring(pcode.length-3,pcode.length) ;
  var resetpcode = eval("document.forms[formnum]."+fieldname+".value=pcode")
//  document.contact01.pcode.value = pcode ;
//  window.alert("Post Code is ("+pcode+")") ;
  return true ;
}


function fixComma(formnum,fieldname){
	var val 	= eval("document.forms[formnum]."+fieldname+".value")
	var newVal	= val.replace(",",".")
	var val		= eval("document.forms[formnum]."+fieldname+".value='" + newVal +"'")
}

function cleanString(formnum,fieldname){
	var val 	= eval("document.forms[formnum]."+fieldname+".value");
	var newVal	= val.replace(/[\n]+/g,'\\n');				// The eval() was crashing because it was taking LITERAL new-lines. This replaces newlines with an escaped char, this can then be parsed by the eval().
	newVal		= newVal.replace(/[\r]+/g,'\\r');
	newVal		= newVal.replace(/\'/g,"&#39;");
	newVal 		= newVal.replace(/\"/g,'&#34;');
	val		= eval("document.forms[formnum]."+fieldname+".value='" + newVal +"'");
}

