var DOMloaded=false;

//window.stop();
var IE=document.all?true:false;
if((window.name=='products_window')&&/\/index\.html/.test(location.href)) location.assign('http://www.sewvacdirect.com/viewproduct.php?id='+location.hash.replace('#',''));

var title=document.title;

//IMPORTANT FUNCTIONS
function setCookie(cname,value){var exdate=new Date();exdate.setDate(exdate.getDate()+7);document.cookie=cname+"="+URLEncode(value)+";expires="+exdate.toGMTString()+"; path=/";}
function getCookie(cname,fall){if(document.cookie.length>0){cstart=document.cookie.indexOf(cname+"=");if(cstart!=-1){cstart=cstart+cname.length+1;cend=document.cookie.indexOf(";",cstart);if(cend==-1)cend=document.cookie.length;return URLDecode(document.cookie.substring(cstart,cend));}}if(!fall)fall=0;return fall;}
function XMLHTTP(){var xmlhttpobj=false;try{xmlhttpobj=new XMLHttpRequest();}catch(e){try{xmlhttpobj=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{xmlhttpobj=new ActiveXObject("Microsoft.XMLHTTP");}catch(e){return false;}}}return xmlhttpobj;}
function windowSize(){var w=0;var h=0;if(!window.innerWidth){if(!(document.documentElement.clientWidth == 0)){w=document.documentElement.clientWidth;h=document.documentElement.clientHeight;}else{w=document.body.clientWidth;h=document.body.clientHeight;}}else{w=window.innerWidth;h=window.innerHeight;}return{width:w,height:h};}
function debug(str){document.getElementById('debug').innerHTML=str;}
//function $(id){return(document.getElementById(id));}
String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"");};
String.prototype.ltrim=function(){return this.replace(/^\s+/,"");};
String.prototype.rtrim=function(){return this.replace(/\s+$/,"");};
//INIT

var cW=1024,cH=768;
if(typeof narrow == 'undefined') var narrow=0;

//window.onresize = updatewidth;

function updatewidth() {
/*
	if(/https|\.cgi/.test(location.href)) return(false);
	if(!DOMloaded) return(false);
	var w = windowSize(); cW = w.width; cH = w.height;
	if((cW<995)&&(narrow==0)) {
		var x = XMLHTTP();
		if(x) {
			x.open("POST",'/setstyle.php',false);
			x.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			x.send("narrow=1"); narrow=1;
			window.location.replace(location.href);
		}
	}
	if((cW>995)&&(narrow==1)) {
		var x = XMLHTTP();
		if(x) {
			x.open("POST",'/setstyle.php',false);
			x.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			x.send("narrow=0"); narrow=0;
			window.location.replace(location.href);
		}
	}
*/
}

//Tells the browser to start an email while keeping the address hidden from spambots.
function email(name, domain) {
	if(!domain) domain = 'sewvacdirect';
	document.location = 'mailt' + 'o:'.concat(name, '@') + domain + '.com';
}

//Pops up the "price_quotes" Product Information Request form in a new window.
function inforequest(product) {
	window.open("/inforequest.php?product="+product, "reqinfo", "resizable=yes,scrollbars=yes,width=600,height=450");
}

//Pops up the "sales" Product Information Request form in a new window.
function retailrequest(product) {
	window.open("/retailrequest.php?product="+product, "reqinfo", "resizable=yes,scrollbars=yes,width=600,height=450");
}

//Pops up the Part Request form in a new window.
function partrequest(product) {
	window.open("/partrequest.php?product="+product, "reqinfo", "resizable=yes,scrollbars=yes,width=600,height=450");
}

//Toggles the display of the answer to a given question.
function faq_toggle(item) {
	item = item.parentNode.parentNode.getElementsByTagName("div")[0];
	if(item.style.display == "block") item.style.display = "none";
	else item.style.display = "block";
}

