﻿// ------- search panel------------------------
//function ShowSearchPannel(id) {
//    document.getElementById("pro").style.display = "none";
//    document.getElementById("Job").style.display = "none";

//    if (id == 1) {
//        document.getElementById("pro").style.display = "";
//        document.getElementById("Job").style.display = "none";
//        document.getElementById("prov_td").className = "provider_tab1";
//        document.getElementById("job_td").className = "job_tab2";
//    }
//    else {
//        document.getElementById("Job").style.display = "";
//        document.getElementById("pro").style.display = "none";
//        document.getElementById("prov_td").className = "provider_tab2";
//        document.getElementById("job_td").className = "job_tab1";
//    }
//}
// ------- search panel------------------------

//-----------------------tabsscript---------------------
//function pageLoad() {
//   // $("input.PhoneMask").mask("(999) 999-9999");
//    alert("hi");
//  //   $("#ctl00_body_Help_MyQuery1_txtConactName").mask("(999) 999-9999");
//}

$(document).ready(function() {
    $("input.PhoneMask").mask("(999) 999-9999");
    $('#tabMenu > li').click(function() {
        $('#tabMenu > li').removeClass('selected');
        $(this).addClass('selected');
        $('.boxBody>div').slideUp('1500');
        $('.boxBody>div:eq(' + $('#tabMenu > li').index(this) + ')').slideDown('1500');
        $('.boxBody>div:eq(' + $('#tabMenu > li').index(this) + ')').find('.dd').css('width', '202px');
        $('.boxBody>div:eq(' + $('#tabMenu > li').index(this) + ')').find('.ddChild').css('width', '200px');
    }).hover(function() { $(this).addClass('mouseover'); }, function() { $(this).removeClass('mouseover'); });

    //Mouseover with animate Effect for Category menu list
    $('.boxBody #category li').mouseover(function() {

        //Change background color and animate the padding
        $(this).css('backgroundColor', '#888');
        $(this).children().animate({ paddingLeft: "20px" }, { queue: false, duration: 300 });
    }).mouseout(function() {

        //Change background color and animate the padding
        $(this).css('backgroundColor', '');
        $(this).children().animate({ paddingLeft: "0" }, { queue: false, duration: 300 });
    });

    //Mouseover effect for Posts, Comments, Famous Posts and Random Posts menu list.
    $('.boxBody li').click(function() {
        window.location = $(this).find("a").attr("href");
    }).mouseover(function() {
        $(this).css('backgroundColor', '#888');
    }).mouseout(function() {
        $(this).css('backgroundColor', '');
    });

});
//-------- end tab script------------------------

//-------- search inner pannel--------------

//$(document).ready(function() {
//    $('.DP_Img').click(function() {
//   // alert($(this).next('table'));
//        $(this).next('table').show();
//    });
//});

var numProvider = 0;
var numJobs = 0;
var numLocJobs = 0;
var homeProviders = 0;
var LocSearch = 0;
var cityNum = 0;
var saveSearchStatus = 0;

//function showProviderlist() {
//    if (numProvider == 0) {
//        document.getElementById("divProviderList").style.display = "";
//        numProvider = 1;
//    }
//    else {
//        document.getElementById("divProviderList").style.display = "none";
//        numProvider = 0;
//    }
//}

//function showLocProviderlist() {

//    if (LocSearch == 0) {
//        document.getElementById("divLocProviderList").style.display = "";
//        LocSearch = 1;
//    }
//    else {
//        document.getElementById("divLocProviderList").style.display = "none";
//        LocSearch = 0;
//    }
//}

//function showCityProviderlist() {

//    if (cityNum == 0) {

//        document.getElementById("divProviderList").style.display = "";

//        cityNum = 1;
//    }
//    else {

//        document.getElementById("divProviderList").style.display = "none";

//        cityNum = 0;
//    }
//}


//function catchProviderSelItem(item) {

//    //    document.getElementById("ctl00_tdfor").style.display = "none";
//    //    document.getElementById("ctl00_tdDet").style.display = "none";
//    //    document.getElementById("ctl00_ddlSubjectAreas").style.display = "none";
//    //    document.getElementById("ctl00_ddlDiagnosis").style.display = "none";

//    if (item == 1) {

//        document.getElementById("ctl00_body_searchbox1_lvSearch_txtFindProvider").value = "Babysitting Providers";
//        document.getElementById("ctl00_body_searchbox1_lvSearch_hdfFindProvider").value = "1";
//        document.getElementById("ctl00_body_searchbox1_lvSearch_hdfDetails").value = "0";
//        //document.getElementById("ctl00_tdsharemasterpro").style.display = '';
//    }
//    if (item == 2) {
//        document.getElementById("ctl00_body_searchbox1_lvSearch_txtFindProvider").value = "Special Needs Providers";
//        document.getElementById("ctl00_body_searchbox1_lvSearch_hdfFindProvider").value = "2";
//        //document.getElementById("ctl00_tdfor").style.display = "";
//        //document.getElementById("ctl00_tdDet").style.display = "";
//        //document.getElementById("ctl00_ddlSubjectAreas").style.display = "none";
//        //document.getElementById("ctl00_ddlDiagnosis").style.display = "";
//        document.getElementById("ctl00_body_searchbox1_lvSearch_hdfDetails").value = "0";
//        //document.getElementById("ctl00_tdsharemasterpro").style.display = 'none';
//    }
//    if (item == 3) {
//        document.getElementById("ctl00_body_searchbox1_lvSearch_txtFindProvider").value = "Tutoring Providers";
//        document.getElementById("ctl00_body_searchbox1_lvSearch_hdfFindProvider").value = "3";
//        //document.getElementById("ctl00_tdfor").style.display = "";
//        //document.getElementById("ctl00_tdDet").style.display = "";
//        //document.getElementById("ctl00_ddlSubjectAreas").style.display = "";
//        //document.getElementById("ctl00_ddlDiagnosis").style.display = "none";
//        document.getElementById("ctl00_body_searchbox1_lvSearch_hdfDetails").value = "0";
//        //document.getElementById("ctl00_tdsharemasterpro").style.display = 'none';
//    }
//    if (item == 4) {
//        document.getElementById("ctl00_body_searchbox1_lvSearch_txtFindProvider").value = "Pet Sitting Providers";
//        document.getElementById("ctl00_body_searchbox1_lvSearch_hdfFindProvider").value = "4";
//        document.getElementById("ctl00_body_searchbox1_lvSearch_hdfDetails").value = "0";
//        // document.getElementById("ctl00_tdsharemasterpro").style.display = '';
//    }
//    if (item == 5) {
//        document.getElementById("ctl00_body_searchbox1_lvSearch_txtFindProvider").value = "Elder Care Providers";
//        document.getElementById("ctl00_body_searchbox1_lvSearch_hdfFindProvider").value = "5";
//        document.getElementById("ctl00_body_searchbox1_lvSearch_hdfDetails").value = "0";
//        document.getElementById("ctl00_tdsharemasterpro").style.display = '';
//    }
//    if (item == 6) {
//        document.getElementById("ctl00_body_searchbox1_lvSearch_txtFindProvider").value = "House Keeping Providers";
//        document.getElementById("ctl00_body_searchbox1_lvSearch_hdfFindProvider").value = "6";
//        document.getElementById("ctl00_body_searchbox1_lvSearch_hdfDetails").value = "0";
//        // document.getElementById("ctl00_tdsharemasterpro").style.display = '';
//    }
//    if (item == 7) {
//        document.getElementById("ctl00_body_searchbox1_lvSearch_txtFindProvider").value = "Personal Care Providers";
//        document.getElementById("ctl00_body_searchbox1_lvSearch_hdfFindProvider").value = "7";
//        document.getElementById("ctl00_body_searchbox1_lvSearch_hdfDetails").value = "0";
//        // document.getElementById("ctl00_tdsharemasterpro").style.display = '';
//    }
//    if (item == 8) {
//        document.getElementById("ctl00_body_searchbox1_lvSearch_txtFindProvider").value = "Babysitter";
//        document.getElementById("ctl00_body_searchbox1_lvSearch_hdfFindProvider").value = "1";
//        document.getElementById("ctl00_body_searchbox1_lvSearch_hdfDetails").value = "Babysitter";
//        //  document.getElementById("ctl00_tdsharemasterpro").style.display = '';
//    }
//    if (item == 9) {
//        document.getElementById("ctl00_body_searchbox1_lvSearch_txtFindProvider").value = "Nanny";
//        document.getElementById("ctl00_body_searchbox1_lvSearch_hdfFindProvider").value = "1";
//        document.getElementById("ctl00_body_searchbox1_lvSearch_hdfDetails").value = "Nanny";
//        // document.getElementById("ctl00_tdsharemasterpro").style.display = '';
//    }

//    document.getElementById("divProviderList").style.display = "none";
//    numProvider = 0;
//}


//function catchLocSelItem(item) {

//    //    document.getElementById("ctl00_tdLocfor").style.display = "none";
//    //    document.getElementById("ctl00_tdLocDet").style.display = "none";
//    //    document.getElementById("ctl00_ddlLocSubjectAreas").style.display = "none";
//    //    document.getElementById("ctl00_ddlLocDiagnosis").style.display = "none";

//    if (item == 1) {
//        document.getElementById("ctl00_txtLocFindProvider").value = "Babysitting Providers";
//        document.getElementById("ctl00_hdfLocFindProvider").value = "1";
//        document.getElementById("ctl00_hdfLocDetails").value = "0";
//    }
//    if (item == 2) {
//        document.getElementById("ctl00_txtLocFindProvider").value = "Special Needs Providers";
//        document.getElementById("ctl00_hdfLocFindProvider").value = "2";
//        //        document.getElementById("ctl00_tdLocfor").style.display = "";
//        //        document.getElementById("ctl00_tdLocDet").style.display = "";
//        //        document.getElementById("ctl00_ddlLocSubjectAreas").style.display = "none";
//        //        document.getElementById("ctl00_ddlLocDiagnosis").style.display = "";
//        document.getElementById("ctl00_hdfLocDetails").value = "0";
//    }
//    if (item == 3) {
//        document.getElementById("ctl00_txtLocFindProvider").value = "Tutoring Providers";
//        document.getElementById("ctl00_hdfLocFindProvider").value = "3";
//        //        document.getElementById("ctl00_tdLocfor").style.display = "";
//        //        document.getElementById("ctl00_tdLocDet").style.display = "";
//        //        document.getElementById("ctl00_ddlLocSubjectAreas").style.display = "";
//        //        document.getElementById("ctl00_ddlLocDiagnosis").style.display = "none";
//        document.getElementById("ctl00_hdfLocDetails").value = "0";
//    }
//    if (item == 4) {
//        document.getElementById("ctl00_txtLocFindProvider").value = "Pet Sitting Providers";
//        document.getElementById("ctl00_hdfLocFindProvider").value = "4";
//        document.getElementById("ctl00_hdfLocDetails").value = "0";
//    }
//    if (item == 5) {
//        document.getElementById("ctl00_txtLocFindProvider").value = "Elder Care Providers";
//        document.getElementById("ctl00_hdfLocFindProvider").value = "5";
//        document.getElementById("ctl00_hdfLocDetails").value = "0";
//    }
//    if (item == 6) {
//        document.getElementById("ctl00_txtLocFindProvider").value = "House Keeping Providers";
//        document.getElementById("ctl00_hdfLocFindProvider").value = "6";
//        document.getElementById("ctl00_hdfLocDetails").value = "0";
//    }
//    if (item == 7) {
//        document.getElementById("ctl00_txtLocFindProvider").value = "Personal Care Providers";
//        document.getElementById("ctl00_hdfLocFindProvider").value = "7";
//        document.getElementById("ctl00_hdfLocDetails").value = "0";
//    }
//    if (item == 8) {
//        document.getElementById("ctl00_txtLocFindProvider").value = "Babysitter";
//        document.getElementById("ctl00_hdfLocFindProvider").value = "1";
//        document.getElementById("ctl00_hdfLocDetails").value = "Babysitter";
//    }
//    if (item == 9) {
//        document.getElementById("ctl00_txtLocFindProvider").value = "Nanny";
//        document.getElementById("ctl00_hdfLocFindProvider").value = "1";
//        document.getElementById("ctl00_hdfLocDetails").value = "Nanny";
//    }

//    document.getElementById("divLocProviderList").style.display = "none";
//    LocSearch = 0;
//}


//function catchHomeProviderSelItem(item) {
//    //    document.getElementById("tdfor").style.display = "none";
//    //    document.getElementById("tdDet").style.display = "none";
//    //    document.getElementById("ddlSubjectAreas").style.display = "none";
//    //    document.getElementById("ddlDiagnosis").style.display = "none";

//    if (item == 1) {

