﻿var boxes = ["Geo", "Time", "Clustern", "Product", "MyBilandia"];


function toggleBox(id) {
   
 var boxStyle = document.getElementById(id).className;

 for (var i = 0; i < boxes.length; i++) {
   if ("leftContent" + boxes[i] != id) {
     document.getElementById("leftContent" + boxes[i]).className = "leftContentBox off";
   }
 }

 if (boxStyle.indexOf(" off") != -1) {
   document.getElementById(id).className = "leftContentBox";
 } else {
   document.getElementById(id).className = "leftContentBox off";
 }

}


function toggleBoxActive(id) {

    var boxActive = document.getElementById(id).className;
  
 for (var n = 0; n < boxes.length; n++) {
   if ("leftSearch" + boxes[n] != id) {
     document.getElementById("leftSearch" + boxes[n]).className = "leftSearchBox";
   }
 }

 if (boxActive.indexOf("Active ") != 0) {
   document.getElementById(id).className = "Active leftSearchBox";
 } else {
   document.getElementById(id).className = "leftSearchBox";
 }

}


 function openContentBox(boxID) {
  
  for (var x = 1; x <= 7; x++) {
   var closeBoxID = x;
   if (closeBoxID < 10) closeBoxID = "0" + closeBoxID;
   document.getElementById("topicBox" + closeBoxID + "_opened").style.display = "none";
   document.getElementById("topicBox" + closeBoxID + "_closed").style.display = "block";
  }
  
  if (document.getElementById("topicBox" + boxID + "_opened").style.display == "block") {
   document.getElementById("topicBox" + boxID + "_opened").style.display = "none";
   document.getElementById("topicBox" + boxID + "_closed").style.display = "block";
  } else if (document.getElementById("topicBox" + boxID + "_opened").style.display == "none") {
   document.getElementById("topicBox" + boxID + "_opened").style.display = "block";
   document.getElementById("topicBox" + boxID + "_closed").style.display = "none";
  }
 }



function showOnlyBox(contentid, searchid) {
    for (var i = 0; i < boxes.length; i++) {
        if ("leftContent" + boxes[i] != contentid) {
            document.getElementById("leftContent" + boxes[i]).className = "leftContentBox off";
        }
        if ("leftSearch" + boxes[i] != searchid) {
            document.getElementById("leftSearch" + boxes[i]).className = "leftSearchBox";
        }
    }
    document.getElementById(contentid).className = "leftContentBox";
    document.getElementById(searchid).className = "Active leftSearchBox";
}

function emptyAllBut(id) {
    if (id != "Geo") {
        emptySelect("searchGeoContinent");
        emptyTextBox("searchGeoCountry");
        emptyTextBox("searchGeoCity");
    }
    if (id != "Time") {
        emptyTextBox("searchTimeYear");
        //emptySelect("searchTimePeriod");
        emptySelect("searchTimeSeason");
        emptySelect("searchTimeFrameReader");
    }
    if (id != "Clustern") {
        emptyTextBox("searchClusternColor");
        emptyTextBox("searchClusternBook");
    }

    if (id != "Product") {
        emptyTextBox("abstractBookTitle");
        emptyTextBox("abstractBookAuthor");
    }
}

function emptyTextBox(id) {
    	document.getElementById("ctl00_" + id).value = "";
}

function emptySelect(id) {
	    document.getElementById("ctl00_" + id).selectedIndex = 0;
}

function emptyCheckBox(id) {
    	document.getElementById("ctl00_" + id).checked = false;
}

function SetOpenContent() {

	if(window.location.search=="?ueberbilandia") {
		openContentBox('01'); 
	}

	if(window.location.search=="?bilandiaSuche") {
		openContentBox('02'); 
	}
					
	if(window.location.search=="?bibliothek") {
		openContentBox('03'); 
	}

	if(window.location.search=="?abstracts") {
		openContentBox('04'); 
	}				

	if(window.location.search=="?provision") {
		openContentBox('05'); 
	}
					
	if(window.location.search=="?meinbilandia") {
		openContentBox('06'); 
	}	
					
	if(window.location.search=="?datensicherheit") {
		openContentBox('07'); 
	}		
				
}

function ChangeValue(id) {
	document.getElementById("ctl00_" + id).value="";
	document.getElementById("ctl00_" + id).style.color="#000000";		
}

function ChangeValueCPH(id) {
	document.getElementById("ctl00_cphBox_" + id).value="";
	document.getElementById("ctl00_cphBox_" + id).style.color="#000000";
}

function doCustomSortSelect(selects) {
    for (var i = 0; i < selects.length; i++) {
        if (document.getElementById(selects[i]) != null) {
            customSortSelect(document.getElementById(selects[i]));
        }
    }
}

function customSortSelect(select) {
    var options = new Array(select.options.length);
    for (var i = 0; i < options.length; i++)
        options[i] = new Option(
            select.options[i].text,
            select.options[i].value,
            select.options[i].defaultSelected,
            select.options[i].selected);
    options.sort(customCompareFunction);
    select.options.length = 0;
    for (var i = 0; i < options.length; i++) {
        select.options[i] = options[i];
    }
}

function customCompareFunction(o1, o2) {
    if (o1.text == "Andere") {
        return 1;
    } else if (o2.text == "Andere") {
        return -1;
    } else {
        return (o1.text < o2.text) ? -1 : (
                       (o1.text > o2.text) ? 1 : 0);
    }
}

function toggleDisplay(id) {
      if (document.getElementById(id) != null) {
        var current = document.getElementById(id).style.display;
        document.getElementById(id).style.display = (current == "none") ? "" : "none";
      }
  }

function friendsMenuT(id, one, two, three, txt){
      var empty_con = document.getElementById('empty_details');
      try {
          empty_con.innerHTML = txt;
      } catch (err) { }
      friendsMenu(id, one, two, three);
}

function friendsMenu(id, one, two, tree) {
      if (document.getElementById("ctl00_cphBox_Community_" + id) != null) {
          document.getElementById("ctl00_cphBox_Community_" + id).style.display = "block";   
      }
      document.getElementById("ctl00_cphBox_Community_"+one).style.display = "none";   
      document.getElementById("ctl00_cphBox_Community_"+two).style.display = "none";
      document.getElementById("ctl00_cphBox_Community_"+tree).style.display = "none";
  }
