MouseMoveTaskArray = new Array();
MouseUpTaskArray = new Array();

var IE = navigator.appName.indexOf('Microsoft')>-1?true:false
if(!IE){ window.captureEvents(Event.mousemove);  window.onmousemove = trackMouse; }
else{document.onmousemove = trackMouse;}    
document.onmouseup=DoMouseupTasks

document.write('<div ID="MessageLayer" style="color:#FFFFFF;position:absolute;visibility:hidden;border:solid white 1px;background:url(js/bg_messagediv.png);"></div>')
document.write('<div ID="echoDiv" style="padding:5px;position:absolute;border:solid white 1px;background:url(js/bg_messagediv.png);visibility:hidden;z-index:1000;" onclick="this.style.visibility=\'hidden\';"></div>')

function DoMouseupTasks(){
    for(ArrayTask in MouseUpTaskArray){eval(MouseUpTaskArray[ArrayTask])}

}

//_________________________________________________________________
function trackMouse(e){
	if(document.body){
		if (IE) {MouseYPos = event.clientY; MouseXPos = event.clientX;} 
		else    {MouseYPos = e.pageY;       MouseXPos = e.pageX;}
		RealMouseYPos = MouseYPos + parseInt(document.body.scrollTop)
		RealMouseXPos = MouseXPos + parseInt(document.body.scrollLeft)
	}
    for(ArrayTask in MouseMoveTaskArray){eval(MouseMoveTaskArray[ArrayTask])}
}


//
function CheckMaxLength(fieldObj,paramMaxLen){
	if(fieldObj.value.length>paramMaxLen){fieldObj.value = fieldObj.value.substring(0,paramMaxLen);}
}

//_________________________________________________________________
function msover(CallingImage){
	CallingImage.src = CallingImage.src.indexOf('_2.')==-1 ? CallingImage.src.replace('_1.','_2.') : CallingImage.src.replace('_2.','_1.');
	CallingImage.src = CallingImage.src.indexOf('_ON.')==-1 ? CallingImage.src.replace('_OFF.','_ON.') : CallingImage.src.replace('_ON.','_OFF.');
}

function msoff(CallingImage){
	CallingImage.src = CallingImage.src.indexOf('_1.')==-1 ? CallingImage.src.replace('_2.','_1.') : CallingImage.src
	CallingImage.src = CallingImage.src.indexOf('_OFF.')==-1 ? CallingImage.src.replace('_ON.','_OFF.') : CallingImage.src
}

//_________________________________________________________________
function ShowMessage(MessageHTML){
	document.getElementById('MessageLayer').innerHTML = MessageHTML  + '<br><br><div style="text-align:center;"><a href="javascript:CloseMessage();">Close</a></div>';
	document.getElementById('MessageLayer').style.top = screen.height/2  - (document.getElementById('MessageLayer').offsetHeight/2) + 'px' //RealMouseYPos - (document.getElementById('MessageLayer').offsetHeight/2) + 'px';
	document.getElementById('MessageLayer').style.left = screen.width/2 -  (document.getElementById('MessageLayer').offsetWidth/2) + 'px'    //RealMouseXPos - (document.getElementById('MessageLayer').offsetWidth/2) + 'px';
	document.getElementById('MessageLayer').style.visibility='visible';

}

//_________________________________________________________________
function CloseMessage(){
	document.getElementById('MessageLayer').style.visibility='hidden';
}

//_________________________________________________________________
function FormatCurrency(TargetNumber){
	TargetNumber = TargetNumber * 100;
	TargetNumber = Math.round(TargetNumber).toString();
	ThisPriceCash = TargetNumber.substring(0,TargetNumber.length-2)
	ThisPriceChange = TargetNumber.substring(TargetNumber.length-2,TargetNumber.length)
	return('$' + ThisPriceCash + '.' + ThisPriceChange);
}