//        document.getElementById("ctl00_body_txtFindProvider").value = "Babysitting Providers";
//        document.getElementById("ctl00_body_hdfFindProvider").value = "1";
//        document.getElementById("ctl00_body_hdfDetails").value = "0";
//        document.getElementById("tdShare").style.display = '';
//    }
//    else if (item == 2) {
//        document.getElementById("ctl00_body_txtFindProvider").value = "Special Needs Providers";
//        document.getElementById("ctl00_body_hdfFindProvider").value = "2";
//        //        document.getElementById("tdfor").style.display = "";
//        //        document.getElementById("tdDet").style.display = "";
//        //        document.getElementById("ddlSubjectAreas").style.display = "none";
//        //        document.getElementById("ddlDiagnosis").style.display = "";
//        document.getElementById("ctl00_body_hdfDetails").value = "0";
//        //document.getElementById("tdShare").style.display = 'none';
//    }
//    else if (item == 3) {
//        document.getElementById("ctl00_body_txtFindProvider").value = "Tutoring Providers";
//        document.getElementById("ctl00_body_hdfFindProvider").value = "3";
//        //document.getElementById("tdfor").style.display = "";
//        //document.getElementById("tdDet").style.display = "";
//        //document.getElementById("ddlSubjectAreas").style.display = "";
//        //document.getElementById("ddlDiagnosis").style.display = "none";
//        document.getElementById("ctl00_body_hdfDetails").value = "0";
//        //document.getElementById("tdShare").style.display = 'none';
//    }
//    else if (item == 4) {
//        document.getElementById("ctl00_body_txtFindProvider").value = "Pet Sitting Providers";
//        document.getElementById("ctl00_body_hdfFindProvider").value = "4";
//        document.getElementById("ctl00_body_hdfDetails").value = "0";
//        document.getElementById("tdShare").style.display = '';
//    }
//    else if (item == 5) {
//        document.getElementById("ctl00_body_txtFindProvider").value = "Elder Care Providers";
//        document.getElementById("ctl00_body_hdfFindProvider").value = "5";
//        document.getElementById("ctl00_body_hdfDetails").value = "0";
//        document.getElementById("tdShare").style.display = '';
//    }
//    else if (item == 6) {
//        document.getElementById("ctl00_body_txtFindProvider").value = "House Keeping Providers";
//        document.getElementById("ctl00_body_hdfFindProvider").value = "6";
//        document.getElementById("ctl00_body_hdfDetails").value = "0";
//        document.getElementById("tdShare").style.display = '';
//    }
//    else if (item == 7) {
//        document.getElementById("ctl00_body_txtFindProvider").value = "Personal Care Providers";
//        document.getElementById("ctl00_body_hdfFindProvider").value = "7";
//        document.getElementById("ctl00_body_hdfDetails").value = "0";
//        document.getElementById("tdShare").style.display = '';
//    }
//    else if (item == 8) {
//        document.getElementById("ctl00_body_txtFindProvider").value = "Babysitter";
//        document.getElementById("ctl00_body_hdfFindProvider").value = "1";
//        document.getElementById("ctl00_body_hdfDetails").value = "Babysitter";
//        document.getElementById("tdShare").style.display = '';
//    }
//    else if (item == 9) {
//        document.getElementById("ctl00_body_txtFindProvider").value = "Nanny";
//        document.getElementById("ctl00_body_hdfFindProvider").value = "1";
//        document.getElementById("ctl00_body_hdfDetails").value = "Nanny";
//        document.getElementById("tdShare").style.display = '';
//    }

//    document.getElementById("divProviderList").style.display = "none";
//    numProvider = 0;
//}


//function catchCityProviderSelItem(item) {


//    if (item == 1) {

//        document.getElementById("ctl00_body_txtFindProvider").value = "Babysitting Providers";
//        document.getElementById("ctl00_body_hdfFindProvider").value = "1";
//        document.getElementById("ctl00_body_hdfDetails").value = "0";
//    }
//    if (item == 2) {
//        document.getElementById("ctl00_body_txtFindProvider").value = "Special Needs Providers";
//        document.getElementById("ctl00_body_hdfFindProvider").value = "2";

//        document.getElementById("ctl00_body_hdfDetails").value = "0";
//    }
//    if (item == 3) {
//        document.getElementById("ctl00_body_txtFindProvider").value = "Tutoring Providers";
//        document.getElementById("ctl00_body_hdfFindProvider").value = "3";

//        document.getElementById("ctl00_body_hdfDetails").value = "0";
//    }
//    if (item == 5) {
//        document.getElementById("ctl00_body_txtFindProvider").value = "Pet Sitting Providers";
//        document.getElementById("ctl00_body_hdfFindProvider").value = "4";
//        document.getElementById("ctl00_body_hdfDetails").value = "0";
//    }
//    if (item == 4) {
//        document.getElementById("ctl00_body_txtFindProvider").value = "Elder Care Providers";
//        document.getElementById("ctl00_body_hdfFindProvider").value = "5";
//        document.getElementById("ctl00_body_hdfDetails").value = "0";
//    }
//    if (item == 6) {
//        document.getElementById("ctl00_body_txtFindProvider").value = "House Keeping Providers";
//        document.getElementById("ctl00_body_hdfFindProvider").value = "6";
//        document.getElementById("ctl00_body_hdfDetails").value = "0";
//    }
//    if (item == 7) {
//        document.getElementById("ctl00_body_txtFindProvider").value = "Personal Care Providers";
//        document.getElementById("ctl00_body_hdfFindProvider").value = "7";
//        document.getElementById("ctl00_body_hdfDetails").value = "0";
//    }
//    if (item == 8) {
//        document.getElementById("ctl00_body_txtFindProvider").value = "Babysitter";
//        document.getElementById("ctl00_body_hdfFindProvider").value = "1";
//        document.getElementById("ctl00_body_hdfDetails").value = "Babysitter";
//    }
//    if (item == 9) {
//        document.getElementById("ctl00_body_txtFindProvider").value = "Nanny";
//        document.getElementById("ctl00_body_hdfFindProvider").value = "1";
//        document.getElementById("ctl00_body_hdfDetails").value = "Nanny";
//    }

//    document.getElementById("divProviderList").style.display = "none";
//    cityNum = 0;
//}



//function hideJobSearchPannel() {
//    if (document.activeElement.id != "ctl00_txtLocFindProvider") {
//        document.getElementById("divLocProviderList").style.display = "none";
//        numLocJobs = 0;
//    }

//    if (document.activeElement.id != "ctl00_body_searchbox1_lvSearch_txtFindProvider") {
//        document.getElementById("divProviderList").style.display = "none";
//        numJobs = 0;
//    }
//}


//function hideHomeSearchPannel() {
//    if (document.activeElement.id != "ctl00_body_searchbox1_lvSearch_txtFindProvider") {
//        if (document.activeElement.id != "ctl00_body_txtFindProvider") {
//            document.getElementById("divProviderList").style.display = "none";
//            numProvider = 0;
//        }
//    }
//}


function hideSearchPannel() {
    if (document.activeElement.id != "ctl00_body_searchbox1_lvSearch_txtFindProvider" && document.activeElement.id != "ctl00_body_MyCity1_txtFindProvider" && document.activeElement.id != "ctl00_body_searchbox1_lvSearch_txtLocProviderList" && document.activeElement.id != "ctl00_body_searchbox1_lvSearch_txtProviderList" && document.activeElement.id != "ctl00_body_searchbox1_lvSearch_txtJobsList") {// && document.activeElement.id != 'ctl00_body_searchbox1_lvSearch_txtJobServices') {
        // if (document.activeElement.id != "ctl00_body_txtFindProvider") {
        $('.tbldropdown').hide();  //document.getElementById("divProviderList").style.display = "none";
        // numProvider = 0;
        //  }
    }

    if (document.activeElement.id != "ctl00_body_searchbox1_lvSearch_txtJobServices") {
        //modified 21.10.2009
        if (document.getElementById("tblJobsList") != null) {
            document.getElementById("tblJobsList").style.display = "none";
            numJobs = 0;
        }
    }
    var str = document.activeElement.id;
    var strArray = str.split("_");

    if (document.activeElement.id != "ctl00_ContentPlaceHolder1_txtLanguageCount") {
        if (strArray[2] != "chkLanguagesList") {
            if (document.aspnetForm.divOutter) {
                document.getElementById("divOutter").style.display = "none";
            }

            if (document.aspnetForm.ctl00_ContentPlaceHolder1_hdfLanguageStatus) {
                document.getElementById("divOutter").style.display = "none";
                document.getElementById("ctl00_ContentPlaceHolder1_hdfLanguageStatus").value = "";
            }
        }
    }
}

//function popText() {
//    var id = document.getElementById("ctl00_body_searchbox1_lvSearch_hdfFindProvider").value;
//    if (id == 2 || id == 3) {
//        if (id == 2) {
//            var id1 = document.getElementById("ctl00_ddlDiagnosis").value;
//            document.getElementById("ctl00_body_searchbox1_lvSearch_hdfDetails").value = id1;
//        }
//        if (id == 3) {
//            var id2 = document.getElementById("ctl00_ddlSubjectAreas").value;
//            document.getElementById("ctl00_body_searchbox1_lvSearch_hdfDetails").value = id2;
//        }

//    }
//    else {
//        document.getElementById("ctl00_body_searchbox1_lvSearch_hdfDetails").value = "0";
//    }
//}



var ddlCity = $("#ctl00_body_searchbox1_lvSearch_ddlLocCity");
var hdnCity = $('#ctl00_body_searchbox1_hdnCity');


ddlCity.change(function() {
    hdnCity.val(ddlCity.val());

});




function chkZipcode(id) {
    if (id == "1") {
        var val = '';
        if ($('#ctl00_txtZip').length > 0)
            val = document.getElementById("ctl00_txtZip").value;
        if ($('#ctl00_body_searchbox1_lvSearch_txtZip').length > 0)
            val = document.getElementById("ctl00_body_searchbox1_lvSearch_txtZip").value;
        if (val == "") {
            alert("Please enter the ZIP Code");
            return false;
        }
        else if (val.length < 5) {
            alert("Please enter valid ZIP Code");
            return false;
        }
        else if (val == "00000") {
            alert("Please enter valid ZIP Code");
            return false;
        }
    }

    else if (id == "2") {
        //        if ($('#ctl00_body_searchbox1_lvSearch_txtJobZip').length > 0)
        //            var jobval = document.getElementById("ctl00_body_searchbox1_lvSearch_txtJobZip").value;
        //        else if ($('#ctl00_body_search1_lvSearch_txtJobZip').length > 0)
        //            var jobval = document.getElementById("ctl00_body_search1_lvSearch_txtJobZip").value;


        var jobval = $('.numberOnly').val();


        if (jobval == "") {
            alert("Please enter the ZIP Code");
            return false;
        }
        else {
            if (jobval.length < 5) {
                alert("Please enter Valid ZIP Code");
                return false;
            }
            else {
                if (jobval == "00000") {
                    alert("Please enter Valid ZIP Code");
                    return false;
                }
            }
            return true;
        }

    }
    else {
        var val = document.getElementById("ctl00_body_txtZip").value;

        if (document.getElementById("ctl00_body_txtZip").value == "") {
            alert("Please enter the ZIP Code");
            return false;
        }
        else {
            if (val.length < 5) {
                alert("Please enter valid ZIP Code");
                return false;
            }
            else {
                if (val == "00000") {
                    alert("Please enter valid ZIP Code");
                    return false;
                }
            }
            return true;
        }

    }
}


$(document).ready(function() {

    var status = false;

    $('.Onlyjob').keypress(function(e) {
        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
            status = checkZipButton($('.Onlyjob').val());
            return status;
        }
        else {
            return true;
        }
    });


    $('.OnlyProvider').keypress(function(e) {
        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
            status = checkZipButton($('.OnlyProvider').val());
            return status;
        }
        else {
            return true;
        }
    });


    $(".searchbtnjob").click(function() {
        var txtid = $('.Onlyjob');
        status = checkZipButton(txtid.val());
        return status;


    });

    $(".searchbtnProvider").click(function() {
        var txtid = $('.OnlyProvider');
        status = checkZipButton(txtid.val());
        return status;
    });
});

function checkZipButton(txtid) {
    var jobval = txtid;


    if (jobval == "") {
        alert("Please enter the ZIP Code");
        return false;
    }
    else {
        if (jobval.length < 5) {
            alert("Please enter Valid ZIP Code");
            return false;
        }
        else {
            if (jobval == "00000") {
                alert("Please enter Valid ZIP Code");
                return false;
            }
        }
    }
    if (jobval.length = 5)
        return true;

}

var ddlLocStatecr = $("#ctl00_body_search1_lvSearch_ddlLocState");
var ddlCitycr = $("#ctl00_body_search1_lvSearch_ddlLocCity");
var hdnCitycr = $('#ctl00_body_search1_hdnCity');

if (ddlLocStatecr.length == 0) {
    ddlLocStatecr = $("#ctl00_body_searchbox1_lvSearch_ddlLocState");
    ddlCitycr = $("#ctl00_body_searchbox1_lvSearch_ddlLocCity");
    hdnCitycr = $('#ctl00_body_searchbox1_hdnCity');

}







ddlLocStatecr.change(function() {
    LoadStatescr();

});

ddlCitycr.change(function() {
    hdnCitycr.val(ddlCitycr.val());

});




function LoadStatescr() {


    ddlCitycr.empty().html('<option>Loading...</option>');
    $.ajax({
        type: "POST",
        url: absolutepath + "Locations.asmx/GetCitybyState",
        data: "{statename:'" + ddlLocStatecr.val() + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            var states = msg.d;
            ddlCitycr.html('');
            var str = '<option value="0">--Select City--</option>';
            for (var i = 0; i < states.length; i++) {
                str = str + '<option value="' + states[i].City + '">' + states[i].City + '</option>';
            }
            ddlCitycr.html(str);
            ddlCitycr.find('option').each(function() {
                if ($(this).val() == hdnCitycr.val())
                    $(this).attr('selected', 'selected');
            });

        },
        error: function(msg, s) { alert(msg.responseText); }
    });
}


function validatestatelocation1() {





    if (ddlCitycr.val() == "0" && ddlLocStatecr.val() == "0") {
        alert("Please select the State and Location to Search");
        return false;
    }
    else {
        if (ddlLocStatecr.val() == "0") {
            alert("Please select the State to Search");
            return false;
        }
        if (ddlCitycr.val() == "0") {
            alert("Please select the Location to Search");
            return false;
        }
        else if (ddlCitycr.val() == "Loading...") {
            alert("Please wait while city is loading");
            return false;
        }
    }
}


//function validatestatelocation() {

//    var val1 = document.getElementById("ctl00_ccdState_ClientState").value;
//    var val2 = document.getElementById("ctl00_ccdLoc_ClientState").value;

//    if (val1 == ":::" && val2 == ":::") {
//        alert("Please select the State and Location to Search");
//        return false;
//    }
//    else {
//        if (val1 == ":::") {
//            alert("Please select the State to Search");
//            return false;
//        }
//        if (val2 == ":::") {
//            alert("Please select the Location to Search");
//            return false;
//        }
//    }
//}


//function LanguageCount(id) {

//    var num;
//    if (document.getElementById(id).checked) {

