﻿// constants to define the title of the alert and button text.
var ALERT_TITLE = "Green Benjamin";
var ALERT_BUTTON_TEXT = "Ok";
var ALERT_TEXT = "Welcome to Green Benjamin";
var ALERT_BUTTON_IMAGE = "../../images/gb_logo.png";
var ALERT_POSTBACK = "";
var ALERT_REDIRECTURL = "";
// over-ride the alert method only if this a newer browser.
// Older browser will see standard alerts
if (document.getElementById) {
    window.alert = function(txt) {
        createCustomAlert(txt);
    }
}

function createCustomAlert(txt) {
    // shortcut reference to the document object
    SetCustomAlert(txt);
    d = document;

    // if the modalContainer object already exists in the DOM, bail out.
    if (d.getElementById("modalContainer")) return;

    // create the modalContainer div as a child of the BODY element
    mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
    mObj.id = "modalContainer";
    // make sure its as tall as it needs to be to overlay all the content on the page
    mObj.style.height = document.documentElement.scrollHeight + "px";

    // create the DIV that will be the alert 
    alertObj = mObj.appendChild(d.createElement("div"));
    alertObj.id = "alertBox";
    // MSIE doesnt treat position:fixed correctly, so this compensates for positioning the alert
    if (d.all && !window.opera) alertObj.style.top = document.documentElement.scrollTop + "px";
    // center the alert box
    alertObj.style.left = (d.documentElement.scrollWidth - alertObj.offsetWidth) / 2 + "px";
    //alertObj.style.top = (d.documentElement.scrollHeight) + "px";
    alertObj.style.backgroundImage = 'url(' + ALERT_BUTTON_IMAGE + ')';

    // create an H1 element as the title bar
    h1 = alertObj.appendChild(d.createElement("h1"));
    h1.appendChild(d.createTextNode(ALERT_TITLE));

    // create a paragraph element to contain the txt argument
    msg = alertObj.appendChild(d.createElement("p"));
    msg.innerHTML = ALERT_TEXT;

    // create an anchor element to use as the confirmation button.
    btn = alertObj.appendChild(d.createElement("a"));
    btn.id = "closeBtn";
   // btn.runat = "Server";
    btn.appendChild(d.createTextNode(ALERT_BUTTON_TEXT));
    btn.href = "#";
    // set up the onclick event to remove the alert when the anchor is clicked
    btn.onclick = function() { removeCustomAlert(); return false; }


}

// removes the custom alert from the DOM
function removeCustomAlert() {
    document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer"));
    if (ALERT_POSTBACK == "postback") {
        if(ALERT_REDIRECTURL=="")
            __doPostBack('', '');
        else
            window.location = ALERT_REDIRECTURL; 
    }
}
function trimAll(sString) {
    while (sString.substring(0, 1) == ' ') {
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length - 1, sString.length) == ' ') {
        sString = sString.substring(0, sString.length - 1);
    }
    return sString;
}

function chkObject(theVal) {
    if (document.getElementById(theVal) != null) {
        return true;
    }
    else {
        return false;
    }
}


