﻿function ValidateNumbers() {
    var Mobilenos = document.getElementById('ctl00_ContentPlaceHolder1_txtRecipients').value;
    var filterednos = Mobilenos.replace(/(\r\n|[\r\n])/g, '');
    var Mynumbers = filterednos.split(",");
    if (Mynumbers.length <= 1500) {
        var finalcontacts = [];
        for (var i = 0; i < Mynumbers.length; i++) {
            {
                if (Mynumbers[i] != "") {

                    var number = trim(Mynumbers[i]);
                    if (number.length > 10) {
                        if (number.length == 12) {
                            if (number.substring(0, 2) != "91") {
                                alert("Number should begin with 91");
                                return false;
                            }
                            else {
                                finalcontacts.push(number);
                            }
                        }
                        else {
                            alert("Message can be sent to Mobile Numbers only");
                            alert(number);
                            return false;
                        }
                    }
                    else if (number.length < 10) {
                        alert("Message can be sent to Mobile Numbers only");
                        return false;
                    }
                    else if (number.length == 10) {
                    if (number.substring(0, 1) == "9" || number.substring(0, 1) == "8" || number.substring(0,1)=="7") {

                            number = "91" + number;
                            finalcontacts.push(number);
                        }
                        else {
                            alert("Message can be sent to Mobile Numbers only");
                            return false;
                        }
                    }
                }
            }
        }
        var newlist = new Array();
        label: for (var i = 0; i < finalcontacts.length; i++) {
            for (var j = 0; j < newlist.length; j++) {
                if (newlist[j] == finalcontacts[i])
                    continue label;
            }
            newlist[newlist.length] = finalcontacts[i];
        }
        document.getElementById('ctl00_ContentPlaceHolder1_txtRecipients').value = newlist;
    }
    else {
        alert("Mobile Numbers limit upto 1500 Only ");
        return false;
    }
}



function CheckCount(obj) {
    var txt = obj;
    document.getElementById('ctl00_ContentPlaceHolder1_txtCharsCount').value = (160 - txt.value.length);
    if (txt.value.length >= 160) {
        alert("Max of 160 chars only");
        document.getElementById('ctl00_ContentPlaceHolder1_txtCharsCount').value = 0;
        var actualval = txt.value.substring(0, 160 - 1);
        txt.value = actualval;
        return false;
    }
}

function CheckAutoResponse(obj) {
    var resp = obj;
    document.getElementById('ctl00_ContentPlaceHolder1_txtrespcount').value = (160 - resp.value.length);
    if (resp.value.length >= 160) {
        alert("Max of 160 chars only");
        var modifytext = resp.value.sunstring(0, 160 - 1);
        resp.value = modifytext;
        return false;
    }
}

function CheckMaxChars(obj) {
    var Checkedobj = obj;
    var checked=true;
    if (Checkedobj.type = "checkbox") {
        if (Checkedobj.checked == true) {
            document.getElementById('ctl00_ContentPlaceHolder1_txtCharCount').value = 450;
        }
        else {
            document.getElementById('ctl00_ContentPlaceHolder1_txtCharCount').value = 160;
        }
    }
}


function CheckSmsMessageCount(obj, maxlength) {
    
    var txt = obj;
    var len=160;
    var strLength;
    if (document.getElementById('ctl00_ContentPlaceHolder1_ChMaxChars').checked == true) {
        var max = 450;
    }
    else {
        var max = 160;
    }
    document.getElementById('ctl00_ContentPlaceHolder1_txtCharCount').value = (max - txt.value.length);
    strLength = txt.value.length;
    var msgcredit = Math.ceil(strLength / len);
    document.getElementById('ctl00_ContentPlaceHolder1_txthiddenmsgcount').value = msgcredit;
    if (txt.value.length >= max) {
        alert("Max of '" + max + "' chars only");
        document.getElementById('ctl00_ContentPlaceHolder1_txtCharCount').value = 0;
        var actualval = txt.value.substring(0, max - 1);
        txt.value = actualval;
        strLength = txt.value.length;
        var msgcredit = Math.ceil(strLength / len);
        document.getElementById('ctl00_ContentPlaceHolder1_txthiddenmsgcount').value = msgcredit;
        return false;
    }
}


