
top.window.status='  ';

// max. integer Wert
var CONST_MAX_INT  = 2147483647;

var mouse_x, mouse_y;
mouse_x = 200;
mouse_y = 200;


function x$(element) 
{
  if (typeof element == 'string')
    element = document.getElementById(element);
  if (element)
    return element;
}

function toggle(element)
{
 if (element)
 if (element.style)
 {
	 if (element.style.display == "")
		element.style.display = "none";
	 else
		element.style.display = "";
 }
}

function visible(element)
{
 if (element.style.display == "")
 	return true;
 else
	return false;
 }

function CloseWindow()
{
	top.window.close();

	if (top.opener)
		top.opener.focus();

}


function OpenWindow(url,w,h)
{

	l = 5;
	t = 5;
	new_window = null;
	new_window = window.open(url,'cmswindow'+w+h,'location=no,directories=no,status=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes,resizeable=yes,width='+w+',height='+h+',top='+t+',left='+l);

	if (new_window!=null)
		  new_window.focus();


}

function OpenWindow2(url,w,h)
{

	l = 5;
	t = 5;

	new_window = null;
	new_window = window.open(url,'cmswindow'+w+h,'location=yes,directories=yes,status=yes,menubar=yes,toolbar=yes,scrollbars=yes,resizable=yes,resizeable=yes,width='+w+',height='+h+',top='+t+',left='+l);

	if (new_window!=null)
		  new_window.focus();


}


function OpenWindow3(url,w,h)
{

	l = (screen.availWidth/2)-(w/2)-20;
	// t = (screen.availHeight/2)-(h/2)-20;
	t = 10;
	
	new_window = null;
	new_window = window.open(url,'cmswindow'+w+h,'location=no,directories=no,status=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes,resizeable=yes,width='+w+',height='+h+',top='+t+',left='+l);

	if (new_window!=null)
		  new_window.focus();


}

function OpenWindow4(url,w,h)
{

	l = (screen.availWidth)-w-20;
	t = 20;

	new_window = null;
	new_window = window.open(url,'cmswindow'+w+h,'location=no,directories=no,status=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes,resizeable=yes,width='+w+',height='+h+',top='+t+',left='+l);

	if (new_window!=null)
		  new_window.focus();

}

function OpenWindow5(theURL,winName,features)
{
	window.open(theURL,winName,features);
	return false;
}

function OpenWindow6(theURL,winName,features)
{
	new_window = null;
	new_window = window.open(theURL,winName,features);
	new_window.focus();
	return false;
}


// Kalender 
function openCalendar(inputfeld)
{
	start = eval(inputfeld + ".value");
	url = "/include/calender.php?inputfeld="+inputfeld+"&start="+start;

	leftPos = 280;
	topPos  = 20;

	window.open(url,"ccalender","width=280,height=300,left="+leftPos+",top="+topPos+",toolbar=no,status=no,location=no,menubar=no,resizable=yes");

	return false;
}

// Bitte warten Hinweis einblenden
function set_bitte_warten()
{
  	if (x$("bitte_warten"))
  		x$("bitte_warten").style.visibility = "visible";
}
	

