//////////////////////////////////////////////////////////
//////// Functions for Product Page DIV's
//////////////////////////////////////////////////////////

dd=document;NS=(dd.layers)?1:0;IE=(dd.all)?1:0;DOM=(dd.getElementById)?1:0 
function showLayer(L){ 
if(NS)dd.layers[L].display='show'; 
else if (IE)obg=dd.all[L]; 
else obg=dd.getElementById(L); 
if(!NS)obg.style.display='block' 
}

function hideLayer(L){ 
if(NS)dd.layers[L].display='hide'; 
else if (IE)obg=dd.all[L]; 
else obg=dd.getElementById(L); 
if(!NS)obg.style.display='none' 
}

function div_overview()
{
showLayer('overview')
hideLayer('forms')
hideLayer('directions')
hideLayer('ingredients')
hideLayer('warnings')
hideLayer('storage')
}

function div_forms()
{
showLayer('forms')
hideLayer('overview')
hideLayer('directions')
hideLayer('ingredients')
hideLayer('warnings')
hideLayer('storage')
}

function div_directions()
{
showLayer('directions')
hideLayer('overview')
hideLayer('forms')
hideLayer('ingredients')
hideLayer('warnings')
hideLayer('storage')
}

function div_ingredients()
{
showLayer('ingredients')
hideLayer('overview')
hideLayer('forms')
hideLayer('directions')
hideLayer('warnings')
hideLayer('storage')
}

function div_warnings()
{
showLayer('warnings')
hideLayer('overview')
hideLayer('forms')
hideLayer('directions')
hideLayer('ingredients')
hideLayer('storage')
}

function div_storage()
{
showLayer('storage')
hideLayer('overview')
hideLayer('forms')
hideLayer('directions')
hideLayer('ingredients')
hideLayer('warnings')
}

function emailfriend_switch()
{
showLayer('submit_off')
hideLayer('submit_on')
}

//////////////////////////////////////////////////////////
document.write('<div id="trace" style="position: absolute; top: 0px; left: 0px; ; border: 1px solid red; background-color: white; z-Index: 99999; display: none;">&nbsp;</div>');
function traceIt(T) {
	document.getElementById('trace').innerHTML += T + "<br>";
	document.getElementById('trace').style.display = "inline";
}

function rollOver(which,state) {
        if (document.images) {
                ext = which.src.substring(which.src.lastIndexOf("."));
                which.src = which.src.substring(0,which.src.lastIndexOf('-')) + "-" + state + ext;
        }
}

function contentbox(c, h, t) {
	document.getElementById("contentbox").style.backgroundImage="url(/images/stjoseph/bg-" + c + "-box.gif)";
	document.getElementById("contentboxtop").style.backgroundImage="url(/images/stjoseph/bg-" + c + "-top.gif)";
	document.getElementById("contentboxbottom").style.backgroundImage="url(/images/stjoseph/bg-" + c + "-bottom.gif)";
	document.getElementById("contentboxbottompad").style.height=h+"px";
	document.getElementById("header_alt").style.height=t+"px";
	if (document.getElementById("sendButton")) {
		document.getElementById("sendButton").src="/images/stjoseph/btn-"+c+"-send-off.gif";
	}
	if (document.getElementById("printButton")) {
		document.getElementById("printButton").src="/images/stjoseph/btn-"+c+"-print-off.gif";
	}
}

function pad(type,px) {
	switch (type) {
		case "tr":
			document.write('<tr><td height="'+px+'"></td></tr>');
		break;
		case "td":
			document.write('<td width="'+px+'"></td>');
		break;
		case "br":
			document.write('<img src="/images/stjoseph/spacer.gif" alt="" width="1" height='+px+'" border="0"><br>');
		break;
	}
}

var arrowSpeed = 66;
var arrowRoll = new Array();
var dir = new Array();
function arrowMove(which) {
	if (!dir[which]) { dir[which] = "l"; }
	pos = document.getElementById(which).style.left.substring(0,document.getElementById(which).style.left.indexOf('px'));
	if (pos.charAt(0) == "-") {
		pos = parseInt(pos.substring(1,pos.length));
	}
	if (dir[which] == "l") {
		if (pos*(-1) == -5) {
			dir[which] = "r";
		}
		else {
			document.getElementById(which).style.left = ((pos*(-1)) - 1) + "px";
		}
	}
	if (dir[which] == "r") {
		if (pos*(-1) == 0) {
			dir[which] = "l";
		}
		else {
			document.getElementById(which).style.left = ((pos*(-1)) + 1) + "px";
		}
	}
	if (arrowRoll[which]) {
		setTimeout("arrowMove('"+which+"')", arrowSpeed);
	}
}
function arrowBounce(which,state) {
	whichTxt = which+'Txt';
	if (state) {
		arrowRoll[which] = true;
		document.getElementById(whichTxt).className='arrowhover';
		arrowMove(which);
	}
	else {
		arrowRoll[which] = false;
		document.getElementById(whichTxt).className='arrow';
		document.getElementById(which).style.left='0px';
	}
}
function hearticles_arrowBounce(which,state) {
	whichTxt = which+'Txt';
	if (state) {
		arrowRoll[which] = true;
		document.getElementById(whichTxt).className='hearticles_hover';
		arrowMove(which);
	}
	else {
		arrowRoll[which] = false;
		document.getElementById(whichTxt).className='hearticles';
		document.getElementById(which).style.left='0px';
	}
}

