
/* Navigation Search */
var navigationSearch = {
	show : function()
	{
		$('navigation_search').show();	
		Event.observe('navigation_search', 'focus', navigationSearch.init);
	},
	init : function()
	{
		Event.observe('navigation_search', 'blur', navigationSearch.hide)
	},
	
	hide : function()
	{
		$('navigation_search').hide();
	}
};


var navigationLogin = {
	toggle : function()
	{
		if (!$('navigation_login').visible()) {
			Effect.SlideDown('navigation_login', { duration: 0.25 });
		}else{
			Effect.SlideUp('navigation_login', { duration: 0.8 });
		}
		//$('navigation_login').toggle();
	}
}


/* employments add */
function toggle(div)
{	
	$(div).toggle();
	if ($('employments_addbtn')) {
		$('employments_addbtn').toggle();
	}
}

function toggleHelpBox(element,link,close_label, open_label)
{
	if(!$(element).visible())
	{
		Effect.BlindDown(element, { duration: 0.5 });
	/*	$(link).innerHTML= close_label; */
	}
	else
	{
		Effect.BlindUp(element, { duration: 0.5 });
		/*$(link).innerHTML= open_label;*/
	}
	
	
}

function toggleJobofferLocalisation(div)
{
	if(!$(div).visible())
	{
		Effect.BlindDown(div, { duration: 0.3 });
	}
	else
	{
		Effect.BlindUp(div, { duration: 0.3 });
	}

}

/* when an image is already uploaded, you can switch in the input form */
function switchImageInputForm(link)
{
	parentelement = $(link).up('div');
	parentelement.down('input').show();
	parentelement.down('p').show();
	parentelement.down('div.preview_filename').show();
	parentelement.down('img').hide();
	parentelement.down('a.cancel').show();
	parentelement.down('br.cancel').show();
	$(link).hide();
}


function cancelImageInputForm(link)
{
	parentelement = $(link).up('div');
	parentelement.down('input').hide();
	parentelement.down('p').hide();
	parentelement.down('div.preview_filename').hide();
	parentelement.down('img').show();
	parentelement.down('a.switch').show();
	parentelement.down('br.cancel').hide();
	$(link).hide();
}

function showPreviewFile(inputID)
{
	var target = $(inputID).up().down('div.preview_filename');
	
	// dateiname und -pfad trennen:
	var filename = $(inputID).getValue();
	filename = filename.substr(filename.lastIndexOf('\\')+1,filename.length);
	filetype = filename.substr(filename.lastIndexOf('.')+1,filename.length);
	
	if (filename.length > 18) {
		filename = filename.substr(0,14) + '...' + filetype;
	}
	if ($(inputID).getValue() != '') {
		//target.update($(inputID).getValue());
		target.update(filename);
		target.show();
	}
}


function changeMediumInput(param)
{
	if(param.value == 'image')
	{
		$('links_source').hide();
		$('image_upload').show();				
		$('image_upload').up('div.product_new_thumbpreview').setStyle({'background':'url(/images/bkgr_profiles_item.gif) no-repeat 0 0'});
		if ($('use_watermark') != null) {
			$('use_watermark').show();
		}
	}
	else if(param.value == 'video')
	{
		$('links_source').show();
		$('image_upload').hide();
		$('image_upload').up('div.product_new_thumbpreview').setStyle({'background':'none'});
		if ($('medium_link_source') != null) {
			$('medium_link_source').value = "Paste your Video-HTML-Code";
		}
		if ($('use_watermark') != null) {
			$('use_watermark').hide();
		}
	}	
	else if(param.value == 'audio')
	{
		$('links_source').show();
		$('image_upload').hide();
		$('image_upload').up('div.product_new_thumbpreview').setStyle({'background':'none'});
		if ($('medium_link_source') != null) {
			$('medium_link_source').value = "Paste your Sound-HTML-Code";
		}
		if ($('use_watermark') != null) {
			$('use_watermark').hide();
		}
	}
}