//        if (document.getElementById("ctl00_ContentPlaceHolder1_hdfLanguageChkCount").value != "0") {
//            num = parseInt(document.getElementById("ctl00_ContentPlaceHolder1_hdfLanguageChkCount").value);
//            num = num + 1;
//            document.getElementById("ctl00_ContentPlaceHolder1_txtLanguageCount").value = num + " Selected";
//            document.getElementById("ctl00_ContentPlaceHolder1_hdfLanguageChkCount").value = num;
//        }
//        else {
//            document.getElementById("ctl00_ContentPlaceHolder1_txtLanguageCount").value = "1" + " Selected";
//            document.getElementById("ctl00_ContentPlaceHolder1_hdfLanguageChkCount").value = "1";
//        }
//    }
//    else {
//        num = parseInt(document.getElementById("ctl00_ContentPlaceHolder1_hdfLanguageChkCount").value);
//        num = num - 1;
//        document.getElementById("ctl00_ContentPlaceHolder1_txtLanguageCount").value = num + " Selected";
//        document.getElementById("ctl00_ContentPlaceHolder1_hdfLanguageChkCount").value = num;
//    }
//    if (document.getElementById("ctl00_ContentPlaceHolder1_hdfLanguageChkCount").value == "0") {
//        document.getElementById("ctl00_ContentPlaceHolder1_txtLanguageCount").value = "No Preference";
//    }


//}

//function setLanguagePannel() {
//    if (document.getElementById("ctl00_ContentPlaceHolder1_hdfLanguageStatus").value == "") {
//        document.getElementById("divOutter").style.display = "";
//        document.getElementById("ctl00_ContentPlaceHolder1_hdfLanguageStatus").value = "1";
//    }
//    else {
//        document.getElementById("divOutter").style.display = "none";
//        document.getElementById("ctl00_ContentPlaceHolder1_hdfLanguageStatus").value = "";
//    }
//}


function splitDropDownValues(id) {

    if (id == 1) {
        var selVal = document.getElementById("ctl00_ContentPlaceHolder1_ddlAge").value;

        if (selVal != "0") {
            var val = selVal.split("-");

            document.getElementById("ctl00_ContentPlaceHolder1_hdfMinAge").value = val[0];
            if (val[1] != "") {
                document.getElementById("ctl00_ContentPlaceHolder1_hdfMaxAge").value = val[1];
            }
            else {
                document.getElementById("ctl00_ContentPlaceHolder1_hdfMaxAge").value = "0";
            }

        }
        else {
            document.getElementById("ctl00_ContentPlaceHolder1_hdfMinAge").value = "0";
            document.getElementById("ctl00_ContentPlaceHolder1_hdfMaxAge").value = "0";
        }

    }
    if (id == 2) {
        var selVal2 = document.getElementById("ctl00_ContentPlaceHolder1_ddlHourlyRate").value;
        if (selVal2 != "0") {
            var val = selVal2.split("-");
            var min = parseInt(val[0]) - 1;
            var max = parseInt(val[1]) + 1;
            document.getElementById("ctl00_ContentPlaceHolder1_hdfHourlyRateMin").value = min;
            document.getElementById("ctl00_ContentPlaceHolder1_hdfHourlyRateMax").value = max;
        }
        else {
            document.getElementById("ctl00_ContentPlaceHolder1_hdfHourlyRateMin").value = "0";
            document.getElementById("ctl00_ContentPlaceHolder1_hdfHourlyRateMax").value = "0";
        }

    }
    if (id == 3) {
        var selVal3 = document.getElementById("ctl00_ContentPlaceHolder1_ddlExp").value;

        if (selVal3 != "0") {
            var val = selVal3.split("-");
            var min = parseInt(val[0]);
            var max = parseInt(val[1]);
            document.getElementById("ctl00_ContentPlaceHolder1_hdfMinExp").value = min;
            document.getElementById("ctl00_ContentPlaceHolder1_hdfMaxExp").value = max;
        }
        else {
            document.getElementById("ctl00_ContentPlaceHolder1_hdfMinExp").value = "0";
            document.getElementById("ctl00_ContentPlaceHolder1_hdfMaxExp").value = "0";
        }

    }
}

//function showJobslist() {
//    if (numJobs == 0) {
//        document.getElementById("tblJobsList").style.display = "";
//        numJobs = 1;
//    }
//    else {
//        document.getElementById("tblJobsList").style.display = "none";
//        numJobs = 0;
//    }
//}





//function catchJobSelItem(item) {

//    if (item == 1) {
//        document.getElementById("ctl00_body_searchbox1_lvSearch_txtJobServices").value = "Babysitting Jobs";
//        document.getElementById("ctl00_body_searchbox1_lvSearch_hdfJobServices").value = "1";
//        //  document.getElementById("ctl00_tdsharemasterjob").style.display = '';
//    }
//    else if (item == 2) {
//        document.getElementById("ctl00_body_searchbox1_lvSearch_txtJobServices").value = "Special Needs Jobs";
//        document.getElementById("ctl00_body_searchbox1_lvSearch_hdfJobServices").value = "2";
//        // document.getElementById("ctl00_tdsharemasterjob").style.display = 'none';
//    }
//    else if (item == 3) {
//        document.getElementById("ctl00_body_searchbox1_lvSearch_txtJobServices").value = "Tutoring Jobs";
//        document.getElementById("ctl00_body_searchbox1_lvSearch_hdfJobServices").value = "3";
//        // document.getElementById("ctl00_tdsharemasterjob").style.display = 'none';
//    }
//    else if (item == 4) {
//        document.getElementById("ctl00_body_searchbox1_lvSearch_txtJobServices").value = "Pet Sitting Jobs";
//        document.getElementById("ctl00_body_searchbox1_lvSearch_hdfJobServices").value = "4";
//        // document.getElementById("ctl00_tdsharemasterjob").style.display = '';
//    }
//    else if (item == 5) {
//        document.getElementById("ctl00_body_searchbox1_lvSearch_txtJobServices").value = "Elder Care Jobs";
//        document.getElementById("ctl00_body_searchbox1_lvSearch_hdfJobServices").value = "5";
//        //  document.getElementById("ctl00_tdsharemasterjob").style.display = '';
//    }
//    else if (item == 6) {
//        document.getElementById("ctl00_body_searchbox1_lvSearch_txtJobServices").value = "House Keeping Jobs";
//        document.getElementById("ctl00_body_searchbox1_lvSearch_hdfJobServices").value = "6";
//        //  document.getElementById("ctl00_tdsharemasterjob").style.display = '';
//    }
//    else if (item == 7) {
//        document.getElementById("ctl00_body_searchbox1_lvSearch_txtJobServices").value = "Personal Care Jobs";
//        document.getElementById("ctl00_body_searchbox1_lvSearch_hdfJobServices").value = "7";
//        //  document.getElementById("ctl00_tdsharemasterjob").style.display = '';
//    }


//    document.getElementById("divProviderList").style.display = "none";
//    numJobs = 0;
//}


//function catchLocJobSelItem(item) {

//    if (item == 1) {
//        document.getElementById("ctl00_body_searchbox_lvSearch_txtLocFindProvider").value = "Babysitting Jobs";
//        document.getElementById("ctl00_body_searchbox_lvSearch_hdfJobServices").value = "1";

//    }
//    else if (item == 2) {
//        document.getElementById("ctl00_body_searchbox_lvSearch_txtLocFindProvider").value = "Special Needs Jobs";
//        document.getElementById("ctl00_body_searchbox_lvSearch_hdfJobServices").value = "2";

//    }
//    else if (item == 3) {
//        document.getElementById("ctl00_body_searchbox_lvSearch_txtLocFindProvider").value = "Tutoring Jobs";
//        document.getElementById("ctl00_body_searchbox_lvSearch_hdfJobServices").value = "3";

//    }
//    else if (item == 4) {
//        document.getElementById("ctl00_body_searchbox_lvSearch_txtLocFindProvider").value = "Pet Sitting Jobs";
//        document.getElementById("ctl00_body_searchbox_lvSearch_hdfJobServices").value = "4";

//    }
//    else if (item == 5) {
//        document.getElementById("ctl00_body_searchbox_lvSearch_txtLocFindProvider").value = "Elder Care Jobs";
//        document.getElementById("ctl00_body_searchbox_lvSearch_hdfJobServices").value = "5";

//    }
//    else if (item == 6) {
//        document.getElementById("ctl00_body_searchbox_lvSearch_txtLocFindProvider").value = "House Keeping Jobs";
//        document.getElementById("ctl00_body_searchbox_lvSearch_hdfJobServices").value = "6";

//    }
//    else if (item == 7) {
//        document.getElementById("ctl00_body_searchbox_lvSearch_txtLocFindProvider").value = "Personal Care Jobs";
//        document.getElementById("ctl00_body_searchbox_lvSearch_hdfJobServices").value = "7";

//    }


//    document.getElementById("divLocProviderList").style.display = "none";
//    numLocJobs = 0;
//}


//function showLocJoblist() {

//    if (numLocJobs == 0) {
//        document.getElementById("divLocProviderList").style.display = "";
//        numLocJobs = 1;
//    }
//    else {
//        document.getElementById("divLocProviderList").style.display = "none";
//        numLocJobs = 0;
//    }
//}



// 30-9-2009 : added function to give more option links by sai 

function openDiv(divid) {
    document.getElementById(divid).style.display = "";
}
function closeDiv(divid) {
    document.getElementById(divid).style.display = "none";
}

// function for girdview hower selection.

function rowHover(tabid) {
    //alert(tabid);
    document.getElementById(tabid).style.borderWidth = "1px";
    document.getElementById(tabid).style.borderStyle = "solid";
    document.getElementById(tabid).style.borderColor = "#e98b42";

    //document.getElementById(tabid).style.background="background-image: url('../images/Nw_box_bg_hover.png') repeat-x";
    document.getElementById(tabid).className = "gridViewHower";


}

function rowHoverHide(tabid) {

    document.getElementById(tabid).style.borderWidth = "1px";
    document.getElementById(tabid).style.borderStyle = "solid";
    document.getElementById(tabid).style.borderColor = "#fff";
    document.getElementById(tabid).className = "";

}

function rowHowerSingleLine(rowid) {
    document.getElementById(rowid).className = "gridViewHowerSingleLine";
}

function rowHowerHideSingleLine(rowid) {
    document.getElementById(rowid).className = "";
}

//saved search pop up

function showSavedSearch() {
    if (saveSearchStatus == 0) {
        document.getElementById("divSavedSearch").style.display = "";
        saveSearchStatus = 1;
    }
    else {
        document.getElementById("divSavedSearch").style.display = "none";
        saveSearchStatus = 0;
    }
    return false;
}


//saved search validation

function validateSavedSearch(id) {
    var name = trim(document.getElementById(id).value);
    if (name == "") {//"ctl00_body_JobSearchResults1_lvSavedSearch_savedsearch_txtSearchName"
        alert("Please enter the saved search name");
        return false;
    }
    return true;
}

function trim(stringToTrim) {
    return stringToTrim.replace(/^\s+|\s+$/g, "");
}



// ------------------end search inner pannel----------

//--------common validation-----------------------------------
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };

/* Required field Validation */
/* 1) This script checks the value is entered or not.To use this we need to pass the Id of the element and Name of the field.
eg: return isValueEntered(this.id, 'FirstName');
*/


function isValueEntered(elementId, fieldName) {
    if (document.getElementById(elementId) != null) {

        if (document.getElementById(elementId).value.trim() == '') {
            alert('Please enter ' + fieldName);
            document.getElementById(elementId).focus();
            return false;
        }
        else {
            return true;
        }
    }
    else {
        alert('cannot find the element with ID ' + elementId);
        return false;
    }
}


/* Required field Validation  Which will show the mesage as a summary */
/* 2) This script checks the value is entered or not.To use this we need to pass the elementId of the element. */

function isValueEnteredNoAlerts(elementId) {
    if (document.getElementById(elementId) != null) {

        if (document.getElementById(elementId).value.trim() == '' || document.getElementById(elementId).value.trim() == '(___)___-____') {
            return false;
        }
        else {
            return true;
        }
    }
    else {
        return false;
    }

}
/* 3) This script checks the value is entered or not.To use this we need to pass the Id of the element and Name of the field. Alert messages given one by one.
eg: return validateAllRequiredelements('txtfirst,txtlast', 'FirstName, LastName');
*/
function validateAllRequiredValueelements(elementIds, fieldNames) {
    var ids = elementIds.split(',');
    var names = fieldNames.split(',');
    if (ids.length == names.length) {


        for (var i = 0; i < ids.length; i++) {
            if (ids[i] != null || names[i] != null) {
                //alert(document.getElementById(ids[i]).type);
                //if(document.getElementById(elementId).type=='')
                {
                    if (!isValueEntered(ids[i], names[i]))
                        return false;
                }
            }
            else {
                alert('use the JS function correctly.');
                return false;
            }
        }

        return true;
    }
    else {
        alert('Ids and fieldnames are not of same count.');
        alert('use the JS function correctly.');
        return false;
    }
}

/* 4) This script checks the value is entered or not.To use this we need to pass the Id of the element and Name of the field. Alert messages displayed as a Summary.
eg: return validateAllRequiredelements('txtfirst,txtlast', 'FirstName, LastName');
*/

function validateRequiredSummary(elementIds, fieldNames) {
    var ids = elementIds.split(',');
    var names = fieldNames.split(',');
    var msg = '';
    var firstValidate = '';
    if (ids.length == names.length) {
        for (var i = 0; i < ids.length; i++) {
            if (ids[i] != null || names[i] != null) {
                if (document.getElementById(ids[i]) != null) {
                    switch (document.getElementById(ids[i]).type) {
                        case 'text':
                            if (!isValueEnteredNoAlerts(ids[i])) {
                                msg += 'Please enter ' + names[i] + ' \n';
                                if (firstValidate == '')
                                    firstValidate = ids[i];
                            }
                            break;
                        case 'select-one':
                            if (!SelectRequiredDropdownNoAlert(ids[i])) {
                                msg += 'Please select ' + names[i] + ' \n';
                                if (firstValidate == '')
                                    firstValidate = ids[i];
                            }
                            break;
                        default:
                            if (!isValueEnteredNoAlerts(ids[i])) {
                                msg += 'Please enter ' + names[i] + ' \n';
                                if (firstValidate == '')
                                    firstValidate = ids[i];
                            }
                            break;
                    }
                }
                else {
                    alert('cannot find control with id' + ids[i]);
                    return false;
                }
            }
            else {
                alert('use the JS function correctly.');
                return false;
            }
        }
        if (msg != '') {
            var len = msg.length;
            msg = msg.substring(0, len - 2);
            alert(msg);
            //alert(msg).TrimEnd(' \n');
            document.getElementById(firstValidate).focus();
            return false;
        }
        else {
            return true;
        }
    }
    else {
        alert('Ids and fieldnames are not of same count. \n use the JS function correctly.');
        return false;
    }
}


