/*
function quenit(param){

	this.param1 = param;	
	alert(param);

	this.test = function(){
		alert("test");
	}
	
	this.test2 = function(){
		alert(param1)
	}
		
}

var obj = new quenit(256);
obj.test();

*/

function onLoaded(){
	setDefaultSearchText();
	/*
		if(navigator.userAgent.indexOf("MSIE 6.0") != -1 ){
			document.getElementById("overlay").style.height = document.getElementsByTagName('body')[0].clientWidth + "px";		
		}
	*/

}

function onScroll(){

}

function onResize(){
	
}

function setSubPA(PA){
	
	alert(PA);	
		
}

function addPABox(mainPABox){
	newBox = document.createElement("div");
	mainPABox.parentNode.appendChild(newBox);
	mainPABox.parentNode.insertBefore(newBox, mainPABox.parentNode.lastChild);
	
	//mainPABox.parentNode.innerHTML += mainPABox.innerHTML;
}

function deletePABox(mainPABox){
	alert(mainPABox.id);
}


function getSubPractiesAreas(value, way, small, spa){
	if (way == "options") {
		var container = document.getElementById("selectorSPA");
		container.disabled = true;
	}	

	var url = getRoot() + "practiceareas/subpractices";
	var param = "id=" + value;	
	httpRequest(url, param, way, small, spa, value);	
}

function getRoot(){
	return location.protocol + "//" +  location.host +"/"
}

function bildSubPractice(value, way, small, spa, valuePA){
	var value = eval('(' + value + ')');
	var container = document.getElementById("selectorSPA");
	removeAllCilds(container);

	if (way == "options") {
		option = document.createElement("option");
		container.appendChild(option);
		option.setAttribute("label", "Alle Spezialisierungen");						
		option.innerHTML = "Alle Spezialisierungen";
		option.setAttribute("value", "-1");
		//container.insertBefore(option, container.firstChild);
	}	

	for(i = 0; i < value.subpracticeareas.practiceareas.length; i++){		

		if (way == "options"){
			option = document.createElement("option");
			container.appendChild(option);
			if (value.subpracticeareas.practiceareas[i]) {
				option.setAttribute("label", value.subpracticeareas.practiceareas[i].title);						
				option.innerHTML = value.subpracticeareas.practiceareas[i].title;
				option.setAttribute("value", value.subpracticeareas.practiceareas[i].id);
			}			
			if (small == true){
				document.getElementById("selectorSPA").value = spa;									
			}	
		}
		if (way == "checkbox") {
			label = document.createElement("span");
			container.appendChild(label);
			if (value.subpracticeareas.practiceareas[i]) {
				label.innerHTML = '<input type="checkbox" class="subpractice" checked="checked" name="' +
				valuePA + '[]" value="' +
				value.subpracticeareas.practiceareas[i].id +
				'"/>' +
				value.subpracticeareas.practiceareas[i].title +
				'<br />';
			}
		}
	}

	container.disabled = false;	
}



function removeAllCilds(element){
	if(element.hasChildNodes()){
		element.removeChild(element.firstChild);
		removeAllCilds(element);
	}	
}

function httpRequest(url, param, way, small, spa, valuePA){
		var xmlHttp = null;
		// Mozilla, Opera, Safari sowie Internet Explorer 7
		if (typeof XMLHttpRequest != 'undefined') {
		    xmlHttp = new XMLHttpRequest();
		}
		if (!xmlHttp) {
		    // Internet Explorer 6 und älter
		    try {
		        xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
		    } catch(e) {
		        try {
		            xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
		        } catch(e) {
		            xmlHttp  = null;
		        }
		    }
		}
		if (xmlHttp) {
		    xmlHttp.open('GET', url + "?" + param, true);
		    xmlHttp.onreadystatechange = function () {
		        if (xmlHttp.readyState == 4) {			
				 	bildSubPractice(xmlHttp.responseText, way, small, spa, valuePA);						
		        }		
		    };
		    xmlHttp.send(null);
		}
}	

function setRegion(id){	
	document.getElementById("regionInput").value = id;
}


var defaultInputMessageSearch = "Was? z.B. Arbeitsrecht    Wo? z.B. Berlin";
var defaultInputMessageSearchSmall = "Was?    Wo?";

function clearDefaultText(obj){
		if(obj.id != "search"){
			defaultInputMessageSearch = defaultInputMessageSearchSmall;
		}

	if (obj.value == defaultInputMessageSearch) {
		changeStyleSearchText(obj);
		obj.value = "";
		
	}
}

