// execute on domready-event
document.observe("dom:loaded", function() {
	stripe('table', 'datatable', 'tr', 'odd', 'even'); // zebra-stripe tables
});


/*  Verlinkung auf Elemente */

function goTo(where) {
	document.location.href = where;
}
/* für ajax requests, wenn onclick gesetzt ist, aber href irgendwas tun soll */
function doNothing() {}

/* LinkElement Position ermitteln: showCart() */
function findPosX(obj) 
{
  var curleft = 0;
  if (obj.offsetParent) 
  {
    while (obj.offsetParent) 
        {
            curleft += obj.offsetLeft;
            obj = obj.offsetParent;
        }
    }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}


function findPosY(obj) 
{
    var curtop = 0;
    if (obj.offsetParent) 
    {
        while (obj.offsetParent) 
        {
            curtop += obj.offsetTop;
            obj = obj.offsetParent;
        }
    }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}


/* Menu Fenster in LinkPosition oeffnen 

TOGGLE: Bei erneutem Aufruf wird das gegenteil ausgeführt.

Universal Anwendbar :

# falls in anderen Elementen (z.B.: Edit Box Toolbar: Fotos Bestellen) implementiert, müssen
die parameter:

elemy
elemx

angepasst werden.

# falls X X als XY Parameter übergeben werden , wird die Position nicht neu ermittelt, ratsam bei
aufrufen der Funktion ausserhalb des realen oeffnenden Divs

# falls LinkElement nicht ausgetauscht werden soll, einfach den selben className
verwenden - e.g.:

if (document.getElementById(windivid).style.display == 'none') {
		linkelem.className = "dropdown";
	} else {
		linkelem.className = "dropdown";
	}


*/
function showFloatingMenu(linkelem, windivid, elemy, elemx){

	var item = $(windivid);
	var modal = $('modalFloatingMenu_' + windivid);
	
	// Bild im LinkElement austauschen
	if (linkelem) {
		if (item.style.display == 'none') {
			linkelem.addClassName('dropdown_sel');
			linkelem.removeClassName('dropdown');
		}
		else {
			linkelem.addClassName("dropdown");
			linkelem.removeClassName('dropdown_sel');
		}
	}
	if (elemy != 'X') {
		// calculate position of popup based on linked element and given parameters
		if ($('menu_main')) {
			// old menu
			item.style.top = (linkelem.cumulativeOffset().top + elemy) + "px";
			item.style.left = (linkelem.cumulativeOffset().left - elemx) + "px";
		} else {
			// new menu
			item.style.top = (linkelem.cumulativeOffset().top - $('main').cumulativeOffset().top + elemy) + "px";
			item.style.left = (linkelem.cumulativeOffset().left - $('main').cumulativeOffset().left - elemx) + "px";
		}
	}
	
	if (modal) {
		item.style.zIndex = parseInt(modal.style.zIndex) + 1;
		var height = document.body.offsetHeight || window.innerHeight || document.documentElement.clientHeight || 0;
		modal.style.height = height + 'px';
		
		// ShoppingCart Anzeigen/Verstecken
		if (item.style.display == 'none' && modal) {
			modal.show();
		}
		else {
			modal.hide();
		}
	}

	new Effect.toggle(item, 'Slide', {duration:0.5});
}

function showModalDialog(linkelem, windivid, elemy, elemx) {

	var item = $(windivid);
	var modal = $('modalDialog_'+windivid);
	// Bild im LinkElement austauschen
	if (item.style.display == 'none') {
		linkelem.addClassName('dropdown_sel');
		linkelem.removeClassName('dropdown');
	} else {
		linkelem.addClassName('dropdown');
		linkelem.removeClassName('dropdown_sel');
	}
	if (elemy != 'X') {
		// calculate position of popup based on linked element and given parameters
		if ($('menu_main')) {
			// old menu
			item.style.top = (linkelem.cumulativeOffset().top + elemy) + "px";
			item.style.left = (linkelem.cumulativeOffset().left - elemx) + "px";
		} else {
			// new menu
			item.style.top = (linkelem.cumulativeOffset().top - $('main').cumulativeOffset().top + elemy) + "px";
			item.style.left = (linkelem.cumulativeOffset().left - $('main').cumulativeOffset().left - elemx) + "px";
		}
	}

	item.style.zIndex = modal.style.zIndex + 1;
	var height = document.body.offsetHeight || window.innerHeight || document.documentElement.clientHeight || 0;
	modal.style.height = height+'px';

	// ShoppingCart Anzeigen/Verstecken
	if(modal.style.display == 'none') {
		var from = 0.0;
		var to = 0.5;
	} else {
		var from = 0.5;
		var to = 0.0;
	}
	new Effect.toggle(modal, 'Appear', {duration:0.5, from:from, to:to});
	new Effect.toggle(item, 'Appear', {duration:0.5});

}