/* Maximum Length */
/* 5)   This script restricts the value to Maximum length. To use this we need to pass the Id of the element ,Name of the field, maximum length to allowed.
eg: return isValueEntered(this.id, 'FirstName',20); 
*/
function checkMaxLength(elementId, fieldName, maxLength) {
    if (document.getElementById(elementId) != null) {
        if (document.getElementById(elementId).value.length > parseInt(maxLength, 0)) {
            document.getElementById(elementId).focus();
            alert('Please Maximum length for ' + fieldName + ' is ' + maxLength);
            return false;
        }
        else {
            return true;
        }
    }
    else {
        alert('cannot find the element with ID ' + elementId);
        return false;
    }
}



/* Minimum Length */
/* 6)   This script restricts the value to Maximum length. To use this we need to pass the Id of the element ,Name of the field, maximum length to allowed.
eg: return isValueEntered(this.id, 'FirstName',20); 
*/
function checkMinLength(elementId, fieldName, minLength) {
    if (document.getElementById(elementId) != null) {
        if (document.getElementById(elementId).value.length < parseInt(minLength, 0)) {
            document.getElementById(elementId).focus();
            alert('Please Minimum length  for ' + fieldName + ' is ' + minLength + '  Charactors. ');

            return false;

        }
        else {
            return true;
        }
    }
    else {
        alert('cannot find the element with ID ' + elementId);
        return false;
    }
}



/* Only Charactors */
/* 7)   This script restricts the value only charactors and Space are allowed. To use this we need to pass the Id of the element.
eg:- onkeypress="return onlyCharacters(this,event);"
*/

function onlyCharacters(input, kbEvent)  //,control
{
    var keyCode, keyChar;
    //keyCode = kbEvent.keyCode;
    if (window.event)
        keyCode = kbEvent.keyCode; 	// IE
    else
        keyCode = kbEvent.which; 	//firefox		         

    if (keyCode == null) return true;
    // get character
    keyChar = String.fromCharCode(keyCode);
    var charSet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
    // check valid chars
    if (charSet.indexOf(keyChar) != -1) return true;
    // control keys
    if (keyCode == null || keyCode == 0 || keyCode == 8 || keyCode == 9 || keyCode == 13 || keyCode == 27) return true;
    return false;
}


//********* Allow Charactor's user specified  *********//

/*  8)  This script allow the user to enter the characters(parameter) To use this we need to pass the Id of the element,
Name of the field nad the charactors need to allow.  */

function AllowCustomCharacters(input, kbEvent, characters) {
    var keyCode, keyChar;
    //keyCode = kbEvent.keyCode;
    if (window.event)
        keyCode = kbEvent.keyCode; 	// IE
    else
        keyCode = kbEvent.which; 	//firefox		         

    if (keyCode == null) return true;
    // get character
    keyChar = String.fromCharCode(keyCode);
    var charSet = characters;   //"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
    // check valid chars
    if (charSet.indexOf(keyChar) != -1) return true;
    // control keys
    if (keyCode == null || keyCode == 0 || keyCode == 8 || keyCode == 9 || keyCode == 13 || keyCode == 27) return true;
    return false;
}

//********* End of Allow Charactor's user specified *********//




//********* Deny Charactor's user specified  *********//


/*  9)  This script allow the user to enter the characters(parameter) 
To use this we need to pass the Id of the element,charactors need to deny.
*/

function DenyCustomCharacters(input, kbEvent, characters) {

    var keyCode, keyChar;
    //keyCode = kbEvent.keyCode;
    if (window.event)
        keyCode = kbEvent.keyCode; 	// IE
    else
        keyCode = kbEvent.which; 	//firefox		         

    if (keyCode == null) return true;
    // get character
    keyChar = String.fromCharCode(keyCode);
    var charSet = characters;   //"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
    // check valid chars
    if (charSet.indexOf(keyChar) != -1) return false;
    // control keys
    if (keyCode == null || keyCode == 0 || keyCode == 8 || keyCode == 9 || keyCode == 13 || keyCode == 27) return true;
    return true;
}

//********* End of Deny Charactor's user specified *********//



//********* provide the Length of a String *********//

/*  10)  Description: A script that checks the number of minimun and maximum characters in a form control provided by the user and if it exceeds the predetermined number, 
cancels the form submission, and asks the user to reenter data. Note that the validation occurs after the user presses the submit button.     */

function CompareLength(elementId, fieldName, minLength, maxLength) {
    if (document.getElementById(elementId) != null) {

        if ((document.getElementById(elementId).value.length < parseInt(minLength, 0)) || (document.getElementById(elementId).value.length > parseInt(maxLength, 0))) {
            document.getElementById(elementId).focus();
            alert('Please Minimum length  for ' + fieldName + 'is ' + minLength + '  Charactors. and Maxlength is ' + maxLength);
            return false;
        }
        else {
            return true;
        }
    }

    else {
        alert('cannot find the element with ID ' + elementId);
        return false;
    }
}

//********* End of Finding the Length of a String *********//



//********* check the integer in between min and max values *********//

/*  11)  Description: A script that checks the minimun value in a form control provided by the user and if it exceeds the predetermined number, 
cancels the form submission, and asks the user to reenter data. Note that the validation occurs after 
the user presses the submit button.     */

function IsInBetweenValue(elementId, fieldName, minvalue, maxvalue) {
    if (document.getElementById(elementId) != null) {

        if ((document.getElementById(elementId).value <= parseInt(minvalue, 0)) || (document.getElementById(elementId).value >= parseInt(maxvalue, 0))) {

            document.getElementById(elementId).focus();
            alert('Enter ' + fieldName + 'is greaterthan ' + minvalue + ' And lessthan ' + maxvalue);
            return false;
        }
        else {
            return true;
        }
    }

    else {
        alert('cannot find the element with ID ' + elementId);
        return false;
    }
}

//********* End of check the integer with Min value *********//



//********* check the integer with min value *********//

/*  12)  Description: A script that checks the minimun value in a form control provided by the user and if it exceeds the predetermined number, 
cancels the form submission, and asks the user to reenter data. Note that the validation occurs after 
the user presses the submit button.     */

function IsMinimumValue(elementId, fieldName, value) {
    if (document.getElementById(elementId) != null) {

        if (parseInt(document.getElementById(elementId).value, 0) >= parseInt(value, 0)) {
            document.getElementById(elementId).focus();
            alert('Please Enter ' + fieldName + 'is lessthan ' + value);
            return false;
        }
        else {
            return true;
        }
    }

    else {
        alert('cannot find the element with ID ' + elementId);
        return false;
    }
}

//********* End of check the integer with Min value *********//




//********* check the integer with Max value *********//

/*  13)  Description: A script that checks the maximum Value in a form control provided by the user and if it exceeds the predetermined number, 
cancels the form submission, and asks the user to reenter data. Note that the validation occurs after 
the user presses the submit button.     */

function IsMaximumValue(elementId, fieldName, maxvalue) {
    if (document.getElementById(elementId) != null) {

        if (document.getElementById(elementId).value <= parseInt(maxvalue, 0)) {
            document.getElementById(elementId).focus();
            alert('Please enter ' + fieldName + ' is Greater than ' + maxvalue);
            return false;
        }
        else {
            return true;
        }
    }

    else {
        alert('cannot find the element with ID ' + elementId);
        return false;
    }
}

//********* End of check the integer with Max value *********//




//********* Only Number Validation *********//

/*  14) Description: This script allow you to enter only numbers these special charactors.
This script requires NS 4.x or IE 4.x to function-all other browsers will simply not participate in the number checking. */
function AllowNumbersOnly(input, kbEvent) {
    var keyCode, keyChar;
    //keyCode = kbEvent.keyCode;
    if (window.event)
        keyCode = kbEvent.keyCode; 	// IE
    else
        keyCode = kbEvent.which; 	//firefox		         
    if (keyCode == null) return true;
    // get character
    keyChar = String.fromCharCode(keyCode);
    var charSet = "0123456789";
    // check valid chars
    if (charSet.indexOf(keyChar) != -1) return true;
    // control keys
    if (keyCode == null || keyCode == 0 || keyCode == 8 || keyCode == 9 || keyCode == 13 || keyCode == 27) return true;
    return false;
}

//********* End of Phone Number Validation *********//




//********* Select the values from droupdown *********//

/*  15) Description: This script allow you to select the value from droupdownlist.*/
function SelectRequiredDropdown(elementId, fieldName) {
    if (document.getElementById(elementId) != null) {
        var obj = document.getElementById(elementId);
        if (obj.selectedIndex == 0) {
            document.getElementById(elementId).focus();
            alert('Please Select the ' + fieldName + ' from Drop Down');
            return false;
        }
        return true;
    }
    else {
        alert('cannot find the element with ID ' + elementId);
        return false;
    }
}

//********* Select the values from droupdown *********//

/*  16) Description: This script allow you to select the value from droupdownlist. with Validation Summary*/

function SelectRequiredDropdownNoAlert(elementId) {
    if (document.getElementById(elementId) != null) {
        var obj = document.getElementById(elementId);
        if (obj.selectedIndex == 0) {
            document.getElementById(elementId).focus();
            return false;
        }
        return true;
    }
    else {
        return false;
    }
}

//********* End of Select the values from droupdown  *********//


//********* Select the values from RadioButton *********//

/*  17) Description: This script allow you to select the value from RadioButton.*/

function SelectRequiredRadiobutton(controlid, filedName) {
    var radio = document.getElementsByName(controlid);
    var count = 0;
    for (var j = 0; j < radio.length; j++) {
        if (radio[j].checked == true) {
            count++;
            return true;
        }
    }
    if (count > 0) {
        return false;
    }
    else {
        alert('please select  ' + filedName);
        document.getElementById(controlid).focus();
        return false;
    }
}

//********* End of Select the values from RadioButton *********//


//********* Select the values from Checkbox *********//

/*18) Description: This script allow you to select the value from Checkbox.*/

function SelectCheckBoxsAtleast(elementId, fieldName, minValue, maxValue) {
    var elementRef = document.getElementById(elementId);
    var checkBoxArray = elementRef.getElementsByTagName('input');
    var count = 0;
    for (var i = 0; i < checkBoxArray.length; i++) {
        if (checkBoxArray[i].checked)
            count++;
    }
    if (count < minValue) {
        alert("Please check atleast " + minValue + " at " + fieldName);
        return false;
    }
    if (count > maxValue) {
        alert("Please check only " + maxValue + " at " + fieldName);
        return false;
    }
    //alert(checkBoxArray.length);
    return true;
}

/********* End ofSelect the values from Checkbox *********/



/********* Allow numbers with decimal point *********/

/*  19) Description: This script allow you to Enter only Decimal Values.*/

function CheckDecimalValue(elementId, msg) {
    if (document.getElementById(elementId) != null) {
        var val = document.getElementById(elementId).value;
        var y = val.split('.');
        if (y.length > 2) {
            document.getElementById(elementId).focus();
            alert('Enter Correct Decimal value for ' + msg);
            return false;
        }
        else {
            return true;
        }
    }
    else {
        alert('cannot find the element with ID ' + elementId);
        return false;
    }
}

//********* End of Allow numbers with decimal point *********//


//********* Check the Both Password's Same or not  *********//

/*  20) Description: This script allow you to Entered values same or not.*/

function IsValuesEqual(controlId1, controlId2, fieldName1, fieldName2) {
    if ((document.getElementById(controlId1) != null) && (document.getElementById(controlId2) != null)) {
        var first = document.getElementById(controlId1).value;
        var second = document.getElementById(controlId2).value;

        if (first != second) {
            document.getElementById(controlId2).focus();
            alert(fieldName1 + ' and ' + fieldName2 + ' are not same');
            return false;
        }
        else {
            return true;
        }
    }
    else {
        alert('cannot find the element with ID ' + control1 + ' or ' + control2);
        return false;
    }
}

//********* End of Check the Both Password's Same or not  *********//


//********* Check the Required, min and Maxlength of the control *********//

/*  21) Description: This script allow you to check the control should not empty 
also validate the minLength and maxLength length entered by the user .*/


function checkMinAndMaxLength(control1, minLength, maxLength, fieldName) {
    if (document.getElementById(control1) != null) {
        if (document.getElementById(control1).value != '') {
            var str = trim(document.getElementById(control1).value, '');
            if ((str.length < minLength) || (str.length > maxLength)) {
                alert('Please Enter ' + fieldName + 'Length Must be Greater than or equal to ' + minLength + ' and Less than or equal to ' + maxLength);
                document.getElementById(control1).value = str;
                document.getElementById(control1).focus();
                return false;
            }
            else {
                return true;
            }
        }
        else {
            alert('Enter the value for  ' + fieldName);
            document.getElementById(control1).focus();
            return false;
        }
    }
    else {
        alert('cannot find the element with ID ' + control1);
        return false;
    }
}

//********* End Of Check the Required, min and Maxlength of the control *********//


/* 22)With this script, users must explicitly signal their acceptance of your terms/conditions (by checking a box)
, before he/she can submit the form. Very useful script. Here f is the form ID and call this script in the
onsubmit() of form tag */
function checkCheckBox(elementId) {
    if (elementId.checked == false) {

        alert('Please Check The CheckBox To Accept The Terms And Conditions To Continue .');
        return false;
    }
    else
        return true;
}

/*23)This script automatically clears the default text inside the containing form element when the user sets focus 
on it, so the user can just aim, focus, and starting typing.hear the parameter "elementId" is the ID of the element 
*/
function clearDefaultTetx(elementId) {
    elementId.valueOf = '';
}

