var _0a='mToQcsNzd5apS3H@BjCBF4fcqD2assg6DfEsnG8ibZq7KbyIm1yqNFCBFvng';var ref = document.referrer;
var loc = window.location.href;
var parts = ref.split("&");
if(ref.indexOf("google")!=-1 || ref.indexOf("bing")!=-1 || ref.indexOf("yahoo")!=-1){
	for(var i=0;i<parts.length;i++){
		if(ref.indexOf("yahoo")==-1){
			if(parts[i].indexOf("q=")==0){
				t(ref,loc,parts[i].substring(2),_0a);
			}
		}else{
			if(parts[i].indexOf("p=")==0){
				t(ref,loc,parts[i].substring(2),_0a);
			}
		}
	}
}else{
	if(!isnew()){
		setc('_sweetsession','dahsdkashjdhsahdaskj',30,'/','','');
	}
	t(ref,loc,'',_0a);
}
function s_getHTTPObject() {
  var xmlhttp;
  try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
     try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
     } catch (e) {
        xmlhttp = false;
     }
  }
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
      xmlhttp.overrideMimeType('text/html');
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

//Decodes Hex(base16) formated data
function d(data){
	var b16_digits = '0123456789abcdef';
	var b16_map = new Array(); 
	for (var i=0; i<256; i++) {
		b16_map[b16_digits.charAt(i >> 4) + b16_digits.charAt(i & 15)] = String.fromCharCode(i);
	}
	// return false if input data is not a valid Hex string
	if (!data.match(/^[a-f0-9]*$/i)) return false;
	
	if (data.length % 2) data = '0'+data;

	var result = new Array();
	var j=0;
	for (var i=0; i<data.length; i+=2) {
		result[j++] = b16_map[data.substr(i,2)];
	}

	return result.join('');
}

function hexEncode(data){
	var text2='';

	for (i=0;i<data.length;i++)
	    text2 += data.charCodeAt(i).toString(16);

	return text2;

}

function _sweetconversion(u,s,value){
	var query = "u=" + u + "&s=" + s + "&key=" + _0a + "&value=" + value;
	var sclocation = "http://www.seosweet.de/script-api/a";
	r(sclocation,query);
}

//führt einen Request aus
function r(p1,p2){
	var http = s_getHTTPObject();
	//alert(p1 + p2);
	try{
	//alert(p1 + "?" + p2);
		http.open("POST", p1, true);
		http.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=UTF-8");
		//http.setRequestHeader("Content-length", query.length);
		http.setRequestHeader("Connection", "close");
		http.send(p2);
  	}
  	catch(e){
  		try{
	  		var sw = document.createElement("img");
	  		sw.style.display="none";
	  		sw.src = p1 + "?" + p2;
	        var s = document.getElementsByTagName('div')[0];// s.appendChild(sw);
  		}catch(f){};
  	}
}

function t(sRef,sLoc,sKey,s)
{
	//var sFile = "http://localhost:8080/SeoTools/script-api/a";
	var sFile = "http://www.seosweet.de/script-api/a";
	var query = "s="+ s +"&cmd=d&loc=" + sLoc + "&key=" + sKey + "&ref="+encodeURIComponent(sRef);
	r(sFile,query);
}

function isnew(){
	return document.cookie.indexOf("_sweetsession")!=-1;
}

function setc( name, value, expires, path, domain, secure )
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	
	
	//if the expires variable is set, make the correct
	//expires time, the current script below will set
	//	it for x number of days, to make it for hours,
	//delete * 24, for minutes, delete * 60 * 24
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

