function helpPop(id)
{
	var popurl="help.jsp?id=" + id 
	winpops=window.open(popurl,"","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=400,height=500");
}

var clicked = false;

function postPage(qs){	
	
	if (clicked != true){
		document.ItemForm.action = qs;
		clicked = true;		
		document.ItemForm.submit();				
	}
}

function processSubmit(form){	
	document["subImg"].src = "i/processing.gif"; ;
	document.getElementById("subHref").href = "#submit";	
   	form.submit();
}

function setSelectedItem(svalue){		
	document.ItemForm.o.options[svalue].selected = true;	
}

function changePicture(picture){
	document.changer.src="../"+ picture + "";
	document.getElementById('changer1').href = "../" + picture + "";	
}

function change_image(dropdown) {
	//Used for Select Boxes	
	document["foldImage"].src =  escape(dropdown.options[dropdown.selectedIndex].id);
	document["foldImage"].title= dropdown.options[dropdown.selectedIndex].text;	
	document.getElementById("foldLink").href = "/" + escape(dropdown.options[dropdown.selectedIndex].id) + "";	
}

function calcPrice(){
	if (priceValidate()){
		document.ItemForm.submit();
	}
}

function formatCurrency(price){
	var fPrice = 0.00;	
	fPrice = price.toFixed(2);
	document.write(fPrice);
}

function reSort(qs,obj){	
	var sortId;	
	sortId = obj.value;			
	qs = qs + sortId
	document.ItemForm.action = qs;		
	document.ItemForm.submit();				
	
}

function refresh(page){
	window.location = page;		
}

function enableField(x)
{	
	inktype = document.ItemForm.INKTYPES[x].value;	
		
	if (inktype == 3){		
		//display InkId box for pms colors
		document.ItemForm.PMSINKS[x].style.width="140";
		document.ItemForm.PMSINKS[x].value = "Enter PMS #";
		document.ItemForm.PMSINKS[x].style.visibility ="visible";		
		document.ItemForm.STANDARDINKS[x].style.visibility ="hidden";				
		document.ItemForm.STANDARDINKS[x].value = "0";
		document.ItemForm.STANDARDINKS[x].style.width="0";		
	}else if (inktype == 2){	
		//display standardInk box
		document.ItemForm.STANDARDINKS[x].style.width="140";	
		document.ItemForm.STANDARDINKS[x].style.visibility ="visible";
		document.ItemForm.PMSINKS[x].style.visibility ="hidden";				
		document.ItemForm.PMSINKS[x].value = "0";
		document.ItemForm.PMSINKS[x].style.width="0";	
	} else {
		//hide both boxes
		document.ItemForm.PMSINKS[x].style.visibility ="hidden";
		document.ItemForm.PMSINKS[x].value = "0";
		document.ItemForm.PMSINKS[x].style.width="0";
		document.ItemForm.STANDARDINKS[x].style.visibility ="hidden";		
		document.ItemForm.STANDARDINKS[x].value = "0";				
		document.ItemForm.STANDARDINKS[x].style.width="0";	
	}
}

function enableCoverField(x)
{	
	inktype = document.ItemForm.COVERINKTYPES[x].value;	
		
	if (inktype == 3){		
		//display InkId box for pms colors
		document.ItemForm.COVERPMSINKS[x].style.width="140";
		document.ItemForm.COVERPMSINKS[x].value = "Enter PMS #";
		document.ItemForm.COVERPMSINKS[x].style.visibility ="visible";		
		document.ItemForm.COVERSTANDARDINKS[x].style.visibility ="hidden";				
		document.ItemForm.COVERSTANDARDINKS[x].value = "0";
		document.ItemForm.COVERSTANDARDINKS[x].style.width="0";		
	}else if (inktype == 2){	
		//display standardInk box
		document.ItemForm.COVERSTANDARDINKS[x].style.width="140";	
		document.ItemForm.COVERSTANDARDINKS[x].style.visibility ="visible";
		document.ItemForm.COVERPMSINKS[x].style.visibility ="hidden";				
		document.ItemForm.COVERPMSINKS[x].value = "0";
		document.ItemForm.COVERPMSINKS[x].style.width="0";	
	} else {
		//hide both boxes
		document.ItemForm.COVERPMSINKS[x].style.visibility ="hidden";
		document.ItemForm.COVERPMSINKS[x].value = "0";
		document.ItemForm.COVERPMSINKS[x].style.width="0";
		document.ItemForm.COVERSTANDARDINKS[x].style.visibility ="hidden";		
		document.ItemForm.COVERSTANDARDINKS[x].value = "0";				
		document.ItemForm.COVERSTANDARDINKS[x].style.width="0";	
	}
}