function showModalFloatingDialog(linkelem, windivid) {
	
	var item = $(windivid);
	var modal = $('modalDialog_'+windivid);
	var width = document.body.offsetWidth || window.innerWidth || document.documentElement.clientWidth || 0;
	var height = document.body.offsetHeight || window.innerHeight || document.documentElement.clientHeight || 0;
	var scrollOffset = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;

	modal.style.height = height+'px';
	item.style.left = (width / 2 - item.getWidth() / 2 - $('main').cumulativeOffset().left)+'px';
	item.style.top = (scrollOffset + screen.availHeight / 5 - $('main').cumulativeOffset().top)+'px';
	
	showModalDialog(linkelem, windivid, 'X', 'X');
}

/* Menu SubElement öffnen aber im child-element wird der content per ajax geladen */
function showMenuChildRemote(parentid, childid, url, contentCached) {
	var child = $(childid);
	var linkelem = $(parentid);
	if(linkelem.hasClassName('open') || linkelem.hasClassName('open_link')) {
		showMenuChild(linkelem, childid);
	} else {
		if(child.empty() || !contentCached) {
			// hier ajax request
			new Ajax.Updater(childid, url, {
					asynchronous:true, 
					evalScripts:false, 
					onCreate:function(request, json){ showLoader(childid); showMenuChild(linkelem, childid);},
					onComplete:function(request, json){hideLoader(childid)}} 
			);
		} else {
			showMenuChild(linkelem, childid);
		}		
	}
	
}

/* Menu SubElement oeffnen */
function showMenuChild(linkelem, childid) {
	var openClass = "open";
	if(linkelem.hasClassName('linkto_div')) {
		openClass = "open_link";
	}
	// Bild im LinkElement austauschen
	if ($(childid).style.display == 'none') {
		linkelem.addClassName(openClass);
	} else {
		linkelem.removeClassName(openClass);
	}
	
	// MenuChild Anzeigen/Verstecken
	new Effect.toggle($(childid), 'Blind', {duration: 0.5});
	
}

function showTooltip(linkelem, tooltip){
	var icon = $(linkelem);
	var tip = $(tooltip);
	var offset = icon.positionedOffset();
	var absolute = icon.cumulativeOffset();
	var viewport = document.viewport.getScrollOffsets();
	var bottom = viewport['top']+document.viewport.getHeight();

	var x = offset['left'] +18;
	var y = offset['top'];
	
	if (absolute['top']+tip.getHeight() > bottom - 20) {
		y = offset['top'] - (absolute['top']+tip.getHeight() - bottom) - 20;
	}
    
	tip.style.left = x+"px";
	tip.style.top  = y+"px";
	
	tip.show();
}

function hideTooltip(tooltipp){
	var tip = $(tooltipp);

	tip.hide();
}

function switch_sharing_options(type) {
	if (!$('album_status_0').checked) {
		$('invite_form').show();
	 } else {
	 	$('invite_form').hide();
	 }
	 if ($('album_status_20').checked) {
		$('album_password_row').show();
	 } else {
	 	$('album_password_row').hide();
	 }
	 $('statusmessage_0').hide();
	 $('statusmessage_1').hide();
	 $('statusmessage_20').hide();
	 $('statusmessage_'+type).show();
}

/**
 * Check/Uncheck item_#id div in organize album view
 *
 * @param string id The id of the div (complete i.e. 'item_12')
 * @param int status The status to set for the selection
 * @author abe
 *
 * Set status to -1 to toggle on/off
 */
