function FillDropDown()
{
    // Fills Dropdwon of Secret Question, City, State
    var strConnection = EmployerReg.GetConnectionString();
    FillSecretQuestionList(strConnection.value);
    FillCityList(strConnection.value);
    FillStateList(strConnection.value);
    CalculateAmount();
}
function FillSecretQuestionList(ConnectionString)
{
    // To Fill DropDown List Of SecretQuestions From 'SecretQuestionMaster' Table
    var dsSecretQuestion = EmployerReg.FillSecretQuestionDropDown(ConnectionString);
    // Flush Table DropDown
    document.getElementById('DDLSecretQuestion').options.length = 0;

    if(dsSecretQuestion.value.Tables[0].Rows.length > 0)
    {
        for(var i=0; i < dsSecretQuestion.value.Tables[0].Rows.length; i++)
        {
            document.getElementById('DDLSecretQuestion').options[i] = new Option(dsSecretQuestion.value.Tables[0].Rows[i].SecretQuestion, dsSecretQuestion.value.Tables[0].Rows[i].SecretQuestionID);
        }
    }
    else
    {
        document.getElementById('DDLSecretQuestion').options[0] = new Option("<-- No Secret Question Defined -->", -1);
    }  
}
function FillCityList(ConnectionString)
{
    // To Fill DropDown List Of City From CityMaster Table
    var dsCity = EmployerReg.FillCityDropDown(ConnectionString);
    // Flush Table DropDown
    document.getElementById('DDLCity').options.length = 0;

    if(dsCity.value.Tables[0].Rows.length > 0)
    {
        for(var i=0; i < dsCity.value.Tables[0].Rows.length; i++)
        {
            document.getElementById('DDLCity').options[i] = new Option(dsCity.value.Tables[0].Rows[i].CityName, dsCity.value.Tables[0].Rows[i].CityID);
        }
    }
    else
    {
        document.getElementById('DDLCity').options[0] = new Option("<-- No City Defined -->", -1);
    }  
}
function FillStateList(ConnectionString)
{
    // To Fill DropDown List Of State From StateMaster Table
   var dsState = EmployerReg.FillStateDropDown(ConnectionString);
    // Flush Table DropDown
    document.getElementById('DDLState').options.length = 0;
    
    if(dsState.value.Tables[0].Rows.length > 0)
    {
        for(var i = 0; i < dsState.value.Tables[0].Rows.length; i++)
        {
            document.getElementById('DDLState').options[i] = new Option(dsState.value.Tables[0].Rows[i].StateName, dsState.value.Tables[0].Rows[i].StateID);
        }
    }
    else
    {
        document.getElementById('DDLState').options[0] = new Option("<!-- No State Defined -->", -1);
    }
}
function CheckValidation()
{
    // Triming All Parameters
    document.getElementById('txtLoginID').value = Trim(document.getElementById('txtLoginID').value);
    document.getElementById('txtPassword').value = Trim(document.getElementById('txtPassword').value);
    document.getElementById('txtConfirmPassword').value = Trim(document.getElementById('txtConfirmPassword').value);
    document.getElementById('txtSecretAnswer').value = Trim(document.getElementById('txtSecretAnswer').value);
    
    document.getElementById('txtFullName').value = Trim(document.getElementById('txtFullName').value);
    document.getElementById('txtOfficeAddress').value = Trim(document.getElementById('txtOfficeAddress').value);
    document.getElementById('txtPinCode').value = Trim(document.getElementById('txtPinCode').value);
    document.getElementById('txtTelephone').value = Trim(document.getElementById('txtTelephone').value);
    document.getElementById('txtFAX').value = Trim(document.getElementById('txtFAX').value);
    document.getElementById('txtContactPerson').value = Trim(document.getElementById('txtContactPerson').value);
    document.getElementById('txtEMailID').value = Trim(document.getElementById('txtEMailID').value).toLowerCase();
    document.getElementById('txtWebsite').value = Trim(document.getElementById('txtWebsite').value).toLowerCase();
    document.getElementById('txtCompanyBriefInfo').value = Trim(document.getElementById('txtCompanyBriefInfo').value).toLowerCase();
    
    // Checking All Validations
    if(document.getElementById('txtLoginID').value == '')
    {
        alert('Login ID should not be blank.');
        document.getElementById('txtLoginID').focus();
        return false;
    }
    if(document.getElementById('txtLoginID').value.length < 8)
    {
        alert('Login ID should be at least 8 characters.');
        document.getElementById('txtLoginID').focus();
        return false;
    }
    if(document.getElementById('txtPassword').value == '')
    {
        alert('Password should not be blank.');
        document.getElementById('txtPassword').focus();
        return false;
    }
    if(document.getElementById('txtPassword').value.length < 8)
    {
        alert('Password should be at least 8 characters.');
        document.getElementById('txtPassword').focus();
        return false;
    }
    if(document.getElementById('txtPassword').value != document.getElementById('txtConfirmPassword').value)
    {
        alert('Passwords typed do not match, please re-enter your passwords.');
        document.getElementById('txtPassword').focus();
        return false;
    }
    
    var SelIndexofSecretQuestionID = document.getElementById("DDLSecretQuestion").selectedIndex;
    var intSecretQuestionID = document.getElementById("DDLSecretQuestion").options[SelIndexofSecretQuestionID].value;
    if(intSecretQuestionID == -1)
    {
        alert('Please select secret question.');
        document.getElementById('DDLSecretQuestion').focus();
        return false;
    }
    if(document.getElementById('txtSecretAnswer').value == '')
    {
        alert('Secret answer should not be blank.');
        document.getElementById('txtSecretAnswer').focus();
        return false;
    }
    if(document.getElementById('txtFullName').value == '')
    {
        alert('Full Name can not be blank.');
        document.getElementById('txtFullName').focus();
        return false;
    }
    if(document.getElementById('txtOfficeAddress').value == '')
    {
        alert('Office address should not be blank.');
        document.getElementById('txtOfficeAddress').focus();
        return false;
    }
    if(document.getElementById('txtOfficeAddress').value.length > 256)
    {
        alert('Office address should be maximum 256 Characters.');
        document.getElementById('txtOfficeAddress').focus();
        return false;
    }

    var SelIndexofCityId = document.getElementById("DDLCity").selectedIndex;
    var intCityID = document.getElementById("DDLCity").options[SelIndexofCityId].value;
    if(intCityID == -1)
    {
        alert('Please select city.');
        document.getElementById('DDLCity').focus();
        return false;
    }
    if(IsNumeric(document.getElementById('txtPinCode').value, 'Pin Code', false, false, false, 1000000) == false)
    {
        document.getElementById('txtPinCode').focus();
        return false;
    }
    if(document.getElementById('txtPinCode').value.length < 6)
    {
        alert('Invalid Pin Code.');
        document.getElementById('txtPinCode').focus();
        return false;
    }
    var SelIndexofStateId = document.getElementById("DDLState").selectedIndex;
    var intStateID = document.getElementById("DDLState").options[SelIndexofStateId].value;
    if(intStateID == -1)
    {
        alert('Please select state.');
        document.getElementById('DDLState').focus();
        return false;
    }

    if(document.getElementById('txtTelephone').value == '')
    {
        alert('Telephone number should not be blank.');
        document.getElementById('txtTelephone').focus();
        return false;
    }
    if(CheckValidCharacter('0123456789 +:-[](),', document.getElementById('txtTelephone').value) == false)
    {
        alert('Invalid Telephone No.');
        document.getElementById('txtTelephone').focus();
        return false;
    }
    if(document.getElementById('txtFAX').value == '')
    {
        alert('FAX number should not be blank.');
        document.getElementById('txtFAX').focus();
        return false;
    }
    if(CheckValidCharacter('0123456789 +:-[](),', document.getElementById('txtFAX').value) == false)
    {
        alert('Invalid FAX No.');
        document.getElementById('txtFax').focus();
        return false;
    }
    if(document.getElementById('txtContactPerson').value == '')
    {
        alert('Contact Person should not be blank.');
        document.getElementById('txtContactPerson').focus();
        return false;
    }
    if(EMailCheck(document.getElementById('txtEMailID').value, true) == false)
    {
        document.getElementById('txtEMailID').focus();
        return false;
    }
    if(document.getElementById('txtCompanyBriefInfo').value == '')
    {
        alert('Company brief information should not be blank.');
        document.getElementById('txtCompanyBriefInfo').focus();
        return false;
    }
    if(document.getElementById('txtCompanyBriefInfo').value.length > 1024)
    {
        alert('Company Brief Info should be maximum 256 Characters.');
        document.getElementById('txtCompanyBriefInfo').focus();
        return false;
    }
    return true;
}
function IntegratePaymentGateway(OrderId)
{
    CalculateAmount();
    var MerchantId = document.getElementById("ctl00_ContentPlaceHolder1_Merchant_Id").value;
    var Redirect_Url            = document.getElementById("ctl00_ContentPlaceHolder1_Redirect_Url").value;
    var Amount = document.getElementById("ctl00_ContentPlaceHolder1_lblAmount").innerHTML;
    var intCheckSum = EmployerReg.GetCheckSum(OrderId,MerchantId,Amount,Redirect_Url);
    
    var billing_cust_name       = document.getElementById("txtFullName").value;
    var billing_cust_address    = document.getElementById("txtOfficeAddress").value;
    var billing_cust_country    = "India";
    var billing_cust_email      = document.getElementById("txtEMailID").value;
    var billing_cust_tel        = document.getElementById("txtTelephone").value;
    var billing_zip_code        = document.getElementById("txtPinCode").value;
   
//    window.open('ThankYou.aspx?Message=' + strErrMsg.value.substring(21, strErrMsg.value.length),'_self');
    window.open("https://www.ccavenue.com/shopzone/cc_details.jsp?Merchant_Id=" + MerchantId + "&Order_Id=" + OrderId + "&Amount=" + Amount + "&billing_cust_name=" +  billing_cust_name + "&billing_cust_address=" +    billing_cust_address + "&billing_cust_country=" +     billing_cust_country + "&billing_cust_email=" +     billing_cust_email + "&billing_cust_tel=" +     billing_cust_tel + "&billing_zip_code=" + billing_zip_code + "&Checksum=" + intCheckSum.value + "&Redirect_Url=" + Redirect_Url,"_self");
}
function SaveRecord()
{
    
    if (CheckValidation() == false)
    {
        return false;
    }
    var strConnection = EmployerReg.GetConnectionString();

    var strLoginID = document.getElementById('txtLoginID').value;
    var strPassword = document.getElementById('txtPassword').value;

    var SelIndexofSecretQuestionID = document.getElementById("DDLSecretQuestion").selectedIndex;
    var intSecretQuestionID = document.getElementById("DDLSecretQuestion").options[SelIndexofSecretQuestionID].value;
    var strSecretQuestionAnswer = document.getElementById('txtSecretAnswer').value;

    var strFullName = document.getElementById('txtFullName').value;
    var strOfficeAddress = document.getElementById('txtOfficeAddress').value;
    var SelIndexofCityId = document.getElementById("DDLCity").selectedIndex;
    var intCityID = document.getElementById("DDLCity").options[SelIndexofCityId].value;

    var strPinCode = document.getElementById('txtPinCode').value;

    var SelIndexofStateId = document.getElementById("DDLState").selectedIndex;
    var intStateID = document.getElementById("DDLState").options[SelIndexofStateId].value;

    var strTelephone = document.getElementById('txtTelephone').value;
    var strFAX = document.getElementById('txtFAX').value;

    var strContactPerson = document.getElementById('txtContactPerson').value;
    var strEMailID = document.getElementById('txtEMailID').value;
    var strWebsite = ''
    strWebsite = document.getElementById('txtWebsite').value;
    var strCompanyBriefInfo = document.getElementById('txtCompanyBriefInfo').value;

    var intPosting = 0;
    if(document.getElementById('optPosting1').checked == true)
        intPosting = 1;
    else if(document.getElementById('optPosting5').checked == true)
        intPosting = 5;
    else if(document.getElementById('optPosting12').checked == true)
        intPosting = 12;

    
    var strBanner468X60 = '';
    if(document.getElementById('chkBanner468X60').checked == true)
        strBanner468X60 = 'Y';
    else
        strBanner468X60 = 'N';

    var strBanner200X200 = '';
    if(document.getElementById('chkBanner200X200').checked == true)
        strBanner200X200 = 'Y';
    else
        strBanner200X200 = 'N';

    var strMicroSite = '';
    if(document.getElementById('chkMicroSite').checked == true)
        strMicroSite = 'Y';
    else
        strMicroSite = 'N';

    var strErrMsg = EmployerReg.InsertEmployerReg(strConnection.value, strLoginID, strPassword, intSecretQuestionID, strSecretQuestionAnswer, strFullName, strOfficeAddress, intCityID, strPinCode, intStateID, strTelephone, strFAX, strContactPerson, strEMailID, strWebsite, strCompanyBriefInfo, intPosting, strBanner468X60, strBanner200X200, strMicroSite)
    if(strErrMsg.value[1].substring(0, 21) == 'Successful Message : ')
    {
        var OptionsSelected = '';
        OptionsSelected = OptionsSelected + 'No Of Postings : ' + intPosting + '<BR>';
        
        if (strBanner468X60=='Y')
            OptionsSelected = OptionsSelected + 'Banner : 468 X 60 : <BR>'
        if (strBanner200X200=='Y')
            OptionsSelected = OptionsSelected + 'Banner : 200 X 200 : <BR>'
        if (strMicroSite=='Y')
            OptionsSelected = OptionsSelected + 'Microsite'
        OptionsSelected = OptionsSelected + 'No Of Postings : ' + intPosting + '<BR>'

        var strMailMessage="Hi, Gopinath, <br/><br/>You have received one more entry in the database for Employer : " + strFullName + "<br/><br/>" + OptionsSelected;
        var SendMail = EmployerReg.SendEmail(strMailMessage);
        if(SendMail.value!="")
        {
            alert(SendMail.value);
        }
           
        var OrderId="";
        OrderId= strErrMsg.value[0];
        IntegratePaymentGateway(OrderId);
   //     EmployerReg.Display();
//        window.open('ThankYou.aspx?Message=' + strErrMsg.value.substring(21, strErrMsg.value.length),'_self');
        //window.open('https://www.ccavenue.com/shopzone/cc_details.jsp?Merchant_Id=' + strMerchant_Id + '&Order_Id=' + strOrder_Id + '&Amount=' + intAmount + '&billing_cust_name=' + strFullName + '&billing_cust_address=' + strOfficeAddress + '&billing_cust_country=' + strCity + '&billing_cust_email=' + strEMailID + '&billing_cust_tel=' + strTelephone + "&billing_zip_code=' + strPinCode + '&Checksum=' + strChecksum + '&Redirect_Url=' + strRedirect_Url);
 //       window.open('https://www.ccavenue.com/shopzone/cc_details.jsp?Merchant_Id=M_dignity_5952' + '&Order_Id=XX' + '&Amount=1000' + '&billing_cust_name=' + strFullName + '&billing_cust_address=' + strOfficeAddress + '&billing_cust_country=Karjat' + '&billing_cust_email=' + strEMailID + '&billing_cust_tel=' + strTelephone + '&billing_zip_code=' + strPinCode + '&Checksum=' + strChecksum + '&Redirect_Url=www.google.com');
    }
    else
    {
        alert(strErrMsg.value[1]);
        document.getElementById('txtLoginID').focus();
    }
}

function CalculateAmount()
{
    var TotalAmount=0;
    if(document.getElementById('optPosting1').checked==true)
    {
        TotalAmount = TotalAmount + 4000;
    }
    else if(document.getElementById('optPosting5').checked==true)
    {
        TotalAmount = TotalAmount + 8000;
    }
    else if (document.getElementById('optPosting12').checked==true)
    {
        TotalAmount = TotalAmount + 40000;
    }
    
    if (document.getElementById('chkBanner468X60').checked==true)
    {
        TotalAmount = TotalAmount + 5000;
    }
    
    if (document.getElementById('chkBanner200X200').checked==true)
    {
        TotalAmount = TotalAmount + 3000;
    }
    
    if (document.getElementById('chkMicroSite').checked==true)
    {
        TotalAmount = TotalAmount + 5000;
    }
   
    document.getElementById('ctl00_ContentPlaceHolder1_lblAmount').innerHTML=TotalAmount;
}