﻿var popupDiv = document.createElement('div');
var progressDiv = document.createElement('div');
var divIdName = 'popupDiv';
var progressDivIdName = 'progressDiv';
popupDiv.setAttribute('id', divIdName);
popupDiv.style.position = 'absolute';

function ShowMessage(msg, autoHide, top, left) {
    var width = '220px';
    var height = '120px';
    var x = (document.body.clientWidth - parseInt(width)) / 2 + "px";
    var y = screen.height / 2 + scrollingDetector() - parseInt(height) / 2 + "px";
    popupDiv.style.backgroundColor = "#eeeeee";
    popupDiv.style.border = "solid black 1px";
    popupDiv.style.width = width;
    popupDiv.style.height = height;
    popupDiv.style.left = (left == null) ? x : left;
    popupDiv.style.top = (top == null) ? y : top;
    popupDiv.innerHTML = MessageTemplate(msg);
    document.getElementsByTagName('BODY')[0].appendChild(popupDiv);
    document.getElementById('popupDiv').focus();
    if (autoHide) {
        window.setTimeout(HideMessage, 2000);
    }
}

function HideMessage() {
    try {
        document.getElementsByTagName('BODY')[0].removeChild(popupDiv);
        if (returnFocusElement != '') {
            document.getElementById(returnFocusElement).focus();
            returnFocusElement = '';
        }
    }
    catch (ex) { }
}

function MessageTemplate(msg) {

    var html = "";
    html += "<table cellpadding='0' cellspacing='0' style=\"table-layout:fixed; width:100%; height:100%; \" onmousedown='HideMessage();'>";
    html += "<tr style=\"background-color:#004276; height:20px;\">";
    html += "<td style=\"text-align:right; padding-right:5px;padding-top:5px;\">";
    html += "<div style=\"color:white;font-family:Wingdings;font-size:16px;cursor:pointer\" onclick='HideMessage()'>x</div>";
    html += "</td>";
    html += "</tr>";
    html += "<tr style=\"height:100px;\">";
    html += "<td style=\"text-align:center; padding: 10px; height:90px;\">";
    html += "<span style=\"font-family : Verdana, Arial; font-size:12px;color:black;direction:ltr;\">" + msg + "</span>";
    html += "</td>";
    html += "</tr>";
    html += "</table>";

    return html;
}

function scrollingDetector() {
    if (navigator.appName == "Microsoft Internet Explorer") {
        return document.documentElement.scrollTop;
    }
    else// For FireFox 
    {
        return window.pageYOffset;
    }
}



function isInteger(s) {
    var i;
    for (i = 0; i < s.length; i++) {
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function IsNumber(control) {

    if (control.value == "") {
        return "error";
    }
    if (isInteger(control.value)) {
        return "";
    }
    else {
        return "error";
    }
}

function CreateXmlHttpObject() {
    var objXMLHttp = null;
    if (window.XMLHttpRequest) {
        objXMLHttp = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    return objXMLHttp
}

function Send(service) {
    
    document.getElementById("ServiceTextBox").value = service;
    switch (service) {
        case 'cnnnews':
            SendService(service, "PhoneNewsTextBox", "PhoneExtNewsDropDownList")
            break;
        case 'cnnbusi':
            SendService(service, "PhoneBizTextBox", "PhoneExtBizDropDownList")
            break;
        case 'cnnent':
            SendService(service, "PhoneEntTextBox", "PhoneExtEntDropDownList")
            break;
        case 'cnnsport':
            SendService(service, "PhoneSportTextBox", "PhoneExtSportDropDownList")
            break;
    }
}

function SendService(service, PhoneTextBox, PhoneExtDropDownList) {
    var phoneTxt = document.getElementById(PhoneTextBox);
    var phoneDdl = document.getElementById(PhoneExtDropDownList);
    if (IsNumber(phoneTxt) == "error") {
        ShowMessage("מספר הטלפון שהוזן אינו תקין, נסה שנית", true);
        phoneTxt.focus();
    }
    else {
        if (phoneTxt.value.length < 7) {
            ShowMessage("מספר טלפון לא תקין, על מספר הטלפון להכין (בנוסף לקידומת) 7 ספרות", true);
            phoneTxt.focus();
        }
        else {

            if (document.getElementById("SendButton") != null) {
                document.getElementById("SendButton").click();
            }
        }
    }
}

function ClearForm() {
    document.getElementById("PhoneNewsTextBox").value = "";
    document.getElementById("PhoneBizTextBox").value = "";
    document.getElementById("PhoneEntTextBox").value = "";
    document.getElementById("PhoneSportTextBox").value = "";
}

