/**
 * Kommentar: commonFunctions
 * 
 * @headurl				$HeadURL: svn://dsrv.eeb.de/IxeaCMS/trunk/app/webroot/js/commonFunctions.js $
 * @author				$Author: mtr $
 * @version				$Revision: 326 $
 * @date				$Date: 2007-10-17 16:34:18 +0200 (Mi, 17 Okt 2007) $
 * @id					$Id: commonFunctions.js 326 2007-10-17 14:34:18Z mtr $
 *
 * @copyright			Copyright (c) 2007, EEB GmbH www.eeb.de
 * 											Gutenbergstra?e 7
 * 											70794 Filderstadt
 */

function showElementById( $id, $idCaption ){
	var elem = document.getElementById( $id );
	var caption = document.getElementById( $idCaption );
	if( elem ){
		elem.style.visibility = "visible";
	}
	if( caption)
		caption.style.visibility = "visible";
}

function getActSelectedImageID(){
	if( document.getElementById('actSelectedImageID') )
		return document.getElementById('actSelectedImageID').value;
}

function setTopArticle( articleID ){
	var actImgID = getActSelectedImageID();
	if( actImgID )
		window.open("/articlesImages/addTopArticle/" + articleID + "/" + getActSelectedImageID(), "EditFenster", "width=450,height=450,scrollbars=yes,resizable=yes");
	else
		alert( 'Artikel besitzt kein Bild! Artikel kann nicht zu den TopArtikeln hinzugef\u00fcgt werden!');
}

function changeArticleText( $text ){
	var articleText = document.getElementById('article_text');
	if( articleText ){
		articleText.innerHTML = $text;
	}
}

function showSelectedEventcategory( categoryId )
{
	window.location.href = '/eventcategories/edit/' + categoryId;
}

function showSelectedMember( businessId, memberId )
{
	window.location.href = '/members/edit/' + businessId + '/' + memberId;
}

function showSelectedLinkcategory( articleId, categoryId )
{
	window.location.href = '/links/edit/' + articleId + '/null/' + categoryId;
}

function writeEmailAdress( localPart, globalPart, count )
{
	var email = document.getElementById('email' + count);
	if( email )
	{
		email.innerHTML = '<a href="mailto:' + localPart + '@' + globalPart + '">' + localPart + '@' + globalPart + '</a>';
	}
}

function hiddenElementById( id ){
	var elem = document.getElementById( id );
	if( elem )
	{
		elem.style.visibility = "hidden";
	}
}

function updateImportElementById( id, text_id, text_value ){
	var elem = document.getElementById( id );
	if( text_value != '' )
		var text = document.getElementById( text_id );
	
	if( elem )
		elem.style.visibility = "hidden";
		
	if( text )
		text.innerHTML = text_value;
}

var zaehler = 1;
var string = '';
var dot = '.';
function load( ziel ) 
{
	if ( zaehler < ziel) 
	{
	 	zaehler = zaehler + 1;
		string = string + dot;
		document.getElementById("dots").innerHTML = string;
	  	window.setTimeout("load('" + ziel + "')", 600);
	 }
	 else 
	 {
		zaehler = 1;
		string = '';
		dot = '.';
		window.setTimeout("load('" + ziel + "')", 600);
	 }
}

function createPasswd() {
	var length = 8;
	var passwd = "";
	var charSet = "23456789qwertzupasdfghkyxcvbnmABCDEFGHKLMNPSTU";
	passwd = passwd + charSet.charAt(Math.floor(Math.random() * charSet.length));
	for (var zaehler = 1; zaehler < length; ++zaehler) {
		passwd = passwd + charSet.charAt(Math.floor(Math.random() * charSet.length));
	}
	document.getElementById('UserPassword').value = passwd;
}

function checkInputEditPw()
{
	if( document.getElementById('UserPassword').value == '' || document.getElementById('UserOldpassword').value == '' )
	{
		errorTxt = "Bitte generieren Sie ein neues Passwort und geben Sie Ihr altes Passwort ein.";
		
		document.getElementById('siteinfoErrorPw').innerHTML = errorTxt;
	}
	else
	{
		document.savePasswordForm.submit();
	}
}

function deleteLinkcategory( linkCategoryId )
{
	if( confirm( unescape('Link-Kategorie wirklich l%F6schen?')) )
	{
		/* 
		document.editLinkCategoryForm.submit();
		window.location.href = '/linkcategories/delete/' + linkCategoryId;
		window.location.reload(true); 
		*/
		
		//Werte und ID zum L?schen setzen
		document.getElementById('LinkcategoryDeletestatus').value = '1';
		document.getElementById('LinkcategoryDeleteid').value = linkCategoryId;
		//Form absenden
		document.editLinkCategoryForm.submit();
	}
}

function deleteLink( articleId, linkId, linkcategoryId )
{
	if( confirm( unescape('Link wirklich l%F6schen?')) )
	{
		//Werte und ID zum L?schen setzen
		document.getElementById('LinkDeletestatus').value = '1';
		document.getElementById('LinkLinkId').value = linkId;
		document.getElementById('LinkArticleId').value = articleId;

		if( linkcategoryId != null )
		{
			document.getElementById('LinkLinkcategoryId').value = linkcategoryId;
		}

		//Form zum speichern absenden
		document.editLinkForm.submit();
	}
}


