/************************************************************************
Author: Kong Georges
***********************************************************************/

var targetjArray = new Array();
targetjArray['ok']=0;
dontRunSearch = false;
function SetSlide()
{   
    if (isLocked)
        return;
    else
        isLocked = this.parentNode;          
    for (i=0 ;i < menuObjArray[0].length; i++)
    {
        if (menuObjArray[3][i] == this.parentNode)
        {
            if (menuObjArray[5][i] == null)
                menuObjArray[5][i] = setInterval("RunSlide(" + i + ")", slideDelay);
            break;
        }
    }

}
function hiddenVideoDiv(){
	if(document.getElementById('filmIntop')){
		document.getElementById('filmIntop').style.visibility = "hidden";
	}
}
function showVideoDiv(){
	if(document.getElementById('filmIntop')){
		document.getElementById('filmIntop').style.visibility = "visible";
	}
}
var searchwaiting = false;
function searchStarted(){
	searchwaiting = true;
	document.getElementById('suchen').style.visibility = "hidden";
	document.getElementById('suchergebnisWartendiv').style.visibility = "visible";
	
}
function blinkdiv(speed) 
{
		
		if (speed) {
			if (document.all)
			setInterval("blinkdiv()", speed*600)
			return;
		}
		if(document.getElementById("suchenInInternetText"))
			document.getElementById("suchenInInternetText").style.visibility  = (document.getElementById("suchenInInternetText").style.visibility == "visible") ? "hidden" : "visible" ;
}
function blinkGoogleSchreibfehlerKorrektur(speed) 
{
		
		if (speed) {
			setInterval("blinkGoogleSchreibfehlerKorrektur()", speed*600)
			return;
		}
		if(document.getElementById("schreibferhlerKor"))
			document.getElementById("schreibferhlerKor").style.visibility  = (document.getElementById("schreibferhlerKor").style.visibility == "visible") ? "hidden" : "visible" ;
}
function searchFinish(){
	searchwaiting = false;
	document.getElementById('stoerbenbuttondiv').style.visibility = "visible";
	document.getElementById('suchergebnisWartendiv').style.visibility = "hidden";
	
}
function UpdateUserCookie(aryIndex)
{
    date = new Date();
    date.setTime(date.getTime() + (1000 * 60 * 60 * 24 * 30)); 
    document.cookie = "xpMenuCookv2" + "=" + escape(menuObjArray[4].toString()) + "; expires=" + date.toGMTString();  
   
}

function checknewpage(name, anzahl)
{
		if(anzahl==""){
			anzahl=2;
		}
        if(targetjArray['ok']<anzahl){
        	targetjArray['ok']++;
        }else{
			/*alert("a");*/
           for (var i = 0; i <= 50; i++){
              if(document.links[i]){
                document.links[i].target="";
              }else break;
           }//end for
          //alert(document.forms['myform'].method);
        }//end else
}



function ChangeStyle()
{
    className = String(this.className);
   
    if (className.substring(className.length - 4, className.length) == "Over")
        this.className = className.substring(0,className.length - 4);
    else
        this.className = this.className + "Over";
   //  alert(this.className);
}



