function getJQueryId(myid) { 
	return '#'+myid.replace(/:/g,"\\:").replace(/\./g,"\\.");
}

/**
 * Enter key pressed? If so, javascript processing is canceled.
 * 
 * Example:
 * <h:inputText id="aaa" value="#{bean.prop}" onkeyup="if(enterKeyPressed(event)){anyAction();}">
 * 	<a4j:jsFunction name="anyAction" action="#{bean.do}" reRender="xyz" />
 * 	
 * ajaxSingle is not possible - embedd code id a4j:region
 */
function enterKeyPressed(e) {
	 var characterCode
	         if(e && e.which){ 
	             e = e
	             characterCode = e.which 
	         } else {
	             e =  event
	             characterCode = e.keyCode
	         }
	         if(characterCode != 13){ 
	             return false; 
	         }
	         return true;
}

// REMOVE LATER: bugfix for jquery hiding and showing tr's in ie8 --> http://stackoverflow.com/questions/975153/jquery-toggle-not-working-with-trs-in-ie
function toggleJQueryFix(classname) {
	var elem = jQuery(classname)[0];
	if(elem.style.display == 'none')
		jQuery(classname).show();
	else
	{
		jQuery(classname).hide();                       
	}
}

jQuery(document).ready(function(){
	jQuery.preloadCssImages({classes: ['leftControl','rightControl','linktype-B3']});

	jQuery(".clickableRows tr td").live('click', 
			function(){
				var links = jQuery(this).find('a');
				var functional = false;
				
				jQuery.each(links, function(index, item) {
					if(jQuery(item).attr('onclick') != null ||  jQuery(item).attr('href') != '#'){
						functional = true;
					}
				});
				if (!functional){
					window.location.href = jQuery(this).parent().find('a').attr('href');
				}
			}
	);
	
	jQuery(".clickableTd").click(
			function(){
				window.location.href = jQuery(this).find('a').attr('href');
			}
	);
	
	jQuery(".clickableRowsOnclick tr").live('click',
			function(){
				jQuery(this).find('a').click();
			}
	);
	
});




jQuery(".info").ready(function(){
	
	var fixed = false;
	
	if (jQuery(".info").hasClass('info-button')){
		jQuery('.info').live('click', function(e) {
			fixed = !fixed;
			o = jQuery(this);
			if(!fixed){
				o.removeClass("hasFocus");
				jQuery("#info-layer-wrapper").hide();
				jQuery(".info-layer").hide();
				
			} else {
			
				o.addClass("hasFocus");
				var isInfoButton = o.hasClass("info-button");
				setTimeout(function(){
					if (o.hasClass("hasFocus")) {
					
					 var p = isInfoButton ? o : o.find(".icon");
			         var position = p.offset();
			         var width = p.outerWidth();
			         var height = p.outerHeight();
			
			         var infoLayer =  o.attr("id") ? o.attr("id") : 'info-layer-default';
			         var infoLayerObj = jQuery("." + infoLayer);
			         var infoLayerWidth = parseInt(infoLayerObj.css('width')); 
			         var borderWidth = 2;
			         var leftShift = isInfoButton ? -5 : 0;
			         if (isInfoButton){
			        	 jQuery('.marker').addClass('info-button');
			         }
			         var cssObj = {
			             top: position.top + height,
			             left: position.left + width - infoLayerWidth + borderWidth + leftShift,
			             display: "block"
			         };
			         
			         jQuery("#info-layer-wrapper").css(cssObj);
			         jQuery("#info-layer-wrapper").show();
			         jQuery("." + infoLayer).show();
			         
					}
				},300);
			}
		});
	} else {
		jQuery('.info').live('mouseover', function(e) {
			
			o = jQuery(this);
			var isInfoButton = o.hasClass("info-button");
			
			if (isInfoButton){
				fixed = !fixed;
			}
			
			if (isInfoButton && !fixed){
				o.removeClass("hasFocus");
				jQuery("#info-layer-wrapper").hide();
				jQuery(".info-layer").hide();
			} else {
				o.addClass("hasFocus");
				setTimeout(function(){
					if (o.hasClass("hasFocus")) {
					
					 var p = isInfoButton ? o : o.find(".icon");
			         var position = p.offset();
			         var width = p.outerWidth();
			         var height = p.outerHeight();
			
			         var infoLayer =  o.attr("id") ? o.attr("id") : 'info-layer-default';
			         var infoLayerObj = jQuery("." + infoLayer);
			         var infoLayerWidth = parseInt(infoLayerObj.css('width')); 
			         var borderWidth = 2;
			         var leftShift = isInfoButton ? -5 : 0;
			         if (isInfoButton){
			        	 jQuery('.marker').addClass('info-button');
			         }
			         var cssObj = {
			             top: position.top + height,
			             left: position.left + width - infoLayerWidth + borderWidth + leftShift,
			             display: "block"
			         };
			         
			         jQuery("#info-layer-wrapper").css(cssObj);
			         jQuery("#info-layer-wrapper").show();
			         jQuery("." + infoLayer).show();
			         
					}
				},300);
			}
		});
		
		jQuery('.info').live('mouseout', function() {
			if(!fixed){
				jQuery(this).removeClass("hasFocus");
				jQuery("#info-layer-wrapper").hide();
				jQuery(".info-layer").hide();
				
			}
		});
	
		jQuery('.info').live('click', function() {
			fixed = !fixed;
		});
	}
	
});


function preventDoubleClick(element) {
	element.onclick = function() { return false; };
}
