/*
 * JQuery - Anweisungen, die in allen Seiten benötigt werden
 *
 */

$(document).ready(function(){

	$.modal.defaults.closeHTML = "<span></span>";


/*
	$("li[class='nav1level']").prev().css('border-bottom','none');
	$("li[class='nav2level']").prev().css('border-bottom','none');
	$("li[class='activenav1level']").prev().css('border-bottom','none');
	$("li[class='activenav2level']").prev().css('border-bottom','none');

	$("li[class='nav1level last']").prev().css('border-bottom','none');
	$("li[class='activenav1level last']").prev().css('border-bottom','none');
	$("li[class='nav2level last']").prev().css('border-bottom','none');
	$("li[class='activenav2level last']").prev().css('border-bottom','none');



	$("li[class='nav1level']").prev().css('border-bottom','none');
	$("li[class='nav2level']").prev().css('border-bottom','none');
	$("li[class='nav1level.active']").prev().css('border-bottom','none');
	$("li[class='nav2level.active']").prev().css('border-bottom','none');

	$("li[class='nav1level.last']").prev().css('border-bottom','none');
	$("li[class='nav1level.active last']").prev().css('border-bottom','none');
	$("li[class='nav2level.last']").prev().css('border-bottom','none');
	$("li[class='nav2level.active last']").prev().css('border-bottom','none');


	$("li.nav0level.active").find("ul").css("display", "block");

	$("li.nav0level").hover(function() {

		$("li.nav0level").find("ul").hide(300);
		$(this).find("ul").show(300);
	});

	jQuery("#nav_root").accordion({
    active: '.nav0level.active',
    header: 'li a.head',
    navigation: true,
    event: 'click',
    fillSpace: false,
    autoheight: false,
	});
	jQuery("#nav_root a[title='PRODUKTE'] > ul").accordion({
    active: '.activenav1level',
    header: 'li a',
    navigation: true,
    event: 'click',
    fillSpace: false,
    autoheight: false,
	});
	*/

	$("#mainnav li.activenav0level").addClass("current");
	$("#mainnav a:not(ul:only-child)").click(function() {

		element = $(this).next();

		if($(element).is(":hidden")) {
			$(this).parent().parent().find("ul:visible").slideUp();
			$("#mainnav li").removeClass("current");
			$(this).parent().addClass("current");
			$(this).parent().parent().parent().addClass("current");
			$(this).parent().find("> ul").slideDown();
			return false;
		}
		/*else { 
			alert('else');
			return false; 
		}*/



		/*
			$(this).parent().parent().find("ul:visible").slideUp();
			$("#mainnav li").removeClass("current");
			$(this).parent().addClass("current");
			$(this).parent().parent().parent().addClass("current");
			$(this).parent().find("> ul").slideDown();
			return false;*/
	});

});


	/*$("#mainnav li a:not(:only-child)").css("background", "red").click(function() {});*/





/*
 * Funktionen zum Öffnen von Modal Dialogen
 *
 */

function openModalDialogVideo(url, swfWidth, swfHeight, id){
	$('#video'+id).modal({position: ["100px"]});
	$('#videoContent'+id).flash({
    src: url,
    width: swfWidth,
    height: swfHeight
    });
}

function openModalDialogImage(url, imgWidth, imgHeight, id){
	$('#image'+id).modal({position: ["100px"]});
	$('#imageContent'+id).html(
		'<img src="'+url+'" ' + 'height="'+imgHeight+'"' + 'width="'+imgWidth+'">'
    )
}

function openModalDialogColor(){
	$('#colordetail').modal({position: ["100px","340px"]});
	showColor(selectedColorId,selectedColor);
}

function openModalDialogSurface(){
	$('#surfacedetail').modal({position: ["100px","340px"]});
	showSurface(selectedSurfaceId,selectedSurface);
}