//AJAX FUNCTIONS
function XMLHTTP(){var xmlhttpobj=false;try{xmlhttpobj=new XMLHttpRequest();}catch(e){try{xmlhttpobj=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{xmlhttpobj=new ActiveXObject("Microsoft.XMLHTTP");}catch(e){return false;}}}return xmlhttpobj;}
function AJAX(ref,method,url,param,func){var ref=XMLHTTP();if(ref){ref.open(method,url,true);if(method.toUpperCase()=='POST')ref.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');ref.onreadystatechange=func;ref.send(param);}}
function ReCSS(){var i,a,s;a=document.getElementsByTagName('link');for(i=0;i<a.length;i++){s=a[i];if(s.rel.toLowerCase().indexOf('stylesheet')>=0&&s.href) {var h=s.href.replace(/(&|\\?)forceReload=d /,'');s.href=h+(h.indexOf('?')>=0?'&':'?')+'forceReload='+(new Date().valueOf());}}}
function searchlink(v) { document.getElementById('searchlink').href = 'http://www.sewvacdirect.com/search.php?q='+encodeURIComponent(v); }

//MUST BE CALLED BEFORE ANYTHING ELSE IS WRITTEN
var ref   = escape(document.referrer)+" ";
var entry = escape(unescape(location.href));
document.write( '<' + 'script language="javascript" src="/axroi/script.php?ref=' + ref + '&entry=' + entry+ '"><' + '/script>' );

function setupanchors(base) {
	var i,a = base.getElementsByTagName('a');
	for(i=0;i<a.length;i++)
		if(/http:\/\/www\.sewvacdirect\.com.*html/.test(a[i].href))
			if(a[i].target!='_blank') a[i].onclick=function(){return(linkto(this.href));}
}

var iframe=false;
var prevhash=location.hash;

function linkto(link) {
	if(/https:/.test(link)) { return(true); } else {
		location.hash=link.replace('http://www.sewvacdirect.com/','').replace(/\#.*/,'');
		if(IE) { if(iframe.src==link) return(false); iframe.src="/tools/browse.php?url="+link }
		return(false);
	}
}

function checkhash(){
	if(prevhash!=location.hash) {
		if(/\.html/.test(location.hash)||(location.hash.replace('#','')=='')) {
			prevhash=location.hash;
			loadcontent('http://www.sewvacdirect.com/'+location.hash.replace('#',''));
		}
	}
	var hashtimer = setTimeout(checkhash,200);
}

function loadcontent(link) {
		var x = XMLHTTP();
		if(x) {
			x.open("POST",link,false);
			x.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			x.send("skinny=1");
			document.getElementById('content').innerHTML = x.responseText+'<'+'script language="javascript" src="/axroi/script.php?ref=http://www.sewvacdirect.com/&entry='+escape(unescape(link))+'"><'+'/script>';
			setupanchors(document.getElementById('content'));
			if(document.getElementById('newtitle')) {
				title='Sew Vac Direct - '+document.getElementById('newtitle').innerHTML.replace(/<.*?>/g,'').replace('&amp;','&');
				document.title=title;
			}
			document.getElementById('content').style.visibility='visible';
			return(false);
		} else { return(true); }
}

function additem(menutext, menulink, mclass) {
	uclass="menu1";
	if(mclass) uclass=mclass;
	document.write('<tr><td class="' + uclass + '"><a href="');
	document.write(menulink);
	document.write('">');
	document.write(menutext);
	document.write('</a></td></tr>');
}

function addcat(menutext) {
	document.write('<tr><td><a href=""><h5 onfocus="this.blur()">   ');
	document.write(menutext);
	document.write('</h5></a></td></tr>');
}

function submitform() {
	if(document.searchform.search_field.value!="") {
		var sfield=document.searchform.search_field.value;
		sfield=replace(sfield,"<","&lt;");
		sfield=replace(sfield,">","&gt;");
		sfield=replace(sfield,"'","&39;");
		sfield=replace(sfield,"(","&40;");
		sfield=replace(sfield,")","&41;");
		document.searchform.search_field.value=sfield;
		document.searchform.submit();
	}
	if(document.searchform.search_field.value=="") alert('Please enter a search term.\n(Example: "Craftmaster")');
}

function submitform2(formobj) {
	if(formobj.search_field.value!="") {
		var sfield=formobj.search_field.value;
		sfield=replace(sfield,"<","&lt;");
		sfield=replace(sfield,">","&gt;");
		sfield=replace(sfield,"'","&39;");
		sfield=replace(sfield,"(","&40;");
		sfield=replace(sfield,")","&41;");
		formobj.search_field.value=sfield;
		formobj.submit();
	}
	if(formobj.search_field.value=="") alert('Please enter a search term.\n(Example: "Craftmaster")');
}

function ShowMenu() {
	additem("<font color=#AA0000>Financing Available!</font>", "/creditapp");
	additem("Sewing Machines", "sewmachcats.html");
	additem("Sergers / Overlocks", "sergercats.html");
	additem("Accessories / Notions", "accessories.html");
	additem("Embroidery Machines", "embroidery.html");
	additem("Embroidery Accessories", "embacccats.html");
	additem("Sewing Furniture", "cabscats.html");
	additem("Quilting", "quilting.html");
	additem("Industrial Machines", "industrialsewing.html");
	additem("Vacuum Cleaners", "vaccats.html");
	additem("Presses & Irons", "ironsandpresses.html");
	additem("Closeout Specials", "closeoutspecials.html");
	additem("Parts", "machineparts.html");
}

function CreateLoginButtons(name) {
	var linktext1="";
	var linkurl1="";
	var linktext2="";
	var linkurl2="";
	var cookies=document.cookie;
	var start = cookies.indexOf(name + "=");
	var name = "";
	var start1;
	var end1;
	var tmp;
	var signed_in = -1;
	if(start != -1) {
		start = cookies.indexOf("=", start) +1;
		var end = cookies.indexOf("|", start);
		if(end != -1) {
			signed_in = cookies.indexOf("|yes", start);
			name = unescape(cookies.substring(start,end-1));
			if(signed_in != -1) {
				additem("<font color=#AA0000>View/Edit Account</font>", "https://www.sewvacdirect.com/sc/registration.cgi?func=3&storeid=*128d36215fda137f00118b&html_reg=html&prevlocation=" + window.location);
				additem("<font color=#AA0000>Sign Out</font>", "https://www.sewvacdirect.com/sc/registration.cgi?func=4&storeid=*128d36215fda137f00118b&html_reg=html&prevlocation=" + window.location);
			}
		}
	}
	if(signed_in == -1) {
		additem("<font color=#AA0000>Create New Account</font>", "https://www.sewvacdirect.com/sc/registration.cgi?func=1&storeid=*128d36215fda137f00118b&html_reg=html&prevlocation=" + window.location);
		additem("<font color=#AA0000>Account Login</font>", "https://www.sewvacdirect.com/sc/registration.cgi?func=2&storeid=*128d36215fda137f00118b&html_reg=html&prevlocation=" + window.location);
	}
}

var prodcount = 0;
var splitfreq = 5;
var totalprod = 20;
var prodstyle = 1;
var spacingw = 20;
var spacingh = 20;
var cellwidth = 102;
var cellheight = 102;
var maincolor = "#003399";
var highcolor = "#0066CC";
var textcolor = "#ffcc33";
var website = "http://www.sewvacdirect.com/";
var imagebase = "http://www.sewvacdirect.com/graphics/";

function changefrequency(splfre) { splitfreq = splfre; }

function changetotal(tprod) { totalprod = tprod; }

function changespacing(chgspace) {
	spacingw = chgspace;
	spacingh = chgspace;
}

function changestyle(chgstyle) { prodstyle = chgstyle; }

function changewidth(chgwidth) { cellwidth = chgwidth; }

function changeheight(chgheight) { cellheight = chgheight; }

function changecolors(cnorm, chigh, ctext) {
	maincolor=cnorm;
	highcolor=chigh;
	textcolor=ctext;
}

function changewebsite(cweb) { website = cweb; }

function changeimagebase(cweb) { imagebase = cweb; }

function mod(a, b) { return(((a % b) + b) % b); }

function replace(string, text, by) {
	var strLength = string.length, txtLength = text.length;
	if((strLength == 0) || (txtLength == 0)) return string;
	var i = string.indexOf(text);
	if((!i) && (text != string.substring(0,txtLength))) return string;
	if(i == -1) return string; var newstr = string.substring(0,i) + by;
	if(i+txtLength < strLength) newstr += replace(string.substring(i+txtLength,strLength),text,by);
	return newstr;
}

function addproduct(pname, plink, pimg, pprice, palt) {
	pname = replace(pname, "'", "&#146;");
	palt = replace(palt, '"', "&#148;");
	plink = replace(plink, "'", "&#146;");
	plink = replace(plink, '"', "&#148;");
	pimg = replace(pimg, "'", "&#146;");
	pimg = replace(pimg, '"', "&#148;");
	pprice = replace(pprice, "'", "&#146;");
	pprice = replace(pprice, '"', "&#148;");
	palt = replace(palt, "'", "&#146;");
	palt = replace(palt, '"', "&#148;");
	if(prodcount==0) {
		document.write('<table class="center post"><tr>');
	}
	if(prodcount != totalprod && prodcount != 0) {
		if(mod(prodcount, splitfreq) == 0) {
			document.write('</tr><tr><td colspan="' + (splitfreq*2) + '"><img src="/media/blank.gif" height=' + spacingh + ' /></td></tr><tr>');
		} else {
			document.write('<td><img src="/media/blank.gif" width=' + spacingw + '></td>');
		}
	}
	if(prodstyle == 1) {
		cellheight=149;
		document.write('<td style="width:' + cellwidth + 'px; height:'+cellheight+'px;" width="' + cellwidth + '" height="'+cellheight+'">');
		document.write('<TABLE cellpadding="0" cellspacing="0" border="0" style="width:' + cellwidth + 'px; height:'+cellheight+'px; border:1px solid '+maincolor+'; display: block; padding: 0px; margin: 0px; cursor: hand;" bgcolor="'+maincolor+'" onMouseover="this.bgColor=\''+highcolor+'\';" onMouseout="this.bgColor=\''+maincolor+'\';" onclick="window.location=\''+website+ plink + '\'" alt="" />');
		document.write('<tr style="height: 21px;"><td valign=center><center><a href="'+website+ plink + '" style="text-decoration: none; font-size:11px; font-weight:bold; color:'+textcolor+';">' + pname + '</a></td></tr>');
		document.write('<tr style="width: ' + cellwidth + 'px; height: 107px;"><td><a href="'+website+ plink + '"><img src="'+imagebase+pimg+'" border=0 width=' + (cellwidth - 2) + ' height=107 onmouseover="window.status=\'' + palt + '\'; return true;" onmouseout="window.status=\'\'; return true;" alt="' + palt + '"></a></td></tr>');
		document.write('<tr style="height: 21px;"><td valign=center><center><a href="'+website+ plink + '" style="text-decoration: none; font-size:11px; font-weight:bold; color:'+textcolor+';">' + pprice + '</a></td></tr></table></td>');
	} else if(prodstyle == 2) {
		if(pprice == "") imageheight = cellheight-15;
		else imageheight = cellheight-30;
		
		document.write('<td>');
		document.write('<table class="border" style="height: ' + cellheight + 'px; background-color: ' + maincolor + '; cursor: hand" bgcolor="' + maincolor + '" onMouseOver="this.style.backgroundColor=\'' + highcolor + '\'" onMouseOut="this.style.backgroundColor=\'' + maincolor + '\'" onClick="window.location=\'' + website + plink + '\'" alt="" />');
		document.write('<tr style="height: 15px"><td class="center"><a href="' + website + plink + '" style="text-decoration: none; font-size: 11px; font-weight: bold; color: ' + textcolor + '">' + pname + '</a></td></tr>');
		document.write('<tr><td class="center" style="width:' + cellwidth + 'px"><a href="' + website + plink + '"><img src="' + imagebase + pimg + '" width=' + cellwidth + ' height=' + imageheight + ' onMouseOver="window.status=\'' + palt + '\'; return true;" onmouseout="window.status=\'\'; return true" alt="' + palt + '"></a></td></tr>');
		if(pprice != "") document.write('<tr style="height: 15px"><td class="center"><a href="' + website + plink + '" style="text-decoration: none; font-size:11px; font-weight:bold; color:' + textcolor + '">' + pprice + '</a></td></tr>');
		document.write('</table></td>');
	}
	prodcount++;
	if(prodcount == totalprod) document.write('</tr></table>');
}

function addinfo(plink, pimg) {
	plink = replace(plink, "'", "&#146;"); plink = replace(plink, '"', "&#148;");
	pimg = replace(pimg, "'", "&#146;"); pimg = replace(pimg, '"', "&#148;");
	if(prodcount==0) {
		document.write('<TABLE width="200" cellpadding="0" cellspacing="0" border="0">');
		document.write('<tr>');
	}
	if((mod(prodcount, splitfreq)==0)&&(prodcount!=totalprod)&&(prodcount!=0)) {
		document.write('</tr><TR><TD colspan="' + (splitfreq * 2) + '" width="540" height="' + spacingh + '"><img src="/media/blank.gif" width=540 height=' + spacingh + '></TD></TR><TR>');
	}
	cellheight=149;
	document.write('<TD style="width: ' + spacingw + 'px;" width="' + spacingw + '" height="'+cellheight+'"><img src="/media/blank.gif" width=' + spacingw + ' height='+cellheight+'></td><td style="width:' + cellwidth + 'px; height:'+cellheight+'px;" width="' + cellwidth + '" height="'+cellheight+'">');
	document.write('<TABLE cellpadding="0" cellspacing="0" border="0" style="width:' + cellwidth + 'px; height:'+cellheight+'px; border:1px solid '+maincolor+'; display: block; padding: 0px; margin: 0px; cursor: hand;" bgcolor="'+maincolor+'" onMouseover="this.bgColor=\''+highcolor+'\';" onMouseout="this.bgColor=\''+maincolor+'\';" onclick="window.location=\''+website+ plink + '\'">');
	document.write('<tr style="width: ' + cellwidth + 'px; height: '+cellheight+'px;"><td style="padding: 1px;"><a href="'+website+ plink + '" style="text-decoration: none; font-size:11px; font-weight:bold; color:'+textcolor+';">'+pimg+'</a></td></tr></table></td>');
	prodcount++;
	if(prodcount==totalprod) document.write('</tr></table>');
}


function ActivateFlash() {
    var objects = document.getElementsByTagName("object");
    for (var i = 0; i < objects.length; i++)
    {
      objects[i].outerHTML = objects[i].outerHTML;
    }
}

// SEARCH SCRIPT
var timer;

function next20(n) {
	var i;
	timer=0;
	document.getElementById('sn'+n).style.display='none';
	for(i=n;i<n+20;i++) {
		if(document.getElementById('sr'+i)) { document.getElementById('sr'+i).style.display='';/* opacity('sr'+i,0,100,200); */}
	}
	document.getElementById('sn'+i).style.display='';
}

function opacity(id,opacStart,opacEnd,millisec) {
    var speed=Math.round(millisec/100);
//	if(!start) start=0;
//	var timer=start*speed;
	document.getElementById(id).style.display="block";
    if(opacStart>opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) { setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); timer++; }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++) { setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); timer++; }
    }
}

