function updateCart(f,action,pid){
	if (f && f.formAction && f.pid){
		f.formAction.value = action;
		f.pid.value = pid;
		f.submit();
	} else {
		var f = document.createElement("<form action='../enc/shoppingcart' method='post'/>");
		var inputFormAction = document.createElement("<input type='hidden' name='formAction' value='"+action+"'>");
		f.appendChild(inputFormAction);
		var inputPid = document.createElement("<input type='hidden' name='pid' value='"+pid+"'>");
		f.appendChild(inputPid);
		document.body.appendChild(f);
		f.submit();
	}
}
    
var hasLogoutSubmit = false;
function logout(logoutPath,returnPath){
	if (!hasLogoutSubmit){
		hasLogoutSubmit = true;
		var popup = window.open(logoutPath+"?returnPath="+returnPath,'logout','scrollbars=no,resizable=no,top=0,left=0,width=5,height=5');
	}
}    

function show_hide_child(e)
{
	var c = e.parentElement.parentElement.nextSibling;
	if ( c.style.display == "" ) {
		c.style.display = "none";
		e.src = "../../img/folderc.gif";
	} else {
		c.style.display = "";
		e.src = "../../img/foldero.gif";
	}
}

function showLoginDiv(){

   	showHideSelectBox(document.forms,"hidden");
   
	document.all.loginDiv.style.display = '';
	document.all.loginFrame.src = "../enc/login";
	document.body.scrollTop = 0;
	document.body.scroll="no";
	
}

function showCheckOutDiv(){

   	showHideSelectBox(document.forms,"hidden");
   	
	document.all.checkOutDiv.style.display = '';
	document.body.scrollTop = 0;
	document.body.scroll="no";
}

function showHideSelectBox(forms,visibility){
  try {
	  if (forms){
	  	for (i=0; i<forms.length; i++){
			var coll = forms[i].elements;
			if (coll!=null) {
			    for (j=0; j<coll.length; j++){
			        if (coll.item(j).tagName == "SELECT") {
			        	coll.item(j).style.visibility = visibility;
			        }
			    }
			}
		}
	  }
   } catch (exception) {}
}

function refreshCodeImage(imageName){
	var codeImage = document.getElementById(imageName);
	if (codeImage){
		var imgSrc = codeImage.src;
		if (imgSrc.indexOf("?") != -1){
			codeImage.src = imgSrc.substring(0,imgSrc.indexOf("?"))+"?ts="+(new Date()).getTime();
		} else {
			codeImage.src = imgSrc+"?ts="+(new Date()).getTime();
		}
	}
}

function onMouseOverProfileTag(f,tdTag){
	if (f.currProfile.value+"Td" != tdTag.id){
		tdTag.className = "profileTagTitleOver";
	}
	tdTag.style.cursor = 'pointer';
}

function onMouseOutProfileTag(f,tdTag){
	if (f.currProfile.value+"Td" == tdTag.id){
		tdTag.className = "profileTagTitleOn";
	} else {
		tdTag.className = "profileTagTitleOff";
	}
}

function onClickProfileDiv(f,tdTag,currProfile){
	if (f.currProfile.value != ''){
		var lastTdTag = document.all[f.currProfile.value+"Td"];
		if (lastTdTag){
			lastTdTag.className = "profileTagTitleOff";
		}
		var lastDivTag = document.all[f.currProfile.value+"Div"];
		if (lastDivTag){
			lastDivTag.style.display = 'none';
		}
	}
	tdTag.className = "profileTagTitleOn";
	f.currProfile.value = currProfile;
	var currDivTag = document.all[currProfile+"Div"];
	if (currDivTag){
		currDivTag.style.display = '';
	}
}

function updateSelectedItem(chkbox){
	var f = document.SelectedItem;
	if (f){
		if (chkbox){
			if (chkbox.checked){
				f.action.value = "Add";
			} else {
				f.action.value = "Remove";
			}
			f.pid.value = chkbox.id.substring(4);
		} else {
			f.pid.value = '';
			f.action.value = "Order";
		}
		f.submit();
	}
}

function check_EMAIL(f,l,m,re)
{
	var v_email = f.value
	var v_email_domain = f.value.substr(f.value.indexOf("@") + 1)
	if ( (v_email.indexOf("@") == -1) ||
	     (v_email.indexOf("@") == 0)  ||
	      (v_email.indexOf("@") != v_email.lastIndexOf("@")) ||
	        (v_email_domain.indexOf(".") == -1)  ||  
	          (v_email_domain.indexOf(".") == 0) ||
	            ((v_email.indexOf(".") + 1) == v_email.length) )
	{
		return invalid_data(f,m);
	}	
	return check_string(f,l,m,re);
}

function goToPage(page_url){
	if (opener){
		opener.top.location.href = page_url;
	} else {
		parent.top.location.href = page_url;
	}
}

function popupProductOrderDetail(id, title, para)
{
	if (!title){
		title = "_blank";
	}
	var url_link = "../enc/productorderdetail?id="+id;
	if (para){
		url_link += "&"+para;
	}
    var popUp = window.open(url_link, title, "top=50,left=50,width=700,height=500,toolbar=0,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=1");
    if (popUp){
    	popUp.focus();
    }
}
