﻿//Common variables
var lang, CountryCode, BaseUrl, outPutPath, defaultText;

//For International rates
var ddlCountry, txtLandline, txtMobile, txtSMS, sid, bVat, bSMS, vProduct;

// for RoamingRates
var ddlDestination, txtZone, txtLocal, txtIncoming, txtIncomSMS, txtOutSMS, txtZone1, txtZone2, txtZone3, txtZone4, txtZone5;

var iMobileNumberLength, txtMobileNumber, lblMsg, sERR_MobileNo, sERR_MobilePrefix, txtTelephone, sERR_ContactNo;


$(document).ready(function () {
    $('.lang-box').mouseover(function () {
        if ($('.langbar li').length > 10) {
            $('.lang-box').css('height', 'auto');
            $('.lang-box').css('border', 'solid 1px #015498');
            $('.lang-box').css('opacity', '0.9');
        }
    });
    $('.lang-box').mouseout(function () {
        if ($('.langbar li').length > 10) {
            $('.lang-box').css('height', '52px');
            $('.lang-box').css('border', 'solid 1px #fff');
        }
    });
});
function chLang(inPutPath) {
    outPutPath = inPutPath + lang.toString()
    window.location = outPutPath;
}

function LoadVariables(args) {

    lang = args[0];
    CountryCode = args[1];
    BaseUrl = args[2];
}

function CommonStartUp() {
    $("ul.dropdown li:nth-child(" + $('ul.dropdown li').length + ")").addClass("last");
    defaultText = $('.txt-bg-store').val();
}


function StoreFind_KeyPress(e, obj) {
    code = (e.keyCode ? e.keyCode : e.which);
    if (code == 13) {
        StoreFind_Click(obj.id);
        return false;
    }
}
function StoreFind_Focus(obj) {
    $('#' + obj.id).val('');
    $('#' + obj.id).css('color', '#000000');
}
function StoreFind_Blur(obj) {
    if (($('#' + obj.id).val() == defaultText) || ($('#' + obj.id).val() == '')) {
        $('#' + obj.id).val(defaultText);
    }
}

function StoreFind_Click(obj) {
    var str = $('#' + obj).val();
    if ((str.length != 0) && (str != defaultText)) {

        switch (CountryCode.toLowerCase()) {
            case "uk":
                Reg = "[a-zA-Z]{1,2}[0-9][0-9A-Za-z]? [0-9][a-zA-Z]{2}";
                break;
            case "nl":
                Reg = "[0-9]{4}";
                break;
            case "ch":
                reg = "[0-9]{4}";
                break;
        }
        var regexp = eval("/" + Reg + "/gi")
        var resultArray = str.match(regexp)
        var queryString;
        var Type;

        if (resultArray) {
            queryString = 'ps' + str + '-type-b/';
            var width = 800;
            var height = 480;
            var left = parseInt((screen.availWidth / 2) - (width / 2));
            var top = parseInt((screen.availHeight / 2) - (height / 2));
            var windowFeatures = "width=" + width + ",height=" + height + ",location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes,left=" + left + ",top=" + top + ",screenX=" + left + ",screenY=" + top;
            var urlwithQry = window.location.toString();
            var sLanguage = urlwithQry.substring(urlwithQry.lastIndexOf('/') + 1, urlwithQry.length);
            var keywords = BaseUrl + 'storelocation-postalcode-';

            if ((sLanguage.length == 0) || (sLanguage.toLowerCase() == "default.aspx")) {
                sLanguage = lang;
            }
            myWindow = window.open(keywords + queryString + sLanguage.toLowerCase(), "_blank", windowFeatures);

        }
        else {
            $('#' + obj).val($('.er-msg').html());
            $('#' + obj).css('color', 'red');
        }
    }
    else {
        $('#' + obj).val($('.txt-bg-store').attr('title'));
        $('#' + obj).css('color', 'red');
    }
}


function LoadRatesVariables(args) {

    ddlCountry = args[0];
    txtLandline = args[1];
    txtMobile = args[2];
    txtSMS = args[3];
    lang = args[4];
    sid = args[5];
}