function newWindow(url,name,w,h,t,m,s,r,st,l,d,c) {
	var windowOptions = "width=" + w + "," +
	"height=" + h + "," +
	"toolbar=" + t + "," +
	"menubar=" + m +"," +
	"scrollbars=" + s + "," +
	"resizable=" + r + "," +
	"status=" + st + "," +
	"location=" + l + "," +
	"directories=" + d + "," +
	"copyhistory=" + c;
	window.open(url, name, windowOptions);
}
function op_lgpr (url) {
	newWindow(url, 'print', 640, 480, 0, 0, 1, 0, 0, 0, 0, 0);
}

function send(url) {
	newWindow('/vcrc/emailfriend/emailform.jhtml', 'send', 400, 550, 0, 0, 1, 0, 0, 0, 0, 0);
}

function isValidEmail(str) {
	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

//////////////////////////////////////////////////////////////////////////
//////////// Page.js Functions Below - Remaining Core Functions
//////////////////////////////////////////////////////////////////////////

function sendPrintButtons(s,p,sUrl,pUrl) {
	document.write('					<table id="contentboxbottompad" cellpadding="0" cellspacing="0" align="right" border="0">');
	document.write('					<tr>');
	if (s) {
		document.write('					<td valign="bottom" align="right"><a href="javascript:send(\''+sUrl+'\');" id="sendButtonLink"><img src="" alt="send a friend" width="123" height="16" border="0" onMouseOver="rollOver(this,\'on\');" onMouseOut="rollOver(this,\'off\');" id="sendButton"></a></td>');
	}
	if (s && p) {
		pad('td',1);
	}
	if (p) {
		document.write('					<td valign="bottom" align="right"><a href="javascript:op_lgpr(\''+pUrl+'\');" id="printButtonLink"><img src="" alt="print" width="75" height="18" border="0" onMouseOver="rollOver(this,\'on\');" onMouseOut="rollOver(this,\'off\');" id="printButton"></a></td>');
	}
	if (!s && !p) {
		document.write('					<td>&nbsp;</td>');
	}
	document.write('					<td style="width: 10px;"></td>');
	document.write('					</tr>');
	document.write('					</table>');
}

var arrowID = 0;

function arrowLink(c, t, l) {
	document.write('<table cellpadding="0" cellspacing="0" border="0">');
	document.write('<tr>');
	document.write('<td valign="top"><a href="'+l+'"><img src="/images/stjoseph/g-arrow-'+c+'.gif" id="arrow'+arrowID+'" border="0" style="position: relative; left: 0px;" onMouseOver="arrowBounce(\'arrow'+arrowID+'\',1);" onMouseOut="arrowBounce(\'arrow'+arrowID+'\',0);"></td>');
	document.write('<td valign="top" style="padding: 2px 0px 0px 2px;"><a href="'+l+'" class="arrow" onMouseOver="arrowBounce(\'arrow'+arrowID+'\',1);" onMouseOut="arrowBounce(\'arrow'+arrowID+'\',0);" id="arrow'+arrowID+'Txt">'+t+'</a></td>');
	document.write('</tr>');
	document.write('</table>');
	arrowID++;
}

function subnav(s,h) {
	mousies = ' onMouseOver="rollOver(this,\'on\');" onMouseOut="rollOver(this,\'off\');"';
	sub = "";
	switch (s) {
		case 2:
			sub += subnavElement(h, "2_2", "St. Joseph 81 mg Chewable Aspirin");
			sub += subnavElement(h, "2_1", "St. Joseph 81 mg Aspirin Enteric safety-coated Tablets");
		break;

		case 3:
			sub += subnavElement(h, "3_1", "Heart Tours");
			sub += subnavElement(h, "3_6", "Heart Health Profile");
			if (h == "3_2" || h == "3_5" || h == "3_4") {
				sub += '<img src="/images/stjoseph/nav-3_dr-on.gif" alt="The Doctor\'s Office" width="158" height="15"><br>';
			}
			else {
				sub += '<img src="/images/stjoseph/nav-3_dr-off.gif" alt="The Doctor\'s Office" width="158" height="15"><br>';
			}
			sub += subnavElement(h, "3_2", "The Doctor is in");
			sub += subnavElement(h, "3_5", "Heartbeat Calculator");
			sub += subnavElement(h, "3_4", "Hearticles");
		break;

		case 4:
			sub += subnavElement(h, "4_3", "Relax");
			sub += subnavElement(h, "4_2", "Exercise");
			sub += subnavElement(h, "4_1", "Eat Right");
			sub += subnavElement(h, "4_5", "Other Resources");
		break;

		case 5:
			sub += subnavElement(h, "5_1", "Our History");
			sub += subnavElement(h, "5_3", "Collectible Tins");			
		break;

		case 9:
			sub += subnavElement(h, "9_2", "Clinical Trials and Studies");
			sub += subnavElement(h, "9_3", "Request a Sample");
		break;

		case 11:
			sub += subnavElement(h, "11_1", "Call us with a question");
			sub += subnavElement(h, "11_2", "Email us a question");
		break;

	}
	document.write(sub);
}

function subnavElement(h, n, a) {
	sub = "";
	sub += '<a href="/page.jhtml?id=/stjoseph/include/'+n+'.inc"><img src="/images/stjoseph/nav-'+n+'-';
	sub += (h == n) ? 'on.gif" ' : 'off.gif" ' + mousies;
	sub += ' alt="'+a+'" width="158" border="0"></a><br>';
	return sub;
}

function productSubnav(p,w,id1,id2) {
	prodsubnav = '<table cellpadding="0" cellspacing="0" border="0">';
	sub = new Array();
	sub[0] = "overview|Overview and Uses|div_overview()";
	sub[1] = "available|Available forms and sizes|div_forms()";
	sub[2] = "directions|Directions|div_directions()";
	sub[3] = "ingredients|Ingredients|div_ingredients()";
	sub[4] = "wnings|Warnings|div_warnings()";
	sub[5] = "storage|Storage and Package Safety|div_storage()";
	sub[6] = "largeprint|Large Print Version|";
	for (i = 0; i < sub.length; i++) {
		parts = sub[i].split("|");
		if (w == parts[0]) {
			prodsubnav += '<tr><td><img src="/images/stjoseph/nav-box-2-'+parts[0]+'-on.gif" alt="'+parts[1]+'" width="118" border="0"></td></tr>';
		}
		else {
			prodsubnav += '<tr><td>'+productSubnavArrow(p, parts[0],parts[1], id1, id2,parts[2])+'</td></tr>';
		}
	}
	prodsubnav += '</table>';
	document.write(prodsubnav);
}

function productSubnavArrow(p, n, a, id1, id2, id3) {
	l = (n == "overview" ? "" : "-"+n);

	// Dev or Production links
	// Dev
	//url = (n == "largeprint") ? "javascript:op_lgpr('"+p+l+".html');" : p+l+".html";

	//Production
	url = (n == "largeprint") ? "javascript:op_lgpr('/print.jhtml?id=/stjoseph/include/"+p+".inc');" : "javascript:"+id3+";"
	elem = "";
	elem += '<table width="175" cellpadding="0" cellspacing="0" border="0">';
	elem += '<tr>';
	elem += '<td valign="top" width="30">&nbsp;</td><td valign="top"><a href="'+url+'"><img src="/images/stjoseph/nav-box-2-'+n+'-arrow.gif" alt="" width="23" height="20" border="0" id="arrow'+arrowID+'" style="position: relative; left: 0px;" onMouseOver="arrowBounce(\'arrow'+arrowID+'\',1); rollOver(document.getElementById(\'arrow'+arrowID+'Txt\'), \'roll\');" onMouseOut="arrowBounce(\'arrow'+arrowID+'\',0); rollOver(document.getElementById(\'arrow'+arrowID+'Txt\'), \'off\');"></td>';
	elem += '<td valign="top"><a href="'+url+'" class="arrow"><img src="/images/stjoseph/nav-box-2-'+n+'-off.gif" alt="'+a+'" width="95" border="0" onMouseOver="arrowBounce(\'arrow'+arrowID+'\',1); rollOver(this,\'roll\');" onMouseOut="arrowBounce(\'arrow'+arrowID+'\',0); rollOver(this,\'off\');" id="arrow'+arrowID+'Txt"></a></td>';
	elem += '</tr>';
	elem += '</table>';
	arrowID++;
	return elem;
}

function hearticles_arrowLink(c, t, l) {
	document.write('<table cellpadding="0" cellspacing="0" border="0">');
	document.write('<tr>');
	document.write('<td valign="bottom"><a href="'+l+'"><img src="/images/stjoseph/g-arrow-'+c+'.gif" id="arrow'+arrowID+'" border="0" style="position: relative; left: 0px;" onMouseOver="hearticles_arrowBounce(\'arrow'+arrowID+'\',1);" onMouseOut="hearticles_arrowBounce(\'arrow'+arrowID+'\',0);"></td>');
	document.write('<td valign="top" style="padding: 2px 0px 2px 2px;"><a href="'+l+'" class="hearticles" onMouseOver="hearticles_arrowBounce(\'arrow'+arrowID+'\',1);" onMouseOut="hearticles_arrowBounce(\'arrow'+arrowID+'\',0);" id="arrow'+arrowID+'Txt">'+t+'</a></td>');
	document.write('</tr>');
	document.write('</table>');
	arrowID++;
}
