﻿var Stage = "1";
var IsValidAmount = false;
function doValidateForm()
{
    var objFrm = document._xclick;
    
    document.getElementById("hidStage").value = Stage;
    
    CheckAmount();
    
    if(document.getElementById("amount").value == "")
    {
        alert("Enter a Amount");
        document.getElementById("amount").focus();
        return false;
    }
    
    if(document.getElementById("amount").value == "0.00" || IsValidAmount == false)
    {
        alert("Enter a Valid Amount");
        document.getElementById("amount").focus();
        return false;
    }
    if(! doValidate())
    {
        return false;
    }
    if(Stage == "1")
    {
        if(__Trim(document.getElementById("txtDonar1_Stage1").value) ==  "")
        {
            alert("Enter Donor Name");
            getFocus("txtDonar1_Stage1");
            return false;
        }
    }
    if(Stage == "2")
    {
        if(__Trim(document.getElementById("txtDonar1_Stage2").value) ==  "")
        {
            alert("Enter Donor Name");
            getFocus("txtDonar1_Stage2");
            return false;
        }
        
        if(__Trim(document.getElementById("txtEmployer1_Stage2").value) ==  "")
        {
            alert("Enter Employer");
            getFocus("txtEmployer1_Stage2");
            return false;
        }
        if(__Trim(document.getElementById("txtOccupation1_Stage2").value) ==  "")
        {
            alert("Enter Occupation");
            getFocus("txtOccupation1_Stage2");
            return false;
        }
    }
    if(Stage == "3")
    {
        if(__Trim(document.getElementById("txtDonar1_Stage3").value) ==  "")
        {
            alert("Enter Donor 1 Name");
            getFocus("txtDonar1_Stage3");
            return false;
        }
        
        if(__Trim(document.getElementById("txtEmployer1_Stage3").value) ==  "")
        {
            alert("Enter Employer");
            getFocus("txtEmployer1_Stage3");
            return false;
        }
        if(__Trim(document.getElementById("txtOccupation1_Stage3").value) ==  "")
        {
            alert("Enter Occupation");
            getFocus("txtOccupation1_Stage3");
            return false;
        }
        if(__Trim(document.getElementById("txtDonar2_Stage3").value) ==  "")
        {
            alert("Enter Donor 2 Name");
            getFocus("txtDonar2_Stage3");
            return false;
        }
        
        if(__Trim(document.getElementById("txtEmployer2_Stage3").value) ==  "")
        {
            alert("Enter Employer");
            getFocus("txtEmployer2_Stage3");
            return false;
        }
        if(__Trim(document.getElementById("txtOccupation2_Stage3").value) ==  "")
        {
            alert("Enter Occupation");
            getFocus("txtOccupation2_Stage3");
            return false;
        }
    }
    if(__Trim(objFrm.txtStreet.value) == "")
    {
         alert("Enter Street");
	     getFocus('txtStreet');
	     return false;
    }
    if(__Trim(objFrm.txtCity.value) == "")
    {
         alert("Enter City");
	     getFocus('txtCity');
	     return false;
    }
    if(__Trim(objFrm.drpState.value) == "0")
    {
         alert("Select State");
	     getFocus('drpState');
	     return false;
    }
    if(objFrm.txtZipCode.value.length !=5)
    {
        alert("Enter a valid Zip Code");
        getFocus('txtZipCode');
        return false;
    }
	
	if(objFrm.txtZipCodeHome.value.length !=5)
    {
        alert("Enter a valid Home Zip Code");
        getFocus('txtZipCodeHome');
        return false;
    }
    
    if(isEmailId(objFrm.txtEmail.value)==false)
	{
		alert("Enter a valid Email Address");
		getFocus('txtEmail');
		return false;
	}
    
    if(objFrm.txtPhone.value != "")
	{
	    if(objFrm.txtPhone.value.length < 13)
	    {
	        alert("Enter a valid Phone no");
	        getFocus('txtPhone');
	        return false;
	    }
	}
	return true;
}   

 function CheckAmount() 
 {
        
        document.getElementById("divStage1").style.display = "block";
        document.getElementById("divStage2").style.display = "none";
        document.getElementById("divStage3").style.display = "none";
            
        var inp = document.getElementById("amount");
        var x = inp.value;
        
        if(parseFloat(x) <= 199.99  &&  parseFloat(x) >= 0.01) 
        {
            document.getElementById("divStage1").style.display = "block";
            document.getElementById("divStage2").style.display = "none";
            document.getElementById("divStage3").style.display = "none";
            Stage = "1";
            IsValidAmount = true;
        }
        
        if(parseFloat(x) <= 350.00 && parseFloat(x) > 199.99) 
        {
            document.getElementById("divStage2").style.display = "block";
            document.getElementById("divStage1").style.display = "none";
            document.getElementById("divStage3").style.display = "none";
            Stage = "2";
            IsValidAmount = true;
        }
        
        if(parseFloat(x) <= 700.00 && parseFloat(x) > 350.00) 
        {
            document.getElementById("divStage3").style.display = "block";
            document.getElementById("divStage1").style.display = "none";
            document.getElementById("divStage2").style.display = "none";
            Stage = "3";
            IsValidAmount = true;
        }
        if(parseFloat(x) >= 700.01)
        {
            IsValidAmount = false;
            alert("The amount you have entered exceeds contribution limits per city finance law.\n Contributions are limited to $350 per couple or $700 per couple.");
            document.getElementById("amount").value = "0.00";
        }  
 }