function deleteDocument( documentId )
{
	if( confirm( unescape('Dokument wirklich l%F6schen?')) )	
	{
		//Werte und Id zum l?schen setzen
		document.getElementById('DocumentDeletestatus').value = '1';
		document.getElementById('DocumentDocumentId').value = documentId;
		
		//Form zum speichern absenden
		document.editDocumentForm.submit();
	}
}

function deleteThumbnail( imageId, articleId )
{
	if( confirm( unescape('Bild wirklich l%F6schen?')) )
	{
		//Werte und Id zum l?schen setzen
		document.getElementById('ImageDeletestatus').value = '1';
		document.getElementById('ImageImageId').value = imageId;
		document.getElementById('ImageArticleId').value = articleId;
		
		//Form zum speichern absenden
		document.editThumbnailsForm.submit();
	}
}

function deleteMenu( menulevel, menuid, parentmenuid )
{
	if( confirm( unescape('Men%FCeintrag wirklich l%F6schen?') ) )
	{
		//Werte und Id zum l?schen setzen
		document.getElementById('MenueDeletestatus').value = '1';
		document.getElementById('MenueMenulevel').value = menulevel;
		document.getElementById('MenueMenuId').value = menuid;
		document.getElementById('MenueParentmenuId').value = parentmenuid;
		
		//Form zum speichern absenden
		document.editMenuForm.submit();
	}
}


function deleteBusinesscategory( businesscategoryid )
{
	if( confirm( unescape('Businesskategorie wirklich l%F6schen?')) )
	{
		//Werte und Id zum l?schen setzen
		document.getElementById('BusinesscategoryDeletestatus').value = '1';
		document.getElementById('BusinesscategoryBusinesscategoryId').value = businesscategoryid;
		
		//Form zum speichern absenden
		document.editBusinesscategoryForm.submit();
	}
}

function deleteTopArticle( articleid, imageid )
{
	if( confirm( unescape('Aus Topartikel entfernen?') ) )
	{
		//Werte und Id zum l?schen setzen
		document.getElementById('ArticlesImageDeletestatus').value = '1';
		document.getElementById('ArticlesImageArticleId').value = articleid;
		document.getElementById('ArticlesImageImageId').value = imageid;
		
		//Form zum speichern absenden
		document.editToparticleForm.submit();
	}
}

function valueChanged()
{
	if( document.getElementById('EditorInputChanged') )
	{
		document.getElementById('EditorInputChanged').value = '1';
	}
}


function closeEditorWindow( formname )
{
	if( document.getElementById('EditorInputChanged') )
	{
		if( document.getElementById('EditorInputChanged').value == '1' )
		{
			if( confirm( unescape("Nicht gespeicherte %C4nderungen im Editor speichern?") ) )
			{
				document.getElementById( formname ).submit();
				opener.location.reload();
				self.close();
			}
			else{
				opener.location.reload();
				self.close();
			}
		}
		else{
			opener.location.reload();
			self.close();
		}
	}
	else{
		opener.location.reload();
		self.close();
	}
}

function editorGoBack( url, formname )
{
	if( document.getElementById('EditorInputChanged') )
	{
		if( document.getElementById('EditorInputChanged').value == '1' )
		{
			if( confirm( unescape("Nicht gespeicherte %C4nderungen im Editor speichern?") ) )
			{
				document.getElementById( formname ).submit();
				self.location.href = url;
			}
			else
			{
				self.location.href = url;
			}
		}
		else
		{
			self.location.href = url;
		}
	
	}
	else
	{
		self.location.href = url;
	}
}


function removeOption()
{
	/*
	index = document.getElementById('selectMenuModul_' + actSelectBoxId).selectedIndex;
	for( i = 0; i<= 100; i++ )
	{
		if( document.getElementById('selectMenuModul_' + i) )
		{
			if( index != 0 )
			{
				document.getElementById('selectMenuModul_' + i).options[ index ].style.display = 'none';
			}
		}
	}
	*/
	
	//Alle markierten Indexe bestimmen
	var selectIndexArr = new Array();
	for( i=0; i<= 100; i++ )
	{
		if( document.getElementById('selectMenuModul_' + i) )
		{
			actIndex = document.getElementById('selectMenuModul_' + i).selectedIndex;
			selectIndexArr.push( actIndex );
		}
	}
	
	//Alle Elemente freischalten
	for( i=0; i<= 100; i++ )
	{
		if( document.getElementById('selectMenuModul_' + i) )
		{		
			for ( s=0; s < document.getElementById('selectMenuModul_' + i).length; s++) 
			{
				document.getElementById('selectMenuModul_' + i).options[ s ].style.display = 'block';
			}
		}
	}
	
	//Die gew?hlten Elemente verstecken
	for( i=0; i<= 100; i++ )
	{
		if( document.getElementById('selectMenuModul_' + i) )
		{		
			for ( a=0; a < selectIndexArr.length; a++) 
			{
				if( selectIndexArr[a] != 0 )
				{
					if( document.getElementById('selectMenuModul_' + i).selectedIndex != selectIndexArr[a] )
					{
						document.getElementById('selectMenuModul_' + i).options[ selectIndexArr[a] ].style.display = 'none';
					}
				}
			}
		}
	}
	
}


function showMenuModulSelectDiv()
{
	document.getElementById('modultypesContainer_id').style.display = 'block';
}