// JavaScript Document
//Menu item Over/Out
function menuOver(no,crt,obj,lg)
{
	if(no!=crt)
	{
		obj.src = "img/"+lg+"/menu_sel_0"+no+".jpg";	
	}
}
function menuOut(no,crt,obj,lg)
{
	if(no!=crt)
	{
		obj.src = "img/"+lg+"/menu_0"+no+".jpg";	
	}
}
//Button Over/Out
function btOver(name,obj)
{
	obj.src = "img/"+name+"_sel.jpg";
}
function btOut(name,obj)
{
	obj.src = "img/"+name+".jpg";
}
//Back button
var t,o;
var lastW  = 13; 
function startMove()
{
	var divelement = document.getElementById('div_bt');
	var width=divelement.style.width;
	width = width.substring(0,width.indexOf("px"));
	width=1*width;		
	if(width > 13 )
	{
	   stopMove();
	  clearTimeout(o);
	}
	startMoving();
}
function startMoving()
{
	var divelement = document.getElementById('div_bt');
	var width=divelement.style.width;
	width = width.substring(0,width.indexOf("px"));
	width=1*width;
	if(width < 31 )
	{
	  divelement.style.width = width+1+"px";	  
	  t=setTimeout("startMoving()",25);
  }
}
function stopMove()
{
	clearTimeout(t);
	var divelement = document.getElementById('div_bt');
	var width=divelement.style.width;
	width = width.substring(0,width.indexOf("px"));
	width=1*width;
	if(width >13 )
	{
	  divelement.style.width = width-1+"px";	  	
	  o=setTimeout("stopMove()",25);
	}	
}
function displayScroll(w,h)
{
   if(document.getElementById("dhtmlgoodies_scrolldiv") != null)
   {
		if(document.getElementById("scrolldiv_content").offsetHeight>h)
		{
			scrolldiv_setBgImage('img/scroll.gif');	// Setting border color of the scrolling content				
			setSliderBgImage('img/scrollbar.gif');
			//setContentBgColor('#ffffff');	// Setting color of the scrolling content
			setScrollButtonSpeed(1);	// Setting speed of scrolling when someone clicks on the arrow or the slider
			setScrollTimer(3);	// speed of 1 and timer of 5 is the same as speed of 2 and timer on 10 - what's the difference? 1 and 5 will make the scroll move a little smoother.
			scrolldiv_setWidth(w);	// Setting total width of scrolling div
			scrolldiv_setHeight(h);	// Setting total height of scrolling div
			scrolldiv_initScroll();	// Initialize javascript functions
			if(document.attachEvent)
			{
				document.getElementById("scrolldiv_slider").attachEvent('onselectstart', rfalse); 
			}
		}
	}
}
//ajax
function showNews(id)
   {
    $('div_news_ajax').update('<img src="img/loading.gif" align="left" alt="Loading" style="height:18px;" />');
				new Ajax.Request('front/ajax_news.php?id='+id, {
					  method: 'post',
					  onComplete: function(transport) {
						$('div_news_ajax').update(unescape(transport.responseText));
						displayScroll(348,191);
						
					  }
					  
					});
   }
 
function adjustPageHeight()
{
	var divContent = document.getElementById('div_content');
	if(divContent!=null)
	{
		if(divContent.offsetHeight<378)	
			divContent.style.height = "378px";
	}
}
function showMore(id)
{
	Effect.toggle('div_desc'+id,'blind');	
	Effect.toggle('div_desc'+id+'_more','blind');	
}
//Form functions
function checkCB(no,obj)
{
	var cb = document.getElementById('cb'+no);
	if(cb.value=="0")
	{
		obj.src = "img/cb_sel.jpg";
		cb.value = "1";
	}
	else
	{
		obj.src = "img/cb_dis.jpg";
		cb.value = "0";
	}
}
//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;
}
//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 #9F226E";
		//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 #9F226E";
			//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 = "0px";
	document.getElementById('div_error_'+err).style.display = "none";
}
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 #9F226E";
			//Effect.Shake(input);
			var divErr = document.getElementById(idErr);
			divErr.style.display='block';
			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;					
}

function submit_reserve()
{
	if(validate_reserve()==true)
		document.getElementById('form_reserve').submit();
}
function validate_reserve()
{
	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;
}
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("img_menu"+crtOver).src = 'img/en/menu_0'+crtOver+'.jpg';
		document.getElementById("hidden_submenu"+crtOver).style.visibility = 'hidden';
	}
	if(no!=page)
	{
		crtOver = no;
		document.getElementById("div_submenu").style.display = 'none';
		document.getElementById("hidden_submenu"+no).style.display = 'block';
		document.getElementById("img_menu"+no).src = 'img/en/menu_sel_0'+no+'.jpg';
		document.getElementById("div_submenu").style.visibility = 'hidden';
		document.getElementById("hidden_submenu"+no).style.visibility = 'visible';
	}
	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("img_menu"+crtOver).src = 'img/en/menu_sel_0'+crtOver+'.jpg';
		document.getElementById("div_submenu").style.visibility = 'hidden';
		document.getElementById("hidden_submenu"+crtOver).style.visibility = 'visible';
	}	
}
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("img_menu"+crtOver).src = 'img/en/menu_0'+crtOver+'.jpg';
		document.getElementById("hidden_submenu"+crtOver).style.visibility = 'visible';
	}
}
function genMouseOver()
{
	crtOver = 0;	
}