/*
_______________________________________________________
lib.js
JS Functions for UCM
_______________________________________________________

Include the correct CSS stylesheet
Author:		manfred.schneiderbauer@world-direct.at
Version:	2.0
Date:		2003-01-20

Description:
Calls one of five different external css files depending on which browser is used.
The CSS files must be named:
'ie.css'	CSS stylesheet for Internet Explorer (all versions)
'nn.css'	CSS stylesheet for Netscape Navigator 4
'nn-l.css'	CSS stylesheet for Netscape Navigator 4 running under Unix/Linux
'dm.css'	CSS stylesheet for W3C DOM standards compliant browsers (all Gecko browsers, Opera 7 and higher)
'op.css'.	CSS stylesheet for Opera lower than version 7

All code contained here in css.js should be copied to the top of your lib.js file!
It will then automatically be executed through including.

*/

// Return user agent values
function cssB(whichValue) {
var isDOM=document.getElementById ? true:false;
var isNN4=document.layers ? true:false;
var isIE4=document.all ? true:false;
var isOpr=false;
var isOpr7up=false;
var isLinux=false;
var isIE55up=false;
var isGecko=false;
if (isDOM&&isIE4) {var isIE5up=true; isIE4=false; isDOM=false;} else {var isIE5up=false;}
if ((isIE5up)&&(navigator.appVersion.indexOf('MSIE 5.0')==-1)) {isIE55up=true;}
if (navigator.userAgent.indexOf('Opera')!=-1) {isOpr=true;isDOM=false;isNN4=false;isIE4=false;isIE5up=false;isIE55up=false;}
if (navigator.userAgent.indexOf('Linux')!=-1) {isLinux=true;}
if (isOpr&&(navigator.userAgent.indexOf('Opera 0')==-1&&navigator.userAgent.indexOf('Opera 1')==-1&&navigator.userAgent.indexOf('Opera 2')==-1&&navigator.userAgent.indexOf('Opera 3')==-1&&navigator.userAgent.indexOf('Opera 4')==-1&&navigator.userAgent.indexOf('Opera 5')==-1&&navigator.userAgent.indexOf('Opera 6')==-1)){isOpr7up=true;}
if (navigator.userAgent.indexOf('Gecko')!=-1){isGecko=true;}
var whichValueValue=eval(whichValue);
return(whichValueValue);
}

// Set the browser flags
var isNN4=cssB('isNN4');var isIE4=cssB('isIE4');var isIE5up=cssB('isIE5up');var isIE55up=cssB('isIE55up');var isOpr=cssB('isOpr');var isOpr7up=cssB('isOpr7up');var isGecko=cssB('isGecko');var isLinux=cssB('isLinux');var isW3c=cssB('isW3c');

function check_login()
{
	if(!(isIE55up) && !(isGecko))
		alert("Achtung!\n\nSie benötigen für diese Applikation entweder Internet Explorer 5.5 oder höher, bzw. Mozilla ab Version 1.3.");
}

// output the inclusion link for the correct css file
var noneOfThem=true;
if (isNN4&&!isLinux){document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"nn.css\">");noneOfThem=false;}
if (isNN4&&isLinux){document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"nn-l.css\">");noneOfThem=false;}
if (isGecko||isW3c||isOpr7up){document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"dm.css\">");noneOfThem=false;}
if (isOpr&&!isOpr7up){document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"op.css\">");noneOfThem=false;}
if ((isIE4||isIE5up||isIE55up)&&(!isW3c)){document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"ie.css\">");noneOfThem=false;}
if(noneOfThem){document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"ie.css\">");}

//active link marked
function linkmarked(newlink,oldlink1,oldlink2,oldlink3){
document.getElementById(newlink).style.textDecoration="underline";
document.getElementById(oldlink1).style.textDecoration="none";
document.getElementById(oldlink2).style.textDecoration="none";
document.getElementById(oldlink3).style.textDecoration="none";
}


