var isIE55up=!(navigator.appVersion.indexOf("MSIE 4")>-1||navigator.appVersion.indexOf("MSIE 5.0")>-1);
var isIE=navigator.appName.toLowerCase().indexOf("microsoft")>-1;
var Popped;

function ValidateSearch(){
	var domains=location.href.substr(7);
	domains=domains.substr(0,domains.indexOf('/'))//+'/ES';
	document.getElementById('domains').value=domains;
	document.getElementById('sitesearch').value=domains;
	if(document.getElementById('q').value!=''){
		document.frmSearch.submit();
	}
}

function ReplaceImage(id,findwhat,replacewith){
	if(document.getElementById(id)&&document.getElementById(id).src){
		document.getElementById(id).src=document.getElementById(id).src.replace(findwhat,replacewith);
	}
}

function DisplayBlock(id){
	if(document.getElementById(id)&&document.getElementById(id).style){
		document.getElementById(id).style.display='block';
	}
}

function DisplayNone(id){
	if(document.getElementById(id)&&document.getElementById(id).style){
		document.getElementById(id).style.display='none';
	}
}

var CurrentProfile;
function PickRandomProfile(){
	var num=Math.random()*100;
	var result;
	
	if(num>0&&num<=25){
		result='Chris';
	}else if(num>25&&num<=50){
		result='Oliver';
	}else if(num>50&&num<=75){
		result='Nicolas';
	}else{
		result='Michael';
	}
	
	RollProfile(result);
	ShowProfile(result);
}
function RollProfile(id){
	//checks if the currently viewed profile is not the same then checks to see if must rollover, or rollout
	if(CurrentProfile!=id){
		if(document.getElementById('img'+id).src.indexOf('N.')>-1){
			ReplaceImage('img'+id,'N.','D.')
		}else{
			ReplaceImage('img'+id,'D.','N.')
		}
	}
}

function ShowProfile(id){
	if(CurrentProfile!=id){
		ReplaceImage('img'+CurrentProfile,'D.','N.')
		DisplayNone('Profile'+CurrentProfile);
		DisplayBlock('Profile'+id);
		CurrentProfile=id;
	}
}

var isIE=navigator.appName.indexOf('Microsoft')>-1;

// BEGIN: scrolling
var tScroll, ScrollBy=5, ScrollDirection, OriginalTop=null, ScrollBarScrollHeight, PagePixelsPerPercent,ButtonPixelsPerPerecent,Percentage, ScrollPos=0;

function InitialiseScroll(){
	if(OriginalTop!=null)return;
	ScrollBarScrollHeight=document.getElementById('ScrollBar').offsetHeight - document.getElementById('ScrollButton').offsetHeight;
	OriginalTop=document.getElementById('Scrolling').offsetTop;
	PagePixelsPerPercent=(document.getElementById('Scrolling').offsetHeight - document.getElementById('Scrolling').offsetParent.offsetHeight)/100;
	ButtonPixelsPerPercent=ScrollBarScrollHeight / 100;
	Percentage=ScrollBy / PagePixelsPerPercent;
}

function ToggleScroll(){
	if(ToggleScroll.arguments.length==0){
		clearInterval(tScroll);
		if(ScrollDirection>0){
			document.getElementById('ScrollUp').innerHTML=document.getElementById('ScrollUp').innerHTML.replace('_d.gif','.gif');
		}else{
			document.getElementById('ScrollDown').innerHTML=document.getElementById('ScrollDown').innerHTML.replace('_d.gif','.gif');
		}
		return
	}
	var theTarget;
	
	
	ScrollDirection=ToggleScroll.arguments[1];
	
	if(ScrollDirection>0){
			document.getElementById('ScrollUp').innerHTML=document.getElementById('ScrollUp').innerHTML.replace('.gif','_d.gif');
		}else{
			document.getElementById('ScrollDown').innerHTML=document.getElementById('ScrollDown').innerHTML.replace('.gif','_d.gif');
		}
	
	InitialiseScroll();
	tScroll=setInterval(ScrollObject,50);
}

