function DeptJump(DeptValue){
	if (DeptValue=="" | DeptValue<1){
	
	}
	else{
	document.location.href="catalog.asp?deptid="+DeptValue;
	}
}

function PasswordChange(){
	document.location.href="changepassword.asp";
}

function SetDisplayMode(theURL,theDeptID,theValue){
		if (theDeptID !="" | theValue !=""){
			document.location.href=theURL+"?deptid="+theDeptID+"&dmode="+theValue;
		}
	}
	
function AddToCart(theDeptID,theProductID,theDisplayMode,theQTY){
	thisform = document.forms.CatalogForm;
	thisform.action = "addtocart.asp"
	thisform.DeptID.value = theDeptID;
	thisform.ProductID.value = theProductID;
	thisform.DisplayModeID.value = theDisplayMode;
	thisform.QTY.value = theQTY;
	
}

function AddToCartQTY(theProductID){
	thisform = document.forms.CatalogForm;
	thisform.action = "addtocart.asp"
	//thisform.submit();
}


function ValidateSearch(){
	thisform = document.forms.ProductSearchForm;
	if (thisform.ProductSearchText.value==""){
		alert("Please enter the item number or name of the product you are searching for. For best results avoid punctuation and use a small portion of the name");
		return false;
	}
	return true;
}

function ValidateSideSearch(){
	thisform = document.forms.PSForm;
	if (thisform.PSText.value==""){
		alert("Please enter the item number or name of the product you are searching for. For best results avoid punctuation and use a small portion of the name");
		return false;
	}
	return true;
}

function ChangeTab(CurrentTabID){
	if (document.getElementById("NumTabs").value != 0){
	for (i = 0; i <= document.getElementById("NumTabs").value-1; i++){
		if (i != CurrentTabID){
		document.getElementById("tab"+i).style.visibility = "hidden";
		document.getElementById("tab"+i).style.display = "none";
		}
	
	document.getElementById("tab"+CurrentTabID).style.visibility ="visible";
	document.getElementById("tab"+CurrentTabID).style.display ="block";
	}
}
}

function SetCurrentTab(CurrentTabID){
	if (document.getElementById("NumTabs").value != 0){
	document.getElementById("tab"+CurrentTabID).style.visibility ="visible";
	document.getElementById("tab"+CurrentTabID).style.display ="block";
	}
}

function ChangeImage(ImageURL){
	document.getElementById("ProductImage").src=ImageURL;
}

function ValidateReview(ReviewMode){
	thisform = document.forms.ProductReviewForm;
	if (ReviewMode==2 | ReviewMode==4){
	if (thisform.ProductRating.options[thisform.ProductRating.selectedIndex].value ==""){
		alert("Please select a rating for this product");
		return false;
	}
	}
	
	if (ReviewMode == 3 | ReviewMode ==4){
	if (thisform.ProductReview.value==""){
		alert("Please select a type in a review for this product");
		return false;
	}
	}
	return true;
}

