//Master function that calls all other validation functions
function ValidateModify(form,pageclass)
{
	var bIsValid = false;		
		
	bIsValid = validatePolicyInfo(form);
	
	if (bIsValid == true)
	{
		bIsValid = validateContactEmail(form);
	}
	
	//alert("agent_info " + bIsValid + " " +pageclass);
	//pageclass is ff9933 for agentlink access
	if ((pageclass == "ff9933") && bIsValid)
	{
		bIsValid = validateAgencyInfo(form);
	}
	
	//alert("dates " + bIsValid + " " +document.frmModify.chkDates.checked);
	if (bIsValid  && document.frmModify.chkDates.checked)
	{
		bIsValid = validateTravelDatesBox(form);	
	} 
	
	//alert("trip cost " + bIsValid + " " + document.frmModify.chkTripCost.checked);
	if (bIsValid && document.frmModify.chkTripCost.checked)
	{
		bIsValid = validateTripCostBox(form);		
	}
	
	//alert("tour op " + bIsValid + " " +document.frmModify.chkTourOp.checked);
	if (bIsValid && document.frmModify.chkTourOp.checked)
	{		
		bIsValid = validateTourOpBox(form);
	}
	
	//alert("benef " + bIsValid + " " +document.frmModify.chkBenef.checked);
	if (bIsValid && document.frmModify.chkBenef.checked)
	{
		bIsValid = validateBeneficiaryBox(form);
	}	
	
	//alert("spelling " + bIsValid + " " +document.frmModify.chkSpelling.checked);
	if (bIsValid && document.frmModify.chkSpelling.checked)
	{
		bIsValid = validateSpellingBox(form);
	}
	
	//alert("mailing " + bIsValid + " " +document.frmModify.chkMaillingAddress.checked);
	if (bIsValid && document.frmModify.chkMailing.checked)
	{		
		bIsValid = validateMailingAddressBox(form);
	}
	
	return bIsValid;
}

//function to validate Policy information
function validatePolicyInfo(form)
{
	if (document.frmModify.policy_number.value == "")
	{
		alert("Please enter policy number.");
		document.frmModify.policy_number.focus();
		return false;
	}
	
	if (document.frmModify.requesting_name.value == "")
	{
		alert("Please enter the name of the person requesting policy change.");
		document.frmModify.requesting_name.focus();
		return false;
	}	
	
	if (document.frmModify.insured_name.value == "")
	{
		alert("Please enter the name of the primary insured.");
		document.frmModify.insured_name.focus();
		return false;
	}
		
	if (document.frmModify.phone.value == "")
	{
		alert("Please enter phone number of the insured.");
		document.frmModify.phone.focus();
		return false;
	}	
	return true;
}

//function to validate agency information, this function is called only
//if file is accessed through agent link.
function validateAgencyInfo(form)
{
   if (document.frmModify.agency_arc.value == "")
   {
		alert("Please enter the ARC number.");
		document.frmModify.agency_arc.focus();
		return false;	
   }
     
   if (document.frmModify.agent_name.value == "")
   {
		alert("Please enter the agent name.");
		document.frmModify.agenct_name.focus();
		return false;
   }
   
    if (document.frmModify.agent_phone.value == "")
   {
		alert("Please enter the agent phone number.");
		document.frmModify.agenct_phone.focus();
		return false;
   }
   
   return true;
}

//function to validate contact email.
function validateContactEmail(form)
{
   if (document.frmModify.contact_email.value == "")
   {
		alert("Please enter contact email");
		document.frmModify.contact_email.focus();
		return false;
   }
   return true;   
}

//this function is called only if travel dates section is selected.
function validateTravelDatesBox(form)
{
	if ((document.frmModify.orig_from_date.value == "") && (document.frmModify.orig_to_date.value=="") && (document.frmModify.new_from_date.value == "") && (document.frmModify.new_to_date.value==""))
	{
		return true;
	}
	
	if (document.frmModify.orig_from_date.value=="")
	{
		alert("Please enter Originial 'From' date");
		document.frmModify.orig_from_date.focus();
		return false;
	}
	
	if (document.frmModify.orig_to_date.value=="")
	{
		alert("Please enter Original 'To' date");
		document.frmModify.orig_to_date.focus();
		return false;
	}
	
	if (document.frmModify.new_from_date.value == "")
	{
		alert("Please enter New 'From' date");
		document.frmModify.new_from_date.focus();
		return false;
	}
	
	if (document.frmModify.new_to_date.value=="")
	{
		alert("Please enter New 'To' date");
		document.frmModify.new_to_date.focus();
		return false;
	}
	
	return true;	
}

