﻿function CheckNumeric(e) {
    //alert(e.keyCode);
    if (window.event) // IE 
    {
        if (e.keyCode < 48 || e.keyCode > 57) {
            if (e.keyCode != 44 & e.keyCode != 8) {
                event.returnValue = false;
                return false;
            }
        }
    }
    else {
        if (e.which < 48 || e.which > 57) {
            if (e.which != 44 & e.which != 8) {
                return false;
            }
        }
    }
}
function KeyPress(e, field) {
    var oEvent = window.event ? window.event : e;

    //oEvent.keyCode checks go here
    //the following example clears the input box when pressed
    //the Tab key
    if (field.value.length >= 70) {
        oEvent.cancel = true;
        oEvent.keyCode = '';
    }

}

function SelectAllCheckboxes(spanChk, ChkBoxName) {
    var t = document.getElementsByName(ChkBoxName)


    if (spanChk.checked)
        for (i = 0; i < t.length; i++) {
            t[i].checked = true;
        }
    else {
        for (i = 0; i < t.length; i++) {
            t[i].checked = false;
        }
    }
}
function Checkdir(ARRdo, txt) {
    if (ARRdo.checked == 1) {
        txt.dir = "rtl";
        txt.onblur();
    }
    else {
        txt.dir = "ltr";
        txt.onblur();
    }
}
var unicodeFlag = 0;
var extraChars = 0;
var msgCount = 0;
function updateTextBoxCounter(ARRdo, EngRdo, SMSText, InfoCharCounter) {
    //    alert(event.keyCode);
    extraChars = 0;
    if (ARRdo.checked == 1) {
        unicodeFlag = 1;
    }
    else {
        unicodeFlag = 0;
    }
    for (var i = 0; (!unicodeFlag && (i < SMSText.value.length)); i++) {

        if ((SMSText.value.charAt(i) >= '0') && (SMSText.value.charAt(i) <= '9')) {
        }
        else if ((SMSText.value.charAt(i) >= 'A') && (SMSText.value.charAt(i) <= 'Z')) {
        }
        else if ((SMSText.value.charAt(i) >= 'a') && (SMSText.value.charAt(i) <= 'z')) {
        }
        else if (SMSText.value.charAt(i) == '@') {
        }
        else if (SMSText.value.charCodeAt(i) == 0xA3) {
        }
        else if (SMSText.value.charAt(i) == '$') {
        }
        else if (SMSText.value.charCodeAt(i) == 0xA5) {
        }
        else if (SMSText.value.charCodeAt(i) == 0xE8) {
        }
        else if (SMSText.value.charCodeAt(i) == 0xE9) {
        }
        else if (SMSText.value.charCodeAt(i) == 0xF9) {
        }
        else if (SMSText.value.charCodeAt(i) == 0xEC) {
        }
        else if (SMSText.value.charCodeAt(i) == 0xF2) {
        }
        else if (SMSText.value.charCodeAt(i) == 0xC7) {
        }
        else if (SMSText.value.charAt(i) == '\r') {
        }
        else if (SMSText.value.charAt(i) == '\n') {
        }
        else if (SMSText.value.charCodeAt(i) == 0xD8) {
        }
        else if (SMSText.value.charCodeAt(i) == 0xF8) {
        }
        else if (SMSText.value.charCodeAt(i) == 0xC5) {
        }
        else if (SMSText.value.charCodeAt(i) == 0xE5) {
        }
        else if (SMSText.value.charCodeAt(i) == 0x394) {
        }
        else if (SMSText.value.charAt(i) == '_') {
        }
        else if (SMSText.value.charCodeAt(i) == 0x3A6) {
        }
        else if (SMSText.value.charCodeAt(i) == 0x393) {
        }
        else if (SMSText.value.charCodeAt(i) == 0x39B) {
        }
        else if (SMSText.value.charCodeAt(i) == 0x3A9) {
        }
        else if (SMSText.value.charCodeAt(i) == 0x3A0) {
        }
        else if (SMSText.value.charCodeAt(i) == 0x3A8) {
        }
        else if (SMSText.value.charCodeAt(i) == 0x3A3) {
        }
        else if (SMSText.value.charCodeAt(i) == 0x398) {
        }
        else if (SMSText.value.charCodeAt(i) == 0x39E) {
        }
        else if (SMSText.value.charCodeAt(i) == 0xC6) {
        }
        else if (SMSText.value.charCodeAt(i) == 0xE6) {
        }
        else if (SMSText.value.charCodeAt(i) == 0xDF) {
        }
        else if (SMSText.value.charCodeAt(i) == 0xC9) {
        }
        else if (SMSText.value.charAt(i) == ' ') {
        }
        else if (SMSText.value.charAt(i) == '!') {
        }
        else if (SMSText.value.charAt(i) == '\"') {
        }
        else if (SMSText.value.charAt(i) == '#') {
        }
        else if (SMSText.value.charCodeAt(i) == 0xA4) {
        }
        else if (SMSText.value.charAt(i) == '%') {
        }
        else if (SMSText.value.charAt(i) == '&') {
        }
        else if (SMSText.value.charAt(i) == '\'') {
        }
        else if (SMSText.value.charAt(i) == '(') {
        }
        else if (SMSText.value.charAt(i) == ')') {
        }
        else if (SMSText.value.charAt(i) == '*') {
        }
        else if (SMSText.value.charAt(i) == '+') {
        }
        else if (SMSText.value.charAt(i) == ',') {
        }
        else if (SMSText.value.charAt(i) == '-') {
        }
        else if (SMSText.value.charAt(i) == '.') {
        }
        else if (SMSText.value.charAt(i) == '/') {
        }
        else if (SMSText.value.charAt(i) == ':') {
        }
        else if (SMSText.value.charAt(i) == ';') {
        }
        else if (SMSText.value.charAt(i) == '<') {
        }
        else if (SMSText.value.charAt(i) == '=') {
        }
        else if (SMSText.value.charAt(i) == '>') {
        }
        else if (SMSText.value.charAt(i) == '?') {
        }
        else if (SMSText.value.charCodeAt(i) == 0xA1) {
        }
        else if (SMSText.value.charCodeAt(i) == 0xC4) {
        }
        else if (SMSText.value.charCodeAt(i) == 0xD6) {
        }
        else if (SMSText.value.charCodeAt(i) == 0xD1) {
        }
        else if (SMSText.value.charCodeAt(i) == 0xDC) {
        }
        else if (SMSText.value.charCodeAt(i) == 0xA7) {
        }
        else if (SMSText.value.charCodeAt(i) == 0xBF) {
        }
        else if (SMSText.value.charCodeAt(i) == 0xE4) {
        }
        else if (SMSText.value.charCodeAt(i) == 0xF6) {
        }
        else if (SMSText.value.charCodeAt(i) == 0xF1) {
        }
        else if (SMSText.value.charCodeAt(i) == 0xFC) {
        }
        else if (SMSText.value.charCodeAt(i) == 0xE0) {
        }
        else if (SMSText.value.charCodeAt(i) == 0x391) {
        }
        else if (SMSText.value.charCodeAt(i) == 0x392) {
        }
        else if (SMSText.value.charCodeAt(i) == 0x395) {
        }
        else if (SMSText.value.charCodeAt(i) == 0x396) {
        }
        else if (SMSText.value.charCodeAt(i) == 0x397) {
        }
        else if (SMSText.value.charCodeAt(i) == 0x399) {
        }
        else if (SMSText.value.charCodeAt(i) == 0x39A) {
        }
        else if (SMSText.value.charCodeAt(i) == 0x39C) {
        }
        else if (SMSText.value.charCodeAt(i) == 0x39D) {
        }
        else if (SMSText.value.charCodeAt(i) == 0x39F) {
        }
        else if (SMSText.value.charCodeAt(i) == 0x3A1) {
        }
        else if (SMSText.value.charCodeAt(i) == 0x3A4) {
        }
        else if (SMSText.value.charCodeAt(i) == 0x3A5) {
        }
        else if (SMSText.value.charCodeAt(i) == 0x3A7) {
        }
        else if (SMSText.value.charAt(i) == '^') {
            extraChars++;
        }
        //      else if (SMSText.value.charAt(i) == '\n') {
        //         extraChars++;
        //      } 
        //      else if (SMSText.value.charAt(i) == '\r') {
        //         extraChars++;
        //      } 
        else if (SMSText.value.charAt(i) == '{') {
            extraChars++;
        }
        else if (SMSText.value.charAt(i) == '}') {
            extraChars++;
        }
        else if (SMSText.value.charAt(i) == '\\') {
            extraChars++;
        }
        else if (SMSText.value.charAt(i) == '[') {
            extraChars++;
        }
        else if (SMSText.value.charAt(i) == '~') {
            extraChars++;
        }
        else if (SMSText.value.charAt(i) == ']') {
            extraChars++;
        }
        else if (SMSText.value.charAt(i) == '|') {
            extraChars++;
        }
        else if (SMSText.value.charCodeAt(i) == 0x20AC) {
            extraChars++;
        }
        else {
            unicodeFlag = 1;
            ARRdo.checked = 1;
            EngRdo.checked = 0;

        }
    }
    extraChars = eval(extraChars) + countNewLines(SMSText.value);
    if (unicodeFlag) {
        msgCount = SMSText.value.length + eval(extraChars);
        if (msgCount <= 70) {
            msgCount = 1;
        }
        else {//after first arabic message system treat the message length as 67 
            msgCount += (67 - 1);
            msgCount -= (msgCount % 67);
            msgCount /= 67;
        }

        if (readCookie('UserCulture') == 'en-US')
            InfoCharCounter.value = (eval(SMSText.value.length) + eval(extraChars)) + "  Char , " + msgCount + " Messages ";
        else
            InfoCharCounter.value = (eval(SMSText.value.length) + eval(extraChars)) + " حرف , " + msgCount + " رسالة قصيرة";
    }
    else {
        msgCount = eval(SMSText.value.length) + eval(extraChars);
        if (msgCount <= 160) {
            msgCount = 1;
        }
        else {//after first english message system treat the message length as 134
            msgCount += (134 - 1);
            msgCount -= (msgCount % 134);
            msgCount /= 134;
        }

        if (readCookie('UserCulture') == 'en-US')
            InfoCharCounter.value = (eval(SMSText.value.length) + eval(extraChars)) + "  Char , " + msgCount + " Messages ";
        else
            InfoCharCounter.value = (eval(SMSText.value.length) + eval(extraChars)) + " حرف , " + msgCount + " رسالة قصيرة";

    }
}