function LoadStandardRatesVariables(args) {
    ddlCountry = args[0];
    txtLandline = args[1];
    txtMobile = args[2];
    txtSMS = args[3];
    lang = args[4];
    sid = args[5];
    bVat = args[6];
    bSMS = args[7];
    vProduct = args[8];

}


function LoadRateDeckVariables(args) {

    ddlCountry = args[0];
    txtLandline = args[1];
    txtMobile = args[2];
    txtSMS = args[3];
    lang = args[4];
    sid = args[5];
    bVat = args[6];
    bSMS = args[7];
    vProduct = args[8];
    vTariff = args[9];
}



function LoadRoamingRatesVariables(args) {
    ddlDestination = args[0];
    txtZone = args[1];
    txtLocal = args[2];
    txtIncoming = args[3];
    txtIncomSMS = args[4];
    txtOutSMS = args[5];
    txtZone1 = args[6];
    txtZone2 = args[7];
    txtZone3 = args[8];
    txtZone4 = args[9];
    txtZone5 = args[10];
}

function LoadContactUsVariables(args) {
    iMobileNumberLength = args[0];
    txtMobileNumber = args[1];
    lblMsg = args[2];
    sERR_MobileNo = args[3];
    sERR_MobilePrefix = args[4];
    txtTelephone = args[5];
    sERR_ContactNo = args[6];

}
function PremiumRates_KeyPress(e) {
    var code = (e.keyCode ? e.keyCode : e.which);
    var key = e.charCode || e.keyCode || 0;
    var keychar = String.fromCharCode(key);

    if (code == 13) {
        loadprice();
        return true;
    }

    if ((key >= 48 && key <= 57) || (key == 32)) { /* 0-9 */
        return true;
    } else {
        return false;
    }
}

function SearchPremiumRates() {
    loadprice();
}



function WhilePaste(e) {
    var key = e.charCode || e.keyCode || 0;
    var keychar = String.fromCharCode(key);
    if (((key == 8 || key == 9 || key == 46 || key == 35 || key == 36 || (key >= 37 && key <= 40)) && e.charCode == 0) /* backspace, end, begin, top, bottom, right, left, del, tab */
                                        || (key >= 48 && key <= 57)) { /* 0-9 */
        return;
    } else {
        e.preventDefault();
    }
}

function ShowInternatonalRates(rate_value) {
    var a = rate_value.split(";");
    var vLandline = a[1];
    var vmobile = a[2];
    var vsms = a[3];

    ddlIntRates = document.getElementById(ddlCountry);

    if (ddlIntRates.options[ddlIntRates.selectedIndex].value != 0) {
        document.getElementById(txtLandline).value = ((vLandline != '') || (vLandline != 'undefined')) ? vLandline : '-';
        document.getElementById(txtMobile).value = ((vmobile != '') || (vmobile != 'undefined')) ? vmobile : '-';
        if (document.getElementById(txtSMS) != null)
            document.getElementById(txtSMS).value = ((vsms != '') || (vsms != 'undefined')) ? vsms : '-';
    }
    else {
        document.getElementById(txtLandline).value = '-';
        document.getElementById(txtMobile).value = '-';
        if (document.getElementById(txtSMS) != null)
            document.getElementById(txtSMS).value = '-';
    }


}

function loadprice() {
    if ($('.prem-rates').val().length != 0) {
        $(".res").empty().html('<img src="images/ajax-loader.gif" />');
        $.get('rateshandler.ashx?lang=' + lang + '&qry=' + $('.prem-rates').val() + '&sid=' + sid + '&v=' + $('.mess').html(), function (result) {
            $('.err1').hide();
            $('.err2').hide();
            $('.res').html(result);
            $('.res').show();
        });
    }
    else {
        $('.err1').show();
        $('.err2').hide();
        $('.res').html('');
    }
}

