﻿
var isIE = (navigator.appName.indexOf("Microsoft") != -1);
var chart1a = new Image();
chart1a.src = "/images/words_orange.gif";

var chart1b = new Image();
chart1b.src = "/images/words_blue.gif";

var chart2a = new Image();
chart2a.src = "/images/category_orange.gif";

var chart2b = new Image();
chart2b.src = "/images/category_blue.gif";

var chart3a = new Image();
chart3a.src = "/images/times_orange.gif";

var chart3b = new Image();
chart3b.src = "/images/times_blue.gif";

function addProperty(obj, onlyget, name, defaultVal, validator) {
    if (!validator) {
        validator = function() { return true; }
    }
    if (!validator(defaultVal)) {
        throw "Invalid  default value (" + defaultVal + ")";
    }
    var prop = defaultVal;
    obj["get" + name] = function() {
        return prop;
    }
    if (!onlyget) {
        obj["set" + name] = function(value) {
            if (!validator(value)) {
                throw "Invalid value (" + value + ")";
            }
            prop = value;
        }
    }
}

function $(id) {
    if (typeof (id) == "string") {
        return document.getElementById(id);
    }
    return id;
}

function getElementHeight(ele) {
    try {
        return $(ele).clientHeight
    } catch (e) { return null; }
}

function setElementHeight(ele, height) {
    try {
        $(ele).style.height = height;
    } catch (e) { return; }
}

function getElementWidth(ele) {
    try {
        return $(ele).clientWidth
    } catch (e) { return null; }
}

function displayElem(ele) {
    try {
        $(ele).style.display = "block"
    } catch (e) { return; }
}
function hideElem(ele) {
    try {
        $(ele).style.display = "none"
    } catch (e) { return; }
}

function setElementWidth(ele, width) {
    try {
        $(ele).style.width = width;
    } catch (e) { return; }
}



function Requester(url, method, params) {
    this.xmlobj = null;
    try {
        // instantiate object for Mozilla, Nestcape, etc.
        this.xmlobj = new XMLHttpRequest();
    }
    catch (e) {
        try {
            // instantiate object for Internet Explorer
            this.xmlobj = new ActiveXObject('Microsoft.XMLHTTP');
        }
        catch (e) {
            // Ajax is not supported by the browser
            this.xmlobj = null;
        }
    }
    // define 'getData()" method
    this.getData = function() {
        // if request is completed
        if (this.xmlobj) {
            if (this.xmlobj.readyState == 4) {
                // if status == 200 return file data
                if (this.xmlobj.status == 200) {
                    // get data
                    return this.xmlobj.responseText;
                }
                else {
                    throw "'Failed to get response :" + this.xmlobj.statusText;
                }
            }
        }
    }
    // assign state handler
    this.xmlobj.onreadystatechange = this.getData;
    // open socket connection

    if (!method || method.toLowerCase() != "get" || method.toLowerCase() != "post") {
        method = "GET";
    }
    this.xmlobj.open(method, url, false);
    // send request
    this.xmlobj.send(params);
}


// instantiate 'requester' object
//var xmlobj=new Requester('http://localhost');
// call 'getData()' method
//alert(xmlobj.getData());


function loadPopup(id, w, h) {

    var popup = $(id);
    var body = $("body");


    popup.style.width = w;
    popup.style.height = h;
    popup.style.position = "absolute"
    //popup.style.left = ((body.scrollWidth-body.clientWidth)==0) ? (body.clientWidth-w)/2 : 0;
    //popup.style.top = ((body.scrollHeight-body.clientHeight)==0) ? (body.clientHeight-h)/2 : 20;
    displayShield();
    popup.style.left = (pageWidth() - body.scrollLeft - w) / 2;
    popup.style.top = (pageHeight() - body.scrollTop - h) / 2;
    setBodyScroll(false);

    popup.style.display = "";
    popup.style.zIndex = 106;
    try { $("flash").style.display = "none" } catch (e) { }


}

function pageWidth() {
    return window.innerWidth != null ? window.innerWidth : document.body != null ? document.body.clientWidth : null;
}
function pageHeight() {
    return window.innerHeight != null ? window.innerHeight : document.body != null ? document.body.clientHeight : null;
}


