var isError = 0;

function check_field(thefield) {
	var thelabel = thefield + "label";
	
	if (document.getElementById(thefield).value == "") {

		document.getElementById(thefield).className = "FormError";
		document.getElementById(thelabel).className = "FormErrorLabel";
		document.getElementById(thefield).focus();
		isError = 1;
	} else {
		document.getElementById(thefield).className = "FieldOk";
		document.getElementById(thelabel).className = "FormLabel";

	}
}

function check_checkbox(thefield)
	{

	var thelabel = thefield + "label";
	var checkedbox = document.getElementById(thefield).checked;
	if (checkedbox == true) {
		
		document.getElementById(thelabel).className = "FormLabel";
		} else {
		
		document.getElementById(thelabel).className = "FormErrorLabel";
		document.getElementById(thefield).focus();
		isError = 1;
		}


	}
	
function check_dropdown(thefield)
	{
		var theSelect = document.getElementById(thefield).value;
		var thelabel = thefield + "label";
		if (theSelect  == null || theSelect == "")
			{
				document.getElementById(thefield).className = "FormErrorSelect";
				document.getElementById(thelabel).className = "FormErrorLabel";
				isError = 1;
				
			}else{
				document.getElementById(thelabel).className = "FormLabel";
			}

		}







function check_email(thefield) {
	
	var email = document.getElementById(thefield).value;
	var AtPos = email.indexOf("@");
	var StopPos = email.lastIndexOf(".");
	Message = "";

if (email == "") {
		isError = 1;
		}

if (AtPos == -1 || StopPos == -1) {
		isError = 1;
		}

if (StopPos < AtPos) {
		isError = 1;
		}

if (StopPos - AtPos == 1) {
		isError = 1;
		}

if (isError == 1) 


		{		
		document.getElementById(thefield).className = "FormError";
		document.getElementById(thefield).focus();

		} else {
		
		document.getElementById(thefield).className = "FieldOK";
		//document.getElementById(thelabel).className = "FormLabel";
		}
}














function validate() {
    isError = 0;
	check_dropdown("agent");
	check_field("company");
	check_field("zip");
	check_dropdown("state");
	check_field("city");
	check_field("email");
	check_field("lname");
	check_field("fname");
	check_checkbox("subscribe");

	
	var message = "Please complete the required fields before updating.";
	
	if (isError == 1) {
	
        document.getElementById('error2').innerHTML = "<p>" +message +"</p>";
        document.getElementById('error2').className = "ShowError";
			return false;

	}else {document.getElementById('error2').innerHTML = "";
        document.getElementById('error2').className = "FormLabel";
        return true;
        //submit code goes here.
        //form.Submit();
    }

	
	isError = 0;
}

function validate2() {
    isError = 0;


	check_dropdown("agent");
	check_field("company");
	check_field("zip");
	check_dropdown("state");
	check_field("city");
	check_field("email");
	check_field("lname");
	check_field("fname");
	
	
	var message = "Please complete the required fields before updating.";
	if (isError == 1) {
	
        document.getElementById('error2').innerHTML = "<p>" +message +"</p>";
        document.getElementById('error2').className = "ShowError";        
        return false;
			

	}else {document.getElementById('error2').innerHTML = "";
        document.getElementById('error2').className = "FormLabel";
        return true;
        //submit code goes here.
        //form.Submit();
    }

	
	isError = 0;
}

function validate3()
{
	isError = 0;

	check_email("profileid");
	var message = "Please enter a valild email address.";

    if (isError == 1) {
	    document.getElementById('error1').innerHTML = "<p>" +message +"</p>";
	    document.getElementById('error1').className = "ShowError";
	    return false
			

	}else {
	
	    document.getElementById('error1').innerHTML = "";
	    document.getElementById('error1').className = "FormLabel";
	    return true;
	//submit code goes here.
	//form.Submit();
	}

}