/* detailed_index_search filter tabs */
function changeSearchTabs(activeTab, link)
{
	$('filter_box_profiles').hide();
	$('filter_box_products').hide();
	//$('filter_box_joboffer').hide();
	$('filter_box_all').hide();
	$('filter_box_news').hide();
	
	ankers = $('searchbar').childElements('a');
	
	$('searchbar').down('a.active').removeClassName('active');
	
	/*ankers.each(function(element){
		element.className ="pattern";
	});*/
	$(link).addClassName("active");
	
	$(activeTab).show();
	
	if($('search_results'))
	{
		$('search_results').innerHTML = '';
	}
}


/* RollOver Text */
function rollOverText(hoverText,targetID)
{
	if ($(targetID).innerHTML != hoverText) {
		$(targetID).setOpacity(0);
		$(targetID).innerHTML = hoverText;
		Effect.Fade(targetID, { duration: 0.5, from: 0, to: 1 });
	}else{
		Effect.Fade(targetID, { duration: 0.5, from: 1, to: 0 });
	}
}


/* Login */
function login(formID)
{		
	if (formID == 'new_user_session_small') {
		if ($('user_session_email_small').getValue() != '' && $('user_session_password_small').getValue() != '') {
			document.forms['new_user_session_small'].submit();
		}
	}
	
	if (formID == 'new_user_session') {
		if ($('user_session_email').getValue() != '' && $('user_session_password').getValue() != '') {
			document.forms['new_user_session'].submit();
		}
	}
}


/* close open message */
function close_message_box(div_id)
{
	Effect.BlindUp(div_id, {duration: 0.25});
	$(div_id + "_close").hide();
	$(div_id + "_read").show();
}


/* close open messages (private / crew) */
function closeopen_messages(div_id,element)
{
	if (element == '')
	{
		element = div_id + "_opener";
	}
		
	if ($(div_id).visible()) {
		Effect.BlindUp(div_id, {duration: 0.8});
		$(element).setStyle({'background':'url(/images/btn_msgs_openclose.gif) no-repeat 0 0'});
	}else{		
		Effect.BlindDown(div_id, {duration: 0.25});
		$(element).setStyle({'background':'url(/images/btn_msgs_openclose.gif) no-repeat 0 -8px'});
	}
}


//this function determines whether the event is the equivalent of the microsoft // mouseleave or mouseenter events. 
function isMouseLeaveOrEnter(e, handler) { if (e.type != 'mouseout' && e.type != 'mouseover') return false; var reltg = e.relatedTarget ? e.relatedTarget : e.type == 'mouseout' ? e.toElement : e.fromElement; while (reltg && reltg != handler) reltg = reltg.parentNode; return (reltg != handler); }


function showTooltipBox(evt,element) {
	if (isMouseLeaveOrEnter(evt,element) && !$(element).next('div.helpBox').visible())
	{		
	 	position_absolute = $(element).cumulativeOffset();
		$(element).next('div.helpBox').setStyle({'top': position_absolute[1] - 38+'px', 'left': position_absolute[0] + 'px'});		
		Effect.Appear($(element).next('div.helpBox'), {queue: {scope: 'tooltipscope'}, duration: 0.25});		
	}
	else if (isMouseLeaveOrEnter(evt,element) && $(element).next('div.helpBox').visible()) 
	{
		var queue = Effect.Queues.get('tooltipscope');
		queue.each(function(effect) { effect.cancel(); });
		$$('div.helpBox').each(function(elem){
			if ((elem != $(element).next('div.helpBox')) && (elem.getStyle('display') != 'none')) {
				elem.hide();
			}
		});
		Effect.Appear($(element).next('div.helpBox'), {queue: {scope: 'tooltipscope'}, duration: 0.25});		
	}
}


function hideTooltipBox(evt,element) {
	Effect.Fade($(element).next('div.helpBox'), {queue: {scope: 'tooltipscope'}, duration: 0.3});
}