//function to validation additional tour provider information
function validateTourOpBox(form)
{
	if (document.frmModify.tour_provider.value="")
	{
		alert("Please enter the name of the tour provider.");
		document.frmModify.tour_provider.focus();
	}
	return true;
}

//function to validate spellings correction inputs.
function validateSpellingBox(form)
{
	if ((document.frmModify.primary_orig_name.value == "")&&(document.frmModify.primary_new_name.value != ""))
	{
		alert("Please enter the original name for the primary insured.");
		document.frmModify.primary_orig_name.focus();
		return false;
	}
	
	if ((document.frmModify.primary_new_name.value == "")&&(document.frmModify.primary_orig_name.value != ""))
	{
		alert("Please enter the new name for the primary insured.");
		document.frmModify.primary_new_name.focus();
		return false;
	}
	
	if ((document.frmModify.secondary_orig_name.value == "") && (document.frmModify.secondary_new_name.value != ""))
	{
		alert("Please enter the original name for the secondary insured");
		document.frmModify.secondary_orig_name.focus();
		return false;		
	}
	
	if ((document.frmModify.secondary_orig_name.value != "") && (document.frmModify.secondary_new_name.value ==""))
	{
		alert("Please enter corrected name for the secondary insured.");
		document.frmModify.secondary_new_name.focus();
		return false;
	}
	
	return true;
}
//This function is used to validate the trip cost adjustments
function validateTripCostBox(form)
{
	if (((document.frmModify.orig_trip_cost.value=="") && (document.frmModify.new_trip_cost.value=="")) && ((document.frmModify.increase_in_premium.value == "") && (document.frmModify.additional_premium.value == "")))
	{
		alert("Please enter the change in trip cost of Primary Or Additional insureds.");
		document.frmModify.orig_trip_cost.focus();
		return false;
	}
	
	if ((document.frmModify.orig_trip_cost.value=="") && (document.frmModify.new_trip_cost.value==""))
	{
		if ((document.frmModify.increase_in_premium.value == "") || (document.frmModify.additional_premium.value == ""))
		{
			alert("Please enter the change in additional insureds trip cost.");
			document.frmModify.increase_in_premium.focus();
			return false;
		}	
	}
	
	if ((document.frmModify.increase_in_premium.value == "") && (document.frmModify.additional_premium.value == ""))
	{
		if ((document.frmModify.orig_trip_cost.value=="") || (document.frmModify.new_trip_cost.value==""))
		{
			alert("Please enter the change in primary insureds trip cost.");
			document.frmModify.orig_trip_cost.focus();
			return false;
		}	
	}

	/*
	if (document.frmModify.orig_trip_cost.value=="")	
	{
		alert("Please enter original trip cost.");
		document.frmModify.orig_trip_cost.focus();
		return false;
	}
	
	if (document.frmModify.new_trip_cost.value=="")
	{
		alert("Please enter new trip cost.");
		document.frmModify.new_trip_cost.focus();
		return false;
	}
	
	if (document.frmModify.increase_in_premium.value == "")
	{
		alert("Please enter the increase in premium.");
		document.frmModify.increase_in_premium.focus();
		return false;
	}	
	*/
	
	if (document.frmModify.card_type.selectedIndex == 0)
	{
		alert("Please select the credit card type.");
		document.frmModify.card_type.focus();
		return false;
	}
	
	if (document.frmModify.card_holder.value=="")
	{
		alert("Please enter credit card holder name");
		document.frmModify.card_holder.focus();
		return false;
	}
	
	if (document.frmModify.card_number.value=="")
	{
		alert("Please enter credit card number");
		document.frmModify.card_number.focus();
		return false;		
	}	
	
	if (document.frmModify.card_expiry.value =="")
	{
		alert("Please enter credit card expiry in MM/YY format");
		document.frmModify.card_expiry.focus();
		return false;
	}
	
	return true;			
}

function validateMailingAddressBox(form)
{
	if ((document.frmModify.current_address1.value=="") && (document.frmModify.current_address2.value=="") && (document.frmModify.new_address1.value =="") && (document.frmModify.new_address2.value==""))
	{
		return true;
	}
	
	if (document.frmModify.current_address1.value =="")
	{
		alert("Please enter line1 of the original address");
		document.frmModify.current_address1.focus();
		return false;
	}
	
	if (document.frmModify.new_address1.value == "")
	{
		alert("Please enter line1 of the new address");
		document.frmModify.new_address1.focus();
		return false;
	}
	
	return true;
}

function validateBeneficiaryBox(form)
{
	if ((document.frmModify.benef_name1.value =="") && (document.frmModify.benef_name2.value=="") && (document.frmModify.benef_name1.value==""))
	{
		alert("Please enter at least one beneficiary or deselect the add beneficiary checkbox");
		document.frmModify.benef_name1.focus();
		return false;
	}
	return true;
}