function hem_affilinet_qstring(querystring) {
  if(querystring == '') return;
  var wertestring = unescape(querystring);
  wertestring = wertestring.slice(1);
  var paare = wertestring.split("&");
  for (var i=0; i < paare.length; i++) {
    var name = paare[i].substring(0, paare[i].indexOf("="));
    var wert = paare[i].substring(paare[i].indexOf("=")+1, paare[i].length);
    this[name] = wert;
  }
}

var temp_hem_affilinet_qstring = new hem_affilinet_qstring(window.location.search);

function hem_affilinet_init(aid) {
  var a = new Date();
  a = new Date(a.getTime() +1000*60*60*24*60);
  document.cookie = 'affilinet='+aid+';path=/;expires='+a.toGMTString()+';'; 
}

for( parameter in temp_hem_affilinet_qstring ) {
  if ( parameter == "aid" ) { hem_affilinet_init(temp_hem_affilinet_qstring[parameter]); }
}

function holeCookie(Keksname) {
  alleCookies=document.cookie;
  cookieArr=alleCookies.split(";");
  for(var i=0;i<cookieArr.length;i++) {
    if(trim(cookieArr[i].split("=")[0]) == trim(Keksname)) {
  		cookieWert=cookieArr[i].split("=");
  		cookieWert=unescape(cookieWert[1]);
  		return cookieWert;  		
  	}
  }
 	return false;
}

function trim(s){
return s.replace(/^\s*(.*?)\s*$/,"$1")
}

function hem_affilinet_order() {

  cookiewert = holeCookie('affilinet');
  if(cookiewert) {
  
    a = document.createElement('img');
    a.setAttribute('src',"https://partners.webmasterplan.com/registersale.asp?site=2899&ref="+cookiewert+"&mode=pps&price="+bestellwertnetto+"&order="+bestellnummer);
    a.setAttribute('width',1);
    a.setAttribute('height',1);
    a.setAttribute('id',"AffilinetImage");
    document.getElementsByTagName('body')[0].appendChild(a);
    
  }
}