function Cookie()
{
	this.get = function(name) {
		var cookies = document.cookie.split(";");
		for (var i = 0; i < cookies.length; i++) {
			var a = cookies[i].split("=");
			if (a.length == 2) {
				a[0] = a[0].mytrim();
				a[1] = a[1].mytrim();
				if (a[0] == name) {
					return unescape(a[1]);
				}
			}
		}
		return "";
	}
	this.set = function(name, value) {
		jetzt = new Date();
		jetzt.setTime(jetzt.getTime() + 1000*60*60*24*30);
		cookieex = jetzt.toGMTString();
		document.cookie = name + "=" + escape(value) + "; expires="+cookieex;
		

	}
	this.del = function(name) {
		document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}


 var cookie = new Cookie();

 if (typeof String.prototype.mytrim == "undefined") {
    String.prototype.mytrim = function() {
        var s = this.replace(/^\s*/, "");
        return s.replace(/\s*$/, "");
    }
}

function trim(str)
{
 while(str.substring(0,1)==' ')
 	str=str.substring(1,str.length);
 while(str.substring(str.length-1,str.length)==' ')
 	str=str.substring(0,str.length-1);
 return str;
}

yPos=0;
e_branche_zugang = "";

msgIdArray=new Array("login","call");

next_brancheID = -1;
next_action = "";
next_open_popup = "";

function zugang_erotik_branchen(brancheID,action,is_best,open_popup)
{
	next_brancheID = brancheID;
	next_action = action;
	next_open_popup = open_popup;

	if ((is_best == "")&&(e_branche_zugang==""))
		showMsg("login");
	else
		weiter_zu_erotik_branchen();

}

function weiter_zu_erotik_branchen()
{

	if (next_open_popup=="kunde_details")
		OpenWindow5(next_action+'&e_branche_zugang=ok','details','width=900,height=750,toolbar=yes,status=yes,resizable=yes,scrollbars=yes,left=200,top=10');
	else
	{
		document.brancheTypForm.e_branche_zugang.value="ok";
		document.brancheTypForm.ID.value=next_brancheID;
		document.brancheTypForm.action=next_action;
		document.brancheTypForm.submit();
	}
	x$("msg").style.visibility = "hidden";
	x$("msg").style.display  = "none";
	clearAllMsg();
	return false;
}



function clearAllMsg(){
	for (var i=0;i<msgIdArray.length;i++){
		try{
			if (x$(msgIdArray[i]))
			   x$(msgIdArray[i]).style.display="none";
		}
		catch(e){
		}
	}

	x$("msgBg").style.width = "100%";
	x$("msgBg").style.height = "100%";

	return false;
}


function showMsg(msgId){
	 showMsgDiv(msgId)
	 msgOffset=x$(msgId).offsetHeight
	 x$(msgId).style.top=(480-msgOffset)+"px"
	 x$("msg").style.display  = "block";
	 fadeInMsg(msgId);
}

function showMsgDiv(msgId){
	try{
		clearAllMsg();
		swidth = screen.width;
		sheight = screen.height;
		if (parseInt(swidth)<=800)
			swidth = 800;
		if (parseInt(sheight)<=600)
			sheight = 600;
		x$("msgBg").style.width  = eval(swidth+50)+"px";
		x$("msgBg").style.height = eval(sheight+50)+"px";
		x$(msgId).style.display  = "block";
	}
	catch(e){
		window.setTimeout("showMsgDiv("+msgId+")",50);
	}
}

function fadeInMsg(msgId){
	if (window.pageYOffset) yPos = window.pageYOffset;
	else if (document.body && document.body.scrollTop) yPos=document.body.scrollTop;
	else if (document.documentElement && document.documentElement.scrollTop) yPos=document.documentElement.scrollTop;

	if (yPos > 0) {
		for (i=yPos;i>0;i-=50) {
			scrollTo(0,i);
		}
	}
	yPos = 0;
	x$("msg").style.visibility = "visible";
	x$("msg").style.display  = "block";
	moveDownMsg(-x$("msgContainer").offsetHeight);
}

function fadeOutMsg(){
	if (window.pageYOffset) yPos = window.pageYOffset;
	else if (document.body && document.body.scrollTop) yPos=document.body.scrollTop;

	if (yPos > 0) {
		for (i=yPos;i>0;i-=3) {
			scrollTo(0,i);
		}
	}
	yPos = 0;
	stopMove=-x$("msgContainer").offsetHeight-20;
	moveUpMsg(parseInt(x$("msgContainer").style.top))
}

function moveDownMsg(newPos){
	var buffer = new Array();
	x$("msgContainer").style.top = newPos+"px"
	buffer[0]="moveDownMsg("
	buffer[1]=newPos+30
	buffer[2]=")"
	if (newPos < (-370+msgOffset))
		window.setTimeout(buffer.join(""),50)
}

function moveUpMsg(newPos){
	var buffer = new Array();
	x$("msgContainer").style.top = newPos+"px"
	buffer[0]="moveUpMsg("
	buffer[1]=newPos-30
	buffer[2]=")"
	if (newPos > stopMove)
		window.setTimeout(buffer.join(""),50)
	else {
		x$("msg").style.visibility = "hidden";
		x$("msg").style.display  = "none";
		clearAllMsg();
	}
}

var backup_call = "";

function init_erotik()
{
	swidth = screen.width;
	sheight = screen.height;
	if (parseInt(swidth)<=800)
		swidth = 800;
	if (parseInt(sheight)<=600)
		sheight = 600;

	backup_call = x$('call').innerHTML;

	x$('call').innerHTML=x$('login').innerHTML; 
	x$('call').style.display=""; 
	x$('call').style.display = "block";
	x$('call').style.left = "50px";
	x$('call').style.top = "230px";
	x$('call').style.width = "500px";
	x$('call').style.height = "400px";
	x$('call_bg').style.display = "block";
	x$('call_bg').style.left = "0px";
	x$('call_bg').style.top = "0px";
	x$('call_bg').style.width  = eval(swidth+50)+"px";
	x$('call_bg').style.height = eval(sheight+50)+"px";
}

function cancel_init_erotik()
{
	x$('call').style.display = "none";
	x$('call_bg').style.display = "none";
	x$('call').style.width = "380px";
	x$('call').style.height = "200px";
	x$('call_bg').style.width = "383px";
	x$('call_bg').style.height = "203px";
	x$('call').innerHTML = backup_call;
}

function init_call(s3,s4)
{
	x$('call_results').innerHTML=""; 
	x$('call_results').style.display=""; 
	x$('call_s3').innerHTML = s3;
	x$('call_s4').innerHTML = s4;
	x$('call').style.display = "block";
	x$('call').style.left = eval(mouse_x-50)+"px";
	x$('call').style.top = eval(mouse_y-30)+"px";
	x$('call_bg').style.display = "block";
	x$('call_bg').style.left = eval(mouse_x-30)+"px";
	x$('call_bg').style.top = eval(mouse_y-20)+"px";
	if (document.form_call)
		if (document.form_call.telnr_vorwahl)
			document.form_call.telnr_vorwahl.focus();
}

function cancel_call()
{
	x$('call').style.display = "none";
	x$('call_bg').style.display = "none";
	x$('call_s3').innerHTML = "";
	x$('call_s4').innerHTML = "";
	return false;
}

function set_call()
{

 var fehler = 0;
 
 telnr_vorwahl   = document.form_call.telnr_vorwahl.value;
 telnr_anschluss = document.form_call.telnr_anschluss.value;
 
 if (fehler ==0 && trim(telnr_vorwahl)=="")
 {
 	alert("Bitte geben Sie Ihre Vorwahl ein.");
 	document.form_call.telnr_vorwahl.focus();
 	fehler = 1;
 }
 if (fehler ==0 && trim(telnr_anschluss)=="")
 {
 	alert("Bitte geben Sie Ihre Telefonnummer ein.");
 	document.form_call.telnr_anschluss.focus();
 	fehler = 1;
 }

if (fehler==0)
{
 	s3 = x$('call_s3').innerHTML;
 	s4 = x$('call_s4').innerHTML;
 	
 	mode = "call";
 	
 	x$('call_results').innerHTML = "Die Verbindung wird aufgebaut .. ";
 	x$('call_results').style.display=""; 
 	
 	iniXMLHttpRequest("/call.php?telnr_vorwahl="+telnr_vorwahl+"&telnr_anschluss="+telnr_anschluss+"&s3="+s3+"&s4="+s4, "POST");
 	XMLHTTP.send(null);
 }
 
 return false;
}


var XMLHTTP = null;
var mode = "";

function iniXMLHttpRequest(file, method)
{
	if (window.XMLHttpRequest)
	{
		XMLHTTP = new XMLHttpRequest();
	}
	else
	{
		if (window.ActiveXObject)
		{
			try
			{
				XMLHTTP = new ActiveXObject("Msxml2.XmlHttp.4.0");
			}
			catch(ex)
			{
				try
				{
					XMLHTTP = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(ex)
				{
					try
					{
						XMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
					}
					catch(ex){}
				}
			}
		}
	}

	XMLHTTP.open(method, file);
	XMLHTTP.onreadystatechange = XMLHttpRequestOnReadStateChange;
	if (method=="POST")
		XMLHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
}


function XMLHttpRequestOnReadStateChange()
{
	if (XMLHTTP.readyState==4)
	{
			results = XMLHTTP.responseText;

			if (mode=="suche")
			{
				if (results != "")
				{

					if (results.indexOf("class=fillSB") == -1)
					{
						x$("ajax_results").style.display="none"; 	
						x$("ajax_results_bg").style.display="none"; 	
						showAllSelectBoxes();
						x$("ajax_results_bg").innerHTML = "";
						al_counter=-1;

					}
					else
					{
						if (ajax_feld == "ds_firmen")
						{
							x$('ajax_results').style.left     ="325px";
							x$('ajax_results_bg').style.left  ="335px";
							x$('ajax_results').style.width    = "252px";
							x$('ajax_results_bg').style.width = "252px";
						}

						if (ajax_feld == "ds_ort")
						{
							x$('ajax_results').style.left      = "540px";
							x$('ajax_results_bg').style.left   = "550px";
							x$('ajax_results').style.width     = "252px";
							x$('ajax_results_bg').style.width  = "252px";
						}
						
						x$('ajax_results').innerHTML = XMLHTTP.responseText;
						
						hideAllSelectBoxes();
						
						x$('ajax_results').style.display=""; 
						x$('ajax_results_bg').style.display=""; 

						if (x$("al0"))
							x$("al0").className = "ajaxselect";

					}

				}
				else
				{
					x$('ajax_results').style.display="none";
					x$('ajax_results_bg').style.display="none";
					showAllSelectBoxes();
					x$('ajax_results').innerHTML = "";
					al_counter=-1;
				}
			}


			if (mode=="call")
			{
				if (results != "")
				{
					if (results.indexOf("Success")>=0)
						x$('call_results').innerHTML = "Die Verbindung wurde aufgebaut.";
					else
						x$('call_results').innerHTML = "Die Verbindung konnte nicht aufgebaut werden.";
				
				}
				else
				{
					x$('call_results').innerHTML = "Fehler beim Verbindungsversuch.";
				}
			}
			
	}

}

function get_mouse_coords(e)
{ 
  if (window.event) // IE
  {
	if (document)
	if (document.documentElement || document.body)
	{
		if (document.documentElement && document.documentElement.scrollLeft)
			mouse_x=window.event.clientX+document.documentElement.scrollLeft;
		else
			mouse_x=window.event.clientX+document.body.scrollLeft;

		if (document.documentElement && document.documentElement.scrollTop)
			mouse_y=window.event.clientY+document.documentElement.scrollTop;
		else
			mouse_y=window.event.clientY+document.body.scrollTop;
  	}
  }
  else              // MOZ
  { 
	mouse_x=e.pageX;
	mouse_y=e.pageY;
  }
  
  // top.window.status = mouse_y;
}


// document.onmousemove = get_mouse_coords;