function checkitem(id,status) {
    var item = $(id);
	var image = item.getElementsByClassName('image')[0];
	var checkbox = item.getElementsByClassName('checkbox')[0];
	
	if (status == -1)
	  if (image.hasClassName('image_active'))
	    status=0;
	  else
	    status=1;
	    
	if (status) {
	  image.addClassName('image_active');
	} else {
	  image.removeClassName('image_active');
	}
	if (checkbox) {
		checkbox.checked = status;
	}
}


function toggle_menu_active(classNameCond, id) {
	var items = $$("."+classNameCond); //document.getElementsByClassName(classNameCond);
	if(items.length > 0) {
		$(id).removeClassName("disabled");
		$(id).readOnly = false;
		if (id == 'into_albums' || id == 'to_cart_albums' || id == 'to_cart_image') {
			$('content_menu').addClassName('active');
		}
	} else {
		$(id).addClassName("disabled");
		$(id).readOnly = true;
		if (id == 'into_albums' || id == 'to_cart_albums' || id == 'to_cart_image') {
			$('content_menu').removeClassName('active');
		}
	}
}

/**
 * Check/Uncheck all item_ divs in organize album view
 * @param int status The status to set for the selection
 * @author abe
 *
 * Set status to -1 to toggle on/off
 */
function checkall(status) {
	var items = $$('.pictures_detail'); //document.getElementsByClassName('pictures_detail');
    for(i=0; i < items.length; i++)
    {
    	checkitem(items[i].id,status);    
    }
}

function checkallParent(status, parentdivclass) {
	var items = $$('.'+parentdivclass); //document.getElementsByClassName(parentdivclass);
    for(i=0; i < items.length; i++)
    {
    	checkitem(items[i].id,status);    
    }
}

function checkallCat(status, parentdivclass, categorydivid) {
	var items = $(categorydivid).childElements();
	//var items = document.getElementsByClassName(parentdivclass);
    for(i=0; i < items.length; i++)
    {
    	checkitem(items[i].id,status);    
    }
}

function serializeItems(name, output_name) {
	var items = document.getElementsByName(name);
	var output = '';
	if (output_name == undefined) output_name = name;

    for(i=0; i < items.length; i++)
    {
    	if (items[i].checked)
    	  output = output+'&'+output_name+'[]='+items[i].value;    
    }
    
    return(output);	
}

function getItems(name) {
	var items = document.getElementsByName(name);
	var output = '';
	var t = 0;
	
    for(i=0; i < items.length; i++)
    {
    	if (items[i].checked)
    	{
    	  if (t==1) output = output+',';
    	  if(t==0) t=1;
    	  output = output+items[i].value;
    	}     
    }
    
    return(output);	
}

function getImageCount() {
	var images = $$('.image'); //document.getElementsByClassName('image');
	var output = '';
	var length = images.length;
	output = "imagecount="+length;
	return(output);
}

function getXactParam(onlyWebUploads) {
	bd = new BrowserDetect();
	xact = bd.detectUpload(onlyWebUploads);
	output = "xact="+xact;
	if ($('upload_sub_' + xact)) {
		$('upload_sub_' + xact).addClassName('active');
	}
	return(output);
}

/* for ajax upload html form */
function myAjaxUploader() {
	$('uploadButton').hide();
	var frame = $('ajaxupload');
	ajaxUploaderQueue = 0;
	if(frame.name == "ajaxUploader") {
		form = frame.contentWindow.document.getElementById("iform");
		form.submit();
	}
}

/*
 * hide/show the loading div positioned at the div represented by parentdivid
 */
function showLoader(parentdivid, positionBefore, loader_div) {
	var loader = $('ajax_load');
	var parent = $(parentdivid);
	if (positionBefore) {
		parent.insert({
			before: loader
		});
	} else {
		parent.insert({
			after: loader
		});
	}
	new Effect.Appear(loader, {duration:0.5});
}

function hideLoader() {
	var loader = $('ajax_load');
	new Effect.Fade(loader, {duration:0.5});
	$('ajax_load_home').insert(loader);
}

/**
 * show a spinner centered in the popupdiv. Must contain a id='inner' container
 */