// Keep the progress and the message element correctly sized and positioned (commLib private function)
//
// Centers and size-fits the modal disabler element
function keepObjectCoveringFullPage(oldWinWidth,oldWinHeight,oldOffsetWidth,oldOffsetHeight,wasFirstRun){
var id=document.getElementById('hiderobject');
if(id.style.visibility=='visible'||!wasFirstRun||wasFirstRun==undefined)
	{
	var winHeight; var offsetWidth; var winWidth; var offsetHeight; var XnonIECorrector=0; var YnonIECorrector=0;
	// set the references to the window's properties
	if(isGecko||isOpr){winWidth=innerWidth;winHeight=innerHeight;offsetHeight=pageYOffset;offsetWidth=pageXOffset;}
	if(isIE5up){winWidth=document.body.clientWidth;winHeight=document.body.clientHeight;offsetHeight=document.body.scrollTop;offsetWidth=document.body.scrollLeft;}
	// get the window dimensions
	winHeight=Number(winHeight); offsetHeight=Number(offsetHeight);
	winWidth=Number(winWidth); offsetWidth=Number(offsetWidth);
	// set positions and sizes
	if(oldOffsetWidth!=offsetWidth||oldOffsetHeight!=offsetHeight){id.style.position='absolute';}
	if(oldOffsetWidth!=offsetWidth){id.style.left=offsetWidth+'px';}
	if(oldOffsetHeight!=offsetHeight){id.style.top=offsetHeight+'px';}
	if(isGecko){XnonIECorrector=15;YnonIECorrector=1;} // correct the size for Gecko to avoid infinite scrollbars
	if(isOpr){XnonIECorrector=20;YnonIECorrector=8;} // correct the size for Opera to avoid infinite scrollbars
	if(oldWinHeight!=winHeight){id.style.height=winHeight-YnonIECorrector+'px';}
	if(oldWinWidth!=winWidth){id.style.width=winWidth-XnonIECorrector+'px';}
	window.setTimeout("keepObjectCoveringFullPage("+winWidth+","+winHeight+","+offsetWidth+","+offsetHeight+",true);",500);
	} else {
	window.setTimeout("keepObjectCoveringFullPage();",250);
	}
}




function getevent(evt) { 
	if(document.layers||(document.getElementById&&!document.all)) return evt.which;
	else return evt.keyCode;
} 

function popup(theURL,winName,features) {
  window.open(theURL,winName,features)
}

function MM_reloadPage(init) {  
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
   document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
 else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);



var fokus="none";
marked= new Array();
var oldfocus="";


function markatstart(id)
{
	if(document.getElementById('zelle_1_'+id))
	{
		marka(id,'#FFA002');
		fixfocus(id,'#7B828C');
	}
}