function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

	function ValidateRegion(){
		thisform = document.forms.CreateAccountForm;
		theCountryID = thisform.RegionID.options[thisform.RegionID.selectedIndex].COUNTRYID;
		theShippingZone = thisform.RegionID.options[thisform.RegionID.selectedIndex].SHIPZONE;
		thisform.ShippingZone.value = theShippingZone;
		thisform.CountryID.value = theCountryID;
	}
	
	function ValidateCountry(){
		thisform = document.forms.CreateAccountForm;
		theCountryID = thisform.CountryID.options[thisform.CountryID.selectedIndex].value;
		if (thisform.RegionID.options[thisform.RegionID.selectedIndex].COUNTRYID != theCountryID){
			thisform.RegionID.options.selectedIndex = 0;
		}
	}
	
	function ValidateCreateAccount(){
		thisform = document.forms.CreateAccountForm;
		if (thisform.Email.value==""){
			alert("Please Enter Your Email Address");
			return false;
		}
		if (thisform.FirstName.value==""){
			alert("Please Enter Your First Name");
			return false;
		}
		if (thisform.LastName.value==""){
			alert("Please Enter Your Last Name");
			return false;
		}
		if (thisform.Address.value==""){
			alert("Please Enter Your Address");
			return false;
		}
		if (thisform.City.value==""){
			alert("Please Enter Your City/Town");
			return false;
		}
		if (thisform.Postal.value==""){
			alert("Please Enter Your Postal/Zip Code");
			return false;
		}
		if (thisform.YearofBirth.options[thisform.YearofBirth.selectedIndex].value==""){
			alert("For security reasons, please select a random year as a security question in case proof of your identity is required");
			return false;
		}
		return true;
	}

	function WhyBirthYear(){
		alert("We ask you to choose a random year as security check in case of a question of your online identity arises. This value is stored in our database in an encrypted form and none of our staff can access it.");
	}
	
	function CheckRegion(){
		thisform = document.forms.QuestionForm;
		theCountryID = thisform.RegionID.options[thisform.RegionID.selectedIndex].COUNTRYID;
		thisform.CountryID.value = theCountryID;
	}
	
	function CheckCountry(){
		thisform = document.forms.QuestionForm;
		theCountryID = thisform.CountryID.options[thisform.CountryID.selectedIndex].value;
		if (thisform.RegionID.options[thisform.RegionID.selectedIndex].COUNTRYID != theCountryID){
			thisform.RegionID.options.selectedIndex = 0;
		}
	}
	
	function ValidateAskExpert(){
		thisform = document.forms.QuestionForm;
		if (thisform.FullName.value==""){
			alert("Please enter your first and last name");
			return false;
		}
		if (thisform.Email.value==""){
			alert("Please enter a valid email address");
			return false;
		}
		if (isEmail(thisform.Email.value)==false){
			alert("Please enter a valid email address");
			return false;
		}
		
		if (thisform.RegionID.options[thisform.RegionID.selectedIndex].value==""){
			alert("Please select a province or state");
			return false;
		}
		if (thisform.CountryID.options[thisform.CountryID.selectedIndex].value==""){
			alert("Please select a country");
			return false;
		}
		if (thisform.Question.value==""){
			alert("Please enter your question in the space provided");
			return false;
		}
		return true;
	}
	
	function ValidateSearchKB(){
		thisform = document.forms.KnowBaseForm;
		if (thisform.KBText.value==""){
			alert("Please enter a search text or keywords");
			return false;
		}
		return true;
	}
	
