// general

function changeClass(varElementId,varClassname) {
    document.getElementById(varElementId).className = varClassname;
}

function getPos(varElementId) {
	var obj = document.getElementById(varElementId);
	var pos = {left:0, top:0};	
	if(typeof obj.offsetLeft != 'undefined')
	{
	   while (obj)
	   {
	       pos.left += obj.offsetLeft;
	       pos.top += obj.offsetTop;
	       obj = obj.offsetParent;
	   }
	}
	else
	{
	   pos.left = obj.left ;
	   pos.top = obj.top ;
	}
	return pos;
}

function setPos(varElementId,varReferenceElementId,diffX,diffY) {
    pos = getPos(varReferenceElementId);
    posX = pos.left + diffX;
    posY = pos.top + diffY;
    document.getElementById(varElementId).style.left = posX + "px";
    document.getElementById(varElementId).style.top = posY + "px";
}	

function openPopup(varLocation, varName, varWidth, varHeight, varPosLeft, varPosTop, varToolbar) {
	var showToolbar = "";
	if (varToolbar == "toolbar") showToolbar = "toolbar=yes, ";
	var PopupWindow = window.open(varLocation, varName, 'width=' + varWidth + ', height=' + varHeight + ', resizable=yes, scrollbars=yes, ' +  showToolbar + ' top=' + varPosTop + ', left=' + varPosLeft);
	PopupWindow.focus();
}



// view images
tryNr = 0;
function funcViewImage(varImageSrc,varAlt,varLanguage,varTitle) {
    tryNr = 0;
	imageView = new Image();
	imageView.src=(varImageSrc);
	funcImageData(varImageSrc,varAlt,varLanguage,varTitle);
}
function funcImageData(varImageSrc,varAlt,varLanguage,varTitle) {
	if((imageView.width!=0) && (imageView.height!=0)) {
		funcViewImageOpen(varImageSrc,varAlt,varLanguage,varTitle);
	}
	else {
		if (tryNr < 500) {
            tryAgain = "funcImageData('"+varImageSrc+"','"+varAlt+"','"+varLanguage+"','"+varTitle+"')";
		    whileLoadingImage = setTimeout(tryAgain,20);
            tryNr++;
        }
        else {
            alert("File not found.")
        }
	}
}
function funcViewImageOpen(varImageSrc,varAlt,varLanguage,varTitle) {
    if (varLanguage == "ger-DE") {
        varCloseWindow = "Fenster<br>schliessen";
    } else {
        varCloseWindow = "Close<br>window";
    } 
    if (varAlt != "") varTitle += " - " + varAlt;
	var posTop    = 10;
	var posLeft   = 10;
	var imgWidth  = imageView.width;
	var imgHeight = imageView.height;
	var windowWidth  = imgWidth + 20 + 20;
	var windowHeight = imgHeight + 20 + 20 + 40;
	var popupWindowSrc = varImageSrc;
	var uniqueWindowname = new Date();
	var popupWindowName = "viewImage" + uniqueWindowname.getTime();
	var popupWindowParams = 'width=' + windowWidth + ', height=' + windowHeight + ', resizable=no, scrollbars=auto, top=' + posTop + ', left=' + posLeft;
	popupView = window.open(popupWindowName, popupWindowName, popupWindowParams);
	popupView.document.write ("<html>\n<head>\n");
	popupView.document.write ("<title>"+varTitle+"</title>\n");
	popupView.document.write ("<style type=\"text/css\">");
	popupView.document.write ("<!--");
	popupView.document.write ("body,td,div, p, a, a:hover {");
	popupView.document.write ("font-family: Arial, Verdana, Helvetica, Tahoma, sans-serif;");
	popupView.document.write ("font-size: 9pt;");
	popupView.document.write ("color: #000;");
	popupView.document.write ("}");
	popupView.document.write ("-->");
	popupView.document.write ("</style>");
	
	popupView.document.write ("</head>\n");
	popupView.document.write ("<body class='bodyPopup'>\n");
    popupView.document.write ("<p style=\"width:" + windowWidth + "px;margin:10px 0px;text-align:center;\"><img src='" + varImageSrc + "' width='" + imgWidth + "' height='" + imgHeight + "' alt='"+varAlt+"' style=\"margin:0px;padding:0px;\"></p>\n");
	popupView.document.write ("<p style=\"width:" + windowWidth + "px;margin:0px;margin-top:20px;text-align:center;\"><a href='#' onClick='self.close();'>" + varCloseWindow + "</a></p>");
	popupView.document.write ("\n</body>\n</html>");
	popupView.focus();
}



// print

function printContent() {
	var varFuncPrint = (window.print) ? true : false;
	if (!varFuncPrint) {
		alert("Bitte benutzen Sie die Druckfunktion Ihres Browsers, um die Seite auszudrucken.");
	} else {
		window.print();
	}
    return false;
}



// specials

function plz_address_search(elementId) {
	var url_error	=  "";
	switch (elementId) {
	  case "country_search":
			var var_country =document.getElementById(elementId).options[document.getElementById(elementId).selectedIndex].value;
			var url_info	=  "/(country_search)/" + var_country;
	    break;
	  case "plz_search":
			var var_plz 	= document.getElementById(elementId).value;
			var url_info	=  "/(plz_search)/" + var_plz;
			if (var_plz.length != 5) {
				url_error =  "/(plz_error)/5";
			} 
	    break;
	}
	var basic_url = window.location.pathname;
	var stop = basic_url.indexOf("/(");
	if (stop != -1) basic_url = basic_url.substring(0, stop);
	var doc_url = basic_url + url_error + url_info;
	document.location.href = doc_url;
}

function world_address(elementId) {
	for (i = 0; i < document.getElementById(elementId).length; ++i) {
		if (document.getElementById(elementId).options[i].selected == true) {
			addressData = document.getElementById(elementId).options[i].value;
    	}
	}
	var addressDataParts = addressData.split(",");
	var var_location = addressDataParts[0];
	var var_addressId = addressDataParts[1];
	var basic_url = window.location.pathname;
	var stop = basic_url.indexOf("/(");
	if (stop != -1) basic_url = basic_url.substring(0, stop);
	if(var_addressId != "") {
		var doc_url = basic_url + "/(location)/" + var_location + "/(address)/" + var_addressId;
	} else {
		var doc_url = basic_url;
	}
	document.location.href = doc_url;
}