function showPopupLoader(popupdivid) {
	$(popupdivid).addClassName('loading');
}

/**
 * hide a spinner centered in the popupdiv. Must contain a id='inner' container
 */
function hidePopupLoader(popupdivid) {
	$(popupdivid).removeClassName('loading')	
}

function showBigLoader(popupdivid) {
	$(popupdivid).addClassName('big_loading');
}

function hideBigLoader(popupdivid) {
	$(popupdivid).removeClassName('big_loading')	
}

function open_popup(popupurl, popupwidth, popupheight) {
	window.open(popupurl, 'pixum_popup', 'toolbar=0,width='+popupwidth+',height='+popupheight+',scrollbars=1,status=1,resizable=yes');
}

function imagesPreloader(imagefiles)	{
	var t = 0;
	//showSlideshowLoader('slideshowLoaderDiv');
	while (imagefiles[t]) {
		customerImage[t] = new Image();
		customerImage[t].src = imagefiles[t];
		//setTimeout('checkload('+t+')', 100);
		t += 1;
	} 
}

function checkload(index) {
	(customerImage[index].complete) ? loaded++ : setTimeout('checkload('+index+')', 100);
	//if (loaded >= customerImage.length) hideSlideshowLoader('slideshowLoaderDiv');
}
 
function resizeFitToWindow(element, offset){
	var window_height = getWindowHeight() - offset;
	
	// Try maximizing to width.
	var element_width = getWindowWidth();
	var element_height = element.height / (element.width / getWindowWidth());
	
	// Too big? Maximize to height then.
	if (element_height > window_height) {
		element_height = window_height;
		element_width = element.width / (element.height / window_height);
	}
	
	element.style['width'] = element_width + 'px';
	element.style['height'] = element_height + 'px'; 
}

function getWindowHeight() {
	if (window.innerHeight) {
    	return window.innerHeight;
  	} else if (document.body) {
    	return document.getElementsByTagName('html')[0].offsetHeight;
  	} else {
    	return 0;
  	}
}

function getWindowWidth() {
	if (window.innerWidth) {
    	return window.innerWidth;
  	} else if (document.body) {
    	return document.getElementsByTagName('html')[0].offsetWidth;
  	} else {
    	return 0;
  	}
}


/**
 * Check if more than one item is selected
 */
function checkMultipleSelectedProducts(name) {
	var items = document.getElementsByName(name);
	var count = 0;
	for(i=0; i < items.length; i++) {
    	if (items[i].checked)
    	  count=count +1;    
    }

	if (count > 1) {
		return true;
	} else {
		return false;
	}
}

function countSelectedProducts(name) {
	var items = document.getElementsByName(name);
	var count = 0;
	for(i=0; i < items.length; i++) {
    	if (items[i].checked)
    	  count=count +1;    
    }

	return count;
}

function forceMaxLength (formelement, numberid, maxlength) {
	if (formelement.value.length <= maxlength) {
		$(numberid).innerHTML = formelement.value.length;
		return true;
	} else {
		formelement.value = formelement.value.substring(0,maxlength);
		$(numberid).innerHTML = formelement.value.length;
		return false;
	}
}

function gotoPager(url, checkDisabledDiv, checkSliderDiv) {
	if ($(checkDisabledDiv).hasClassName('disabled')) {
		return false;
	} else {
		if($(checkSliderDiv) && $(checkSliderDiv).visible()) {
			if(url.indexOf('?')!=-1) {
				url = url + "&";
			} else {
				url = url + "?";
			}
			url = url + "slide=1";
		}
		goTo(url);
	}
}

/**
 * show given Text in the message_slot div
 * @param {Object} text
 */
function showMessage(text, element_id, hide_after) {
	if (typeof element_id == "undefined") {
		element_id = 'message_slot';
	}
	$(element_id).update(text); 
	$(element_id).removeClassName('message_warning')
	$(element_id).addClassName('message_ok')
	if (typeof hide_after != "undefined" && hide_after > 0) {
		Effect.BlindDown(element_id, { scaleTo: 70 } );
		window.setTimeout(function() { hideMessage(element_id, 'yes') }, hide_after * 1000);
	}
	else {
		Element.show(element_id);
	}
}