function changeOpac(opacity, id) {
	object=document.getElementById(id).style;
    if(typeof(object.opacity)!='undefined') object.opacity = (opacity / 100);
    if(typeof(object.MozOpacity)!='undefined') object.MozOpacity = (opacity / 100);
    if(typeof(object.KhtmlOpacity)!='undefined') object.KhtmlOpacity = (opacity / 100);
    if(typeof(object.filter)!='undefined') object.filter = "alpha(opacity=" + opacity + ")";
} 


// IMAGE BOX SCRIPT

var overlay,imgbox;

function showimgbox(imgsrc) {
  var img=new Image();
  img.style.background='#FFFFFF no-repeat center center url(/graphics/loading.gif)';
  img.src=imgsrc.src.replace('ss_size2','ss_size1');
  var ps=getPageSize();
  overlay=document.createElement('div');
  overlay.setAttribute('id','overlay');
  overlay.style.height=ps[1]+'px';
  imgbox=document.createElement('div');
  imgbox.setAttribute('id','imgbox');
  imgbox.innerHTML='<div>CLICK ANYWHERE TO RETURN TO PAGE</div>';
  imgbox.appendChild(img);
  overlay.onclick=function(){ document.body.removeChild(overlay); document.body.removeChild(imgbox); }
  imgbox.onclick=overlay.onclick;
  document.body.appendChild(overlay);
  document.body.appendChild(imgbox);
}

