//pre-load for menu rollover images
home0 = new Image;
home0.src = "images/home0.jpg";
home1 = new Image;
home1.src = "images/home1.jpg";
FAQ0 = new Image;
FAQ0.src = "images/FAQ0.jpg";
FAQ1 = new Image;
FAQ1.src = "images/FAQ1.jpg";
contact0 = new Image;
contact0.src = "images/contact0.jpg";
contact1 = new Image;
contact1.src = "images/contact1.jpg";


addbutton = false //set var addbutton to prevent form submission, except by clicking add to cart button.
buypan = 

function findmouse(){ if (document.all) getMouseLoc(); }//IE only

function Point(x,y) {  this.x = x; this.y = y; }
mouseLocation = new Point(-500,-500);

function getMouseLoc(e)
{
  if(document.all) //IE only
  {
    mouseLocation.x = event.x + document.body.scrollLeft;
    mouseLocation.y = event.y + document.body.scrollTop;
  }
  return true;
}

function pickfont(itemnumber, tab) {
	if(tab) {tabstring = "&tab=" + tab;} else {tabstring = "";}
	var fontwindow = window.open("./fontview/fontview.php?itemnumber=" + itemnumber + tabstring, "fontname", "dependent=1, height=440, width=490");
	fontwindow.focus();
}

function pickcolor(target, primary) {
	target.style.backgroundColor=target.options[target.selectedIndex].style.backgroundColor;
	target.style.color=target.options[target.selectedIndex].style.color;
	if (primary) document.getElementById(primary).style.backgroundColor=target.options[target.selectedIndex].style.color;
}

function validate(targetform, checklist) {
	if(!addbutton) return false;
	failed=false;		//this function accepts a literal referance to the form, and an array of references to info needing validation
	errormessage="";
	os0="";
	for(x=0; checklist[x]; x++) {
			if(checklist[x].name == "glasscheck") { 
				if(checklist[x].checked == false) { 
					failed=true;
					errormessage+="You must acknowledge you buying both a pan and etching as seperate items"+ "\n"; 
				}
			}
			if (checklist[x].value=="") {
				failed=true;
				errormessage+="ERROR:  Missing "+ checklist[x].name
				
				if (checklist[x].name == "date") { errormessage+=", if you don't want an \"Est. Date\" please type \"None\" in the date field"; }
				errormessage+="\n";
			}
			else {
				if(checklist[x].type=='checkbox'){
					os0 += " " + checklist[x].name + "=" + checklist[x].checked; 
				} else {
					os0 += " " + checklist[x].name + "=" + checklist[x].value;
				}
			}
	}

	if (failed) {
		alert(errormessage);
		return false;
	}
	targetform.os0.value=os0;
	targetform.amount.disabled = false; //amount can not be disabled when submitted to paypal
}

function displaycolor(cssid, target, text, form) {
	var len = 15;
	if(document.getElementById('vinyllist')) document.getElementById('vinyllist').style.display = "none"
	if(document.getElementById('paintlist')) document.getElementById('paintlist').style.display = "none"
	if(document.all) { //IE only
		document.getElementById(cssid).style.position = "absolute";
		document.getElementById(cssid).style.posTop = mouseLocation.y + document.body.parentNode.scrollTop + 35;
	}
	document.getElementById(cssid).style.display = "block";
	colorTarget=target;
	colorText = document.getElementById(text);
	if (colorText) {
	   var trunc = colorText.innerHTML;
	   if (trunc.length > len) {
	   trunc = trunc.substring(0, len);
		colorText.innerHTML = trunc;
	}
	}
	formTarget=form;
}
function truncate() {
  var len = 15;
  var p = document.getElementById('truncateMe');
  if (p) {
    var trunc = p.innerHTML;
    if (trunc.length > len) {

      /* Truncate the content of the P, then go back to the end of the
         previous word to ensure that we don't truncate in the middle of
         a word */
      trunc = trunc.substring(0, len);
      trunc = trunc.replace(/\w+$/, '');

      /* Add an ellipses to the end and make it a link that expands
         the paragraph back to its original size */
      trunc += '<a href="#" ' +
        'onclick="this.parentNode.innerHTML=' +
        'unescape(\''+escape(p.innerHTML)+'\');return false;">' +
        '<span style="font-size: 10px;">[ more ... ]</span><\/a>';
      p.innerHTML = trunc;
    }
  }
}



