var exit=true;

function echeck(str) {

        var at="@"
        var dot="."
        var lat=str.indexOf(at)
        var lstr=str.length
        var ldot=str.indexOf(dot)
        if (str.indexOf(at)==-1){
           alert("Invalid E-mail Address")
           return false
        }

        if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
           alert("Invalid E-mail Address")
           return false
        }

        if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
            alert("Invalid E-mail Address")
            return false
        }

         if (str.indexOf(at,(lat+1))!=-1){
            alert("Invalid E-mail Address")
            return false
         }

         if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
            alert("Invalid E-mail Address")
            return false
         }

         if (str.indexOf(dot,(lat+2))==-1){
            alert("Invalid E-mail Address")
            return false
         }

         if (str.indexOf(" ")!=-1){
            alert("Invalid E-mail Address")
            return false
         }

         return true
    }

function ValidateEmail(){
    var emailID=document.frmMain.email

    if ((emailID.value==null)||(emailID.value=="")){
        alert("Please Enter your Email Address")
        emailID.focus()
        return false
    }
    if (echeck(emailID.value)==false){
        emailID.focus()
        return false
    }
    return true
 }

function ValidateAC(){
    var acy = document.frmMain.activechecking[0].checked;
    var acn = document.frmMain.activechecking[1].checked;
    if(!acy && !acn)
    {
        return false
    }
    return true
}

function getURL(offer_choiceArr){
    exit=false;
    if( ValidateEmail()==false ){
        return false;
    }

    if(!ValidateAC())
    {
        alert("Do you have an active checking/savings account?");
        return false;
    }

    var nac = document.frmMain.activechecking[1].checked;
    var picked = -1;
    
    if( document.frmMain.offer_choice[0].checked ) picked=0;
    else if( document.frmMain.offer_choice[1].checked ) picked=1;
    else if( document.frmMain.offer_choice[2].checked ) picked=2;
    else if( document.frmMain.offer_choice[3].checked ) picked=3;
    else if( document.frmMain.offer_choice[4].checked ) picked=4;
    else if( document.frmMain.offer_choice[5].checked ) picked=5;
    else if( document.frmMain.offer_choice[6].checked ) picked=6;
    //if( document.frmMain.offer_choice[7].checked ) picked=7;
    if( picked < 0 ){
        alert( "Please choose what kind of financial help you need." );
        return false;
    }

    var Foffer_choice = document.frmMain.offer_choice[picked].value;
    var Furl = offer_choiceArr[Foffer_choice];
    if(nac == true)
    {
        Furl = nac_choiceArr[Foffer_choice];
    }
    window.open(Furl,'offer_Qc','');
    return true;
}

