function verify_organization_name() {
	var org_div = "organization_div";
	
	if (document.callingform.n501c31.value != "" && document.callingform.whoid.value == "") {		
		document.getElementById(org_div).style.display='inline';
		mydiv = document.getElementById(org_div); 
		randnum = (Math.round((Math.random()*9)+1));
		
		var orgName = document.callingform.n501c31.value;
		orgName = orgName.replace("'","''");

		//myurl ="fndajaxorg.pgm?orgname="+encodeURIComponent(orgName)+
		myurl = "fndajaxorg.pgm?orgname=" + orgName +
		"&sid="+encodeURIComponent(document.callingform.sid.value); 
		AJAX_Update(myurl, mydiv, Receive_AJAX_Response); 
	}
		
		
}


function verify() {
	
	themessage = '';
	fnd = '';
    	rfields();

	//alert if fields are empty and cancel form submit
	if (fnd == '1') {
	    alert(themessage);
	    return false;
	}else {
	    document.callingform.submit();
	    return false;
	}

}



function rfields() {

	if (document.callingform.org_exists) {
		themessage = themessage + " This organization already exists in the system" +
		" and can not be duplicated.";
		fnd = "1";	
		return;
	}
	
	if (document.callingform.orgname.value=="") {
		themessage = themessage + " \nOrganization name is a required field.";
		document.callingform.orgname.style.backgroundColor="yellow";
		fnd = "1";
	}

	//do password stuff
	p1 = document.callingform.password1.value;
	pr = document.callingform.passwordr.value;
	
	p1_length = document.callingform.password1.value.length;
	
	if (p1 != pr || p1 == "") {
		themessage = themessage + " \nMatching passwords are required.";
		document.callingform.password1.style.backgroundColor="yellow";
		document.callingform.passwordr.style.backgroundColor="yellow";
		fnd = "1";
	}else if (p1_length > 8 || p1_length < 4){
		themessage = themessage + " \nYour password must be at least 4 characters.";
		document.callingform.password1.style.backgroundColor="yellow";
		document.callingform.passwordr.style.backgroundColor="yellow";
		fnd = "1";
	}else {
		document.callingform.password1.style.backgroundColor="white";
		document.callingform.passwordr.style.backgroundColor="white";
	}


	if (document.callingform.address1.value=="") {
		themessage = themessage + " \nAddress is a required field.";
		document.callingform.address1.style.backgroundColor="yellow";
		fnd = "1";
	}else {
		document.callingform.address1.style.backgroundColor="white";
	}

	if (document.callingform.city1.value=="") {
		themessage = themessage + " \nCity is a required field.";
		document.callingform.city1.style.backgroundColor="yellow";
		fnd = "1";
	}else {
		document.callingform.city1.style.backgroundColor="white";
	}

	if (document.callingform.state1.selectedIndex=="") {
		themessage = themessage + " \nState is a required field.";
		document.callingform.state1.style.backgroundColor="yellow";
		fnd = "1";
	}else {
		document.callingform.state1.style.backgroundColor="white";
	}

	st = document.callingform.state1.selectedIndex;
	if (document.callingform.cnty1.selectedIndex=="") {
		themessage = themessage + " \nCounty is a required field.";
		document.callingform.cnty1.style.backgroundColor="yellow";
		fnd = "1";
	}else {
		document.callingform.cnty1.style.backgroundColor="white";
	}

	if (document.callingform.zip1.value=="") {
		themessage = themessage + " \nZip is a required field.";
		document.callingform.zip1.style.backgroundColor="yellow";
		fnd = "1";
	}else {
		document.callingform.zip1.style.backgroundColor="white";
	}

	if (document.callingform.contact1.value=="") {
		themessage = themessage + " \nContact is a required field.";
		document.callingform.contact1.style.backgroundColor="yellow";
		fnd = "1";
	}else {
		document.callingform.contact1.style.backgroundColor="white";
	}

	if (document.callingform.areacode.value=="" || document.callingform.prefix.value=="" || document.callingform.suffix.value=="") {
		themessage = themessage + " \nA complete phone number is a required.";
		document.callingform.areacode.backgroundColor="yellow";
		document.callingform.prefix.backgroundColor="yellow";
		document.callingform.suffix.backgroundColor="yellow";
		fnd = "1";
	}else {
		document.callingform.areacode.backgroundColor="white";
		document.callingform.prefix.backgroundColor="white";
		document.callingform.suffix.backgroundColor="white";
	}


	e1 = document.callingform.email1.value;
	er = document.callingform.emailr.value;
	p=e1.indexOf('@');
	if (e1 != er || e1 == "") {
		themessage = themessage + " \nMatching emails are required.";
		document.callingform.email1.backgroundColor="yellow";
		document.callingform.emailr.backgroundColor="yellow";
		fnd = "1";
	}else if (p<1 || p==(p.length-1)) {
        	themessage+='\nA valid email address is required (fff@xxxxx.com).';
		document.callingform.email1.backgroundColor="yellow";
		document.callingform.emailr.backgroundColor="yellow";
		fnd = "1";
   	 }else {
		document.callingform.email1.backgroundColor="white";
		document.callingform.emailr.backgroundColor="white";
	}






}


