﻿function checkform(wo, was)
{
	of = document.getElementById(wo);
	var hidden_id = was;
	var reqfields,em,i,f,ty;			
			
	if(document.getElementById(hidden_id))
	{
		reqfields=document.getElementById(hidden_id).value.split(',');
		
	  	if(document.getElementById('errormsg'))
	  	{
	   		em=document.getElementById('errormsg');
		   	em.parentNode.removeChild(em);
	  	}
			
	  	for(i=0;i<reqfields.length;i++)
	  	{
	   		f=document.getElementById(reqfields[i]);
	   		if(f.previousSibling && /img/i.test(f.previousSibling.nodeName)){
	    		f.parentNode.removeChild(f.previousSibling);
	   		}
	   		f.style.background='white';
	
			
	   		if(f)
	   		{
	    		ty=f.type.toLowerCase();
	    		switch(ty)
	    		{
							case 'text':
								if(f.value==''){adderr(f.id,of)}
								if (!validEmail(f.value) && (f.id =='email')) {adderr(f.id,of)}						
							break;
							case 'textarea':
								if(f.value==''){adderr(f.id,of)}							
							break;
							case 'checkbox':
								if(!f.checked){adderr(f.id,of)}							
							break;
	    		}
	   		}
	  	}
	}

	if(document.getElementById('errormsg')){
		return false;
	}
}


function validEmail(email) {
  var strReg = "^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$";
  var regex = new RegExp(strReg);
  return(regex.test(email));
}

	
function adderr(id,of)
{
	var se,i,nli,na;
 	i=document.createElement('img');
 	i.src='bilder/icons/exclamation.png';
	i.alt='Error';
	i.title='This field has an error!';
	se=document.getElementById(id);
	se.parentNode.insertBefore(i,se)
	se.style.background='#fcc';

	if(!document.getElementById('errormsg'))
	{
		var em=document.createElement('p');
		em.id='errormsg';
		em.style.border='2px solid #fff';
		em.style.padding='5px';
		em.style.width='20em';
		em.style.backgroundColor='#c5dec1';
		em.appendChild(document.createTextNode('Bitte geben sie die Pflichtfelder* an!'))
		i=document.createElement('img');
		i.src='bilder/icons/exclamation.png';
		i.alt='Error';
		i.title='This field has an error!';
		em.appendChild(i);
		for(var i=0;i<of.getElementsByTagName('input').length;i++)
		{
			nowelm=of.getElementsByTagName('input')[i];
			if(/submit/i.test(nowelm.getAttribute('type')))
			{
				var sb=nowelm;
				break;
			}
		}
		sb.parentNode.insertBefore(em,sb);
		}
	
}

function einblenden()
{
 document.getElementById('anaus').style.display='block';
}

function ausblenden()
{
 document.getElementById('anaus').style.display='none';
}

function showhide(id)
{
	if(document.getElementById(id).style.display=='none')
		document.getElementById(id).style.display='block';
	else
		document.getElementById(id).style.display='none';
		
	//if(document.getElementById(id).style.visibility == 'hidden')
	//	document.getElementById(id).style.visibility = 'visible';
	//else
	//	document.getElementById(id).style.visibility = 'hidden';
}

function showhide_table(id)
{
	if(document.getElementById(id).style.display=='none')
		document.getElementById(id).style.display='block';
	else
		document.getElementById(id).style.display='none';
	for (var i = 0; i < document.getElementById(id).cells.length; i++)
	{
		//alert(i);
		if(document.getElementById(id).cells[i].style.display=='none')
			document.getElementById(id).cells[i].style.display=='block';
		else
			document.getElementById(id).cells[i].style.display='none';
	}
}

function UnCryptMailto( s )
{
	var n = 0;
    var r = "";
        for( var i = 0; i < s.length; i++)
        {
            n = s.charCodeAt( i );
            if( n >= 8364 )
            {
                n = 128;
            }
            r += String.fromCharCode( n - 1 );
        }
        return r;
    }

    function linkTo_UnCryptMailto( s )
    {
        location.href=UnCryptMailto( s );
    }