function selectcolor(selected) {
	var len = 9;
	colorTarget.style.backgroundColor = selected.style.backgroundColor;
	selected.parentNode.parentNode.style.display = 'none';
	colorText.value = selected.innerHTML;
	if (colorText) {
	   var trunc = colorText.value;
	   if (trunc.length > len) {
	   trunc = trunc.substring(0, len);
		colorText.value = trunc;
		selected.innerHTML = trunc;
	}
	}
	showfont(formTarget);
	
}

function showfont(itemnumber) {
	color="";
	if (!itemnumber) itemnumber=0;  //pages using only 1 item don't require an item number
	if (document.forms[itemnumber].fonttype.value == "") return false;  //abort if no font has been selected
	if (document.forms[itemnumber].inscription) { inscription = document.forms[itemnumber].inscription.value;}
	if (inscription=="") return false //prevent inscription from being completely blank
	primaryColorLocation = 'primary' + itemnumber;  //concatenate name of location for primary color
	if (document.getElementById(primaryColorLocation)) {
		color = "&tcolor=" + document.getElementById(primaryColorLocation).style.backgroundColor.replace("#",""); //replace() strips the # from string
	}
	secondaryColorLocation = 'secondary' + itemnumber;  //concatenate name of location for secondary color
	if (bglocation = document.getElementById(secondaryColorLocation)) {
		if (bglocation.selectedIndex < 0) {
			color += "&bcolor=" + bglocation.options[bglocation.selectedIndex].style.backgroundColor.replace("#",""); //replace() strips the # from string
		} else {
			color += "&bcolor=" + bglocation.style.backgroundColor.replace("#",""); //replace() strips the # from string
		}
	}
	openstring = "fontview/font.php?fontname=" + document.forms[itemnumber].fonttype.value + "&usertext=" + inscription + "&textheight=35" + color;
	imagename = 'fontimage' + itemnumber;
	document.images[imagename].src=openstring;
}

function calculate(itemnumber) { //calculate cost of vinyl sticker
	if (!itemnumber) itemnumber = 0;
	imagename = 'fontimage' + itemnumber;
	if(document.forms[itemnumber].height) {
		document.forms[itemnumber].width.value = (document.forms[itemnumber].height.value * document.images[imagename].width / document.images[imagename].height).toFixed(2);
		if (document.forms[itemnumber].height.value<=22) {rate=12;}
		if (document.forms[itemnumber].height.value<=12) {rate=8;}
		if (document.forms[itemnumber].height.value<=6) {rate=5;}
		if (document.forms[itemnumber].height.value>22) {
			alert("We are unable to cut vinyl taller than 22\"\nPlease select a smaller Height value");
			document.forms[itemnumber].height.value=22; //prevent irritating popups by forcing height back down to acceptable number.
			return false;    //do not continue calculating cost on over-height request
		}		
		document.forms[itemnumber].amount.value = (Math.ceil(document.forms[itemnumber].width.value) * rate/12).toFixed(2); //round up to next inch, convert rate to inch, multiply, force 2 decimal points
	}
} //end function calculate

function quote(selected) {
	window.scroll(0,150); //move upscreen to order form.
	document.forms[0].inscription.value = selected.innerHTML;
	showfont();
}

function imageswitch(month) {
	imageList = Array('product/nameframehalloween.jpg',
							'product/nameframepumpkin.jpg',
							'product/nameframechristmas.jpg');
	if (month=='') { return imageList[7]; } //default picture
	if (month=='January') { return imageList[0]; }
	if (month=='February') { return imageList[1]; }
	if (month=='March') { return 'product/photona.jpg'; }
	if (month=='April') { return imageList[2]; }
	if (month=='May') { return 'product/photona.jpg'; }
	if (month=='June') { return 'product/photona.jpg'; }
	if (month=='July') { return imageList[3]; }
	if (month=='August') { return 'product/photona.jpg'; }
	if (month=='September') { return imageList[4]; }
	if (month=='October') { return imageList[5]; }
	if (month=='November') { return imageList[6]; }
	if (month=='December') { return imageList[7]; }
	if (month='random') { return imageList[Math.floor(Math.random()*imageList.length)];	}
}