function setBodyScroll(enable) {

    if (isIE) {
        if (enable) {
            document.body.scroll = "yes";
        } else {
            document.body.scroll = "no";
        }
    } else {
        if (enable) {
            document.getElementsByTagName("html")[0].style.overflow = "auto";
        } else {
            document.getElementsByTagName("html")[0].style.overflow = "hidden";
        }
    }

}


function displayShield() {
    $("shield").style.display = "block";
    $("shield").style.height = $("body").scrollHeight;
}

function hideShield() {
    $("shield").style.display = "none";
}
function closePopup(id) {
    hideShield();
    try { $("flash").style.display = "" } catch (e) { }
    var popup = $(id);
    popup.style.display = "none";
    setBodyScroll(true);
}
function NVPair(name, value) {
    addProperty(this, false, "Name", name, null);
    addProperty(this, false, "Value", value, null)

}

function Button(caption, invoke) {
    addProperty(this, false, "Caption", caption, null);
    addProperty(this, false, "Invoke", invoke, null)

    this.paint = function() {
        return "<table align=left dir='rtl' style='margin-left:0px' cellpadding=0 cellspacing=0><tr><td style='width:8px;height:26px' class='rightButton'>&nbsp;</td><td class='centerButton'><a href=\"javascript:" + this.getInvoke() + "\" style='color:white'>" + this.getCaption() + "</a></td><td  class='leftButton' style='width:10px:height:26px'>&nbsp;</td></tr></table>";
    }
}

function PopupManager() { }
PopupManager.popups = [];


PopupManager.add = function(popup) {
    PopupManager.popups[popup.getId()] = popup;
}
PopupManager.get = function(id) {
    return PopupManager.popups[id];
}