function getPageSize(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth; yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){
		xScroll = document.body.scrollWidth; yScroll = document.body.scrollHeight;
	} else {
		xScroll = document.body.offsetWidth; yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	if(yScroll < windowHeight){ pageHeight = windowHeight; } else { pageHeight = yScroll; }
	if(xScroll < windowWidth){ pageWidth = windowWidth; } else { pageWidth = xScroll; }
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}

// END IMAGE BOX SCRIPT

// JAVASCRIPT FOR ASK QUESTION BUTTON
  var sq,product='',fromemail='',post='',alerts='',fromname='',echeck=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  function question_form_send(prod) {
	fromemail=''; post='Referer: '+location.href+'\n'; alerts='';product=prod;
	if(document.getElementById('question_form_name').value.length<1) { alerts+='Please enter your first name.\n'; } else { fromname=document.getElementById('question_form_name').value; post+='Name: '+fromname+'\n'; }
	if(document.getElementById('question_form_zip').value.replace(/[^0-9]/g,'').length!=5) { alerts=alerts; } else { post+='Zip Code: '+document.getElementById('question_form_zip').value+'\n'; }
	if(document.getElementById('question_form_email').value.length<1) { alerts+='Please enter an email address.\n'; }
	else { if(!echeck.test(document.getElementById('question_form_email').value)) { alerts+='The email address you have entered is not valid.\n'; } else { fromemail=document.getElementById('question_form_email').value; post+='Email Address: '+fromemail+'\n'; } }
	if(document.getElementById('question_form_question').value.length<1) { alerts+='Please enter an question.\n'; } else { post+='==========\n'+document.getElementById('question_form_question').value+'\n'; }
	if(alerts!='') {
	  alert(alerts);
	} else {
	  if(document.getElementById('question_form_submit').innerHTML!="Submitting.. Please Wait") {
		sq=XMLHTTP();
		if(sq) {
		  document.getElementById('question_form_submit').innerHTML="Submitting.. Please Wait";
		  document.getElementById('question_form_submit').disabled=true;
		  sq.open('POST','/submitquestion.php',true);
		  sq.onreadystatechange=function(){if(sq.readyState==4||sq.readyState=="complete"){
			if(sq.responseText=="success") { alert('Thank you! Your email has been sent!'); document.getElementById('question_form_question').value=''; document.getElementById('question_form_submit').innerHTML="Submit Question &raquo;"; document.getElementById('question_form_submit').disabled=false; document.getElementById('question').className=''; } else { alert(sq.responseText); }
		  }};
		  sq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		  sq.send('contact=questions&subject='+encodeURIComponent('Question On: '+product+'.')+'&name='+encodeURIComponent(fromname)+'&email='+encodeURIComponent(fromemail)+'&content='+encodeURIComponent(post));
		}
	  }
	}
  }

  function prodquestion_toggle() { var prodquestion=document.getElementById('prodquestion_full'); if(prodquestion.style.display=='block') { prodquestion.style.display='none'; } else { prodquestion.style.display='block'; document.getElementById('giftcert_full').style.display='none'; } }