function showWarning(text, element_id) {
	if (typeof element_id == "undefined") {
		element_id = 'message_slot';
	}
	$(element_id).update(text); 
	$(element_id).removeClassName('message_ok')
	$(element_id).addClassName('message_warning')
	Element.show(element_id);
}

/**
 * hide the message slot
 */
function hideMessage(element_id, effect_blind_up) {
	if (typeof element_id == "undefined") {
		element_id = 'message_slot';
	}
	if (effect_blind_up == 'yes') {
		Effect.BlindUp(element_id, { scaleFrom: 70 } );
	}
	else {
		Element.hide(element_id);
	}
}

function changeNaviUpDown(element, checkElement) {
	if($(checkElement).hasClassName('open_link')) {
		$(element).src = '/images/icon_up_white.gif'
	} else {
		$(element).src = '/images/icon_down_white.gif'
	}
}

/**
 * Used e.g. to hide a group of elements when an option element in a 
 * drop down list is clicked. Then one element which is connected
 * to the select option's value attribute is shown.
 * 
 * See shop/combinatedProductSelector component for working sample.
 * 
 * Puts a click observer on elements which fit a css rule. When one of them 
 * is clicked, all elements fitting another css rule get hidden. Then a single
 * element is shown, which is identified by the content of the "value" attribute
 * of the clicked element and an optional prefix.
 * 
 * @param observed_elems css rule for the elements to click-observe
 * @param hide_elems css rule for the elements to hide
 * @param ref_attr the attribute of the observed element which contains the name 
 *		reference by which to identify the element to show
 * @param prefix_show_elems optional prefix for the id of the element to show
 */
function hideAllShowOneObserver(observed_elems, hide_elems, ref_attr, prefix_show_elems) {
	$$(observed_elems).each(function (elem) {
		if (elem.readAttribute('disabled') != 'disables') {
			elem.observe('click', function (event) {
				$$(hide_elems).each(function (elem) {elem.hide()});
				$(prefix_show_elems+event.element().readAttribute(ref_attr)).show();
			});
		}
	})
}

/**
 * Use when having a form with mixed input options of the same name. E.g.
 * 
 * <input type="radio" name="variable" ...>
 * <input type="radio" name="variable" ...>
 * <select name"variable"><option>... <option>... <option></select>
 * 
 * This method helps to deactivate already made selections when the user jumps
 * between the two different types of form elements, e.g. deactivate all radio
 * buttons if a selection is made in the list box.
 * 
 * If the selection to deactivate is in a list box, deact_css should point to
 * an empty or pseudo <option> in that box.
 * 
 * See shop/combinatedProductSelector component for working sample.
 * 
 * @param deact_type 'radio' or 'option', depending on what kind of tags to deactivate
 * @param observed_css css rule to detect the elements to observe
 * @param deact_css css rule to find the elements to deactivate
 */
function deactivateWhenClickedObserver(deact_type, observed_css, deact_css) {
	$$(observed_css).each(function (elem) {
		elem.observe('click', function (event) {
			$$(deact_css).each(function (elem) {
				if (deact_type='radio') elem.checked = false;
				if (deact_type='option') elem.selected = true;
			})
		})
	})
}

/**
 * Toggle multiple slide open as accordion, the sliding elements need to hav the same class
 * @author abe <abe@pixum.com> 
 * @param {string} element Name of clicked element
 * @param {string} elementclass name of class
 */
function toggleAccordion(element, elementclass) {
	var items = $$('.'+elementclass);
	
	for(i=0; i < items.length; i++) {
    	if (items[i].id != element) {
			//new Effect.Fade(items[i], {duration:0.2});
			Effect.BlindUp(items[i].id);
		} else {
			//new Effect.Appear(items[i], {duration:0.2});
			Effect.toggle(items[i].id, 'blind');	
		}    	     
    }
}

/* 
 * central class for browser related issues e.g. name of browser, version of browser, os
 * and checks for plugins (flash, java, activex)
 */