function preparePopup(id, errorMsg, params) {
    var popup = null;
    var buttons = null;
    var popupParam = "";
    if (params != null && params.length > 0) {
        for (var i = 0; i < params.length; i++) {
            popupParam += "&" + params[i].getName() + "=" + escape(params[i].getValue());
        }
    }
    var errorParam = !errorMsg ? "" : ((errorMsg.indexOf("&") == 0) ? "errorMsg=" + escape(errorMsg.substring(1, errorMsg.length)) : "errorMsg=" + escape(errorMsg));
    var completeParams = (errorParam == "" && popupParam == "") ? "" : "?" + ((popupParam == "") ? "" : "&" + popupParam) + ((errorParam == "") ? "" : "&" + errorParam)
    while (completeParams.indexOf("?&") == 0) {
        completeParams = completeParams.indexOf("?&") == 0 ? completeParams.substring(0, 1) + completeParams.substring(2, completeParams.length) : completeParams
    }
    switch (id) {
        case "loginPopup":
            var xmlobj = new Requester('../popups/login.asp' + completeParams);
            buttons = [new Button("התחבר", "$('login').submit()"), new Button("הרשמה", "location.href='register.asp'")];
            popup = new Popup(id, 375, 200, "כניסה למערכת", "/images/icon_close_lock.jpg", xmlobj.getData(), buttons, [$("computers")]);
            break;
        case "logoffPopup":
            var xmlobj = new Requester('../popups/logoff.asp' + completeParams);
            popup = new Popup(id, 375, 200, "התנתקות", "/images/icon_open_lock.jpg", xmlobj.getData(), buttons, [$("computers")]);
            break;
        case "alert_notification_methods":
            var xmlobj = new Requester('../popups/alert_notification_methods.asp' + completeParams);
            buttons = [new Button("אפס", "$('send_configform').reset()"), new Button("עדכן", "$('send_configform').submit()")];
            popup = new Popup(id, 375, 200, "הגדרות שליחה", "/images/icon_close_lock.jpg", xmlobj.getData(), buttons, [$("computers")]);
            break;
        case "not-ready":
            var xmlobj = new Requester('../popups/not-ready.asp' + completeParams);
            popup = new Popup(id, 375, 200, "בבנייה", "/images/icon_close_lock.jpg", xmlobj.getData(), buttons, [$("computers")]);
            break;
        case "screenshot_config":
            var xmlobj = new Requester('../popups/screenshot_conf.asp' + completeParams);
            buttons = [new Button("אפס", "$('screenshot_configform').reset()"), new Button("עדכן", "$('screenshot_configform').submit()")];
            popup = new Popup(id, 375, 200, "הגדרות תצלום מסך", "/images/icon_close_lock.jpg", xmlobj.getData(), buttons, [$("computers")]);
            break;
        case "logs":
            var xmlobj = new Requester('../sys/showlog.asp' + completeParams);
            popup = new Popup(id, 700, 450, "רשימת אירועים", null, xmlobj.getData(), buttons, [$("computers")]);
            break;
        case "changeuserdetails":
            var xmlobj = new Requester('../popups/changedetails.asp' + completeParams);
            buttons = [new Button("אפס", "$('changeusrdetails').reset()"), new Button("עדכן", "if(checkupdatedetailsform()){$('changeusrdetails').submit()}")];
            popup = new Popup(id, 400, 450, "עדכון פרטים", "/images/icon_close_lock.jpg", xmlobj.getData(), buttons, [$("computers")]);
            break;
        case "settingssaved":
            popup = new Popup(id, null, null, "שמירת שינויים", "/images/button_ok.png", "<div class='normalText'>השינויים נשמרו בהצלחה</div>", buttons, [$("computers")]);
            break;
        case "reconnect":
            popup = new Popup(id, null, null, "התחברות לאתר", null, "<form action='../index.asp' method='post' id='notlogged'><input type='hidden' name='popup' value='loginPopup'></form><div class='normalText' id='relog'>אינך מחובר לאתר, על מנת להתחבר לחץ <span class=\"embeddedLink\"><a href=\"javascript:$('notlogged').submit()\" onclick=\"$('notlogged').submit()\">כאן </a></span></div><br/>", buttons, [$("computers")]);
            break;
        case "add_change_words":
            var xmlobj = new Requester('/popups/add_change.asp' + completeParams);
            buttons = [new Button("שמור", "selectAll('items',true); $('itemsmanageform').submit()")];
            popup = new Popup(id, 450, 300, "הוסף/הסר ביטויים", null, xmlobj.getData(), buttons, [$("computers")]);
            break;
        case "add_change_computers":
            var xmlobj = new Requester('/popups/add_change.asp' + completeParams);
            buttons = [new Button("שמור", "prepareForSending($('computersmanageform'),$('hiddenval')); selectAll('items',true); $('computersmanageform').submit()")];
            popup = new Popup(id, 450, 300, "הוסף/הסר מחשבים", null, xmlobj.getData(), buttons, [$("computers")]);
            break;
        case "add_change_urls":
            var xmlobj = new Requester('/popups/add_change.asp' + completeParams);
            buttons = [new Button("שמור", "selectAll('items',true); $('itemsmanageform').submit()")];
            popup = new Popup(id, 450, 300, "הוסף/הסר אתר", null, xmlobj.getData(), buttons, [$("computers")]);
            break;
        case "charts":
            var xmlobj = new Requester('/popups/charts.asp' + completeParams);
            popup = new Popup(id, 650, 500, "גרפים", null, xmlobj.getData(), null, [$("computers")]);
            break;
        case "error":
            popup = new Popup(id, null, null, "שגיאה", "/images/error_Icon.jpg", "<div class='normalText' dir='rtl'>" + errorMsg + "</div>", buttons, [$("computers")]);
            break;
        case "reg-success":
            popup = new Popup(id, null, null, "רישום משתמש חדש", "/images/button_ok.png", "<div class='normalText' dir='rtl'>תהליך הרישום הסתיים.<br/><br/>כעת עליך להוריד את התוכנה ולהתקינה.<br/><span class='embeddedlink'><a href='/client/BeeAlarmsetup.exe'>נא ללחוץ כאן להמשך התהליך</a></span></div>", buttons, [$("computers")]);
            break;
        case "formsent":
            popup = new Popup(id, null, null, "שליחת טופס", null, "<div class='normalText'>הטופס נשלח בהצלחה! נציגנו יחזרו אליך בהקדם</div>", buttons, [$("computers")]);
            break;

        case "add_change_B":
            var xmlobj = new Requester('/popups/add_change_B.asp' + completeParams);
            switch (completeParams) {
                case '?type=app_filter':
                    buttons = [new Button("שמור", "prepare_add_change_B_Form();$('add_change_B_form').submit()")];
                    popup = new Popup(id, 800, 600, "ניהול תוכנות", null, xmlobj.getData(), buttons, [$("computers")]);
                    break;
                case '?type=wordgroups':
                    buttons = [new Button("שמור", "prepare_add_change_B_Form();$('add_change_B_form').submit()")];
                    popup = new Popup(id, 450, 300, "קבוצת מילים", null, xmlobj.getData(), buttons, [$("computers")]);
                    break;
                //					case '?type=urlgroups': 
                //						buttons = [new Button("שמור","prepare_add_change_B_Form();$('add_change_B_form').submit()")]; 
                //						popup =  new Popup(id,450,300, "קבוצת אתרים", null, xmlobj.getData(), buttons,[$("computers")]); 
                //					break; 
                case '?type=urlgroups':
                    //var xmlobj=new Requester('../popups/logoff.asp' + completeParams);
                    popup = new Popup(id, 375, 200, "קבוצות אתרים", null, xmlobj.getData(), buttons);
                    break;
                    break;
            }




    }
    if (popup) {
        PopupManager.add(popup);
    }
    return popup
}


