// JavaScript File

ajHOST=window.location.hostname;
ajPROTOCOL=window.location.protocol;
ajDOMAIN=ajPROTOCOL+"//"+ajHOST+"/";
Tdomain=ajDOMAIN;

function checkEmail ( addressField ) {
    retVALUE = true;
    addressField=String(addressField);

    if(addressField=="") {
        retVALUE=false;
    }
    if(addressField.indexOf("@") <1) {
        retVALUE=false;
    }
    if(addressField.indexOf(".") <1) {
        retVALUE=false;
    }
    return retVALUE;
}

function Tsender(sCODE,sTYPE,sNAME,sDESC) {
    _eto=document.getElementById("eto").value;
    _efrom=document.getElementById("efrom").value
    
    if( !checkEmail( _eto) ) {
        alert("To is a required field. Please provide a valid To email address.");
        return;
    }
    
    if( !checkEmail(_efrom) ) {
        alert("From is a required field. Please provide a valid From email address.");
        return;
    }

    _esubject="Complementary Prescriptions Email a Colleague from "+document.getElementById("efrom").value;
    _ebody ="<span style='font-size:12pt;font-weight:bold;color:navy;'>Complementary Prescriptions<br>Email a Colleague</span><br /><br />";
    _ebody+="The sender thought you would be interested in this.<br />";
    _ebody+="Please click on the link provided below to read more about it.<br /><br />"
    if(sTYPE==1) {
        _ebody+="<a href='"+Tdomain+"ProductPage.aspx?ProdID="+sCODE+"'>";
        _ebody+="<img border='0' src='"+Tdomain+"prodimgs/cp"+sCODE+"w95.jpg' alt='' /><br />"+sNAME+"</a><br />";
    }
    if(sTYPE==2) {
        //_ebody+="<a href='"+Tdomain+"articles.aspx?page=LIST&ProdID="+sCODE+"'>"+sNAME+"</a><br />";
        _ebody+="<a href='"+Tdomain+"articles.aspx?ProdID="+sCODE+"'>"+sNAME+"</a><br />";
    }
    if(sTYPE==3) {
        //_ebody+="<a href='"+Tdomain+"deardoctorresults.aspx?page=LIST&ProdID="+sCODE+"'>"+sNAME+"</a><br />";
        _ebody+="<a href='"+Tdomain+"deardoctorresults.aspx?ProdID="+sCODE+"'>"+sNAME+"</a><br />";
    }
    _ebody+="<br />Senders Comments: "+document.getElementById("ecomm").value+"<br />";
    _SendResult=PostGet("TELLFRIEND",_eto,_efrom,_esubject,_ebody,"","","","","","");
    msgData ="<form action='' method='post'><strong>SENT:</strong><br />";
    msgData+="To: "+_eto+"<br />";
    msgData+="From: "+_efrom+"<br />";
    msgData+="Subject: "+_esubject+"<br />";
    msgData+=_ebody+"<br />"
    msgData+="<center><input type='button' value='Close' onclick='Tfriend(0,\"\");'>";
    msgData+="</form>";
	oPage = "";
	msgWidth=400;
	msgHeight=400;
    document.getElementById('vrpMsg').style.top="5px";
    document.getElementById('vrpMsg').style.left=(GetWidth()/2)-(msgWidth/2)+"px";
    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.
        mouseY2=5+sTOP;
        boxTop= (  mouseY2 - (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('vrpMsg').style.top=Trim(boxTop)+"px";
	document.getElementById('vrpMsg').style.width=(msgWidth+12)+"px";
	document.getElementById('vrpMsg').style.height=(msgHeight+16)+"px";
	oPage += "<table border='0' cellpadding='3' cellspacing='0' width="+Trim(msgWidth)+" height="+Trim(msgHeight);
	oPage += " style='background-color: white; filter: alpha(opacity=96); opacity: 0.96; border: solid 1px black;'>";
	oPage += "<tr style='background-image:url(/images/bg_bluestrip_22b.jpg); background-repeat:repeat-x;' ><td align='center' style='color:white;'><b>Email a Colleague</b></td>";
	oPage += "<td align='right'>";
	oPage += "<a href='' onClick=\"Tfriend(0,''); return false;\"><img src='/images/red-x.gif' border='0' title='Close' alt='Close'></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('vrpMsg').innerHTML= oPage;
}
function Tfriend( tMODE,tCODE,tTYPE,tNAME,tDESC) {
    if( GotAj()=="N") {
        tCODE=String(tCODE).replace(/ /gi,"%20");
        tTYPE=String(tTYPE).replace(/ /gi,"%20");
        tNAME=String(tNAME).replace(/ /gi,"%20");
        tDESC=String(tDESC).replace(/ /gi,"%20");
        zwin=window.open("/TellFriend.aspx?c="+tCODE+"&t="+tTYPE+"&n="+tNAME+"&d="+tDESC,"TellFriend","location=0,status=0,scrollbars=1,resizable=1,width=460,height=400");
    } else {
    if( tMODE==0 ) {
		document.getElementById('vrpMsg').style.border="";
		document.getElementById('vrpMsg').style.width="1px";
		document.getElementById('vrpMsg').style.height="1px";
		document.getElementById('vrpMsg').innerHTML= " ";
		return;
    }
	oPage = "";
	msgWidth=350;
	msgHeight=300;
	msgData ="<form action=\"/index.aspx\" method=\"post\" name=\"tfriend\">";
	msgData+="<table border='0' cellpadding='2' cellspacing='0'>";
	msgData+="<tr><td colspan='2'>";
	msgData+="<strong>Email a Colleague!</strong><br /><br />We will send an email to the person you designate, from you. We will include a ";
	msgData+="link to this page. We will also include any comments you enter.<br /><br />";
	msgData+="</td></tr>";
	msgData+="<tr><td align='right'>To:</td><td><input type='text' name='eto' id='eto' size='30' /></td></tr>";
	msgData+="<tr><td align='right'>From:</td><td><input type='text' name='efrom' id='efrom' size='30' /></td></tr>";
	msgData+="<tr><td align='right' valign='top'>Comments:</td><td><textarea id='ecomm' name='ecomm' rows='4' cols='36'></textarea></td></tr>";
	msgData+="<tr><td colspan='2' align='center'><input type='button' value='Send' onclick=\"Tsender('"+tCODE+"',"+tTYPE+",'"+tNAME+"','"+tDESC+"');\"/>&nbsp;&nbsp;&nbsp;";
	msgData+="<input type='button' value='Cancel' onclick=\"Tfriend(0,'',1);\" /></td></tr>";
	msgData+="</table>";
	msgData+="</form>";
    document.getElementById('vrpMsg').style.top="5px";
    document.getElementById('vrpMsg').style.left=(GetWidth()/2)-(msgWidth/2)+"px";
    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.
        mouseY2=5+sTOP;
        boxTop= (  mouseY2 - (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('vrpMsg').style.top=Trim(boxTop)+"px";
	document.getElementById('vrpMsg').style.width=(msgWidth)+"px";
	document.getElementById('vrpMsg').style.height=(msgHeight)+"px";
	if(!document.all) {   // Firefox
	    oPage += "<table border='1' cellpadding='3' cellspacing='0' width='"+Trim(msgWidth)+"'";
	    oPage += " style='width:"+Trim(msgWidth)+"px; height:"+Trim(msgHeight-23)+"px;";
	} else {
	    oPage += "<table border='0' cellpadding='3' cellspacing='0' width='"+Trim(msgWidth)+"'";
	    oPage += " style='width:"+Trim(msgWidth)+"px; height:"+Trim(msgHeight-23)+"px;";
	}
	oPage += " background-color: white; filter: alpha(opacity=96); opacity: 0.96; border: solid 1px black;'>";
	oPage += "<tr style='background-image:url(/images/bg_bluestrip_22b.jpg); background-repeat:repeat-x;' ><td align='center' style='color:white;'><b>Email a Colleague</b></td>";
	oPage += "<td align='right'>";
	oPage += "<a href='' onClick=\"Tfriend(0,'',1); return false;\"><img src='/images/red-x.gif' border='0' title='Close' alt='Close'></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('vrpMsg').innerHTML= oPage;
	}
}