//window.onload=montre;
function montre(id) {
var d = document.getElementById(id);
	for (var i = 1; i<=15; i++) 
	{
		if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';			
		}
	}
	
	if (d) {d.style.display='block';}
}



function popup(loc)
{
	HTML ="<html><head><title>Bild</title><meta http-equiv=\"imagetoolbar\" content=\"no\">";
	HTML+="<style type=\"text/css\">body{margin:0px; background-color: #fff;}</style></head>";
	HTML+="<body marginwidth=\"0\" marginheight=\"0\" onBlur='top.close()'>";
	HTML+="<a href=\"javascript:window.close()\">";
	HTML+="<img src='bilder/grossbild/"+loc+"' border=0 alt=\"Fenster schliessen\" name=\"li\" onLoad='window.resizeTo(document.li.width+50,document.li.height+60)'>";
	HTML+="</a></body></html>";
	if(window.screen) var myleft=(screen.width-500)/2,mytop=50;
	popupImage=window.open('about:blank','_blank','resizable=yes,toolbar=no,scrollbars=no,width=100,height=200,left='+myleft+',top='+mytop);
	popupImage.document.open();
	popupImage.document.write(HTML);
	popupImage.document.close();
} 

function checkUncheckAll(theElement) 
{
   	var theForm = theElement.form, z = 0;
	for(z=0; z<theForm.length;z++)
	{
   		if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall')
   		{
 			theForm[z].checked = theElement.checked;
 	  	}
 	}
}

function checkUncheckOne(theElement, names) 
{
   	var theForm1 = theElement.form, x = 0;
	for(x=0; x<theForm1.length;x++)
	{
   		if(theForm1[x].type == 'checkbox' && theForm1[x].name == names)
   		{
   			if (theElement.checked == true) 
   			{
 				theForm1[x].checked = theElement.checked;
 			}
 	  	}
 	}
}

function checkUncheckTwo(theElement) 
{
   	var theForm = theElement.form, z = 0;
	for(z=0; z<theForm.length;z++)
	{
   		if(theForm1[x].type == 'checkbox' && theForm1[x].name == names)
   		{
 			theForm[z].checked = theElement.checked;
 	  	}
 	}
}

function checkVoraus(theElement, names) 
{
   	var theForm1 = theElement.form, x = 0;
	for(x=0; x<theForm1.length;x++)
	{
   		if(theForm1[x].type == 'checkbox' && theForm1[x].name == names)
   		{
   			if (theElement.checked == true) 
   			{
 				theForm1[x].checked = theElement.checked;
 			}
 	  	}
 	}
}

function checkVorausAll(theElement, names) 
{
   	var theForm1 = theElement.form, x = 0;
	for(x=0; x<theForm1.length;x++)
	{
   		if(theForm1[x].type == 'checkbox' && theForm1[x].name.indexOf(names) != -1)
   		{
   			theForm1[x].checked = theElement.checked; 			
 	  	}
 	}
}

function checkRuckwaerts(theElement, names) 
{
   	var theForm1 = theElement.form, x = 0;
	for(x=0; x<theForm1.length;x++)
	{
   		if(theForm1[x].type == 'checkbox' && theForm1[x].name == names)
   		{
   			if (theElement.checked != true) 
   			{
 				theForm1[x].checked = theElement.checked;
 			}
 	  	}
 	}
}

function checkHoch(theElement, names)
{
	var theForml = theElement.form, x = 0;
	for(x=0; x<theForml.length;x++)
	{
		if(theForm[x].type == 'checkbox' && theForml[x].name.test(names))
		{
			if (theElement.checked == true) 
   			{
 				theForm1[x].checked = theElement.checked;
 			}
		}
	}
}

function logoutConfirm()
{
	var anfrage = confirm('Sind Sie sicher, dass Sie ausloggen wollen?');
	if(anfrage)
	{
		document.logout.submit();
	}
}

function ConfirmSomething(Formname, Text)
{
	var anfrage = confirm(Text);
	if(anfrage)
	{
		document.forms[Formname].submit();
	}
}

function ConfirmCloseTool(Text)
{
	var anfrage = confirm(Text);
	if(anfrage)
	{
		tt_HideInit();
	}
}

