
//14.06.2011
//IMPORTANT !!! not delete !!!
function startSWFAnimation(t, id){

	var swfObj=swfobject.getObjectById(id);
	swfObj.Play();
	
	$(t).hide();
}

function toggleShowHide(id){
	var obj = id;
    if ($(id).style.display == 'none'){
   		$(id).show();
   	}
   	else {
   		$(id).hide();
   	} 

}


function get_url_param( name )
{
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");

	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );

	if ( results == null ){
		return "";
	}else{
		return results[1];
	}
}

function popUpPrintview(pop_width, pop_height){
		if  (get_url_param('n')=='')
			var URL = (document.location + "?print=true");
		else
			var URL = (document.location + "&print=true");

	eval("WIN = window.open(URL, '','toolbar=0,scrollbars=1,locationbar=0,statusbar=0,menubar=0,resizable=1,width="+pop_width+",height="+pop_height+",left=100,top=100');");


}


/**
	* return array with mouse positions relative to id="body"
	* body element need width declaration in css
	*
	* @since 2009-07-08
	* @author effective-world
	* @copyrigth effective GmbH
	*
	*/
	function getRelativeMousePoints(ereignis) {

		var windowWidth = window.innerWidth;
		if(windowWidth == undefined) {
			windowWidth = document.documentElement.clientWidth;
		}

		var body = $('body');
		var bodyWidth = $('body').offsetWidth;
		var bodyHeight = $('body').offsetHeight;
		//var offsetX = (windowWidth - bodyWidth) / 2; //site align center
		var offsetX = 0; //site align left
		var offsetY = window.pageYOffset;

                //ie
		if(offsetY == undefined) {
			offsetY = document.body.scrollTop;
		}


		var relMouseX = ereignis.clientX - offsetX;
		var relMouseY = ereignis.clientY + offsetY;

		var points = new Array;
		points['x'] = relMouseX;
		points['y'] = relMouseY;

		return points;
	}


function reportAjaxError(request){
	alert('AJAX Error!');
}


function getEventList(id,what){
	var placeIn = $(what);

	var placeIn = $(what);
	var url = '/inc/ajax.getEventList.php';
	var myAjax = new Ajax.Updater(
	{success: placeIn},
	url,
	{
		method: 'get',
		parameters: {id:id,what:what},
		onFailure:reportAjaxError,
		evalScripts:true
	}
	);

}


function getSalesPartners(id,what){
var placeIn = $(what);

	var placeIn = $(what);
	var url = '/inc/ajax.getSalesPartner.php';
	var myAjax = new Ajax.Updater(
	{success: placeIn},
	url,
	{
		method: 'get',
		parameters: {id:id,what:what},
		onFailure:reportAjaxError,
		evalScripts:true
	}
	);

}


function getTeamDetails(id,what)	{

	var placeIn = $(what);
	var url = '/inc/ajax.teamDetails.php';
	var myAjax = new Ajax.Updater(
	{success: placeIn},
	url,
	{
		method: 'get',
		parameters: {teamId:id,what:what},
		onFailure:reportAjaxError,
		evalScripts:true
	}
	);

}



function getGlossarDetails(id,what,item)	{

	var placeIn = $(what);

	var a=$$('a.glossarnavi');
	a.each(function(e){

		$(e).removeClassName('glossarnavi_active');

	});

	$(item).addClassName('glossarnavi_active');

	var url = '/inc/ajax.getGlossar.php';
	var myAjax = new Ajax.Updater(
	{success: placeIn},
	url,
	{
		method: 'get',
		parameters: {glossarId:id,what:what},
		onFailure:reportAjaxError,
		evalScripts:true
	}
	);


}


/**
 * This function switch the 
 * visiblity from all variation items  
 *
 * @param null
 * @return null
 **/
function prevItem(t){
//fetch all active
	var active= jQuery('#variationItems .singleItem:visible');
	var all=jQuery('#variationItems div');
	
	var firstActive = jQuery('#variationItems .singleItem:visible:first');
	var lastActive = jQuery('#variationItems .singleItem:visible:last');
	var firstActiveId=firstActive.attr('id');
	var tmp = firstActiveId.split('_');
	var id=parseInt(tmp[1]);
	tmp='#item_'+(id-1);
	
	lastActive.hide();
	jQuery(tmp).show();
	
	var test =jQuery('#item_'+(id-2));
	if(test.length==0){
		jQuery('.button_left').hide();	
	}
	jQuery('.button_right').show();

	/*
	//fetch all
	var last_visible = null;
	var a = $$('#variationItems div');

	a.each(function(e){
		if(e.getStyle('display')!='none' ){
			if(e.id != ''){
				last_visible = e;
			}
		}
	});
	var visible_id = last_visible.id.split('_');
	visible_id =visible_id[1];
	var invis_id = parseInt(visible_id)-3;
	
	
	$('item_'+invis_id).setStyle({display: 'block'});
	
	$(t).up('.bibliothek').down('.button_right').setStyle({display:'block'});
	
	if($('item_'+invis_id) ==null || $('item_'+(invis_id-1)) ==null){
		//hide button
		$(t).setStyle({display: 'none'});
		return 0;
	}
	*/
}