function openContactsPopuP(strOpen) {
    open(strOpen, "Contacts", "status=1,width=500,height=300,top=100,left=300,scrollbars=yes");
}
function openTemplatesPopuP(strOpen) {
    open(strOpen, "Templates", "status=1,width=600,height=300,top=100,left=300,scrollbars=yes");
}

function openTermsPage(strOpen) {
    open(strOpen, "", "status=1,width=700,height=500,location = no, menubar = no,resizable = no,top=100,toolbar = no,scrollbars=yes");
   /* open(strOpen,"termsConditions"," height = 500, ,, , scrollbars = yes, , width = 600);*/
}

function DisplayAlert(response, context) {
    alert(response);
}


function ValidateRegisterNumber(source, clientside_arguments) {
    clientside_arguments.IsValid = false;
    var txt = clientside_arguments.Value;
    if (txt.substring(0, 1) == "9" || txt.substring(0, 1) == "8" || txt.substring(0,1)=="7") {
        clientside_arguments.IsValid = true;
        return;
    }
    //clientside_arguments.IsValid = true;
}

function ValidateText(source, clientside_arguments) {
    clientside_arguments.IsValid = false;
    var txtVal = clientside_arguments.Value;
    var len = txtVal.length;
    var Search = 0;
    if (len < 10) 
    {
        if (len > 8) 
        {
           clientside_arguments.IsValid = false;
           return false;
        }
        if (len < 3) 
        {
           clientside_arguments.IsValid = false;
           return false;
        }
        clientside_arguments.IsValid = true;
    }
    if (len == 10) {
        var ichars = "^[0-9]";
        if (txtVal.substring(0, 1) == "9" || txtVal.substring(0, 1) == "8" || txtVal.substring(0, 1) == "7") {
            for (var i = 0; i < txtVal.length; i++) {
                if (!txtVal.charAt(i).match(ichars)) {
                    clientside_arguments.IsValid = false;
                    return false;
                }
            }
        }
        else 
        {
            clientside_arguments.IsValid = false;
            return false;
        }
        clientside_arguments.IsValid = true;
    }
}

function ValidateSenderText(source, clientside_arguments) {
    clientside_arguments.IsValid = false;
    var txtVal = clientside_arguments.Value;
    alert(txtVal);
    var len = txtVal.length;
    var Search = 0;
    if (len < 10) {
        var iChars = "^[A-Za-z0-9]";
        for (var i = 0; i < txtVal.length; i++) {
            if (!txtVal.charAt(i).match(iChars)) {
                //clientside_arguments.IsValid = false;
                alert("Invalid SenderID");
                return false;
            }
        }
        if (len > 8) {
            //clientside_arguments.IsValid = false;
            alert("Invalid SenderID");
            return false;
        }
        if (len < 3) {
            //clientside_arguments.IsValid = false;
            alert("Invalid SenderID");
            return false;
        }
        clientside_arguments.IsValid = true;
    }
    if (len == 10) {
        var ichars = "^[0-9]";
        if (txtVal.substring(0, 1) == "9") {
            for (var i = 0; i < txtVal.length; i++) {
                if (!txtVal.charAt(i).match(ichars)) {
                    //clientside_arguments.IsValid = false;
                    alert("Invalid SenderID");
                    return false;
                }
            }
        }
        else {
            //clientside_arguments.IsValid = false;
            alert("Invalid SenderID");
            return false;
        }
        clientside_arguments.IsValid = true;
    }
}


// Removes leading whitespaces
function LTrim(value) {

    var re = /\s*((\S+\s*)*)/;
    return value.replace(re, "$1");

}

// Removes ending whitespaces
function RTrim(value) {
    var re = /((\s*\S+)*)\s*/;
    return value.replace(re, "$1");
}

// Removes leading and ending whitespaces
function trim(value) {
    return LTrim(RTrim(value));
}