// JAVASCRIPT FOR GIFT CERTIFICATE
  var sq,product='',fromemail='',post='',alerts='',fromname='',echeck=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  function giftcert_submit(prod) {
	fromemail=''; post='Referer: '+location.href+'\n'; alerts='';product=prod;
	if(document.getElementById('giftcert_name').value.length<1) { alerts+='Please enter your first name.\n'; } else { fromname=document.getElementById('giftcert_name').value; post+='Name: '+fromname+'\n'; }
//alert(document.getElementById('giftcert_phone').value.replace(/[^0-9]/g,''));
	if(document.getElementById('giftcert_phone').value.replace(/[^0-9]/g,'').length<10) { alerts+='Please enter a valid phone number.\n'; } else { post+='Phone Number: '+document.getElementById('giftcert_phone').value.replace(/[^0-9]/g,'')+'\n'; }
	if(document.getElementById('giftcert_email').value.length<1) { alerts+='Please enter an email address.\n'; }
	else { if(!echeck.test(document.getElementById('giftcert_email').value)) { alerts+='The email address you have entered is not valid.\n'; } else { fromemail=document.getElementById('giftcert_email').value; post+='Email Address: '+fromemail+'\n'; } }
//	if(document.getElementById('giftcert_question').value.length<1) { alerts+='Please enter an question.\n'; } else { post+='==========\n'+document.getElementById('prodquestion_question').value+'\n'; }
	if(alerts!='') {
	  alert(alerts);
	} else {
	  if(document.getElementById('giftcert_submitbutton').value!="Submitting.. Please Wait.") {
		sq=XMLHTTP();
		if(sq) {
		  document.getElementById('giftcert_submitbutton').value="Submitting.. Please Wait.";
		  document.getElementById('giftcert_submitbutton').disabled=true;
		  sq.open('POST','/submitform.php',true);
		  sq.onreadystatechange=function(){if(sq.readyState==4||sq.readyState=="complete"){
			if(sq.responseText=="success") { alert('Thank you! You have successfully submitted your entry!'); giftcert_toggle(); document.getElementById('giftcert_submitbutton').value="Submit Entry"; document.getElementById('giftcert_submitbutton').disabled=false; } else { alert(sq.responseText); }
		  }};
		  sq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		  sq.send('contact=giftcert&subject='+encodeURIComponent('Gift Certificate Entry')+'&name='+encodeURIComponent(fromname)+'&email='+encodeURIComponent(fromemail)+'&content='+encodeURIComponent(post));
		}
	  }
	}
  }
  function giftcert_toggle() { var giftcert=document.getElementById('giftcert_full'); if(giftcert.style.display=='block') { giftcert.style.display='none'; } else { giftcert.style.display='block'; document.getElementById('prodquestion_full').style.display='none'; } }