/*
function fixfocus(id,color,count)
{
fokus=id;
//top.head.document.headform.customerstorer.value=id;
for (i=0; i < marked.length; ++i)
	{
	if (marked[i]!=id)
		{unmark(marked[i],color,count);}
	}
}

// mark unmark
function mark(id,color,count)
{
marked.length=marked.length+1
marked[marked.length-1]=id;
document.getElementById('zelle_1_'+id).style.borderBottom='1px solid '+color;
document.getElementById('zelle_2_'+id).style.borderBottom='1px solid '+color;
document.getElementById('zelle_3_'+id).style.borderBottom='1px solid '+color;
document.getElementById('zelle_4_'+id).style.borderBottom='1px solid '+color;
document.getElementById('zelle_1_'+id).style.borderTop='1px solid '+color;
document.getElementById('zelle_2_'+id).style.borderTop='1px solid '+color;
document.getElementById('zelle_3_'+id).style.borderTop='1px solid '+color;
document.getElementById('zelle_4_'+id).style.borderTop='1px solid '+color;
document.getElementById('zelle_1_'+id).style.borderLeft='1px solid '+color;
document.getElementById('zelle_2_'+id).style.borderLeft='1px solid '+color;
document.getElementById('zelle_3_'+id).style.borderLeft='1px solid '+color;
document.getElementById('zelle_4_'+id).style.borderLeft='1px solid '+color;
document.getElementById('zelle_1_'+id).style.borderRight='1px solid '+color;
document.getElementById('zelle_2_'+id).style.borderRight='1px solid '+color;
document.getElementById('zelle_3_'+id).style.borderRight='1px solid '+color;
document.getElementById('zelle_4_'+id).style.borderRight='1px solid '+color;
	if (count=="5")
	{document.getElementById('zelle_5_'+id).style.borderBottom='1px solid '+color;
	document.getElementById('zelle_5_'+id).style.borderTop='1px solid '+color;}
}

function unmark(id,color,count)
{
if((fokus!=id)||(fokus=='none'))
	{
document.getElementById('zelle_1_'+id).style.borderBottom='1px solid '+color;
document.getElementById('zelle_2_'+id).style.borderBottom='1px solid '+color;
document.getElementById('zelle_3_'+id).style.borderBottom='1px solid '+color;
document.getElementById('zelle_4_'+id).style.borderBottom='1px solid '+color;
document.getElementById('zelle_1_'+id).style.borderTop='1px solid '+color;
document.getElementById('zelle_2_'+id).style.borderTop='1px solid '+color;
document.getElementById('zelle_3_'+id).style.borderTop='1px solid '+color;
document.getElementById('zelle_4_'+id).style.borderTop='1px solid '+color;
document.getElementById('zelle_1_'+id).style.borderLeft='1px solid '+color;
document.getElementById('zelle_2_'+id).style.borderLeft='1px solid '+color;
document.getElementById('zelle_3_'+id).style.borderLeft='1px solid '+color;
document.getElementById('zelle_4_'+id).style.borderLeft='1px solid '+color;
document.getElementById('zelle_1_'+id).style.borderRight='1px solid '+color;
document.getElementById('zelle_2_'+id).style.borderRight='1px solid '+color;
document.getElementById('zelle_3_'+id).style.borderRight='1px solid '+color;
document.getElementById('zelle_4_'+id).style.borderRight='1px solid '+color;
	if (count=="5")
	{document.getElementById('zelle_5_'+id).style.borderBottom='1px solid '+color;
	document.getElementById('zelle_5_'+id).style.borderTop='1px solid '+color;}
	}
}
*/
//mark unmark alex 4 felder
var currentcolor;
function marka(id,color,count)
{
currentcolor=document.getElementById('zelle_1_'+id).style.backgroundColor;

	for(i = 1; i <= count; i++)
	{
		document.getElementById("zelle_"+i+"_"+id).style.backgroundColor=color;
	}
}

function markselected(id,color,count)
{
unmarka(oldfocus,color,count);
currentcolor=document.getElementById('zelle_1_'+id).style.backgroundColor;

	for(i = 1; i <= count; i++)
	{
		document.getElementById("zelle_"+i+"_"+id).style.backgroundColor=color;
	}
fixfocus(id,color,count);
}

function unmarka(id,color,count)
{
	if(id != fokus)
	{
		for(j = 1; j <= count; j++)
		{
			document.getElementById("zelle_"+j+"_"+id).style.backgroundColor=currentcolor;
		}
	}
}
// marked 4 felder
function fixfocus(id,color,count)
{
fokus=id;

	if (oldfocus == "")
	{
		oldfocus = id;
	
	}
	else
	{	

		if (oldfocus != id)
			unmarka(oldfocus,color,count);
		oldfocus = id;
	}
}

function calcPos() {
document.all.suchfeatures.style.left=document.body.clientWidth+10;
//  if (ie4 || ns4) {
//    windowWidth  = (ie4)?document.body.clientWidth:window.innerWidth;
//    windowHeight = (ie4)?document.body.clientHeight:window.innerHeight;
//    logoLeft = windowWidth - 100;
//    logoTop = 45;
//    posObj('suchfeatures',logoLeft,logoTop);
//  }
}

function posObj(objName,objLeft,objTop) {
  if (ie4) { objMove = document.all[objName].style;}
  else if (ns4) { objMove = document.layers[objName]; }
  objMove.left = objLeft; objMove.top = objTop;
}