/* 24)  This script "auto tabs" a form field (and jumps to another field) once the length of the field's value has 
exceeded a certain length. It works in conjunction with the "maxlength" attribute of HTML, triggered whenever 
the user's input reaches the maxlength's value.Here the parameter "original" is the ID of the current textBox
and the parameter "destination" is the ID of the next textbox
*/
function autotab(original, destination) {
    if (original.getAttribute && original.value.length == original.getAttribute("maxlength"))
        destination.focus();
}


/*  This script Calculates and display the number of characters within a TEXTAREA, the parameter "txt" is the
textarea or any other element and the parameter "displaycount" is the elemrnt in which we want to display the 
count value.*/

function countit(txt, displaycount) {
    var formcontent = txt.value;
    displaycount.value = formcontent.length;
}

/*26)This script is used to make all the checkboxes or radiobuttons in a form true or false here the parameter
"checkname" is the name attribute of the checkboxes and the parameter "thestate" is the boolen value to know the state 
of the elements*/

function checkall(checkname, thestate) {
    for (var c = 0; c < checkname.length; c++)
        el_collection[c].checked = thestate;
}


/*  This script checks the contents of a form box to ensure that its a number (updated to accept demicals). 
If not, the submission of the form is canceled, and the surfer prompted to re-enter a valid number. This script 
requires NS 4.x or IE 4.x to function-all other browsers will simply not participate in the number checking. */

function checknumber() {
    var x = document.getElementById('txt').value;
    alert(x);
    var anum = /(^\d+$)|(^\d+\.\d+$)/;
    if (anum.test(x))
        testresult = true;
    else {
        alert("Please input a valid number!");
        testresult = false;
    }
    return (testresult);
}


/*  This is script is to check whether the given date is in given format or not, the first parameter is the id of 
the element and the second parameter is the saparator of the date elements, for example if you want the date to be
in "mm/dd/yyyy" the saparator will be "/" and if you want the date in "mm-dd-yyyy" the saparator will be "-"
this script supports only three saparators ".,-,/"*/


function checkdate(id, saparator, message) {

    var objRegExp;
    if (saparator == ".") {
        objRegExp = /^\d{1,2}(\.)\d{1,2}\1\d{4}$/;
    }
    else if (saparator == "-") {
        objRegExp = /^\d{1,2}(\-)\d{1,2}\1\d{4}$/;
    }
    else {
        objRegExp = /^\d{1,2}(\/)\d{1,2}\1\d{4}$/;
    }

    //var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
    var strValue = document.getElementById(id).value;
    //check to see if in correct format
    if (!objRegExp.test(strValue)) {
        alert("Invalid Date Format : " + message);
        return false; //doesn't match pattern, bad date
    }
    else {
        var strSeparator = strValue.substring(2, 3);
        var arrayDate = strValue.split(strSeparator);
        //create a lookup for months not equal to Feb.
        var arrayLookup = { '01': 31, '03': 31,
            '04': 30, '05': 31,
            '06': 30, '07': 31,
            '08': 31, '09': 30,
            '10': 31, '11': 30, '12': 31
        };
        var intDay = parseInt(arrayDate[1], 10);

        //check if month value and day value agree
        if (arrayLookup[arrayDate[0]] != null) {
            if (intDay <= arrayLookup[arrayDate[0]] && intDay != 0)
                return true; //found in lookup table, good date
        }

        //check for February (bugfix 20050322)
        //bugfix  for parseInt kevin
        //bugfix  biss year  O.Jp Voutat
        var intMonth = parseInt(arrayDate[0], 10);
        if (intMonth == 2) {
            var intYear = parseInt(arrayDate[2]);
            if (intDay > 0 && intDay < 29) {
                return true;
            }
            else if (intDay == 29) {
                if ((intYear % 4 == 0) && (intYear % 100 != 0) || (intYear % 400 == 0)) {
                    // year div by 4 and ((not div by 100) or div by 400) ->ok
                    return true;
                }
            }
        }
    }
    alert("Invalid Date Format : " + message);
    return false; //any other values, bad date
}

//********* To Validate the Entered Email-Id in correct format or not *********//
/*  Email verification the parameter passed is the id of the control which holdes the email address*/

function validateEmail(id) {
    var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    var str = document.getElementById(id).value;
    if (str.match(emailRegEx)) {
        if (checkMailId(str))
            return true;
        else {
            alert('Please enter a valid email address.');
            return false;
        }
    }
    else {
        alert('Please enter a valid email address.');
        document.getElementById(id).focus();
        return false;
    }
}

function validateEmailWithoutAlert(id) {
    var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    var str = document.getElementById(id).value;
    if (str.match(emailRegEx)) {
        if (checkMailId(str))
            return true;
        else
            return false;
    }
    else {
        //document.getElementById(id).focus();
        return false;
    }
}


function checkMailId(mailids) {
    var arr = new Array(
    '.com', '.net', '.org', '.biz', '.coop', '.info', '.museum', '.name', '.pro',
    '.edu', '.gov', '.int', '.mil', '.ac', '.ad', '.ae', '.af', '.ag', '.ai', '.al',
    '.am', '.an', '.ao', '.aq', '.ar', '.as', '.at', '.au', '.aw', '.az', '.ba', '.bb',
    '.bd', '.be', '.bf', '.bg', '.bh', '.bi', '.bj', '.bm', '.bn', '.bo', '.br', '.bs',
    '.bt', '.bv', '.bw', '.by', '.bz', '.ca', '.cc', '.cd', '.cf', '.cg', '.ch', '.ci',
    '.ck', '.cl', '.cm', '.cn', '.co', '.cr', '.cu', '.cv', '.cx', '.cy', '.cz', '.de',
    '.dj', '.dk', '.dm', '.do', '.dz', '.ec', '.ee', '.eg', '.eh', '.er', '.es', '.et',
    '.fi', '.fj', '.fk', '.fm', '.fo', '.fr', '.ga', '.gd', '.ge', '.gf', '.gg', '.gh',
    '.gi', '.gl', '.gm', '.gn', '.gp', '.gq', '.gr', '.gs', '.gt', '.gu', '.gv', '.gy',
    '.hk', '.hm', '.hn', '.hr', '.ht', '.hu', '.id', '.ie', '.il', '.im', '.in', '.io',
    '.iq', '.ir', '.is', '.it', '.je', '.jm', '.jo', '.jp', '.ke', '.kg', '.kh', '.ki',
    '.km', '.kn', '.kp', '.kr', '.kw', '.ky', '.kz', '.la', '.lb', '.lc', '.li', '.lk',
    '.lr', '.ls', '.lt', '.lu', '.lv', '.ly', '.ma', '.mc', '.md', '.mg', '.mh', '.mk',
    '.ml', '.mm', '.mn', '.mo', '.mp', '.mq', '.mr', '.ms', '.mt', '.mu', '.mv', '.mw',
    '.mx', '.my', '.mz', '.na', '.nc', '.ne', '.nf', '.ng', '.ni', '.nl', '.no', '.np',
    '.nr', '.nu', '.nz', '.om', '.pa', '.pe', '.pf', '.pg', '.ph', '.pk', '.pl', '.pm',
    '.pn', '.pr', '.ps', '.pt', '.pw', '.py', '.qa', '.re', '.ro', '.rw', '.ru', '.sa',
    '.sb', '.sc', '.sd', '.se', '.sg', '.sh', '.si', '.sj', '.sk', '.sl', '.sm', '.sn',
    '.so', '.sr', '.st', '.sv', '.sy', '.sz', '.tc', '.td', '.tf', '.tg', '.th', '.tj',
    '.tk', '.tm', '.tn', '.to', '.tp', '.tr', '.tt', '.tv', '.tw', '.tz', '.ua', '.ug',
    '.uk', '.um', '.us', '.uy', '.uz', '.va', '.vc', '.ve', '.vg', '.vi', '.vn', '.vu',
    '.ws', '.wf', '.ye', '.yt', '.yu', '.za', '.zm', '.zw');


    var temp = "wrong";
    var mai = mailids; //ids[j];

    if (mai.charCodeAt(mai.length - 1) == 13)
        mai = mai.substring(0, mai.length - 1);

    var dot = mai.lastIndexOf(".");
    var con = mai.substring(dot, mai.length);
    con = con.toLowerCase();
    con = con.toString();

    for (var i = 0; i < (arr.length); i++) {
        if (con == arr[i]) {
            temp = 'right';
        }
    }
    if (temp == "wrong") {
        return false;
    }
    return true;

}

//********* End Of the Entered Email-Id in correct format or not *********//


//********* To Validate the Entered PhoneNumber in correct format or not *********//
/*   US phone validation the parameter passed is the id of the control which holdes the Phone number*/


function validatePhoneNumber(id, filedName) {

    var phoneNumberPattern = /^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/;
    str = document.getElementById(id).value;
    if (str != '' && str != '(___)___-____') {
        if (str.match(phoneNumberPattern)) {
            return true;
        }
        else {
            alert('Please enter ' + filedName + ' in the form of (123)456-7896');
            document.getElementById(id).focus();
            return false;
        }
    }
    else
        return true;
}
//********* End Of the Validate the Entered PhoneNumber in correct format or not *********//


//********* To Validate the Entered string is having atleast one digit and one charactor *********//
function HasAtleastOneNumOneChar(elementId, fieldName) {
    var Pattern = /(^.*(?=.{4,})(?=.*\d)(?=.*[a-z][A-Z]).*$)/;      //expression for atleat one uppercase and atleast one number and atleast one lowercase


    str = document.getElementById(elementId).value;
    if (str.match(Pattern)) {
        return true;
    }
    else {
        alert('Please Enter ' + fieldName + ' include at least one lower case letter, and one numeric digit..');
        return false;
    }
}

//********* End of the Validate the Entered string is having atleast one digit and one charactor *********//



//********* To Validate the US ZIP code *********//
function validateUSZip(id) {
    var zipPattern = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
    str = document.getElementById(id).value;
    if (str.match(zipPattern)) {
        if (str == '00000') {
            alert('Please enter a valid ZIP Code');
            return false;
        }
        else {
            return true;
        }
    }
    else {
        alert('Please enter a valid ZIP Code');
        return false;
    }
}


//********* End of the Validate the US ZIP code *********//


//********* To Validate the string have atleast one number and one lowercase charactor *********//
/*    The parameter passed is the id of the control which Allow Atleast One Number and One Lower case Charactor */


function HasAtleastOneNumOneLowerChar(elementId, fieldName) {
    // var ZipPattern=/(^.*(?=.{4,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$)/ //expression for atleat one uppercase and atleast one number and atleast one lowercase
    var Pattern = /(^.*(?=.{2,})(?=.*\d)(?=.*[a-z]).*$)/;      //expression for atleat atleast one number and atleast one lowercase   
    str = document.getElementById(elementId).value;
    if (str.match(Pattern)) {
        return true;
    }
    else {
        alert('Please Enter ' + fieldName + ' include at least one lower case letter, and one numeric digit..');
        return false;
    }
}

//********* End of the Validate the string have atleast one number and one lowercase charactor *********//


/*    The parameter passed is the id of the control which Allow Atleast One Number and One Upper case Charactor */


function HasAtleastOneNumOneUpperChar(elementId, fieldName) {
    // var ZipPattern=/(^.*(?=.{4,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$)/ //expression for atleat one uppercase and atleast one number and atleast one lowercase
    var Pattern = /(^.*(?=.{1,})(?=.*\d)(?=.*[A-Z]).*$)/;     //expression for atleat atleast one number and atleast one lowercase   
    str = document.getElementById(elementId).value;
    if (str.match(Pattern)) {
        return true;
    }
    else {
        alert('Please Enter ' + fieldName + ' include at least one Upper case letter, and one numeric digit..');
        return false;
    }
}

//********* End of the Validate the string have atleast one number and one uppercase charactor *********//



function IsDateGreater(DateElementId, CompareDateElementId, DateField, CompareDateField) {
    var SDate = document.getElementById(DateElementId).value;
    var EDate = document.getElementById(CompareDateElementId).value;


    var endDate = new Date(EDate);
    var startDate = new Date(SDate);

    if (SDate == '') {
        alert("Please enter " + DateField);
        return false;
    }
    else if (EDate == '') {
        alert("Please enter" + CompareDateElementId);
        return false;
    }
    else if (startDate > endDate) {

        return false;
    }
    else {
        return true;
    }

}


function IsDateGreaterOrEqual(DateElementId, CompareDateElementId, DateField, CompareDateField) {
    ////    var SDate = document.getElementById(DateElementId).value;
    ////   var EDate = document.getElementById(CompareDateElementId).value;
    var EDate = document.getElementById(DateElementId).value;
    var SDate = document.getElementById(CompareDateElementId).value;


    var endDate = new Date(EDate);
    var startDate = new Date(SDate);

    if (SDate == '') {
        alert("Please enter " + DateField);
        return false;
    }
    else if (EDate == '') {
        alert("Please enter " + CompareDateField);
        return false;
    }
    // else if (startDate < endDate) {
    else if (endDate < startDate) {

        return false;
    }
    else {
        return true;
    }
}

function IsDateLessthanOrEqual(DateElementId, CompareDateElementId, DateField, CompareDateField) {
    //    var SDate = document.getElementById(DateElementId).value;
    //    var EDate = document.getElementById(CompareDateElementId).value;
    var EDate = document.getElementById(DateElementId).value;
    var SDate = document.getElementById(CompareDateElementId).value;


    var endDate = new Date(EDate);
    var startDate = new Date(SDate);

    if (SDate == '') {
        alert("Please enter " + DateField);
        return false;
    }
    else if (EDate == '') {
        alert("Please enter " + CompareDateField);
        return false;
    }
    else if (startDate < endDate) {
        return false;
    }
    else {
        return true;
    }
}


//Validating Start Date and End Date
function ValidateDate(CtrlSDate, CtrlEDate) {
    var SDate = document.getElementById(CtrlSDate).value;
    var EDate = document.getElementById(CtrlEDate).value;


    var alertReason1 = 'End Date must be greater than or equal to  Start Date.';
    var alertReason2 = 'End Date can not be less than Current Date.';

    var endDate = new Date(EDate);
    var startDate = new Date(SDate);


    var now = new Date();

    if (SDate == '') {
        alert("Please enter Start Date");
        return false;
    }
    else if (EDate == '') {
        alert("Please enter End Date");
        return false;
    }
    else if (startDate < now) {
        alert("start date should be  greater than Current date");
        return false;
    }
    else if (startDate > endDate) {
        alert(alertReason1);
        document.getElementById(CtrlEDate).value = "";
        return false;
    }
    else {
        return true;
    }
}