// JAVASCRIPT FOR SHIPPING CALCULATOR

var calculator = new Image(); calculator.src='/media/calculator.gif';
var calculating = new Image(); calculating.src='/media/calculating.gif';

function calculateshipping(w,o,z) {
	if(w===undefined) w = document.getElementById('shippingcalculatorweight').value;
	if(o===undefined) o = document.getElementById('shippingcalculatoroptions').value;
	if(z===undefined) z = document.getElementById('shippingcalculatorzip').value;
	if(z.length<5) { alert('"'+z+'" is not a valid zip code.'); return false; }
	document.getElementById('shipcalc').className='complete';
	var req = XMLHTTP();
	document.getElementById('shipcalc_table_list').innerHTML='<center><b>Please wait while your shipping is calculated... </b><br><img src="/media/calculating.gif"></center>';
	parameters='zip='+z+'&weight='+w+'&options='+o;
	req.open('POST','/tools/shippingcalculator.php',true);
	req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	req.onreadystatechange=function(){if((req.readyState==4)&&(req.status==200)){document.getElementById('shipcalc_table_list').innerHTML=req.responseText;if(req.responseText=='')document.getElementById('shipcalc').className='clicked';}}
	req.send(parameters);
	return false;
}

function calculateshippingkeypress(e) {
	if(window.event){e=window.event.keyCode;}else{e=e.which;}
	if(e==13) { calculateshipping(); return(false); }
	return(true);
}