function SchduleRadioListSelectedValue() {
    var Radiolist = document.getElementsByName('ctl00_ContentPlaceHolder1_schRadioList');
    document.getElementById('ctl00_ContentPlaceHolder1_txtschcount').value = '10';
    var lblAspradiobuttonValue = document.getElementById('ctl00_ContentPlaceHolder1_lbschtext');
    lblAspradiobuttonValue.innerHTML = '<b>Selected Value:</b>';
    alert(Radiolist.length);
    for (var i = 0; i < Radiolist.length; i++) {
       
        if (Radiolist[i].checked) {
            var lblAspradiobuttonValue = document.getElementById('ctl00_ContentPlaceHolder1_lbschtext');
            lblAspradiobuttonValue.innerHTML = '<b>Selected:</b>';
        }
    }
}

function getCheckedRadio(SchduleValue) {
    if (SchduleValue.value == "2") {
        var lblAspradiobuttonValue = document.getElementById('ctl00_ContentPlaceHolder1_lblschperiod');
       lblAspradiobuttonValue.innerHTML = 'Days';
        document.getElementById('ctl00_ContentPlaceHolder1_txtschcount').value = '';
    }
    if (SchduleValue.value == "3") {
        var lblAspradiobuttonValue = document.getElementById('ctl00_ContentPlaceHolder1_lblschperiod');
        lblAspradiobuttonValue.innerHTML = 'Weeks';
        document.getElementById('ctl00_ContentPlaceHolder1_txtschcount').value = '';
    }
    if (SchduleValue.value == "4") {
        var lblAspradiobuttonValue = document.getElementById('ctl00_ContentPlaceHolder1_lblschperiod');
        lblAspradiobuttonValue.innerHTML = 'Months';
        document.getElementById('ctl00_ContentPlaceHolder1_txtschcount').value = '';
    }
    if (SchduleValue.value == "1") {
        var lblAspradiobuttonValue = document.getElementById('ctl00_ContentPlaceHolder1_lblschperiod');
        lblAspradiobuttonValue.innerHTML = 'Once';
        document.getElementById('ctl00_ContentPlaceHolder1_txtschcount').value = '1';
        //document.getElementById('ctl00_ContentPlaceHolder1_txtschcount').style.display = "none";
        //document.getElementById('ctl00_ContentPlaceHolder1_txtschcount').style.visibility = "hidden";
    }
}

function ShowSelectedDiv(itemValue) {
    if (itemValue.value == "0") {
        document.getElementById('shortcodePanel').style.display = 'block';
        document.getElementById('longcodePanel').style.display = 'none';
    }
    if (itemValue.value == "1") {
        document.getElementById('shortcodePanel').style.display = 'none';
        document.getElementById('longcodePanel').style.display = 'block';  
    }
}


function CheckLoyalityMessage(obj) {
    var resp = obj;
    document.getElementById('ctl00_ContentPlaceHolder1_tabMsgSettings_pnlBirthDay_lblAdvCount').innerText = (140 - resp.value.length);
    document.getElementById('ctl00_ContentPlaceHolder1_tabMsgSettings_pnlBirthDay_lblAdvCount').textContent = (140 - resp.value.length);
    if (resp.value.length >= 140) {
        alert("Max of 140 chars only");
        var modifytext = resp.value.substring(0, 140 - 1);
        resp.value = modifytext;
        return false;
    }
}

function CheckLoyalityOnDayMessage(obj) {
    var resp = obj;
    document.getElementById('ctl00_ContentPlaceHolder1_tabMsgSettings_pnlBirthDay_lblOnDayCount').innerText = (140 - resp.value.length);
    document.getElementById('ctl00_ContentPlaceHolder1_tabMsgSettings_pnlBirthDay_lblOnDayCount').textContent = (140 - resp.value.length);
    if (resp.value.length >= 140) {
        alert("Max of 140 chars only");
        var modifytext = resp.value.substring(0, 140 - 1);
        resp.value = modifytext;
        return false;
    }
}

