//IDENTIFY BROWSER AND USE GET OBJECT
var isIE = true;
var isNS = false;
var brVer = 0;

if ( parseInt( navigator.appVersion) >=4 ) {
    if ( !document.all && document.getElementById){
        isNS = true;
        isIE = false;
        brVer = 6;
    }
    else
    if ( document.layers ){ 
        isNS = true;
        isIE = false;
        brVer = 4;
    }
    else
    if (document.all && document.getElementById) {
        isNS = false;
        isIE = true;
        brVer = 5;
    }
    else
    if (document.all && !document.getElementById) {
        isNS = false;
        isIE = true;
        brVer = 4;
    }
}

function getIdObj( id ) {
    var obj;
    if (isNS && brVer==4){
        obj = document.layers[id];
    }
    else 
    if (isIE && brVer==4) {
        obj = document.all[id];
    }
    else 
    if (brVer>4) {
        obj = document.getElementById(id);
    }
    return obj;
}

function getIdStyleObj( id ) {
    var obj = getIdObj(id);
    if ( isIE || brVer>4 )
        obj = obj.style;
    return obj;
}

//This code will search for the parent containing the status window and then call the progressbar function
function setProgressBar( state ) {
    var iCount = 0;
    var par = window.parent;
    while ( iCount<20 ) {
        if ( par==null )
            return;
        if ( par.toolbar!=null ) {
        	if (par.toolbar.progresbar!=null) 
            	par.toolbar.progresbar( state );
            else
            if (par.toolbar.progressbar!=null) 
            	par.toolbar.progressbar( state );
            return;
        }
        par = par.parent;
        iCount++;
    }
}

//This code will search for the parent containing the status window and then call the setTitle function
function setTitle( stitle ) {
    var iCount = 0;
    var par = parent;
    while ( iCount<20 ) {
        if ( par==null )
            return;
        if ( par.header!=null ) {
            par.header.setTitle( stitle );
            return;
        }
        par = par.parent;
        iCount++;
    }
}

function right(e) {
//    if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2)) {
//        alert("Sorry, you do not have permission to right click.");
//        return false;
//    }
//    else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) {
//        alert("Sorry, you do not have permission to right click.");
//        return false;
//    }
//    return true;
}

//This will call the doHandleFKey method if it exists in thje html document
//F1-112,F2-113,F3-114...........
//The method must return true if the event was handled
var doHandleKey;
var doHandleFKey;
function doKeyDown(evt){
	evt = (evt) ? evt : ((event) ? event : null);
	if (evt.keyCode>=112 && evt.keyCode<=123){
		var sKey = 'F'+(evt.keyCode-111);
		if ( doHandleFKey ) {
			if ( doHandleFKey( sKey ) ){
				return doCancelKey(evt);
			}
			return true;
		}
	}
	if ( doHandleKey ) {
		if ( doHandleKey( evt ) ){
			return doCancelKey(evt);
		}
	}
}

function doCancelKey(evt) {
    if (evt.preventDefault) {
        evt.preventDefault();
        evt.returnValue  = false;
        evt.cancel = true;
        evt.keyCode = 0;
        return false;
    }
    else {
        evt.keyCode = 0;
        evt.returnValue = false;
    }
}

function doinit(){
    document.onmousedown=right;
    document.onkeydown=doKeyDown;
    if (document.layers) {
    	window.captureEvents(Event.MOUSEDOWN);
    	window.captureEvents(Event.KEYPRESSED);
    }
    window.onmousedown=right;
    document.onkeydown=doKeyDown;
}

doinit();

function doPopup( sMessage, type ) {
    var sColor = "#808080";
    if ( type=='E' )
        sColor = "#FF0000";
    var newWindow = window.open('','NoraPopUp','width=300,height=100,resizable=yes,scrollbars=auto,toolbar=no,dependent=yes,directories=no,menubar=no,location=no,status=no');
    newWindow.document.write( "<p align='center'><b><font face='Arial' color='"+sColor+"'>"+sMessage+"</font></b></p>" );
    newWindow.document.close();
    newWindow.focus();
}