// search results fade in	
function fadeSearchResults(container_id,class_selector)
{ 
  var items = $(container_id).select('.' + class_selector);
  
  rows = Math.ceil(items.length/3);
  
  items.each(function(item, index){
    new Effect.Appear(item, { delay: 0.1 + (index * 0.2), duration: 1 });	
  });
  
}


// the raster view resizes the height, undo this
function resetFlashCloudHeight(container_id)
{
	$(container_id).setStyle({height: 'auto'});
}


function insert_msg_recipient(element_id)
{
	$('message_user_name').clear();
	$('message_user_name').disable();
	$('message_user_name').hide();
	$('msg_recipient').show();
	if ($(element_id).innerHTML.length > 23) {
		$(element_id).innerHTML = $(element_id).innerHTML.substr(0,20) + '...';
	}
	$('msg_recipient').innerHTML = '<span class="msg_inner_recipient">' + $(element_id).innerHTML + '</span> &nbsp;<a href="javascript:enable_msg_auto_complete();"><img src="/images/icon_delete.gif" alt=""/></a>';
}


function enable_msg_auto_complete()
{
	$('msg_recipient').hide();
	$('msg_recipient').innerHTML = '';
	$('message_recipient_hash').value = '';
	$('message_user_name_auto_complete').innerHTML = '';
	$('message_user_name').enable();
	$('message_user_name').show();
}

/* Image Slider for Gallery */
document.observe('dom:loaded', function () {
	$$('div.gallery_slider').each(function (e) {
	    new Slider(e)
	})
});

function closeOverlay() {
	$('gallery_overlay').fade();
}


/* Preloading */
function showPreloader(element)
{
	$(element).innerHTML = '';
	$(element).innerHTML = '<div class="preloader">&nbsp;</div>';
}

function nextPanelSearchHistory(element)
{	
	//new Effect.Fade($(element), { duration: 0.25, afterFinish: function(){showPreloader(element);$(element).show();} });
	showPreloader(element);
}

function highlightInput(element)
{
	$(element).setStyle({'border':'1px solid #000000'});
	$(element).setStyle({'color':'#000000'});
}

function removeHighlightInput(element)
{
	$(element).setStyle({'border':'1px solid #a5acb2'});
	$(element).setStyle({'color':'#7d7d7d'});
}


var timer_overlay;

/* profiles item overlay */
function showProfileOverlay(event, element, ajax_function)
{	
	
	if (isMouseLeaveOrEnter(event,element))
	{				
		timer_overlay = setTimeout(function(){blendProfileOverlay(element,ajax_function);}, 400);
	}
}


function blendProfileOverlay(element, ajax_function)
{
	position_absolute = $(element).cumulativeOffset();
	elements = $(element).getElementsBySelector( 'div');
	
	el = elements[0];
	el.setStyle({'top': position_absolute[1] - 41 + 'px', 'left': position_absolute[0] - 36 + 'px'});	
		
	//$(el).show();
	new Effect.Appear(el, { duration: 0.25 });
	setTimeout(ajax_function, 100);
}



function hideProfileOverlay(event, element)
{
	if (isMouseLeaveOrEnter(event,element))
	{	
		clearTimeout(timer_overlay);
		elements = $(element).getElementsBySelector( 'div');	
		//elements[0].hide();
		new Effect.Fade(elements[0], { duration: 0.15 });
	}
}