function openModalDialogColorSurface(product, selectedColorSurface, color, surface, colorId, surfaceId){
	$('#colorsurfacedetail').modal();
	$('#colorsurfaceselected').attr('src', 'images/content_images/' + selectedColorSurface + '_389x141.jpg');
	if( surface == 'glasiert' ) {
		$('#linkReference a').html(revlinktext2);
	} else {
		$('#linkReference a').html(revlinktext1);
	}
	if ((color.indexOf('sand') != -1) || (color.indexOf('beige') != -1) || (color.indexOf('elfenbein') != -1) || (color.indexOf('safran') != -1) || (color.indexOf('hellgrau') != -1)) {
		if (product == 0){
			$('#labelcolorsurfaceselected').html('<span class="grey">'+ color + ' ' + surface + '</span>');
		} else {
			$('#labelcolorsurfaceselected').html('<span class="grey">'+ color + '</span>');
		}

	} else {
		if (product == 0){
			$('#labelcolorsurfaceselected').html('<span class="white">'+ color + ' ' + surface + '</span>');
		} else {
			$('#labelcolorsurfaceselected').html('<span class="white">'+ color + '</span>');
		}
	}

	ajaxReferences('getLatestReference', product, colorId, surfaceId, 0);

	productColorId = colorId;
	productSurfaceId = surfaceId;
}




/*
 * ajaxGetAllReferences(product, color, surface, direction)
 *
 * Holt Informationen zu allen Referenzen innerhalb des aktuellen Anzeigebereiches (Scrollbereich)
 * Schrittweite für Schrollbereich: 7
 *
 * Paramter:
 * product:	0 (alphaton), 1 (longoton)
 * color: primäre Farbe der Referenz
 * surface: primäre Oberfläche der Referenz
 * direction: Richtung des Scrollen (-1, +1)
 *
 */

function ajaxGetAllReferences(product, color, surface, direction){
	//console.log(arguments);
	if(direction == 1){
		currentScrollRange += 7;
	} else if (direction == -1 && currentScrollRange >= 7){
		currentScrollRange -= 7;
	} else {
		currentScrollRange = 0;
	}
	ajaxReferences('getArticleDownload', product, color, surface, currentScrollRange);
	ajaxReferences('getArticleText', product, color, surface, currentScrollRange);
	ajaxReferences('getThumbnails', product, color, surface, currentScrollRange);
	ajaxReferences('getArticleThumbnails', product, color, surface, currentScrollRange);
	ajaxReferences('getArticleImage', product, color, surface, currentScrollRange);

	teaserReference = '';
	colorId = '';
	surfaceId = '';
}


/*
 * showReference(product)
 *
 * Ruft Referenzen (nach productColorId und productSurfaceId gefiltert) aus einer anderen Seite auf
 *
 * Paramter:
 * product:	0 (alphaton), 1 (longoton)
 *
 */

function showReference(product){
	if(product == 0){
		self.location.href= '/cms/front_content.php?lang=' + lang + '&idcat=21&idcolor=' + productColorId + '&idsurface=' + productSurfaceId;
	} else {
		self.location.href= '/cms/front_content.php?lang=' + lang + '&idcat=22&idcolor=' + productColorId + '&idsurface=' + productSurfaceId;
	}
}


/*
 * changeThumbnail(img, id, counter, product, color, surface, idart)
 *
 * Wechselt die dargestellte Referenz bei Klick auf Thumbnail
 *
 * Paramter:
 * img:	Bild der Referenz
 * id: Id zur Identifizierung der Layer und Images zur jeweiligen Referenz (0 ... x)
 * product:	0 (alphaton), 1 (longoton)
 * color: primäre Farbe der Referenz
 * surface: primäre Oberfläche der Referenz
 * idart: Idart der Referenz
 *
 */

function changeThumbnail(img, id, product, color, surface, idart){
	$('#referenceid').attr('value',idart);
	changeReference(id, product, color, surface);
	$('#thumbs img').removeClass('selected');
	$('#thumbnail'+ id +'image').addClass('selected');
	$('div.thumbnailover').hide();

	if(downloadArray[id] && downloadArray[id] != ''){
		$('#downloadinfo').show();
		$('#downloadinfo > a:first').attr('href',downloadArray[id]);
	} else {
		$('#downloadinfo').hide();
	}

	if (product == 0){
		$('#downloadbrochure > a').attr('href','upload/pdf_referenzen/Alphaton_05-08.pdf');
	} else if (selectedProduct == 1){
		$('#downloadbrochure > a').attr('href','upload/pdf_referenzen/Longoton_05-08.pdf');
	}

	buildSurfaceSelection();
	zoomImage = img;
	currentThumbnail = id;
	currentThumbnailId = idart;
}


