//Ajax
if (!window.XMLHttpRequest)
{
	window.XMLHttpRequest = function()
	{
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
} 

var MyXml = function(url,onComplete,onError) 
{ 
	var rp;	
	var onComplete;	
	var onError; 
	var requestUrl; 
	this.onComplete = onComplete; 
	this.onError = onError; 
	this.requestUrl = url; 
	this.get_request(); 
} 
MyXml.prototype = 
{
	get_request: function() 
	{ 
		this.rp = new XMLHttpRequest(); 
		if (this.rp) 
		{ 
			var self = this; 
			this.rp.onreadystatechange = function() 
			{ 
				self.readyhandler();	
			}; 
			
			//
			
			this.rp.open('GET', this.requestUrl, true); 
			
			this.rp.send(null); 
		} 
		else
		{
			alert('This browser has no suitable XMLHttpRequest functionality');
		}
	}
	,readyhandler: function()
	{ 
		if (this.rp.readyState == 4)
		{ 
			if (!this.rp.status || (this.rp.status >= 200 && this.rp.status < 400)) 
			{ 
				this.process(); 
			}
			else
			{ 
				if(this.onError) 
				{ 
					var tmpOnError = eval(this.onError); tmpOnError(this.rp.statusText);
				} 
				else
				{ 
					window.status = 'Error receiving xml data'; 
				}; 
					this.rp = null; 
			} 
		} 
	}
	,process: function()
	{
		if(this.onComplete)
		{
			var tmpComplete = eval(this.onComplete);
			tmpComplete(this.rp);
		}; 
		this.rp = null;
	}
} 


//---------------------------------------------------------------------------


//Navigation Toggle
function navtoggle(id)
{
	ul = "ul_" + id;
	ulElement = document.getElementById(ul);
	if (ulElement)
	{
		if (ulElement.className == 'UlClosed')
		{
			ulElement.className = "UlSub";
		}
		else
		{
			ulElement.className = "UlClosed";
		}
	}
}

//---------------------------------------------------------------------------

//GetSearchCount
function GetSearchCount(sessionID,langID,hostID)
{

//Gather Obj
	var ObjAreaID = document.getElementById('areaID');
	var ObjLocationID = document.getElementById('locationID');
	var ObjCity = document.getElementById('city');
	var ObjBedroom = document.getElementById('bedroom');
	var ObjHousetypeID = document.getElementById('housetypeID');
	var ObjPrice = document.getElementById('maxprice');
	var ObjSalesType = document.getElementById('stID');
	var ObjSalesArea = document.getElementById('saID');

	//var
	var areaID = ""; if(ObjAreaID) { areaID = ObjAreaID.value; }
	var locationID = ""; if(ObjLocationID) { locationID = ObjLocationID.value; }
	var city = ""; if(ObjCity) { city = ObjCity.value; }
	var housetypeID = ""; if(ObjHousetypeID) { housetypeID = ObjHousetypeID.value; }
	var bedroom = ""; if(ObjBedroom) { bedroom = ObjBedroom.value; }
	var maxprice = ""; if(ObjPrice) { maxprice = ObjPrice.value; }
	var salestype = ""; if(ObjSalesType) { salestype = ObjSalesType.value; }
	var salesarea = ""; if(ObjSalesArea) { salesarea = ObjSalesArea.value; }
					
	//Buidl xml url
	var SearchCountUrl = "/index.php?SID="+sessionID+"&s=fb80af925cdabeb0ef28f2b25722bb35&langID="+langID+'&areaID='+areaID+'&locationID='+locationID+'&city='+city+'&housetypeID='+housetypeID+'&bedroom='+bedroom+'&maxprice='+maxprice+'&hostID='+hostID+'&stID='+salestype+'&saID='+salesarea;
	new MyXml(SearchCountUrl,'ProcessSearchCount');
	//	alert(SearchCountUrl);
}

//---------------------------------------------------------------------------

//ProcessSearchCount
function ProcessSearchCount(request)
{
	//alert(request.responseText);
	//Process xmldata
	var syntec = request.responseXML.getElementsByTagName("syntec");	
	var count_string = getElementTextNS("", "count", syntec[0], 0);

	//add count to td
	var ObjSc = document.getElementById('SearchCount');
	if(ObjSc) { ObjSc.innerHTML = count_string; }
	
}

//---------------------------------------------------------------------------


//GetTab
function GetTab(sessionID,type,houseID,langID)
{

	//Buidl xml url
	SetTabUp(type);

} //End function MyOdbc()

//---------------------------------------------------------------------------

function SetTabUp(TabUp)
{
	var TabArray = new Array('desc','desc_t','map','map_t','project','sur','sur_t','fotos','contact');
	
	for(i=0; i < TabArray.length; i++)
	{
		var obj = document.getElementById(TabArray[i]);
		var objTab = document.getElementById('Container'+TabArray[i]);
		
		if(obj)
		{
			if(TabArray[i]==TabUp)
			{
				obj.className = 'TabDown';
				objTab.className = 'showtab';
			}
			else
			{
				obj.className = 'TabUp';
				objTab.className = 'hidetab';
			}
		}		
		
	} //End for(i=0; i < TabArray.length; i++)
	
} //End function SetTabUp(TabUp) 

//---------------------------------------------------------------------------

//ProcessPage
function ProcessPage(request)
{
	//alert(request.responseText);
	document.getElementById('PageBodyContainer').innerHTML = request.responseText;
} //End function ProcessKomnr()

//---------------------------------------------------------------------------

function getElementTextNS(prefix, local, parentElem, index)
{

	try
	{

		var result = "";
		if (prefix && isIE)
		{
			result = parentElem.getElementsByTagName(prefix + ":" + local)[index];
		}
		else
		{
			result = parentElem.getElementsByTagName(local)[index];
		}
		if (result)
		{
			if (result.childNodes.length > 1) {
				return result.childNodes[1].nodeValue;
			} else {
				return result.firstChild.nodeValue;    		
			}
		} else {
			return "n/a";
		}
	}
	catch (ex)
	{
		return "";
	}
} //End function getElementTextNS(prefix, local, parentElem, index)

//---------------------------------------------------------------------------

var SlideShowAuto = true;
var HouseI = 0;
var hi = getCookie("houseID");
if(hi) { HouseI = hi; }
function SlideshowStart()
{
	//Get Pic
	if(SlideShowArray)
	{
		var len = SlideShowArray.length;
		if(HouseI > (len-1) )
		{
			HouseI = 0;
		} //End if(HouseI < (len-1) )
		setCookie("houseID",HouseI);
		
		//Loop Slideshows
		for(i=0; i<len; i++)
		{
			if(i==HouseI)
			{
				document.getElementById(SlideShowArray[i]).className = 'showtab';
			}
			else
			{
				document.getElementById(SlideShowArray[i]).className = 'hidetab';
			}
			
		} //End for(i=0; i<len; i++)
		
		//GetSlideShow(sessionID,SlideShowArray[HouseI],langID,hostID);
		
		HouseI++;
	} //End if(SlideShowArray)

	//Test auto
	if(SlideShowAuto)
	{
		var ss = "SlideshowStart();";
		setTimeout(ss,5000);
	} //End if(SlideShowAuto)
	
} //End function SlideshowStart()


//---------------------------------------------------------------------------

//GetTab
function GetSlideShow(sessionID,houseID,langID,hostID)
{
	//Buidl xml url
	var houseurl = "webscripts/xml_slideshow.php?SID="+sessionID+"&houseID="+houseID+"&langID="+langID+'&hostID='+hostID;
	new MyXml(houseurl,'ProcessSlide');
		
} //End function MyOdbc()

//---------------------------------------------------------------------------

//ProcessSlide
function ProcessSlide(request)
{
	var obbox = document.getElementById('SlideBox');
	obbox.innerHTML = request.responseText;
} //End function ProcessSlide(request)

//---------------------------------------------------------------------------

//PrintProjects
function PrintProjects()
{
	url = "/script/JSprojects";
	new MyXml(url,'ProcessProjects');
	document.write('<div id=\"innerProject\">&nbsp;</div>');
} //End function PrintEvents()

//---------------------------------------------------------------------------

//ProcessProjects
function ProcessProjects(request)
{
	var tmpObject = document.getElementById('innerProject');
	if(tmpObject) { tmpObject.innerHTML = request.responseText;	}
} //End function ProcessEvents(request)

//---------------------------------------------------------------------------

//PrintEvents
function PrintEvents()
{
	url = "/script/JSevents";
	new MyXml(url,'ProcessEvents');
	document.write('<div id=\"innerEvent\">&nbsp;</div>');
} //End function PrintEvents()

//---------------------------------------------------------------------------

//ProcessEvents
function ProcessEvents(request)
{
	var tmpObject = document.getElementById('innerEvent');
	if(tmpObject) { tmpObject.innerHTML = request.responseText;	}
} //End function ProcessEvents(request)

//---------------------------------------------------------------------------

//popupWindow
function Popup(PopupUrl,PopupWidth,PopupHeight)
{
	ie=document.all;

	//Calculate Screen Width
 	var screenwidth = ie?screen.width:window.innerWidth;
	var screenheight = ie?screen.height:window.innerHeight;

    //Calculate popup left and top
	var NewLeft = ((screenwidth-PopupWidth) /2);
    var NewTop = ((screenheight-PopupHeight) /2);
	var tmpDate = new Date();
	var tmpDay=tmpDate.getDay()
	var tmpMonth=tmpDate.getMonth()
	var tmpYear=tmpDate.getYear()
	var tmpHour=tmpDate.getHours()
	var tmpMinute=tmpDate.getMinutes()
	var tmpSecond=tmpDate.getSeconds()	
	//Open popup in center screen en focus it		
	//if(window.pwindow) { window.pwindow.close(); }
	SyntecPopupName = tmpDay+tmpMonth+tmpYear+tmpHour+tmpMinute+tmpSecond;
	pwindow = window.open(PopupUrl, SyntecPopupName, 'width='+PopupWidth+', height='+PopupHeight+', left='+NewLeft+',top='+NewTop+', menubar=no, status=yes, location=no, toolbar=no, scrollbars=yes, resizable=yes');
	pwindow.focus();
	return pwindow;
}


//---------------------------------------------------------------------------

//SetCookie
function setCookie(name, value, expires, path, domain, secure) 
{
	document.cookie= name + "=" + escape(value) +
	((expires) ? "; expires=" + expires.toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
} //End function setCookie(name, value, expires, path, domain, secure) 

//---------------------------------------------------------------------------

//getCookie
function getCookie(name)
{
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
	begin = dc.indexOf(prefix);
	if (begin != 0) return null;
	} else {
	begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) {
	end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
}

//---------------------------------------------------------------------------
function SetS(Type)
{
	s = document.getElementById('s');	
	if(Type=="CB")
	{
		s.value = 'c4fc0a34-ed6d-63b4-1d8b-254a7388bdc5';
	}
	else
	{
		s.value = 'ce5b1a56-4bb4-7bc4-31d3-60de1c168eb5';
	}
	
	
}

function OpenNode(objNode)
{
	//Map parent
	if(objNode.parentElement) { _parent = objNode.parentElement; } else { _parent = objNode.parentNode; }
	
	//Test childs
	if(_parent.childNodes.length > 0)
	{
		//Loop childs
		for(i=0; i < _parent.childNodes.length; i++)
		{
			//Test ul
			if(_parent.childNodes[i].tagName=="UL")
			{
				//Test class
				if(_parent.childNodes[i].className=="ulSubClose")
				{
					_parent.className="selected";
					_parent.childNodes[i].className="ulSubOpen";
				} //End if(_parent.childNodes[i].className=="")
				else
				{
					_parent.className="";
					_parent.childNodes[i].className="ulSubClose";
				} //End else if(_parent.childNodes[i].className=="ulSubClose")
				
			} //End if(_parent.childNodes[i].tagName=="UL")
			
		} //End for(i=0; i < _parent.childNodes.length; i++)
		
	} //End if(_parent.childNodes.length > 0)

} //End function OpenNode(objNode)


var FadoutRequested = true;
var FadoutDoneRequested = false;
function fadeIn(fileName)
{
	FadoutRequested = false;
	blendimage('WebFoto', 'webImg', fileName, 300);
}
function fadeOut()
{
	FadoutRequested = true;
	if(!FadoutDoneRequested)
	{
		FadoutDoneRequested = true;
		setTimeout(realFadeOut,1000);
	}
		
}

function realFadeOut()
{
	if(FadoutRequested)
		blendimage('WebFoto', 'webImg', 'images/new/foto.jpg', 300);
	FadoutDoneRequested = false;
}
function write2log(message)
{
	document.getElementById('log').value += message+'\r\n';
}