function setNames(){
	var inktypes = "No Ink";
	var standardInks = "No Ink";
	var options = "None";
	
	if (document.ItemForm.INKTYPES[0][0] == null){		
		inktypes = inktypes + "," + document.ItemForm.INKTYPES[document.ItemForm.INKTYPES.selectedIndex].text;
		inktypes = inktypes.replace("No Ink,","");
		document.ItemForm.INKTYPENAMES.value = inktypes;
	} else {
		for (x=0; x<document.ItemForm.INKTYPES.length; x++){
			inktypes = inktypes + "," + document.ItemForm.INKTYPES[x][document.ItemForm.INKTYPES[x].selectedIndex].text;
		}
		inktypes = inktypes.replace("No Ink,","");
		document.ItemForm.INKTYPENAMES.value = inktypes;
	}		
	
	if (document.ItemForm.STANDARDINKS[0][0] == null){
		if (document.ItemForm.STANDARDINKS.selectedIndex == 0){
			standardInks = standardInks + "," + "0";
		} else {
			standardInks = standardInks + "," + document.ItemForm.STANDARDINKS[document.ItemForm.STANDARDINKS.selectedIndex].text;
		}
		standardInks = standardInks.replace("No Ink,","");
		document.ItemForm.STANDARDINKNAMES.value = standardInks;
	} else {
		for (x=0; x<document.ItemForm.STANDARDINKS.length; x++){
			if (document.ItemForm.STANDARDINKS[x].selectedIndex == 0){
				standardInks = standardInks + "," + "0";
			} else {
				standardInks = standardInks + "," + document.ItemForm.STANDARDINKS[x][document.ItemForm.STANDARDINKS[x].selectedIndex].text;
			}
		}
		standardInks = standardInks.replace("No Ink,","");
		document.ItemForm.STANDARDINKNAMES.value = standardInks;
	}		
	
	if (document.ItemForm.OPTIONSNAMES != null){
		if (document.ItemForm.OPTIONS[0][0] == null){
			document.ItemForm.OPTIONSNAMES.value = document.ItemForm.OPTIONS[document.ItemForm.OPTIONS.selectedIndex].text
		} else {
			for (x=0; x<document.ItemForm.OPTIONS.length; x++){
				if (document.ItemForm.OPTIONS[x].selectedIndex != 0){
					options = options + "," + document.ItemForm.OPTIONS[x][document.ItemForm.OPTIONS[x].selectedIndex].text;
				}
			}
			options = options.replace("None,","");
			if (options != "None") document.ItemForm.OPTIONSNAMES.value = options;
		}	
	}	
	
	if (document.ItemForm.COVERSTOCKID != null){
		var coversummary = "";
		if (document.ItemForm.COVERSTOCKID.selectedIndex != 0){
			coversummary = coversummary + "Stock - " + document.ItemForm.COVERSTOCKID[document.ItemForm.COVERSTOCKID.selectedIndex].text + ";";
		}
		
		if (document.ItemForm.COVERINKTYPES[0] == null){
			if (document.ItemForm.COVERINKTYPES.selectedIndex != 0){
					coversummary = coversummary + "Side " + document.ItemForm.COVERINKSIDES.value + " - " + document.ItemForm.COVERINKTYPES[document.ItemForm.COVERINKTYPES.selectedIndex].text;			
					
					if (document.ItemForm.COVERSTANDARDINKS.selectedIndex != 0){
						coversummary = coversummary + " - " + document.ItemForm.COVERSTANDARDINKS[document.ItemForm.COVERSTANDARDINKS.selectedIndex].text;
					}			
					if (document.ItemForm.COVERPMSINKS.value != 0){
						coversummary = coversummary + " - " + document.ItemForm.COVERPMSINKS.value;
					}
					coversummary = coversummary + ";";					
			}
		} else {				
			for(x=0; x<document.ItemForm.COVERINKSIDES.length; x++){
				if (document.ItemForm.COVERINKTYPES[x].selectedIndex != 0){
					coversummary = coversummary + "Side " + document.ItemForm.COVERINKSIDES[x].value + " - " + document.ItemForm.COVERINKTYPES[x][document.ItemForm.COVERINKTYPES[x].selectedIndex].text;			
					
					if (document.ItemForm.COVERSTANDARDINKS[x].selectedIndex != 0){
						coversummary = coversummary + " - " + document.ItemForm.COVERSTANDARDINKS[x][document.ItemForm.COVERSTANDARDINKS[x].selectedIndex].text;
					}			
					if (document.ItemForm.COVERPMSINKS[x].value != 0){
						coversummary = coversummary + " - " + document.ItemForm.COVERPMSINKS[x].value;
					}
					coversummary = coversummary + ";";			
				}			
			}
		}
		document.ItemForm.COVERSUMMARY.value = coversummary;
	}			
}