/*
color picker
*/
var perline = 9;
     var divSet = false;
     var curId;
     var colorLevels = Array('0', '3', '6', '9', 'C', 'F');
     var colorArray = Array();
     var ie = false;
     var nocolor = 'none';
	 if (document.all) { ie = true; nocolor = ''; }
	 function getObj(id) {
		if (ie) { return document.all[id]; } 
		else {	return document.getElementById(id);	}
	 }

     function addColor(r, g, b) {
     	var red = colorLevels[r];
     	var green = colorLevels[g];
     	var blue = colorLevels[b];
     	addColorValue(red, green, blue);
     }

     function addColorValue(r, g, b) {
     	colorArray[colorArray.length] = '#' + r + r + g + g + b + b;
     }
     
     function setColor(color) {
     	var link = getObj(curId);
     	var field = getObj(curId + 'field');
     	var picker = getObj('colorpicker');
     	field.value = color;
     	if (color == '') {
	     	link.style.background = nocolor;
	     	link.style.color = nocolor;
	     	color = nocolor;
     	} else {
	     	link.style.background = color;
	     	link.style.color = color;
	    }
     	picker.style.display = 'none';
	    eval(getObj(curId + 'field').title);
     }
        
     function setDiv() {     
     	if (!document.createElement) { return; }
        var elemDiv = document.createElement('div');
        if (typeof(elemDiv.innerHTML) != 'string') { return; }
        genColors();
        elemDiv.id = 'colorpicker';
	    elemDiv.style.position = 'absolute';
        elemDiv.style.display = 'none';
        elemDiv.style.border = '#000000 1px solid';
        elemDiv.style.background = '#FFFFFF';
        elemDiv.innerHTML = '<span style="font-family:Verdana; font-size:11px;">Pick a color: ' 
          	+ '(<a href="javascript:setColor(\'\');">No color</a>)<br>' 
        	+ getColorTable() 
        	+ '<center><a href="http://www.flooble.com/scripts/colorpicker.php"'
        	+ ' target="_blank">color picker</a> by <a href="http://www.flooble.com" target="_blank"><b>flooble</b></a></center></span>';

        document.body.appendChild(elemDiv);
        divSet = true;
     }
     
     function pickColor(id) {
     	if (!divSet) { setDiv(); }
     	var picker = getObj('colorpicker');     	
		if (id == curId && picker.style.display == 'block') {
			picker.style.display = 'none';
			return;
		}
     	curId = id;
     	var thelink = getObj(id);
     	picker.style.top = getAbsoluteOffsetTop(thelink) + 20;
     	picker.style.left = getAbsoluteOffsetLeft(thelink);     
	picker.style.display = 'block';
     }
     
     function genColors() {
        addColorValue('0','0','0');
        addColorValue('3','3','3');
        addColorValue('6','6','6');
        addColorValue('8','8','8');
        addColorValue('9','9','9');                
        addColorValue('A','A','A');
        addColorValue('C','C','C');
        addColorValue('E','E','E');
        addColorValue('F','F','F');                                
			
        for (a = 1; a < colorLevels.length; a++)
			addColor(0,0,a);
        for (a = 1; a < colorLevels.length - 1; a++)
			addColor(a,a,5);

        for (a = 1; a < colorLevels.length; a++)
			addColor(0,a,0);
        for (a = 1; a < colorLevels.length - 1; a++)
			addColor(a,5,a);
			
        for (a = 1; a < colorLevels.length; a++)
			addColor(a,0,0);
        for (a = 1; a < colorLevels.length - 1; a++)
			addColor(5,a,a);
			
			
        for (a = 1; a < colorLevels.length; a++)
			addColor(a,a,0);
        for (a = 1; a < colorLevels.length - 1; a++)
			addColor(5,5,a);
			
        for (a = 1; a < colorLevels.length; a++)
			addColor(0,a,a);
        for (a = 1; a < colorLevels.length - 1; a++)
			addColor(a,5,5);

        for (a = 1; a < colorLevels.length; a++)
			addColor(a,0,a);			
        for (a = 1; a < colorLevels.length - 1; a++)
			addColor(5,a,5);
			
       	return colorArray;
     }
     function getColorTable() {
         var colors = colorArray;
      	 var tableCode = '';
         tableCode += '<table border="0" cellspacing="1" cellpadding="1">';
         for (i = 0; i < colors.length; i++) {
              if (i % perline == 0) { tableCode += '<tr>'; }
              tableCode += '<td bgcolor="#000000"><a style="outline: 1px solid #000000; color: ' 
              	  + colors[i] + '; background: ' + colors[i] + ';font-size: 10px;" title="' 
              	  + colors[i] + '" href="javascript:setColor(\'' + colors[i] + '\');">   </a></td>';
              if (i % perline == perline - 1) { tableCode += '</tr>'; }
         }
         if (i % perline != 0) { tableCode += '</tr>'; }
         tableCode += '</table>';
      	 return tableCode;
     }
     function relateColor(id, color) {
     	var link = getObj(id);
     	if (color == '') {
	     	link.style.background = nocolor;
	     	link.style.color = nocolor;
	     	color = nocolor;
     	} else {
	     	link.style.background = color;
	     	link.style.color = color;
	    }
	    eval(getObj(id + 'field').title);
     }
     function getAbsoluteOffsetTop(obj) {
     	var top = obj.offsetTop;
     	var parent = obj.offsetParent;
     	while (parent != document.body) {
     		top += parent.offsetTop;
     		parent = parent.offsetParent;
     	}
     	return top;
     }
     
     function getAbsoluteOffsetLeft(obj) {
     	var left = obj.offsetLeft;
     	var parent = obj.offsetParent;
     	while (parent != document.body) {
     		left += parent.offsetLeft;
     		parent = parent.offsetParent;
     	}
     	return left;
     }
     
     function initPage()
{
	var myCookies = getCookies();
	if ( myCookies[ "HIDEDIV" ] != null ){
		var mypanel=myCookies[ "HIDEDIV" ];
		if (mypanel!='none'){ 
		document.getElementById(mypanel).style.display = "block";
		document.getElementById('adminsidebutton').src = "/bilder/icons/admin_side.png";
		}
	}
}