function doPrint(){
	this.focus();
	window.print();
}

function doScroll(){
	var scrollTop = document.body.scrollTop;
	var posType;
	if ( scrollTop < 20 ) {
             scrollTop = -100;
	}
	document.all["headrow"].style.top = scrollTop;
}

function fixObjNum ( obj ) {
    obj.value = fixNum( obj.value );
 }

function fixNum( sInVal ) {
    var cChar;  
    var newStr = "";
    var testStr = ""+sInVal;
    var sLen = testStr.length;
    var bEFound = 0;
    var eVal = "";
    for ( var i=0; i<sLen; i++ ) {       
        cChar = testStr.charAt(i);
        if ( bEFound==0 ) {
            if ( cChar=='E' ) {
                bEFound = 1;
            }
            else
            if ( i==0 && cChar=='-' ) {
                newStr = "-";
            }
            else
            if ( cChar=='.' || (cChar>='0' && cChar<='9') ) {
                newStr += cChar;
            }  
        }
        else {
            if ( cChar=='.' || (cChar>='0' && cChar<='9') ) {
                eVal += cChar;
            }
        }
    }
    if ( newStr.length == 0 ) {
        return "0";
    }
    
    if ( bEFound==1 )
        return ""+(newStr * Math.pow(10, eVal));
    else
        return newStr;
}   
 
function fixPrecision( sInVal, precision ) {
    sInVal = fixNum( sInVal );
    var index = sInVal.indexOf(".");
    var cRoundIndicator = "0";
    var cRoundChar = 0;
    if ( index==-1 ) {
    	if ( precision==0 )
    		return sInVal;
    	
    	index = sInVal.length;
    	sInVal += '.';
    }
    else
    if ( precision==0 ){
    	return sInVal.substring(0,index);
    }

    {
        if ( index<sInVal.length-precision ) {
            cRoundChar = sInVal.charAt(index+precision);
            cRoundIndicator = sInVal.charAt(index+precision+1);
            if ( cRoundIndicator>='5' ) cRoundChar ++;
            sInVal = sInVal.substring(0,index+precision)+cRoundChar;
        }
        else {
        	var iPrecShort = precision - (sInVal.length-index-1);
        	while ( iPrecShort>0 ) {
        		sInVal += '0';
        		iPrecShort--;
        	}
        }
        return sInVal;
    }
}
function roundNumber(number, digits) {
	var roundedNumber = (parseFloat(number)).toFixed(digits);
	//var roundedNumber = toFixed(number, digits);
    //var multiple = Math.pow(10, digits);
    //var roundedNumber = Math.round(number * multiple) / multiple;
    return roundedNumber;
}
function doStyleOn(obj,sType){ 
    if (sType=="textarea"){
        obj.className= "normTArea";
    }
	if (sType=="text"){
        obj.className= "normText";   
    }
}   

function doStyleOff(obj,sType){  
    if (sType=="textarea"){
        obj.className= "smallTArea";
    }
	if (sType=="text"){
        obj.className= "smallText";    
    }  
}

function doSwitchClass(obj,sClass){  
    obj.className= sClass;
}

/**********************************************************************
  BEGIN MODAL DIALOG CODE (can also be loaded as external .js file)
***********************************************************************/
// One object tracks the current modal dialog opened from this window.
var dialogWin = new Object()