function ShowRoamingRates(rate_value) {
    var a = rate_value.split(";");
    var vTxtZone = a[1];
    var vTxtLocal = a[2];
    var vTxtIncomeCall = a[3];
    var vTxtOutSms = a[4];
    var vTxtIncomeSms = a[5];

    var vTxtZone1 = a[6];
    var vTxtZone2 = a[7];
    var vTxtZone3 = a[8];
    var vTxtZone4 = a[9];
    var vTxtZone5 = a[10];

    ddlIntRates = document.getElementById(ddlDestination);

    if (ddlIntRates.options[ddlIntRates.selectedIndex].value != 0) {
        document.getElementById(txtZone).value = ((vTxtZone != '') || (vTxtZone != 'undefined')) ? vTxtZone : '-';
        document.getElementById(txtLocal).value = ((vTxtLocal != '') || (vTxtLocal != 'undefined')) ? vTxtLocal : '-';
        document.getElementById(txtIncoming).value = ((vTxtIncomeCall != '') || (vTxtIncomeCall != 'undefined')) ? vTxtIncomeCall : '-';
        document.getElementById(txtIncomSMS).value = ((vTxtIncomeSms != '') || (vTxtIncomeSms != 'undefined')) ? vTxtIncomeSms : '-';
        document.getElementById(txtOutSMS).value = ((vTxtOutSms != '') || (vTxtOutSms != 'undefined')) ? vTxtOutSms : '-';

        document.getElementById(txtZone1).value = ((vTxtZone1 != '') || (vTxtZone1 != 'undefined')) ? vTxtZone1 : '-';
        document.getElementById(txtZone2).value = ((vTxtZone2 != '') || (vTxtZone2 != 'undefined')) ? vTxtZone2 : '-';
        document.getElementById(txtZone3).value = ((vTxtZone3 != '') || (vTxtZone3 != 'undefined')) ? vTxtZone3 : '-';
        document.getElementById(txtZone4).value = ((vTxtZone4 != '') || (vTxtZone4 != 'undefined')) ? vTxtZone4 : '-';
        document.getElementById(txtZone5).value = ((vTxtZone5 != '') || (vTxtZone5 != 'undefined')) ? vTxtZone5 : '-';

    }
    else {
        document.getElementById(txtZone).value = '-';
        document.getElementById(txtLocal).value = '-';
        document.getElementById(txtIncoming).value = '-';
        document.getElementById(txtIncomSMS).value = '-';
        document.getElementById(txtOutSMS).value = '-';

        document.getElementById(txtZone1).value = '-';
        document.getElementById(txtZone2).value = '-';
        document.getElementById(txtZone3).value = '-';
        document.getElementById(txtZone4).value = '-';
        document.getElementById(txtZone5).value = '-';
    }

}


function ShowIntRates(rate_value) {
    var a = rate_value.split(";");
    var vLandline = a[1];
    var vmobile = a[2];
    var vsms = a[3];
    var vLandVAT, vMobVAT, vSmsVAT;


    ddlIntRates = document.getElementById(ddlCountry);

    if (ddlIntRates.options[ddlIntRates.selectedIndex].value != "") {
        document.getElementById(txtLandline).value = ((vLandline != '') || (vLandline != 'undefined')) ? vLandline : '-';
        document.getElementById(txtMobile).value = ((vmobile != '') || (vmobile != 'undefined')) ? vmobile : '-';
        if (document.getElementById(txtSMS) != null) {
            document.getElementById(txtSMS).value = ((vsms != '') || (vsms != 'undefined')) ? vsms : '-';
        }

        if (bVat.toLowerCase() != "false") {

            vLandVAT = "(" + a[4] + " iva incl.)";
            vMobVAT = "(" + a[5] + " iva incl.)";
            vSmsVAT = "(" + a[6] + " iva incl.)";

            if (document.getElementById('ltLandVAT') != null) {
                document.getElementById('ltLandVAT').innerHTML = ((vLandVAT != '') || (vLandVAT != 'undefined')) ? vLandVAT : '-';
            }

            if (document.getElementById('ltMobileVAT') != null) {
                document.getElementById('ltMobileVAT').innerHTML = ((vMobVAT != '') || (vMobVAT != 'undefined')) ? vMobVAT : '-';
            }

            if (bSMS.toLowerCase() != "false") {
                if (document.getElementById('ltSmsVAT') != null) {
                    document.getElementById('ltSmsVAT').innerHTML = ((vSmsVAT != '') || (vSmsVAT != 'undefined')) ? vSmsVAT : '-';
                }
            }
        }

    }
    else {
        document.getElementById(txtLandline).value = '-';
        document.getElementById(txtMobile).value = '-';
        if (document.getElementById(txtSMS) != null) {
            document.getElementById(txtSMS).value = '-';

        }
        if (bVat.toLowerCase() != "false") {
            document.getElementById('ltLandVAT').innerHTML = "";
            document.getElementById('ltMobileVAT').innerHTML = "";
            document.getElementById('ltSmsVAT').innerHTML = "";
        }
    }

    if (vProduct == 'fr') {
        IsFreeCreditCountry(a[0]);
    }
}