function enablePages(dropdown){
	
	if (document.ItemForm.pages != null){
		var sizeid = dropdown.value;
		var pageBoxes = document.ItemForm.pages.length;
		
		for (x =0; x < pageBoxes; x++){
			document.ItemForm.pages[x].style.visibility ="hidden";		
			document.ItemForm.pages[x].style.width="0";	
			document.ItemForm.pages[x].selectedIndex = 0;
			document.ItemForm.CSPID.value = "0";
		}	
		
		if (sizeid != 0){
			document.getElementById(sizeid).style.width="175";	
			document.getElementById(sizeid).style.visibility ="visible";
		}
	}
}

function setCSPID(dropdown){
	document.ItemForm.CSPID.value = dropdown.value;
}

function shippingWindow(){
	var checkvalue;
	var checkfield;
	
	var stockid = document.ItemForm.STOCKID.value;
	var sizeid = document.ItemForm.SIZEID.value;
	var cspid = document.ItemForm.CSPID.value;
	var qty = document.ItemForm.QTY.value;
	
	if (priceValidate()){				
		checkfield = document.ItemForm.zip;
		checkvalue = document.ItemForm.zip.value;
		if (isNaN(checkvalue) || checkvalue.length != 5) {  	
		  	checkfield.focus();
			checkfield.select();
		  	alert("This must be a 5-digit zip code");	  		  	
		} else {
			var url = "shipestimator.jsp?zip=" + checkvalue + "&stockid=" + stockid + "&sizeid=" + sizeid + "&cspid=" + cspid + "&qty=" + qty;
			open_window(url, 600, 400);
		}
	}
}

function open_window(newwin, width, height) {	
	flyout=window.open(newwin, "popup_sizing", "width=" + width + ",height=" + height + ",menubar=no,toolbar=no,resizeable=no,status=no,scrollbars=yes,center=1");
	flyout.focus();
}

function priceChange(){
	var elementType = "";
	var elementName = "";
	for (x=0;x<document.ItemForm.elements.length;x++){
		elementType = document.ItemForm.elements[x].type;
		elementName = document.ItemForm.elements[x].name;
		if ((elementType == "select-one" || elementType == "text") && elementName != "zip"){
			if (isChanged(document.ItemForm.elements[x])){
				alert("Price must be recalculated");
				return true;
			}
		}
	}
	return false;
}

function priceValidate(){	
	var printSelected = false;

	checkfield = document.ItemForm.SIZEID;
	if (checkfield.selectedIndex == 0) {
  		checkfield.focus();
  		alert("Please Select a Size");
  		return false;
  	}
  	
  	if (document.ItemForm.pages != null){
  		checkvalue = document.ItemForm.CSPID.value;
		if (checkvalue == 0) {	  		
	  		alert("Please Select Number of Pages");
	  		return false;
	  	}
  	}
  	
  	checkfield = document.ItemForm.STOCKID;
	if (checkfield.selectedIndex == 0) {
  		checkfield.focus();
  		alert("Please Select a Stock");
  		return false;
  	}
  	
  	checkfield = document.ItemForm.QTY;
	if (checkfield.selectedIndex == 0) {
  		checkfield.focus();
  		alert("Please Select a qty");
  		return false;
  	}
  	
  	if (document.ItemForm.INKTYPES[0][0] == null){
  		checkfield = document.ItemForm.INKTYPES;
  		if (checkfield.selectedIndex == 0){
  			checkfield.focus();
  			alert("Please Select an Ink");
  			return false;
  		}
  	} else {
	  	for (x=0; x<document.ItemForm.INKTYPES.length; x++){
			checkfield = document.ItemForm.INKTYPES[x];
			if (checkfield.selectedIndex != 0){
	  			printSelected = true;
  			}
		}
		if (!printSelected){
			alert("Please select at least 1 ink");
			return false;
		}
	}
  	
  	//if (document.ItemForm.COVERSTOCKID != null){
  	//	checkfield = document.ItemForm.COVERSTOCKID;
	//	if (checkfield.selectedIndex == 0) {
	//  		checkfield.focus();
	// 		alert("Please Select a Cover Stock");
	//  		return false;
	//  	}  	
  	//}  	
  	return true;
}

function addToCart(){
	if (priceValidate()){
		if (!priceChange()) postPage('addtocart.jsp');
	}
}

function protectmail(name,address,style,subject) {
	document.write('<a class="' + style + '" href=mailto:' + name + '@' + address + '?subject=' + subject + '>' + name + '@' + address + '</a>');
}

function bookmarksite(title,url){
if (window.sidebar) // firefox
window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
var elem = document.createElement('a');
elem.setAttribute('href',url);
elem.setAttribute('title',title);
elem.setAttribute('rel','sidebar');
elem.click();
}
else if(document.all)// ie
window.external.AddFavorite(url, title);
}

