// -------------- some form-functions -------------- // 

function formatValues(string) {
	var query = /(\w.+)_(\w.+)/;
	if (query.exec(string)) {
		string = RegExp.$1 + " " + RegExp.$2;
	}
	return "   " + string + "\n";;
}

function getValues(form,values){
	var f = form;
	var fields = values.split(",");
	var error = "";

	for (i=0; i < fields.length; i++) {
		if (fields[i].indexOf('select') > -1) {
			var t = fields[i].split("=");	
			if (document.forms[f].elements[t[1]].selectedIndex == 0) {
				error += formatValues(t[1]);
			}
		}
		else if (fields[i].indexOf('radio') > -1) {
			var t = fields[i].split("=");	
			var hit = -1;

			for (j=0; j < document.forms[f].elements[t[1]].length; j++) {
				if (document.forms[f].elements[t[1]][j].checked == true) {
					hit++;
				}
			}
			if (hit == -1) { error += formatValues(t[1]); }
		}
		else if (fields[i].indexOf('checkbox') > -1) {
			var t = fields[i].split("=");	
			if (document.forms[f].elements[t[1]].checked == false) {
				error += formatValues(t[1]);
			}
		}
		else if(document.forms[f].elements[fields[i]].value == ""){
			error += formatValues(fields[i]);
		}
	}
	if (error != "") {
		if (lang == "de") { alert("Fuer eine erfolgreiche Weiterverarbeitung benoetigen wir noch folgende Daten von Ihnen:\n"+error); }
		else { alert("Please fill the with * marked fields completely!\n"); }
		return false;
	}
	else {
		document.forms[f].submit();	
	}
}

function holdCheckbox(form,checkbox) {
	if (lang == "de") { alert('Aus datenschutzrechlichen Gruenden koennen wir Ihnen unser Trendjournal nur zusenden, wenn Sie sich damit einverstanden erklaeren.'); }
	else { alert('You must agree that we store your adress data electronically for marketing purposes.'); }
	document.forms[form].elements[checkbox].checked = true;
}

function getPrueffeld() {
	if (lang == "de") { alert('Hier bitte nichts eingeben. \n\nWie es scheint haben Sie CSS (Casscading Stylesheets) in Ihrem Browser deaktiviert.\nDieses Feld ist normalerweise nicht sichtbar und dient ausschliesslich zur Abwehr gegen Spammails.\n\nWir danken für Ihr Verständnis.'); }
	else { alert('Do not insert anything in this field. \n\nIt seems you have deactivated CSS (Casscading Stylesheets) in your browser.\nNormaly this field is not visible, its just used for antispam.\n\nThank you for your understanding.'); }
}


// -------------- some window-functions -------------- // 

function getWindowXpos() {
	if (window.screenLeft) return window.screenLeft;
	else if (window.screenX ) return window.screenX;
}
function getWindowYpos() {
	if (window.screenTop) return window.screenTop;
	else if (window.screenY ) return window.screenY;
	
}
function getWindowWidth() {
	if (window.innerWidth) return window.innerWidth;
	else if (document.body && document.body.offsetWidth) return document.body.offsetWidth;
	else return 0;
}
function getWindowHeight() {
	if (window.innerHeight) return window.innerHeight;
	else if (document.body && document.body.offsetHeight) return document.body.offsetHeight;
	else return 0;
}

function openViewer(which,width,height) {
	var t = window.open(which,'PopUp','width='+ width +',height='+ height +',screenX=' + (getWindowXpos()+10) + ', screenY=' + (getWindowYpos()+10) + ', left=' + (getWindowXpos()+10) + ', top=' + (getWindowYpos()+10) + ', scrollbars=0, resizable=0, toolbar=0, location=0, status=0');
	t.focus();
	return void(t);
}

function openWin(which,width,height) {
	var t = window.open(which,'PopUp','width='+ width +',height='+ height +',screenX=' + (getWindowXpos()+10) + ', screenY=' + (getWindowYpos()+10) + ', left=' + (getWindowXpos()+10) + ', top=' + (getWindowYpos()+10) + ', scrollbars=1, resizable=1, toolbar=1, location=0, status=1');
	t.focus();
	return void(t);
}



// -------------- some useful-functions -------------- // 

function hideLinkBorder(which) {
	if (!document.layers) {
		if (which.blur()) { which.blur(); }
	}
}

function setBookmark(url,titel) {
	if(navigator.userAgent.indexOf('MSIE') > 0) {
		window.external.AddFavorite(url, "FRANK WALDER " + titel);
	}
	else {
		if (lang == "de") { alert('Die verwendete Technik wird von Ihrem Browser ...\n     '+ navigator.userAgent +'\nNICHT unterstuetzt!\n\nSie können alternativ die Tastenkombination [Strg] + [D] ausprobieren!'); }
		else { alert('This method ist not supported by your browser:\n\n      '+ navigator.userAgent + '\n\n Please try the alternate key-combination [Strg] + [D]. '); }
	}
}

function replaceBackground() {
	if (ContentObj.typeOf != 'undefined') {
		var fb = (document.documentElement.clientWidth) ? document.documentElement.clientWidth : getWindowWidth();
		var newLeft = parseInt((fb-800)/2);
		var newTop  = parseInt((getWindowHeight()-ContentObj.getHeight())/2+21);
		if (newLeft < 0) newLeft = ContentObj.getLeft();

		if (newTop < 60) newTop = 0;
		ContentObj.css.backgroundPosition = newLeft+"px " +newTop+"px";
	}
}

function ResizeExtras() {
 	if (navigator.userAgent.indexOf("MSIE 7")>-1 || navigator.userAgent.indexOf("MSIE 8")>-1) {
 		replaceBackground();
 	}
}

// -------------- some init-functions -------------- // 

var SaveWindowWidth  = "";
var SaveWindowHeight = "";

var onload_extras = 0;
var onresize_extras = 0;
var isload = false;
var ContentObj = '';

function init() {
	SaveWindowWidth  = getWindowWidth();
	SaveWindowHeight = getWindowHeight();   

	if (document.getElementById && document.getElementById("ContentDiv")) {
		ContentObj = new LayerObject("ContentDiv");
		if ((navigator.userAgent.indexOf("MSIE 8") > -1 || navigator.userAgent.indexOf("MSIE 7") > -1) && navigator.userAgent.indexOf("MSIE 6") == -1 ) { 
			onresize_extras = 1;
			replaceBackground(); 
		}
	}
	
	if (onload_extras != 0) { OnloadExtras(); }
	isload = true;
}

function resizeFunction() {
 	if (navigator.userAgent.indexOf("MSIE 7")>-1) { 
	 	if (getWindowWidth()>800 || getWindowHeight()>600) { location.reload(); }
	}
	if (onresize_extras > 0) ResizeExtras();

}

window.onresize = resizeFunction;

function doNothing() {}