// MINICART

function DisplayMiniCart() {
	return false();
        var cookies=document.cookie,start=cookies.indexOf("ss_cart_0001128840="),cartvalues="",linecount=0,start1,end1,tmp;
        var minicart="<a href=\"/sc/order.cgi?storeid=*10fdd818e117dff10997&function=show\">Click Here to View Cart</a>";
        if(start==-1){}else{
        	minicart+="<table cellspacing=\"0\" cellpadding=\"0\">\n";
        	start=cookies.indexOf("=",start)+1;var end=cookies.indexOf(";",start);	
        	if(end==-1)end=cookies.length;
        	cartvalues=unescape(cookies.substring(start,end));
        	start=0;
        	while((start=cartvalues.indexOf("|",start))!=-1){
        		start++;end=cartvalues.indexOf("|", start);
        		if(end!=-1){
        			linecount++;
        			if(linecount==3){ start1=start;end1=end; minicart+="<tr><td class=\"header\">Product</td><td class=\"header\">Price</td></tr>"; }
        			if(linecount>3){
        				tmp=cartvalues.substring(start,end);
        				colon=tmp.indexOf(":",0);
        				minicart+="<tr><td>("+tmp.substring(0,colon)+") ";
        				colon2 = tmp.indexOf(":", colon+1);
        				minicart+=tmp.substring(colon2+1,end - start);
        				minicart+="</td><td class=\"price\">"+tmp.substring(colon+1,colon2)+"</td></tr>\n";
        			}
        			start = end;
        		} else { break; }
        	}
        	minicart+="<tr><td class=\"subtotal\">Subtotal:</td><td class=\"price\">";
        	tmp = cartvalues.substring(start1, end1);
        	colon = tmp.indexOf(":", 0);
        	minicart+=tmp.substring(colon+1, end1-start1);
        	minicart+="</td></tr></table>\n";
        }
		if(mc=document.getElementById('minicart')) mc.innerHTML=minicart;
}