// Generate a modal dialog.
// Parameters:
//    url -- URL of the page/frameset to be loaded into dialog
//    width -- pixel width of the dialog window
//    height -- pixel height of the dialog window
//    returnFunc -- reference to the function (on this page)
//                  that is to act on the data returned from the dialog
//    args -- [optional] any data you need to pass to the dialog
function openDialog(url, width, height, returnFunc, args) {
	if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed)) {
		// Initialize properties of the modal dialog object.
		dialogWin.returnFunc = returnFunc
		dialogWin.returnedValue = ""
		dialogWin.args = args
		dialogWin.url = url
		dialogWin.width = width
		dialogWin.height = height
		// Keep name unique so Navigator doesn't overwrite an existing dialog.
		dialogWin.name = (new Date()).getSeconds().toString()
		// Assemble window attributes and try to center the dialog.
		if ( isNS && brVer==4 ) {
			// Center on the main window.
			dialogWin.left = window.screenX + 
			   ((window.outerWidth - dialogWin.width) / 2)
			dialogWin.top = window.screenY + 
			   ((window.outerHeight - dialogWin.height) / 2)
			var attr = "screenX=" + dialogWin.left + 
			   ",screenY=" + dialogWin.top + ",resizable=no,width=" + 
			   dialogWin.width + ",height=" + dialogWin.height
		} else {
			// The best we can do is center in screen.
			dialogWin.left = (screen.width - dialogWin.width) / 2
			dialogWin.top = (screen.height - dialogWin.height) / 2
			var attr = "left=" + dialogWin.left + ",top=" + 
			   dialogWin.top + ",resizable=no,width=" + dialogWin.width + 
			   ",height=" + dialogWin.height
		}
		
		// Generate the dialog and make sure it has focus.
		dialogWin.win=window.open(dialogWin.url, dialogWin.name, attr)
		dialogWin.win.focus()
	} else {
		dialogWin.win.focus()
	}
}

// Event handler to inhibit Navigator form element 
// and IE link activity when dialog window is active.
function deadend() {
	if (dialogWin.win && !dialogWin.win.closed) {
		dialogWin.win.focus()
		return false
	}
}

// Since links in IE4 cannot be disabled, preserve 
// IE link onclick event handlers while they're "disabled."
// Restore when re-enabling the main window.
var IELinkClicks

// Disable form elements and links in all frames for IE.
function disableForms() {
	IELinkClicks = new Array()
	for (var h = 0; h < frames.length; h++) {
		for (var i = 0; i < frames[h].document.forms.length; i++) {
			for (var j = 0; j < frames[h].document.forms[i].elements.length; j++) {
				frames[h].document.forms[i].elements[j].disabled = true
			}
		}
		IELinkClicks[h] = new Array()
		for (i = 0; i < frames[h].document.links.length; i++) {
			IELinkClicks[h][i] = frames[h].document.links[i].onclick
			frames[h].document.links[i].onclick = deadend
		}
	}
}

// Restore IE form elements and links to normal behavior.
function enableForms() {
	for (var h = 0; h < frames.length; h++) {
		for (var i = 0; i < frames[h].document.forms.length; i++) {
			for (var j = 0; j < frames[h].document.forms[i].elements.length; j++) {
				frames[h].document.forms[i].elements[j].disabled = false
			}
		}
		for (i = 0; i < frames[h].document.links.length; i++) {
			frames[h].document.links[i].onclick = IELinkClicks[h][i]
		}
	}
}

// Grab all Navigator events that might get through to form
// elements while dialog is open. For IE, disable form elements.
function blockEvents() {
	if ( isNS && brVer==4 ) {
		window.captureEvents(Event.CLICK | Event.MOUSEDOWN | Event.MOUSEUP | Event.FOCUS)
		window.onclick = deadend
	} else {
		disableForms()
	}
	window.onfocus = checkModal
}
// As dialog closes, restore the main window's original
// event mechanisms.
function unblockEvents() {
	if ( isNS && brVer==4 ) {
		window.releaseEvents(Event.CLICK | Event.MOUSEDOWN | Event.MOUSEUP | Event.FOCUS)
		window.onclick = null
		window.onfocus = null
	} else {
		enableForms()
	}
}

// Invoked by onFocus event handler of EVERY frame,
// return focus to dialog window if it's open.
function checkModal() {
	if (dialogWin.win && !dialogWin.win.closed) {
		dialogWin.win.focus()	
	}
}