function restoteDefaultText(obj){
	if(obj.value == ""){
		changeStyleSearchText(obj);
		if(obj.id == "search"){
			obj.value = defaultInputMessageSearch;
		}else{
			obj.value = defaultInputMessageSearchSmall;
		}				
	}
}

function changeStyleSearchText(obj){
	var mainClass;
	
	if(obj.id == "search"){
		mainClass = "left";		
	}else{
		mainClass = "text";		
	}

	if(obj.className == mainClass){
		obj.className = mainClass + " defaultText";
	}
	else{
		obj.className = mainClass;
	}
}

function setDefaultSearchText(){
	
	try{
		if (document.getElementById("search")){
			if (document.getElementById("search").value == ""){
				document.getElementById("search").value = defaultInputMessageSearch;
			}
			else{
				changeStyleSearchText(document.getElementById("search"));
			}
		}
	}
	catch(e){}

	try{
		if (document.getElementById("searchSmall")){
			if (document.getElementById("searchSmall").value == ""){
				document.getElementById("searchSmall").value = defaultInputMessageSearchSmall;
			}
			else{
				changeStyleSearchText(document.getElementById("searchSmall"));			
			}
		}
	}
	catch(e){}
	
}

function toggleCombination(id, directionID, inputID){
	var container = document.getElementById(id);
	var i;
 	var active = 0;
	
	for(i = 0; i < container.childNodes.length; i++){
		if (container.childNodes[i].tagName == "A"){
			if (container.childNodes[i].href.indexOf('javascript') != -1){
				container.childNodes[i].href = container.childNodes[i].href.substr(0 , container.childNodes[i].href.lastIndexOf("'") );
				container.childNodes[i].href = container.childNodes[i].href.substr(container.childNodes[i].href.lastIndexOf(",'") + 2 , container.childNodes[i].href.length );												

				container.childNodes[i].removeAttribute("class");								
				container.childNodes[i].removeAttribute("onclick");				
				
				if (active == 0 ){
					active = 1;
				}
			}
			else{
				container.childNodes[i].href = "javascript:setCityforPA('" + directionID + "','" + inputID + "','" + container.childNodes[i].href + "')";
				container.childNodes[i].setAttribute("onclick", "setActiveCity(this, '"+ id + "')");
			}
		}
	}
	
	if (active == 1){
		document.getElementById(inputID).value = "";
		document.getElementById(directionID + "Container").style.display = "none";
	}
	
}

function setCityforPA(directionID, inputID, city){
	city = city.substr(0, city.indexOf(".html"));
	city = city.substr(city.lastIndexOf("/") + 1);
	
	document.getElementById(inputID).value = city;	
	document.getElementById(directionID).innerHTML = city;
	document.getElementById(directionID + "Container").style.display = "inline";
}

function setActiveCity(currentElement, id){
	var container = document.getElementById(id);

	for (i = 0; i < container.childNodes.length; i++) {
		if (container.childNodes[i].tagName == "A") {
			container.childNodes[i].removeAttribute("class");
		}
	}

	currentElement.className = "active";	
}

/* Utillitis */

function getElementsByClassName(class_name)
{
  var all_obj,ret_obj=new Array(),j=0;
  if(document.all)all_obj=document.all;
  else if(document.getElementsByTagName && !document.all)all_obj=document.getElementsByTagName("*");
  for(i=0;i<all_obj.length;i++)
  {
    if(all_obj[i].className==class_name)
    {
      ret_obj[j]=all_obj[i];
      j++
    }
  }
  return ret_obj;
}      

function writeEmail(part1,part2, part3, name){
	var mail = part1 + "@" + part2 + "." + part3;

	var aTag = document.createElement('A');
	
	document.getElementById('emailContainer').appendChild(aTag);

	aTag.setAttribute('href', 'mailto:' + mail );

	if(name){
		aTag.innerHTML = name;	
	}
	else{
		aTag.innerHTML = mail;		
	}
}

function writeStaticEmail(part1,part2, part3, name){
	var container = Math.random();
	
	document.write("<span id=" + container + "></span>");
	
	var mail = part1 + "@" + part2 + "." + part3;

	var aTag = document.createElement('A');
	
	document.getElementById(container).appendChild(aTag);

	aTag.setAttribute('href', 'mailto:' + mail );

	if(name){
		aTag.innerHTML = name;	
	}
	else{
		aTag.innerHTML = mail;		
	}
}