function validateNewShopProduct(locale)
{	
	var targetForm = document.forms['new_shop_product'];
	var error = '';	
	
	if (error == '' && !($('shop_product_title').value.length > 3)) {
		error = error_msgs['title'];
		$('shop_product_title').focus();
		$('shop_product_title').setStyle({'border':'1px solid #ff0000'});
	}
	
	if (error == '' && !($('shop_product_description').value.length > 10)) {
		error = error_msgs['description'];
		$('shop_product_description').focus();
		$('shop_product_description').setStyle({'border':'1px solid #ff0000'});
	}
	
	if (error == '' && $('shop_product_cancelation_right') != null) {
		if (!($('shop_product_cancelation_right').value.length > 10)) {
			error = error_msgs['cancelation_right'];
			$('shop_product_cancelation_right').focus();
			$('shop_product_cancelation_right').setStyle({'border':'1px solid #ff0000'});
		}
	}
	
	if (error == '' && $('shop_product_income_revenue') != null) {
		var revenue = parseFloat($('shop_product_income_revenue').value.replace(',00', ''));
		if (!(revenue > 0) || (revenue > 50000)) {
			error = error_msgs['revenue'];
			$('shop_product_income_revenue').focus();
			$('shop_product_income_revenue').setStyle({'border':'1px solid #ff0000'});
		}
	}
	
	if (error == '' && $('shop_product_image') != null) {
		if ($('shop_product_image').value.length == 0) {
			error = error_msgs['product_image'];
			$('shop_product_image').focus();
		}
	}
	
	if ($('shop_product_shop_category') != null) {
		if ($('shop_product_shop_category').value == 'false') {
			error = error_msgs['category'];
			$('shop_product_shop_category').focus();
		}
	}
	
	// Check & test the different combinations:
	if (error == '' && $('shop_product_selling_type') != null) {
		var selection = $('shop_product_selling_type').value;
		switch (selection) {
			// Eigenherstellung:
			case 'self':
				var shipping_type = '';
				if ($('shop_product_self_shipping') != null) {
					shipping_type = $('shop_product_self_shipping'); // normal mode 
				}else{
					shipping_type = $('shop_product_shipping_self_shipping'); // edit mode
				}
				if (shipping_type.value == 'false') {
					error = error_msgs['shipping'];
					shipping_type.focus();
				}else if (shipping_type.value != 'selbstabholer') {
					var countries = $('shipping_countries').getElementsBySelector('select');
					var prices = $('shipping_countries').getElementsBySelector('input');
					if (countries.length > 0 && prices.length > 0) {						
						for (var j = prices.length-1; j >= 0; j--) {
							
							if (prices[j].value == '' || !(prices[j].value.replace(/,/,'.') >= 0)) {
								error = error_msgs['shipping_price'];
								prices[j].focus();
								prices[j].setStyle({'border':'1px solid #ff0000'});
							}
						}
						for (var i = countries.length-1; i >= 0; i--) {
							if (countries[i].value == 'false') {
								error = error_msgs['shipping_country'];
								countries[i].focus();
							}
						}
						// Check for duplicate entries:
						if (error == '' && countries.length > 1 && prices.length > 1) {
							error = checkShippingOptions(countries, prices);
						}
					}else{									
						error = error_msgs['shipping_option'];
					}
				}			
				break;
			
			// My Art Print:
			case '1':
				
			if (error == '' && $('shop_product_upload_image') != null) {
				if ($('shop_product_upload_image').value.length == 0) {
					error = error_msgs['high_quality_image'];
					$('shop_product_image').focus();
				}
			}
				var product_selection = $('shop_product_product').value;
				switch (product_selection) {
					// Leinwand:
					case '1':
						if ($('shop_product_format').value == 'false') {
						
							error = error_msgs['format'];
							$('shop_product_format').focus();
						}else if ($('shop_product_option').value == 'false') {
							error = error_msgs['option'];
							$('shop_product_option').focus();
						}
						break;
					
					// Sonderformat:
					case '2':
						if ($('special_format_reference_nr').value == '') {
							error = error_msgs["format_reference_nr"];
							$('special_format_reference_nr').focus();
							$('special_format_reference_nr').setStyle({'border':'1px solid #ff0000'});
							
						}else if ($('special_format_height').value == '' || !(parseFloat($('special_format_height').value) > 0) || parseFloat($('special_format_height').value) > 500) {
							error = error_msgs["format_height"];
							$('special_format_height').focus();
							$('special_format_height').setStyle({'border':'1px solid #ff0000'});
							
						}else if ($('special_format_width').value == '' || !(parseFloat($('special_format_width').value) > 0) || parseFloat($('special_format_width').value) > 500) {							
							error = error_msgs["format_width"];
							$('special_format_width').focus();
							$('special_format_width').setStyle({'border':'1px solid #ff0000'});
							
						}else if ($('special_format_depth').value == '' || !(parseFloat($('special_format_depth').value) >= 0) || parseFloat($('special_format_depth').value) > 500) {
							error = error_msgs["format_depth"];
							$('special_format_depth').focus();
							$('special_format_depth').setStyle({'border':'1px solid #ff0000'});
							
						}else if ($('special_format_weight').value == '' || !(parseFloat($('special_format_weight').value) > 0) || parseFloat($('special_format_weight').value) > 30) {
							error = error_msgs["format_weight"];
							$('special_format_weight').focus();
							$('special_format_weight').setStyle({'border':'1px solid #ff0000'});
							
						}else if ($('special_format_price').value == '' || !($('special_format_price').value.replace(/,/,'.') >= 0) || ($('special_format_price').value > 50000)) {
							error = error_msgs["format_price"];
							$('special_format_price').focus();
							$('special_format_price').setStyle({'border':'1px solid #ff0000'});
						}					
						break;
					
					default:
						error = error_msgs["product"];
						$('shop_product_product').focus();
				}
				break;
			
			default:
				error = error_msgs["distributor"];
				$('shop_product_selling_type').focus();
		}
	}
	
	if (error == '') {
		targetForm.submit();
	}else{
		alert(error);
	}
}

