﻿//<![CDATA[
/*
Public.js Description
AlDimna Software, Inc.
3/15/2004 6:23:20 AM
By Faisal Alazemi 
Description :
Public javascript file will hold the public javascript functions 
that could be used between private scripts.
*/

//addEvent_P(window,"load",StartLoading_P);     
addEvent_P(window, "unload", StartLoading_P);
//addEvent_P(window, "load", Resize_P);

/*this function is for onload events
you can call this function to call any other function on load the page
Esample: addEvent(window,"load",GetList);
*/
function addEvent_P(o, e, f) {
    if (o.addEventListener) { o.addEventListener(e, f, true); return true; }
    else if (o.attachEvent) { return o.attachEvent("on" + e, f); }
    else { return false; }
}

/*this function will change the class of any element and 
will take care of the different between IE and FireFox
*/
function ChangeClass_P(Obj, Class) {
    try {

        if (navigator.appName == "Microsoft Internet Explorer") {
            Obj.setAttribute("className", Class);
            Obj.setAttribute("class", Class);
        }
        else { Obj.setAttribute("class", Class); }
    } catch (e) { ErrorCenter_MH("Public.js File ChangeClass_P", e); }
}

/*this function will Get the class name of any element and 
will take care of the different between IE and FireFox
*/
function GetClassName_P(Obj) {
    try {
        var ClassName_P;
        if (navigator.appName == "Microsoft Internet Explorer") {
            ClassName_P = Obj.getAttribute("className");
            if (ClassName_P == null) { ClassName_P = Obj.getAttribute("class"); }
        }
        else { ClassName_P = Obj.getAttribute("class"); }
        return ClassName_P;
    } catch (e) { ErrorCenter_MH("Public.js File GetClassName_P", e); }
}

/*this function will Change  the Langauge */
function ChangeLangauge_P() {
    try {
        MessageCenter_MH("تغير اللغلة الي العربية", "ناسف لعدم وجود اللغة العربية في الموقع ولكن العمل جاري لوضع اللغة العربية وجعلها اللغة الاولي للموقع.", "Info");
    } catch (e) { ErrorCenter_MH("Public.js File ChangeLangauge_P", e); }
}

/*this function ContactUS */
function ContactUS_P() {
    try {
        //StartLoading_P();

        var WebService = load_JS_CSS_File_P("JavaScripts/WebService/WebService.js");

        WebService[CallJS_P()] = function () {
            ReturnObj = document.getElementById('Container');
            StrQuery = "http://www.aldimna.com/Interfaces/WS/WSRequests.aldimna?ws=ContactUS";
            SendRequest();

        };


        //Contents    
    } catch (e) { ErrorCenter_MH("Public.js File ContactUS", e); }
}


/* this function will get the list of sub divation of the page you are in*/
function LoadSubDivisionsList_P(Obj) {
    try {
        load_JS_CSS_File_P("JavaScripts/SubDivisionsList/SubDivisionsList.js");
    } catch (e) { ErrorCenter_MH("Public.js File LoadSubDivisionsList_P", e); }
}
/* this function will get the list of Parent Navigation of the page you are in*/
function LoadParentNavigation_P() {
    try {
        load_JS_CSS_File_P("JavaScripts/ParentNavigation/ParentNavigation.js");
    } catch (e) { ErrorCenter_MH("Public.js File LoadParentNavigation_P", e); }
}

/* this function to resizy the content dive to macth the navigation div*/
function Resize_P() {
    try {
        /*
        if (navigator.appName == "Microsoft Internet Explorer") {

        var TreeViewTagDiv = document.getElementById('TreeViewTag');
        var MainNavigationDiv = document.getElementById('MainNavigation');
        var NavigationDiv = document.getElementById('Navigation');
            
        var ResultDiv = document.createElement("div");
        ResultDiv.innerHTML = "<br /><br /><br />";
        ResultDiv.innerHTML += "<h1>NavigationDiv offsetHeight:" + NavigationDiv.offsetHeight + "</h1>";
        ResultDiv.innerHTML += "<h1>NavigationDiv clientHeight:" + NavigationDiv.clientHeight + "</h1>";
        ResultDiv.innerHTML += "<h1>NavigationDiv height:" + NavigationDiv.style.height + "</h1>";
        ResultDiv.innerHTML += "<h1>MainNavigationDiv offsetHeight:" + MainNavigationDiv.offsetHeight + "</h1>";
        ResultDiv.innerHTML += "<h1>MainNavigationDiv clientHeight:" + MainNavigationDiv.clientHeight + "</h1>";
        ResultDiv.innerHTML += "<h1>MainNavigationDiv height:" + MainNavigationDiv.style.height + "</h1>";
        ResultDiv.innerHTML += "<h1>TreeViewTagDiv offsetHeight:" + TreeViewTagDiv.offsetHeight + "</h1>";
        ResultDiv.innerHTML += "<h1>TreeViewTagDiv clientHeight:" + TreeViewTagDiv.clientHeight + "</h1>";
        ResultDiv.innerHTML += "<h1>TreeViewTagDiv height:" + TreeViewTagDiv.style.height + "</h1>";
        TreeViewTagDiv.style.height = MainNavigationDiv.clientHeight + "px";
        document.body.insertBefore(ResultDiv, document.body.firstChild);
        }
        else { }
        */
    } catch (e) { ErrorCenter_MH("Public.js File Resize_P", e); }
}

