/**************************************************************************************
# Author:	Alexander Geilhaupt <alex@geilhaupt.de>
# Datei:	/js/ajax.js
# Inhalt:	Ajax Bibliothek
#
# Copyright (c) 2001 - 2007 by Alexander Geilhaupt
# All Rights reserved. Unauthorized copying is a violance against applicable laws.
# You are not allowed to remove this comment.
#
**************************************************************************************/

// Hack for MB
function fitSearchContainer()
	{
	var width = screen.width;
	if(window.innerHeight)
		{
		var height = window.innerHeight;
		var width = window.innerWidth;
		var theight = height - 5;
		}
	else
		{
		var height = document.documentElement.clientHeight;
		var width = document.documentElement.clientWidth;
		if(height == 0)
			{
			height = document.getElementsByTagName('body')[0].clientHeight + 12;
			}
		var theight = height - 5;
		}
	var totalFromTop = document.getElementById("mercedes-content").offsetTop + document.getElementById("mercedes-content").offsetParent.offsetTop;
	var maxHeight = height - totalFromTop - 57;
	var style = document.getElementById("mercedes-content").style.height = maxHeight+"px";
	var scndstyle = document.getElementById("search-footer").style.top = (theight - document.getElementById("search-footer").offsetHeight)+"px";
	}
	



var xmlHttp = false;
var xmlHttpB = false;
var xmlHttpC = false;

try 
	{
    xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
	} 
catch(e) 
	{
    try 
		{
        xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
    	} 
	catch(e) 
		{
		xmlHttp  = false;
		}
	}
	
try 
	{
    xmlHttpB  = new ActiveXObject("Msxml2.XMLHTTP");
	} 
catch(e) 
	{
    try 
		{
        xmlHttpB  = new ActiveXObject("Microsoft.XMLHTTP");
    	} 
	catch(e) 
		{
		xmlHttpB  = false;
		}
	}
	
try 
	{
    xmlHttpC  = new ActiveXObject("Msxml2.XMLHTTP");
	} 
catch(e) 
	{
    try 
		{
        xmlHttpC  = new ActiveXObject("Microsoft.XMLHTTP");
    	} 
	catch(e) 
		{
		xmlHttpC  = false;
		}
	}
	
if(!xmlHttp  && typeof XMLHttpRequest != 'undefined') 
	{
    xmlHttp = new XMLHttpRequest();
	}

if(!xmlHttpB  && typeof XMLHttpRequest != 'undefined') 
	{
    xmlHttpB = new XMLHttpRequest();
	}

if(!xmlHttpC  && typeof XMLHttpRequest != 'undefined') 
	{
    xmlHttpC = new XMLHttpRequest();
	}


function initModelList(makeId,contentDiv,groupId,dealerId)
	{
	if(document.getElementById("showPkw"))
		{
		if(document.getElementById("showPkw").checked == true)
			{
			areaId = "1";
			}
		if(document.getElementById("showKrad").checked == true)
			{
			areaId = "5";
			}
		if(document.getElementById("showAll").checked == true)
			{
			areaId = "";
			}
		}
	else if(document.getElementById("area_id"))
		{
		areaId = document.getElementById("area_id").value;
		}
	else
		{
		areaId = "";
		}
	var page = "/includes/dbresults.php?qtype=models&groupId="+groupId+"&dealerId="+dealerId+"&makeId="+makeId+"&areaId="+areaId;
	if(xmlHttp) 
		{
		xmlHttp.open('GET', page, true);
		xmlHttp.onreadystatechange = function () 
			{
			if (xmlHttp.readyState == 4) 
				{
				document.getElementById(contentDiv).innerHTML = xmlHttp.responseText;
				}
			};
		xmlHttp.send(null);
		}
	}
	
function initMakeList(makeId,contentDiv,groupId,dealerId,areaId)
	{
	initModelList('noValue', 'modellist',groupId,dealerId);
	var page = "/includes/dbresults.php?qtype=getMake4Search&groupId="+groupId+"&dealerId="+dealerId+"&makeId="+makeId+"&areaId="+areaId;
	if(xmlHttpC) 
		{
		xmlHttpC.open('GET', page, true);
		xmlHttpC.onreadystatechange = function () 
			{
			if (xmlHttpC.readyState == 4) 
				{
				document.getElementById(contentDiv).innerHTML = xmlHttpC.responseText;
				}
			};
		xmlHttpC.send(null);
		}
	var bodypage = "/includes/dbresults.php?qtype=getBody4Search&groupId="+groupId+"&dealerId="+dealerId+"&makeId="+makeId+"&areaId="+areaId;
	if(xmlHttpB) 
		{
		xmlHttpB.open('GET', bodypage, true);
		xmlHttpB.onreadystatechange = function () 
			{
			if (xmlHttpB.readyState == 4) 
				{
				document.getElementById('bodylist').innerHTML = xmlHttpB.responseText;
				}
			};
		xmlHttpB.send(null);
		}
	}
	
