/**
 * @author 	Bassier, Bergmann & Kindler 
 * 			Digital Sales and Brand Specialists GmbH
 */


var _currentLang = document.documentElement.lang;
var strSearchText;
var tblHoverScr = false;


/**
 * JS	 	write additional JavaScript-Includes
 */
if (_currentLang == "") _currentLang = "de";
document.write('<script type="text/javascript" language="JavaScript" src="/js/constants_'+_currentLang+'.js" charset="utf-8"></script>');
//Font-Size-Script: 
document.write('<script type="text/javascript" language="JavaScript" src="/js/cookies.js" charset="utf-8"></script>');
document.write('<script type="text/javascript" language="JavaScript" src="/js/efa_fontsize.js" charset="utf-8"></script>');
//Table-Row-Hover IE6:
document.write('<!--[if lte IE 6]><script type="text/javascript" language="JavaScript" src="/js/tblhover.js" charset="utf-8"></script><![endif]-->');

/**
 * PDF 		Global function for opening pdf documents in the same new window.
 */
function loadPDF(strURL) {
	var pdfwin = window.open(strURL,"pdfwin","scrollbars=yes,resizable=yes");
	pdfwin.focus();
}

/**
 * Popup 		Global function for opening html-documents in a new sized window.
 */
function fenster(site,name,width,height,scroll) 
{
	var auf;
	breit = (screen.width - width) / 2;
	hoch = (screen.height - height) / 2;	
	auf = window.open(site, name, "width=" + width + ",height=" + height + ",scrollbars=" + scroll + ",top=" + hoch + ", left=" + breit);
}

/**
 * langAvail	Global function that opens a confirm-box; returns true/false by user action
 */
function confMsg(lang){
	if(lang == 'de') Check = confirm(_STRCONTENTAVAIL_DE);
	if(lang == 'en') Check = confirm(_STRCONTENTAVAIL_EN);

	return Check;
}