function Popup(id, width, height, title, imgUrl, content, buttons, objectsToHide) {
    addProperty(this, false, "Id", id, null);
    addProperty(this, false, "Width", (width > Popup.minWidth) ? width : Popup.minWidth, null);
    addProperty(this, false, "Height", (height > Popup.minHeight) ? height : Popup.minHeight, null);
    addProperty(this, false, "Title", title, null);
    addProperty(this, false, "ImageUrl", imgUrl, null);
    addProperty(this, false, "Content", content, null);
    addProperty(this, false, "ScrollTop", 0, null);
    addProperty(this, false, "ObjectsToHide", objectsToHide, null);


    if (buttons) {
        buttons[buttons.length] = new Button("סגור", "PopupManager.get('" + this.getId() + "').hide()");
    } else {
        buttons = [new Button("סגור", "PopupManager.get('" + this.getId() + "').hide()")];
    }
    buttons = buttons.reverse();
    addProperty(this, false, "Buttons", buttons, null);
    var buttonsHTML = "<table align='left' border=0><tr>";
    for (i = 0; i < this.getButtons().length; i++) {
        buttonsHTML += "<td>" + this.getButtons()[i].paint() + "</td>";
    }
    buttonsHTML += "</tr></table>";
    var image = this.getImageUrl() ? "<img src=\"" + this.getImageUrl() + "\" border=0 style=\"margin:20px\">" : "&nbsp;";
    var html = "<div class=popup onkeypress=\"closePopupOnEsc(event,'" + this.getId() + "')\" id=\"" + this.getId() + "\" style=\"position:absolute;display:block;width:" + this.getWidth() + ";height:" + this.getHeight() + ";background-image: url(../images/login-icon02.jpg) ;	background-repeat:no-repeat;		background-position:bottom right;\">" +
	"<TABLE style=\"width:100%;height:100%\" border=0><TR>" +
		"<TD valign=top>" + image + "</TD>" +
		"<td  style=\"width:100%;height:100%\" height='100%' valign=\"top\">" +
				"<table  cellpadding=0 cellspacing=0 width='100%' height='100%' border=0>" +
"<tr><TD align=right valign=top height='20'><b><a href=\"javascript:PopupManager.get('" + this.getId() + "').hide()\">סגור</a></b></td></tr>" +
"<tr><td><table cellpadding=0 cellspacing=0><tr><td class='popupTitleLeft'>&nbsp;&nbsp;&nbsp;</td><td class='popupTitleCenter' align=right><div class='popuptitle' style='width:100%;height:100%;margin-top:3px;margin-right:10px'>" + this.getTitle() + "</div></td><td class='popupTitleRight'>&nbsp;&nbsp;&nbsp;</td></tr></table></td>" +
				"<tr><TD align=right valign='top' height='100%'><br/>" + this.getContent() + "</td></tr>" +
				"<tr><TD align=left width='100%'>" + buttonsHTML + "</td></tr>" +
			"</TABLE>" +
		"</TD></TR>" +
	"</TABLE>" +
	"</div>";

    addProperty(this, true, "HTML", html, null);
    PopupManager.add(this);
    this.show = function() {
        displayShield();
        setBodyScroll(false);
        var popupDiv = document.createElement("div");
        popupDiv.id = this.getId();
        popupDiv.innerHTML = this.getHTML();
        var body = $("body");
        body.appendChild(popupDiv);
        this.setScrollTop(body.scrollTop)
        self.scrollTo(0, 0);
        popupDiv.style.position = "absolute"
        popupDiv.style.left = (pageWidth() - body.scrollLeft - this.getWidth()) / 2;
        popupDiv.style.top = (pageHeight() - body.scrollTop - this.getHeight()) / 2;

        popupDiv.style.display = "block";
        popupDiv.style.zIndex = 106;
        try { $("flash").style.display = "none" } catch (e) { }
        if (popupDiv.getElementsByTagName("form")) {
            var form = popupDiv.getElementsByTagName("form")[0];
            if (form) {
                var i = 0;
                for (; form.elements && i < form.elements.length; i++) {
                    try {
                        form.elements[i].focus();
                        break;
                    } catch (e) { }
                }
            }
        }
        if (this.getObjectsToHide() != null) {
            var toHide = this.getObjectsToHide();
            if (toHide instanceof String) {
                toHide = [toHide];
            }
            for (var i = 0; i < toHide.length; i++) {
                try { toHide[i].style.display = "none"; } catch (e) { }
            }
        }

    }
    this.hide = function() {
        var popupDiv = $(this.getId());
        popupDiv.style.display = "none";
        var body = $("body");
        body.removeChild(popupDiv);
        self.scrollTo(0, this.getScrollTop());
        self.scrollTop = this.getScrollTop();
        try { $("flash").style.display = "" } catch (e) { }
        setBodyScroll(true);
        hideShield();

        if (this.getObjectsToHide() != null) {
            var toHide = this.getObjectsToHide();
            if (toHide instanceof String) {
                toHide = [toHide];
            }
            for (var i = 0; i < toHide.length; i++) {
                try { toHide[i].style.display = ""; } catch (e) { }
            }
        }

    }

}
Popup.minWidth = 350;
Popup.minHeight = 250;
Popup.titleBGImage = new Image();
Popup.titleBGImage.src = "/images/login-flach.jpg";
Popup.titleBGImage.width = 246;
Popup.titleBGImage.height = 36;
function Group(caption, content) {
    this.caption = caption;
    this.content = content;
}
function markMenuItem(item) {
    $("top" + item.id).style.backgroundColor = "#ffa500";
}
function markMenubItem(item) {
    $("top" + item.id).style.background = "#ffc20f";
}
function unmarkMenuIbtem(item) {
    $("top" + item.id).style.backgroundColor = "#ffffff";
}
function unmarkMenuItem(item) {
    $("top" + item.id).style.backgroundColor = "#ffd700";
}



