/*=======================================================================================
//
// $Id: functions.js,v 1.42 2008/08/26 14:44:32 webadmin Exp $
//
// Passende Stylesheet-Datei zur Aufl&ouml;sung
//
//	auflx = window.screen.width;
//	aufly = window.screen.height;
//	document.getElementById('css').href = '/_css/tampy_main_' + auflx + "x" + aufly + ".css";
//
//=======================================================================================
*/

// Cookie setzen und zur entsprechenden Seite wechseln
function setCookieAndJump(cName,cValue,url) {
	$.cookie(cName,cValue);
	window.location.href = url;
}

// X/Y Koordinaten eines Elements ermitteln
function getElementCoords(eo){
	if(eo){
		var coords = {x: 0, y: 0};
		var i = 0;
		var eo_original = eo;
		do {
			i++;
			coords.x += eo.offsetLeft;
			coords.y += eo.offsetTop;
			eo = eo.offsetParent;
		} while(eo);
		
		return coords;
		
	} else {
		return null;
	}
}

function enlargeImg(imgId,imgBoxId) {
	offset = $('#'+imgId).offset();
	offset.left += 80;
	cssObj = {
        "position": "absolute",
        "top": offset.top+"px",
        "left": offset.left+"px"
	}
	$('#'+imgBoxId).css(cssObj);
	$('#'+imgBoxId).slideDown(600);
}

function hideImg(imgBoxId) {
	$('#'+imgBoxId).slideUp(600);
}

function changeAction1(target) {
  document.attrgroup.action = target;
  document.attrgroup.submit();
}

function changeAction(target) {
  document.anmeldung_dbinsert.action = target;
  document.anmeldung_dbinsert.submit();
}

function sendCoverimg(url,img) {
	window.location.href = url+'index.php?pageId=mt&action=pres_coverimg&coverimage='+img;
}

function submitAStatus(f) {
	document.getElementById('uploadstatus').value = 0;
	var w = 300;
	var h = 400;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	window.open('/uplstatus.html','upload','width='+w+',height='+h+',dependent=yes,'+
		'status=no,menubar=no,scrollbars=no,location=no,left='+winl+',top='+wint);
	f.submit();
}

function testSelection() {
	var sel = document.newattr.attr_group_id.selectedIndex;
	if (document.newattr.attr_group_id.value == "new") {
		document.newattr.attr_group_name.readOnly = false;
		document.newattr.attr_group_name.disabled = false;
	} else {
		document.newattr.attr_group_name.readOnly = true;
		document.newattr.attr_group_name.disabled = false;
		document.newattr.attr_group_name.value = document.newattr.attr_group_id[sel].text;
	}
}

function toggleFilterBox(id1,id2,id3) {
	if($('#'+id1).css("display") == 'block') {
		$('#'+id1).hide(300,function() { 
			$('#'+id2).attr("src","/icons/SmokeCons/24x24/Down.png");
			$('#'+id2).attr("title","Filter aufklappen");
			$('#'+id3).attr("class","menuheader");
		}); 
	} else {
		$('#'+id1).show(300,function() { 
			$('#'+id2).attr("src","/icons/SmokeCons/24x24/Up.png");
			$('#'+id2).attr("title","Filter zuklappen");
			$('#'+id3).attr("class","openheader");
		}); 
	}	
}

function toggleSearchFilter(id1,id2) {
	if($('#'+id1).css("display") == 'block') {
		$('#'+id1).hide(300,function() { 
			$('#'+id2).attr("src","/icons/SmokeCons/12x12/Plus.png");
			$('#'+id2).attr("title","Filter aufklappen");
		}); 
	} else {
		$('#'+id1).show(300,function() { 
			$('#'+id2).attr("src","/icons/SmokeCons/12x12/Minus.png");
			$('#'+id2).attr("title","Filter zuklappen");
		}); 
	}	
}


function getCValue(name) {
	var allC = document.cookie;
	var posName = allC.indexOf("; " + name + "=");
	
	if (posName == -1) {
		if (allC.indexOf(name + "=") == 0) posName = 0;
		else return 0;
	}
	
	var cValueBeg = allC.indexOf("=", posName)+1;
	var cValueEnd = allC.indexOf(";", posName+1);
	if (cValueEnd == -1) cValueEnd = allC.length;
	var cValue = allC.substring(cValueBeg, cValueEnd);
	return unescape(cValue);
}

