function open_window(URL) {
	window.open(URL,'win','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=400,height=460');
}

function open_window_sizeable(URL,window_name,w,h) {
	window.open(URL,window_name,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width='+w+',height='+h);
}

function submitData(form) {
	userSelected = form.productid.selectedIndex;
	selected_productid = form.productid.options[userSelected].value;
	if (selected_productid == 0){
		alert("Please select a Phone Type and Paper Color.");
		return false;
	}
	return true;
}

function check_for_keyword(form) {
	if (form.keywords.value == ""){
		alert("Please enter a Keyword before submitting your search.");
		return false;
	}
	return true;
}

function deleteitem(partnumber, manufacturerid)	{
	document.delete_form.partnumber.value = partnumber;
	document.delete_form.manufacturerid.value = manufacturerid;
	document.delete_form.submit();
}

function formatCurrency(num) { 
	var sign, cents; 
	num = num.toString().replace(/\$|\,/g,''); 
	if(isNaN(num)) 
		num = "0"; 
		sign = (num == (num = Math.abs(num))); 
		num = Math.floor(num*100+0.50000000001); 
		cents = num%100; 
		num = Math.floor(num/100).toString(); 
	if(cents<10) 
		cents = "0" + cents; 
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) 
		num = num.substring(0,num.length-(4*i+3))+','+ 
		num.substring(num.length-(4*i+3)); 
	return (((sign)?'':'-') + '$' + num + '.' + cents); 
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//generic form validation based on array of fields passed in
//		fieldarray[1] = fieldlist
//		fieldarray[2] = fieldname
//		fieldarray[3] = fieldrequired
function verifyFormArray(fieldlist,fieldname,fieldrequired,formName){
	var filedlistArray = fieldlist.split(","); //convert list to an array
	var fieldnameArray = fieldname.split(","); //convert list to an array
	var fieldrequiredArray = fieldrequired.split(","); //convert list to an array
	
	
	for (var i=0, len=fieldrequiredArray.length; i<len; ++i){
		if(fieldrequiredArray[i]==1){
			if (document.forms[formName].elements[fieldnameArray[i]]){
				//check for empty required fields
				if (document.forms[formName].elements[fieldnameArray[i]].value == ""){
					alert (filedlistArray[i]+" is a REQUIRED field");
					document.forms[formName].elements[fieldnameArray[i]].focus();
					document.forms[formName].elements[fieldnameArray[i]].select();
					return false;
				}
				//Check password matches confirmation password
				if (fieldnameArray[i]=="PASSWORD"){
					if (document.forms[formName].CONFIRM_PASSWORD.value != document.forms[formName].PASSWORD.value){
						alert("The Confiramtion Password entered does not match the Password.\n\nPlease re-type your Password and Confirmation.");
						document.forms[formName].elements[fieldnameArray[i]].focus();
						document.forms[formName].elements[fieldnameArray[i]].select();
						return false;
					}
				}
				//validate email address
				//Call EMAIL validation subfunction
				if (fieldnameArray[i] == "EMAIL" || fieldnameArray[i] == "EMAIL_ADDRESS"){
					emialVar=fieldnameArray[i]
					if(!Confirm_Email(document.forms[formName].elements[fieldnameArray[i]].value)){
						alert("Please enter a valid EMAIL ADDRESS.");
						document.forms[formName].elements[fieldnameArray[i]].focus();
						document.forms[formName].elements[fieldnameArray[i]].select();
						return false;
					}
				}
			}
		}
	}
	
	return true;
}

//  Validate Email Address - (Called from other Functions on this page)
function Confirm_Email(EMAIL){
	//Check email address is not blank
	if (EMAIL==""){
		return false
	}
	
	//Invalid email Chars
	invalidChars = " /:,;"
	
	//Check email address for invalid Chars
	for (i=0; i<invalidChars.length;i++){
		badChar=invalidChars.charAt(i)
			if (EMAIL.indexOf(badChar) != -1){
				return false
			}
	}
	//Check for @ Char
	atPos=EMAIL.indexOf("@",1)
	if (atPos == -1){
		return false
	}
	if (EMAIL.indexOf("@",atPos+1) != -1){
		return false
	}
	//Check for dot(.) Char
	dotPos=EMAIL.indexOf(".",atPos)
	if (dotPos <= 0){
		return false
	}
	if (dotPos+3 > EMAIL.lenght){
		return false
	}
	return true
}