//_________________________________________________________________
function echo(ResponseString){
    if (ResponseString==''){ResponseString = 'Note: An unkown script has attempted to display a message to you, but the message is empty.'}
    document.getElementById('echoDiv').innerHTML = ResponseString + "<br><span style=\"font-size:.7em;\">(Click to close)</span>";
    document.getElementById('echoDiv').style.top = (parseInt(screen.availHeight)/2) - (parseInt(document.getElementById('echoDiv').offsetHeight)/2);
    document.getElementById('echoDiv').style.left = (parseInt(screen.availWidth)/2) - (parseInt(document.getElementById('echoDiv').offsetWidth)/2);
    document.getElementById('echoDiv').style.visibility = 'visible';
}

//_________________________________________________________________
function XMLRequest(TargetURL,PostValue,MultipartBoundary){
	if(MultipartBoundary==null){MultipartBoundary = "";}
	if (window.XMLHttpRequest) {
		if(PostValue==undefined){PostValue=null;}
		xmlhttp = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		if(PostValue==undefined){PostValue=null;}
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}

	if(PostValue!=null && PostValue!=0){
		xmlhttp.open("POST", TargetURL, false);
		if(MultipartBoundary.length>0){xmlhttp.setRequestHeader("Content-Type","multipart/form-data, boundary="+MultipartBoundary);}
		else{xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");}
		xmlhttp.setRequestHeader("Content-Length", PostValue.length);
		xmlhttp.setRequestHeader("Connection", "close");
	}
	else{
		xmlhttp.open("GET", TargetURL, false);
		xmlhttp.setRequestHeader("Content-Length", '0');
	}


	xmlhttp.send(PostValue);
	if(xmlhttp.ResponseText){ ReturnText = xmlhttp.ResponseText.toString(); }
	else{ReturnText = xmlhttp.responseText.toString();}

	if(ReturnText.indexOf('The system cannot find the file specified.') > -1){
		while(ReturnText.indexOf('The system cannot find the file specified.') > -1){
			xmlhttp.send(PostValue);
			if(xmlhttp.ResponseText){ ReturnText = xmlhttp.ResponseText.toString(); }
			else{ReturnText = xmlhttp.responseText.toString();}
		}
	}

	return ReturnText
}

//_________________________________________________________________
function findPosX(obj)
{
    var curleft = 0;
    if (obj.offsetParent)
    {
        while (obj.offsetParent)
        {
            curleft += obj.offsetLeft
            obj = obj.offsetParent;
        }
    }
    else if (obj.x){curleft += obj.x;}
    return curleft;
}

//_________________________________________________________________
function findPosY(obj)
{
    var curtop = 0;
    if (obj.offsetParent)
    {
        while (obj.offsetParent)
        {
            curtop += obj.offsetTop
            obj = obj.offsetParent;
        }
    }
    else if (obj.y){curtop += obj.y;}
    return curtop;
}

//_________________________________________________________________
function GetLocation(TargetLocation,IsNewWindow){
    if(IsNewWindow==1){window.open(TargetLocation,'window2','width=700,height=580');}
    else{document.location.href=TargetLocation}
}

function ClearMessage(){
	document.getElementById('MessageDiv').innerHTML = "";
}

//_________________________________________________________________
function ShowHelp(){
	CurrentContent = document.getElementById('HelpDiv').innerHTML
	if (CurrentContent==''){document.getElementById('HelpDiv').style.width=360;	document.getElementById('HelpDiv').innerHTML = HelpText;}
	else{document.getElementById('HelpDiv').innerHTML = ''; document.getElementById('HelpDiv').style.width=1;}
}

function CheckNumeric(CallingField){
	if(isNaN(CallingField.value) || CallingField.value.indexOf('.')!=-1){
		alert('Please enter only numbers into this field')
		while((isNaN(CallingField.value) || CallingField.value.indexOf('.')!=-1) && CallingField.value!=''){
			CallingField.value = CallingField.value.substring(0,CallingField.value.length-1)
		}
	}
}