/*
JavaScript-Functions for dimX
dimX copyright by adera-web : clever internet
Script copyright by W.Modrow
*/
function checkGbForm() {	//Gästebuch-Eintrag
	var f = document.gb_form;
	if (!f)
		return false;
	var err = "";
	if (f.gb_name.value == "")
		err+= gbErr1;	//"Bitte geben Sie Ihren Namen ein\n";
	//if (f.gb_email.value == "")
	//	err+= gbErr2;   //"Bitte geben Sie Ihre eMail-Adresse ein\n";
	if (f.gb_email.value != "" && !checkEmail(f.gb_email.value))
		err+= gbErr3;	//"Die eingegebene eMail-Adresse scheint fehlerhaft zu sein.\n";
	if (f.gb_text.value == "")
		err+= gbErr4;	//"Bitte geben Sie einen Text ein\n";
	if (f.gb_code.value == "" || f.gb_code.value.length != 4)
		err+= gbErr5;	//"Bitte geben Sie den angezeigten Code ein\n";
	if (err != "") {
		alert (err);
		return false;
	}
	return true;
}
function checkEmail(str) {
    var re = new RegExp("^([a-zA-Z0-9\\-\\.\\_]+)(\\@)([äöüÄÖÜa-zA-Z0-9\\-\\.]+)(\\.)([a-zA-Z]{2,4})$");
    return re.test(str);
}
function dimx_checkFormFileTypes(f) {
	if (!f || !dimx_fileFields)
		return false;
	var err = false;
	var err2 = false;
	for (var i in dimx_fileFields) {
		var el = f.elements[i];
		if (el && el.value!="") {
			found = false;
			var p = el.value.lastIndexOf(".");
			if (p > 0) {
				var t = el.value.substring(p+1).toLowerCase();
				var arr = dimx_fileFields[i].split("|");
				for (var j=0; j<arr.length; j++) {
					if (arr[j] == t) {
						found = true;
						break;
					}
				}
			}
		   	if (!found)
				err = true;
			if (el.parentNode)
				el.parentNode.style.border = found ? "0px solid black" : "1px solid red";
		}
	}
	for (var i in dimx_codeFields) {
		var el = f.elements[i];
		if (el) {
            var sum = 0;
            for (var j=0; j<el.value.length; j++)
                sum+= el.value.charCodeAt(j);
            err2 = sum != dimx_codeFields[i];

			if (err2 && el.parentNode)
		   		el.parentNode.style.border = "1px solid red";
		}
	}
	if (err || err2) {
		var errTx = err ? dimx_fileTypeErrorString : "";
		errTx = errTx ? errTx+"\n\n" : errTx;
		errTx+= err2 ? dimx_codeErrorString : "";
    	alert (errTx);
        return false;
    }
    return true;
}
/*
function checkCnForm(f) {	//Kontaktformular
	if (!f || !checkFields)
		return false;
	var err = false;
	var radios = new Array();
	try {
	    for (var i=0; i<checkFields.length; i++) {
            var field = f.elements[checkFields[i]];
            if (field) {
            	if (field.length && !radios[checkFields[i]]) {	//radio
            		for (var j=0; j<field.length; j++) {
                        if (field[j].checked) {
                            radios[checkFields[i]] = 1;
                            break;
                        }
                    }
                    if (!radios[checkFields[i]]) {
                        err = true;
                        break;
                    }
            	}
                else if ((field.type.toLowerCase() == "text" || field.type.toLowerCase() == "textarea") && field.value.replace(/ /g,"") == "") {
                    err = true;
                    break;
                }
                else if (field.type.toLowerCase() == "checkbox" && !field.checked) {
                	err = true;
                    break;
               	}
            }
        }

        if (err) {
            alert ("Bitte füllen Sie alle mit * gekennzeichneten Felder aus.");
            return false;
        }
        return true;
	}
	catch (e) {
		window.status= "Fehler: "+e.name+" : "+e.description;
		return false;
	}
}
*/
var w,h;
var currentImg = -1;
function showImg(id) {
	var img = document.images['album_img'];
	img.src = "gfx/clearpixel.gif";
	img.width = 1;
	img.height = 1;
	w = album_imgs[id][1];
	h = album_imgs[id][2];
	var alt = album_imgs[id][6];
	var windowTitle = alt ? alt : "Detail";
	currentImg = id;
	var src = "<html><head><title>"+windowTitle+"</title></head><body><img src='"+pageMediaDir+"/"+album_imgs[id][0]+"' border=0 title='"+alt+"'></body></html>";
	img.onclick = album_imgs[id][3] ? function() { win=window.open("","_blank","menubar=yes,scrollbars=yes,resizable=yes,width="+(album_imgs[id][4]+40)+",height="+(album_imgs[id][5]+50));win.document.write(src);win.document.close() } : "";
	img.style.cursor = album_imgs[id][3] ? "pointer" : "default";
	var hr = document.getElementById("album_headRow");
	var p = Math.round(album_imgs[id][1]/album_imgs[id][4]*100);
	if (hr) {
		var hrtx = album_imgs[id][3] ? albumStr1+p+"%)<br>" : "";	//"Klicken Sie auf das Bild, um es in Originalgr&ouml;&szlig;e anzuzeigen (Ansicht = "
		if (alt)
			hrtx = "<b>"+alt+"</b><br>" + hrtx;
		hr.innerHTML = hrtx+"<br>";
	}
	img.onload = function() {var img=document.images['album_img'];img.width = w;img.height = h;img.title=alt; };
	img.src = pageMediaDir+"/"+album_imgs[id][0];
}