function checkShippingOptions(countries, prices)
{
	// Check the shipping options for duplicate entries:
	error = '';
	for (var i = 0; i < countries.length; i++) {
		for (var j = 0; j < countries.length; j++) {
			if (i != j && countries[i].value == countries[j].value && countries[i].value != 'false' && countries[j].value != 'false') {
				error = error_msgs["one_shipping_option"];
				break;
			}
		}
		if (error != '') {
			break;
		}
	}
	return error; // Return error or ''
}

// MiniCart Functions:
var minicart_visible = false;
var minicart_animation_active = false;
var closeCart = undefined;
var showButtons = undefined;
function openMinicart()
{
	if (closeCart != undefined) {
		window.clearTimeout(closeCart);
	}
	if (!minicart_visible && !minicart_animation_active) {			
		//$('minicart_buttons').setStyle({'display':'block'});		
		minicart_animation_active = true;
		Effect.SlideDown('minicart_buttons', { queue: { position: 'end', scope: 'minicart', limit: 1 }, duration: 1.0, afterFinish:function(){ minicart_visible = true; minicart_animation_active = false; $('minicart_bottomhr').setStyle({'display':'block'}); showButtons = window.setTimeout('displayMiniCartButtons(true)', 1); } });
	}
}

function closeMinicart()
{
	if (minicart_visible && !minicart_animation_active || (!minicart_visible && minicart_animation_active)) {
		//$('minicart_buttons').setStyle({'display':'none'});
		$('minicart_bottomhr').setStyle({'display':'none'});
		minicart_animation_active = true;
		Effect.SlideUp('minicart_buttons', { queue: { position: 'end', scope: 'minicart', limit: 1 }, duration: 1.0, afterFinish:function(){ minicart_visible = false; minicart_animation_active = false;} });
	}
}

function displayMiniCartButtons(showIt) // this function is needed as IE fix for the sliding of the minicart
{
	if (showButtons != undefined) {
		window.clearTimeout(showButtons);
	}
	if (showIt) {
		$('minicart_buttons').setStyle({'display':'block'});
	}else{
		$('minicart_buttons').setStyle({'display':'none'});
	}
}

function closeMinicartTimed()
{
	closeCart = window.setTimeout('closeMinicart()', 1000);
}

function cancelMinicartClose()
{
	if (closeCart != undefined && !minicart_animation_active) {
		window.clearTimeout(closeCart);
	}
}

