var url = "";

function urlencode( str ) {    
    var ret = str;     
    ret = ret.toString();    
    ret = encodeURIComponent(ret);    
    ret = ret.replace(/%20/g, '+');     
    return ret;
}
function PopWindow(popname){
    var LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    var TopPosition = (screen.height) ? (screen.height-h)/2 : 0;  
    window.open("http://"+this.strDomainName+this.strVirtualPath+"popup.htm",popname,"toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=1,height=1,left = "+LeftPosition+",top = "+TopPosition);
}
function NewWindow(url,wx,hx,wname){
    var LeftPosition = (screen.width) ? (screen.width-wx)/2 : 0;
    var TopPosition = (screen.height) ? (screen.height-hx)/2 : 0;  
    if(wname==''){wname='new';}
    window.open(url,wname,"toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width="+wx+",height="+hx+",left = "+LeftPosition+",top = "+TopPosition);
}

function addToCart(product_id, field_id,server_back,server_referer){
    var quant;
	if(document.getElementById("products_to_alter_" + field_id)){
	   quant = document.getElementById("products_to_alter_" + field_id).value;
	}else{
	    quant = 1;
	}
	if(quant!=0){
		document.location = this.strHomePage+"?mod=cart&action=add&redirect="+urlencode(server_back)+"&referer="+urlencode(server_referer)+"&product_id=" + product_id + "&quant=" + quant;
	}
}
function UpdateCart(product_id, field_id){
	var quant = document.getElementById("products_to_alter_" + field_id).value;
	if(quant!=0){
		document.location = this.strHomePage+"?mod=cart&action=update&product_id="+product_id+"&quant="+quant;
	}
}
function deleteFromCart(product_id, field_id){
	var quant = document.getElementById("products_to_alter_" + field_id).value;
	if(quant!=0){
		document.location = this.strHomePage+"?mod=cart&action=delete&product_id=" + product_id + "&quant=" + quant;
	}
}
function getUrlParam(name) {
  var name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp(regexS);
  var results = regex.exec(window.location.href);
  if (results == null)
    return "";
  else
    return results[1];
}
if(typeof addEvent!='function'){
	var addEvent=function(o,t,f,l){var d='addEventListener',n='on'+t,rO=o,rT=t,rF=f,rL=l;if(o[d]&&!l)return o[d](t,f,false);if(!o._evts)o._evts={};if(!o._evts[t]){o._evts[t]=o[n]?{b:o[n]}:{};o[n]=new Function('e','var r=true,o=this,a=o._evts["'+t+'"],i;for(i in a){o._f=a[i];r=o._f(e||window.event)!=false&&r;o._f=null}return r');
	if(t!='unload')addEvent(window,'unload',function(){removeEvent(rO,rT,rF,rL)})}if(!f._i)f._i=addEvent._i++;o._evts[t][f._i]=f};addEvent._i=1;
	var removeEvent=function(o,t,f,l){var d='removeEventListener';if(o[d]&&!l)return o[d](t,f,false);if(o._evts&&o._evts[t]&&f._i)delete o._evts[t][f._i]}
}