/*
 * thumnailOver(type, id)
 *
 * Zeigt vergrössertes Thumbnail bei Mouseover
 * Um Browser-Kompatibilität zu erreichen, muß z-index verändert werden.
 *
 * Paramter:
 * type: 0 (erstes Element), 2 (zweites Element ... Element x-1), 3 (letztes Element)
 * id: Id zur Identifizierung der Images zum jeweiligen Thumbnail (0 ... x)
 *
 */

function thumnailOver(type, id){
	switch (type) {
	  case "1":
	  	next = id+1;
	    if($('#thumbnail'+id+'image').hasClass('selected')==false){
			$('#thumbnail'+id).css('z-index','98');
			$('#thumbnail'+next).css('z-index','97');
			$('#thumb'+id).show();
		}
	    break;
	  case "2":
	    next = id+1;
		previous = id-1;
	   	if($('#thumbnail'+id+'image').hasClass('selected')==false){
			$('#thumbnail'+previous).css('z-index','97');
			$('#thumbnail'+id).css('z-index','98');
			$('#thumbnail'+next).css('z-index','97');
			$('#thumb'+id).show();
		}
	    break;
	  case "3":
	    previous = id-1;
	    if($('#thumbnail'+id+'image').hasClass('selected')==false){
			$('#thumbnail'+previous).css('z-index','97');
			$('#thumbnail'+id).css('z-index','98');
			$('#thumb'+id).show();
		}
	    break;
	}
}


/*
 * changeReference(img, id, counter)
 *
 * Wechselt dargestellte Referenz
 *
 * Paramter:
 * id: Id zur Identifizierung der jeweiligen Referenz (0 ... x)
 * product:	0 (alphaton), 1 (longoton)
 * color: primäre Farbe der Referenz
 * surface: primäre Oberfläche der Referenz
 *
 */

function changeReference(id, product, color, surface){
	$("#contenttext > div").hide();
	$("#medium > div").hide();
	$("#articlethumbs > div").hide();
	$("#articletext"+id).show();
	$("#mediumimage"+id).show();
	$("#articlethumb"+id).show();

	selectedProduct = product;

	setColor(color);
	setSurface(surface);
}


/*
 * changeReferenceThumbnail(img, id, counter)
 *
 * Wechselt dargestelltes Thumbnail der jeweiligen Referenz
 *
 * Paramter:
 * img: Bild der Referenz
 * id: Id zur Identifizierung der jeweiligen Referenz (0 ... x)
 * counter: Id zur Identifizierung des jeweiligen Thumbnails der Referenz (0 ... x)
 *
 */

function changeReferenceThumbnail(img, id, counter){
	$("#mediumimage"+id).html('<img src="'+ img +'" width="399" height="391" alt="" />');
	$('#articlethumbs img').removeClass('selected');
	$('#articlethumbnail'+id+counter+'image').addClass('selected');
	zoomImage = img;
}

function changeRefThumb(img, counter){
	$("#mediumimage img").attr('src', img);
	$('#articlethumbs img').removeClass('selected');
	$('#articlethumbnail'+counter+'image').addClass('selected');
	zoomImage = img;
}


/*
 * showColor(id,color)
 *
 * Zeigt ausgewählte Farbe in der Großansicht
 *
 * Paramter:
 * id: Id zur Identifizierung der jeweiligen Farbe
 * color: Farbe als String, wird benötigt um Grafiken zu identifizieren
 *
 */

function showColor(id,color){
	$('#colorselected').attr('src','images/content_images/'+color+'_standard_389x141.jpg');
	labelColor = $('#color'+id).html();
	$('#labelcolorselected').html(labelColor);
	selectedColor = color;
	selectedColorId = id;
}


