// 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,msgType) {
	oPage = "";
	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;
	}
	// Estimate message box height.
	msgWidth=msgWidth+25;
	msgHeight=Number( (msgData.length*.78) );
	if( msgHeight<160) { msgHeight=160; }
	if( msgHeight>400) { msgHeight=msgHeight-50; }
	if(msgPos==1) {
	    // Show just left of cursor.
        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;
        var boxLeft = 0;
        var boxTop = 0;
        boxLeft= (  mouseX -(msgWidth+40)  );
        //        
        if(!document.all) {   // FIREFOX
            boxTop= (  mouseY - (msgHeight/2) );
        } else {                  // I.E.
            mouseY=mouseY+sTOP;
            boxTop= (  mouseY - (msgHeight/2) );
        }
        xtop=Number(boxTop);
        xheight=Number(msgHeight);
        xvalue=xtop+xheight;
        ytop=Number(sTOP);
        yheight=Number(sHEIGHT);
        yvalue=ytop+yheight;
        zvalue=yvalue-xheight;
        if( xtop < ytop ) {
            boxTop=ytop+40;
        } else {
            if( xvalue > yvalue ) {
                boxTop = zvalue-40;
            }
        }
	    document.getElementById('ihaMsg').style.left=Trim(boxLeft)+"px";
	    document.getElementById('ihaMsg').style.top=Trim(boxTop)+"px";
	} else {
	    // Show centered on screen.
	    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";
	if(!document.all) {   // Firefox
	    oPage += "<div style='position: absolute; left: 10px; top: 10px; width: "+Trim(msgWidth)+"px; height: "+Trim(msgHeight)+"px;";
	    oPage += " background-color: black; filter: alpha(opacity=20); opacity: 0.20;'></div>";
    	oPage += "<div style='position: relative; height: "+Trim(msgHeight)+"px; width: "+Trim(msgWidth)+"px; border: solid 1px black;'>";
	} else {      // IE
	    oPage += "<div style='position: absolute; left: 10px; top: 10px; width: "+Trim(msgWidth)+"px; height: "+Trim(msgHeight+20)+"px;";
	    oPage += " background-color: black; filter: alpha(opacity=30); opacity: 0.30;'></div>";
    	oPage += "<div style='position: relative; height: "+Trim(msgHeight+20)+"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=96); opacity: 0.96;'>";
	if( msgType==0 ) {
	    // VRP Sponsored
	oPage += "<tr style='background-image:url(/images/bg_bluestrip_22b.jpg); background-repeat:repeat-x;' ><td align='center' style='color:white;'><b>Vitamin Research Products</b></td>";
	} else {
	    // CP Sponsored
		oPage += "<tr style='background-image:url(/images/bg_bluestrip_22b.jpg); background-repeat:repeat-x;' ><td align='center' style='color:white;'><i>Sponsored by</i> <b>Complementary Prescriptions</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;
}
function Chngr( what2add) {
    URLString=String(window.location.href);
    URLString=URLString.replace(" ","%20");
   what2add=what2add.replace(" ","%20");
   if(URLString.indexOf("attribute_value_date_range")>0) {
       URLString=URLString.substring(0,URLString.indexOf("attribute_value_date_range"));
   }
    window.location.href=URLString+what2add;
}