// #TODO: USE THIS FUNCTION OR REMOVE IT:
function cancelMinicartAnimation()
{
	var queue = Effect.Queues.get('minicart');
	//queue.each(function(effect) { effect.cancel(); });
	Effect.Queues.get('minicart').invoke('cancel');
}

// Overlay for Shop Products:
function createShopImageOverlay()
{
	if ($('shop_product_show') != null) {
		var overlay = document.createElement('div');		
		overlay.setAttribute('id', 'shop_product_overlay');
		overlay.setAttribute('style', 'display: none;');
		var table = document.createElement('table');
		table.setAttribute('cellpadding', '0');
		table.setAttribute('cellspacing', '0');
		table.setAttribute('border', '0');
		table.setAttribute('id', 'shop_product_overlay_table');
		var tr1 = document.createElement('tr');
		var tr2 = document.createElement('tr');
		var tr3 = document.createElement('tr');
		var td1_1 = document.createElement('td');
		var td1_2 = document.createElement('td');
		var td1_3 = document.createElement('td');
		var td2_1 = document.createElement('td');
		var td2_2 = document.createElement('td');
		var td2_3 = document.createElement('td');
		var td3_1 = document.createElement('td');
		var td3_2 = document.createElement('td');
		var td3_3 = document.createElement('td');
		td1_1.setAttribute('width', '40'); td1_1.setAttribute('height', '40'); td1_1.setAttribute('class', 'ovl_shadow_tl');
		td1_2.setAttribute('class', 'ovl_shadow_top');
		td1_3.setAttribute('width', '40'); td1_3.setAttribute('height', '40'); td1_3.setAttribute('class', 'ovl_shadow_tr');
		td2_1.setAttribute('width', '40'); td2_1.setAttribute('class', 'ovl_shadow_left');
		td2_2.setAttribute('class', 'ovl_content');
		td2_3.setAttribute('width', '40'); td2_3.setAttribute('class', 'ovl_shadow_right');
		td3_1.setAttribute('width', '40'); td3_1.setAttribute('height', '40'); td3_1.setAttribute('class', 'ovl_shadow_bl');
		td3_2.setAttribute('class', 'ovl_shadow_bottom');
		td3_3.setAttribute('width', '40'); td3_3.setAttribute('height', '40'); td3_3.setAttribute('class', 'ovl_shadow_br');
		td1_1.innerHTML = '&nbsp;';
		td1_3.innerHTML = '&nbsp;';
		td2_1.innerHTML = '&nbsp;';
		td2_3.innerHTML = '&nbsp;';
		td3_1.innerHTML = '&nbsp;';
		td3_3.innerHTML = '&nbsp;';				
		var image = document.createElement('img');
		image.setAttribute('id', 'shop_product_overlay_image');
		image.setAttribute('src', '');
		image.setAttribute('border', '0');
		image.setAttribute('alt', '');
		//overlay.appendChild(image);
		td2_2.appendChild(image);
		tr1.appendChild(td1_1);
		tr1.appendChild(td1_2);
		tr1.appendChild(td1_3);
		tr2.appendChild(td2_1);
		tr2.appendChild(td2_2);
		tr2.appendChild(td2_3);
		tr3.appendChild(td3_1);
		tr3.appendChild(td3_2);
		tr3.appendChild(td3_3);		
		table.appendChild(tr1);
		table.appendChild(tr2);
		table.appendChild(tr3);
		overlay.appendChild(table);
		$(overlay).observe('click', function() { hideShopProductImage(); });
		document.body.appendChild(overlay);
	}
}
function showShopProductImage(imgUrl)
{
	if ($('shop_product_overlay') != null && $('shop_product_overlay_image') != null) {
		$('shop_product_overlay_image').setAttribute('src', imgUrl);
		//$('shop_product_overlay').setStyle({'display':'block'});
		Effect.Appear('shop_product_overlay', { queue: { position: 'end', scope: 'shopoverlay', limit: 1 }, duration: 0.5, afterFinish:function(){ } });		
	}
}
function hideShopProductImage() {
	if ($('shop_product_overlay') != null) {
		//$('shop_product_overlay').setStyle({'display':'none'});
		Effect.Fade('shop_product_overlay', { queue: { position: 'end', scope: 'shopoverlay', limit: 1 }, duration: 0.5, afterFinish:function(){ } });
	}
}
document.observe('dom:loaded', function () {
	if ($('shop_product_show') != null) {
		createShopImageOverlay();
	}
});

