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");
}

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=no,center=1");
	flyout.focus();
}

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 postMulti(form,page){	
	document["subImg"].src = "/i/processing.gif"; ;
	document.getElementById("subHref").href = "#submit";	
	form.encoding = "multipart/form-data";
	form.action = page;
   	form.submit();
}

function setSelectedItem(svalue){		
	document.ItemForm.o.options[svalue].selected = true;	
}

function calcPrice(){
	var selectedItem = document.ItemForm.PriceBox.selectedIndex;
	var qty = document.ItemForm.PriceBox.options[selectedItem].text;
	var unitPrice = document.ItemForm.PriceBox.options[selectedItem].value;	
	var totalPrice = qty * unitPrice;
	totalPrice = totalPrice.toFixed(2);
	document.ItemForm.itemPrice.value = totalPrice;
	document.ItemForm.itemQty.value = qty;

}

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 changePicture(picture,altText){	
	document["itemImage"].src = picture;
	document.getElementById("itemLink").href = picture;		
	document["itemImage"].title = altText;
}

function getCheckedRadio(radioObj) {
	if(!radioObj)		
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked){			
			return radioObj;
		}else{		
			radioObj.checked = true;	
			return radioObj;
		}
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i];
		}
	}
	radioObj[0].checked = true;	
	return radioObj[0];
}

function highlightTerm(){
	var anchorID = location.hash;
	if (anchorID != ""){
		anchorID = anchorID.replace(/(#)/g,"");	
		document.getElementById(anchorID).style.color = "#FF0000";	
	}
}

function priceValidate(minQty){		
	checkfield = document.ItemForm.itemQty;
	if (isNaN(checkfield.value)){
		checkfield.focus();
  		alert("Please enter numbers only");
  		return false;
	}
	
	if (checkfield.value < minQty) {
  		checkfield.focus();
  		alert("The minimum order quantity is " + minQty + " dozen");
  		return false;
  	}  	  	
  	return true;
}

function addToCart(){
	
	var radio = getCheckedRadio(document.ItemForm.minQty);
	var minQty = parseInt(radio.value) ;
	if (document.ItemForm.OPTION_NAMES != null){
		if (document.ItemForm.OPTIONS[0][0] == null){
			document.ItemForm.OPTION_NAMES.value = document.ItemForm.OPTIONS[document.ItemForm.OPTIONS.selectedIndex].text
		} else {
			options = document.ItemForm.OPTIONS[0][document.ItemForm.OPTIONS[0].selectedIndex].text;
			for (x=1; x<document.ItemForm.OPTIONS.length; x++){
				options = options + "," + document.ItemForm.OPTIONS[x][document.ItemForm.OPTIONS[x].selectedIndex].text;
			}
			
			options = options.replace("None,","");
			document.ItemForm.OPTION_NAMES.value = options;
		}	
	}	
	
	if (priceValidate(minQty)){
		postPage('/addtocart.jsp');
	}	
}

function updateQty(dropdown, item){
	var minQty = dropdown.value;
	document.ItemForm.itemQty.value = minQty;
	document.ItemForm.ordertype.value = dropdown.id;
	getPrice(item,minQty);
}

function getAll(form,gType,gName){
	var i = 0;
	var resultArray = new Array();
	var elementType = "";
	var elementName = "";
	var elementValue = "";
	for (x=0;x<form.elements.length;x++){
		elementType = form.elements[x].type;
		elementName = form.elements[x].name;
		elementValue = form.elements[x].value;
		if (elementType == gType && elementName.match(gName) != null){
			resultArray[i] = elementValue;
			i++;
		}
	}
	return resultArray;
}

function setScreenWidth(id){
	var screenW = 640, screenH = 480;
	if (parseInt(navigator.appVersion)>3) {
 		screenW = screen.width; 		
 	}
 	
 	if (screenW >= 1280){
 		document.getElementById(id).width="600";
 	} else {
 		document.getElementById(id).width="400";
 	}
}

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);
}
