// (c) 2004-2007 Copyright Nedstat BV Netherlands.
// ALL RIGHTS RESERVED
// version v4.7 2004-02-22 TP added ns_ prefix and ns_undefined validation
// version v5.0 2007-06-21 SH complete rewrite
var ns_sendOrders={};function ns_order(ns_counterURL,ns_client_id,ns_order_id,delimiter){var DELIMITER=".";this.hasDelimiter=!!(delimiter);this.counterURL=ns_counterURL;this.clientID=ns_client_id;this.orderID=ns_order_id;this.delimiter=(delimiter)?/^[\.,];$/.test(delimiter)?delimiter:DELIMITER:DELIMITER;this.orders=[];this.DEBUG=false;};ns_order.prototype.addLine=function(prod_id,brand,prod_grp,shop,qty,prod_price){this.orders[this.orders.length]={ns_prod_id:!this.isEmpty(prod_id)?prod_id:"ns_undefined",ns_brand:!this.isEmpty(brand)?brand:"ns_undefined",ns_prod_grp:!this.isEmpty(prod_grp)?prod_grp:"ns_undefined",ns_shop:!this.isEmpty(shop)?shop:"ns_undefined",ns_qty:this.toFloat(qty),ns_prod_price:this.toSignedFloat(prod_price),ns_ec_price:prod_price}};ns_order.prototype.sendOrder=function(){var cookieStr="ns_order_id_"+this.orderID+"=true";if(!this.orderID||(ns_sendOrders[this.orderID]||document.cookie.indexOf(cookieStr)>0))
return;ns_sendOrders[this.orderID]=true;document.cookie=cookieStr;var log=this.counterURL+"&ns__t="+(new Date()).getTime()+"&ns_ec_ver=2.0.0"+"&ns_commerce=true&ns_type=hidden"+"&ns_ec_has_delimiter="+this.hasDelimiter+"&ns_ec_delimiter="+this.delimiter+"&ns_client_id="+this.toValueString(this.clientID)+"&ns_order_id="+this.toValueString(this.orderID)+"&ns_orderlines="+this.orders.length;for(var i=0,order,logURL;(order=this.orders[i]);i++){logURL=log;logURL+="&ns_orderline_id="+(i+1);for(var key in order)logURL+="&"+key+"="+escape(this.toValueString(order[key]));if(this.DEBUG&&document.getElementById("debug")){document.getElementById("debug").firstChild.appendChild(document.createTextNode(logURL+"\n"));}var imgId="ns_order_"+this.orderID+"#"+i;window[imgId]=new Image();window[imgId].id=imgId;window[imgId].onload=window[imgId].onerror=function(){try{window[this.id]=null;delete window[this.id];}catch(e){}};window[imgId].src=logURL;}};ns_order.prototype.toValueString=function(s){
return new String((typeof s=="undefined")?0:s).replace(/(%3C|%3E|<|>)/gi,"_");};ns_order.prototype.toFloat=function(s){var val=parseFloat(s);
return isNaN(val)?"ns_undefined":val;};ns_order.prototype.toSignedFloat=function(s){s=new String(s||"");var regEx=/([\+-])?(?:0+)?(\d.*)/;var matches=s.match(regEx);if(!matches)
return 0;var index=(matches[2].indexOf(this.delimiter)>0)?matches[2].indexOf(this.delimiter):matches[2].length;var val=matches[2].substring(0,index).replace(/[\.,]/g,"");var decimals=matches[2].substring(Math.min(matches[2].length,index+1));var signedFloat=parseFloat(parseInt(val)+"."+((decimals.length>2)?(Math.round(decimals/100)*100):decimals)).toFixed(2);
return isNaN(signedFloat)?0:((matches[1])?matches[1]:"")+signedFloat;};ns_order.prototype.isMoney=function(s){
return/^([\+-])?([0-9]+|[0-9]{1,3}([\.,][0-9]{3})*)([\.,][0-9]{1,2})?$/.test(new String((typeof s=="undefined")?0:s).replace(/(^\s+)|\s+$/g,""));};ns_order.prototype.isEmpty=function(s){s=new String((typeof s=="undefined")?"":s);
return(s)?s.match(/^([\s]+)?$/):false;};