/* beginn help functions for suchmaschine */
function simpleKey(e)
{
/*alert(e.which);*/
 switch (emod) {
   case "W3C":

  //ctrl+s 
if(e.ctrlKey&&(e.which==88))
  document.getElementById('Eingabefeld1').focus();


//ctrl+k  category     
if(e.ctrlKey&&(e.which==75))
	setTimeout("document.getElementById('category').focus();",1); 

 //ctrl+t       
if(e.ctrlKey&&(e.which==222))
  document.getElementById('ort').focus();

 //ctrl+z
if(e.ctrlKey&&(e.which==90))
  document.getElementById('plz').focus();

 //ctrl+a
if(e.ctrlKey&&(e.which==65)){
	document.getElementById('bl').focus();
        return false;
}
//ctrl+u
if(e.ctrlKey&&(e.which==192)){
  document.getElementById('suchen').focus();
  submit_searchform();
}

//ENTER
if(e.which==13){

	document.getElementById('suchen').focus();
			submit_searchform();
}

 break;


case "NN4":
  //ctrl+s
if(((e.modifiers & Event.ALT_MASK) == Event.ALT_MASK)&&(e.which==88))
 document.getElementById('Eingabefeld1').focus();

  //ctrl+k category
if(((e.modifiers & Event.ALT_MASK) == Event.ALT_MASK)&&(e.which==75))
    document.getElementById('category').focus();

  //ctrl+t
if(((e.modifiers & Event.ALT_MASK) == Event.ALT_MASK)&&(e.which==222))
      document.getElementById('ort').focus();

  //ctrl+z
if(((e.modifiers & Event.ALT_MASK) == Event.ALT_MASK)&&(e.which==90))
        document.getElementById('plz').focus();

  //ctrl+a
if(((e.modifiers & Event.ALT_MASK) == Event.ALT_MASK)&&(e.which==65)){
        document.getElementById('bl').focus();
        return false;
}
  //ctrl+u
if(((e.modifiers & Event.ALT_MASK) == Event.ALT_MASK)&&(e.which==192)){
        document.getElementById('suchen').focus();
		submit_searchform();
}

if(e.which==13){
        document.getElementById('suchen').focus();
		submit_searchform();
}


break;



//###############

case "IE4+":
    e = window.event;
  //ctrl+s
    if(e.ctrlKey&&(e.keyCode==88))
    document.getElementById('searchstring').focus();
/*
  //ctrl+k  category
    if(e.ctrlKey&&(e.keyCode==75))
    document.getElementById('category').focus();

  //ctrl+t
      if(e.ctrlKey&&(e.keyCode==222))
      document.getElementById('ort').focus();

  //ctrl+z
        if(e.ctrlKey&&(e.keyCode==90))
        document.getElementById('plz').focus();

  //ctrl+a
        if(e.ctrlKey&&(e.keyCode==65)){
        document.getElementById('bl').focus();
        return false;
}
*/
//ctrl+ö
        if(e.ctrlKey&&(e.keyCode==192)){
        	document.getElementById('suchen').focus();
			submit_searchform();
		}
		
//Enter
        if(e.keyCode==13){
        	document.getElementById('suchen').focus();
			submit_searchform();
		}


  break;

default:
alert(emod);
//################  
  
  }//end switch
  //return false;
  }//end function simpleKey

function onloadH(e)
{
   /*get the event model*/
   emod = (e) ? (e.eventPhase) ? "W3C" : "NN4" : (window.event) ? "IE4+" : "unknown";

   /*A*/
   
   if (emod == "NN4") {
      document.captureEvents(Event.KEYDOWN); }

    document.onkeydown = simpleKey;
    return true;
}
/* end help functions for suchmaschine */

function selectWert(sObj) {
	if(!sObj || sObj == "undefined"){
			return "";
	}
	with (sObj) return options[selectedIndex].value;
}

function radioWert(rObj) {
	return false;
	if(!rObj || rObj == "undefined"){
			return "";
	}
    for (var i=0; i<rObj.length; i++) if (rObj[i].checked) return rObj[i].value;
    return false;
}
  
function input_changed() {
	// since onchange() doesn't seem to work properly everywhere, we do this
	var changed = false;
	
	changed = changed | (input.searchstring != document.forms["suchformular"].searchstring.value);
	changed = changed | (input.cat != selectWert(document.forms["suchformular"].cat));
	changed = changed | (input.bl != selectWert(document.forms["suchformular"].bl));
	changed = changed | (input.sort != radioWert(document.forms["suchformular"].sort));
	if(document.forms["suchformular"].plz)
		changed = changed | (input.plz != document.forms["suchformular"].plz.value);
	if(document.forms["suchformular"].ort)
		changed = changed | (input.ort != document.forms["suchformular"].ort.value);
	if(document.forms["suchformular"].plzort)
		changed = changed | (input.plzort != document.forms["suchformular"].plzort.value);
		
	changed = changed | (input.target != radioWert(document.forms["suchformular"].target));
	if(document.forms["suchformular"].amount_window)
		changed = changed | (input.amount_window != document.forms["suchformular"].amount_window.value);
	
	return changed;
}