function CheckLoyalityMrgAdvMessage(obj) {
    var resp = obj;
    document.getElementById('ctl00_ContentPlaceHolder1_tabMsgSettings_pnlMrgDay_lblMrgAdvCount').innerText = (140 - resp.value.length);
    document.getElementById('ctl00_ContentPlaceHolder1_tabMsgSettings_pnlMrgDay_lblMrgAdvCount').textContent = (140 - resp.value.length);
    if (resp.value.length >= 140) {
        alert("Max of 140 chars only");
        var modifytext = resp.value.substring(0, 140 - 1);
        resp.value = modifytext;
        return false;
    }
}

function CheckLoyalityMrgOnDayMessage(obj) {
    var resp = obj;
    document.getElementById('ctl00_ContentPlaceHolder1_tabMsgSettings_pnlMrgDay_lblMrgOnDayCount').innerText = (140 - resp.value.length);
    document.getElementById('ctl00_ContentPlaceHolder1_tabMsgSettings_pnlMrgDay_lblMrgOnDayCount').textContent = (140 - resp.value.length);
    if (resp.value.length >= 140) {
        alert("Max of 140 chars only");
        var modifytext = resp.value.substring(0, 140 - 1);
        resp.value = modifytext;
        return false;
    }
}

function showCurrentlink(current) {
    var active = current;
    document.getElementById(active).style.background = "url(images/navigation-bg-selected.gif) 0 0 no-repeat";
}

function showCurrentlinkAfterLogin(current,cursubmenu) {
    var active = current;
    document.getElementById(active).style.background = "url(images/navigation-bg-selected.gif) 0 0 no-repeat";
    var open = cursubmenu;
    document.getElementById(open).style.display = "block";
}

function ShowCurrentlinkCoupon(current, cousubmenu) {
    var active = current;
    document.getElementById(active).style.background = "url(../images/navigation-bg-selected.gif) 0 0 no-repeat";
    var open = cousubmenu;
    document.getElementById(open).style.display = "block";
}

function ValidateCouponNumbers() {
    var Mobilenos = document.getElementById('ctl00_ContentPlaceHolder_Coupon_txtRecipients').value;
    var filterednos = Mobilenos.replace(/(\r\n|[\r\n])/g, '');
    var Mynumbers = filterednos.split(",");
    if (Mynumbers.length <= 1500) {
        var finalcontacts = [];
        for (var i = 0; i < Mynumbers.length; i++) {
            {
                if (Mynumbers[i] != "") {

                    var number = trim(Mynumbers[i]);
                    if (number.length > 10) {
                        if (number.length == 12) {
                            if (number.substring(0, 2) != "91") {
                                alert("Number should begin with 91");
                                return false;
                            }
                            else {
                                finalcontacts.push(number);
                            }
                        }
                        else {
                            alert("Message can be sent to Mobile Numbers only");
                            alert(number);
                            return false;
                        }
                    }
                    else if (number.length < 10) {
                        alert("Message can be sent to Mobile Numbers only");
                        return false;
                    }
                    else if (number.length == 10) {
                        if (number.substring(0, 1) == "9" || number.substring(0, 1) == "8" || number.substring(0, 1) == "7") {

                            number = "91" + number;
                            finalcontacts.push(number);
                        }
                        else {
                            alert("Message can be sent to Mobile Numbers only");
                            return false;
                        }
                    }
                }
            }
        }
        var newlist = new Array();
        label: for (var i = 0; i < finalcontacts.length; i++) {
            for (var j = 0; j < newlist.length; j++) {
                if (newlist[j] == finalcontacts[i])
                    continue label;
            }
            newlist[newlist.length] = finalcontacts[i];
        }
        document.getElementById('ctl00_ContentPlaceHolder_Coupon_txtRecipients').value = newlist;
    }
    else {
        alert("Mobile Numbers limit upto 1500 Only ");
        return false;
    }
}

function OnCheckRedemptionType(itemValue) {
    if (itemValue.value == '0') {
        // '0' stands for unlimited.
        document.getElementById('ctl00_ContentPlaceHolder_Coupon_tab_RedmpMsg_pnl_redmp_msg_txtRedmp_count').value = 0;
        document.getElementById('ctl00_ContentPlaceHolder_Coupon_tab_RedmpMsg_pnl_redmp_msg_txtRedmp_count').disabled = true;
    }
    if (itemValue.value == '1') {
        // '1' stands for limited.
        document.getElementById('ctl00_ContentPlaceHolder_Coupon_tab_RedmpMsg_pnl_redmp_msg_txtRedmp_count').disabled = false;
        document.getElementById('ctl00_ContentPlaceHolder_Coupon_tab_RedmpMsg_pnl_redmp_msg_txtRedmp_count').value = "";
    }
}