function searchani()
{
if (out==0)
	{
	MM_showHideLayers('suchfeatures','','show');
	//links=document.body.clientWidth-405;
	//AW_SlideLayer('suchfeatures',links,'40','50','','document.layers[\'suchfeatures\']','document.all[\'suchfeatures\']');
	out=1;
	}

}


function radioon(what,referrer)
{
for (i=1; i < anzahl+1; ++i)
	{
	document.all["radio"+i].src="bin/radio_button_0.gif";}		
document.all[what].src="bin/radio_button_1.gif";
document.formular.referrer.value=referrer;
}

//Add for person_create_edit
//Florian
function check()
{
	if(document.form.Firma.value.length == 2) { cp = eval(document.getElementById('search')); cp.style.visibility = 'visible'; }
}

//---==============================================================================================================
// begin functions for the html editor
// ---

var mode="text";

if (navigator.product == 'Gecko')
{
    gecko = true;
}
else gecko = false;

function getDocument(name) 
{
	try
	{
    		if (gecko)
    		{
    			gEditDocument = document.getElementById(name).contentDocument;
    		}
		else
		{
    			gEditDocument = frames.eval(name).document;
    		}
  
 	 	return gEditDocument;
 	 }
 	 catch(exception)
 	 {
 	 	//alert("getDocument: "+exception);	
 	 	return false;	
 	 }
}

function focusEditWindow(value)
{
	try
	{
    		gEditWindow = document.getElementById(value).contentWindow;
		gEditWindow.focus();
	
		return gEditWindow;
	}
	catch(exception)
	{
		//alert("focusEditWindow: "+exception);
		return false;
	}	
}

function GetSelectionParentNode(sel, name)
{
	try
	{
		if(gecko)
		{
			var focusEditWin = focusEditWindow(name);
			
			if(focusEditWin != false)
			{
				var csel = focusEditWin.getSelection()
				var cnode = csel.anchorNode;
		
				return cnode;
			}
			else
				throw "focusEditWindowException";
		}
		else
			return sel.parentElement();
	}
	catch(exception)
	{
		//alert("GetSelection ParetnNode: "+exception);
		return false;
	}
}

function GetSelectionHTML(sel,name) 
{
	try
	{
		if (gecko)
		{
			var cnode = GetSelectionParentNode(sel, name);
			
			if(cnode != false)
			{
			
				while(cnode.tagName != "A" && cnode.tagName != "HTML")
				{	
					cnode = cnode.parentNode;
						
				}
				
				if(cnode.tagName == "A")
					return cnode.parentNode.innerHTML;
				else
					return null;
			}
			else
				throw "GetSelectionParentNodeException";
	    	}
	  	else
	    		return sel.htmlText;
	  }
	  catch(exception)
	  {
	  	//alert("GetSelectionHTML: "+exception);	
	  	return false;
	  }
}

function GetSelectionText(sel,name)
{
	try
	{
		if(gecko)
		{
			var focusEditWin = focusEditWindow(name);
			
			if(focusEditWin != false)
			{
				return focusEditWin.getSelection().toString();	
			}
			else
				throw "focusEditWindowException";
		}
		else
			return sel.text;
	}
	catch(exception)
	{
		//alert("GetSelectionText: "+exception);
		return false;
	}
		
}

function CreateSelectionRange(name) 
{
	try
	{
		if (gecko) 
  		{
    			var focusEditWin = focusEditWindow(name);
    			
    			if(focusEditWin != false)
    			{
    				var getDoc = getDocument(name);
    				
    				if(getDoc != false)
    				{
    					return getDoc.createRange();
    				}
    				else
    					throw "getDocumen";
    			}
    			else
    				throw "focusEditWindowException";
  		}
  		else
  		{
  			var getDoc = getDocument(name);
  			
  			if(getDoc != false)
  			{
  				return getDoc.selection.createRange();
  			}
  			else
  				throw "getDocumentException";	
    		}
    	}
    	catch(exception)
    	{
    		//alert("CreateSelectionRange: "+exception);
    		return false;
	}
}

