function divIdent(id) {
	if(document.all && !document.getElementById)	return document.all[id];
	else if(document.getElementById)	return document.getElementById(id);
	else	return false;
}
function divIdentStil(id) {
	if(document.all && !document.getElementById)	return document.all[id];
	else if(document.getElementById)	return document.getElementById(id).style;
	else	return false;
}

function grossansicht(bild,titel,jahr,material,groesse,preis) {
	if(window.focus('popup')) {
		window.blur('popup');
		window.focus();
	}
	var bild_array = bild.split('/');
	var bild_name = bild_array[bild_array.length-1];
	
	var hoehe = document.images[bild_name].height;
	var breite = document.images[bild_name].width;
	
	divIdent('gross').src = bild;

	var quotient = 1;
	
	if( bild.indexOf('fahnen') >= 0) {
		quotient = 0.35;
	}
	else {
		// Is image wider than high or vs?
		var quotient = parseInt(breite) / parseInt(hoehe);
	}
	// Height is greater than width
	if(quotient <= 1) {
		divIdentStil('gross').height = '360px';
		var neuerwert = 360 * quotient;
		divIdentStil('gross').width = neuerwert+'px';
	}
	// Width is greater than height
	else {
		divIdentStil('gross').width = '340px';
		var neuerwert = 340 / quotient;
		divIdentStil('gross').height = neuerwert+'px';
	}


	var neuehoehe = divIdentStil('gross').height;
	neuehoehe = parseInt(neuehoehe);
	if(neuehoehe > 0) {
		var differenz = 400 - neuehoehe;
		if(differenz > 0) {
			var abstand = (differenz / 2) - 4;
			divIdent('gross').style.marginTop = abstand+'px';
		}
	}
	
	var bildinfo = '<strong>'+titel+'</strong>, '+jahr+', '+material+', '+groesse+', '+preis;
	divIdent('info').innerHTML = bildinfo;
}

function popGrossansicht(elm) {
	var bild = divIdent(elm).src;
	var bild_array = bild.split('/');
	var bild_name = bild_array[bild_array.length-1];
	var inhalt = '<html><head><link rel="stylesheet" type="text/css" href="css/schrift.css"><title>Gisela Hubert</title></head>';
		inhalt += '<body><div id="includemain">';
		inhalt += '<img src="'+bild+'" border="0" height="540" />';
		inhalt += '<p><a href="javascript:self.close();">Schlie&szlig;en</a></p></div>';
		inhalt += '</body></html>';
	
	if(window.focus('popup'))
		window.focus('popup');
	else
		var popup = window.open('','popup','width=660,height=600,resizable=yes,menubar=no,scrollbars=auto,status=no,toolbar=no');
	
	popup.document.write(inhalt);
	popup.document.close();
	popup.focus();
}


function oeffnen( bild ) {
	window.open( 'assets/templates/cmb/popup.php?bild='+bild, 'popup', 'height=720,width=640,resizable=yes,scrollbars=auto,status=no,toolbar=no' );
}


function popDruck(type,elm) {
	var inhalt = '<html><head><link rel="stylesheet" type="text/css" href="css/schrift.css"><title>'+elm+'</title></head>'
				+'<body><div style="display:block;text-align:center;padding:0.5%;">';
	if(type == 'img') {
		inhalt += '<img src="'+elm+'" style="border:1px solid #000000;width:100%;"></div>'
				+ '<div id="includemain"><div style="float:left;"><a href="javascript:window.print();">Drucken</a></div>'
				+ '<div style="float:right;"><a href="javascript:self.close();">Schlie&szlig;en</a></div></div>';
	}
	inhalt += '</div></body></html>';
	
	if(window.focus('popup'))
		window.focus('popup');
	else
		var popup = window.open('','popup','width=600,height=300,resizeable=yes,menubar=yes,scrollbars=auto,status=no,toolbar=no');
	
	popup.document.write(inhalt);
	popup.document.close();
	popup.focus();	
}

function codeEmail( name, domain, displayname, subject ) {
	var linktext = ( displayname == '' ) ? name : displayname;
	var mailtolink = '<a href="mailto:'+name+'@'+domain+'">'+linktext+'@'+domain+'</a>';
	return mailtolink;
}



function eingabenCheck(formname) {
	var name = document.forms[formname].name.value;
	var email = document.forms[formname].email.value;
	var tel = document.forms[formname].tel.value;
	var textfeld = document.forms[formname].textfeld.value;

	var err = false;
	var ext = email.substring(email.lastIndexOf('.'),email.length+1);

	if(name.length < 3) {
		err = true;
		alert('Bitte geben Sie Ihren Namen an.');
	}
	if(!err && email.length < 7 && tel.length < 5) {
		err = true;
		alert('Bitte geben Sie entweder Ihre Email Adresse oder Ihre Telefonnummer an.');
	}
	if(!err && (email.length > 6 && ( email.indexOf('@') < 0 || email.indexOf('.') < 0 ))) {
		err = true;
		alert('Bitte geben Sie eine echte Email Adresse an.');
	}
	if(!err && (email.length > 6 && (ext.length < 3 || ext.length > 4))) {
		err = true;
		alert('Bitte geben Sie eine Email Adresse mit gültiger Landesendung ein.');
	}
	if(!err && tel.length > 0 && tel.length < 5) {
		err = true;
		alert('Bitte geben Sie eine gültige Telefonnummer an.');
	}
	if(!err && tel.length > 4 && tel.match(/[a-z]|[ßöäü,\.:;\'\"\+\*#<>\|`´\?=\(\)\[\]\{\}\&%$§!^°]/i)) {
		err = true;
		alert('Bitte verwenden Sie für die Telefonnummer nur Ziffern, das Leerzeichen, den Bindestrich und den Schrägstrich.');
	}
	if(!err && textfeld.length < 10) {
		err = true;
		alert('Bitte geben Sie Ihre Anfrage in das Textfeld ein.');
	}
	
	if(!err == true) {
		document.forms[formname].submit();
	}
}

// Öffnet die Seite, die gerade im Inhalts-Frame ist, in einem neuen Fenster und druckt sie
// Man beachte die Kontroll-Struktur, die in der toplink.inc und toplink_level1.inc untergebracht ist.
function druck_pop(id){
	var inhalt = '<div style="text-align:right;"><a href="javascript:window.print();">Drucken</a></div>';
	inhalt += document.getElementById(id).innerHTML;
	nw = window.open("","nw","width=700,height=500,menubar=no,toolbar=yes,scrollbars=yes,resizeable=yes,status=no");
	nw.document.write(inhalt);
	nw.focus();
	nw.document.close();

}