function setFormChooserState() {
	if(document.cookie) {
		cValue = getCValue('formChooserState');
		return cValue;
	}
	return false;
}

/* mit referenzen
var fCStates_tdid = new Array('pres_text','pres_contact','pres_attributes','pres_references');
var fCStates_tdcolored_tl = new Array('mtext_tl','mcontact_tl','mattributes_tl','mreferences_tl');
var fCStates_tdcolored_nt = new Array('mtext_nt','mcontact_nt','mattributes_nt','mreferences_nt');
var fCStates_tdcolored_tr = new Array('mtext_tr','mcontact_tr','mattributes_tr','mreferences_tr');
var fCStates_link = new Array('mtext_link','mcontact_link','mattributes_link','mreferences_link');
*/

var fCStates_tdid = new Array('pres_text','pres_contact','pres_attributes');
var fCStates_tdcolored_tl = new Array('mtext_tl','mcontact_tl','mattributes_tl');
var fCStates_tdcolored_nt = new Array('mtext_nt','mcontact_nt','mattributes_nt');
var fCStates_tdcolored_tr = new Array('mtext_tr','mcontact_tr','mattributes_tr');
var fCStates_link = new Array('mtext_link','mcontact_link','mattributes_link');

function chooseForm(id1) {

	formChooserState = id1;
	document.cookie = "formChooserState="+formChooserState;
	
	for(i=0;i<=2;i++) {
	
		path1 = document.getElementById(fCStates_tdid[i]);
		path2 = document.getElementById(fCStates_tdcolored_tl[i]);
		path3 = document.getElementById(fCStates_tdcolored_nt[i]);
		path4 = document.getElementById(fCStates_tdcolored_tr[i]);
		path5 = document.getElementById(fCStates_link[i]);
	
		if (fCStates_tdid[i] == "pres_text") {
			path2.attributes['class'].nodeValue = 'round_corner_greyBB_tl';
		} else {
			path2.attributes['class'].nodeValue = 'round_corner_greyBB_nt';
		}
		path3.attributes['class'].nodeValue = 'round_corner_greyBB_nt';
		if (fCStates_tdid[i] == "pres_attributes") {
			path4.attributes['class'].nodeValue = 'round_corner_greyBB_tr';
		} else {
			path4.attributes['class'].nodeValue = 'round_corner_greyBB_nt';
		}
		path5.attributes['class'].nodeValue = 'smalldark';
	}
	
	path1 = document.getElementById(fCStates_tdid[formChooserState]);
	path2 = document.getElementById(fCStates_tdcolored_tl[formChooserState]);
	path3 = document.getElementById(fCStates_tdcolored_nt[formChooserState]);
	path4 = document.getElementById(fCStates_tdcolored_tr[formChooserState]);
	path5 = document.getElementById(fCStates_link[formChooserState]);
	
	path2.attributes['class'].nodeValue = 'round_corner_red_tl';
	path3.attributes['class'].nodeValue = 'round_corner_red_nt';
	path4.attributes['class'].nodeValue = 'round_corner_red_tr';
	
	path5.attributes['class'].nodeValue = 'smallwhite';
	
	for(i=0;i<=2;i++) {
		path1 = document.getElementById(fCStates_tdid[i]);
		path1.style.display = 'none';
	}
	path1 = document.getElementById(fCStates_tdid[formChooserState]);
	if (document.all) {
		path1.style.display = 'block';
	} else {
		path1.style.display = 'table';
	}
}


function show_send_message(id1,id2) {
	path1 = document.getElementById(id1);
	path2 = document.getElementById(id2);
	if (path2.style.display == 'block') {
		path2.style.display = 'none';
		path1.firstChild.nodeValue = "Kontakt";
	} else {
		path2.style.display = 'block';
		path1.firstChild.nodeValue = "Nachricht senden";
	}
}


function open_window_centered(file,title) {
	screenY = (screen.height/2)-200;
	screenX = (screen.width/2)-150;

	open(file,title,'dependent=yes,width=300,height=400,screenX='+screenX+',screenY='+screenY);
}