function formatMoney(num){
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 isValidNumber(inpString) {
   if (isNaN(parseFloat(inpString))){
   		return true;
   }else{
   return false;
   }
}

function hasOptions(obj){
	if (obj!=null && obj.options!=null) { return true; }
	return false;
	}

	function moveSelectedOptions(from,to) {
	// Unselect matching options, if required
	if (arguments.length>3) {
		var regex = arguments[3];
		if (regex != "") {
			unSelectMatchingOptions(from,regex);
			}
		}
	// Move them over
	if (!hasOptions(from)) { return; }
	for (var i=0; i<from.options.length; i++) {
		var o = from.options[i];
		if (o.selected) {
			if (!hasOptions(to)) { var index = 0; } else { var index=to.options.length; }
			to.options[index] = new Option( o.text, o.value, false, false);
			}
		}
	// Delete them from original
	for (var i=(from.options.length-1); i>=0; i--) {
		var o = from.options[i];
		if (o.selected) {
			from.options[i] = null;
			}
		}
	if ((arguments.length<3) || (arguments[2]==true)) {
		sortSelect(from);
		sortSelect(to);
		}
	from.selectedIndex = -1;
	to.selectedIndex = -1;
	}

	
	function selectAllOptions(obj){
		if (!hasOptions(obj)) { return; }
			for (var i=0; i<obj.options.length; i++) {
				obj.options[i].selected = true;
			}
		}
		
	function DeselectAllOptions(obj){
		if (!hasOptions(obj)) { return; }
			for (var i=0; i<obj.options.length; i++) {
				obj.options[i].selected = false;
			}
		}	
		
	function copySelectedOptions(from,to) {
	var options = new Object();
	if (hasOptions(to)) {
		for (var i=0; i<to.options.length; i++) {
			options[to.options[i].value] = to.options[i].text;
			}
		}
	if (!hasOptions(from)) { return; }
	for (var i=0; i<from.options.length; i++) {
		var o = from.options[i];
		if (o.selected) {
			if (options[o.value] == null || options[o.value] == "undefined" || options[o.value]!=o.text) {
				if (!hasOptions(to)) { var index = 0; } else { var index=to.options.length; }
				to.options[index] = new Option( o.text, o.value, false, false);
				}
			}
		}
	if ((arguments.length<3) || (arguments[2]==true)) {
		sortSelect(to);
		}
	from.selectedIndex = -1;
	to.selectedIndex = -1;
	}

	function moveAllOptions(from,to) {
	selectAllOptions(from);
	if (arguments.length==2) {
		moveSelectedOptions(from,to);
		}
	else if (arguments.length==3) {
		moveSelectedOptions(from,to,arguments[2]);
		}
	else if (arguments.length==4) {
		moveSelectedOptions(from,to,arguments[2],arguments[3]);
		}
	}
	
	function copyAllOptions(from,to) {
	selectAllOptions(from);
	if (arguments.length==2) {
		copySelectedOptions(from,to);
		}
	else if (arguments.length==3) {
		copySelectedOptions(from,to,arguments[2]);
		}
	}
	
	function moveOptionUp(obj) {
	if (!hasOptions(obj)) { return; }
	for (i=0; i<obj.options.length; i++) {
		if (obj.options[i].selected) {
			if (i != 0 && !obj.options[i-1].selected) {
				swapOptions(obj,i,i-1);
				obj.options[i-1].selected = true;
				}
			}
		}
	}
	
	function moveOptionDown(obj) {
	if (!hasOptions(obj)) { return; }
	for (i=obj.options.length-1; i>=0; i--) {
		if (obj.options[i].selected) {
			if (i != (obj.options.length-1) && ! obj.options[i+1].selected) {
				swapOptions(obj,i,i+1);
				obj.options[i+1].selected = true;
				}
			}
		}
	}

	function removeSelectedOptions(from) { 
	if (!hasOptions(from)) { return; }
	if (from.type=="select-one") {
		from.options[from.selectedIndex] = null;
		}
	else {
		for (var i=(from.options.length-1); i>=0; i--) { 
			var o=from.options[i]; 
			if (o.selected) { 
				from.options[i] = null; 
				} 
			}
		}
	from.selectedIndex = -1; 
	} 
	
	function removeAllOptions(from) { 
	if (!hasOptions(from)) { return; }
	for (var i=(from.options.length-1); i>=0; i--) { 
		from.options[i] = null; 
		} 
	from.selectedIndex = -1; 
	} 

	function sortSelect(obj) {
	var o = new Array();
	if (!hasOptions(obj)) { return; }
	for (var i=0; i<obj.options.length; i++) {
		o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;
		}
	if (o.length==0) { return; }
	o = o.sort( 
		function(a,b) { 
			if ((a.text+"") < (b.text+"")) { return -1; }
			if ((a.text+"") > (b.text+"")) { return 1; }
			return 0;
			} 
		);

	for (var i=0; i<o.length; i++) {
		obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
		}
	}
	
	function ShowProductImage(ProductID){
	var imgwindow=window.open("showproductimage.asp?pid="+ProductID,"imgwindow","location=no,menubar=no,scrollbars=no,titlebar=no,status=no,resizable=no,height=300,width=300,left=40,top=40,screenx=40,screeny=40");
}

function ClearSearchText(){
		document.getElementById("txtSearchText").value = "";
	}
	function ValidateProductSearch(){
		objSearchText = document.getElementById("txtSearchText");
		objDeptID = document.getElementById("ddlDeptID");
		if (objSearchText.value == "" | objSearchText.value == "Product Search"){
			if (objDeptID.options[objDeptID.selectedIndex].value ==""){
				alert("Please enter a product name or keyword to search for");
				return false;
			} else{
				return true;
			}				
		}else{
			
			return true;
		}
	}
