//
// Cross Browsers JS Model
//
var ObjectsType;

if(document.getElementById) ObjectsType="DOM2";
else if(document.all) ObjectsType="IEDOM1"
else if(document.layers) ObjectsType="NCDOM1";

function GetStyleById(IdName){
    switch(ObjectsType){
        case "DOM2":
            if (GetObjectById(IdName)) {
                return document.getElementById(IdName).style;
			}
            break;
        case "IEDOM1":
			if (GetObjectById(IdName)) {
                return document.all[IdName].style;
			}
            break;
        case "NCDOM1":
            return document.layers[IdName];
    }
}

function GetObjectById(IdName, FormName){
    switch(ObjectsType){
        case "DOM2":
            if (FormName) {
                return eval('document.getElementById("'+FormName+'").'+IdName) ;
            } else
                return document.getElementById(IdName);
        case "IEDOM1":
            if (FormName)
                return eval('document.all["'+FormName+'"].'+IdName) ;
            else
                return document.all[IdName];
        case "NCDOM1":
            if (FormName)
                return eval('document.layers["'+FormName+'"].'+IdName) ;
            else
                return document.layers[IdName];
    }
}

function GetObjectByName(IdName, FormName){
    switch(ObjectsType) {
        case "DOM2":
            if (FormName) {
                return eval('document.getElementsByName("'+FormName+'").'+IdName) ;
            } else
                return document.getElementsByName(IdName);
        case "IEDOM1":
            if (FormName)
                return eval('document.all["'+FormName+'"].'+IdName) ;
            else
                return document.all[IdName];
        case "NCDOM1":
            if (FormName)
                return eval('document.layers["'+FormName+'"].'+IdName) ;
            else
                return document.layers[IdName];
    }
}

function MyNewWindow(mypage,myname,w,h,scroll,ret) 
{
	// showModalDialog for IE
 	// MyNewWindow() - centering new window if user's screen resolution > 800x600
 	if (h<=0) { h = 480; }
 	if (w<=0) { w = 640; }
 	var scW = screen.availWidth ? screen.availWidth : screen.width;
	var scH = screen.availHeight ? screen.availHeight : screen.height;
	var winl = (scW-w)/2; 
	var wint = (scH-h)/2;
	
  	if (!screen) {
	    winl = 0; wint = 0;
	}
  	var settings  ='height='+h+',';
      	settings +='width='+w+',';
      	settings +='top='+wint+',';
      	settings +='left='+winl+',';
      	settings +='status=0,';
      	settings +='scrollbars='+scroll+',';
      	settings +='resizable=yes';
  	win=window.open(mypage,myname,settings);
  	if( !window.opera ) { win.moveTo(winl,wint); }
  	if (parseInt(navigator.appVersion) >= 4) {win.window.focus();}
  	if (ret) { return win ; }
}

function _showPopup(modal,url,value,properties,winname,alignment) {
    if (modal && !properties) properties = "dialogWidth=230px;dialogHeight=155px;status=0;scroll=0;help=0" ;
    if (modal && typeof window.showModalDialog != 'undefined') {
        var thevalues = value.split(/,/);
        return window.showModalDialog(url, thevalues, properties);
    }

    if (!properties) {
        var w = 640 ;
        var h = 480 ;
        var scW = screen.availWidth ? screen.availWidth : screen.width;
        var scH = screen.availHeight ? screen.availHeight : screen.height;
        var winl = (scW-w)/2;
        var wint = (scH-h)/2;
        properties = 'width='+w+',height='+h+',status=0,scrollbars=0,top='+wint+',left='+winl ;
    }
    if (alignment) {
        switch(alignment) {
            case "center":
                var w = properties.replace(/^.*width=(\d+),.*$/i, '$1') ;
                var h = properties.replace(/^.*height=(\d+),.*$/i, '$1') ;
                var scW = screen.availWidth ? screen.availWidth : screen.width;
                var scH = screen.availHeight ? screen.availHeight : screen.height;
                var winl = (scW-w)/2;
                var wint = (scH-h)/2;
                properties = properties + ',top='+wint+',left='+winl ;
                break;
        }
    }
    var win=window.open(url,winname?'POPUP'+winname:'_BLANK',properties);    
    if (!win) {
        alert('We have detected that you are using popup blocking software. Please turn off popup blocking for this site!');
    }
    //win.resizeTo(w,h);
  	if (parseInt(navigator.appVersion) >= 4) {win.window.focus();}
    else win.focus();
    return win ;
}

function _selectall(tableName, state) {
    // applicable to table with rows and cols only, no nested tables
    var tbl = GetObjectById(tableName) ;
    if (!tbl) return ;
    for (i = 0; i < tbl.rows.length; i++) {
        for (j = 0; j < tbl.rows[i].cells.length; j++) {
            for (k =0; k < tbl.rows[i].cells[j].childNodes.length; k++) {
                cb = tbl.rows[i].cells[j].childNodes[k];
                if (!cb || cb.type != "checkbox") continue;
                if (cb.disabled) 
                    cb.checked = false;
                else
                    cb.checked = state ;
            }
        }
    }
}

function xmlGet(IDTag, xmlURL, postAction) {
    var Area = GetObjectById(IDTag);
    //Area.innerHTML = 'Retrieving in progress, please wait...';
    var xmlHttp = XmlHttp.create();
    xmlHttp.open('GET', xmlURL+'&r='+Math.random(), true);
    xmlHttp.onreadystatechange = function()
    {
        if (xmlHttp.readyState == 4) {
            Area.innerHTML = xmlHttp.responseText ;
            if (postAction) eval(postAction);
        }
    }
    xmlHttp.send(null);
}

function doOrdering(InputName, type) {
    var oSelect = document.getElementById(InputName);
    var swap;

    if (oSelect.options.length==0) return;
    if (type == 1 && !oSelect.options[0].selected) {
        for (var i = 0; i < oSelect.options.length; i++) {
            if (oSelect.options[i].selected) {
                swap = oSelect.options[i-1];
                if (!swap.selected) oSelect.options[i].swapNode(swap);
            }
        }
    } else if (type == 2 && !oSelect.options[oSelect.options.length-1].selected) {
        for (var i = oSelect.options.length - 1; i >= 0; i--) {
            if (oSelect.options[i].selected) {
                swap = oSelect.options[i+1];
                if (!swap.selected) oSelect.options[i].swapNode(swap);
            }
        }
    }
}