/*
 * selectColor()
 *
 * Wechselt Farbauswahl-Icon und Label
 *
 */

function selectColor(){
	if(selectedProduct == 0){
		$("#alphaton").show();
		$("#alphatonColors").show();
		$("#longoton").hide();
		$("#longotonColors").hide();
		$('#alphaton .colorfilter').attr('src','images/content_images/'+selectedColor+'_standard_99x55.jpg');
		$('#alphaton .colorvalue').html(labelColor);

	} else {
		$("#longoton").show();
		$("#longotonColors").show();
		$("#alphaton").hide();
		$("#alphatonColors").hide();
		$('#longoton .colorfilter').attr('src','images/content_images/'+selectedColor+'_standard_199x55.jpg');
		$('#longoton .colorvalue').html(labelColor);
	}
}


/*
 * setColorSelected(status)
 *
 * Setzt Id des Farbfilters
 *
 * Paramter:
 * status: true (Filter wird gesetzt), false (Filter wird zurückgesetzt)
 *
 */

function setColorSelected(status){
	isColorSelected = status;
	if(isColorSelected == true){
		filteredColorId = selectedColorId;
	} else {
		filteredColorId = 0;
	}
}


/*
 * showSurface(id,surface)
 *
 * Zeigt ausgewählte Oberfläche in der Großansicht
 *
 * Paramter:
 * id: Id zur Identifizierung der jeweiligen Oberfläche
 * surface: Oberfläche als String, wird benötigt um Grafiken zu identifizieren
 *
 */

function showSurface(id,surface){
	$('#surfaceselected').attr('src','images/content_images/'+selectedColor+'_'+surface+'_389x141.jpg');
	labelSurface = $('#surface'+id).html();
	$('#labelsurfaceselected').html(labelSurface);
	selectedSurface = surface;
	selectedSurfaceId = id;
}


/*
 * selectSurface()
 *
 * Wechselt Oberflächen-Icon und Label
 *
 */

function selectSurface(){
	if (selectedProduct == 0) {
		$('#alphaton .surfacefilter').attr('src', 'images/content_images/' + selectedColor + '_' + selectedSurface + '_99x55.jpg');
		$('#alphaton .surfacevalue').html(labelSurface);

		if (selectedSurface != 'glasiert') {
			$('#alphaton .colorlink').html('<a onmouseover="showColorSelection();"><img src="images/layout_images/trans.gif" width="99" height="55" alt="" /></a>');
			$('#selectSurfaceLink').show();
			$('#alphaton .colorlabel').addClass('selectionArrow');
			$('#alphaton .surfacelabel').addClass('selectionArrow');
		}
		else {
			setSpecialSurface('#alphaton');
			$('#alphaton .surfacevalue').html($('#surface99').html());
			$('#alphaton .colorlink').html('');
			$('#selectSurfaceLink').hide();
			$('#alphaton .colorlabel').removeClass('selectionArrow');
			$('#alphaton .surfacelabel').addClass('selectionArrow');
		}
	}
	else {
		$('#longoton .surfacevalue').html(labelSurface);

		if (selectedSurface != 'glasiert') {
			$('#longoton .surfacefilter').attr('src', 'images/content_images/' + selectedColor + '_' + selectedSurface + '_199x55.jpg');
			$('#longoton .colorlink').html('<a onmouseover="showColorSelection();"><img src="images/layout_images/trans.gif" width="199" height="55" alt="" /></a>');
			$('#longoton .surfacelink').html('');
			$('#selectSurfaceLink').hide();
			$('#longoton .colorlabel').addClass('selectionArrow');
			$('#longoton .surfacelabel').removeClass('selectionArrow');
		}
		else {
			setSpecialSurface('#longoton');
			$('#longoton .surfacevalue').html($('#surface99').html());
			$('#longoton .colorlink').html('');
			$('#longoton .surfacelink').html('<a onmouseover="showSurfaceSelection();"><img src="images/layout_images/trans.gif" width="199" height="55" alt="" /></a>');
			$('#selectSurfaceLink').hide();
			$('#longoton .colorlabel').removeClass('selectionArrow');
			$('#longoton .surfacelabel').addClass('selectionArrow');
		}
	}
	if ((selectedColor == 'sand') || (selectedColor == 'beige') || (selectedColor == 'elfenbein') || (selectedColor == 'safran') || (selectedColor == 'hellgrau')) {
		changeLabelColor(0, 'white', 'grey');
	} else {
		changeLabelColor(0, 'grey', 'white');
	}
}