function submit_searchform(){
	if(!input_changed()) {
		return false;
	} else {
		if(document.getElementById("category").value != "" || document.getElementById("searchstring").value != "" ){
				sendSubmit();
				searchStarted();
				document.getElementById("zwischenspeicher").innerHTML = "<input type='hidden' name='zs' value='1' />";
				document.getElementById("searchform").submit();	
		}
		/* zwischengespeicherte ergebnisse müssen gelöscht werden*/
	}
}
function sendSubmit(){
	var bundesland = document.forms["suchformular"].bl.value;
	
	if(document.forms["suchformular"].cat.value == "")
	{
		document.forms["suchformular"].action = "http://"+bundesland+".kompaktsuche.de/kleinanzeigen/search.php";
	}else{
		var catPath = getCatPath(document.forms["suchformular"].cat.value);
		if(catPath == undefined)
		{
			catPath = "";
		} 
		document.forms["suchformular"].action = "http://"+bundesland+".kompaktsuche.de/kleinanzeigen/"+catPath+"search.php";
	}
	
	document.forms["suchformular"].suchen.style.visibility = "hidden";
	
	document.getElementById("suchergebnisWartendiv").style.height = "auto";
	document.getElementById("suchergebnisWartendiv").style.width = "auto";
}
function submit_ortswahl(plz_ort){
	var teile = plz_ort.split("||");
	document.getElementById("ort").value = teile[1];
	document.getElementById("plz").value = teile[0];
	document.getElementById("zwischenspeicher").innerHTML = "<input type='hidden' name='zs' value='1' />";
	document.suchformular.submit();	
	document.getElementById("ortswahl").style.top ="-1000px";
}

function open_ortswahl(){
	document.getElementById("ortswahl").style.top ="220px";
}

function showsubmenu(divid){
	document.getElementById(divid).style.display="block";
}
function hiddensubmenu(divid){
	if(document.getElementById(divid))
		document.getElementById(divid).style.display="none";
}
function hiddenAllSubmenus(){
	
	hiddensubmenu('ihrewerbung_subs');
	hiddensubmenu('ueberunssubmenu');
	
	document.getElementById('ihrewerbung_subs').style.display="none";
	document.getElementById('ueberunssubmenu').style.display="none";
}
function showSubMenus(id)
	{
		document.getElementById(id).style.display = "block";
	}

function selectAddcat(id, text){
	document.getElementById("add_cat").value = id;
	document.getElementById("add_cat_text").value = text;
	document.getElementById("addcatlistdiv").style.display="none";		
}
function addCatClick(){
	document.getElementById("addcatlistdiv").style.display="block";
}
function keydownAddcat(e, id, text){
	var keyCode = getKeyCode(e, 'keydown');
	if(keyCode == 13){
		selectAddcat(id, text);
	}
}
function getOffset(strID){
  var objStart = document.getElementById(strID);
  // Startwert
  var intOffsetLeft = objStart.offsetLeft;
  // Offset-Objekt
  var objOffset = {
    left: objStart.offsetLeft,
    top: objStart.offsetTop
  }

  // Elternelement mit Offset ermitteln
  var objHelpOffset = objStart.offsetParent;

  // Solange OffsetElemente existieren
  while(objHelpOffset){
    // Offsets addieren
    objOffset.left += objHelpOffset.offsetLeft;
    objOffset.top += objHelpOffset.offsetTop;
    // Nächstes OffsetElement
    objHelpOffset = objHelpOffset.offsetParent;
  }

  return objOffset;  // Offset-Objekt zurückgeben; Zugriff über .left und .top
}
function CatMenuClick(){

	document.getElementById("menuUL").style.display="block";
	CorrectDropdownMenuPos();
	
}

function HiddenCat(){
	document.getElementById("menuUL").style.display="none";
	CorrectDropdownMenuPos();
	
}
function CorrectDropdownMenuPos(){
	document.getElementById("menuUL").style.left=getOffset("selectedcatname").left + "px";
}
