function trim(stringToTrim) {
	if(stringToTrim)
		return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	if(stringToTrim)
		return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	if(stringToTrim)
		return stringToTrim.replace(/\s+$/,"");
}
function openResizeWindow(url) { 
  window.open(url,'Resize','toolbar=yes,location=yes,scrollbars=yes,resizable=yes,width=800');
}
function Add2ShopCart(form)
{
	quantity=parseInt(form.quantity.value);
	if (form.maxQuantity!=null && quantity > 0 && quantity > parseInt(form.maxQuantity.value)) { 
		alert('There is a maximum quantity limit on this item.');
	}
	else {
		form.URL.value = 'OrderCalculate?calculationUsageId=-5&orderItemId*=&quantity*=&URL=OrderItemDisplay';
		form.addItem.value = 'true';
		form.submit();
	}
}
function Add2Favorites(form, encodedURL)
{
	form.action=encodedURL;
	form.URL.value='InterestItemDisplay'
	form.submit()
}
	
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function openShippingInfoWindow(theURL) {
	window.open(theURL,'ShippingInfoWindow','scrollbars=yes,height=600,width=600,resizable=yes');
}
function popUpEmailToFriend(url) {
	emailToFriendWin=window.open(url,"emailwin",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=700,height=450');
	emailToFriendWin.focus();
}
function checkNumOfComparedItem(form,totalItemDisplayed)
{
	var count=0;
	form.compareItems.value="";
	for(var i=0;i<totalItemDisplayed;i++){
		box=eval("document."+form.name+".compareItem" + i); 
		if(box.checked){
			count++;
			if(count>3){
				alert("Only 3 items can be compared at the same time!");
				box.checked=false;
			}else{
				form.compareItems.value=form.compareItems.value+box.value+"_";
			}
		}
	}		
}
function checkNumOfComparedItemChked(form,totalItemDisplayed)
{
	var count=0;
	form.compareItems.value="";
	for(var i=0;i<totalItemDisplayed;i++){
		box=eval("document."+form.name+".compareItem" + i); 
		if(box.checked){
			count++;
		}
	}
	return count;		
}
function openLibraryWindow() {
	window.open('Swanson/html/SHPLib_main.html','LibraryWindow','scrollbars=yes,toolbar=yes,height=400,width=450,resizable=yes');
}
function openGSpopupWindow(theURL) {
	window.open(theURL,'GSpopupWindow','scrollbars=yes,toolbar=no,height=500,width=500,resizable=yes');
}
function isNotEmpty(elem){
	//alert("see me");
	var str=elem.value;
	var re=/.+/;
	if(!str.match()){
		alert("Please fill");
		return false;
	}
	else{
		return true;
	}
}
function isLen7(elem){
	var str=elem.value;
	var re=/\d{7}/;
	if(re.test(str)){
		return true;
	}else{
		return false;
	}	
}
function isLen4(elem){
	var str=elem.value;
	var re=/\d{4}/;
	if(re.test(str)){
		return true;
	}else{
		return false;
	}	
}
function isMatchPatten(elem,patten){
	var str=trim(elem.value);
	if(patten.test(str)){
		return true;
	}else{
		return false;
	}	
}
	
	
function PartnerPageAdd2ShopCart(form, qty, partNumber)
{
	form.URL.value = 'OrderCalculate?calculationUsageId=-5&orderItemId*=&quantity*=&URL=OrderItemDisplay';
	form.partNumber_1.value = partNumber.toUpperCase();
	form.quantity_1.value = qty;
	form.addAllItemsQB.value = 'true';
	form.submit();
}	
function prepareSubmitOrderStatusEntry(form){
		var lenthMatch=isMatchPatten(form.order,/(^\d{7}$|^\d{8}$)/ );
		var stringMatch=isMatchPatten(form.lastName,/.+/);
		//alert(form.lastName.value);
		if(!lenthMatch){
		   alert("Order number must only contain 7 or 8 digits!");
		}else if(!stringMatch||form.lastName.value==""){
		   alert("Please fill out your last name!");
		}else{
		    form.order.value=trim(form.order.value);
		    form.lastName.value=trim(form.lastName.value);
			form.submit();
		}
		//alert(form.lastName.value+ isMatchPatten(form.lastName,/.+/));
}