/*
 * setSurfaceSelected(status)
 *
 * Setzt Id des Oberflächenfilters
 *
 * Paramter:
 * status: true (Filter wird gesetzt), false (Filter wird zurückgesetzt)
 *
 */

function setSurfaceSelected(status){
	isSurfaceSelected = status;
	if(isSurfaceSelected == true){
		filteredSurfaceId = selectedSurfaceId;
	} else {
		filteredSurfaceId = 0;
	}
}


/*
 * showColorSelection()
 *
 * Zeigt Farbauswahl-Layer
 *
 */

function showColorSelection(){
	$('#surfacedetaillinks').hide();
	$('.surfaceselection').css({opacity: 0.5});
	$('#colordetaillinks').show();
	$('.colorselection').css({opacity: 1});
	if(isColorSelected){
		$('#showAllColorsLink').show();
	} else {
		$('#showAllColorsLink').hide();
	}
}


/*
 * showSurfaceSelection()
 *
 * Zeigt Oberflächenauswahl-Layer
 *
 */

function showSurfaceSelection(){
	$('#colordetaillinks').hide();
	$('.colorselection').css({opacity: 0.5});
	$('#surfacedetaillinks').show();
	$('.surfaceselection').css({opacity: 1});
	if(isSurfaceSelected){
		$('#showAllSurfacesLink').show();
	} else {
		$('#showAllSurfacesLink').hide();
	}
}

/*
 * hideColorAndSurfaceSelection()
 *
 * Versteckt Oberflächen- und Farbenauswahl-Layer
 *
 */

function hideColorAndSurfaceSelection(){
	$('.colorselection').css({opacity: 1});
	$('#colordetaillinks').hide();
	$('.surfaceelection').css({opacity: 1});
	$('#surfacedetaillinks').hide();
}


/*
 * buildSurfaceSelection()
 *
 * Baut die Oberflächenauswahl zusammen, in Abhängigkeit der ausgewählten Farbe
 * Es werden nur Oberflächen der ausgewählten Farbe dargestellt, die als Grafik auf dem Server existieren
 *
 */

function buildSurfaceSelection(){
	var strParams = '';
	for(z=0;z<surfaces.length;z++){
		strParams += '&image'+z+'=images/content_images/'+selectedColor+'_'+surfaces[z]+'_128x45.jpg';
	}
	ajaxImageExist(strParams);
}


/*
 * changeLabelColor(product, oldColor, newColor)
 *
 * Ändert die Farbe der Label für Farb- und Oberflächenauswahl
 *
 * heller Hintergrund: graue Farbe
 * dunkler Hintergrund: weisse Farbe
 *
 */

