//  BROWSER *******************************************
/*
 var browserName = navigator.appName;
 var browserVersion = parseInt(navigator.appVersion);
 var browser;
 
 
 if (browserName == "Microsoft Internet Explorer" &&
          browserVersion < 8) {
     browser = "ie8down";
 }
*/





// ANTISPAM********************************************

function noSpam() {
    var a = document.getElementsByTagName("a");
    for (var i = a.length-1; i >= 0; i--) {
      if (a[i].className.search(/\bmaillink\b/) != -1) {
        var email = a[i].firstChild.data + "@" + a[i].lastChild.data;
        a[i].innerHTML = email;
        //a[i].href = "mailto:" + email;
      }
    }
  }
 window.onload=noSpam;
 




//*****************************************************
//***********__checkbox_TRUE / FALSE __****************
//*****************************************************


function toggleInput(el) {

//alert(el);

var checkbox="box_"+el;
var d="wert_"+el; 


if(document.getElementById(checkbox).checked==true) 
{ 
document.getElementById(d).value = 'true';
} 
else 
{ 
document.getElementById(d).value = '';
} 
} 

/*
	if (document.getElementById(el).disabled == '') {
		document.getElementById(el).disabled = 'true';
		document.getElementById(el).value = '';
	} else {
		document.getElementById(el).disabled = '';
		document.getElementById(el).value = 'true';
	}
}
*/



//****************************************************
//***********__AUTO_LOGOUT_JAVASCRIPT__***************

 /*  var test = "TEST"; 
  var time = 1000 * 60 * 19; //19 minutes  
  var theTimer = setTimeout("document.location.href='logout.php?comment="+test+"'",time);  
   */
  
//**********__VORSCHAU__***************************** 
  
  function vorschau(url){
	//alert(url);
	
	window.open(url, 'fenster1' , 'toolbar=no,status=no,menubar=no,scrollbars=1').focus();
	}

//**********__FLASH_CALLS_JS_RELOAD_PAGE__****************************

var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
// Handle all the the FSCommand messages in a Flash movie
function fscommand_DoFSCommand(command, args) {
	var fscommandObj = InternetExplorer ? fscommand : document.fscommand;
	 if(command == "reloadme") {
	
		
		reloadme();
	}
}

function reloadme(){


//alert("reloadme");

window.location.reload();
//window.location.href='edit.php?id='+id;
}

//**********__ANIMATE__LAYER__//__HIDE__SHOW__************************

function animateHeight(id, size, size2)
{

 //obj = document.getElementsByTagName("div");
   // if (obj[id].style.visibility == 'visible'){
// obj = document.getElementsByTagName(id);
    if (document.getElementById(id).style.visibility == 'visible'){
    //obj[id].style.visibility = 'hidden';
	//alert("close function called");
	closewin(id, size2);
	
    }
    else {
	
	openwin(id, size, size2);
   // obj[id].style.visibility = 'visible';
    }

}

function openwin(id, size, size2)
{
//alert("ANIMATE IT ");
//document.getElementById(id).style.backgroundColor = "red";
document.getElementById(id).style.display='block';
document.getElementById(id).style.visibility='visible';
el = document.getElementById(id);
var h_size1 = el.offsetHeight;
if (h_size1 < size)
{
el.style.height = h_size1 + 10+"px";
setTimeout("openwin('" + id + "','" + size + "','" + size2 + "')", 1);
}
}
//}


function closewin(id, size2)
{
//alert("close function called_"+id+"_"+size2);
document.getElementById(id).style.visibility='hidden';
el2 = document.getElementById(id);
var h_size2 = el2.offsetHeight;
if (h_size2 > size2)
{
el2.style.height = h_size2 - 10+"px";
setTimeout("closewin('" + id + "','" + size2 + "')", 1);
//document.getElementById(id2).style.visibility='hidden';
}
if (h_size2 == size2)
{
document.getElementById(id).style.visibility='hidden';
document.getElementById(id).style.display='none';
}
}

//***************** ANIMATE LAYER ONLY ONE OPENED ************************************



function animateHeight_only(id, size, size2, count)
{


//alert("Client Width:   " + document.getElementById(id).clientHeight);
        
//alert("Offset Width:   " + document.getElementById(id).offsetHeight);

//if (document.getElementById(id).style.visibility == 'visible'){
    //obj[id].style.visibility = 'hidden';
	//alert("close function called");
	//closewin_only(id, size2);
	
   // }else{
   
var my_id = "";   
var i = "";   
   

openwin_only(id, size, size2);	

	for(i = 0; i< count; i++){

          var my_id = "Layer" + i;
		  
		//  alert("close function called "+i);
            if(my_id != id){

               closewin_only("Layer" + i, size2);
                            }
	//}						
 }
	
}

function openwin_only(id, size, size2)
{
//alert("ANIMATE IT ");
//document.getElementById(id).innerHTML = "TEST";
//document.getElementById(id).style.backgroundColor = "red";
document.getElementById(id).style.display='block';
document.getElementById(id).style.visibility='visible';
el = document.getElementById(id);
var h_size1 = el.offsetHeight;
if (h_size1 < size)
{
el.style.height = h_size1 + 20+"px";
setTimeout("openwin_only('" + id + "','" + size + "','" + size2 + "')", 1);
}
}
//}


