﻿ var browser = {
                isIE: navigator.appName == "Microsoft Internet Explorer" ? true : false,
                isOpera: navigator.appName == "Opera" ? true : false,
                isFF: !document.all && document.getElementById && !this.isOpera
            }
            
//setTimeout('hookEvent(window, "load", setClientSize);', 50);
//setTimeout('hookEvent(window, "resize", setClientSize);', 50);            

function $(documentID)
{    
    if (document.all)//ie4
    {
        return document.all[documentID];
    }
    else if(document.getElementById){//isIE6
        return document.getElementById(documentID);
    }
    else if (document.layers){//isNS4
        return document.layers[documentID];
    }
    else if (document.getElementById && !document.all){//isNS6
        return document.getElementById(documentID);
    }
}

function CheckNumericValues(evt)
{
    evt = (null == evt) ? event : evt;
	var code = evt.keyCode;
	if(code == 0)
	    code = evt.charCode;
	if((code >= '48' && code <= '57') || code == '8' || code == '46') //8-backspace, 46-delete
		return true;
	else
		return false;
}

function addEvent(target, functionref, tasktype){ //assign a function to execute to an event handler (ie: onunload)
	var tasktype=(window.addEventListener)? tasktype : "on"+tasktype
	if (target.addEventListener)
		target.addEventListener(tasktype, functionref, false)
	else if (target.attachEvent)
		target.attachEvent(tasktype, functionref)
}

function AddEndRequest(fn) {    
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(fn);
}

function RemoveEndRequest(fn) {
    Sys.WebForms.PageRequestManager.getInstance().remove_endRequest(fn);
}

function ModalFormSelfClose(timeoutScript)
{
    var frameList;
    if(browser.isIE)
        frameList = window.parent.document.frames;
    else
        frameList = window.parent.frames;    
    var fId;
    for(var i=0; i<frameList.length;i++ )
    {
        if(window.location.href == frameList[i].frameElement.src)
        {
            fId = frameList[i].frameElement.id;
            break;
        }
    }
    if(timeoutScript)
        setTimeout("window.parent." + timeoutScript, 0);
    window.parent.ModalFormHide(fId);    
}

function openPopup(url, name)
{
var settings = new popupSettings().getSettings(requestType.toUpperCase());             
        window.open(url, requestType,
            "height=" + settings.height +
            ",width=" + settings.width +
            ",menubar=" + settings.menubar +
            ",toolbar=" + settings.toolbar +
            ",scrollbars=" + settings.scrollbars +
            ",resizable=" + settings.resizable +
            ",top=" + settings.top +
            ",left=" + settings.left);    
    window.open(url, name, "height=550;width=780;scroll");
}

var popup = {
    width: 780,
    height: 550,
    location: 0,
    scroolbars: 1,
    menubar: 0,
    toolbar: 0,
    status: 1,
    left: 0,
    top: 0, 
    resizable: 0,
          
    open: function(url, name)
    {
        this._init(name);
        window.open(url, name,
            "height=" + this.height +
            ",width=" + this.width +
            ",menubar=" + this.menubar +
            ",toolbar=" + this.toolbar +
            ",scrollbars=" + this.scrollbars +
            ",resizable=" + this.resizable +
            ",top=" + this.top +
            ",left=" + this.left);   
    },
    _init: function(name)
    {
        switch(name)
        {
            default:
                this._default();
                break;
        }   
    },
    _default: function()
    {
        this.width = 780;
        this.height = 550;
        this.location = 0;
        this.scroolbars = 1;
        this.menubar = 0;
        this.toolbar = 0;
        this.status = 1;
        this.left = 0;
        this.top = 0;
        this.resizable = 0;
    }    
}

//function setClientSize()
//{
//    if(browser.isFF)
//    {
//        var frm = document.getElementsByTagName("form")[0];
//        frm.style.height = getClientSize().h;
//        document.body.style.height = getClientSize().h;
//        alert(getClientSize().h);
//    }
//}

//function getClientSize() {
//    var myWidth = 0, myHeight = 0;
//    if (typeof (window.innerWidth) == 'number') {
//        //Non-IE
//        myWidth = window.innerWidth;
//        myHeight = window.innerHeight;
//    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
//        //IE 6+ in 'standards compliant mode'
//        myWidth = document.documentElement.clientWidth;
//        myHeight = document.documentElement.clientHeight;
//    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
//        //IE 4 compatible
//        myWidth = document.body.clientWidth;
//        myHeight = document.body.clientHeight;
//    }
//    return { w: myWidth, h: myHeight };
//}

//function hookEvent(element, eventName, callback) {
//    if (typeof (element) == "string")
//        element = $(element);
//    if (element == null)
//        return;
//    if (element.addEventListener)
//        element.addEventListener(eventName, callback, false);
//    else if (element.attachEvent)
//        element.attachEvent("on" + eventName, callback);
//}

//function unhookEvent(element, eventName, callback) {
//    if (typeof (element) == "string")
//        element = $(element);
//    if (element == null)
//        return;
//    if (element.removeEventListener)
//        element.removeEventListener(eventName, callback, false);
//    else if (element.detachEvent)
//        element.detachEvent("on" + eventName, callback);
//}



