﻿// theihaorg.js
_timerID=0;
_timerCNT=0;
mouseX=0;
mouseY=0;
//
document.onmousemove = mouseMove;
function mouseMove(ev){
	ev           = ev || window.event;
	var mousePos = mouseCoords(ev);
}
function mouseCoords(ev){
	if(ev.pageX || ev.pageY){
		mouseX=ev.pageX;
		mouseY=ev.pageY;
		return {x:ev.pageX, y:ev.pageY};
	}
	mouseX=ev.clientX + document.body.scrollLeft - document.body.clientLeft;
	mouseY=ev.clientY + document.body.scrollTop  - document.body.clientTop;
	return {
		x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
		y:ev.clientY + document.body.scrollTop  - document.body.clientTop
	};
}
function GetWidth() { return window.document.body.clientWidth; }
function GetHeight() { 	return window.document.body.clientHeight; }
function MsgBox(msgOn,msgClosable,msgData,msgWidth,msgHeight,msgPos) {
	oPage = "";

	msgHeight=Number( (msgData.length/2)+30 );

	if(msgOn==0) {
		document.getElementById('ihaMsg').style.border="";
		document.getElementById('ihaMsg').style.width="1px";
		document.getElementById('ihaMsg').style.height="1px";
		document.getElementById('ihaMsg').innerHTML= " ";
		return;
	}
	if(msgPos==1) {
        var sTOP = 0;
        var sDOWN = 0;
        var sHEIGHT = 0;
        if (document.documentElement && !document.documentElement.scrollTop) {
            sTOP=document.documentElement.scrollTop;
            sHEIGHT=document.documentElement.clientHeight;
        }
        else if (document.documentElement && document.documentElement.scrollTop) {
            sTOP=document.documentElement.scrollTop;
            sHEIGHT=document.documentElement.clientHeight;
        }
        else if (document.body && document.body.scrollTop) {
            sTOP=document.body.scrollTop;
            sHEIGHT=document.body.clientHeight;
        }
        sDOWN=sTOP;
        if(!document.all) { sTOP=0; }
        var boxLeft = 0;
        var boxTop = 0;
        boxLeft= (  mouseX -(msgWidth+40)  );
        boxTop= (  mouseY -(msgHeight/2) )+sTOP;
        if( boxTop <= sDOWN ) {
            boxTop = sDOWN;
        } else if( (boxTop+msgHeight) >= (sHEIGHT+sDOWN) ) {
            boxTop=(((sHEIGHT-msgHeight)-20)+sTOP);
        }
	    document.getElementById('ihaMsg').style.left=Trim(boxLeft)+"px";
	    document.getElementById('ihaMsg').style.top=Trim(boxTop)+"px";
	} else {
	    document.getElementById('ihaMsg').style.left=(GetWidth()/2)-(msgWidth/2)+"px";
	    document.getElementById('ihaMsg').style.top=(GetHeight()/2)-(msgHeight/2)+"px";
	}
	document.getElementById('ihaMsg').style.width=(msgWidth+12)+"px";
	document.getElementById('ihaMsg').style.height=(msgHeight+14)+"px";
	oPage += "<div style='position: absolute; left: 10px; top: 10px; width: "+Trim(msgWidth)+"px; height: "+Trim(msgHeight)+"px;";
	oPage += " background-color: gray; filter: alpha(opacity=30); opacity: 0.30;'></div>";
	oPage += "<div style='position: relative; height: "+Trim(msgHeight)+"px; width: "+Trim(msgWidth)+"px; border: solid 1px black;'>";
	oPage += "<table border='0' cellpadding='3' cellspacing='0' width="+Trim(msgWidth)+" height="+Trim(msgHeight);
	oPage += " style='width: "+Trim(msgWidth)+"px; height: "+Trim(msgHeight)+"px;";
	oPage += " background-color: white; filter: alpha(opacity=97); opacity: 0.97;'>";
	oPage += "<tr bgcolor='#8CBAFE'><td align='center'><i>Sponsored by</i> <b>Vitamin Research Products</b></td>";
	oPage += "<td align='right'>";
	if(msgClosable==0) {
		oPage += "&nbsp;";
	} else {
		oPage += "<a href='' onClick=\"MsgBox(0,0,'',1,1,0); return false;\"><img src='/images/red-x.gif' border='0'></a>";
	}
	oPage += "</td></tr>";
	oPage += "<tr height='98%'><td height='98%' valign='top' colspan='2'><p align='justify'>";
	oPage += msgData;
	oPage += "</p></td></tr>";
	oPage += "</table>";
	oPage += "</div>";
	document.getElementById('ihaMsg').innerHTML= oPage;
}
function Trim( str ) {
	astr = String( str );
	LastCharAt = 0;
	while(astr.substring(0,1)==" ") {
		astr=astr.substring(1);
	}
	for(x=astr.length-1;x>=0;x--) {
		if( astr.charAt(x) != " " ) {
			LastCharAt = x+1;
			break;
		}
	}
	rSTR=astr.substring(0,LastCharAt);
	if(rSTR=="null")
		rSTR="";
	return rSTR;
}