function Start(value)
{	
	try 
	{
		var editContent = 'EditorValue_'+value;
		var iFrameName = 'myEditor_'+value;
		
		var getDoc = getDocument(iFrameName);
		
		if(getDoc != false)
		{
			getDoc.designMode = 'on';
		}
		else
			throw "getDocumentException";	
		
		var focusEditWin = focusEditWindow(iFrameName);
		
		if(focusEditWin == false)
			throw "focusEditWindowException";
			
		getAllValues(iFrameName,editContent);
	}
	catch(exception)
	{
		//alert("Start: "+exception);
		setTimeout("Start("+value+")", 100);
	}
}

function getAllValues(iFrameName,editContent)
{
	try 
	{
		var getDoc = getDocument(iFrameName);
		
		if(getDoc != false)
		{
			getDoc.body.innerHTML = document.getElementById(editContent).value;

			getDoc.body.style.fontFamily = "verdana";
			getDoc.body.style.fontSize = "8pt";
		}
		else
			throw "getDocumentException";
	}
	catch(exception)
	{	
		//alert("getAllValues: "+exception);
		setTimeout ("getAllValues("+iFrameName+",'"+editContent+"')",100);	
	}
}

function ChangeSaveStat(element)
{
	try
	{
		if(document.getElementById("button_save_"+element).src.lastIndexOf("bt_diskette.gif") == -1)
		{
			document.getElementById("button_save_"+element).src = "bin/new/bt_diskette.gif";
			document.getElementById("button_save_"+element).disabled = "";
			document.getElementById("button_save_"+element).style.cursor = "pointer";	
		}
	}
	catch(exception)
	{
		//alert("ChangeSaveStat: "+exception);
		setTimeout("ChangeSaveStat("+element+")", 100);
	}	
}

function CheckSaveStat(elementCount)
{
	try
	{
	
		for(j=0; j<elementCount;j++)
		{
			
			var entCode = 'EntitiesValue_'+j;
			var iFrameName = 'myEditor_'+j;
			
			
			var elementId = 'Link_'+j;
				
			if(!document.getElementById(elementId))
				alert("Element Not Found?");
					
			var currentElementId = document.getElementById(elementId).value;
				
			
			var virtStat = 'virtual'+currentElementId;
			
			var getDoc = getDocument(iFrameName);
			
			if(getDoc != false)
			{
				if(getDoc.body)
				{
					//MODIFIED CONTENT
				
					var CEhtml = getDoc.body.innerHTML;
					var CEenthtml = document.getElementById(entCode).innerHTML;
					
					
					//HAS NEVER BEEN SAVED =/
					
					var CEvirt = document.getElementById(virtStat).value;
					
					var button_src = document.getElementById("button_save_"+j).src.lastIndexOf("bt_diskette.gif");
				
					if((CEhtml != CEenthtml && button_src == -1) || (CEvirt != 0 && button_src == -1))
					{
						/*alert("N HTML:"+CEhtml+":"+"\n-----------------------\n"+"E HTML:"+CEenthtml+":");
						
						if(CEhtml != CEenthtml && button_src == -1)
							alert("Ungleich HTML & Disk grau");
						
						if(CEvirt != 0 && button_src == -1)	
							alert("Virtuell & Button grau");*/
							
						
						document.getElementById("button_save_"+j).src = "bin/new/bt_diskette.gif";
						document.getElementById("button_save_"+j).disabled = "";
						document.getElementById("button_save_"+j).style.cursor = "pointer";		
					}
				}
			}
			else
				throw "getDocumentException";
		}
	}
	catch(exception)
	{
		//alert("CheckSaveStat: "+exception);
		setTimeout("CheckSaveStat("+elementCount+")", 100);	
	}	
}

function SaveStat(elementCount)
{
	CheckSaveStat(elementCount);
	
	setTimeout("SaveStat("+elementCount+")",500);	
}