function changeLabelColor(product, oldColor, newColor){
	if(product == 0){
		$('#alphaton span').removeClass(oldColor);
		$('#alphaton span').addClass(newColor);
		if(newColor == 'white'){
			$('#alphaton .colorlabel').removeClass('selectionArrowGrey');
			$('#alphaton .surfacelabel').removeClass('selectionArrowGrey');
			if (selectedSurface != 'glasiert') {
				$('#alphaton .colorlabel').addClass('selectionArrow');
			}
			$('#alphaton .surfacelabel').addClass('selectionArrow');
		} else {
			$('#alphaton .colorlabel').removeClass('selectionArrow');
			$('#alphaton .surfacelabel').removeClass('selectionArrow');
			if (selectedSurface != 'glasiert') {
				$('#alphaton .colorlabel').addClass('selectionArrowGrey');
			}
			$('#alphaton .surfacelabel').addClass('selectionArrowGrey');
		}
	} else {
		$('#longoton span').removeClass(oldColor);
		$('#longoton span').addClass(newColor);
		if(newColor == 'white'){
			$('#longoton .colorlabel').removeClass('selectionArrowGrey');
			$('#longoton .surfacelabel').removeClass('selectionArrowGrey');
			if (selectedSurface != 'glasiert') {
				$('#longoton .colorlabel').addClass('selectionArrow');
			}
			if (selectedSurface == 'glasiert') {
				$('#longoton .surfacelabel').addClass('selectionArrow');
			}
		} else {
			$('#longoton .colorlabel').removeClass('selectionArrow');
			$('#longoton .surfacelabel').removeClass('selectionArrow');
			if (selectedSurface != 'glasiert') {
				$('#longoton .colorlabel').addClass('selectionArrowGrey');
			}
			if (selectedSurface == 'glasiert') {
				$('#longoton .surfacelabel').addClass('selectionArrowGrey');
			}
		}
	}
}


/*
 * Funktionen für den Pdf- und Zip-Download
 *
 */

function savePdfReference( idRef, title ){
	var cookieText = '';

	if( !idRef ) idRef = currentThumbnailId;
	if( !title ) title = $('#articletext' + currentThumbnail + ' > h1 p').html();
	
	cookietext = document.cookie;
	cookiename = 'reference' + idRef;
	cookiedeleted = 'reference' + idRef + '=deleted';

	if ((cookietext.indexOf(cookiename) == -1) || (cookietext.indexOf(cookiedeleted) != -1)) {
		$('#downloadsDetailList').html( 
			$('#downloadsDetailList').html() + 
			'<div class="checkboxlist"><input type="checkbox" name="refdownload' + idRef + '" id="refdownload' + idRef + '" value="' + title + '" checked="checked" class="checkbox downloads" onclick="checkDownloads();" /><p>' + title + '</p></div>');
		$('#downloadbutton').show();
		$('#downloadsDetailNotice').hide();
		//cookieText = title;
		setCookie('reference', idRef, title);
	} else {
		alert('damn it');
	}
}

function savePdfRepresentation(){
	var cookieText = '';

	cookietext = document.cookie;
	cookiename = 'systemdarstellung' + categoryId;
	cookiedeleted = 'systemdarstellung' + categoryId + '=deleted';

	if ((cookietext.indexOf(cookiename) == -1) || (cookietext.indexOf(cookiedeleted) != -1)) {
		$('#downloadsDetailList').html($('#downloadsDetailList').html() + '<div class="checkboxlist"><input type="checkbox" name="representationdownload' + categoryId + '" id="representationdownload' + categoryId + '" value="' + $('#representationsContent > h1').html() + '" checked="checked" class="checkbox downloads" onclick="checkDownloads();" />' + $('#representationsContent > h1').html() + '</div>');
		$('#downloadbutton').show();
		$('#downloadsDetailNotice').hide();
		cookieText = $('#representationsContent > h1').html();
		setCookie('systemdarstellung', categoryId, cookieText);
	}
}

function downloadPdfReference(){
	submitPage('referenceSearch','front_content.php?idart=40&idcat=3&saveall=1','_self');
	deleteCookies('reference');
	$('#downloadsDetailList').html('');
	$('#downloadbutton').hide();
	$('#downloadsDetailNotice').show();
}

function downloadPdfRepresentation(){
	submitPage('representations','front_content.php?idart=82&idcat=4','_self');
	deleteCookies('systemdarstellung');
	$('#downloadsDetailList').html('');
	$('#downloadbutton').hide();
	$('#downloadsDetailNotice').show();
}

function writeDownloadsReferences(name){
	refArray = getCookies(name);
	if (refArray.length > 0){
		for(i=0;i<refArray.length;i++){
			$('#downloadsDetailList').html($('#downloadsDetailList').html()+'<div class="checkboxlist"><input type="checkbox" name="refdownload'+ refArray[i]["id"] +'" id="refdownload'+ refArray[i]["id"] +'" value="'+ refArray[i]["text"] +'" checked="checked" class="checkbox downloads" onclick="checkDownloads(\'referenceSearch\');" />'+ refArray[i]["text"] +'</div>');
		}
		$('#downloadbutton').show();
		$('#downloadsDetailNotice').hide();
	} else {
		$('#downloadbutton').hide();
		$('#downloadsDetailNotice').show();
	}
}