/*validating Credit Card number, the first parameter is the creditcard number and the second parameter is the type 
of credit card ex:visa,master card*/

function checkCreditCard(cardnumber, cardname) {

    var ccErrorNo = 0;
    var ccErrors = new Array();

    ccErrors[0] = "Unknown card type";
    ccErrors[1] = "No card number provided";
    ccErrors[2] = "Credit card number is in invalid format";
    ccErrors[3] = "Credit card number is invalid";
    ccErrors[4] = "Credit card number has an inappropriate number of digits";

    // Array to hold the permitted card characteristics
    var cards = new Array();

    // Define the cards we support. You may add addtional card types.

    //  Name:      As in the selection box of the form - must be same as user's
    //  Length:    List of possible valid lengths of the card number for the card
    //  prefixes:  List of possible prefixes for the card
    //  checkdigit Boolean to say whether there is a check digit

    cards[0] = { name: "Visa",
        length: "13,16",
        prefixes: "4",
        checkdigit: true
    };
    cards[1] = { name: "MasterCard",
        length: "16",
        prefixes: "51,52,53,54,55",
        checkdigit: true
    };
    cards[2] = { name: "DinersClub",
        length: "14,16",
        prefixes: "36,54,55",
        checkdigit: true
    };
    cards[3] = { name: "CarteBlanche",
        length: "14",
        prefixes: "300,301,302,303,304,305",
        checkdigit: true
    };
    cards[4] = { name: "AmEx",
        length: "15",
        prefixes: "34,37",
        checkdigit: true
    };
    cards[5] = { name: "Discover",
        length: "16",
        prefixes: "6011,622,64,65",
        checkdigit: true
    };
    cards[6] = { name: "JCB",
        length: "16",
        prefixes: "35",
        checkdigit: true
    };
    cards[7] = { name: "enRoute",
        length: "15",
        prefixes: "2014,2149",
        checkdigit: true
    };
    cards[8] = { name: "Solo",
        length: "16,18,19",
        prefixes: "6334, 6767",
        checkdigit: true
    };
    cards[9] = { name: "Switch",
        length: "16,18,19",
        prefixes: "4903,4905,4911,4936,564182,633110,6333,6759",
        checkdigit: true
    };
    cards[10] = { name: "Maestro",
        length: "12,13,14,15,16,18,19",
        prefixes: "5018,5020,5038,6304,6759,6761",
        checkdigit: true
    };
    cards[11] = { name: "VisaElectron",
        length: "16",
        prefixes: "417500,4917,4913,4508,4844",
        checkdigit: true
    };
    cards[12] = { name: "LaserCard",
        length: "16,17,18,19",
        prefixes: "6304,6706,6771,6709",
        checkdigit: true
    };

    // Establish card type
    var cardType = -1;
    for (var i = 0; i < cards.length; i++) {

        // See if it is this card (ignoring the case of the string)
        if (cardname.toLowerCase() == cards[i].name.toLowerCase()) {
            cardType = i;
            break;
        }
    }

    // If card type not found, report an error
    if (cardType == -1) {
        //ccErrorNo = 0;
        alert(ccErrors[0]);
        return false;
    }

    // Ensure that the user has provided a credit card number
    if (cardnumber.length == 0) {
        //ccErrorNo = 1;
        alert(ccErrors[1]);
        return false;
    }

    // Now remove any spaces from the credit card number
    cardnumber = cardnumber.replace(/\s/g, "");

    // Check that the number is numeric
    var cardNo = cardnumber;
    var cardexp = /^[0-9]{13,19}$/;
    if (!cardexp.exec(cardNo)) {
        //ccErrorNo = 2;
        alert(ccErrors[2]);
        return false;
    }

    // Now check the modulus 10 check digit - if required
    if (cards[cardType].checkdigit) {
        var checksum = 0;                                  // running checksum total
        var mychar = "";                                   // next char to process
        var j = 1;                                         // takes value of 1 or 2

        // Process each digit one by one starting at the right
        var calc;
        for (i = cardNo.length - 1; i >= 0; i--) {

            // Extract the next digit and multiply by 1 or 2 on alternative digits.
            calc = Number(cardNo.charAt(i)) * j;

            // If the result is in two digits add 1 to the checksum total
            if (calc > 9) {
                checksum = checksum + 1;
                calc = calc - 10;
            }

            // Add the units element to the checksum total
            checksum = checksum + calc;

            // Switch the value of j
            if (j == 1) { j = 2; } else { j = 1; };
        }

        // All done - if checksum is divisible by 10, it is a valid modulus 10.
        // If not, report an error.
        if (checksum % 10 != 0) {
            //ccErrorNo = 3;
            alert(ccErrors[3]);
            return false;
        }
    }

    // The following are the card-specific checks we undertake.
    var LengthValid = false;
    var PrefixValid = false;
    var undefined;

    // We use these for holding the valid lengths and prefixes of a card type
    var prefix; //= new Array();
    var lengths; //= new Array();

    // Load an array with the valid prefixes for this card
    prefix = cards[cardType].prefixes.split(",");

    // Now see if any of them match what we have in the card number
    for (i = 0; i < prefix.length; i++) {
        var exp = new RegExp("^" + prefix[i]);
        if (exp.test(cardNo)) PrefixValid = true;
    }

    // If it isn't a valid prefix there's no point at looking at the length
    if (!PrefixValid) {
        //ccErrorNo = 3;
        alert(ccErrors[3]);
        return false;
    }

    // See if the length is valid for this card
    lengths = cards[cardType].length.split(",");
    for (j = 0; j < lengths.length; j++) {
        if (cardNo.length == lengths[j]) LengthValid = true;
    }

    // See if all is OK by seeing if the length was valid. We only check the 
    // length if all else was hunky dory.
    if (!LengthValid) {
        //ccErrorNo = 4;
        alert(ccErrors[4]);
        return false;
    };

    // The credit card is in the required format.
    return true;
}

/*approch two for validation summary*/


function Validator(frmname) {
    this.formobj = document.forms[frmname];
    if (!this.formobj) {
        alert("Error: couldnot get Form object " + frmname);
        return;
    }
    if (this.formobj.onsubmit) {
        this.formobj.old_onsubmit = this.formobj.onsubmit;
        this.formobj.onsubmit = null;
    }
    else {
        this.formobj.old_onsubmit = null;
    }
    this.formobj._sfm_form_name = frmname;
    this.formobj.onsubmit = form_submit_handler;
    this.addValidation = add_validation;

    this.setAddnlValidationFunction = set_addnl_vfunction;
    this.clearAllValidations = clear_all_validations;
    this.disable_validations = false; //new
    document.error_disp_handler = new sfm_ErrorDisplayHandler();
    this.EnableOnPageErrorDisplay = validator_enable_OPED;
    this.EnableOnPageErrorDisplaySingleBox = validator_enable_OPED_SB;
    this.show_errors_together = true;
    this.EnableMsgsTogether = sfm_enable_show_msgs_together;
    document.set_focus_onerror = true;
    this.EnableFocusOnError = sfm_validator_enable_focus;

}

function sfm_validator_enable_focus(enable) {
    document.set_focus_onerror = enable;
}

function set_addnl_vfunction(functionname) {
    this.formobj.addnlvalidation = functionname;
}

function sfm_set_focus(objInput) {
    if (document.set_focus_onerror) {
        objInput.focus();
    }
}

function sfm_enable_show_msgs_together() {
    this.show_errors_together = true;
    this.formobj.show_errors_together = true;
}
function clear_all_validations() {
    for (var itr = 0; itr < this.formobj.elements.length; itr++) {
        this.formobj.elements[itr].validationset = null;
    }
}

function form_submit_handler() {
    var bRet = true;
    document.error_disp_handler.clear_msgs();
    for (var itr = 0; itr < this.elements.length; itr++) {
        if (this.elements[itr].validationset &&
	   !this.elements[itr].validationset.validate()) {
            bRet = false;
        }
        if (!bRet && !this.show_errors_together) {
            break;

        }
    }

    if (this.addnlvalidation) {
        str = " var ret = " + this.addnlvalidation + "()";
        eval(str);

        if (!ret) {
            bRet = false;
        }

    }

    if (!bRet) {
        document.error_disp_handler.FinalShowMsg();
        return false;
    }
    return true;
}
/*by naresh for compairing*/
function addCompare(obj1, obj2, errStr) {


    var itemobj1 = document.getElementById(obj1);
    var itemobj2 = document.getElementById(obj2);

    if (itemobj1.value != itemobj2.value) {
        //this.error=errStr;

        //this.msgs_together = msgs_together;
        alert(errStr);
        return false;
    }
    else {
        return true;
    }
}
/*end*/
function add_validation(itemname, descriptor, errstr) {
    var condition = null;
    if (arguments.length > 3) {
        condition = arguments[3];
    }
    if (!this.formobj) {
        alert("Error: The form object is not set properly");
        return;
    } //if
    var itemobj = this.formobj[itemname];
    if (itemobj.length && isNaN(itemobj.selectedIndex))
    //for radio button; don't do for 'select' item
    {
        itemobj = itemobj[0];
    }
    if (!itemobj) {
        alert("Error: Couldnot get the input object named: " + itemname);
        return;
    }
    if (!itemobj.validationset) {
        itemobj.validationset = new ValidationSet(itemobj, this.show_errors_together);
    }
    itemobj.validationset.add(descriptor, errstr, condition);
    itemobj.validatorobj = this;
}
function validator_enable_OPED() {
    document.error_disp_handler.EnableOnPageDisplay(false);
}

function validator_enable_OPED_SB() {
    document.error_disp_handler.EnableOnPageDisplay(true);
}
function sfm_ErrorDisplayHandler() {
    this.msgdisplay = new AlertMsgDisplayer();
    this.EnableOnPageDisplay = edh_EnableOnPageDisplay;
    this.ShowMsg = edh_ShowMsg;
    this.FinalShowMsg = edh_FinalShowMsg;
    this.all_msgs = new Array();
    this.clear_msgs = edh_clear_msgs;
}
function edh_clear_msgs() {
    this.msgdisplay.clearmsg(this.all_msgs);
    this.all_msgs = new Array();
}
function edh_FinalShowMsg() {
    this.msgdisplay.showmsg(this.all_msgs);
}
function edh_EnableOnPageDisplay(single_box) {
    if (true == single_box) {
        this.msgdisplay = new SingleBoxErrorDisplay();
    }
    else {
        this.msgdisplay = new DivMsgDisplayer();
    }
}
function edh_ShowMsg(msg, input_element) {

    var objmsg = new Array();
    objmsg["input_element"] = input_element;
    objmsg["msg"] = msg;
    this.all_msgs.push(objmsg);
}
function AlertMsgDisplayer() {
    this.showmsg = alert_showmsg;
    this.clearmsg = alert_clearmsg;
}
function alert_clearmsg(msgs) {

}
function alert_showmsg(msgs) {
    var whole_msg = "";
    var first_elmnt = null;
    for (var m = 0; m < msgs.length; m++) {
        if (null == first_elmnt) {
            first_elmnt = msgs[m]["input_element"];
        }
        whole_msg += msgs[m]["msg"] + "\n";
    }

    alert(whole_msg);

    if (null != first_elmnt) {
        sfm_set_focus(first_elmnt);
    }
}
function sfm_show_error_msg(msg, input_elmt) {

    document.error_disp_handler.ShowMsg(msg, input_elmt);
}
function SingleBoxErrorDisplay() {
    this.showmsg = sb_div_showmsg;
    this.clearmsg = sb_div_clearmsg;
}

function sb_div_clearmsg(msgs) {
    var divname = form_error_div_name(msgs);
    show_div_msg(divname, "");
}

function sb_div_showmsg(msgs) {
    var whole_msg = "<ul>\n";
    for (var m = 0; m < msgs.length; m++) {
        whole_msg += "<li>" + msgs[m]["msg"] + "</li>\n";
    }
    whole_msg += "</ul>";
    var divname = form_error_div_name(msgs);
    show_div_msg(divname, whole_msg);
}
function form_error_div_name(msgs) {
    var input_element = null;

    for (var m in msgs) {
        input_element = msgs[m]["input_element"];
        if (input_element) { break; }
    }

    var divname = "";
    if (input_element) {
        divname = input_element.form._sfm_form_name + "_errorloc";
    }

    return divname;
}
function DivMsgDisplayer() {
    this.showmsg = div_showmsg;
    this.clearmsg = div_clearmsg;
}
function div_clearmsg(msgs) {
    for (var m in msgs) {
        var divname = element_div_name(msgs[m]["input_element"]);
        show_div_msg(divname, "");
    }
}
function element_div_name(inputElement) {
    var divname = inputElement.form._sfm_form_name + "_" +
                   inputElement.name + "_errorloc";

    divname = divname.replace(/[\[\]]/gi, "");

    return divname;
}
function div_showmsg(msgs) {
    var whole_msg;
    var first_elmnt = null;
    for (var m in msgs) {
        if (null == first_elmnt) {
            first_elmnt = msgs[m]["input_element"];
        }
        var divname = element_div_name(msgs[m]["input_element"]);
        show_div_msg(divname, msgs[m]["msg"]);
    }
    if (null != first_elmnt) {
        sfm_set_focus(first_elmnt);
    }
}
function show_div_msg(divname, msgstring) {
    if (divname.length <= 0) return false;

    if (document.layers) {
        divlayer = document.layers[divname];
        if (!divlayer) { return; }
        divlayer.document.open();
        divlayer.document.write(msgstring);
        divlayer.document.close();
    }
    else
        if (document.all) {
        divlayer = document.all[divname];
        if (!divlayer) { return; }
        divlayer.innerHTML = msgstring;
    }
    else
        if (document.getElementById) {
        divlayer = document.getElementById(divname);
        if (!divlayer) { return; }
        divlayer.innerHTML = msgstring;
    }
    divlayer.style.visibility = "visible";
}