function setAllValues(elementCount) 
{
	try
	{

		for (var i=0; i<elementCount; i++)
		{
			var iFrameName = 'myEditor_'+i+''; 
			var hiddenFieldName = 'contentBlock_'+i+'';
			
			var getDoc = getDocument(iFrameName);
			
			if(getDoc != false)
			{
				document.getElementById(hiddenFieldName).value = getDoc.body.innerHTML; 
			}
			else
				throw "getDocumentException";
		}
	}
	catch(exception)
	{
		//alert("setAllValues: "+exception);
		setTimeout("setAllValues("+elementCount+")", 100);	
	}
}

function setValues(elementCount,element,extend) 
{
	try
	{
		document.form.element.value = element;
	
		for (var i=0; i<elementCount; i++)
		{
			var iFrameName = 'myEditor_'+i+''; 
			var hiddenFieldName = 'contentBlock_'+i+'';
			
			document.getElementById(hiddenFieldName).value = getDocument(iFrameName).body.innerHTML; 
		}
		
		if(extend == true)
		{
			document.form.submit();
		}
	}
	catch(exception)
	{
		//alert("setValues: "+exception);
		setTimeout("setValues("+elementCount+", "+element+", "+extend+")", 100);
	}
}


function delElement(all,element,extend)
{
	var checkdel = confirm("Wollen Sie dieses Element wirklich löschen?");
	
	if(checkdel == true)
	{
		setValues(all,element,extend);
	} 
	else 
	{ 
		return false; 
	}	
}

function moveElement(all, element, direction, extend)
{	
	document.form.direction.value = direction;
	
	setValues(all, element, direction, extend);
}


function SetPreview(elementCount)
{
	window.open('output_content.php','NWpreview','width=640,height=480,toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=1,resizable=yes');
	
	document.form.action = 'newsletter_preview.php?mode=editor';
	document.form.target = 'NWpreview';
	
	setAllValues(elementCount);
	
	document.form.submit();
	document.form.target = '';
	document.form.action = 'newsletter_content.php';	
}

function swapModes(elementNumber,mode) 
{
	var iFrameName='myEditor_'+elementNumber;
	
	if (mode=="text") 
	{
		getDocument(iFrameName).body.innerText = getDocument(iFrameName).body.innerHTML;
		getDocument(iFrameName).body.style.fontFamily = "monospace";
		getDocument(iFrameName).body.style.fontSize = "12px";
	}
	else 
	{
		getDocument(iFrameName).body.innerHTML = getDocument(iFrameName).body.innerText;
		getDocument(iFrameName).body.style.fontFamily = "verdana";
		getDocument(iFrameName).body.style.fontSize ="8pt";
	}
}

function doFormat(elementNumber,what) 
{
	var iFrameName='myEditor_'+elementNumber;
	var select3Name='select3_'+elementNumber;
	
	focusEditWindow(iFrameName);
	
	getDocument(iFrameName).execCommand(what, false, null);
}

function SetFontSize(elementNumber)
{
	var iFrameName='myEditor_'+elementNumber;
	var cursel = document.getElementById("fontsize_"+elementNumber).selectedIndex;
	var selectedfontsize = document.getElementById("fontsize_"+elementNumber).options[cursel].value;
	
	focusEditWindow(iFrameName);
	
	getDocument(iFrameName).execCommand("fontsize", false, selectedfontsize);
	
	focusEditWindow(iFrameName);
}

function SetStyle(elementNumber)
{
	//IE ONLY =/
	
	var iFrameName='myEditor_'+elementNumber;
	
	var cursel = document.getElementById("style_"+elementNumber).selectedIndex;
	var selectedstyle = document.getElementById("style_"+elementNumber).options[cursel].value;
	
	if(selectedstyle!="")
	{
		var oSel = CreateSelectionRange(iFrameName);
		var content = GetSelectionText(oSel, iFrameName);
		
		if(selectedstyle=="blank")
		{
			var element = oSel.parentElement();
			
			while(element.nodeName!='SPAN' && element.nodeName!='HTML') 
				element = element.parentElement;
			
			if(element.nodeName=='SPAN' && element.className!=null)
				element.removeNode(false);
		}
		else
		{
			oSel.pasteHTML('<SPAN CLASS='+selectedstyle+'>'+oSel.htmlText+'</SPAN>');
		}
	}
}