function submitenter(myfield, e) {
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;

    if (keycode == 13) {
        myfield.form.submit();
        return false;
    }
    else
        return true;
}
function closePopupOnEsc(e, id) {
    var kC = (window.event) ?    // MSIE or Firefox?
                 event.keyCode : e.keyCode;
    var Esc = (window.event) ?
                27 : e.DOM_VK_ESCAPE // MSIE : Firefox
    if (kC == Esc) {
        PopupManager.get(id).hide()
    }
}


function checkupdatedetailsform() {
    if (changeusrdetails.Contact_FirstName.value == "") {
        alert("יש למלא שם פרטי");
        changeusrdetails.Contact_FirstName.focus()
        return false;
    } else {
        if (changeusrdetails.Contact_LastName.value == "") {
            alert("יש למלא שם משפחה");
            changeusrdetails.Contact_LastName.focus()
            return false;
        } else {
            if (changeusrdetails.Contact_cellular.value == "") {
                alert("יש למלא טלפון נייד");
                changeusrdetails.Contact_cellular.focus()
                return false;
            } else {
                var str = changeusrdetails.Contact_Email.value
                var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
                if (!(filter.test(str))) {
                    alert("יש למלא כתובת דואר אלקטרוני");
                    changeusrdetails.Contact_Email.focus()
                    return false;
                } else {
                    if (changeusrdetails.Account_Password.value != "") {
                        if ((changeusrdetails.Account_Password.value.length < 5) || (changeusrdetails.Account_Password.value.length > 11)) {
                            alert("הסיסמא צריכה להכיל בין 5 ל 11 תווים");
                            changeusrdetails.Account_Password.focus()
                            return false;
                        } else {
                            if (changeusrdetails.Account_Password.value != changeusrdetails.Account_PasswordConfirm.value) {
                                alert("סיסמת האימות אינה תואמת לסיסמא שהוזנה, נא להזינה שוב");
                                changeusrdetails.Account_PasswordConfirm.focus()
                                return false;
                            } else {
                                return true;
                            }
                        }
                    } else {
                        return true;
                    }
                }
            }
        }
    }
}