/**
 * 30.03.2011 - David Leschnik
 * ***************************
 * 
 * ***************************
 **/
 
 

function toggleItemDescription(t, str, intern_link, extern_link, title, img_id, manual, datasheet){
	
	
	//hide all arrows
	jQuery('.bibArrow').hide();
	
	//remove all orange borders
	jQuery('.singleItem').css('border','1px solid #FFFFFF');
	
	//fetch needed container
	var a = $(t).up('div.contentInner');
	a = $(a).down('.bibliothekOverlay', 0);
	if(a==undefined){
		/*var z= $$('.bibliothekOverlay');*/
		var z= jQuery('.bibliothekOverlay').get(0);
		a=z;
	}
	
	if(title==''){
	
		var als = $$('div.bibArrow');
		
	als.each(function(e){
		e.setStyle({
			display: 'none'
		});
		//jQuery(a).corner();
		$(a).setStyle({display: 'none'});
		
	});
		
		return null;
	}
	
	

	var s = $(t).up('div.singleItem');
	

	
	var alls = $$('div.singleItem');
	
	alls.each(function(e){
		e.setStyle({
			border: '1px solid #FFFFFF',
			background:'#FFFFFF'
		});
	});
	
	var als = $$('div.bibArrow');
	als.each(function(e){
		e.setStyle({
			display: 'none'
		});
	});

	$(s).setStyle({
		border: '1px solid #d97c15'
	});

		var b = $(a).down('.overlayTitle',0);
		if(b==undefined){
			b=jQuery('.overlayTitle').get(0);;
		}
		$(b).innerHTML = unescape(decodeURI(title));
		var c= $(a).down('.overlayImage', 0);
		if(c==undefined){
			c=jQuery('.overlayImage').get(0);;
		}
		a = $(a).down('.overlayContent', 0);
		if(a==undefined){
			a=jQuery('.overlayContent').get(0);;
		}
		if(img_id != ''){
			c.innerHTML = '<img src="/inc/bild.galerie.php?'+img_id+'" alt="" title="" style="border:none;" />';
		}else{
			/* empty image if img_id has no value */
			c.innerHTML = '<img src="/data/pixel.gif" alt="" title="" style="border:none;" />';
		}
		str = unescape(decodeURI(str))
		if(intern_link != ''){
			str = str + '<br /><a href="./?n='+intern_link+'">-link-</a>';
		}else{
			if(extern_link !=''){
				str = str + '<br /><a href="'+extern_link+'" class="ewtrack_link">-link-</a>';
			}
		}
		
				
			//31.03.2011 - David Leschnik
			//add some brs if datasheet oder manual is aviable
			//to seperate it from the hyperlink or the text
			if(manual!='' || datasheet!=''){
				str =str + '<br /><select class="inp200 ewtrack_file" ONCHANGE="window.open(this.options[this.selectedIndex].value,\'_blank\');"><option disabled selected>Downloads</option>';
			}
			
			
			//30.03.2011 - David Leschnik
			//add datasheet output logic here
			
			
	
			if( datasheet != null && datasheet != undefined && datasheet!='' ){
				for (var i = 0; i < datasheet.length; i++) {
					var datasheetAr = datasheet[i].split(';');
					if (datasheetAr.length > 0 && (datasheetAr[0]!=0 || datasheetAr[0]!= undefined))
						str = str + '<option value="/inc/file.inc.php?id=' + datasheetAr[0] + '" class="ewtrack_file"><a href="/inc/file.inc.php?id=' + datasheetAr[0] + '" class="downloadfile ewtrack_file">'+datasheetAr[1]+'</a></option>';
				}	
			}
			
			 
			//30.03.2011 - David Leschnik
			//add manual output logic  there
	
			if( manual != null && manual != undefined && manual!='' ){
				for (var i = 0; i < manual.length; i++) {
					var manualAr = manual[i].split(';');
					if (manualAr.length > 0 && (manualAr[0]!=0 || manualAr[0]!= undefined))
						str = str + '<option value="/inc/file.inc.php?id=' + manualAr[0] + '" class="ewtrack_file"><a href="/inc/file.inc.php?id=' + manualAr[0] + '" class="downloadfile ewtrack_file">'+manualAr[1]+'</a></option>';
				}
			}
			
			
			
			if(manual!='' || datasheet!=''){
				str =str + '</select><br /><br />';
			}
				
		$(a).innerHTML= str;
		a = $(a).up('.bibliothekOverlay');
		if(a==undefined){
			a=jQuery('.bibliothekOverlay').get(0);;
		}
		if(jQuery("#bib_mailtolink")!='undefined' && jQuery("#bib_mailtolink")!=null)
			jQuery("#bib_mailtolink").attr("href",'mailto:insys@insys-tec.de?body='+title+'&subject=Anfrage%20'+title);
		//jQuery(a).corner();
		$(a).setStyle({display: 'block'});
	
}