function open_window_centered_pv(file,title) {
	screenY = (screen.height/2)-300;
	screenX = (screen.width/2)-275;

	open(file,title,'dependent=yes,width=550,height=700,screenX='+screenX+',screenY='+screenY);
}

function toggleImage(name,path) {
	document.images[name].src = path;
	document.images[name].style.width = '400px';
}

/*
startseite = new Image();
startseite.src = "/icons/tampy/startseite.gif";
startseite_hover = new Image();
startseite_hover.src = "/icons/tampy/startseite_hover.gif";
anmeldung = new Image();
anmeldung.src = "/icons/tampy/anmeldung.gif";
anmeldung_hover = new Image();
anmeldung_hover.src = "/icons/tampy/anmeldung_hover.gif";
meintampy = new Image();
meintampy.src = "/icons/tampy/meintampy.gif";
meintampy_hover = new Image();
meintampy_hover.src = "/icon/tampy/meintampy_hover.gif";
faq = new Image();
faq.src = "/icons/tampy/faq.gif";
faq_hover = new Image();
faq_hover.src = "/icons/tampy/faq_hover.gif";
support = new Image();
support.src = "/icons/tampy/support.gif";
support_hover = new Image();
support_hover.src = "/icons/tampy/support_hover.gif";
*/

function changeImg(id,path) {
		document.getElementById(id).src = path;
}

function showEmail(id) {
	path = document.getElementById(id);
	if (path.style.display == 'block') {
		path.style.display = 'none';
	} else {
		path.style.display = 'block';
	}
}

function previous_image(img_id,text_id) {
	path = document.getElementById(img_id).src;
	textpath = document.getElementById(text_id);
	if (path == img_1) {
		if(img_3 != "") {
			document.getElementById(img_id).src = img_3;
			document.getElementById(text_id).firstChild.nodeValue = text_3;
			return;
		} else {
			if(img_2 != "") {
				document.getElementById(img_id).src = img_2;
				document.getElementById(text_id).firstChild.nodeValue = text_2;
				return;
			}
		}
		return;
	}
	if (path == img_2) {
		if(img_1 != "") {
			document.getElementById(img_id).src = img_1;
			document.getElementById(text_id).firstChild.nodeValue = text_1;
			return;
		} else {
			if(img_3 != "") {
				document.getElementById(img_id).src = img_3;
				document.getElementById(text_id).firstChild.nodeValue = text_3;
				return;
			}
		}
		return;
	}
	if (path == img_3) {
		if(img_2 != "") {
			document.getElementById(img_id).src = img_2;
			document.getElementById(text_id).firstChild.nodeValue = text_2;
			return;
		} else {
			if(img_1 != "") {
				document.getElementById(img_id).src = img_1;
				document.getElementById(text_id).firstChild.nodeValue = text_1;
				return;
			}
		}
		return;
	}
}

function next_image(img_id,text_id) {
	path = document.getElementById(img_id).src;
	textpath = document.getElementById(text_id);
	if (path == img_1) {
		if(img_2 != "") {
			document.getElementById(img_id).src = img_2;
			document.getElementById(text_id).firstChild.nodeValue = text_2;
			return;
		} else {
			if(img_3 != "") {
				document.getElementById(img_id).src = img_3;
				document.getElementById(text_id).firstChild.nodeValue = text_3;
				return;
			}
		}
		return;
	}
	if (path == img_2) {
		if(img_3 != "") {
			document.getElementById(img_id).src = img_3;
			document.getElementById(text_id).firstChild.nodeValue = text_3;
			return;
		} else {
			if(img_1 != "") {
				document.getElementById(img_id).src = img_1;
				document.getElementById(text_id).firstChild.nodeValue = text_1;
				return;
			}
		}
		return;
	}
	if (path == img_3) {
		if(img_1 != "") {
			document.getElementById(img_id).src = img_1;
			document.getElementById(text_id).firstChild.nodeValue = text_1;
			return;
		} else {
			if(img_2 != "") {
				document.getElementById(img_id).src = img_2;
				document.getElementById(text_id).firstChild.nodeValue = text_2;
				return;
			}
		}
		return;
	}
}