function checkpasslen(str) {
    var ctrl = str.id;
    var MobileLength = iMobileNumberLength;
    
    if (ctrl == txtMobileNumber) {
        if ((str.value.length > 0) && (str.value.length < MobileLength)) {
            setTimeout(function () { document.getElementById(ctrl).focus() }, 10);
            document.getElementById(lblMsg).innerHTML = sERR_MobileNo;
            return false;
        }
        else {
            document.getElementById(lblMsg).innerHTML = "";
        }
        if ((str.value.length > 0) && (str.value.substring(1, 0) != "0")) {
            setTimeout(function () { document.getElementById(ctrl).focus() }, 10);
            document.getElementById(lblMsg).innerHTML = sERR_MobilePrefix;
            return false;
        }
        else {
            document.getElementById(lblMsg).innerHTML = "";
        }
    }

    else if (ctrl == txtTelephone) {
        if (document.getElementById(ctrl).value.length == 0) {
            setTimeout(function () { document.getElementById(ctrl).focus() }, 10); ;
            document.getElementById(lblMsg).innerHTML = sERR_ContactNo;
            return false;
        }
        else {
            document.getElementById(lblMsg).innerHTML = "";
        }
    }
}

function evalTextInput(e) {
    var allow = '1234567890';
    var k;
    if ((e.keyCode == 46 && !document.all) || (e.keyCode == 8) || (e.keyCode == 9) || (e.keyCode == 37 && !document.all) || (e.keyCode == 39 && !document.all) || (e.keyCode == 35 && !document.all) || (e.keyCode == 36 && !document.all)) {
        return true;
    }
    k = document.all ? parseInt(e.keyCode) : parseInt(e.which);
    return (allow.indexOf(String.fromCharCode(k)) != -1);
}
function evalTextAlpha(e) {
    allow = ' ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
    var k;
    if ((e.keyCode == 46 && !document.all) || (e.keyCode == 8) || (e.keyCode == 9) || (e.keyCode == 37 && !document.all) || (e.keyCode == 39 && !document.all) || (e.keyCode == 35 && !document.all) || (e.keyCode == 36 && !document.all)) {
        return true;
    }
    k = document.all ? parseInt(e.keyCode) : parseInt(e.which);
    return (allow.indexOf(String.fromCharCode(k)) != -1);
}

function clearForm(oForm) {
    var elements = oForm.elements;
    oForm.reset();
    closing = '1';
    document.location = document.location.href;
}

function ValidatePage() {
    if (Page_ClientValidate() == true) {
        return true;
    }
    else {
        return false;
    }
}

function IsFreeCreditCountry(cname) {

    if (cname != '') {
        var loc = document.location;
        var countries = $('.countries').html();
        var Country = countries.split("|");
        for (var i = 0; i < Country.length; i++) {
            if (cname.toLowerCase() == Country[i].toLowerCase()) {
                $('.fc-box-' + lang.replace(' ')).show();
                return;
            }
            else {
                $('.fc-box-' + lang.replace(' ')).hide();
            }
        }
    }
    else {
        $('.fc-box-' + lang.replace(' ')).hide();
    }
}


/*********International Rate Bind***************/

function getInternationalRates(Qry, Object) {

    var DefaultText = $('#' + Object + '> option').html();
    $('#' + Object).html('');
    if ($('#' + Object).empty())
        $('.ajax-loader').html('<img src="Images/ajax-loader.gif" />');

    $.get('rateshandler.ashx?lang=' + lang + '&qry=' + Qry + '&sid=' + sid + '&df=' + DefaultText, function (data) {
        $('#' + Object).html(data);
        $('.ajax-loader').html('');
    });
}