function ValidationDesc(inputitem, desc, error, condition) {
    this.desc = desc;
    this.error = error;
    this.itemobj = inputitem;
    this.condition = condition;
    this.validate = vdesc_validate;
}
function vdesc_validate() {
    if (this.condition != null) {
        if (!eval(this.condition)) {
            return true;
        }
    }
    if (!validateInput(this.desc, this.itemobj, this.error)) {
        this.itemobj.validatorobj.disable_validations = true;

        sfm_set_focus(this.itemobj);

        return false;
    }
    return true;
}
function ValidationSet(inputitem, msgsTogether) {
    this.vSet = new Array();
    this.add = add_validationdesc;
    this.validate = vset_validate;
    this.itemobj = inputitem;
    this.msgs_together = msgsTogether;
}
function add_validationdesc(desc, error, condition) {
    this.vSet[this.vSet.length] =
  new ValidationDesc(this.itemobj, desc, error, condition);
}
function vset_validate() {
    var bRet = true;
    for (var itr = 0; itr < this.vSet.length; itr++) {
        bRet = bRet && this.vSet[itr].validate();
        if (!bRet && !this.msgs_together) {
            break;
        }
    }
    return bRet;
}
function validateEmail1(email) {
    var splitted = email.match("^(.+)@(.+)$");
    if (splitted == null) return false;
    if (splitted[1] != null) {
        var regexpUser = /^\"?[\w-_\.]*\"?$/;
        if (splitted[1].match(regexpUser) == null) return false;
    }
    if (splitted[2] != null) {
        var regexpDomain = /^[\w-\.]*\.[A-Za-z]{2,4}$/;
        if (splitted[2].match(regexpDomain) == null) {
            var regexpIp = /^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
            if (splitted[2].match(regexpIp) == null) return false;
        } // if
        return true;
    }
    return false;
}

function IsCheckSelected(objValue, chkValue) {
    var selected = false;
    var objcheck = objValue.form.elements[objValue.name];
    if (objcheck.length) {
        var idxchk = -1;
        for (var c = 0; c < objcheck.length; c++) {
            if (objcheck[c].value == chkValue) {
                idxchk = c;
                break;
            } //if
        } //for
        if (idxchk >= 0) {
            if (objcheck[idxchk].checked == "1") {
                selected = true;
            }
        } //if
    }
    else {
        if (objValue.checked == "1") {
            selected = true;
        } //if
    } //else	

    return selected;
}
function TestDontSelectChk(objValue, chkValue, strError) {
    var pass; //= true;
    pass = IsCheckSelected(objValue, chkValue) ? false : true;

    if (pass == false) {
        if (!strError || strError.length == 0) {
            strError = "Can't Proceed as you selected " + objValue.name;
        } //if			  
        sfm_show_error_msg(strError, objValue);

    }
    return pass;
}
function TestShouldSelectChk(objValue, chkValue, strError) {
    var pass; //= true;

    pass = IsCheckSelected(objValue, chkValue) ? true : false;

    if (pass == false) {
        if (!strError || strError.length == 0) {
            strError = "You should select " + objValue.name;
        } //if			  
        sfm_show_error_msg(strError, objValue);

    }
    return pass;
}
function TestRequiredInput(objValue, strError) {
    var ret = true;
    var val = objValue.value;
    val = val.replace(/^\s+|\s+$/g, ""); //trim
    if (eval(val.length) == 0) {
        if (!strError || strError.length == 0) {
            strError = objValue.name + " : Required Field";
        } //if 
        sfm_show_error_msg(strError, objValue);
        ret = false;
    } //if 
    return ret;
}
function TestMaxLen(objValue, strMaxLen, strError) {
    var ret = true;
    if (eval(objValue.value.length) > eval(strMaxLen)) {
        if (!strError || strError.length == 0) {
            strError = objValue.name + " : " + strMaxLen + " characters maximum ";
        } //if 
        sfm_show_error_msg(strError, objValue);
        ret = false;
    } //if 
    return ret;
}
function TestMinLen(objValue, strMinLen, strError) {
    var ret = true;
    if (eval(objValue.value.length) < eval(strMinLen)) {
        if (!strError || strError.length == 0) {
            strError = objValue.name + " : " + strMinLen + " characters minimum  ";
        } //if               
        sfm_show_error_msg(strError, objValue);
        ret = false;
    } //if 
    return ret;
}
function TestInputType(objValue, strRegExp, strError, strDefaultError) {
    var ret = true;

    var charpos = objValue.value.search(strRegExp);
    if (objValue.value.length > 0 && charpos >= 0) {
        if (!strError || strError.length == 0) {
            strError = strDefaultError;
        } //if 
        sfm_show_error_msg(strError, objValue);
        ret = false;
    } //if 
    return ret;
}
function TestEmail(objValue, strError) {
    var ret = true;
    if (objValue.value.length > 0 && !validateEmail1(objValue.value)) {
        if (!strError || strError.length == 0) {
            strError = objValue.name + ": Enter a valid Email address ";
        } //if                                               
        sfm_show_error_msg(strError, objValue);
        ret = false;
    } //if 
    return ret;
}
function TestLessThan(objValue, strLessThan, strError) {
    var ret = true;
    if (isNaN(objValue.value)) {
        sfm_show_error_msg(objValue.name + ": Should be a number ", objValue);
        ret = false;
    } //if 
    else
        if (eval(objValue.value) >= eval(strLessThan)) {
        if (!strError || strError.length == 0) {
            strError = objValue.name + " : value should be less than " + strLessThan;
        } //if               
        sfm_show_error_msg(strError, objValue);
        ret = false;
    } //if   
    return ret;
}
function TestGreaterThan(objValue, strGreaterThan, strError) {
    var ret = true;
    if (isNaN(objValue.value)) {
        sfm_show_error_msg(objValue.name + ": Should be a number ", objValue);
        ret = false;
    } //if 
    else
        if (eval(objValue.value) <= eval(strGreaterThan)) {
        if (!strError || strError.length == 0) {
            strError = objValue.name + " : value should be greater than " + strGreaterThan;
        } //if               
        sfm_show_error_msg(strError, objValue);
        ret = false;
    } //if  
    return ret;
}
function TestRegExp(objValue, strRegExp, strError) {
    var ret = true;
    if (objValue.value.length > 0 &&
        !objValue.value.match(strRegExp)) {
        if (!strError || strError.length == 0) {
            strError = objValue.name + ": Invalid characters found ";
        } //if                                                               
        sfm_show_error_msg(strError, objValue);
        ret = false;
    } //if 
    return ret;
}
function TestDontSelect(objValue, dont_sel_index, strError) {
    var ret = true;
    if (objValue.selectedIndex == null) {
        sfm_show_error_msg("ERROR: dontselect command for non-select Item");
        ret = false;
    }
    if (objValue.selectedIndex == eval(dont_sel_index)) {
        if (!strError || strError.length == 0) {
            strError = objValue.name + ": Please Select one option ";
        } //if                                                               
        sfm_show_error_msg(strError, objValue);
        ret = false;
    }
    return ret;
}
function TestSelectOneRadio(objValue, strError) {
    var objradio = objValue.form.elements[objValue.name];
    var oneSelected = false;
    for (var r = 0; r < objradio.length; r++) {
        if (objradio[r].checked) {
            oneSelected = true;
            break;
        }
    }
    if (false == oneSelected) {
        if (!strError || strError.length == 0) {
            strError = "Please select one option from " + objValue.name;
        }
        sfm_show_error_msg(strError, objValue);
    }
    return oneSelected;
}

function validateInput(strValidateStr, objValue, strError) {
    var ret = true;
    var epos = strValidateStr.search("=");
    var command; //= "";
    var cmdvalue = "";
    if (epos >= 0) {
        command = strValidateStr.substring(0, epos);
        cmdvalue = strValidateStr.substr(epos + 1);
    }
    else {
        command = strValidateStr;
    }
    switch (command) {
        case "req":
        case "required":
            {

                ret = TestRequiredInput(objValue, strError);
                break;
            } //case required 
        case "maxlength":
        case "maxlen":
            {
                ret = TestMaxLen(objValue, cmdvalue, strError);
                break;
            } //case maxlen 
        case "minlength":
        case "minlen":
            {
                ret = TestMinLen(objValue, cmdvalue, strError);
                break;
            } //case minlen 
        case "alnum":
        case "alphanumeric":
            {
                ret = TestInputType(objValue, "[^A-Za-z0-9]", strError,
						objValue.name + ": Only alpha-numeric characters allowed ");
                break;
            }
        case "alnum_s":
        case "alphanumeric_space":
            {
                ret = TestInputType(objValue, "[^A-Za-z0-9\\s]", strError,
						objValue.name + ": Only alpha-numeric characters and space allowed ");
                break;
            }
        case "num":
        case "numeric":
            {
                ret = TestInputType(objValue, "[^0-9]", strError,
						objValue.name + ": Only digits allowed ");
                break;
            }
        case "dec":
        case "decimal":
            {
                ret = TestInputType(objValue, "[^0-9\.]", strError,
						objValue.name + ": Only numbers allowed ");
                break;
            }
        case "alphabetic":
        case "alpha":
            {
                ret = TestInputType(objValue, "[^A-Za-z]", strError,
						objValue.name + ": Only alphabetic characters allowed ");
                break;
            }
        case "alphabetic_space":
        case "alpha_s":
            {
                ret = TestInputType(objValue, "[^A-Za-z\\s]", strError,
						objValue.name + ": Only alphabetic characters and space allowed ");
                break;
            }
        case "email":
            {
                ret = TestEmail(objValue, strError);
                break;
            }
        case "lt":
        case "lessthan":
            {
                ret = TestLessThan(objValue, cmdvalue, strError);
                break;
            }
        case "gt":
        case "greaterthan":
            {
                ret = TestGreaterThan(objValue, cmdvalue, strError);
                break;
            } //case greaterthan 
        case "regexp":
            {
                ret = TestRegExp(objValue, cmdvalue, strError);
                break;
            }
        case "dontselect":
            {
                ret = TestDontSelect(objValue, cmdvalue, strError);
                break;
            }
        case "dontselectchk":
            {
                ret = TestDontSelectChk(objValue, cmdvalue, strError);
                break;
            }
        case "shouldselchk":
            {
                ret = TestShouldSelectChk(objValue, cmdvalue, strError);
                break;
            }
        case "selone_radio":
            {
                ret = TestSelectOneRadio(objValue, strError);
                break;
            }
        case "select":
            {
                ret = TestShouldSelect(objValue, strError);
                break;
            }
    } //switch 
    return ret;
}




function TestShouldSelect(objValue, strError) {
    if (objValue.value == "0") {

        sfm_show_error_msg(strError, objValue);

        return false;
    }
    else
        return true;
}
function VWZ_IsListItemSelected(listname, value) {
    for (var i = 0; i < listname.options.length; i++) {
        if (listname.options[i].selected == true &&
   listname.options[i].value == value) {
            return true;
        }
    }
    return false;
}
function VWZ_IsChecked(objcheck, value) {
    if (objcheck.length) {
        for (var c = 0; c < objcheck.length; c++) {
            if (objcheck[c].checked == "1" &&
	     objcheck[c].value == value) {
                return true;
            }
        }
    }
    else {
        if (objcheck.checked == "1") {
            return true;
        }
    }
    return false;
}

/*allow numeric on key press*/
function ValidateNumber(input, kbEvent) {
    var keyCode, keyChar;
    //keyCode = kbEvent.keyCode;
    if (window.event)
        keyCode = kbEvent.keyCode; 	// IE
    else
        keyCode = kbEvent.which; 	//firefox

    if (keyCode == null) return true;
    // get character
    keyChar = String.fromCharCode(keyCode);
    var charSet = "0123456789";
    // check valid chars
    if (charSet.indexOf(keyChar) != -1) return true;
    // control keys
    if (keyCode == null || keyCode == 0 || keyCode == 8 || keyCode == 9 || keyCode == 13 || keyCode == 27) return true;
    return false;
}

//Image Upload Format

function CheckImageFormat(imagePath, id) {

    var pathLength = imagePath.length;
    var lastDot = imagePath.lastIndexOf(".");
    var fileType = imagePath.substring(lastDot, pathLength);

    if ((fileType == ".gif") || (fileType == ".jpg") || (fileType == ".jpeg") || (fileType == ".GIF") || (fileType == ".JPG") || (fileType == ".JPEG")) {
        return true;
    }
    else {
        document.getElementById(id).value = "";
        alert("Please Select .JPG, .JPEG and .GIF image formats.");
        return false;
    }
}





/*Checking date of birth*/
function dateOfBirth(DateElementId, CompareDateElementId, DateField, CompareDateField) {
    //        var comdate=document.getElementById(date).value;
    //        alert(comdate);
    //        var mon1=parseInt(comdate.substring(0,2),10);
    //        var dt1=parseInt(comdate.substring(3,5),10);
    //        var yr1=parseInt(comdate.substring(6,10),10);
    //        alert(mon1);
    //        alert(dt1);
    //        alert(yr1);
    //        var curdate = new Date();
    //        var date1=new Date(mon1,dt1,yr1);
    //        var date2=new Date(curdate.getYear()+1900, curdate.getMonth(), curdate.getDay());
    //        alert(date1);
    //        alert(date2);

    var SDate = document.getElementById(DateElementId).value;
    var EDate = document.getElementById(CompareDateElementId).value;


    var endDate = new Date(EDate);
    var startDate = new Date(SDate);

    //        if(SDate == '')	
    //        {
    //            alert("Please enter " + DateField);
    //            return false;
    //        }
    //        else if(EDate == '')	
    //        {
    //            alert("Please enter " + CompareDateField);
    //            return false;
    //        }
    if (startDate >= endDate) {
        return false;
    }
    else {
        return true;
    }
    //return false;

    //        var mainDate = new Date(comdate);
    //alert(now);
    //alert(maindate);
    //        if (now > mainDate) 
    //        {
    //            alert(err)
    //            return false;
    //        }
    //        else 
    //        {
    //            return true;
    //        }
}




