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_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_findObj(n, d) { //v4.01
  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);
  if(!x && d.getElementById) x=d.getElementById(n); 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];}
}

function printPage(isdesigner) {
	if(window.print) {
		agree = confirm('OK to print this tearsheet?');
	
		if(agree) {
			
			if(isdesigner == 1) {
				showprice = confirm('Click OK to include list price; click CANCEL to hide price');
				
				if(!showprice) {
					document.getElementById('price').style.display = "none";
				}
			}
			
			window.print(); 
		}
	}
}

function verify_email(str) {
	if(!str.match(/^[\w]{1}[\w\.\-_]*@[\w]{1}[\w\-_\.]*\.[\w]{2,6}$/i)) {
		return false;
	} else {
		return true;
	}
}

function validate_register(theform) {	
	if(theform.email.value.length == 0 || theform.first_name.value.length == 0 || theform.last_name.value.length == 0 || theform.password.value.length == 0) {
		alert("Please complete all the registration fields.");
		return false;
	}
	
	//check email
	if(!verify_email(theform.email.value)) {
		alert ("Please provide a valid email address.");
		return false;
	}
	
	//check passwords
	if(theform.password.value != theform.password_confirm.value) {
		alert("Your passwords do not match.");
		return false;
	}
	
	theform.submit();
	return true;
}

function validate_register_designer(theform) {	
	if(theform.email.value.length == 0 || theform.first_name.value.length == 0 || theform.last_name.value.length == 0 || theform.password.value.length == 0 || theform.address_1.value.length == 0 || theform.city.value.length == 0 || theform.state.value.length == 0 || theform.zip.value.length == 0 || theform.company_name.value.length == 0 || theform.resale_number.value.length == 0) {
		alert("Please complete all the registration fields.");
		return false;
	}
	
	//check email
	if(!verify_email(theform.email.value)) {
		alert ("Please provide a valid email address.");
		return false;
	}
	
	//check passwords
	if(theform.password.value != theform.password_confirm.value) {
		alert("Your passwords do not match.");
		return false;
	}
	
	theform.submit();
	return true;
}

function validate_login(theform) {	
	if(theform.email.value.length == 0 || theform.password.value.length == 0) {
		alert("Please provide your email address and password to login.");
		return false;
	}
	
	theform.submit();
	return true;
}

function validate_myportfolio_add(theform) {	
	if(theform.portfolio_id.value.length == 0) {
		alert("Please select a portfolio.");
		return false;
	}
	
	theform.submit();
	return true;
}

function change_category_page(thelistbox, url) {
	//check to make sure it's not a dummy value before redirecting
	if(thelistbox.options[thelistbox.selectedIndex].value != '' && thelistbox.options[thelistbox.selectedIndex].value != '-') {
		window.location = url + thelistbox.options[thelistbox.selectedIndex].value;
	}
}

function validate_myportfolio_remove(theform) {
	var onechecked = false;
	for(var i = 0; i < theform.elements.length; i++) {
		var e = theform.elements[i];

		if(e.type == 'checkbox' && e.checked) {
			onechecked = true;
			break;
		}
	}

	if(!onechecked) {
		alert("Please select at least one item to delete.");
		return false;
	}
	
	theform.submit();
	return true;
}