var tempPassword
function validateForm(objForm){
	//Scrub data
	var replApos = /'/g;
	var replQote = /"/g;
	flag=0
	for (i=0;i<objForm.length;i++){
		var tempField = objForm.elements[i];
		if(tempField.type=="text" || tempField.type=="textarea" || tempField.type=="password"){
			tempField.value=scrubData(tempField.value)
			if(!validateData(tempField)){flag=1}
		}
	}
	if(flag==1){
		alert('There was a problem with some of the information that you entered.\n Please correct the fields marked in red.')
		return false
	}else{
		for (i=0;i<objForm.length;i++){
			var tempField = objForm.elements[i];
			if(tempField.type=="text" || tempField.type=="textarea" || tempField.type=="password"){
				var arrName = tempField.name.split("_")
				if(arrName.length>1){
					tempField.name=arrName[0]
				}
			}
		}
		return true
	}
}
function scrubData(objText){
	var replApos = /'/g;
	var replQote = /"/g;
	objText = objText.replace(replApos,"")
	objText = objText.replace(replQote,"")
	return objText
}
function validateData(objField){
	objField.style.backgroundColor="White"
	var flag=0
	var arrName = objField.name.split("_")
	if(arrName.length>1){
		reqs=arrName[1]
		if(reqs.indexOf("R")>=0){
			if(objField.value.length<1){
				objField.style.backgroundColor="Red"
				flag=1
			}
		}
		if(reqs.indexOf("N")>=0){
			if(isNaN(objField.value)){
				objField.style.backgroundColor="Red"
				flag=1
			}
		}
		if(reqs.indexOf("E")>=0){
			if(objField.value.indexOf("@")>0){
				if(objField.value.lastIndexOf(".")<=objField.value.indexOf("@")+2){
					objField.style.backgroundColor="Red"
					flag=1
				}
			}else{
				objField.style.backgroundColor="Red"
				flag=1
			}
		}
		if(reqs.indexOf("P")>=0){
			tempPassword = objField
		}
		if(reqs.indexOf("C")>=0){
			if(tempPassword.value!=objField.value){
				objField.style.backgroundColor="Red"
				tempPassword.style.backgroundColor="Red"
				flag=1
			}
		}
	}
	if(flag==1){
		return false
	}else{
		return true
	}	
}