function countNewLines(message) {

    var delimiter = '\n';
    var count = 0;

    if (message.indexOf('\r\n') != -1) {
        delimiter = '\r\n';
    } else if (message.indexOf('\r') != -1) {
        delimiter = '\r';
    }
    var str = navigator.userAgent;
    var i = 0;
    while ((i = message.indexOf(delimiter, i)) != -1) {

        if ((str.indexOf('MSIE') == -1) && (message.length != 0)) {
            count++;
        }
        i++;

        if (message.length < i) {
            break;
        }
    }
    return count;
}

//not used
function updateNumberCounter() {
    if (unicodeFlag) {

        var MaxSMSCount = 20;
        var accumelator = 0;
        var copystr = document.getElementById('ctl00_ContentPlaceHolder1_SMSText').value;
        var VInfoCharCounter1 = document.getElementById("ctl00_ContentPlaceHolder1_InfoCharCounter").value
        var NumberArr = document.getElementById('ctl00_ContentPlaceHolder1_txtNumber').value.split(",");
        var numcount = NumberArr.length;

        for (var i = 0; i < numcount; i++) {
            if (NumberArr[i].search("966") == 0 || NumberArr[i].search("05") == 0) {
                if (NumberArr[i].search("96654") == 0 || NumberArr[i].search("96656") == 0 || NumberArr[i].search("056") == 0 || NumberArr[i].search("054") == 0) {
                    accumelator += 1;
                }
                else {
                    accumelator += 1;
                }
            }
            else {
                accumelator += 1;
            }
        }

        if (readCookie('UserCulture') == 'en-US') {
            document.forms[0].ctl00_ContentPlaceHolder1_InfoCharCounter.value = "" + (eval(document.forms[0].ctl00_ContentPlaceHolder1_SMSText.value.length) + eval(extraChars)) + " Char , " + msgCount + " Messages" + " , " + (accumelator * msgCount) + " Credit";
        }
        else {
            document.forms[0].ctl00_ContentPlaceHolder1_InfoCharCounter.value = "" + (eval(document.forms[0].ctl00_ContentPlaceHolder1_SMSText.value.length) + eval(extraChars)) + " حرف , " + msgCount + " رسالة قصيرة" + " , " + (accumelator * msgCount) + " نقطة";
        }
    }
    else {

        var MaxSMSCount = 20;
        var accumelator = 0;
        var copystr = document.getElementById('ctl00_ContentPlaceHolder1_SMSText').value;
        var VInfoCharCounter1 = document.getElementById("ctl00_ContentPlaceHolder1_InfoCharCounter").value

        var NumberArr = document.getElementById('ctl00_ContentPlaceHolder1_txtNumber').value.split(",");
        var numcount = NumberArr.length;

        for (var i = 0; i < numcount; i++) {
            if (NumberArr[i].search("966") == 0 || NumberArr[i].search("05") == 0) {
                if (NumberArr[i].search("96654") == 0 || NumberArr[i].search("96656") == 0 || NumberArr[i].search("056") == 0 || NumberArr[i].search("054") == 0) {
                    accumelator += 1;
                }
                else {
                    accumelator += 1;
                }
            }
            else {
                accumelator += 1;
            }
        }

        if (readCookie('UserCulture') == 'en-US') {
            document.forms[0].ctl00_ContentPlaceHolder1_InfoCharCounter.value = "" + (eval(document.forms[0].ctl00_ContentPlaceHolder1_SMSText.value.length) + eval(extraChars)) + "  Char , " + msgCount + "  Messages" + " , " + (accumelator * msgCount) + " Credit";
        }
        else {
            document.forms[0].ctl00_ContentPlaceHolder1_InfoCharCounter.value = "" + (eval(document.forms[0].ctl00_ContentPlaceHolder1_SMSText.value.length) + eval(extraChars)) + " حرف , " + msgCount + " رسالة قصيرة" + " , " + (accumelator * msgCount) + " نقطة";
        }
    }
    return true;
}

function btnclear_onclick() {
    document.getElementById('ctl00_ContentPlaceHolder1_txtNumber').value = ""
}



function readCookie(name) {
    var ca = document.cookie.split(';');
    var nameEQ = name + "=";
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length); //delete spaces
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}




function CloseDiv(divName) {

    document.getElementById(divName).style.display = "none";
}
function GoTo(URL) {
    if (URL != "#") {
        window.location = URL;
    }
}
function ShowDiv(DivName) {
    document.getElementById('div0').style.display = "none";
    document.getElementById('div1').style.display = "none";
    document.getElementById('div2').style.display = "none";
    document.getElementById('div3').style.display = "none";
    document.getElementById('div4').style.display = "none";

    document.getElementById(DivName).style.display = "block";
}
function HideDiv() {
    document.getElementById('div0').style.display = "none";
    document.getElementById('div1').style.display = "none";
    document.getElementById('div2').style.display = "none";
    document.getElementById('div3').style.display = "none";
    document.getElementById('div4').style.display = "none";
}