function nextItem(t){
	//fetch all active
	var active= jQuery('#variationItems .singleItem:visible');
	var all=jQuery('#variationItems div');
	
	var firstActive = jQuery('#variationItems .singleItem:visible:first');
	var lastActive = jQuery('#variationItems .singleItem:visible:last');
	var lastActiveId=lastActive.attr('id');
	var tmp = lastActiveId.split('_');
	var id=parseInt(tmp[1]);
	tmp='#item_'+(id+1);
	
	firstActive.hide();
	jQuery(tmp).show();
	
	var test =jQuery('#item_'+(id+2));
	if(test.length==0){
		jQuery('.button_right').hide();	
	}
	jQuery('.button_left').show();
	/*
	//fetch all
	var first_visible=null;
	var a = jQuery('#variationItems div').get();
	//
	$(a).each(function(e){
		if(e.getStyle('display')!='none' && first_visible == null){
			if(e.id != ''){
				first_visible = e;
			}
		}
	});
	var visible_id = first_visible.id.split('_');
	visible_id =visible_id[1];
	var invis_id = parseInt(visible_id)+3;

	$(first_visible).setStyle({display: 'none'});
	$('item_'+invis_id).setStyle({display: 'block'});
	$(t).up('.bibliothek').down('.button_left').setStyle({display:'block'});
	
	if($('item_'+invis_id) ==null || $('item_'+(invis_id+1)) ==null){
		//hide button
		$(t).setStyle({display: 'none'});
		return 0;
	}
	
	*/
}

function fetchVariationItems(t, vId, title){

	var a = $(t).up('div.bibliothek');
	a = $(a).down('.variationItems');

	//change request on first hide the overlay if it's visible then go on with the logic
	$(t).up('div.contentInner').down('div.bibliothekOverlay').setStyle({display: 'none'});


	new Ajax.Request('/inc/ajax.getVariationItems.php', {
	  method: 'get',
	  evalJS: true, 
	  parameters: {'vId': vId, lang : 1 ,'title': title},
	  	onSuccess: function(transport) {
	  		if(transport.responseText=='0' || transport.responseText==0){
	  			return 0;
	  		}else{
	  			a.innerHTML = transport.responseText;

	  			//now check the item count, if >3 show buttons else hide it
				var itemCount = a.children.length;
				if(itemCount > 3){
					//display the button container and resize
					
					
					$(a).up('div.bibliothek').down('div.bibliothekButtons').setStyle({display: 'block'});
					/*
					$(a).up('div.contentInner').down('div.bibliothekOverlay').setStyle({height: '185px'});
					$(a).up('div.contentInner').down('div.overlayContent').setStyle({height: '175px'});
					*/
					//reset the buttons to their default state
					$(a).up('div.bibliothek').down('.button_left').setStyle({display: 'none'});
					$(a).up('div.bibliothek').down('.button_right').setStyle({display: 'block'});
				}else{
				
					$(a).up('div.bibliothek').down('div.bibliothekButtons').setStyle({display: 'none'});
					/*
					$(a).up('div.bibliothek').down('div.bibliothekOverlay').setStyle({height: '155px'});
					$(a).up('div.bibliothek').down('div.overlayContent').setStyle({height: '145px'});
					*/
				}
	  		}
	  	}
	});
	$(t).up('div.variationList').down('.variationActive').className= 'variationPassive';
	$(t).up('div').className = 'variationActive';
}


function openHttrackOverlay(t, id){
	
	//hide all arrows
	jQuery('.bibArrow').hide();
	
	//hide all other overlay container to prevent wrong views due to fals z-indexes
	jQuery('.bibliothekOverlay').hide();
	
	//remove all orange borders
	jQuery('.singleItem').css('border','1px solid #FFFFFF');

	jQuery('#overlay'+id).show();
	jQuery('div#bibArrow_'+id).show();
	
	var s = $(t).up('div.singleItem');	

	
	var alls = $$('div.singleItem');
	
	alls.each(function(e){
		e.setStyle({
			border: '1px solid #FFFFFF',
			background:'#FFFFFF'
		});
	});
	

	$(s).setStyle({
		border: '1px solid #d97c15'
	});
}


