// JavaScript Document

/****** target="_blank" *************************************************************/
function targetBlank(address) {
	var newWindow = window.open(address, "secondWindow", "width=1000, height=700, left=10 ,top=20, scrollbars=yes, location=yes, menubar=yes, status=yes, toolbar=yes");
	newWindow.focus();
}

/****** Screenauflösung *************************************************************/
//function getScreen() {
//	
//}


/****** listener ********************************************************************/
function selectChange(id, site) {
	if (window.location.search != "") {
		var getString = window.location.search;

		if (site == "entryForm") {
			var issetToH1 = getString.indexOf("toH1_h2");
			if (issetToH1 > 0) {
				var findLastAmp = getString.lastIndexOf("&");
				getString = getString.slice(0, findLastAmp);
			}
			window.location.href = "cmsIndex.php"+getString+"&toH1_h2="+id+"#anchorNewEntry";
		}else if (site == "setMain") {
			window.location.href = "cmsIndex.php?site=settings&id_main="+id+"#bottom";
		}else if (site == "setSub") {
			window.location.href = "cmsIndex.php?site=settings&id_sub="+id+"#bottom";
		}
	}
}

/****** Formularfelder leeren ********************************************************/
function resetCheck (site,editEntry,idName,idNr,ii) {
	var chk = window.confirm("Wollen Sie wirklich alle Formularfelder leeren?")
	if (chk == true) {
		window.location.href = "../scripts/functions.php?action=reset&site="+site+"&toSite="+site+"&editEntry="+editEntry+"&idName="+idName+"&idNr="+idNr+"&ii="+ii;
	}
}

/****** Unterpunkt hinzufügen ********************************************************/
function addSubitem (site,idName,idNr,ii) {
	if (window.location.search != "") {
		var getString = window.location.search;
		var findAmp = getString.indexOf("&");
		if (findAmp > 0) {
			getString = getString.slice(0, findAmp);
		}
	}
	window.location.href = "cmsIndex.php"+getString+"&toSite="+site+"&"+idName+"="+idNr+"&action=addSubitem#anchorEntry"+ii;
}

/****** Eintrag löschen *************************************************************/
function deleteEntry (site,idName,idNr) {
	if (site != "contact" && site != "backend") {
		var chk = window.confirm("Wollen Sie diesen Eintrag wirklich löschen?\r\n\r\nBedenken Sie, dass alle damit verbundenen Einträge und Unterpunkte ebenfalls gelöscht werden!\r\n\r\nWirklich löschen?")
	}else{
		var chk = window.confirm("Wollen Sie diese Kontaktdaten wirklich endgültig löschen?")
	}
	if (chk == true) {
		window.location.href = "../scripts/functions.php?action=delete&site="+site+"&"+idName+"="+idNr;
	}
}

/****** abbrechen ********************************************************************/
function entryAbort(site) {
	window.location.href = "cmsIndex.php?site="+site;
}

/****** Homepage ********************************************************************/
function goHome(url) {
	window.location.href = url+"/index.php?site=home";
}

/****** Größere Bildansicht *********************************************************/
function scaleImage(image, imgWidth, imgHeight, imgAlt) {
	
  /**
  ***** Hier den Style anpassen! *************************
  **/
	linkColor = "666";
	linkColorHover = "000";
	linkTextDec = "none";
	linkTextDecHover = "underline";
	myBorderStyle = "#333399 5px groove";
  /*******************************************************/
	
	windowWith = (imgWidth*1)+50;
	windowParam = "width="+windowWith+",";
	windowParam += "height=600,";
	windowParam += "left=10,top=20,scrollbars=yes,location=no,menubar=no,status=no,toolbar=no";
	
	var imgWindow = window.open("", "secondWindow", windowParam);
	imgWindow.document.open();
	
	with (imgWindow.document) {
		write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r\n');
		write('<html xmlns="http://www.w3.org/1999/xhtml">\r\n');
		write('\t<head>\r\n');
		write('\t\t<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />\r\n');
		write('\t\t<title>'+imgAlt+'</title>\r\n');
		write('\t\t<style type="text/css">\r\n');
		write('\t\t\ta:link { color:#'+linkColor+'; text-decoration:'+linkTextDec+'; font-style:normal; }\r\n');
		write('\t\t\ta:visited { color:#'+linkColor+'; text-decoration:'+linkTextDec+'; font-style:normal; }\r\n');
		write('\t\t\ta:hover { color:#'+linkColorHover+'; text-decoration:'+linkTextDecHover+'; font-style:normal; }\r\n');
		write('\t\t\ta:active { color:#'+linkColorHover+'; text-decoration:'+linkTextDecHover+'; font-style:normal; }\r\n');
		write('\t\t</style>\r\n');
		write('\t</head>\r\n');
		write('\t<body>\r\n');
		write('\t\t<div style="text-align:center;">\r\n');
		write('\t\t\t<img src="'+image+'" width="'+imgWidth+'" height="'+imgHeight+'" alt="'+imgAlt+'" style="border:'+myBorderStyle+';" />\r\n');
		write('\t\t\t<br />\r\n');
		write('\t\t\t<a href="javascript:window.close()">Fenster schlie&szlig;en</a>\r\n');
		write('\t\t</div>\r\n');
		write('\t</body>\r\n');
		write('</html>');
	}
	
	imgWindow.document.close();
	imgWindow.focus();
}

/****** Bildvergrößerung *************************************************************/
//function imageMagnify(imgNr, position) {
//	image[imgNr].width = orgWidth[imgNr]*2;
//	image[imgNr].height = orgHeight[imgNr]*2;
//	var styleValue = document.createAttribute("style");
//	if (position == true) {
//		styleValue.nodeValue = "position:relative; z-index:10; margin-right:-1.65em; margin-left:-1.65em; margin-bottom:-4.4em;";
//		image[imgNr].setAttributeNode(styleValue);
//	}
//}
//
//function imageDemagnify(imgNr) {
//	image[imgNr].width = orgWidth[imgNr];
//	image[imgNr].height = orgHeight[imgNr];
//	var styleValue = document.createAttribute("style");
//	styleValue.nodeValue = "position:static; z-index:1; "+orgStyle[imgNr];
//	image[imgNr].setAttributeNode(styleValue);
//}
//
//function init() {
//	image = document.getElementsByTagName("img");
//	orgWidth = new Array();
//	orgHeight = new Array();
//	orgStyle = new Array();
//	for (i=0; i < image.length; i++) {
//		orgWidth[i] = image[i].width;
//		orgHeight[i] = image[i].height;
//		orgStyle[i] = image[i].getAttribute("style");
//		var idValue = document.createAttribute("name");
//		idValue.nodeValue = i;
//		image[i].setAttributeNode(idValue);
//	}
//}