function showNextImg() {
	currentImg = currentImg == album_imgs.length-1 ? 0 : currentImg+1;
	showImg(currentImg);
}
function showPrevImg() {
	currentImg = currentImg == 0 ? album_imgs.length-1 : currentImg-1;
	showImg(currentImg);
}

//------------------ Submenü-Funktionen
var curr = false;
var currId = 0;
var fsize = 0;
var targetSize = subFontSize;
var vis = new Array();
var hideAll = false;
var showTimer = null;
var hideTimer = null;

function showSubFor(mId) {
	if (showTimer)
		window.clearTimeout(showTimer);
	if (hideTimer)
		window.clearTimeout(hideTimer);
	if (currId == mId) {
		return;
	}
	showTimer = window.setTimeout("showSubFor_now("+mId+")",menuDelay);
}

function showSubFor_now(mId) {
	if (showTimer)
		window.clearTimeout(showTimer);
	hideAll = false;
	if (currId == mId) {
		if (hideTimer)
			window.clearTimeout(hideTimer);
		return;
	}
	var sub = document.getElementById("sub_"+mId);
	if (!sub) {
	    hideSubsBeyond(0);
        vis = new Array();
    	return;
	}
	fsize = targetSize;
	anim();

	var offx=0,offy=0,coords;
	if (!mPath[mId]) {				//Top-Level
		hideSubsBeyond(0);
		aId = "area_"+mId;
	    var el = document.getElementById(aId);
        coords = el.coords.split(",");
        cont = document.getElementById("menubar");
        var offsetPos = getOffsetPos(cont);
	    offx = offsetPos[0]+parseInt(coords[0]);
        offy = offsetPos[1]+parseInt(coords[1]);
        if (subMode == "top") {
        	offy+=(parseInt(coords[3]-parseInt(coords[1])-5));
        	offx+=borderL;
        }
        else {
        	offx+=(parseInt(coords[2])-margLeft);
        	offy+=-1;
        }
    }
    else {
    	var lnk = document.getElementById("td_"+mId);
    	var offsetPos = getOffsetPos(lnk);
    	offx = offsetPos[0]+lnk.offsetWidth;
        offy = offsetPos[1];
    }

	sub.style.top = (offy+4)+"px";
	sub.style.left = (offx-2)+"px";

	fsize = 0;
	curr = sub;
	currId = mId;
	vis[vis.length] = sub;
	anim();
}
function getOffsetPos(elem) {
	var offx=0,offy=0;
	while (elem) {
		offx+= elem.offsetLeft ? elem.offsetLeft : 0;
		offy+= elem.offsetTop ? elem.offsetTop : 0;
		elem = elem.offsetParent;
	}
	return new Array(offx,offy);
}
function hideSubsBeyond(mId) {
	if (showTimer)
		window.clearTimeout(showTimer);
	if (hideTimer)
		window.clearTimeout(hideTimer);
	hideAll = false;
	fsize = targetSize;
	anim();
	curr = false;
	currId = 0;
	for (var i=vis.length-1; i>=0; i--) {
		var sub = vis[i];
		if (sub.id == "sub_"+mId)
			return;
        sub.style.left = "-9000px";
        sub.style.top = "-1000px";
    }
}
function checkHideAll() {
	if (hideAll) {
		hideSubsBeyond(0);
		currId = 0;
		curr = false;
	}
}
function prepHideAll() {
	if (showTimer)
		window.clearTimeout(showTimer);
	hideAll = true;
	hideTimer = window.setTimeout("checkHideAll()",500);
}
function anim() {
	if (curr && fsize <= targetSize) {
		for (var i=0; i<mCont[currId].length; i++)
			document.getElementById("td_"+mCont[currId][i]).style.fontSize=fsize+"px";
		fsize+=targetSize/2;
		if (fsize <= targetSize)
			window.setTimeout("anim()",50);
	}
}
var dx_subCls = new Array("n","hi","ho","n2","hi2","ho2");
function dx_sout(el,cls) {						//Submenü - onMouseOut
	el.className = "sub_"+dx_subCls[cls];
	prepHideAll();
}
function dx_sov(el,cls,hideBeyond,showFor) {	//Submenü - onMouseOver
	hideSubsBeyond(hideBeyond);
	if (cls > -1)
		el.className = "sub_"+dx_subCls[cls];
	if (showFor)
		showSubFor_now(showFor);
}
function dx_sclk(id) {							//Submenü - click
	if (isNaN(id))
		location.href=id+sessionString1;
	else
		location.href="/index.php?id="+id+sessionString1;
}

function dimx_switchDisplay(elId) {
	var el = document.getElementById(elId);
	if (el && el.style) {
		el.style.display = el.style.display == "none" ? "block" : "none";
	}
}
function arrangeTitle() {
	return;
}

function verschicken() {
	email();
}
function toBlock(num) {
	var blk = document.getElementById('blk_'+num);
	if (blk){ blk.scrollIntoView(); } else {window.scrollTo(0,0); }
}

//nav2 - Funktionen
function nav2_go(id) {
	if (isNaN(id))
		location.href=id+sessionString1;
	else
		location.href="index.php?id="+id+sessionString1;
}
function nav2_cls(el,mode,isSub,padd) {
	var cls = mode ? "nav2_h" : "nav2_n";
	cls = isSub ? cls+"2" : cls;
	el.className = cls;
	if (isSub)
		el.style.paddingLeft = padd;
}

function writeTx(tx) {
	document.write(tx);
}
function dimx_setImgSrc(img,src) {
	img.src = src;
}
function dimx_popup(url,nm,params) {
    var w = window.open(url,nm,params);
    w.focus();
}

//----------------------------------
