var errors='';

function FormVaildateContact(f)
{
    errors='';
	if ((document.getElementById('MachineNo').value == '') && (document.getElementById('SerialNo').value == ''))
	{
	    errors+='- Machine No or Serial No are required.\n';	    
	    hiliteField (document.getElementById('MachineNo'));
	    hiliteField (document.getElementById('SerialNo'));
	}
	 
	//MM_validateForm('CompanyName','','R','MachineNo','','R', 'SerialNo','','R','Email','','RisEmail','Meter1','','R');
	MM_validateForm('CompanyName','','R','Email','','RisEmail','Meter1','','R');

	return document.MM_returnValue;
	 
}
	
function setFormContent(elementArray, bCheckValue)
{
	//pass in a checkValue (boolean), then set the display based on that value
	var e;
	//alert(bCheckValue);
	for (var i=0;i<elementArray.length;i++){
		var e = document.getElementById(elementArray[i])
		if (bCheckValue){
			e.style.display = 'inline';
		}else{
			e.style.display = 'none';
		}
		//alert(e.style.display)
	}
}



function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { 
  	test=args[i+2]; val=MM_findObj(args[i]);
	
    if (val) { 
			nm=val.name; 
			e = val
			
			if ((val=val.value)!="") {
	
				if (test.indexOf('isEmail')!=-1) {

					p = val.indexOf('@');
					if (p<1 || p==(val.length-1)) {
						hiliteField(e);
						errors+='- '+nm+' must contain an e-mail address.\n';
					}
					
				} else if (test!='R') { 
					num = parseFloat(val);
					if (isNaN(val)) {
						hiliteField(e);
						errors+='- '+nm+' must contain a number.\n';
					}
					if (test.indexOf('inRange') != -1) { 
						p=test.indexOf(':');
						min=test.substring(8,p); max=test.substring(p+1);
						if (num<min || max<num) {
							hiliteField(e);
							errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
						}
					}
	  		}
	  	} else if (test.charAt(0) == 'R') {
				//alert(e.name)
				hiliteField(e)
		 		errors += '- '+nm+' is required.\n'; 
			} 
	 	}
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function hiliteField(e){
	e.style.backgroundColor = '#ffc'
}