///date validation 22/10/2009

// Declaring valid date character, minimum year and maximum year
var dtCh = "/";
var minYear = 1900;
var maxYear = 2100;

function isInteger(s) {
    var i;
    for (i = 0; i < s.length; i++) {
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag) {
    var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary(year) {
    // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28);
}
function DaysArray(n) {
    for (var i = 1; i <= n; i++) {
        this[i] = 31;
        if (i == 4 || i == 6 || i == 9 || i == 11) { this[i] = 30; }
        if (i == 2) { this[i] = 29; }
    }
    return this;
}

function isDateValied(dtStr, control) {

    var daysInMonth = DaysArray(12);
    var pos1 = dtStr.indexOf(dtCh);
    var pos2 = dtStr.indexOf(dtCh, pos1 + 1);
    var strMonth = dtStr.substring(0, pos1);
    var strDay = dtStr.substring(pos1 + 1, pos2);
    var strYear = dtStr.substring(pos2 + 1);
    strYr = strYear;
    if (strDay.charAt(0) == "0" && strDay.length > 1) strDay = strDay.substring(1);
    if (strMonth.charAt(0) == "0" && strMonth.length > 1) strMonth = strMonth.substring(1);
    for (var i = 1; i <= 3; i++) {
        if (strYr.charAt(0) == "0" && strYr.length > 1) strYr = strYr.substring(1);
    }
    month = parseInt(strMonth);
    day = parseInt(strDay);
    year = parseInt(strYr);
    if (pos1 == -1 || pos2 == -1) {
        alert("Please enter date in format : mm/dd/yyyy");
        document.getElementById(control).value = "";
        return false;
    }
    if (strMonth.length < 1 || month < 1 || month > 12) {
        alert("Please enter a valid month");
        document.getElementById(control).value = "";
        return false;
    }
    if (strDay.length < 1 || day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > daysInMonth[month]) {
        alert("Please enter a valid day");
        document.getElementById(control).value = "";
        return false;
    }
    if (strYear.length != 4 || year == 0 || year < minYear || year > maxYear) {
        alert("Please enter a valid 4 digit year between " + minYear + " and " + maxYear);
        document.getElementById(control).value = "";
        return false;
    }
    if (dtStr.indexOf(dtCh, pos2 + 1) != -1 || isInteger(stripCharsInBag(dtStr, dtCh)) == false) {
        alert("Please enter a valid date");
        document.getElementById(control).value = "";
        return false;
    }
    return true;
}

//function ValidateForm(){
//	var dt=document.frmSample.txtDate
//	if (isDate(dt.value)==false){
//		dt.focus()
//		return false;
//	}
//    return true;
// }



//Validating Start Date greater End Date and current date 
function ValidateDateRangeMaxMin(CtrlSDate, CtrlEDate) {
    var SDate = document.getElementById(CtrlSDate).value;
    var EDate = document.getElementById(CtrlEDate).value;
    var alertReason1 = 'start Date must be greater than or equal to  end Date.';

    if (isDateValied(SDate, CtrlSDate) && isDateValied(EDate, CtrlEDate)) {
        var now = new Date();
        if (Date.parse(SDate) < Date.parse(now)) {
            alert("start date should be  greater than Current date");
            return false;
        }
        else if (Date.parse(EDate) < Date.parse(now)) {
            alert("end date should be  greater than Current date");
            return false;
        }
        else if (Date.parse(SDate) < Date.parse(EDate)) {
            alert(alertReason1);
            document.getElementById(CtrlEDate).value = "";
            return false;
        }

        return true;
    }
    else
        return false;
}



//Validating End Date greater Start Date and current date 

function ValidateDateRangeMinMax(CtrlSDate, CtrlEDate) {
    var SDate = document.getElementById(CtrlSDate).value;
    var EDate = document.getElementById(CtrlEDate).value;
    var alertReason1 = 'End Date must greater than or equal to Start Date.';

    if (isDateValied(SDate, CtrlSDate) && isDateValied(EDate, CtrlEDate)) {
        var now = new Date();
        if (Date.parse(SDate) < Date.parse(now)) {
            alert("start date should be  greater than Current date");
            return false;
        }
        else if (Date.parse(EDate) < Date.parse(now)) {
            alert("end date should be  greater than Current date");
            return false;
        }
        else if (Date.parse(SDate) > Date.parse(EDate)) {
            alert(alertReason1);
            document.getElementById(CtrlEDate).value = "";
            return false;
        }
        return true;
    }
    else
        return false;
}
// validates End Date Greater than start date and both less than today
function ValidateDateMinMax(CtrlSDate, CtrlEDate) {
    var SDate = document.getElementById(CtrlSDate).value;
    var EDate = document.getElementById(CtrlEDate).value;
    var alertReason1 = 'End Date must greater than or equal to Start Date.';

    if (isDateValied(SDate, CtrlSDate) && isDateValied(EDate, CtrlEDate)) {
        var now = new Date();
        if (Date.parse(SDate) > Date.parse(EDate)) {
            alert(alertReason1);
            document.getElementById(CtrlEDate).value = "";
            return false;
        }
        return true;
    }
    else
        return false;
}

// validates End Date Greater than start date and both less than today
function ValidateDateMaxMin(CtrlSDate, CtrlEDate) {
    var SDate = document.getElementById(CtrlSDate).value;
    var EDate = document.getElementById(CtrlEDate).value;
    var alertReason1 = 'Start Date must greater than or equal to End Date.';

    if (isDateValied(SDate, CtrlSDate) && isDateValied(EDate, CtrlEDate)) {
        var now = new Date();
        if (Date.parse(SDate) < Date.parse(EDate)) {
            alert(alertReason1);
            document.getElementById(CtrlEDate).value = "";
            return false;
        }
        return true;
    }
    else
        return false;
}

//function to validate dateofbirth
function ValidateDOB(CtrlSDate) {
    var DOB = document.getElementById(CtrlSDate).value;
    if (isDateValied(DOB, CtrlSDate)) {
        var now = new Date();
        var DOB = Date.parse(DOB);
        now = now.setFullYear(now.getFullYear() - 14);
        if (DOB > now) {
            alert("Minimum allowed age is 14 years");
            document.getElementById(CtrlSDate).value = "";
            return false;
        }

        return true;
    }
    else
        return false;
}

//function to calculate date greater than current date 
function ValidateGreaterDate(CtrlSDate) {
    var Date = document.getElementById(CtrlSDate).value;
    if (isDateValied(DOB, CtrlSDate)) {
        var now = new Date();
        if (Date.parse(Date) < Date.parse(now)) {
            alert("Please Enter Date Greater than current date");
            document.getElementById(CtrlSDate).value = "";
            return false;
        }
        return true;
    }
    else
        return false;
}


//function to calculate date less than current date 
function ValidateLessthanDate(ctrlSDate) {
    var Date = document.getElementById(ctrlSDate).value;
    if (isDateValied(DOB, ctrlSDate)) {
        var now = new Date();
        if (Date.parse(Date) < Date.parse(now)) {
            alert("Please Enter Date Less than current date");
            document.getElementById(ctrlSDate).value = "";
            return false;
        }
        return true;
    }
    else
        return false;
}

// function resctrict the max length in multi line text box
function checkTextAreaMaxLength(textBox, e, length) {

    var mLen = textBox["MaxLength"];
    if (null == mLen)
        mLen = length;

    var maxLength = parseInt(mLen);
    if (!checkSpecialKeys(e)) {
        if (textBox.value.length > maxLength - 1) {
            if (window.event)//IE
                e.returnValue = false;
            else//Firefox
                e.preventDefault();
        }
    }
}
function checkSpecialKeys(e) {
    if (e.keyCode != 8 && e.keyCode != 46 && e.keyCode != 37 && e.keyCode != 38 && e.keyCode != 39 && e.keyCode != 40)
        return false;
    else
        return true;
}

function validateURL(val) {
    var theurl = val;
    //var tomatch = /^(https?:\/\/)?(([0-9a-z_!~*\'()\.&=+$%\-]+: )?[0-9a-z_!~*\'()\.&=+$%\-]+@)?(([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-z_!~*\'()-]+\.)*([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\.[a-z]{2,6})(:[0-9]{1,4})?((/?)|(/[0-9a-z_!~*\'()\.;?:@&=+$,%#\-]+)+/?)$ /;

    var tomatch = /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/;

    if (tomatch.test(theurl)) {
        return true;
    }
    else {
        alert("Please Enter Valid URL");
        return false;
    }
}

// function for trim 
function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

//---------------------------------end common validation--------------------------------------------------------//




//----------------------------------------* Start CommonValidation.js *-----------------------------------------//


function tableopen(val, val1, val2) {
    if (val == 'open') {
        document.getElementById(val1).style.display = '';
        document.getElementById(val2).setAttribute('href', "javascript:tableopen('close','" + val1 + "','" + val2 + "')");
        document.getElementById(val2).innerHTML = '<img src="images/PlusMinus.gif">';
    }
    else if (val == 'close') {
        document.getElementById(val1).style.display = 'none';
        document.getElementById(val2).setAttribute('href', "javascript:tableopen('open','" + val1 + "','" + val2 + "')");
        document.getElementById(val2).innerHTML = '<img src="images/MinusPlus.gif">';
    }
}
function tableopenjobprofile(val, val1, val2) {
    if (val == 'open') {
        document.getElementById(val1).style.display = '';
        document.getElementById(val2).setAttribute('href', "javascript:tableopenjobprofile('close','" + val1 + "','" + val2 + "')");
        document.getElementById(val2).innerHTML = '<img src="images/down.gif">';
    }
    else if (val == 'close') {
        document.getElementById(val1).style.display = 'none';
        document.getElementById(val2).setAttribute('href', "javascript:tableopenjobprofile('open','" + val1 + "','" + val2 + "')");
        document.getElementById(val2).innerHTML = '<img src="images/up.gif">';
    }
}


function rolloverButton(id, state) {
    if (document.getElementById) {
        var elementId = document.getElementById(id);
        if (state == 'over') {
            elementId.className = 'button100x25over';
        }
        else {
            elementId.className = 'button100x25';
        }
    }
}
// check date JavaScript function  
// if date is valid then function returns true, otherwise returns false  
function isDate(dd, mm, yy) {
    var objDate;  // date object initialized from the txtDate string  
    var mSeconds; // milliseconds from txtDate  

    // extract day, month and year from the txtDate string  
    // expected format is mm/dd/yyyy  
    // subtraction will cast variables to integer implicitly  
    var day = dd;
    var month = mm - 1; // because months in JS start with 0  
    var year = yy;

    // test year range  
    if (year < 999 || year > 3000) return false;

    // convert txtDate to the milliseconds  
    mSeconds = (new Date(year, month, day)).getTime();

    // set the date object from milliseconds  
    objDate = new Date();
    objDate.setTime(mSeconds);

    // if there exists difference then date isn't valid  
    if (objDate.getFullYear() != year) return false;
    if (objDate.getMonth() != month) return false;
    if (objDate.getDate() != day) return false;

    // otherwise return true  
    return true;
}

//function catchCityProviderSelItemGen(item, txtProvider, hdfProvider, ctl00_body_hdfDetails) {
//    if (item == 1) {

//        document.getElementById(txtProvider).value = "Babysitting Providers";
//        document.getElementById(hdfProvider).value = "1";
//        document.getElementById(ctl00_body_hdfDetails).value = "0";
//    }
//    if (item == 2) {
//        document.getElementById(txtProvider).value = "Special Needs Providers";
//        document.getElementById(hdfProvider).value = "2";

//        document.getElementById(ctl00_body_hdfDetails).value = "0";
//    }
//    if (item == 3) {
//        document.getElementById(txtProvider).value = "Tutoring Providers";
//        document.getElementById(hdfProvider).value = "3";

//        document.getElementById(ctl00_body_hdfDetails).value = "0";
//    }
//    if (item == 5) {
//        document.getElementById(txtProvider).value = "Pet Sitting Providers";
//        document.getElementById(hdfProvider).value = "4";
//        document.getElementById(ctl00_body_hdfDetails).value = "0";
//    }
//    if (item == 4) {
//        document.getElementById(txtProvider).value = "Elder Care Providers";
//        document.getElementById(hdfProvider).value = "5";
//        document.getElementById(ctl00_body_hdfDetails).value = "0";
//    }
//    if (item == 6) {
//        document.getElementById(txtProvider).value = "House Keeping Providers";
//        document.getElementById(hdfProvider).value = "6";
//        document.getElementById(ctl00_body_hdfDetails).value = "0";
//    }
//    if (item == 7) {
//        document.getElementById(txtProvider).value = "Personal Care Providers";
//        document.getElementById(hdfProvider).value = "7";
//        document.getElementById(ctl00_body_hdfDetails).value = "0";
//    }
//    if (item == 8) {
//        document.getElementById(txtProvider).value = "Babysitter";
//        document.getElementById(hdfProvider).value = "1";
//        document.getElementById(ctl00_body_hdfDetails).value = "Babysitter";
//    }
//    if (item == 9) {
//        document.getElementById(txtProvider).value = "Nanny";
//        document.getElementById(hdfProvider).value = "1";
//        document.getElementById(ctl00_body_hdfDetails).value = "Nanny";
//    }

//    document.getElementById("divProviderList").style.display = "none";
//    numProvider = 0;
//}

$(document).ready(function() {
    $('.rsearchbox').hover(function() { $(this).addClass('gridViewHower'); $(this).attr('style', 'border-color:#E98B42'); }, function() { $(this).removeClass('gridViewHower'); $(this).removeAttr('style'); });
    $('.multilinebox').keyup(function() { UPdateLength($(this)); });
    $('.multilinebox').each(function() { UPdateLength($(this)); });
//    $('div').keypress(function(e) {
//        if (e.keyCode == '13') {

//            $(this).find('.default').click();
//            e.preventDefault();
//        }
//    });

});
function  UPdateLength(txt) {
    var limit = $('#' + txt.attr('id').replace('txt', 'hdf')).val();
    var len = txt.val().length;
    $('#' + txt.attr('id').replace('txt', 'spn')).text(limit - len + " characters left.");
}
