/* A library of useful little javascripts*/ 
function noscript() {
// invoke css rule in lieu of <NOSCRIPT> tag
document.write('<style>.noscript {display:none} .yesscript {display:block}</style>');
}

/* simple image swapper: put the calling pic into the <img src id="mainpic" > tag*/
function changepic(pic) {
	document.images.mainpic.src = pic;
}

/* 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"), "");
		}
	}
}

/* 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 (subj==undefined || subj=='') subj=''
if (bod==undefined || bod=='') bod=''
var addy=''
var y
var hash
switch (recp){
	case undefined:
	case 1: //email
		y='>c"jpgd? ocknvm8gocknBnncrc,amo';
		hash=2;
		break;
	case 2: //sales
		y="4i(`zmn5*eiad|g2{idm{Hddixi&kge";
		hash=8;
		break;
	case 3: //admin
		y="8e$lvab9&iemhpk>e`imjDhhete*gki";
		hash=4;
//		break;  // uncomment this break to allow this addy
	default: //email
		y='>c"jpgd? ocknvm8gocknBnncrc,amo';
		hash=2;
		break;
}
for(i=0;i<y.length;i++) addy +=	String.fromCharCode(hash^y.charCodeAt(i))
if (promp==undefined || promp=="") promp=addy.slice(16);
if(subj!='') addy+='?subject=' + subj;
if(bod!='') {
	if (subj=='') addy+='?'; else addy+="\&";
	addy+='body=' + bod;
} // end if
addy+= '">' + promp + '</a>';
return addy;
}

function fillsaddy() {
	/* populate shipping address form with shipping address if same box checked*/
	if(form1.sameaddy.checked==true){
		form1.sname.value=form1.name.value;
		form1.saddress1.value=form1.address1.value;
		form1.saddress2.value=form1.address2.value;
		form1.scity.value=form1.city.value;
		val=form1.countrySelect.value;
//		alert(val)
		for(x=0; x<form1.scountrySelect.length; x++) {
			if(form1.scountrySelect[x].value==val) {form1.scountrySelect[x].selected=true; break;}
		}
		/* this part still buggy - state doesn't always update */
		val=form1.stateSelect.value;
		for(x=0; x<form1.sstateSelect.length; x++) {
			if(form1.sstateSelect[x].value==val) {form1.sstateSelect[x].selected=true; break;}
		}
		form1.szip.value=form1.zip.value;
	}
	else { // if customer unchecks the box, then clear everything
		form1.sname.value='';
		form1.saddress1.value='';
		form1.saddress2.value='';
		form1.scity.value='';
		form1.szip.value='';
	}
}

function adddiv(starttag, endtag, tid) {
	// put divs around selected text in textarea; won't work in IE, boo-hoo
    var textArea = document.getElementById(tid); 
    var start = textArea.selectionStart;
    var end = textArea.selectionEnd;
    var replacement = starttag + textArea.value.substring(start, end) + endtag;
    textArea.value=textArea.value.substring(0, start) + replacement + textArea.value.substring(end, textArea.value.length);
}