var BrowserDetect = function() {
	this.init();
}
BrowserDetect.prototype.init = function () {
	this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
	this.version = this.searchVersion(navigator.userAgent)
		|| this.searchVersion(navigator.appVersion)
		|| "an unknown version";
	this.OS = this.searchString(this.dataOS) || "an unknown OS";
};
BrowserDetect.prototype.searchString = function (data) {
	for (var i=0;i<data.length;i++)	{
		var dataString = data[i].string;
		var dataProp = data[i].prop;
		this.versionSearchString = data[i].versionSearch || data[i].identity;
		if (dataString) {
			if (dataString.indexOf(data[i].subString) != -1)
				return data[i].identity;
		}
		else if (dataProp)
			return data[i].identity;
	}
};
BrowserDetect.prototype.searchVersion = function (dataString) {
	var index = dataString.indexOf(this.versionSearchString);
	if (index == -1) return;
	return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
};
BrowserDetect.prototype.hasFlash = function () {
	return this.getFlashVersion() != -1;
},
BrowserDetect.prototype.getFlashVersion = function () {
	var flashVer = -1;

	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");			
			var flashVer = tempArrayMajor[0];
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if (this.browser == "Explorer" && this.OS == "Windows") {
		var axo;
		var e;
		try {
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
			flashVer = axo.GetVariable("$version");
			var descArray = flashVer.split(" ");
			var tempArrayMajor = descArray[1].split(",");			
			flashVer = tempArrayMajor[0];
		} catch (e) {}
		if (flashVer == -1) {
			try {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
				axo.AllowScriptAccess = "always";
				flashVer = axo.GetVariable("$version");
				var descArray = flashVer.split(" ");
				var tempArrayMajor = descArray[1].split(",");			
				flashVer = tempArrayMajor[0];
			} catch (e) {}
		}
		if (flashVer == -1) {
			try {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
				flashVer = axo.GetVariable("$version");
				var descArray = flashVer.split(" ");
				var tempArrayMajor = descArray[1].split(",");			
				flashVer = tempArrayMajor[0];
			} catch (e) {}
		}
		if (flashVer == -1) {
			try {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
				flashVer = 3;
			} catch (e) {}
		}
		if (flashVer == -1) {
			try {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
				flashVer = 2;
			} catch (e) {}
		}
	}
	return flashVer;
};
BrowserDetect.prototype.hasJava = function () {
	return navigator.javaEnabled();
};
BrowserDetect.prototype.hasScripting = function() {
	return this.OS == "Windows" && this.browser == "Explorer";
};
BrowserDetect.prototype.detectUpload = function(onlyWebUploads) {
	var xact = 'html';
	flashVer = this.getFlashVersion();
	if(flashVer != -1) {
		flashOK = true;
	} else {
		flashOK = false;
	}
	onlyWebUploads = true;
	if(this.OS == 'Windows') {
		if (flashOK) {
			xact = 'swf';
		} else if (!onlyWebUploads) {
			if (this.hasScripting()) {
				xact = 'ax';
			} else if (this.hasJava()) {
				xact = 'java';
			}
		}
	} else if (this.OS == 'Mac') {
		if(this.Browser != 'Opera' && flashOK) {
			xact = 'swf';
		} 
	} else if (this.OS == 'Linux') {
		if((this.Browser == 'Mozilla' || this.Browser == 'Netscape' || this.browser == 'Firefox') && flashOK) {
			xact = 'swf';
		}
	}
	return xact;
}
BrowserDetect.prototype.dataBrowser = [
	{
		string: navigator.userAgent,
		subString: "Chrome",
		identity: "Chrome"
	},                                   
	{ 	string: navigator.userAgent,
		subString: "OmniWeb",
		versionSearch: "OmniWeb/",
		identity: "OmniWeb"
	},
	{
		string: navigator.vendor,
		subString: "Apple",
		identity: "Safari",
		versionSearch: "Version"
	},
	{
		prop: window.opera,
		identity: "Opera"
	},
	{
		string: navigator.vendor,
		subString: "iCab",
		identity: "iCab"
	},
	{
		string: navigator.vendor,
		subString: "KDE",
		identity: "Konqueror"
	},
	{
		string: navigator.userAgent,
		subString: "Firefox",
		identity: "Firefox"
	},
	{
		string: navigator.vendor,
		subString: "Camino",
		identity: "Camino"
	},
	{		// for newer Netscapes (6+)
		string: navigator.userAgent,
		subString: "Netscape",
		identity: "Netscape"
	},
	{
		string: navigator.userAgent,
		subString: "MSIE",
		identity: "Explorer",
		versionSearch: "MSIE"
	},
	{
		string: navigator.userAgent,
		subString: "Gecko",
		identity: "Mozilla",
		versionSearch: "rv"
	},
	{ 		// for older Netscapes (4-)
		string: navigator.userAgent,
		subString: "Mozilla",
		identity: "Netscape",
		versionSearch: "Mozilla"
	}
];
BrowserDetect.prototype.dataOS = [
	{
		string: navigator.platform,
		subString: "Win",
		identity: "Windows"
	},
	{
		string: navigator.platform,
		subString: "Mac",
		identity: "Mac"
	},
	{
		   string: navigator.userAgent,
		   subString: "iPhone",
		   identity: "iPhone/iPod"
	},
	{
		string: navigator.platform,
		subString: "Linux",
		identity: "Linux"
	}
];