window.onload = function() {

	/**
 	* search 	set / clear field default value 
 	* 			set / clear CSS-Class for text in field (set inactive if default text is displayed)
 	*/
	if(document.getElementById('TEXT')) {
		strSearchText = _STRSEARCHTXTDEFAULT;
		if (document.getElementById('TEXT').value != strSearchText) {
			document.getElementById('TEXT').className = '';
		} else {
			document.getElementById('TEXT').className = 'inactive';
		}
		document.getElementById('TEXT').onfocus = function() {
			if(this.value==strSearchText) { this.value=''; this.className = ''; }
		};
		document.getElementById('TEXT').onblur = function() {
			if(this.value=='') { this.value=strSearchText; this.className = 'inactive'; }
		};
	}
	if(document.getElementById('searchform')) {
		document.getElementById('searchform').onsubmit = function() {
			if (document.getElementById('TEXT').value == _STRSEARCHTXTDEFAULT) {
				document.getElementById('TEXT').value = '';
			}
		};
	}
	
	/**
 	* zoom	 	write zoom-links into page 
 	* 			use efa_fontSize-Script
 	*/
	
	if(document.getElementById('zoomselect')) {				
		if (efa_fontSize06) {
			if (document.getElementById('langselect') && (document.getElementById('langselect') != '')) {
				document.getElementById('langselect').innerHTML += '&nbsp;|&nbsp;';
			}
			document.getElementById('zoomselect').innerHTML = efa_fontSize06.biggerLink + efa_fontSize06.resetLink + efa_fontSize06.smallerLink;			
		}
	}
	
	/**
 	* print	 	write print-link into page 
 	*/
	if(document.getElementById('print')) {
		document.getElementById('print').innerHTML = _STRPRINTSCRIPT;
	}
	
	/**
 	* zoomimage	set thumbnail-/zoom-view 
 	*/
	if(document.getElementsByTagName('a')) {
		var allZoomBox = document.getElementsByTagName('a');
		for (var i=0;i <= allZoomBox.length; i++) {
			if (allZoomBox[i] && allZoomBox[i].className) {
				if ((allZoomBox[i].className == "zoom tn fleft") || (allZoomBox[i].className == "zoom tn fright")) {
					//get icon-image ...
					var zoomIcon;
					var allSubImg = allZoomBox[i].getElementsByTagName('img');
					for (var j=0;j <= allSubImg.length; j++) {
						if (allSubImg[j] && allSubImg[j].className) {
							if (allSubImg[j].className == "iconlens") {
								zoomIcon = allSubImg[j];
							}
						}					
					}
					// set icon-tooltip
					if (zoomIcon) zoomIcon.alt = _STRZOOMOPEN;
					allZoomBox[i].onclick = function() {
						//get icon- & zoom-image ...
						var zoomIcon;
						var zoomImg;
						var allSubImg = this.getElementsByTagName('img');
						for (var j=0;j <= allSubImg.length; j++) {
							if (allSubImg[j] && allSubImg[j].className) {
								if (allSubImg[j].className == "iconlens") {
									zoomIcon = allSubImg[j];
								}
								if (allSubImg[j].className == "zoomimg") {
									zoomImg = allSubImg[j];
								}
							}						
						}
						if (this.className.indexOf('view') > -1) {
							// replace zoom with thumbnail ...
							this.className = this.className.replace('view','tn');
							if (zoomIcon) zoomIcon.alt = _STRZOOMOPEN; // set icon-tooltip
						} else if (this.className.indexOf('tn') > -1) {
							// replace thumbnail with zoom ...
							this.className = this.className.replace('tn','view');
							if (zoomIcon) zoomIcon.alt = _STRZOOMCLOSE; // set icon-tooltip
						}
												
						//prepare zoom-box if zoom-image has maximum size ...
						if(zoomImg.width >= 496) {
							if (this.className.indexOf('fright') > -1) this.className = this.className.replace('fright','frightmax');
							if (this.className.indexOf('fleft') > -1) this.className = this.className.replace('fleft','fleftmax');
						} else {
							if (this.className.indexOf('frightmax') > -1) this.className = this.className.replace('frightmax','fright');
							if (this.className.indexOf('fleftmax') > -1) this.className = this.className.replace('fleftmax','fleft');
						}
					}
				}
			}
		}
	}
	
	/**
 	* tombstones, fieldreports	generate mouse-over/-out-function to show text
 	*/
	if (document.getElementsByTagName('div')) {
		var allTSBox = document.getElementsByTagName('div');
		for (var x=0;x <= allTSBox.length; x++) {
			if (allTSBox[x] && allTSBox[x].className) {
	
				/** tombstones */
				if (allTSBox[x].className == "tombstones") {
					var allTSImg = allTSBox[x].getElementsByTagName('img');
					for (var y=0;y <= allTSImg.length; y++) {
						if (allTSImg[y]) {
							var _tmp;
							allTSImg[y].onmouseover = function() {
								_tmp = this.parentNode.getElementsByTagName('p')[0].innerHTML;
								if (this.alt) {
									this.parentNode.getElementsByTagName('p')[0].innerHTML = this.alt;
								}
							};
							allTSImg[y].onmouseout = function() {
								if (_tmp) {
									this.parentNode.getElementsByTagName('p')[0].innerHTML = _tmp;
								}
							};
						}					
					}
				}
				/** End tombstones */
				
				/** Erfahrungsberichte Azubis */
				if (allTSBox[x].className == "fieldreports") {
					var allAzubiReport = allTSBox[x].getElementsByTagName('span');
					for (var y=0;y <= allAzubiReport.length; y++) {
						if (allAzubiReport[y]) {
							if (allAzubiReport[y].className == "azubi") {
								var _tmp;
								var _tmpAzubiName;
								allAzubiReport[y].onmouseover = function() {
									var _tmpLayer = this.parentNode.parentNode.getElementsByTagName('div')[0];
									_tmp = this.title;
									_tmpAzubiName = this.innerHTML;
									if (_tmp) {
										_tmpLayer.className = 'reportLayer show';
										_tmpLayer.innerHTML = '<p><strong>'+_tmpAzubiName+'</strong><br/><br/>'+_tmp+'</p>';
										this.title = '';
										_tmpLayer.style.display = 'block';						
									}
								};
								allAzubiReport[y].onmouseout = function() {
									if (_tmp) {
										var _tmpLayer = this.parentNode.parentNode.getElementsByTagName('div')[0];
										_tmpLayer.className = 'reportLayer';
										_tmpLayer.style.display = 'none';
										_tmpLayer.innerHTML = '';
										this.title = _tmp;
									}
								};
							}
						}					
					}
				}
				/** End Erfahrungsberichte Azubis */
				
			}
		}
	}
		
	/**
 	* Tbl-Hover	table-hover-script, IE6 only ...
 	*/
	if(tblHoverScr == true) { initTblHover(); }
	
}