﻿/* Page Load javascript Functions */
var _baseUrl = "Service/TSIService.svc/";

/* Country Region JScripts */
//$(document).ready(function () {
//    $("#contents img[title]").tooltip();
//}); 


//    $.ajax({
//        url: _baseUrl + "LoadCountries",
//        type: "POST",
//        contentType: "application/json; charset=utf-8",
//        data: {},
//        processdata: true,
//        dataType: "json",
//        async: true,
//        success: function (msg) {
//            if (msg != null) {
//                var output = [];
//                $.each(msg["d"], function (key, value) {
//                    output.push('<option value="' + msg["d"][key]["CountryCode"] + '">' + msg["d"][key]["CountryName"] + '</option>');
//                });
//                $('#CountryDropDown').html(output.join(''));

//                //Get the Default Country and assign it.
//                $.ajax({
//                    url: _baseUrl + "GetCurrentCountry",
//                    type: "POST",
//                    contentType: "application/json; charset=utf-8",
//                    data: "{}",
//                    processdata: true,
//                    dataType: "json",
//                    async: true,
//                    success: function (rcvdmsg) { $('#CountryDropDown').val(rcvdmsg["d"]); GetProvinces("provincectl", rcvdmsg["d"]); }
//                });
//            }
//        }
//    });



/* End Country Region JScripts */

/* End Page Load javascript Functions */

/* Province Region JScripts */


function GetProvinces(ctlToLoad, countryCode) {

    ClearTownDetails();

    $.ajax({
        url: _baseUrl + "GetProvincesByCode",
        type: "POST",
        contentType: "application/json; charset=utf-8",
        data: '{"countryCode":"' + countryCode + '"}',
        processdata: true,
        dataType: "json",
        async: true,
        success: function (msg) {

            if (msg != null) {
                var output = [];
                output.push('<option value="' + (-1) + '">' + document.getElementById('ProvicelistPreText').value + '</option>');
                $.each(msg["d"], function (key, value) {

                    output.push('<option value="' + msg["d"][key]["Province_Id"] + '">' + msg["d"][key]["ProvinceName"] + '</option>');

                });
                $('#' + ctlToLoad).html(output.join(''));
            }
        }
    });


}
/* End Province Region JScripts */

/* Town Region JScripts */

function GetTowns(ctlid, province_id) {

    $.ajax({
        url: _baseUrl + 'GetTowns',
        type: "POST",
        contentType: "application/json; charset=utf-8",
        data: '{"province_id":"' + province_id + '"}',
        processdata: true,
        dataType: "json",
        async: true,
        success: function (townmsg) {
            if (townmsg != null) {
                var output = [];
                output.push('<option value="' + (-1) + '">' + document.getElementById('TownlistPreText').value + '</option>');
                $.each(townmsg["d"], function (key, value) {

                    output.push('<option value="' + townmsg["d"][key]["Town_Id"] + '">' + townmsg["d"][key]["TownName"] + '</option>');

                });
                $('#' + ctlid).html(output.join(''));


            }
        }
    });


}
function CheckTownCtl() {
    //    $('input[name="whereOptns"][value="Town"').attr('checked', true); 
    document.getElementById("TownRadioBtn").checked = true;
}
function CheckProvinceCtl() {
    //    $('input[ id="ProvinceRadioBtn"][value="Province"').attr('checked', true);
    document.getElementById("ProvinceRadioBtn").checked = true;
}
/* End Town Region JScripts */

/* Other Common Functions */
function ClearTownDetails() {
    var output = [];
    output.push('<option value="' + (-1) + '">' + document.getElementById('TownlistPreText').value + '</option>');
    $('#townctl').html(output.join(''));

}

//function Search() {

//}
/* End Common Functions */


function ShowMailInfo(id) {
    document.getElementById(id).style.visibility = "visible";
    //document.getElementById("ctl00_MainContent_TextLine1Ctl")
    document.getElementById(id).style.display = "block";
    return false;
}

function ResetProvinceTowns() {
    $('#townctl').get(0).selectedIndex = 0;
    $('#provincectl').get(0).selectedIndex = 0;
}

function SearchDesignChangedTotop() {



    if (Page_ClientValidate('SubmitValidationGroup')) {
    if (document.getElementById("WhatWhoCtl").value != "" || document.getElementById("TelNoCtl").value != "" || document.getElementById("VatNoCtl").value != "") {
        document.getElementById("AlertDiv").style.visiblity = "hidden";
        document.getElementById("AlertDiv").style.display = "none";
        document.getElementById("SearchAlert").innerHTML = "";
        document.getElementById("SearchMainDiv").style.width = "100%";
        document.getElementById("CtlDiv1").style.width = "48%";
        document.getElementById("CtlDiv2").style.width = "48%";
        document.getElementById("CtlDiv1").style.marginLeft = "0px";
        document.getElementById("FirstDiv").style.width = "13%";
        document.getElementById("FirstDiv").style.paddingTop = "30px";
        document.getElementById("SearchDiv").style.width = "70%";
        document.getElementById("SearchDiv").style.paddingBottom = "0px";
        document.getElementById("SearchDiv").style.marginTop = "0px";
        document.getElementById("BtnDiv").style.width = "5%";
        document.getElementById("BtnDiv").style.paddingTop = "120px";
        document.getElementById("BtnDiv").style.paddingLeft = "0px";
        document.getElementById("BtnDiv").style.TextAlign = "left";
        document.getElementById("MainContentDiv").style.marginTop = "0px";
        document.getElementById("MainContentDiv").style.paddingTop = "0px";
        document.getElementById("hrDiv").style.visibility = "visible";
        document.getElementById("hrDiv").style.display = "block";

        Search(1);
        
    }
    else {
        document.getElementById("SearchAlert").innerHTML = document.getElementById("EnterAnyoneText").value;
        document.getElementById("AlertDiv").style.visiblity = "visible";
        document.getElementById("AlertDiv").style.display = "block";
        //return false;
    }

      }
}

function showModalPopupViaClient() {
    //var modalPopupBehavior = $find('programmaticModalPopupBehavior');
    //modalPopupBehavior.show();
    $get('HiddenButton').click();
}
function close() {
    window.close();
}

function Clear(ctl) {

   if (ctl.id == "WhatWhoCtl") {
        $("#TelNoCtl").val('');
        $("#VatNoCtl").val('');
        document.getElementById("TelNoCtlValidator").style.visibility = "hidden";
       document.getElementById("VatNoCtlValidator").style.visibility = "hidden";
    }
    else if (ctl.id == "TelNoCtl") {
        $("#WhatWhoCtl").val('');
        $("#VatNoCtl").val('');
        document.getElementById("VatNoCtlValidator").style.visibility = "hidden";
        document.getElementById("TelNoCtlValidator").style.visibility = "visible";

    }
    else if (ctl.id == "VatNoCtl") {
        $("#WhatWhoCtl").val('');
        $("#TelNoCtl").val('');
        document.getElementById("VatNoCtlValidator").style.visibility = "Visible";
        document.getElementById("TelNoCtlValidator").style.visibility = "hidden";
    }
}

function num(e) {
    var k;
    document.all ? k = e.keyCode : k = e.which;
    return ((k > 47 && k < 58) || k == 46);
}

function Count(text, long) {

    var maxlength = new Number(long); // Change number to your max length.

    if (text.value.length > maxlength) {

        text.value = text.value.substring(0, maxlength);

    }
}
