//////////////////////////////////////////////////////////
//// 
//////////////////////////////////////////////////////////
function includeJSFile(fileURL){ 
    var newScript = document.createElement('script'); 
    newScript.type = "text/javascript"; 
    newScript.src = fileURL; 
    document.getElementsByTagName('head')[0].appendChild(newScript);
}

//////////////////////////////////////////////////////////
//// 
//////////////////////////////////////////////////////////
function trimleft(str, n){
    if (n <= 0)
	return "";
    else if (n > String(str).length)
	return str;
    else
	return String(str).substring(0,n);
}

//////////////////////////////////////////////////////////
//// 
//////////////////////////////////////////////////////////
function trimright(str, n){
    if (n <= 0)
	return "";
    else if (n > String(str).length)
	return str;
    else {
	var iLen = String(str).length;
	return String(str).substring(iLen, iLen - n);
    }
}

//////////////////////////////////////////////////////////
//// 
//////////////////////////////////////////////////////////
function FocusToFirstControl()
{
    var bFound = false;  

    //for each form
    for (f=0; f < document.forms.length; f++) { 
	//for each element in each form
	for(i=0; i < document.forms[f].length; i++) { 
	    //if it's not a hidden element
	    if (document.forms[f][i].type != "hidden") { 
		//and it's not disabled
		if (document.forms[f][i].disabled != true) {
		    try {
			//set the focus to it
			document.forms[f][i].focus();
			var bFound = true;
		    }
		    catch(er) {
		    }
		}
	    }
	    //if found in this element, stop looking
	    if (bFound == true)
		break;
	}
	//if found in this form, stop looking
	if (bFound == true)
	    break;
    }
}

//////////////////////////////////////////////////////////
// FocusToFirstControl();
//////////////////////////////////////////////////////////
function HideMe (id1,id2) {
    //HIDE NAVICATOR
    if (document.getElementById('RCTRL0')) {
	document.getElementById('RCTRL' + id1).style.display='none';
	document.getElementById('RCTRL' + id2).style.display='block';
    }

    if ((id1 == 1) || (id1 == 3)) {
	timingex();
    }
}

//////////////////////////////////////////////////////////
//// 
//////////////////////////////////////////////////////////
function timingex () {
    setTimeout("HideMe(1,0);",12000);
}

//////////////////////////////////////////////////////////
// HIDE NAVIGATOR
//////////////////////////////////////////////////////////
timingex();
function TOPHideLHS () {
    alert(window.top.getElementById('LHS'));
}

//////////////////////////////////////////////////////////
// FORCE ACTION 
//////////////////////////////////////////////////////////
function gotoURL(newUrl)
{
    location.href=newUrl;
}

//////////////////////////////////////////////////////////////
// Get an XMLHttpRequest object
//////////////////////////////////////////////////////////////
function GetHttpRequest() {
    if (window.XMLHttpRequest) {
	return new XMLHttpRequest();
    } else if (window.ActiveXObject) {
	return new ActiveXObject('Microsoft.XMLHTTP');
    } else {
	return null;
    }
}

//////////////////////////////////////////////////////////////
// Make an asynchronous request
//////////////////////////////////////////////////////////////
function HttpRequest(url, payload, callback) {
    var hr = GetHttpRequest();
    // Send the request
    if (hr) {
	hr.onreadystatechange = function () {
	    if (hr.readyState == 4) {
		callback(hr);
	    }
	};
	hr.open((payload) ? "POST" : "GET", url, true);
	hr.send(payload);
    }
}

//////////////////////////////////////////////////////////////
// Make a synchronous request
//////////////////////////////////////////////////////////////
function SyncHttpRequest(url, payload) {
    var hr = GetHttpRequest();
    // Send the request
    if (hr) {
	hr.open((payload) ? "POST" : "GET", url, false);
	hr.send(payload);
	return hr;
    }
}

//////////////////////////////////////////////////////////////
/////
//////////////////////////////////////////////////////////////
function LoadJSFile(file, toString) {
    if (toString) {
	try {
	    return SyncHttpRequest(file, null).responseText;
	} catch (e) {
	    alert('LoadJSFile() Error: Failed to load resource ('+file+')');
	    return '';
	}
    } else {
	var e = document.createElement('script');
	e.src = file;
	document.getElementsByTagName('head')[0].appendChild(e);
    }
}

//////////////////////////////////////////////////////////
//// 
//////////////////////////////////////////////////////////
function show (ename) {
    ele = document.getElementById(ename);

    if (ele)
	ele.style.display='block';
}

//////////////////////////////////////////////////////////
//// 
//////////////////////////////////////////////////////////
function hide (ename) {
    ele = document.getElementById(ename);

    if (ele)
	ele.style.display='none';
}

//////////////////////////////////////////////////////////
//// 
//////////////////////////////////////////////////////////
function showhide (ename) {
    var ele = document.getElementById(ename);
    
    if (ele.style.display == 'block') {
	ele.style.display = 'none';
    } else {
	ele.style.display = 'block';
    }
}

//////////////////////////////////////////////////////////
//// 
//////////////////////////////////////////////////////////
function addLoadEvent(func) { 
    var oldonload = window.onload; 

    if (typeof window.onload != 'function') { 
	window.onload = func; 
    } else { 
	window.onload = function() { 
	    if (oldonload) { 
	        oldonload(); 
	    } 
	    func(); 
	} 
    } 
} 
	 
//////////////////////////////////////////////////////////
// FocusToFirstControl();
//////////////////////////////////////////////////////////
function helpdiv (id,str) {
    //HIDE NAVICATOR
    ele = document.getElementById(id);

    if (ele) {
	if (ele.style.display == 'none') {
	    ele.style.display = 'block';
	    ele.innerHTML = str;
	} else {
	    ele.style.display = 'none';
	}
    }
}


//addLoadEvent(func1); 