// Shipping Options Block:
var shipping_all_visible = false;
function showShippingOptions(elem)
{
	var target = $(elem).up('div').down('.shipping_options_block');
	if (target.getStyle('display') == 'none') {
		shipping_all_visible = false;
	}
	if (shipping_all_visible) {
		Effect.BlindUp(target, { queue: { position: 'end', scope: 'shippingoptions', limit: 1 }, duration: 1.0, afterFinish:function(){ shipping_all_visible = false; } });
	}else{
		Effect.BlindDown(target, { queue: { position: 'end', scope: 'shippingoptions', limit: 1 }, duration: 1.0, afterFinish:function(){ shipping_all_visible = true; } });
	}	
}

// CollapseBox functions:
function handleCollapseBox(elem,moretext,lesstext)
{	elem = $(elem);
	var collapsedText = elem.up().down('div[class="collapsebox_text"]');
	if (collapsedText != undefined) {
		if (collapsedText.getStyle('display') == 'block') {
			elem.innerHTML = moretext;
			//elem.removeClassName('floatRight');
			//elem.addClassName('floatLeft');
			Effect.BlindUp(collapsedText, { queue: { position: 'end', scope: 'collapse', limit: 2 }, duration: 0.5, afterFinish:function(){ collapsedText.setStyle({'display':'none'}); } });
		}else{
			elem.innerHTML = lesstext;
			//elem.removeClassName('floatLeft');
			//elem.addClassName('floatRight');
			Effect.BlindDown(collapsedText, { queue: { position: 'end', scope: 'collapse', limit: 2 }, duration: 0.5, afterFinish:function(){ collapsedText.setStyle({'display':'block'}); } });
		}		
	}
	return false;
}

function confirmSubmitPremium(questionText)
{
	var confirmed = confirm(questionText);
	if (confirmed == true) {
		document.forms['new_premiumservice'].submit();
	}
}

function insert_text(text, element)
{
	$(element).value = text;
}


function format_price(element, add_end)
{	
	
	var regEx = /[^\d\.,]/ig; // no chars other than 0-9, comma and dot are allowed
	var price = $(element).value.replace(regEx, '');
	
	
	if(price == '') 
	{ 
		price = "0"; 
	}
	
	
	var lastIndexOfDot = price.lastIndexOf('.');
	var lastIndexOfComma = price.lastIndexOf(',');

	
	// eg. 1.000,05 (comma after dot)
	if ((lastIndexOfComma > lastIndexOfDot) && (lastIndexOfComma > 0)) {
		price = price.replace(/\./g,''); // remove dots
		lastIndexOfComma = price.lastIndexOf(',');
		price = price.substr(0,lastIndexOfComma) + '|' + price.substr(lastIndexOfComma+1, price.length);
		price = price.replace(/,/g,''); // remove commas
		price = price.replace(/\|/g,','); // replace | with comma
	
		
	// eg. 1.000 (no comma)
	}else if ((lastIndexOfDot >= 0) && (lastIndexOfComma == -1)) {
		if (lastIndexOfDot == price.length-3 || lastIndexOfDot == price.length-2) {
			price = price.substr(0,lastIndexOfDot) + '|' + price.substr(lastIndexOfDot+1, price.length);
		}
		price = price.replace(/\./g,''); // remove dots
		price = price.replace(/\|/g,','); // replace | with comma
	
		
	// eg. 1,000.05 (dot after comma)
	}else if ((lastIndexOfDot > lastIndexOfComma) && (lastIndexOfDot > 0)) {
		price = price.replace(/,/g,''); // remove commas
		lastIndexOfDot = price.lastIndexOf('.');
		price = price.substr(0,lastIndexOfDot) + '|' + price.substr(lastIndexOfDot+1, price.length);
		price = price.replace(/\./g,''); // remove dots
		price = price.replace(/\|/g,','); // replace | with comma
	}	
	
	
	// Ceil the value:

	//price = Math.ceil(parseFloat(price.replace(/,/,'.'))).toString().replace().replace(/\./, ',');
	price = parseFloat(price.replace(/,/,'.')).toString().replace().replace(/\./, ',');
	

	if (price == '') { price = "0"; }

	
	if(add_end && price != '')
	{
		// Add zeros:
		if (price.toString().indexOf(',') == -1) {
			price += ',00';
		}else if (price.toString().indexOf(',') == price.length-2) {
			price += '0';
		}else if (price.toString().indexOf(',') == price.length-1) {
			price += '00';
		}
	}
	//alert(price + ' ' + lastIndexOfDot + ' ' + lastIndexOfComma);

	$(element).value = price;
}