function hideOverlayContainer(){
	jQuery('.bibliothekOverlay').hide();
	jQuery('.bibArrow').hide();
	//remove all orange borders
	jQuery('.singleItem').css('border','1px solid #FFFFFF');
}

/**
 * 09.03.2011 - David Leschnik
 * ***************************
 * function to emit the current
 * screen position:
 * return[0] == X
 * return[1] == Y
 * ***************************
 **/
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape mode
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM mode
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}


/**
 * 28.02.2011 - David Leschnik
 * ***************************
 * function to set the image
 * content of the clicked item
 * ***************************
 **/
function showZoomOverlay(img_id, str){

	var image = new Image();
	image.src= '/inc/bild.galerie.php?'+img_id;

	var overlay = jQuery('#zoomOverlayContainer');
	var container = jQuery('#container');
	
	
	var left = ((container.width())/2) - (image.width/2);
	/*var top = getScrollXY();
	top=top[1] + 55;
	*/
	
		if(window.innerHeight != 'undefined') {
			var top = getScrollXY();
				top=top[1] + 55;
          } else { 
              var top=  Math.round(document.body.scrollTop +  (($('body').clientHeight - image.heigh))/2) + 55;
             
          }

	if(image.width==0 || image.height==0){
		setTimeout('showZoomOverlay(\''+img_id+'\',\''+str+'\')',100);
		return 0;
	}else{
		jQuery('#zoomOverlayContent')
			.attr('width',image.width)
			.attr('height',image.height)
			.css('top',  top)
			.css('left', left)
			.css('opacity', '1')
			.html('<div id="zoomOverlayClose"><img src="/data/close_button.png" alt="-close_button-" title="-close_button-" onclick="hideZoomOverlay();" /></div>')
			.append(image);

		overlay.fadeIn();
	}
}

function hideZoomOverlay(){
	var overlay = jQuery('#zoomOverlayContainer');
	overlay.hide();

}

function addThumbnailIcon(){
	var thumbnails= $$('.thumbnail_a');
	$(thumbnails).each(function(e){
		var icon = document.createElement('div');
		icon.setAttribute('class', 'zoomIcon');
		e.appendChild(icon);
	});
}


function addEffectiveTrackingClass(class_name)
	{
		var l=document.getElementsByTagName("a").length;

		for(var i=0;i<l;i++){
			var cn=document.getElementsByTagName("a")[i].getAttribute('class');
			if(cn != null && cn != ''){
				document.getElementsByTagName("a")[i].setAttribute('class',cn+" "+class_name);
			}
			else
			{
				document.getElementsByTagName("a")[i].setAttribute('class',class_name);
			}
		}
		for(i=0;i<l;i++){
			//alert(i+" - "+document.getElementsByTagName("a")[i].getAttribute('class'));
		}
	}

	function addTrackingClass2Links(value)
	{
		elements = document.getElementsByTagName("a");
		for (x=0;x<elements.length;x++)
		{
			if (!elements[x].className)
			{
				elements[x].className = value;
			}
			else
			{
				elements[x].className = elements[x].className+" "+value;
			}
		}
	}

	function sh_sub(container){

		//alle bereits göffneten sub Punkte schließen
		var subpoints = document.getElementsByClassName('topNaviSub');
		for(i = 0;i < subpoints.length;i++)
			subpoints[i].style.display = 'none';

		if($('topNaviSub_' + container) == null)
			return 0;

		//Position Links ermitteln und an Ergebniss setzen
		var new_x = $('top_nav' + container).offsetLeft;
		$('topNaviSub_' + container).style.left = new_x + 'px';


		//Display Style ermitteln
		var dis = $('topNaviSub_' + container).style.display;
		if(dis == 'none')
		$('topNaviSub_' + container).style.display = 'inline';
	}

	function Track(site,user,customer)
	{
			var Amp=unescape("%26");
			var Ref="";
			var TrackSrc="http://track.effective-tracking.de/Tracking/tracker.php?";
			var Cur=escape(window.location.href);
			site=escape(site);
			customer=escape(customer);
			user=escape(user);
			var param=escape("Seite="+site+Amp+"Kunde="+customer+Amp+"Benutzer="+user);
			var Img;

			try { Ref = escape(parent.document.referrer); }
			catch(e) {}

			TrackSrc+="pParam="+param;
			TrackSrc+=Amp+"pHome="+Cur;
			TrackSrc+=Amp+"pReferer="+Ref;


			Img = new Image();
			Img.src = TrackSrc;
	}