/* load javascript or CSS file at run time*/
function load_JS_CSS_File_P(FileName) {
    try {

        var FileType = FileName.substring(FileName.lastIndexOf(".") + 1, FileName.length);

        if (FileType == "js") { //if filename is a external JavaScript file
            var FileRef = document.createElement('script');
            FileRef.setAttribute("type", "text/javascript");
            //FileRef.setAttribute("src", "http://ws" + document.domain + "/Interfaces/" + FileName); //"../../" + FileName);
            if (FileName.indexOf("http://") == -1) {
                FileRef.setAttribute("src", "http://ws.aldimna.com/Interfaces/" + FileName); //"../../" + FileName);
            }
            else { FileRef.setAttribute("src", FileName); }
        }
        else if (FileType == "css") { //if filename is an external CSS file

            var FileRef = document.createElement("link");
            FileRef.setAttribute("rel", "stylesheet");
            FileRef.setAttribute("type", "text/css");
            FileRef.setAttribute("href", "http://" + document.domain + "/" + FileName);
        }

        if (typeof FileRef != "undefined") {
            document.getElementsByTagName("head")[0].appendChild(FileRef);
            return FileRef;
        }
        else { ErrorCenter_MH("load_JS_CSS_File_P", "Only CSS and JS files."); }
    }
    catch (e) { ErrorCenter_MH("Public.js File load_JS_CSS_File_P", e); }
}
/* since IE and FF dont work the same way calling a function after loaded is not the same
IE = onreadystatechange
FF = onload
*/
function CallJS_P() {
    try {
        if (navigator.appName == "Microsoft Internet Explorer") { return "onreadystatechange"; }
        else { return "onload"; }
    }
    catch (e) { ErrorCenter_MH("Public.js File CallJS_P", e); }
}

/* This to show a looding div*/
function StartLoading_P() {
    try {
        GrayOut(true);
        Loading();
    }
    catch (e) { ErrorCenter_MH("Public.js File StartLoading_P", e); }
}

function EndLoading_P() {
    try {
        document.body.removeChild(document.getElementById("LoadingDiv"));
        document.body.removeChild(document.getElementById("GrayOutScreenObject"));
        document.body.style.overflow = 'auto';
    }
    catch (e) { ErrorCenter_MH("Public.js File CallJS_P", e); }
}

/* This to GrayOut page*/
function GrayOut(status, options) {
    try {

        var GrayOutDiv = document.getElementById('GrayOutScreenObject');

        if (!GrayOutDiv) {
            var DivElm = document.createElement('div');
            DivElm.style.position = 'absolute';
            DivElm.style.top = '0px';
            DivElm.style.left = '0px';
            DivElm.style.overflow = 'hidden';
            DivElm.style.display = 'none';
            DivElm.id = 'GrayOutScreenObject';
            document.body.insertBefore(DivElm, document.body.firstChild);
            GrayOutDiv = document.getElementById('GrayOutScreenObject');
        }

        GrayOutOptions(status, options, GrayOutDiv);
    } catch (e) { ErrorCenter_MH("GrayOut", e); }
}

function GrayOutOptions(status, options, GrayOutDiv) {
    try {
        var options = options || {};
        var zindex = options.zindex || 50;
        var opacity = options.opacity || 70;
        var opaque = (opacity / 100);
        var bgcolor = options.bgcolor || '#000000';

        if (status) {
            var pageWidth = '100%';
            var pageHeight = '100%';
            //opera Netscape 6 Netscape 4x Mozilla 
            if (window.innerWidth || window.innerHeight) {
                pageWidth = window.innerWidth;
                pageHeight = window.innerHeight;
            }
            //IE Mozilla 
            if (document.body.clientWidth || document.body.clientHeight) {
                pageWidth = document.body.clientWidth;
                pageHeight = document.body.clientHeight;
            }
            GrayOutDiv.style.opacity = opaque;
            GrayOutDiv.style.MozOpacity = opaque;
            GrayOutDiv.style.filter = 'alpha(opacity=' + opacity + ')';
            GrayOutDiv.style.zIndex = zindex;
            GrayOutDiv.style.backgroundColor = bgcolor;
            GrayOutDiv.style.overflow = 'hidden';
            document.body.style.overflow = 'hidden';
            GrayOutDiv.style.width = '100%';
            GrayOutDiv.style.height = '100%';
            GrayOutDiv.style.display = 'block';
            window.scrollTo(0, 0);

        } else { GrayOutDiv.style.display = 'none'; document.body.removeChild(document.getElementById("LoadingDiv")); }


    } catch (e) { ErrorCenter_MH("GrayOutOptions", e); }
}
/* This to GrayOut page*/

function Loading() {
    try {
        var LoadingDiv = document.createElement("div");

        ChangeClass_P(LoadingDiv, "Loading");
        LoadingDiv.setAttribute("id", "LoadingDiv");
        // LoadingDiv.innerHTML= "<h1>Please wait....</h1>";
        document.body.insertBefore(LoadingDiv, document.body.firstChild);
        window.scrollTo(0, 0);
    } catch (e) { ErrorCenter_MH("Loading.js File Loading", e); }
}

//]]>   