/** new modal popup functions **/

function showModalBox(element_id, attach_to, offset_x, offset_y, is_modal, width) {
	var item = $(element_id);
	var modal = $('modal_box');
	var modal_content = $('modal_content');
	var modal_back = $('modal_back');
	
	modal_content.innerHTML = item.innerHTML;
	displayModalBox(attach_to, offset_x, offset_y, is_modal, width);
}
	
function showModalBoxRemote(remote_url, attach_to, offset_x, offset_y, is_modal, width) {
	var modal = $('modal_box');
	var modal_content = $('modal_content');
	
	modal_content.innerHTML = '';
	displayModalBox(attach_to, offset_x, offset_y, is_modal, width);
	new Ajax.Updater('modal_content', remote_url, {
		asynchronous:true,
		evalScripts:true,
		onLoading:function(){showPopupLoader('modal_box_inner')},
		onComplete:function(){hidePopupLoader('modal_box_inner')}
	});
}

function displayModalBox(attach_to, offset_x, offset_y, is_modal, box_width) {
	var modal = $('modal_box');
	var modal_back = $('modal_back');
	var iframe = $('modal_iframe');

	var width = document.body.offsetWidth || window.innerWidth || document.documentElement.clientWidth || 0;
	var height = document.body.offsetHeight || window.innerHeight || document.documentElement.clientHeight || 0;
	var scrollOffset = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
	
	if (!box_width) {
		box_width = 400;
	}
	
	$('modal_box_inner').setStyle({ width: box_width+'px' });
	
	modal_back.style.height = height+'px';
	if (attach_to != 0) {
		modal.style.left = (findPosX($(attach_to)) + offset_x) + "px";
		modal.style.top = (findPosY($(attach_to)) + offset_y) + "px";
	} else {
		modal.style.left = (width / 2 - modal.getWidth() / 2) + 'px';
		modal.style.top = (scrollOffset + screen.availHeight / 5) + 'px';
	}
	
	iframe.style.display = 'block';
    iframe.style.width = width+'px';
    iframe.style.height = height+'px';
    iframe.style.left = 0;
    iframe.style.top = 0;

	new Effect.Appear(modal, {duration:0.5});

	if (is_modal) {
		new Effect.Appear(modal_back, {duration:0.7, from: 0.0, to: 0.5});
	}	
}

function showModalPopup(element_id, width) {
	if (typeof(width)=="undefined") {
		width = 400;
	}
	showModalBox(element_id,0,0,0,true,width);	
}

function showModalPopupRemote(remote_url, width) {
	showModalBoxRemote(remote_url,0,0,0,true,width);
}

function hideModalPopup() {
	var modal = $('modal_box');
	var modal_back = $('modal_back');

	new Effect.Fade(modal, {duration:0.7});
	new Effect.Fade(modal_back, {duration:0.5, from: 0.5, to: 0.0});
	$('modal_iframe').style.display = 'none';	
}

/**
 * switch innerHTML of two elements
 * @param id1 id of first element
 * @param id2 id of second element
 * @return
 */
