function getBooleanValue(value){
	if( value == null ) return false;
	if( value == "false" || value == 0 ) return false;
	return Boolean(value);
}

function submitFormAction(formNameStr, actionURLStr) {
    document.forms[formNameStr].action = actionURLStr;
    document.forms[formNameStr].submit();
 }

function confirmCancel(confirmTextStr, actionURLStr) {
   if (confirm(confirmTextStr)) {
      document.location = actionURLStr;
   } 
}

// Two functions to toggle styles by adding/removing class="on" to an element with a certain id, e.g. used for tabs
function activate(idArr) {
	var pattern = /( |^)(on)( |$)/;
	for (var i = 0; i < idArr.length; i++) {
		var el = document.getElementById(idArr[i]);
		if (!el.className.match(pattern)) {
			el.className += " on";
		}
	}
}

function deactivate(idArr) {
	var pattern = /( |^)(on)( |$)/;
	for (var i = 0; i < idArr.length; i++) {
		var el = document.getElementById(idArr[i]);
		if (el.className.match(pattern)) {
			var oldClassStr = el.className;
			var newClassStr = oldClassStr.replace(pattern, "");
			el.className = newClassStr;
		}
	}
}

/* open a new window...requires window.js */
function popOpen(url) {
   openCenteredOnOpenerWindow(url, 'window2', 500, 500, '', true, '', 'opener');
   }

/* open a new window...requires window.js */
function CP_salesPop(url) {
   openCenteredOnOpenerWindow(url, 'window2', 300, 200, '', true, '', 'opener');
   }

/* Selectbox navigation...the <select> tag requires an id */
function go(whatToSelect,protocol) {
   var theSelectBox = document.getElementById(whatToSelect);
   if (!protocol) protocol = "";
   if (theSelectBox.options[theSelectBox.selectedIndex].value != "none") {
      location = protocol + theSelectBox.options[theSelectBox.selectedIndex].value;
   }
}

  	function persistCouponCode(){
  		var hiddenCouponCode = document.getElementById("hiddenCouponCode");
		var couponCode = document.getElementById("couponCode");
		hiddenCouponCode.value=couponCode.value;
		alert(document.getElementById("hiddenCouponCode").value);
		document.getElementById("promotionForm").submit();
  	}
  	


function checkThis(name){
	if (confirm("Do you want to delete this item?")){
		var chk = document.getElementsByTagName("input");
		for(var i=0; i<chk.length; i++) {
			if(chk[i].getAttribute("type")=="checkbox"){
				var tempID = chk[i].getAttribute("id");
				var tempName = name;
				if(tempID == tempName){
					chk[i].checked = true;
				}
			}
		}
		document.cartform.update.click();
	}
}

function setChangedEcommQuantityValues(relId, catRefId, qty, isbn) {
	document.cartform.changedRelationshipId.value = relId;
	document.cartform.changedQuantityItem.value = catRefId;
	document.cartform.changedQuantityItemAmt.value = qty;
	document.cartform.changedISBN.value = isbn;

	document.cartform.update.click();
}

function icfrRemove(commerceId) {
	document.getElementById("removedItem").value = commerceId;
	document.getElementById("remove").click();
}

function setChangedIcfrQuantityValues(relId, catRefId, qty, isbn) {
	document.icfrform.changedRelationshipId.value = relId;
	document.icfrform.changedQuantityItem.value = catRefId;
	document.icfrform.changedQuantityItemAmt.value = qty;
	document.icfrform.changedISBN.value = isbn;

	document.getElementById("update").click();
}

function confirmationCreateAccount(email) {
	document.getElementById("profileEmail").value = email;
	document.getElementById("create").click();
}

function showCartNoticeDiv() {
	alert("success");
    // var pos = $('subtotal').cumulativeOffset();
	$('miniCart').absolutize().show();
}

function getResults(indx,pFilterCriteria,pCategoryId,pLevel1,pLevel2,pLevel3,pCurrTree,pSel){
	var filterCriteria = document.getElementById("filterCriteria");
	var publishedBy = document.getElementById("publishedBy");
	var lstPublishedBy = document.getElementById("lstPublishedBy[" + indx + "]");
	filterCriteria.value = pFilterCriteria;
	var categoryId = document.getElementById("categoryId");	
	categoryId.value = pCategoryId;
	
	if(pCategoryId!=''){
		var searchInput = document.getElementById("searchInput");
		searchInput.value = pCategoryId;
	}else{
		var mainSearchInput = document.getElementById("mainSearchInput");
		var searchInput = document.getElementById("searchInput");
		searchInput.value=mainSearchInput.value;
	}
	
	var level1 = document.getElementById("level1");
	level1.value = pLevel1;
	var level2 = document.getElementById("level2");
	level2.value = pLevel2;
	var level3 = document.getElementById("level3");
	level3.value = pLevel3;
	var currTree = document.getElementById("currTree");
	currTree.value = pCurrTree;
	var sel = document.getElementById("sel");
	sel.value = pSel;
	
	if (pFilterCriteria!="publishedBy") {
		publishedBy.value = "None";
	} else {
		if (lstPublishedBy) {
			var tmpPublishedBy = lstPublishedBy.options[lstPublishedBy.selectedIndex].value;
			if(tmpPublishedBy == "None") {
				filterCriteria.value = "all";
			}
			publishedBy.value = tmpPublishedBy;
		}	
	}
	
	document.getElementById("search-form").submit();
}