function GetSelectionHREFId(elementNumber)
{
	
	var iFrameName='myEditor_'+elementNumber;
	var oSel = CreateSelectionRange(iFrameName);
	var innerHTML = GetSelectionHTML(oSel, iFrameName);
	
	if(innerHTML != '' && innerHTML != null)
	{
		
		var all = unescape(innerHTML);
		test = /\[[A-Z_0-9:]+\]/g;
		
		if(test.test(all))
			var found = all.match(test);
		else
			var found = new Array();
		
		if(found.length == 1)
			return found[0].match(/[0-9]+/);
		else
			return 0;
			
	}
	else
		return 0;
}

function CreateLink(elementNumber,url,type)
{
	var iFrameName='myEditor_'+elementNumber;
	var oSel = CreateSelectionRange(iFrameName);
	
	getDocument(iFrameName).execCommand("CreateLink",false,url);
	
	var node = GetSelectionParentNode(oSel,iFrameName);	
	
	if(gecko)
	{
		if(type!="")
 		{
 			var attr1 = document.createAttribute('id');
  			attr1.value = type;
  		}
  		
  		if(node.nodeName=="A")
  		{
  			if(type!="")
  				node.setAttributeNode(attr1);
  				
  			//node.target="_blank";
  		}
		
	}
	else
	{	
		if(type!="")
			node.setAttribute("id",type);
			
		node.target="_blank";
	}
	
}

function imposeMaxLength(Object, MaxLen)
{
  	return (Object.value.length <= MaxLen);
}

function checkMaxLength(Object, MaxLen)
{
	if(Object.value.length > MaxLen)
	{
		alert("Achtung\n\nDas Impressum darf nur "+MaxLen+" Zeichen beinhalten!");
		return false;
	}
	
	return true;
}

// ---
// end functions for the html editor
// ---==============================================================================================================

//---==============================================================================================================
// begin functions for nice window look
// ---


/* ---------------------INITIAL CONFIGURATION------------------------------------- */

var popupWidth	=430; // width for the popup
var popupHeight	=210; // height for the popup
var popupParams	='menubar=no,directories=no,resizable=no,scrollbars=yes,status=no' // further parameters for the popup

/* ----------------------------------------------------------------------- */

// Store the current window's dimensions and replace it by the popup
function formatWindow(){

if(location.search.indexOf('window=formatted')==-1)
	{
	
	var thisUrl='';
	if(location.search==''){thisUrl=location.href+'?window=formatted';}else{thisUrl=location.href+'&window=formatted';} // Add the 'formatted' flag to the window's address while eventually keeping all parameters
	
	var microsite=window.open(thisUrl,'Microsite','height='+popupHeight+',width='+popupWidth+','+popupParams); // Create the replacement window

	var windowWidth;
	var windowHeight;
	if (document.layers){windowWidth=window.innerWidth;windowHeight=window.innerHeight}else{windowWidth=document.body.clientWidth;windowHeight=document.body.clientHeight;} // Determine the browser window's current dimensios to store them in a cookie to restore them later
	setCookie('windowWidth',windowWidth);
	setCookie('windowHeight',windowHeight);

	window.opener=window; // Fake the root window to believe it has an opener...
	window.close(); // ...because if it believes this, it will not ask the user for the permission to close

	}

}

// When the popup is to be closed, reformat it to its old dimensions to avoid having the user wrong formatted browser windows
function reformatWindow(){

var windowWidth=getCookie('windowWidth');
var windowHeight=getCookie('windowHeight');

if(windowWidth>99&&windowHeight>99) // If valid values are stored...
	{
	window.resizeTo(windowWidth,windowHeight); //...reformat the window...
	window.close(); // ...and close it.
	}

}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}


// ---
// end functions for nice window look
// ---==============================================================================================================



