/*
    Funktionen zum vewalten der Klasse Component

    Autor           : Joachim Ruf
    Erstellungsdatum: 2008.02.28

    Letzte Änderung : 2008.08.23
    Revision        : 1.3
*/





/**
* Zaehlt die Anzahl der Zeichen in einem Textfeld
* @param string secId ID des anzusprechenden Elements
* @param int $maxLength Maximale Anzahl zulaessiger Zeichen
* @return void
*/
function getNbrChar( secId, maxLength )
{
    document.getElementById(secId.name + 'Count').value = maxLength + '/' + secId.value.length;
}




/**
* Checkt eine Checkbox per Klick auf den CheckBox-Text ein
* @param string secId ID des anzusprechenden Elements
* @return void
*/
function setCheckbox( secId )
{
    obj = document.getElementById(secId);
	if(obj.checked == false)
		obj.checked = true;
	else
		obj.checked = false;
}





/**
* Prüft ob es sich beim Upload um eine gültige Grafik handelt
* @param int image Pfad der Grafikdatei
* @return bool
*/
function checkUpload( image )
{
    dotPos = image.lastIndexOf(".");
    fileFormat = image.substr(dotPos, image.length - dotPos);
	fileFormat = fileFormat.toLowerCase();
    
    //alert(fileFormat);
	if( fileFormat == ".jpg" || fileFormat == ".bmp" || fileFormat == ".gif" || fileFormat == ".png")
		return true;
	else
		return  false;
}





/**
* Erstellt eine Vorschau der abzuloadenden Grafik
* @param string uploadFormId ID des Upload-Formulars
* @param string secId ID des anzusprechenden Elements
* @return void
*/
function setUploadImage( uploadFormId, secId, size )
{
 	if( checkUpload(uploadFormId.value) == true ) // Upload-Format gueltig
 	{
 		// Bildbreite ermitteln um Bild der groesse als Vorschau entsprechend anzuzeigen
 		var img = new Image();
 		img.src = uploadFormId.value;

 		var aspectRatio = img.width / img.height;
 		//alert(uploadFormId.value);
    	document.getElementById(secId).src = uploadFormId.value; 	
    	document.getElementById(secId).width = parseInt(size * aspectRatio);
    	document.getElementById(secId).height = parseInt(size);
 	}
	else //Upload-Format ungueltig
	{
		alert("Dateiformat ungültig. Es sind nur folgende Dateiformate zulässig:\n.jpg, .bmp, .gif, .png");	
	}
}





/**
* Erstellt eine Vorschau der abzuloadenden Grafik
* @param string secId ID des anzusprechenden Elements
* @return void
*/
function expandImage( secId )
{
	filePath = secId.src;
	if( filePath.indexOf("component/fileUploadImg.png") == -1 )
	{
		img = new Image();
		img.src = secId.src;

		aspectRatio = img.width / img.height;

		secId.width = parseInt(140 * aspectRatio);
		secId.height = 140;
	}
}





/**
* Erstellt eine Vorschau der abzuloadenden Grafik
* @param string secId ID des anzusprechenden Elements
* @return void
*/
function collapseImage( secId )
{
	filePath = secId.src;
	if( filePath.indexOf("component/fileUploadImg.png") == -1 )
	{
		img = new Image();
		img.src = secId.src;

		aspectRatio = img.width / img.height;

		secId.width = parseInt(70 * aspectRatio);
		secId.height = 70;
	}
}





/**
* Gibt anhand der Farben rot, grün und blau die Mix-Farbe in einem Dialog aus
* @return void
*/
function setColorPicker( secId )
{
	clr = '#' + document.getElementById('clrPickerRed').value + document.getElementById('clrPickerGreen').value + document.getElementById('clrPickerBlue').value;

	document.getElementById('div_' + secId).style.backgroundColor = clr;
	document.getElementById(secId).value = clr;
	
}