function writeDownloadsRepresentation(name){
	refArray = getCookies(name);
	if (refArray.length > 0){
		for(i=0;i<refArray.length;i++){
			$('#downloadsDetailList').html($('#downloadsDetailList').html()+'<div class="checkboxlist"><input type="checkbox" name="refdownload'+ refArray[i]["id"] +'" id="refdownload'+ refArray[i]["id"] +'" value="'+ refArray[i]["text"] +'" checked="checked" class="checkbox downloads" onclick="checkDownloads(\'representations\');" />'+ refArray[i]["text"] +'</div>');
		}
		$('#downloadbutton').show();
		$('#downloadsDetailNotice').hide();
	}

}

function checkDownloads(form){
	var check = false;
	for(i=0;i<document.forms[form].length;i++){
		elmName = document.forms[form][i].name;
		if(elmName.indexOf('refdownload') != -1){
			if (document.forms[form][i].checked == true) {
				check = true;
			}
		}
	}
	if(check == false){
		$('#downloadbutton').hide();
	} else {
		$('#downloadbutton').show();
	}
}


/*
 * Funktionen zum Schreiben und Lesen von Cookies
 *
 */

function setCookie(name, refId, refText) {
	var date = new Date();
	date = new Date(date.getTime() +1000*60*60*24*365);
	if (document.cookie) {
		document.cookie = name + refId +'=' + refText + '; expires=' + date.toGMTString() + ';';
	}
}

function getCookies(name){
	a = document.cookie;
	index = 0;
 	res = new Array();

	while(a != ''){
  		while(a.substr(0,1) == ' '){
			a = a.substr(1,a.length);
		}
  		cookiename = a.substring(0,a.indexOf('='));
  		if(a.indexOf(';') != -1){
			cookiewert = a.substring(a.indexOf('=')+1,a.indexOf(';'));
		} else {
			cookiewert = a.substr(a.indexOf('=')+1,a.length);
		}
  		if((cookiename.indexOf(name) != -1) && (cookiewert != 'deleted')){
			res[index] = new Array();
			res[index]['id'] = cookiename.substring(name.length,cookiename.length);
			res[index]['text'] = cookiewert;
			index++;
		}
  		i = a.indexOf(';')+1;
  		if(i == 0){
			i = a.length;
		}
  		a = a.substring(i,a.length);
 	}

	return(res);
}

function deleteCookies(name){
	refArray = getCookies(name);
	if (refArray.length > 0){
		for(i=0;i<refArray.length;i++){
			cookiename = name + refArray[i]['id'];
			document.cookie = cookiename + '=deleted; expires=Thu, 01-Jan-70 00:00:01 GMT;';
		}
 	}
}


/*
 * Sonstige Funktionen
 *
 */

function submitPage(form, url, target, noref ){
	if(noref) $("#referenceid").remove();
	document.forms[form].action = url;
	document.forms[form].target = target;
	document.forms[form].submit();
}

function openSpecialFormImage(idart, img, imgPopup){
	$('#image'+idart).attr('src','upload/bilder_sonderformate/mittel/'+img);
	eval(imgPopup + "= '/cms/upload/bilder_sonderformate/gross/" + img + "'");
}

function popImg(bild,w,h,text) {

	bild = bild.replace(/klein/g, "gross");
	
	/*$.modal('<img src="'+bild+'" style="display: block;"/>', {
		'persist'  : false,
		'position' : ["50%","50%"],
		'escClose' : true,
		'close'	   : true
	})*/
	tb_pathToImage = "/cms/images/loadingAnimation.gif";
	tb_show('', bild);
}

function rightTrim (str) {
    return str.replace(/\s+$/,"");
 }