function adminpan(MyDiv, MySide)
{	
	var oMyDiv = document.getElementById(MyDiv);
	var isHidden = ( oMyDiv.style.display != "none" ) ? 'none' : MyDiv;
	//var theother = (MyDiv=='adminpannel'+MySide) ? 'adminlist'+MySide :'adminpannel'+MySide;
	//document.getElementById( theother ).style.display="none";
	oMyDiv.style.display = ( oMyDiv.style.display != "none" ) ? "none" : "block";
	document.getElementById('adminsidebutton').src = ( oMyDiv.style.display != "none" ) ? "/bilder/icons/admin_side.png" : "/bilder/icons/admin_side_active.png";
	setCookie( "HIDEDIV" , isHidden );
}

// ********************** cookie Funktionen ************************

function getCookies(){
    var result = [] , i , values ,
    storedCookies = document.cookie.split(";"); 
    
    for ( i=0;i<storedCookies.length;i++)
    {
            values = storedCookies[ i ].split("=");  
		    result[ values[0].replace(/^ /,'') ] = values[ 1 ];
    };
    return result;
}

function setCookieTime( days ){
    if ( !days )
       return ( new Date( 2037 , 0 , 1 )).toGMTString();
    return new Date( ( new Date().getTime() + 1000 * 3600 * 24 * days ) ).toGMTString();
}

function setCookie( name , value ){
    document.cookie = name + "=" + unescape( value ) + ";"+
       "expires=" + setCookieTime()  + ";";
}

function deleteCookie( cookieName ){
    document.cookie = coookieName + "=;expires=" + setCookieTime( -1 );
}

// ********************** cookie Funktionen ( END ) ************************

 
 function checklength(field) {
     var textlength = field.value.length;
     
     if (textlength<120){field.style.backgroundColor='#ff9999'};
     if (textlength>=120 && textlength<=140){field.style.backgroundColor='#ffffcc'};
	 if (textlength>=140 && textlength<=180){field.style.backgroundColor='#ccffcc'};
	 if (textlength>=180 && textlength<=220){field.style.backgroundColor='#ffffcc'};
	 if (textlength>=220 ){field.style.backgroundColor='#ff9999'};
 }