// ACCOUNT INFORMATION

function DisplayAccount(name) {
	var cookies=document.cookie;
	var start = cookies.indexOf(name + "=");
	var name = "";
	var start1;
	var end1;
	var tmp;
	var signed_in = -1;
	if (start != -1) {
		start = cookies.indexOf("=", start) +1;
		var end = cookies.indexOf("|", start);
		if (end != -1) {
			signed_in = cookies.indexOf("|yes", start);
			name = unescape(cookies.substring(start,end-1));
		}
	}
	var account='';
	if (signed_in == -1) {
		account+='<b class="center" style="font-size:11px;color:#808080;line-height:12px;">You do not have to create an account to shop with us.<b>';
		account+="<a href=\"http://www.sewvacdirect.com/sc/registration.cgi?func=1&storeid=*0e4aa6f9147d701fc9&html_reg=html\"><img src=\"/images/cr_create.gif\" style=\"width:160px;height:30px;\" /></a>";
		account+="<a href=\"http://www.sewvacdirect.com/sc/order.cgi?func=2&storeid=*0e4aa6f9147d701fc9&html_reg=html\"><img src=\"/images/cr_login.gif\" style=\"width:160px;height:30px;\" /></a>";
	} else {
		account+="<b>LOGGED IN</b><br /><i>" + name + "</i>";
		account+="<a href=\"http://www.sewvacdirect.com/sc/registration.cgi?func=3&storeid=*0e4aa6f9147d701fc9&html_reg=html\"><img src=\"/images/cr_view.gif\" style=\"width:160px;height:30px;\" /></a>";
		account+="<a href=\"http://www.sewvacdirect.com/sc/registration.cgi?func=4&storeid=*0e4aa6f9147d701fc9&html_reg=html\"><img src=\"/images/cr_logout.gif\" style=\"width:160px;height:30px;\" /></a>";
	}
	if(ac=document.getElementById('account')) ac.innerHTML=account;

}

// VALIDATE CUSTOM FORM REQUIREMENTS

function ValidateCustom(message){
	var custom,entry=new String('');
    for(var i=1; i<arguments.length; i++) {
		custom=$('custom_'+arguments[i]);
		//if(custom.value.replace(/[^a-zA-Z0-9]/,'')==''){
		//	alert('PLEASE FILL OUT ALL REQUIRED INFORMATION:\n\n'+message+': '+arguments[i]+'\n\nPress OK to enter this information.');
		//	custom.style.background='#FFE0E0';
		//	custom.onkeypress=function(){this.style.background='#FFFFFF'};
		//	custom.focus();return(false);
		//} 
		entry+=(i>1?'\n':'')+arguments[i]+': '+custom.value.trim();
	}
	$('optionbox').value=entry;
	return(true);
}

// GOOGLE ANALYTICS

var _uacct="UA-318307-1";
function loadGA() {
	var ga = document.createElement('script');
	ga.setAttribute('type', 'text/javascript');
	ga.setAttribute('src', 'http://www.google-analytics.com/urchin.js');
	//document.body.appendChild(ga);
//	ga.setAttribute('onload','_uacct="UA-318307-1";urchinTracker();if(debug)alert(_uacct);');
//	var head=document.getElementsByTagName('head').item(0);
//	head.insertBefore(ga,head.firstChild);
}

// ONLOAD EVENTS

historyChange = function(newLocation) {
	//alert(newLocation);
	if(!/https?:/.test(newLocation)) {
		var anchor = document.createElement('a');
		anchor.href = 'http://www.sewvacdirect.com/'+newLocation.replace('http://www.sewvacdirect.com/','');
		loadcontent(anchor);
	}
}

/*$(document).ready(function(){
	DOMloaded=true;
	//addTracker();
    updatewidth();
});*/

function addTracker(code){
	try{
		var gaURL = 'https://ssl.google-analytics.com/ga.js';
		$.getScript(gaURL,function(){
			var pageTracker = _gat._getTracker('UA-318307-1');
			pageTracker._setDomainName("none");
			pageTracker._setAllowLinker(true);
			pageTracker._trackPageview();
			//$('a').each(function(){
			//	var u = $(this).attr('href');
			//	if(!(/sewvacdirect\.com/i.test(u)))$(this).click(function(){pageTracker._link(u);return(false);});
			//});
		});
	} catch(err) {}
}