function OnCheckCampaignType(itemValue) {
    //alert(itemValue.value);
    if (itemValue.value == '0') {
        //'0' stands for push method.
        //document.getElementById('ctl00_ContentPlaceHolder_Coupon_txtkeyword').value = "";
        //document.getElementById('ctl00_ContentPlaceHolder_Coupon_txtkeyword').style.display = "none";
        //document.getElementById('ctl00_ContentPlaceHolder_Coupon_lblkey').style.display = "none";
       // document.getElementById('ctl00_ContentPlaceHolder_Coupon_txtkeyword').disabled = true;
        //document.getElementById('ctl00_ContentPlaceHolder_Coupon_txtkeyword').style.background = 'DarkGray';
        document.getElementById('ctl00_ContentPlaceHolder_Coupon_ddl_logcode_list').disabled = true;
        //document.getElementById('ctl00_ContentPlaceHolder_Coupon_ddl_logcode_list').style.background = 'DarkGray';
        //document.getElementById('ctl00_ContentPlaceHolder_Coupon_lblkeyinfo').innerText = "";
        //document.getElementById('ctl00_ContentPlaceHolder_Coupon_lblkeyinfo').textContent = "";
        //document.getElementById('ctl00_ContentPlaceHolder_Coupon_txtkeyword').display = "none";
    }
    if (itemValue.value == '1') {
       // document.getElementById('ctl00_ContentPlaceHolder_Coupon_txtkeyword').value = "";
        //document.getElementById('ctl00_ContentPlaceHolder_Coupon_txtkeyword').disabled = false;
        //document.getElementById('ctl00_ContentPlaceHolder_Coupon_txtkeyword').style.background = 'white';
        document.getElementById('ctl00_ContentPlaceHolder_Coupon_ddl_logcode_list').disabled = false;
        //document.getElementById('ctl00_ContentPlaceHolder_Coupon_ddl_logcode_list').style.background = 'white';
        //document.getElementById('ctl00_ContentPlaceHolder_Coupon_txtkeyword').style.display = "";
        //document.getElementById('ctl00_ContentPlaceHolder_Coupon_lblkey').style.display = "";
    }
}

function OnDefaultCampaignType() {
    alert("coming into function");
}

function OnCheckLongCode(itemDiv) {
    if (itemDiv.value == '0') {
        document.getElementById('div_leadgeneration').style.display = "block";
        document.getElementById('div_bcard').style.display = "none";
        document.getElementById('div_coupon').style.display = "none";
    }
    if (itemDiv.value == '1') {
        document.getElementById('div_bcard').style.display = "block";
        document.getElementById('div_leadgeneration').style.display = "none";
        document.getElementById('div_coupon').style.display = "none";
    }
    if (itemDiv.value == '2') {
        document.getElementById('div_coupon').style.display = "block";
        document.getElementById('div_bcard').style.display = "none";
        document.getElementById('div_leadgeneration').style.display = "none";
    }
}


