/** indicates the used browser **/
var bN = navigator.userAgent;
var mozilla = bN.indexOf("Gecko")>-1;
var opera = bN.indexOf("Opera")>-1;
var ie = bN.indexOf("MSIE")>-1;
var ie7 = bN.indexOf("MSIE 7")>-1;

var x,y;
var re = new Array();
var pn = new Array("p","act","what","where","offset","advise", 							// 5
			   	   "hits","vc","position_click","ppcresponse","ppcclk",		   					// 10
				   "category","fonclk","prvclk", "referrer", "browser",					// 15
				   "screen_resolution", "os", "plugins", "java_aktiv", "screendepth",	// 20
				   "jsVersion", "ppc_top_position_click", "ppc_bottom_position_click","lt"); // 24

var act, what, where, ofs, path;
var p=0;
var lopa = new Array();
var prvVisible = false;

/** preview show */
var pshw = function(e,url) {
	if (!prvVisible) {
		setXY(e);
		yo = 255; // prvdiv-height
		if (y - yo < 0) yo = 0;
		o("prvdiv").firstChild.src=url;
		o("prvdiv").style.left = (x + 5) + "px";
		o("prvdiv").style.top  = (y) + "px";
		o("prvdiv").style.visibility = "visible";
		prvVisible = true;
	}
};

/** sets the X/Y Coordinate for preview image */
var setXY = function (e) {
	if (ie || ie7) {
		x=window.event.clientX;
		y=window.event.clientY;
	} else {
		x = e.clientX;
		y = e.clientY;
	}
};

/** preview hide */
var phid = function(e) {
	o("prvdiv").style.visibility = "hidden";
	prvVisible = false;
};

/** open bcs */
var obcs = function(id) {
  opent(re[id],390,700,'BCS');
};

/** open Feedback */
var feedback = function() {
	opent("http://webadress.lohmedia.de/index.php?what="+what + "&where=" + where,775,650,'Feedback');
};

/** open Feedback and bcs */
var opent = function(url,h,w,titel) {
  tpop = window.open(url,titel,'resizable=yes,scrollbars=yes,status=yes,height='+h+',width='+w);
  tpop.focus();
};

/** getElementById */
var o = function(name) {
	return document.getElementById(name);
};

/** log */
var sl = function() {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', '/stats', true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) { lopa = new Array(); }
    }
    self.xmlHttpReq.send(gqs());
};

/** log vcard parameter */
var vlp  = function(k,v,vc,i) {
	alp(8,i+1); lp(k,v);
};

/** log direct */
var lp = function(k,v) {
	if (ofs==null) ofs = 0;
	alp(1,act);
	alp(0, -1);
	if(k == 10){
		k = 22;
		if(v > 4){
			k = 23;
		}
	}
	alp(k,v); 
	sl();
};

/** alp */
var alp = function(k,v) {
	lopa[lopa.length] = new Array(pn[k], v);
};

/** generate query string for statistic logging */
var gqs = function() {
	par = "";
	alp(15, navigator.userAgent); //log browser type
	for (i=0;i<lopa.length;i++) {
		par += "&"+lopa[i][0] +"="+lopa[i][1];
	}
	return par.toLowerCase();
};

/** preview open url */
var pdis = function(url,id) {
    w = window.open(url,'','resizable=yes,toolbar=yes,menubar=yes,scrollbars=yes,location=yes,status=yes,height=520,width=800');
  	w.focus();
  	tmp = p; p = 65; // swich page id
 	alp(1,act); sl(); 	
 	p = tmp;
};

/** get actual mouse position */
var getMouseX = function(e) {
	if (ie || ie7) {
		return window.event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
	} else {
		return e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
	}
};

/** get actual mouse position */
var getMouseY = function(e) {
	if (ie || ie7) {
		return window.event.clientY + document.body.scrollTop + document.documentElement.scrollTop;//window.event.clientY;
	} else {
		return e.clientY + document.body.scrollTop + document.documentElement.scrollTop;//window.event.clientY;; //e.clientY;
	}
};

/** show the freecall image for telephone numbers on mouseover */
var showFreeCallOver = function(e,img){

	var fco = o("freeCallOver");
	fco.src=img;
	fco.id='freeCallOver';

	var mouseX = getMouseX(e) + 15;
	var mouseY = getMouseY(e);

	fco.style.top = mouseY + "px";
	fco.style.left = mouseX + "px";
	fco.style.visibility = "visible";
	fco.style.display = "block";
};

/** hide the freecall image for telephone numbers on mouseover */
var hideFreeCallOver = function() {
	var fco = o("freeCallOver");
	fco.style.display = "none";
	fco.style.visibility = "hidden";
};

/**
 * "aepl" - add extended logging parameter
 */
function aepl() {
	//alp(21, document.referrer); //log referer
	alp(15, navigator.userAgent); //log browser type
    alp(16, screen.width + "x" + screen.height); //log screen resolution
	alp(20, screen.pixelDepth);//screen depth
	alp(17, navigator.oscpu); //log  operating system
	alp(21, jsVersion);
	p=0;
	var plug;
	if (navigator.plugins.length == 0) plug = "null";
	for (var i = 0; i < navigator.plugins.length; i++)  plug += navigator.plugins[i].name + "+";
	alp(18, plug); //log browser plugins
	alp(19, navigator.javaEnabled()); //log if java is enabled
}

/** hide and show additional domains in result list */
var shdom = function(idx) {
	var dl = o('dlst'+idx);
	if (dl != null && dl.style.visibility == 'hidden') {
		dl.style.visibility = 'visible';
		dl.style.display = '';
		o('shimg'+idx).src = 'images/minus.gif';
	} else {
		dl.style.visibility = 'hidden';
		dl.style.display = 'none';
		o('shimg'+idx).src = 'images/plus.gif';	
	}
}

/** set the focus in the what field  */
function setMainFocus(){
	if (document.eingabe != null) {
			document.eingabe.what.focus();
	}
}