function openScreenshotZoom(picPath) {
    window.open('/sys/show_screenshot.asp?pic=' + picPath, 'BeeAlarm', 'location=no,toolbar=no,resizable=yes,scrollbars=yes"');
}

function toggleLogRow(id) {
    var row = $(id);
    if (row) {
        if (row.style.display == "none") { row.style.display = "" }
        else { row.style.display = "none" }
    }
}





function DoAdd(type) {
    //if(type==1){
    var strText = $("input_text").value
    //}else{
    //	var strText = $("input_text").optionId
    //}


    if (strText == "")
        return;

    if (!IsItemExists($("items"), strText)) {

        //ccheck	if (maxcomp >0){
        //ccheck		if (($("items").options.length)+1>maxcomp){
        //ccheck			alert('ביכולתך להגדיר כרגע עד '+maxcomp+' מחשבים, בשביל יותר מחשבים עליך לקנות עוד רישיונות');
        //ccheck	}else{
        if (type == 1) {
            AddItem($("items"), strText, strText);
            $("input_text").value = "";
        } else {
            AddItem($("items"), strText, $("input_text").optionId);
            $("input_text").value = "";
            $("input_text").optionId = "";
        }
        //ccheck	}
        //ccheck }else{
        //ccheck  	AddItem($("items"), strText, $("input_text").optionId);
        //ccheck	$("input_text").value = "";
        //ccheck	$("input_text").optionId = "";
        //ccheck	}
    }
}

function DoRemove() {
    RemoveItem(document.getElementById("items"));
}

function DoEdit() {
    if (GetSelectedIndex() != -1) {
        var intIndex = GetSelectedIndex();
        var List = $("items");
        var CurVal = List.options[intIndex].value;
        var CurText = List.options[intIndex].text;
        DoRemove();

        $("input_text").value = CurText;
        $("input_text").optionId = CurVal;
    }
}

function IsItemExists(List, txtItem) {
    for (var i = 0; i < List.options.length; i++) {
        var strCurrentValueId = List.options[i].text;
        if (txtItem == strCurrentValueId) {
            return true;
        }
    }

    return false;
}

function ImMouseDown(Im, Src) {
    Im.src = Src;
}

function ImMouseUp(Im, Src) {
    Im.src = Src;
}

function ImMouseOver(Im, Src) {
    Im.src = Src;
}

function AddItem(objListBox, strText, strValue) {
    var newOpt;
    if (!strValue) {
        strValue = "";
    }

    newOpt = new Option(strText, strValue);
    newOpt.id = strText;
    objListBox.options[objListBox.options.length] = newOpt;
}

function RemoveItem(objListBox) {
    var intIndex = GetSelectedIndex();
    if (intIndex != -1) {
        //ccheck if (maxcomp>0){
        //ccheck	if ((objListBox.options.length)>1){
        //ccheck	    objListBox.remove(intIndex);
        //ccheck		}else{
        //ccheck		alert('לא ניתן להסיר את כל המחשבים שברשותך עלך להשאיר לפחות אחד');
        //ccheck		}
        //ccheck	}else{
        objListBox.remove(intIndex);
        //ccheck	}
    }
}

function GetItemIndex(objListBox, strId) {
    for (var i = 0; i < objListBox.options.length; i++) {
        var strCurrentValueId = objListBox.options[i].id;
        if (strId == strCurrentValueId) {
            return i;
        }
    }
    return -1;
}

function GetSelectedIndex() {
    var words = document.getElementById('items');
    for (var i = 0; i < words.options.length; i++) {
        if (words.options[i].selected)
            return i;
    }

    return -1;
}

function OnTextboxKeyDown(e, field) {
    if (e.keyCode == 13) {//Enter
        DoAdd(type);
        field.focus();
        return false;
    }
}
function selectAll(selectBox, selectAll) {
    // have we been passed an ID
    if (typeof selectBox == "string") {
        selectBox = document.getElementById(selectBox);
    }
    // is the select box a multiple select box?
    if (selectBox.type == "select-multiple") {
        for (var i = 0; i < selectBox.options.length; i++) {
            selectBox.options[i].selected = selectAll;
        }
    }
}

function Mid(str, start, len) {
    // Make sure start and len are within proper bounds
    if (start < 0 || len < 0) return "";
    var iEnd, iLen = String(str).length;
    if (start + len > iLen)
        iEnd = iLen;
    else
        iEnd = start + len;
    return String(str).substring(start, iEnd);
}