function closewin_only(id, size2)
{
//alert("close function called "+id);
document.getElementById(id).style.visibility='hidden';

el2 = document.getElementById(id);
//el2.style.height = 1 + "px";
var h_size2 = el2.offsetHeight;

if (h_size2 > size2)
{
el2.style.height = h_size2 - 20+"px";
setTimeout("closewin_only('" + id + "','" + size2 + "')", 1);
//document.getElementById(id2).style.visibility='hidden';
}
if (h_size2 == size2)
{
document.getElementById(id).style.visibility='hidden';
document.getElementById(id).style.display='none';
}
}

	
	
	function vorschau(url){
	//alert(url);
	//document.vorschau.ff.value=document.test.textfield.value;
	window.open(url, 'fenster1' , 'width=1024,height=600,toolbar=no,status=no,menubar=no,scrollbars,left=2, top=1').focus();
	}
	
	
	
	
	
	function animateHeight(id, size)
{

//alert("animate");
document.getElementById(id).style.display='block';
document.getElementById(id).style.visibility='visible';
el = document.getElementById(id);
var h_size1 = el.offsetHeight;
if (h_size1 < size)
{
el.style.height = h_size1 + 10+"px";
setTimeout("animateHeight('" + id + "','" + size + "')", 1);
}
}

function closewin(id2, size2)
{
//document.getElementById(id2).style.visibility='hidden';
el2 = document.getElementById(id2);
var h_size2 = el2.offsetHeight;
if (h_size2 > size2)
{
el2.style.height = h_size2 - 10+"px";
setTimeout("closewin('" + id2 + "','" + size2 + "')", 1);
//document.getElementById(id2).style.visibility='hidden';
}
if (h_size2 == size2)
{
document.getElementById(id2).style.visibility='hidden';
document.getElementById(id).style.display='none';
}
	
}	
	
//***************************** EDIT TEXT ****************************************
	
function getSelection(ta,empty)
	  { 
	  
	 
	  
	  var bits = [ta.value,'','','']; 
	  
	  
		if(document.selection)
		  { 
		   
		   
		    
			var vs = '#$%^%$#';
			var tr=document.selection.createRange()
			
			
			
			
			if(tr.parentElement()!=ta) return null;
			bits[2] = tr.textfield;
			
			
			
			tr.textfield = vs;
			fb = ta.value.split(vs);
			tr.moveStart('character',-vs.length);
			tr.textfield = bits[2];
			bits[1] = fb[0];
			bits[3] = fb[1];
			
			
			
		  }
		else
		  { if(ta.selectionStart == ta.selectionEnd && empty == false) return null;
		   
		  
			bits=(new RegExp('([\x00-\xff]{'+ta.selectionStart+'})([\x00-\xff]{'+(ta.selectionEnd - ta.selectionStart)+'})([\x00-\xff]*)')).exec(ta.value);
			
		  }
		 return bits;
	  }
	
function matchPTags(str)
	  { str = ' ' + str + ' ';

		ot = str.split(/\[[B|U|I].*?\]/i);
		ct = str.split(/\[\/[B|U|I].*?\]/i);
		return ot.length==ct.length;
	  }
	  

		
function str_replace(subject, search, replace) {
             return subject.split(search).join(replace);
              }
			  
	  
function addPTag(ta,pTag,pTag2,closeTag){ 

    var empty = false;
	
	

	if(pTag == "a href=*" ){
	Check = prompt("Url eingeben                                   ", "http://www.");
	//alert(Check);
	var url = Check;
	}
	
	if(pTag == "a href=*mailto:" ){
Check = prompt("Mailadresse eingeben                                   ", "");
//alert(Check);
	var mail = Check;
	}
	

	
	if(pTag == "pdf_spacer"){

	var spacer = pTag;
	var empty = true;
	}
	

	
	//pTag = pTag.replace('*', '"');
	//pTag2 = pTag2.replace('*', '"');
	
	
	 
 
    pTag = str_replace(pTag, '*', '"');
	pTag2 = str_replace(pTag2, '*', '"');

    bits = getSelection(ta,empty);
	  
	  
	
	  
	  
	  
		if(bits)
		  { if(!matchPTags(bits[2]))
			  { alert('\t\tInvalid Selection\nSelection contains unmatched opening or closing tags.');
				return;
			  }

			 
			 
			  
			if(mail && bits[2] != "" && mail != "" && bits[1] != "" && bits[3] != ""){
			// alert(mail);
			ta.value = bits[1] + '<' + pTag  + mail + pTag2 + '>' + bits[2] + '</' + closeTag + '>'+  bits[3];
             }
			 else if(url && bits[2] != ""  && url != "" && bits[1] != "" && bits[3] != ""){
			  ta.value = bits[1] + '<' + pTag  + url + pTag2 + ' target = "_blank">' + bits[2] + '</' + closeTag + '>'+  bits[3];
			 }
			  else if(spacer){
			  ta.value = bits[1] + '<' + pTag  + pTag2 + '>' + bits[2] +   bits[3];
			 }
			 else{
			ta.value = bits[1] + '<' + pTag  + pTag2 + '>' + bits[2] + '</' + closeTag + '>' + bits[3];
			
		  }}
	 }


//*********************************************************************************************************************************









//******************__OPEN__NEW_WINDOW_FOR_LARGE_IMAGE__******************************



function openPicture(imageType,imageName,imageWidth,imageHeight,alt,posLeft,posTop) { 
	newWindow = window.open("","newWindow","width="+imageWidth+",height="+imageHeight+",scrollbars=no,left="+posLeft+",top="+posTop);
	newWindow.document.open();
	newWindow.document.write('<html><title>'+imageName+'</title><body bgcolor="#ffffff" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onBlur="self.close()">'); 
	
	newWindow.document.write('<img src=\"'+imageName+'\" width='+imageWidth+' height='+imageHeight+' alt=\"'+alt+'\">'); 
	newWindow.document.write('</body></html>');
	
	//newWindow.document.close();
	newWindow.focus();
	//window.location.reload();
	//opener.location.reload();

}



