/*
#------------------------------------------
#  javascript.js
#  Author:  Jan Huschauer (EDV-Dienstleistungen)
#  Kontakt: Jan@Huschauer.de http://www.Huschauer.de
#  fuer:    Garant Immobilien GmbH (Stuttgart)
#  Version: 1.0a
#  Datum:   11.09.05
#  aktuall.:11.09.05
#  CVS:     $ID$
#------------------------------------------
#  11.09.05 created
#  16.12.10 ported to new layout
#------------------------------------------
*/

function submitSuchen(Command, ObjArt) {
	if (ObjArt)
		document.Suchen.ObjArt.value = ObjArt;
	if (Command)
		document.Suchen.Command.value = Command;
	document.Suchen.submit();
}

function checkKontakt() {
	var f = document.forms['Kontakt'];
	if (f) {
		if (f.elements['1_Vorname'].value == '' || f.elements['2_Name'].value == '') {
			alert('Bitte Ihren Namen eingeben!');
			f.elements['1_Vorname'].focus();
			return false;
		}
		if (f.elements['3_Strasse'].value == '') {
			alert('Bitte Ihre Adresse vollst&auml;ndig eingeben!');
			f.elements['3_Strasse'].focus();
			return false;
		}
		if (f.elements['4_PLZ'].value == '' || f.elements['5_Ort'].value == '') {
			alert('Bitte Ihre Adresse vollst&auml;ndig eingeben!');
			f.elements['4_PLZ'].focus();
			return false;
		}
		if (f.elements['6_Telefon'].value == '') {
			alert('Bitte Ihre Telefonnummer eingeben!');
			f.elements['6_Telefon'].focus();
			return false;
		}
		if (f.elements['7_Email'].value == '') {
			alert('Bitte Ihre Email-Adresse eingeben!');
			f.elements['7_Email'].focus();
			return false;
		}
		return true;
	}
	return false;
}

function checkEmailField(formName, elemName) {
	ret = true;
	if (document.layers||document.getElementById||document.all) {
		var str = document.forms[formName].elements[elemName].value;
		var filter = $EmailRegEx;
		if (filter.test(str)) {
			ret = true;
		} else {
			alert('Bitte eine g&uuml;ltige Email-Adresse eingeben!');
			ret = false;
		}
	}
	return ret;
}

function openWindow(theURL) {
	if (window.name != 'GarantPics') {
		theURL = window.location.protocol + '//' + window.location.host + '/empty.html';
		window.open(theURL, 'GarantPics', 'width=500,height=420,scrollbars=yes,screenX=0,screenY=0,resizable=yes,dependent=yes');
	}
}

var plus_x    = 70;
var plus_y    = 383;

function resizeWindow_(pic_x, pic_y) {
	if ((screen.availWidth <= window.outerWidth) || (screen.availHeight <= window.outerHeight)) {
		window.moveTo(0, 0);
		if (screen.availWidth  < pic_x + plus_x)  { 
			if (img) img.width = screen.availWidth - plus_x;
		}
/*		if (screen.availHeight  < pic_y + plus_y)  { 
			if (img) img.height = screen.availHeight - plus_y;
		} */
		return;
	}
}

function resizeWindow(pic_x, pic_y) {
	var thumb_x   = pic_cnt * 90;
	var winWidth  = pic_x;
	var winHeight = pic_y;
	if (screen.availWidth <= window.outerWidth) {
		winWidth = window.outerWidth - plus_x;
	}
	if (screen.availHeight <= window.outerHeight) {
		winHeight = window.outerHeight - plus_y;
	}
	if (winWidth < thumb_x) winWidth = thumb_x;
	if (winWidth < 512)     winWidth = 465;
	winWidth  = winWidth  + plus_x;
	winHeight = winHeight + plus_y;
	if ((screen.availWidth  < winWidth) || (screen.availHeight < winHeight)) { 
		resizeImage(pic_x, pic_y, winWidth - plus_x, winHeight - plus_y);
	}
	window.moveTo(0, 0);
	window.resizeTo(winWidth, winHeight);
	window.focus();
}

function resizeImage(scr_x, scr_y, pic_x, pic_y) {
	var img = document.getElementById('obj_pic');
	if (!img) return;
	var faktor = 1.0;
	var fakt_x = scr_x / pic_x;
	var fakt_y = scr_y / pic_y;
	if ((scr_x < pic_x) || (scr_y < pic_y)) {
		faktor = (fakt_x < fakt_y) ? fakt_x : fakt_y;
	}
	img.width  = faktor * pic_x;
	img.Height = faktor * pic_y;
}

function gotoHome() {
	location.href = 'http://'+location.host+'/';
}
function gotoSearch() {
	location.href = 'http://'+location.host+'/Suche.html';
}

function createDivs() {
	var bl = document.getElementById('le-3-schnellsuche');
	if (bl) {
		var div = document.createElement('div');
		div.id = 'logoclick';
		div.style.position = 'absolute';
		div.style.display = 'block';
		div.style.left   = (bl.offsetLeft + 41)+'px';
		div.style.top    = bl.offsetTop+'px';
		div.style.width  = '188px';
		div.style.height = '55px';
		div.style.zIndex = '100';
		div.style.cursor = 'pointer';
		div.onclick = gotoHome;
		//div.addEventListener('click', gotoHome, false);
		document.body.appendChild(div);
	}
	var tx = document.getElementById('text');
	if (bl && tx) {
		var div = document.createElement('div');
		div.id = 'searchclick';
		div.style.position = 'absolute';
		div.style.display = 'block';
		div.style.left   = tx.offsetLeft+'px';
		div.style.top    = tx.offsetTop +'px';
		div.style.width  = '226px';
		div.style.height = '40px';
		div.style.zIndex = '100';
		div.style.cursor = 'pointer';
		div.onclick = gotoSearch;
		//div.addEventListener('click', gotoSearch, false);
		document.body.appendChild(div);
	}
}

window.onresize = function() {
	var bl = document.getElementById('le-3-schnellsuche');
	var div = document.getElementById('logoclick');
	if (bl && div) {
		div.style.left   = (bl.offsetLeft + 41)+'px';
	}
	var tx = document.getElementById('text');
	div = document.getElementById('searchclick');
	if (bl && tx && div) {
		div.style.left   = tx.offsetLeft+'px';
	}
}

function isReady() {
	if (!document.body) {
		setTimeout(isReady, 13);
	} else {
		createDivs();
	}
}

window.onload = function() {
	isReady();
}