function ScrollObject(){
	ScrollPos-=ScrollDirection*Percentage;
	if(ScrollPos<0)ScrollPos=0;
	if(ScrollPos>100)ScrollPos=100;
	document.getElementById('Scrolling').style.top=(0-ScrollPos) * PagePixelsPerPercent+OriginalTop+'px';
	
	document.getElementById('ScrollButton').style.top=ScrollPos * ButtonPixelsPerPercent+'px';
}
// END: scrolling

var tPickup,Dropped="";

function Drop(id){
	if(tPickup)clearTimeout(tPickup);
	if(!id)return;
	if(Dropped!=id)Pickup();
	Dropped=id;

	if(document.getElementById(id+'Child')){
		document.getElementById(id+'Child').style.display='block';
		if(document.getElementById(id).className.indexOf('HasChild')==-1)document.getElementById(id).className+='HasChild';
		
	}
}

function ReadyPickup(){
	tPickup=setTimeout(Pickup,500);
}

function Pickup(){
	if(Dropped=="")return;

	if(document.getElementById(Dropped+'Child')){
		document.getElementById(Dropped+'Child').style.display='none';
		document.getElementById(Dropped).className=document.getElementById(Dropped).className.replace('HasChild','');
	}
}

if(isIE&&isIE55up){
		var path,url=unescape(location.href).toLowerCase();
		if(url.indexOf("design")>-1)path="../";
		if(url.indexOf("work examples")>-1||url.indexOf("Fluids")>-1)path+="../";
		if(url.indexOf("key technologies")>-1||url.indexOf(" valve")>-1||url.indexOf(" dissipating")>-1||url.indexOf(" mitech")>-1||url.indexOf("slurry")>-1||url.indexOf("capabilities")>-1)path+="../";
		if(url.indexOf("passageway")>-1||url.indexOf("gcv")>-1||url.indexOf("edart")>-1)path+="../";
		
		document.getElementById("Popup").runtimeStyle.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+path+"img/common/disabledoverlay.png',sizingMethod='scale')";
		document.getElementById("Popup").style.backgroundImage="none";
	}

function ShowPopup(id){
	if(isIE&&isIE55up){
		//var path,url=unescape(location.href).toLowerCase();
		//if(url.indexOf("design")>-1)path="../";
		//if(url.indexOf("work examples")>-1||url.indexOf("nikas efd lab")>-1)path+="../";
		//if(url.indexOf("key technologies")>-1||url.indexOf(" valve")>-1||url.indexOf(" dissipating")>-1||url.indexOf(" mitech")>-1||url.indexOf("slurry")>-1||url.indexOf("capabilities")>-1)path+="../";
		//if(url.indexOf("passageway")>-1||url.indexOf("gcv")>-1||url.indexOf("edart")>-1)path+="../";
		
		document.getElementById("Popup").runtimeStyle.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+path+"img/Common/DisabledOverlay.png',sizingMethod='scale')";
		document.getElementById("Popup").style.backgroundImage="none";
	}
	
	document.getElementById(id).style.display="block";
	document.getElementById("Popup").style.display="block";
	Popped=id;
}

function HidePopup(){
	document.getElementById("Popup").style.display="none"; document.getElementById(Popped).style.display="none";
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

var thidetooltip;

function getPosition(e) {
    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else {
        cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
        cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
    }
    return cursor;
}

function showtooltip(txt,e){
	var divvy;
	if(!document.getElementById('tooltip')){
		divvy=document.createElement('div');
		divvy.id='tooltip';
		document.body.appendChild(divvy);
	}else{
		divvy=document.getElementById('tooltip');
	}
	if(divvy.style.display=='block')return
	divvy.innerHTML=txt;
	var cursorpos=getPosition(e);
	divvy.style.left=cursorpos.x+'px';
	divvy.style.top=cursorpos.y+'px';
	divvy.style.display='block';
	thidetooltip=setTimeout(hidetooltip,txt.length*50);
}

function hidetooltip(){
	clearTimeout(thidetooltip);
	var divvy=document.getElementById('tooltip');
	if(divvy)divvy.style.display='none';
}