function format_shipping_price(element, add_end)
{	
	
	var regEx = /[^\d\.,]/ig; // no chars other than 0-9, comma and dot are allowed
	var price = $(element).value.replace(regEx, '');
	
	
	if(price == '') 
	{ 
		price = "0"; 
	}
	
	
	var lastIndexOfDot = price.lastIndexOf('.');
	var lastIndexOfComma = price.lastIndexOf(',');

	
	// eg. 1.000,05 (comma after dot)
	 if ((lastIndexOfComma > lastIndexOfDot) && (lastIndexOfComma > 0)) {
		price = price.replace(/\./g,''); // remove dots
		lastIndexOfComma = price.lastIndexOf(',');
		price = price.substr(0,lastIndexOfComma) + '|' + price.substr(lastIndexOfComma+1, price.length);
		price = price.replace(/,/g,''); // remove commas
		price = price.replace(/\|/g,','); // replace | with comma
	
	 
	// eg. 1.000 (no comma)
	 }else if ((lastIndexOfDot >= 0) && (lastIndexOfComma == -1)) {
		if (lastIndexOfDot == price.length-3 || lastIndexOfDot == price.length-2) {
			price = price.substr(0,lastIndexOfDot) + '|' + price.substr(lastIndexOfDot+1, price.length);
		}
		price = price.replace(/\./g,''); // remove dots
		price = price.replace(/\|/g,','); // replace | with comma
	
	 
	// eg. 1,000.05 (dot after comma)
	
	}else if ((lastIndexOfDot > lastIndexOfComma) && (lastIndexOfDot > 0)) {
		price = price.replace(/,/g,''); // remove commas
		lastIndexOfDot = price.lastIndexOf('.');
		price = price.substr(0,lastIndexOfDot) + '|' + price.substr(lastIndexOfDot+1, price.length);
		price = price.replace(/\./g,''); // remove dots
		price = price.replace(/\|/g,','); // replace | with comma
	} 	
	
	
	// Ceil the value:

	//price = Math.ceil(parseFloat(price.replace(/,/,'.'))).toString().replace().replace(/\./, ',');
	
	

	if (price == '') { price = "0"; }

	
	if(add_end && price != '')
	{
		price = parseFloat(price.replace(/,/,'.'));
		price = Math.round(price*100)/100;
		
		
		
		price = price.toString().replace().replace(/\./, ',');

		
		// Add zeros:
		if (price.toString().indexOf(',') == -1) {
			price += ',00';
		}else if (price.toString().indexOf(',') == price.length-2) {
			price += '0';
		}else if (price.toString().indexOf(',') == price.length-1) {
			price += '00';
		}
	}
	//alert(price + ' ' + lastIndexOfDot + ' ' + lastIndexOfComma);

	$(element).value = price;
}



















