﻿
    function downloadMedia( file ){
        window.open( '/Downloader.aspx?D=' + file, "LargeView", "width=300,height=300,scrollbars=no,resizable,top=0,left=0");
    }

    function MaskingCallMe() {
        var txtAC = $("[id$='_txtMaskingAC']").val();
        var txtPrefix = $("[id$='_txtMaskingPrefix']").val();
        var txtSuffix = $("[id$='_txtMaskingSuffix']").val();
        if (txtAC.length < 3 || !isInteger(txtAC)) {
            alert("The phone number entered is invalid. Please enter a valid area code.");
            return false;
        }

        if (txtPrefix.length < 3 || !isInteger(txtPrefix)) {
            alert("The phone number entered is invalid. Please enter a valid prefix.");
            return false;
        }

        if (txtSuffix.length < 4 || !isInteger(txtSuffix)) {
            alert("The phone number entered is invalid. Please enter a valid suffix.");
            return false;
        }
        PageMethods.CallMe(txtAC + txtPrefix + txtSuffix, ibo, siteValue, CallMe_Success, null);
    }
    
    function CallMe_Success(response){
        if(response){
            $("[id$='_panMaskingThankYou']").show();
            $("[id$='_panDisplayMaskingContactUsByPhone']").hide();
        }
    }

    function MaskingEmailMe() {
        var txtName = $("[id$='_txtMaskingName']").val();
        var txtEmail = $("[id$='_txtMaskingEmail']").val();
        var txtMessage = $("[id$='_txtMaskingMessage']").val();
        var txtPhone = $("[id$='_txtMaskingAC']").val() + $("[id$='_txtMaskingPrefix']").val() + $("[id$='_txtMaskingSuffix']").val();
        
        if (txtName.length == 0) {
            alert("Please enter a name.");
            return false;
        }
                    
        if (txtEmail == ''){
            alert("Please enter an email address.");
           return false;
        }
           
        if (! /^[A-Za-z0-9]([A-Za-z0-9]|[_/\-.\\])*@[A-Za-z0-9]([A-Za-z0-9]|[_/\-.\\])*(.[A-Za-z0-9]([A-Za-z0-9]|[_/\-.\\])*)+$/.test(txtEmail) ){
            alert("Please enter a valid email address.");
            return false;
        }
        
        if (txtPhone == ''){
            txtPhone = " ";
        }
                    
        if (txtMessage == ''){
            alert("Please enter a message.");
            return false;
        }
        
        if(!validateText(txtMessage)){
            return false;
        }   
        PageMethods.MaskingSendEmail(ibo, txtName, txtEmail, txtPhone, txtMessage, ($("[id$='_chkMaskingSendCopy']").val() == null ? false : true) , maskingEmail_Success, null );                                                                                                 
    }
    
    function maskingEmail_Success(response){
        if(response){
            $("[id$='_panMaskingThankYou']").show();
            $("[id$='panDisplayMaskingContactUsByEmail']").hide();
        }
    }

    function validateText(text) {
        var arr = new Array('`', '~', '^', '{', '}', '[', ']', '|', '\"', '<', '>', '/');

        var blnValid = true;
        for (i = 0; i < text.length; i++) {
            for (j = 0; j < arr.length; j++) {
                if (text.charAt(i) == arr[j]) {
                    result = alert('[ ' + arr[j] + ' ] is an invalid character, please try again.');
                    text = text.replace(arr[j], '');
                    blnValid = false;
                }
            }
        }
        return blnValid;
    }

    function isInteger(s) {
        var i;

        if (isEmpty(s))
            if (isInteger.arguments.length == 1) return 0;
        else return (isInteger.arguments[1] == true);

        for (i = 0; i < s.length; i++) {
            var c = s.charAt(i);

            if (!isDigit(c)) return false;
        }
        return true;
    }

    function isEmpty(s) {
        return ((s == null) || (s.length == 0))
    }

    function isDigit(c) {
        return ((c >= "0") && (c <= "9"))
    }
    
    function byEmail(){
        $("[id$='_panDisplayMaskingContactUsByEmail']").show();
        $("[id$='_panDisplayMaskingContactUs']").hide();
    }
    
    function byPhone(){
        $("[id$='_panDisplayMaskingContactUsByPhone']").show();
        $("[id$='_panDisplayMaskingContactUs']").hide();
    }
    
    Array.prototype.contains = function (element) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] == element) {
                return true;
            }
        }
        return false;
    }
    
    function showAmway(){
        window.open('http://www.amway.com/Shop/Registration/CustomerLanding.aspx', 'LargeView', 'scrollbars=yes, resizable, top=0,left=0');
    }
    function showWWDB(){
        window.open('http://www.wwdb.com', 'LargeView', 'scrollbars=yes, resizable, top=0,left=0');
    }
    function showMyBiz(siteMyBiz){
        window.open("http://" + siteMyBiz, 'LargeView', 'scrollbars=yes, resizable, top=0,left=0');
    }

 $(document).ready(function() {
//         var _location = top.location.href;
//         if (_location.indexOf("Shop.aspx") < 0 && _location.indexOf("Ditto.aspx") < 0) {
//             if (top.location != location) {
//                 $j("[id$='_divMaskingModal']").show();
//                 $j('#box1').jOverlay({ bgClickToClose: false, autohide: false, closeOnEsc: false });
//                 $j("[id$='_panDisplayMaskingText']").show();

//                 if (callMe) {
//                     $j("[id$='_panCallMe']").show();
//                 }
//             }
//         }
     if ($("[id$='_divMaskingModal']").css('display') == '') {
         $("[id$='_panLogin']").hide();
     }
     $("#country").msDropDown({ visibleRows: 2, rowHeight: 30 });
 });
 function onSelectChange() {
     var selected = $("#country option:selected");
     if (selected.val() == 0) {
         document.cookie = 'Country = 1;path=/';
         top.location.href = top.location.href;
     }
     else {
         document.cookie = 'Country = 0;path=/';
         top.location.href = top.location.href;
     }
 }