function Validate_Forwarding_Numbers() {
    var FMobilenos = document.getElementById('ctl00_ContentPlaceHolder1_txt_Mobile_Forwarding').value;
    var forward_filterednos = FMobilenos.replace(/(\r\n|[\r\n])/g, '');
    var My_numbers = forward_filterednos.split(",");
    if (My_numbers.length <= 3) {
        var final_contacts = [];
        for (var i = 0; i < My_numbers.length; i++) {
            {
                if (My_numbers[i] != "") {

                    var num_ber = trim(My_numbers[i]);
                    if (num_ber.length > 10) {
                        if (num_ber.length == 12) {
                            if (num_ber.substring(0, 2) != "91") {
                                alert("Number should begin with 91");
                                return false;
                            }
                            else {
                                final_contacts.push(num_ber);
                            }
                        }
                        else {
                            alert("Plz Check Forward Mobile Numbers.");
                            alert(num_ber);
                            return false;
                        }
                    }
                    else if (num_ber.length < 10) {
                        alert("Plz Check Forward Mobile Numbers.");
                        return false;
                    }
                    else if (num_ber.length == 10) {
                        if (num_ber.substring(0, 1) == "9" || num_ber.substring(0, 1) == "8" || num_ber.substring(0, 1) == "7") {

                            num_ber = "91" + num_ber;
                            final_contacts.push(num_ber);
                        }
                        else {
                            alert("Plz Check Forward Mobile Numbers.");
                            return false;
                        }
                    }
                }
            }
        }
        var new_list = new Array();
        label: for (var i = 0; i < final_contacts.length; i++) {
            for (var j = 0; j < new_list.length; j++) {
                if (new_list[j] == final_contacts[i])
                    continue label;
            }
            new_list[new_list.length] = final_contacts[i];
        }
        document.getElementById('ctl00_ContentPlaceHolder1_txt_Mobile_Forwarding').value = new_list;
    }
    else {
        alert("Forward Mobile Numbers limit upto 3 Only ");
        return false;
    }
}


function Validate_OptNumbers() {
    var Mobilenos = document.getElementById('ctl00_ContentPlaceHolder1_txt_optRecepients').value;
    var filterednos = Mobilenos.replace(/(\r\n|[\r\n])/g, '');
    var Mynumbers = filterednos.split(",");
    if (Mynumbers.length <= 1500) {
        var finalcontacts = [];
        for (var i = 0; i < Mynumbers.length; i++) {
            {
                if (Mynumbers[i] != "") {

                    var number = trim(Mynumbers[i]);
                    if (number.length > 10) {
                        if (number.length == 12) {
                            if (number.substring(0, 2) != "91") {
                                alert("Number should begin with 91");
                                return false;
                            }
                            else {
                                finalcontacts.push(number);
                            }
                        }
                        else {
                            alert("Message can be sent to Mobile Numbers only");
                            alert(number);
                            return false;
                        }
                    }
                    else if (number.length < 10) {
                        alert("Message can be sent to Mobile Numbers only");
                        return false;
                    }
                    else if (number.length == 10) {
                        if (number.substring(0, 1) == "9" || number.substring(0, 1) == "8" || number.substring(0, 1) == "7") {

                            number = "91" + number;
                            finalcontacts.push(number);
                        }
                        else {
                            alert("Message can be sent to Mobile Numbers only");
                            return false;
                        }
                    }
                }
            }
        }
        var newlist = new Array();
        label: for (var i = 0; i < finalcontacts.length; i++) {
            for (var j = 0; j < newlist.length; j++) {
                if (newlist[j] == finalcontacts[i])
                    continue label;
            }
            newlist[newlist.length] = finalcontacts[i];
        }
        document.getElementById('ctl00_ContentPlaceHolder1_txt_optRecepients').value = newlist;
    }
    else {
        alert("Mobile Numbers limit upto 1500 Only ");
        return false;
    }
}

function move(fromID, toID, containerID) {
   
    var from = document.getElementById(fromID);
    var to = document.getElementById(toID);

    for (var i = 0; i < from.options.length; i++) {
        if (from.options[i].selected) {
            to.options.add(new Option(from.options[i].text, from.options[i].value))
            from.remove(i--);
        }
    }

    var container = document.getElementById(containerID);
    container.value = escape("<listboxes>" + serialize(from) + serialize(to) + "</listboxes>");
    //container.value = escape("<listboxes>" + serialize(to) + "</listboxes>");
}

function serialize(dropdown) {
    var value = '<' + dropdown.id + '>';
    for (var i = 0; i < dropdown.options.length; i++) {
        value += '<option><key><![CDATA[' + dropdown.options[i].text + ']]></key><value><![CDATA[' + dropdown.options[i].value + ']]></value></option>';
    }
    value += '</' + dropdown.id + '>';
    return value
}

function unselect(listbox) {
    document.getElementById(listbox).selectedIndex = -1;
}


