function openWindow(site,frame,w,h,sb)
	{
	if(sb == 3)
		{
		sb = "yes,resizable=yes";
		w = screen.availWidth;
		h = screen.availHeight;
		}
	if(sb == 2)
		{
		sb = "yes,toolbar=yes,menubar=yes,resizable=yes,location=yes";
		}
	var topPosition = (screen.height / 2) - (h / 2);
	var leftPosition = (screen.width / 2) - (w / 2);
	if(sb == 1)
		{
		window.open(''+site+'',''+frame+'');
		}
	else
		{
		window.open(''+site+'',''+frame+'','width='+w+',height='+h+',scrollbars='+sb+',top='+topPosition+',left='+leftPosition+'');
		}
	}
	
function showBigPicture(image,carId,picWidth)
	{
	var bg = openBgDiv();
	document.getElementById('picFrame').className = "displayPicDialog";
	if(picWidth == undefined)
		{
		picWidth = 600;
		}
	var page = "/includes/showpic.php?pic="+image+"&car_id="+carId+"&width="+picWidth;
	if(xmlHttp) 
		{
		xmlHttp.open('GET', page, true);
		xmlHttp.onreadystatechange = function () 
			{
			if (xmlHttp.readyState == 4) 
				{
				document.getElementById('picFrame').innerHTML = xmlHttp.responseText;
				}
			};
		xmlHttp.send(null);
		}
	}
	
function showImprint(dgroupId)
	{
	var bg = openBgDiv();
	document.getElementById('imprintFrame').className = "displayPicDialog";
	var page = "/includes/showimprint.php?dealergroup_id="+dgroupId;
	if(xmlHttp) 
		{
		xmlHttp.open('GET', page, true);
		xmlHttp.onreadystatechange = function () 
			{
			if (xmlHttp.readyState == 4) 
				{
				document.getElementById('imprintFrame').innerHTML = xmlHttp.responseText;
				}
			};
		xmlHttp.send(null);
		}
	}
	
// Hintergrund DIV öffnen
function openBgDiv()
	{
	document.getElementById('dialog').className = "showDialog";
	if(window.innerHeight)
		{
		var height = window.innerHeight;
		}
	else
		{
		var height = document.documentElement.clientHeight;
		}
	if(height < document.getElementById('height').offsetTop)
		{
		height = document.getElementById('height').offsetTop;
		}
	var setUp = document.getElementById('dialog').style.height = height+"px";
	}

function closePicDialog()
	{
	document.getElementById('dialog').className = "hide";
	document.getElementById('dialog').innerHTML = "&nbsp;";
	document.getElementById('picFrame').className = "hide";
	document.getElementById('picFrame').innerHTML = "&nbsp;";
	document.getElementById('imprintFrame').className = "hide";
	document.getElementById('imprintFrame').innerHTML = "&nbsp;";
	}
	
function imageChange(carId,pic)
	{
	var page = "/html/mercedes-images.php?car_id="+carId+"&pic="+pic;
	document.getElementById('imageBox').innerHTML = "<p style=\"text-align:center; padding-top:65px; height:85px;\">Lade Fahrzeugbild...</p>";
	if(xmlHttp) 
		{
		xmlHttp.open('GET', page, true);
		xmlHttp.onreadystatechange = function () 
			{
			if (xmlHttp.readyState == 4) 
				{
				document.getElementById('imageBox').innerHTML = xmlHttp.responseText;
				}
			};
		xmlHttp.send(null);
		}
	}

/* added by Hartmann, date : 2009-06-12, show or hide the link embeded div*/
function hideLe(link_id)
	{
	document.getElementById(link_id).className = "hideLe";
	return false;
	}

function showLe(link_id)
	{
	document.getElementById(link_id).className = "showLe";
	return false;
	}

function chngLe(link_id)
	{
	if (document.getElementById(link_id).className == "showLe")
		{
		document.getElementById(link_id).className = "hideLe";
		}
	else
		{
		document.getElementById(link_id).className = "showLe";
		}
	return false;
	}

	
