/* some useful javascripts */

/* work pull-down menu for older IE */
sfHover = function() {
	var sfEls = document.getElementById("dropmenu").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

/* Show designated picture and text in a brand new window */
function Showpic(picname)
{
var winleft=0
var wintop=0
var winwid=932
if(navigator.appName=='Microsoft Internet Explorer') winwid=936
var winhi=750
var loadwin=null
/* include descriptive text with picture */
var divHandle = document.getElementById('descrip' + picname).innerHTML;
var title = document.getElementById('title' + picname).innerHTML;
var newImg1 = new Image();
newImg1.src = 'image/pyrotool_' + picname + '.jpg?' + (new Date()).getTime() //load latest image

/* This next section will resize the screen based on picture size. But that means putting the window.open command in a function, which will make popup blocker cry. So we have to shut it out for now.... */ /*
picwid=newImg1.width //get image size for window
pichi=newImg1.height
	if (picwid>10) writewindow()
	else{     //wait for it to download to get size
		newImg1.onload = function()
 		 {
	     picwid=newImg1.width
		 pichi=newImg1.height
		 writewindow()
		 }
		}
function writewindow(){ 
//** use defaults until all our pix are big enough  ****
//get screen resolution and size window accordingly
var asprat=picwid/pichi // aspect ratio
var screenhi=(screen.availHeight-150)
if (pichi > screenhi)pichi = screenhi
picwid=Math.round(pichi*asprat)
//set position and size of window - change for aesthetics
if ((picwid+40) > winwid) winwid=picwid+40
winhi=pichi+300 

//write HTML with picture name & specs */
var docstring = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"\r';
docstring+='   "http://www.w3.org/TR/html4/strict.dtd">\r';
docstring+='<html><head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">\r';
docstring+='<title>Wolter Pyro Tools - ' + title + '</title>\r';
docstring+='<link rel="stylesheet" type="text/css" href="pyrostyles_new.css" />\r';
docstring+='<style type="text/css">input.smallbutton {display: none}</style>\r';  // hide cart buttons
docstring+='<!--[if gte IE 8]>\r<link rel="StyleSheet" type="text/css" href="pyrostyles_gteie8.css">\r<![endif]-->\r'; //fix ie8's reduced font bug
docstring+='</head>\r';
docstring+='<body>\r'; // style="background:none;">\r';	
docstring+='<div class="popup">\r';
docstring+='<h2>' + title + '</h2>\r';
docstring+='<img src="' + newImg1.src + /* '" width="' + picwid + '" height="' + pichi + */ '"/></br>\r';
docstring+= '<p>';
docstring+=divHandle;  									//include text with picture
docstring+='</div>\r</body>\r</html>\r';
windowset='menubar=1,resizable=1,scrollbars=1,left=' + winleft + ',top=' + wintop + ',width=' + winwid + ',height=' + winhi;
displaywindow=window.open('','_blank', windowset);
displaywindow.document.write(docstring);
displaywindow.document.close();
//if (loadwin && loadwin.open && !loadwin.closed) loadwin.close()
//						}  // this function no longer a function
}

function Showcap(){// hide caption from non-JS browsers
document.write("<br>Click Image to Enlarge")
}

/* encrypt email and add some text */
function hashmail(promp,subj,bod,recp)
{
//parameters: user "click-here" prompt, subject line, message in email body, recipient
if (promp==undefined || promp=='') promp='Email'
if (subj==undefined || subj=='') subj='Wolter Pyro Tools'
if (bod==undefined || bod=='') bod=''
var addy=''
var y
var hash
switch (recp){
	case undefined:
	case 1: //info
		y='>c"jpgd? ocknvm8kldmBumnvgpr{pmvmmnq,amo';
		hash=2;
		break;
	case 2: //sales
		y="5h)a{lo4+dh`e}f3zhelzI~fe}l{yp{f}ffez'jfd";
		hash=9;
		break;
	case 3: //rich
		y="9d%mw`c8'hdliqj?wlfmErjiq`wu|wjqjjiv+fjh";
		hash=5;
		break;
	case 4: //admin
	default:
		y='?b#kqfe>!nbjowl9bgnjmCtlowfqszqlwllop-`ln';
		hash=3;
		break;
}
for(i=0;i<y.length;i++) {
addy +=	String.fromCharCode(hash^y.charCodeAt(i))
	}
	addy+="?subject=" + subj + "\&body=" + bod + "\">" + promp + "</a>"
	document.write(addy)
}

/* write to a popup window */
function popup(file,name,winwid,winhi)
{
var winleft=20
var wintop=20
if (winwid=='') winwid=300
if (winhi=='') winhi=600
if (file=='cbd_howto_order.html'){//default size for some links
winwid=740
winhi=640
}
var windowset='menubar=yes,resizable=yes,scrollbars=yes,left=' + winleft + ',top=' + wintop + ',width=' + winwid + ',height=' + winhi 
window.open(file,name,windowset);
}

/* return to same page position after user hits form button  */ 
function SaveScrollXY(num) {
	if (document.body && document.body.scrollTop) {
    document.forms["addtocart" + num].ScrollX.value = document.body.scrollLeft;
    document.forms["addtocart" + num].ScrollY.value = document.body.scrollTop;
	}
	else {
    document.forms["addtocart" + num].ScrollX.value = document.documentElement.scrollLeft;
    document.forms["addtocart" + num].ScrollY.value = document.documentElement.scrollTop;
	}
/*	IE6 and DTD 4.01 require you to use document.documentElement in stead of document.body, so u will need something like the below:

if (document.documentElement && !document.documentElement.scrollTop)
// IE6 +4.01 but no scrolling going on
else if (document.documentElement && document.documentElement.scrollTop)
// IE6 +4.01 and user has scrolled
else if (document.body && document.body.scrollTop)
// IE5 or DTD 3.2
*/
} 
function ResetScrollPosition(num) {
    var hidx, hidy;
    hidx = document.forms["addtocart" + num].ScrollX;
    hidy = document.forms["addtocart" + num].ScrollY;
    if (typeof hidx != 'undefined' && typeof hidy != 'undefined') {
    	window.scrollTo(hidx.value, hidy.value);
    }
} 

function noscript() {
// invoke css rule in lieu of <NOSCRIPT> tag
document.write('<style>.noscript {display:none} .yesscript {display:block}</style>');
}