function SetCustomAlert(txt) {
    var arr = new Array();
    arr = txt.split("<^>");
    if (arr.length == 2) {
        ALERT_TEXT = arr[0];
        ALERT_TITLE = trimAll(arr[1]);
    }
    else if (arr.length == 3) {
        ALERT_TEXT = arr[0];
        ALERT_TITLE = trimAll(arr[1]);
        if (trimAll(arr[2].toLowerCase()) == "save") {
            ALERT_BUTTON_IMAGE = "../../images/Save.png";
        }
        else if (trimAll(arr[2].toLowerCase()) == "info") {
        ALERT_BUTTON_IMAGE = "../../images/Info.png";
    }
    else if (trimAll(arr[2].toLowerCase()) == "update") {
        ALERT_BUTTON_IMAGE = "../../images/Update.png";
    }
    else if (trimAll(arr[2].toLowerCase()) == "delete") {
        ALERT_BUTTON_IMAGE = "../../images/Delete.png";
    }
    else if (trimAll(arr[2].toLowerCase()) == "postback") {
    ALERT_BUTTON_IMAGE = "../../images/Info.png";
    ALERT_POSTBACK = "postback";
    ALERT_TITLE = "Info";
    }
        else if (trimAll(arr[2].toLowerCase()) == "warning") {
        ALERT_BUTTON_IMAGE = "../../images/Warning.png";
        }
        else if (trimAll(arr[2].toLowerCase()) == "error") {
        ALERT_BUTTON_IMAGE = "../../images/Error.png";
        }
    }
    else if (arr.length == 4) {
        ALERT_TEXT = arr[0];
        ALERT_TITLE = trimAll(arr[1]);
        if (trimAll(arr[2].toLowerCase()) == "save") {
            ALERT_BUTTON_IMAGE = "../../images/Save.png";
        }
        else if (trimAll(arr[2].toLowerCase()) == "info") {
            ALERT_BUTTON_IMAGE = "../../images/Info.png";
        }
        else if (trimAll(arr[2].toLowerCase()) == "update") {
            ALERT_BUTTON_IMAGE = "../../images/Update.png";
        }
        else if (trimAll(arr[2].toLowerCase()) == "delete") {
            ALERT_BUTTON_IMAGE = "../../images/Delete.png";
        }
        else if (trimAll(arr[2].toLowerCase()) == "postback") {
            ALERT_BUTTON_IMAGE = "../../images/Info.png";
            ALERT_POSTBACK = "postback";
            ALERT_REDIRECTURL = arr[3];
            ALERT_TITLE = "Info";
        }
        else if (trimAll(arr[2].toLowerCase()) == "warning") {
            ALERT_BUTTON_IMAGE = "../../images/Warning.png";
        }
        else if (trimAll(arr[2].toLowerCase()) == "error") {
            ALERT_BUTTON_IMAGE = "../../images/Error.png";
        }
    }
    else if (arr.length == 0) {
        ALERT_TEXT = txt;
    }
}

//function getheight() {
////var obj = this.parent;
////var xlocation = parseInt(obj.offsetLeft);
////var ylocation = parseInt(obj.offsetTop);
//document.getElementById("HiddenField1").value)=ylocation;
////}
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------------------------------------*/

// [ GLOBAL FUNCTION FOR XMLHTTP OBJECT -------------------------- [ START ]
function GetXmlHttpObject() {
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    }
    catch (e) {
        // Internet Explorer
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {
                alert("Your browser does not support AJAX!");
                return false;
            }
        }
    }
    return xmlHttp;
}

function Hitcount() {
    xmlHttpExternal1 = GetXmlHttpObject();
    xmlHttpExternal1.onreadystatechange = function() { stateLoadpage(); }
    now = new Date();
    var Curtm = now.getMilliseconds();
    xmlHttpExternal1.open("GET", "../AjaxSet.aspx?tm=" + Curtm, true);
        xmlHttpExternal1.send(null);
    }


function stateLoadpage() {
    if (xmlHttpExternal1.readyState == 4 || xmlHttpExternal1.readyState == 'complete') {
        var msg = xmlHttpExternal1.responseText;
    }
}

function imgdel() {
    xmlHttpExternal1 = GetXmlHttpObject();
    xmlHttpExternal1.onreadystatechange = function() { stateimgdelpage(); }
    now = new Date();
    var Curtm = now.getMilliseconds();
    xmlHttpExternal1.open("GET", "../../AjaxSet.aspx?img=atc&tm=" + Curtm, true);
    xmlHttpExternal1.send(null);
}


function stateimgdelpage() {
    if (xmlHttpExternal1.readyState == 4 || xmlHttpExternal1.readyState == 'complete') {
        var msg = xmlHttpExternal1.responseText;
    }
}
// ------------------------------------- [ SEND EMAIL ] --------------------------------- [ END ]


function postback() {
    __doPostBack('', '');
}