function switchInner(id1, id2) {
	var id1inner = $(id1).innerHTML;
	$(id1).update($(id2).innerHTML);
	$(id2).update(id1inner);
}

/**
 * onfocus-function for form elements with input prompt pattern
 * @param id of form element
 * @param label displayed in form element when user input is empty
 * @return
 */
function inputPromptFocus(elem, label) {
	var textfield = Element.extend(elem);
	textfield.addClassName('typing');
	if (!textfield.hasClassName('userinput')) {
		textfield.setValue('');
	}
}

/**
 * onblur-function for form elements with input prompt pattern
 * @param id of form element
 * @param label displayed in form element when user input is empty
 * @return
 */
function inputPromptBlur(elem, label) {
	var textfield = Element.extend(elem);
	textfield.removeClassName('typing');
	if (textfield.value == "") {
		textfield.setValue(label);
		textfield.removeClassName('userinput');
	} else {
		textfield.addClassName('userinput');
	}
}

/**
 * clears value of inputprompt-elements if user didnt enter anything
 * @param f form element
 * @return
 */
function clearInputPromptLabels(f) {
	var form = Element.extend(f);
	form.select('input.inputprompt').each(function(elem) {
		if (!elem.hasClassName('userinput') && !elem.hasClassName('typing')) {
			elem.value = "";
		}
	});
}

/**
 * hides modal upload window on upload error
 * @return
 */
function hideSourceSelectModal() {
	if ($('source_select') && $('modalDialog_source_select')) {
		showModalDialog($('header'), 'source_select', 'X', 'X');
	}
}

/**
 * displays specified shortfaq content and hides all others
 * @param id id of shortfaq-div to be displayed
 * @return
 */
function showShortFaq(id) {
	$$('.shortfaq').each(function(elem) {
		$(elem.id).hide();
		$(elem.id).removeClassName('shortfaq');
	});
	$(id).show();
	$(id).addClassName('shortfaq');
}

/**
 * adds classes for odd and even child-elements 
 * @param parenttype type of parent-element
 * @param parentclass class of parent-element
 * @param childtype type of child-element to which classes are applied
 * @param classodd class given to odd child-elements
 * @param classeven class given to even child-elements
 * @return
 */
function stripe(parenttype, parentclass, childtype, classodd, classeven) {
  $$(parenttype+'.'+parentclass+' '+childtype+':nth-child(odd)').each(function(tr) { tr.addClassName(classodd); });
  $$(parenttype+'.'+parentclass+' '+childtype+':nth-child(even)').each(function(tr) { tr.addClassName(classeven); });
}

function switchContactFormInputs() {
	// voucher code input field
	if ($('subject_cat').value == 'voucher') { 
		$('cf_gutschein').show();
	} else {
		$('cf_gutschein').hide();
	}
	// order number input field
	if ($('subject_cat').value == 'orders' 
		|| $('subject_cat').value == 'easybook'
		|| $('subject_cat').value == 'reclamation' 
		|| $('subject_cat').value == 'voucher') { 
		$('cf_auftragsnummer').show();
	} else { 
		$('cf_auftragsnummer').hide();
	}
	// upload fields
	if ($('subject_cat').value == 'reclamation' 
		|| $('subject_cat').value == 'tech'
		|| $('subject_cat').value == 'misc') { 
		$('cf_uploadfields').show();
	} else { 
		$('cf_uploadfields').hide(); 
	}
}

function highlightRatingStars(score) {
	for (i=1; i<=score; i++) {
		$('star_'+i).src = "/images/service/star_active.gif";
	}
	for (i=score+1; i<=5; i++) {
		$('star_'+i).src = "/images/service/star_not_active.gif";
	}
}

function stopRatingStars(score) {
	for (i=1; i<=score; i++) {
		$('star'+i).innerHTML = '<img src="/images/service/star_active.gif"/>';
	}
	for (i=score+1; i<=5; i++) {
		$('star'+i).innerHTML = '<img src="/images/service/star_not_active.gif"/>';
	}
}

function downloader(url){
	window.focus();
	setTimeout('window.location.href="'+url+'"',1000);
}
