// JavaScript Document
//Highslide settings
hs.align = 'center';
hs.transitions = ['expand', 'crossfade'];
hs.outlineType = 'rounded-white';
hs.wrapperClassName = 'controls-in-heading';
hs.fadeInOut = true;
//hs.dimmingOpacity = 0.75;
// Add the controlbar
if (hs.addSlideshow) hs.addSlideshow({
	//slideshowGroup: 'group1',
	interval: 5000,
	repeat: false,
	useControls: true,
	fixedControls: false,
	overlayOptions: {
		opacity: 1,
		position: 'top right',
		hideOnMouseOut: false
	}
});
//-------------------------------------------------------------------------------
//Menu item over
function menuOver(obj,root_path,no,crt)
{
	if(no!=crt)
		obj.style.backgroundImage = 'url("'+root_path+'images/bkgr_menu_sel.jpg"'+')';
}
//Menu item out
function menuOut(obj,root_path,no,crt)
{
	if(no!=crt)
		obj.style.backgroundImage = 'url("'+root_path+'images/bkgr_menu.jpg"'+')';
}
//Select history phase
var crtHistory = 3;
var historyText = new Array();
historyText[1] = "1840-1957";
historyText[2] = "1957-2000";
historyText[3] = "2010";
function displayHistory(no)
{
	for(i=1;i<=3;i++)	
	{
		if(i==no)
		{
			document.getElementById('div_etape'+i).style.display = "block";
			document.getElementById('div_etape_photo'+i).style.display = "block";
			document.getElementById('div_link'+i).className = "border_sel"; 
			document.getElementById('a_etape'+i).className = "year_sel"; 
			document.getElementById('div_etape_title').innerHTML = historyText[i];
		}
		else
		{
			document.getElementById('div_etape'+i).style.display = "none";
			document.getElementById('div_etape_photo'+i).style.display = "none";
			document.getElementById('div_link'+i).className = "border"; 
			document.getElementById('a_etape'+i).className = "year"; 
		}
	}
	crtHistory = no;
}
//Mouseover/out history years right
function linkRightOver(no)
{
	if(no!=crtHistory)
		document.getElementById('div_link'+no).className = "border_sel"; 
}
function linkRightOut(no)
{
	if(no!=crtHistory)
		document.getElementById('div_link'+no).className = "border"; 
}
//Open/close panel
function openclosePanel(no)
{
	var bt = document.getElementById('img_bt_panel'+no);
	if(document.getElementById("div_panel"+no).style.display=="none")
	{
		bt.src = ROOT_PATH+"images/panel_close.jpg";
		bt.title = "-";
		bt.alt = "-";
	}
	else
	{
		bt.src = ROOT_PATH+"images/panel_open.jpg";
		bt.title = "+";
		bt.alt = "+";
	}
	Effect.toggle("div_panel"+no,'blind');
}
//------------------------------------------------------------------------------
//Form
//checks if a field is not empty
function field_required(input,err_msg,isFocus)
{
	if(isFocus==1)
		document.getElementById(input).value=trim(document.getElementById(input).value);	
	if(document.getElementById(input).value=="")
	{
		alert(err_msg);
		if(isFocus==1)
			document.getElementById(input).focus();
		return false;
	}
	return true;
}
//checks if a field is valid calling the specific function
function field_validate(input,err_msg,isFocus,checkFunction)
{
	if(isFocus==1)
		document.getElementById(input).value=trim(document.getElementById(input).value);	
	if(document.getElementById(input).value!="")
	{
		checkValue = eval(checkFunction+'(document.getElementById("'+input+'").value)');
		if(checkValue==false)
		{
			alert(err_msg);
			if(isFocus==1)
				document.getElementById(input).focus();
			return false;
		}
	}
	return true;
}
//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;
}
//ajax test for credentials
function testCredentials(iLogin,iPass,err_msg)
{
	var inputLogin = trim(document.getElementById(iLogin).value);
	var inputPass = trim(document.getElementById(iPass).value);
	if((inputLogin!="")&&(inputPass!=""))
	{
		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",ROOT_PATH+"include/test_credentials.php?login="+inputLogin+"&pass="+inputPass,false);
		xmlHttp.send(null);
		res=xmlHttp.responseText; 
		if(res=="true")
			return true;
		else
		{
			alert(err_msg);
			return false;
		}
	}
	else
		return true;
}
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;					
}