function checkinput(txtinput, maxlen, chars, mode, act, notify) {
    var specialcharstxt = chars;
    var specialchars = specialcharstxt.split(" ");
    var m = ""
    var found = 0
    if (((txtinput.value.length) != 0)) {
        if (maxlen != '' && (txtinput.value.length) > maxlen) {
            if (act == "autochange") {
                txtinput.value = Mid(txtinput.value, 0, maxlen);
            }
            if (notify == 1) {
                alert('bad chars found');
            }

        }
        if (mode == "accept") {
            m = 0;
            for (var i = 0; i < txtinput.value.length; i++) {
                found = 0;
                for (var j = 0; j < specialchars.length; j++) {

                    if (Mid(txtinput.value, i, 1) != specialchars[j]) {
                        found = 1;
                    }
                }
                if (found == 0) {
                    if (act == "autochange") {
                        txtinput.value = txtinput.value.replace(Mid(txtinput.value, i, 1), '');
                    }
                    m = 1;
                }

            }

        } else {
            if (mode == "deny") {
                for (var i = 0; i < specialchars.length; i++) {
                    while ((txtinput.value.indexOf(specialchars[i])) != -1) {
                        if (act == "autochange") {
                            txtinput.value = txtinput.value.replace(specialchars[i], '');
                        }
                        m = 1;
                    }
                }
            }
        }
        if ((notify == 1) && (m == 1)) {
            alert('bad chars found');
        }
    }
}

function searchMethod(form) {
    var f = $(form);
    var qe = f.searWords.value;
    if (window.encodeURIComponent) qe = encodeURIComponent(qe);
    if (f.area)
        if (f.area.value == 2) {
        //		document.location="http://www.google.com/search?p=search_results&q="+qe;return false;
    }

    var pt = new String(document.location.hostname);
    var iq = pt.indexOf('?');

    if (iq != -1) pt = pt.substring(0, iq);
    if (f.action) if (f.action != "") pt = f.action;


    var ue = "/searchresults.asp?searWords=" + qe;
    if (f.search) ue += "&search=" + f.search.value;
    if (f.match) ue += "&match=" + f.match.value;

    f.action = ue
    f.submit()
}
function prepareForSending(form, hiddenfield) {
    var select = form.getElementsByTagName("select")[0];
    var options = select.options;
    var hiddenvalues = new Array();
    for (var i = 0; i < options.length; i++) {
        hiddenvalues.push(options[i].text);
    }
    hiddenfield.value = hiddenvalues.join(", ");

}

function prepare_add_change_B_Form() {
    var resultArray = new Array();
    var form = document.forms["add_change_B_form"];
    var formElements = form.elements;
    for (var i = 0; i < formElements.length; i++) {
        var currentElement = formElements[i];
        if (currentElement.type.toLowerCase() == "checkbox") {
            if (currentElement.checked) {
                resultArray.push(currentElement.value);
            }
        }
    }
    $("selectedapps").value = resultArray.join(",");
}

function changeChart(param) {

    var xmlobj = new Requester('/sys/BuildChart.asp' + param);
    var retVal = xmlobj.getData();
    eval(retVal)
}
function ajaxget(page, obj) {
    var xmlobj = new Requester(page);
    var retVal = xmlobj.getData();
    if (obj == null) {
        eval(retVal);
        //$("benzona").value = retVal 
        //alert(retVal);
    } else {
        $(obj).innerHTML = retVal;
        //eval(retVal);
    }

}
function addnewitem(group, item, item_id) {
    if ((item_id) != '' && (group) != '' && (item) != '') {
        //var xmlobj=new Requester('ajax.asp?purpose='+purpose+'&group='+$('group_id').value+'&item='+$('newitem_txt').value+'&item_id='+item_id);
        //if (xmlobj.getData()==1){
        //alert(self.frames[0].addRow)
        self.frames[0].addRow(group, item, item_id);
        // }
    }
}

function IsNumeric(sText) {
    var ValidChars = "0123456789";
    var IsNumber = true;
    var Char;


    for (i = 0; i < sText.length && IsNumber == true; i++) {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1) {
            IsNumber = false;
        }
    }
    return IsNumber;

}
function ChangeTimeBetweenSmsStatus() {
    if ($('sms').checked == true) {
        $('TimeBetweenSms').disabled = false;
    } else {
    $('TimeBetweenSms').disabled = true;
    }
}