// JavaScript Document
function flagOver(obj,crt,sel,path)
{
	if(crt!=sel)
		obj.src = path+"images/flag_"+crt+"_sel.jpg";
}
function flagOut(obj,crt,sel,path)
{
	if(crt!=sel)
		obj.src = path+"images/flag_"+crt+".jpg";
}
function menuOver(obj,crt,sel,lg)
{
	if(crt!=sel)	
		obj.className = "div_menu_item div_menu_0"+crt+" div_menu_sel_0"+crt+"_"+lg;
}
function menuOut(obj,crt,sel,lg)
{
	if(crt!=sel)	
		obj.className = "div_menu_item div_menu_0"+crt+" div_menu_0"+crt+"_"+lg;
}
//Submenu
var crtOver = 0;
//mouse over function for menu
function menuMouseOver(no,page)	
{
	if(crtOver!=0)
	{
		document.getElementById("hidden_submenu"+crtOver).style.display = 'none';
		document.getElementById("hidden_submenu"+crtOver).style.visibility = 'hidden';
		document.getElementById("div_menu"+crtOver).className = "div_menu_item div_menu_0"+crtOver+" div_menu_0"+crtOver+"_"+LANG;
	}
	if(no!=page)
	{
		crtOver = no;
		document.getElementById("div_submenu").style.display = 'none';
		document.getElementById("div_submenu").style.visibility = 'hidden';
		document.getElementById("hidden_submenu"+no).style.display = 'block';
		document.getElementById("hidden_submenu"+no).style.visibility = 'visible';
		document.getElementById("div_menu"+no).className = "div_menu_item div_menu_0"+no+" div_menu_sel_0"+no+"_"+LANG;
		if(document.getElementById("hidden_submenu"+no).innerHTML!="&nbsp;")
			document.getElementById("div_header").style.backgroundColor = "#F1F1F1";
		else
			document.getElementById("div_header").style.backgroundColor = "#FFFFFF";
	}
	else
	{
		crtOver = 0;
		document.getElementById("div_submenu").style.display = 'block';
		document.getElementById("div_submenu").style.visibility = 'visible';
	}
}
function menuMouseOut()
{
//	document.getElementById("div_submenu").style.display = 'block';
//	document.getElementById("hidden_submenu"+crtOver).style.display = 'none';
}
function submenuMouseOver()
{
	if(crtOver!=0)
	{
		document.getElementById("div_submenu").style.display = 'none';
		document.getElementById("hidden_submenu"+crtOver).style.display = 'block';
		document.getElementById("div_submenu").style.visibility = 'hidden';
		document.getElementById("hidden_submenu"+crtOver).style.visibility = 'visible';
		document.getElementById("div_menu"+crtOver).className = "div_menu_item div_menu_0"+crtOver+" div_menu_sel_0"+crtOver+"_"+LANG;
		if(document.getElementById("hidden_submenu"+crtOver).innerHTML!="&nbsp;")
			document.getElementById("div_header").style.backgroundColor = "#F1F1F1";
		else
			document.getElementById("div_header").style.backgroundColor = "#FFFFFF";
	}	
}
function submenuMouseOut()
{
	document.getElementById("div_submenu").style.display = 'block';
	document.getElementById("div_submenu").style.visibility = 'visible';
	if(crtOver!=0)
	{
		document.getElementById("hidden_submenu"+crtOver).style.display = 'none';
		document.getElementById("hidden_submenu"+crtOver).style.visibility = 'hidden';
		document.getElementById("div_menu"+crtOver).className = "div_menu_item div_menu_0"+crtOver+" div_menu_0"+crtOver+"_"+LANG;
		if((CRTPG==0)||(document.getElementById("div_submenu").innerHTML=="&nbsp;"))
			document.getElementById("div_header").style.backgroundColor = "#FFFFFF";
		else
			document.getElementById("div_header").style.backgroundColor = "#F1F1F1";
	}
}
function genMouseOver()
{
	crtOver = 0;	
}
//Items
var crtItem = 0;
function displayItem(no)
{
	crtItem = no;
	document.getElementById("div_items").style.display = 'none';
	document.getElementById("div_buttons").style.display = 'none';
	document.getElementById("div_item"+no).style.display = 'block';
	document.getElementById("div_back").style.display = 'block';
}
function displayItems()
{
	document.getElementById("div_item"+crtItem).style.display = 'none';
	document.getElementById("div_back").style.display = 'none';
	document.getElementById("div_items").style.display = 'block';
	document.getElementById("div_buttons").style.display = 'block';
	crtItem = 0;
}
function showHistory(id)
{
	document.getElementById('div_history'+id).style.display = "block";
	document.getElementById('cursor_L'+id).style.visibility = "visible";
	document.getElementById('cursor_R'+id).style.visibility = "visible";
}
function hideHistory(id)
{
	document.getElementById('div_history'+id).style.display = "none";
	document.getElementById('cursor_L'+id).style.visibility = "hidden";
	document.getElementById('cursor_R'+id).style.visibility = "hidden";
}
//Tabs
var crtTab = 1;
function selTab(no)
{
	if(crtTab!=0)
	{
		if(document.getElementById("tab"+crtTab)!=null)
		{
			document.getElementById("tab"+crtTab).style.display="none";
			document.getElementById("button"+crtTab).className="button";
		}
	}
	document.getElementById("tab"+no).style.display="block";
	document.getElementById("button"+no).className="button button_sel";
	crtTab = no;
}
//Job
var crtJob = 0;
function selectJob(id)
{
	document.getElementById("button2").style.display="block";
	document.getElementById('select_job').selectedIndex = 0;
	selTab(2);
    $('tab2').update('<img src="../images/admin/loading.gif" align="left" alt="Loading" width="20" />');
                new Ajax.Request('ajaxJob.php?job='+id, {
                      method: 'post',
                      onComplete: function(transport) {
                        $('tab2').update(unescape(transport.responseText));
                      }
                     
                    });
}
function apply(id)
{
	var sJob = document.getElementById('select_job');
	var selI = 0;
	for(i=0;i<sJob.length;i++)
	{
		if(sJob.options[i].value == id)
			selI = i;
	}
	sJob.selectedIndex = selI;
	selTab(1);
}
function formJob()
{
	var sJob = document.getElementById('select_job');
	id = sJob.options[sJob.selectedIndex].value;
	if(id==0)
		document.getElementById("button2").style.display="none";
	else
	{
		document.getElementById("button2").style.display="block";
		$('tab2').update('<img src="../images/admin/loading.gif" align="left" alt="Loading" width="20" />');
					new Ajax.Request('ajaxJob.php?job='+id, {
						  method: 'post',
						  onComplete: function(transport) {
							$('tab2').update(unescape(transport.responseText));
						  }
						 
						});
	}
}
//Map
function displayMap(no)
{
	document.getElementById("div_map"+no).style.display = 'block';
}
function hideMap(no)
{
	document.getElementById("div_map"+no).style.display = 'none';
}
function validate_careers()
{
	var ok = true;
	ok = field_required('input_last_name','div_error_last_name');
	ok &= field_required('input_first_name','div_error_first_name');
	ok &= field_required('input_mail','div_error_mail');
	ok &= field_validate('input_mail','check_mail','div_error_mail2');
	ok &= field_required('input_phone','div_error_phone');
	ok &= field_required('input_code','div_error_code');
	ok &= testDbValue('input_code','securitycode','div_error_code2');
	if(ok==false)
		return false;
	return true;
}
function submit_careers()
{
	if(validate_careers()==true)
		document.getElementById("form_careers").submit();
}
var inputColor = "#B3B3B3";
//checks if a field is not empty
function field_required(input,idErr)
{
	document.getElementById(input).value=trim(document.getElementById(input).value);	
	if(document.getElementById(input).value=="")
	{
		document.getElementById(input).style.border = "1px solid #E6A180";
		//Effect.Shake(input);
		var divErr = document.getElementById(idErr);
		divErr.style.display='block';
		return false;
	}
	return true;
}
//checks if a field is valid calling the specific function
function field_validate(input,checkFunction,idErr)
{
	document.getElementById(input).value=trim(document.getElementById(input).value);	
	if(document.getElementById(input).value!="")
	{
		checkValue = eval(checkFunction+'(document.getElementById("'+input+'").value)');
		if(checkValue==false)
		{
			document.getElementById(input).style.border = "1px solid #E6A180";
			//Effect.Shake(input);
			var divErr = document.getElementById(idErr);
			divErr.style.display='block';
			return false;
		}
	}
	return true;
}
//reset error div
function reset_error(input,err)
{
	document.getElementById('input_'+input).style.border = "1px solid "+inputColor;
	document.getElementById('div_error_'+err).style.display = "none";
}
//eliminates white spaces from a string
function trim(str)
{  
	while(str.charAt(0) == (" ") )
		str = str.substring(1);
  	while(str.charAt(str.length-1) == " " )
		str = str.substring(0,str.length-1);
  return str;
}
function check_mail(str) 
{
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1){
	   return false;
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false;
	}
	 if (str.indexOf(at,(lat+1))!=-1){
		return false;
	 }
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false;
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		return false;
	 }
	
	 if (str.indexOf(" ")!=-1){
		return false;
	 }
	 return true;					
}
function testDbValue(input,fileName,idErr)
{
	var inputValue = trim(document.getElementById(input).value);
	if(inputValue!="")
	{
		var xmlHttp;
		try
		{
			// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
		}
		catch (e)
		{
			// Internet Explorer
			try
			{
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{
				try
				{
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e)
				{
					alert("Your browser does not support AJAX!");
					return false;
				}
			}
		}
		xmlHttp.open("GET","../front/test_"+fileName+".php?val="+inputValue,false);
		xmlHttp.send(null);
		res=xmlHttp.responseText; 
		if(res=="true")
			return true;
		else
		{
			document.getElementById(input).style.border = "1px solid #E6A180";
			//Effect.Shake(input);
			var divErr = document.getElementById(idErr);
			divErr.style.display='block';
			return false;
		}
	}
	else
		return true;
} 
//gallery thyumb bar speed (miliseconds)
var thumbsSpeed = 5;

//initial values for gallery
var crtThumbPos = 0;
var crtTimeout;

//move thumbs bar left (dir=0) or right(dir=1) onmouseover
function moveThumbs(dir)
{
	//home page
	movingThumbs = true;
	if(dir==0)
	{
		//left button
		if (crtThumbPos!=0) //test limit
		{
			//move right
			crtThumbPos++;
			newMg = crtThumbPos+"px";
			document.getElementById("div_move").style.marginLeft = newMg;
			crtTimeout = setTimeout('moveThumbs(0)',thumbsSpeed);
		}
	}
	else
	{
		//right button
		divWidth = document.getElementById("div_move").offsetWidth;
		limitR = divWidth-630;
		if(Math.abs(crtThumbPos)!=limitR) //test limit
		{
			//move left
			crtThumbPos--;
			newMg = crtThumbPos+"px";
			document.getElementById("div_move").style.marginLeft = newMg;
			crtTimeout = setTimeout('moveThumbs(1)',thumbsSpeed);
		}
	}
}

//stop thumbs moving onmouseout
function stopThumbs()
{
	//stop moving
	clearTimeout(crtTimeout);
}
//-------------------------------------------------------------
//3D
function startTour()
{
	Effect.Fade("div_take_tour_button",{duration:2.0});
	Effect.Appear("div_img_heli_graphic",{duration:2.0});
	Effect.Fade("div_img_heli",{duration:2.0});
	Effect.Fade("div_img_heli_graphic",{duration:2.0,queue:'end'});
	Effect.Appear("div_main_graphic",{duration:2.0,queue:'end'});
	Effect.toggle("div_3D_menu",'blind',{queue:'end'});
}
var crtOpenedSub = 0;
var crtFloor = 0;
var crtCat = 0;
function select3DCategory(id,cntCat)
{
	//select menu item
	if(crtCat!=0)
	{
		document.getElementById('item'+crtCat).className="item";
		if(crtCat!=1)
		{
			prevCat = crtCat-1;
			document.getElementById('overlay'+prevCat).className="overlay";
		}
		nextCat = crtCat;
		if(noCat!=crtCat)
			document.getElementById('overlay'+nextCat).className="overlay";
		else
			document.getElementById('overlay'+nextCat).className="overlay_last";
	}
	document.getElementById('item'+cntCat).className="item_sel";
	if(cntCat!=1)
	{
		prevCat = cntCat-1;
		document.getElementById('overlay'+prevCat).className="overlay_01";
	}
	nextCat = cntCat;
	if(noCat!=cntCat)
		document.getElementById('overlay'+nextCat).className="overlay_10";
	else
		document.getElementById('overlay'+nextCat).className="overlay_last_sel";
	crtCat=cntCat;
	//hide minimap & highlights
	document.getElementById('div_minimap').style.display = "none";
	document.getElementById('div_highlights_mini').style.display = "none";
	//display main graphic
	document.getElementById('div_main_graphic').style.display = "block";
	crtProcess = 0;
	$('div_buildings').update('');
				new Ajax.Request('ajaxHLBuildings.php?cat='+id, {
					  method: 'post',
					   onCreate: function() { 
					   				document.getElementById("div_buildings").style.display = "none"; 
									if(crtFloor!=0)
										Effect.Fade("div_floor"+crtFloor,{duration:1.0});
									Effect.Fade("div_highlights_rooms",{duration:1.0});
						   			Effect.Fade("div_photos",{duration:1.0});
										},
					   onSuccess: function() { document.getElementById("div_buildings").style.display = "block"; blinkObject('div_buildings',-1,4); },
					  onComplete: function(transport) {
						$('div_buildings').update(unescape(transport.responseText));
					  }
					 
					});
	crtOpenedSub = 0;
	$('div_processes').update('');
				new Ajax.Request('ajaxGetProcesses.php?cat='+id, {
					  method: 'post',
					  onComplete: function(transport) {
						$('div_processes').update(unescape(transport.responseText));
					  }
					 
					});
}

function blinkObject(div,crt,no)
{
	var divO = document.getElementById(div);
	if(crt!=no)
	{
		crt++;
		if(crt%2==0)
			divO.style.display = "block";
		else
			divO.style.display = "none";
		setTimeout('blinkObject("'+div+'",'+crt+','+no+')',200);
	}
}
function open3dSub(id)
{
	if(crtOpenedSub!=id)
	{
		if(crtOpenedSub!=0)	
			Effect.toggle('div_3d_submenu_sub'+crtOpenedSub,'blind');
		Effect.toggle('div_3d_submenu_sub'+id,'blind');
		crtOpenedSub=id
	}
}
function select3DProcess(id,id_floor)
{
	document.getElementById('div_minimap').style.display = "block";
	document.getElementById('div_highlights_mini').style.display = "block";
	document.getElementById('div_highlights_rooms').style.display = "none";
	if(testIE6()==false)
		document.getElementById("div_highlights_mini").style.backgroundImage = "url(../images/3D/hl_floor_mini"+id_floor+".png)";
	else
		document.getElementById("div_highlights_mini").style.backgroundImage = "url(../images/3D/hl_floor_mini"+id_floor+".gif)";
	if(crtProcess!=0)
	{
		document.getElementById('a_process'+crtProcess).style.color = "#858181";
		document.getElementById('div_a_process'+crtProcess).style.color = "#858181";
	}
	document.getElementById('a_process'+id).style.color = "#EF6000";
	document.getElementById('div_a_process'+id).style.color = "#EF6000";
	crtProcess = id;
	if(crtFloor!=0 && crtFloor!=id_floor)
		Effect.Fade("div_floor"+crtFloor,{duration:1.0});
	Effect.Appear("div_floor"+id_floor,{duration:1.0});
	crtFloor = id_floor;
	$('div_highlights_rooms').update('');
	new Ajax.Request('ajaxGetItem.php?item='+id+'&floor='+id_floor, {
		  method: 'post',
		  onCreate: function() {
				Effect.Fade("div_buildings",{duration:1.0});
				Effect.Fade("div_main_graphic",{duration:1.0});
			  },
			onSuccess: function() { 
					setTimeout("blinkObject('div_highlights_rooms',-1,8)",1000);
					},
		  onComplete: function(transport) {
			$('div_highlights_rooms').update(unescape(transport.responseText));
		  }
		 
		});
	$('div_photos').update('<img src="../images/admin/loading.gif" align="left" alt="" width="20"  style="margin:30px 250px"/>');
	new Ajax.Request('ajaxItemPhotos.php?item='+id, {
		  method: 'post',
		onSuccess: function() { 
				Effect.Appear("div_photos",'blind');
			},
		  onComplete: function(transport) {
			$('div_photos').update(unescape(transport.responseText));
		  }
		 
		});
}
//move thumbs bar left (dir=0) or right(dir=1) onmouseover
function moveThumbs3D(dir)
{
	//home page
	movingThumbs = true;
	if(dir==0)
	{
		//left button
		if (crtThumbPos!=0) //test limit
		{
			//move right
			crtThumbPos++;
			newMg = crtThumbPos+"px";
			document.getElementById("div_move").style.marginLeft = newMg;
			crtTimeout = setTimeout('moveThumbs3D(0)',thumbsSpeed);
		}
	}
	else
	{
		//right button
		divWidth = document.getElementById("div_move").offsetWidth;
		limitR = divWidth-580;
		if(Math.abs(crtThumbPos)!=limitR) //test limit
		{
			//move left
			crtThumbPos--;
			newMg = crtThumbPos+"px";
			document.getElementById("div_move").style.marginLeft = newMg;
			crtTimeout = setTimeout('moveThumbs3D(1)',thumbsSpeed);
		}
	}
}
function testIE6()
{
	var browserName=navigator.appName; 
	var agt=navigator.userAgent.toLowerCase();
	if (browserName=="Microsoft Internet Explorer")
	{
	  if((agt.indexOf("msie 6.")!=-1))
	  {
	  	return true;
	  }
	}
	return false;
}
function itemOver(id)
{
	if(id!=crtProcess)
	{
		var d = document.getElementById("div_a_process"+id);
		d.style.color = "#EF6000";
	}
}
function itemOut(id)
{
	if(id!=crtProcess)
	{
		var d = document.getElementById("div_a_process"+id);
		d.style.color = "#858181";
	}
}
function categoryOver(no)
{
	if(no!=crtCat)
	{
		document.getElementById('item'+no).className="item_sel";
		if(no!=1)
		{
			prevCat = no-1;
			if(prevCat!=crtCat)
				document.getElementById('overlay'+prevCat).className="overlay_01";
			else
				document.getElementById('overlay'+prevCat).className="overlay_11";
		}
		nextCat = no;
		if(noCat!=no)
		{
			if(nextCat+1!=crtCat)
				document.getElementById('overlay'+nextCat).className="overlay_10";
			else
				document.getElementById('overlay'+nextCat).className="overlay_11";
		}
		else
			document.getElementById('overlay'+nextCat).className="overlay_last_sel";
	}
}
function categoryOut(no)
{
	if(no!=crtCat)
	{
		document.getElementById('item'+no).className="item";
		if(no!=1)
		{
			prevCat = no-1;
			if(prevCat!=crtCat)
				document.getElementById('overlay'+prevCat).className="overlay";
			else
				document.getElementById('overlay'+prevCat).className="overlay_10";
		}
		nextCat = no;
		if(noCat!=no)
		{
			if(nextCat+1!=crtCat)
				document.getElementById('overlay'+nextCat).className="overlay";
			else
				document.getElementById('overlay'+nextCat).className="overlay_01";
		}
		else
			document.getElementById('overlay'+nextCat).className="overlay_last";
	}
}