// CHECKS VALIDITY OF NEW MEMBER LOGIN ENTRIES
// REQUIRES LOADING 'GENERALVALIDATE.JS' BEFORE
// THIS FILE IN YOUR CALLING PAGE

var isOkay = true;

aFieldList = new Array();
aFieldList[0] = "isAlpha(document.forms[\"f1\"].Requested_By, \"a name in Requested By\");"
aFieldList[1] = "isAny(document.forms[\"f1\"].Company, \"a Company\");"
aFieldList[2] = "isAny(document.forms[\"f1\"].ClientID, \"your ID number. This identifies your company as a customer of the Michael Ehrenfeld Company. \\n\\nIf you do not know your ID code, please call us. Entering the wrong code will delay the Certificate Request processing\");"
aFieldList[3] = "isStrPhone(document.forms[\"f1\"].Phone, \"a Phone\");"
aFieldList[4] = "isAlpha(document.forms[\"f1\"].Certificate_Holder, \"a Certificate Holder\");"
aFieldList[5] = "isAlpha(document.forms[\"f1\"].Address_1, \"an Address\");"
aFieldList[6] = "isAlpha(document.forms[\"f1\"].City, \"a City\");"
aFieldList[7] = "isAlpha(document.forms[\"f1\"].State, \"a State\");"
aFieldList[8] = "isDigit(document.forms[\"f1\"].Zip, \"a Zip Code\");"
//aFieldList[9] = "isAlpha(document.forms[\"f1\"].Attention, \"something in Attention\");"
//aFieldList[10] = "isAlpha(document.forms[\"f1\"].Agent_or_Account_Manager, \"your Agent or Account Manager\");"

function CheckForm(){
    iLength = aFieldList.length;
    for(i = 0; i < iLength; i++){
        if(isOkay){
            //alert("i = " + i);
            isOkay = eval(aFieldList[i]);
        }
    }
    if(isOkay){
		CheckDescriptionOfRelationship();
		if(!isOkay){
	        isOkay = true;
	        return false;
		}
		CheckCoverageToInclude();
		if(!isOkay){
	        isOkay = true;
	        return false;
		}
//		CheckSubrogationOther();
//		if(!isOkay){
//	        isOkay = true;
//	        return false;
//		}
	    document.forms["f1"].submit();
    } else {
        isOkay = true;
        return false;
    }
}

function CheckDescriptionOfRelationship(){
	if(isOkay){
		isOkay = false;
		var piChecked = "";
		var pilen = document.forms["f1"].Description_of_Relationship_count.value;
		for(pi = 1; pi <= pilen; pi++){
			var pif = "Description_of_Relationship_" + pi;
			var pifld = eval("document.forms[\"f1\"]." + pif + ".checked");
			if(pifld){
				isOkay = true;
				//alert(pif + " checked!");
			}
			// FIX FOR CHECKING "Other" ( field # 7 )
			if(document.forms["f1"].Description_of_Relationship_7.value.length > 1){
				isOkay = true;
			}
		}	
		if(!isOkay){
			if(document.forms["f1"].Description_of_Relationship_count.value.length > 1){
				isOkay = true;
			} else {
				alert("Please select a Description of Relationship [ Mortgage, Vendor, etc. ]");
				isOkay = false;
				document.forms["f1"].Description_of_Relationship_1.focus();
				return false;
			}
		}
	}
}

function CheckCoverageToInclude(){
	if(isOkay){
		isOkay = false;
		var piChecked = "";
		var pilen = document.forms["f1"].Coverage_To_Include_count.value;
		for(pi = 1; pi <= pilen; pi++){
			var pif = "Coverage_To_Include_" + pi;
			var pifld = eval("document.forms[\"f1\"]." + pif + ".checked");
			if(pifld){
				isOkay = true;
				//alert(pif + " checked!");
			}
			// FIX FOR CHECKING "Other" ( field # 7 )
			if(document.forms["f1"].Coverage_To_Include_7.value.length > 1){
				isOkay = true;
			}
		}	
		if(!isOkay){
			if(document.forms["f1"].Coverage_To_Include_count.value.length > 1){
				isOkay = true;
			} else {
				alert("Please select the Coverage To Include [ General Liability, Professional Liability, etc. ]");
				isOkay = false;
				document.forms["f1"].Coverage_To_Include_1.focus();
				return false;
			}
		}
	}
}

function CheckSubrogationOther(){
	if(isOkay){
		isOkay = false;
		var piChecked = "";
		var pilen = document.forms["f1"].Subrogation_Other_count.value;
		for(pi = 1; pi <= pilen; pi++){
			var pif = "Subrogation_Other_" + pi;
			var pifld = eval("document.forms[\"f1\"]." + pif + ".checked");
			if(pifld){
				isOkay = true;
				//alert(pif + " checked!");
			}
		}	
		if(!isOkay){
			if(document.forms["f1"].Subrogation_Other_count.value.length > 1){
				isOkay = true;
			} else {
				alert("Please select an Include Waiver of Subrogation On [ General Liability, Professional Liability, etc. ]");
				isOkay = false;
				document.forms["f1"].Subrogation_Other_1.focus();
				return false;
			}
		}
	}
}


