// BlinDown one submenu and BlindUp the others
/* Parameters:
 		i: Number of submenu
 		dim: Quantity of submenus
   Vars:
   		menu_var: Used in order to not do the animation until the last action in menu is finished
   		menu2: Indicates that submenu2 is opened. Is used to get a better performance of the menu
 */
function menu_on(i,dim){

	if (menu_var == 0) {
			menu_var = 1

			if(i==2){
				menu2 =1;
			}

			if(i==3){
				menu3 =1;
			}


			document.getElementById('tit'+i).setAttribute("src","../img/menu_"+i+lang+"b.gif");



			$("#submenu"+i).slideDown("fast",function(){
			   //alert("Animation Done.");
		  	   menu_var = 0;

				if(i==2){
					menu2 = 0;
				}

				if(i==3){
					menu3 = 0;
				}

			 });


			// SlideUp of all elements that are not the one selected
			// Also, change the image of the elements that are not selected
	  	    for (j=1;j<=dim;j++) {
				if (i!=j) {

					$("#submenu"+j).slideUp();
					document.getElementById('tit'+j).setAttribute("src","../img/menu_" +j+lang+ ".gif");
				}
			}
	} // End of menu_var == 0


	// if the tit3 is selected and the tit2 was selected
	// Just open the tit3 and close tit2 and change their images
	if (i == 3 && menu2 == 1){
		document.getElementById('tit'+i).setAttribute("src","../img/menu_"+i+lang+"b.gif");
		$("#submenu"+i).slideDown("fast");

		$("#submenu2").slideUp("fast");
		document.getElementById('tit2').setAttribute("src","../img/menu_2"+lang+".gif");
	}

	// If the tit1 is selected and the tit2 was selected
	// Just open the tit1 and close tit2 and change their images
	if (i == 1 && menu2 == 1){
		document.getElementById('tit'+i).setAttribute("src","../img/menu_"+i+lang+"b.gif");
		$("#submenu"+i).slideDown("fast");

		$("#submenu2").slideUp("fast");
		document.getElementById('tit2').setAttribute("src","../img/menu_2"+lang+".gif");
	}

	if (i == 4 && menu3 == 1){
		document.getElementById('tit'+i).setAttribute("src","../img/menu_"+i+"b.gif");
		$("#submenu"+i).slideDown("fast");
	}



}

// BlindUp all other submenus
/* Parameters:
 		dim: Quantity of submenus
 */
function menu_out_all(dim){
			for (i=1;i<=dim;i++) {
				$("#submenu"+i).slideUp();
				document.getElementById('tit'+i).setAttribute("src","../img/menu_" +i+lang+ ".gif");
			}
}

function select_page(page){
  /*
	if(page != "contacte")
		ajax_loadContent('main_div',"page_" + page + ".html");

	if(page == "contacte"){
		ajax_loadContent('main_div',"http://cirici.com/test/viladrau2/index2.php?page=contacte");
	}

	if(page == "joc")
		ajax_loadContent('main_div',"http://cirici.com/test/viladrau2/index2.php?page=joc");

	return false;
  */
}

function dis_menu(dim){
	for (i=1;i<=dim;i++) {
		document.getElementById('submenu' + i).style.display = 'none';
	}
}

function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}

function formSend(place) {
	document.getElementById('index').sendPlaceToFlash(place);
	return false;
}


function getPlaceFromFlash(str) {
	if (str == 'index') str = 'home';
	if (str!= 'agua' & str!='empresa' & str!='index') {
 			ajax_loadContent('main_div', "page_" + str + ".asp");
	}
}

function open_map(){
	$("#gmap").slideToggle();
	document.getElementById('gmap_text').innerHTML = '<a href="#" onclick="open_map(); return false;" style="text-decoration:none;" ><img src="../img/google.gif" ALIGN=LEFT>mapa</a>';
}


function open_new_window(str) {
	open(str, 'Sizewindow', 'width=540,height=450,scrollbars=yes,toolbar=no');
}

function select_rute(str){
	if(str!='montseny' & str!='index'){
		 ajax_loadContent('main_div',"page_" + str + ".asp");
	}
}

function hide_map(){
	document.getElementById('gmap').style.display = 'none';
}

function change_arrow_on(but){
	switch(but)
	{
		case 'prev':
			document.getElementById(but).style.background='url(../img/esq-on.gif) no-repeat';
		break;

		case 'next':
			document.getElementById(but).style.background='url(../img/dret-on.gif) no-repeat';
			document.getElementById('prev').style.visibility='visible';
		break;

		default:
			document.getElementById(but).style.background='url(../img/num-on.gif) no-repeat';
	}

}

function change_arrow_off(but){
	switch(but)
	{
		case 'prev':
			document.getElementById(but).style.background='url(../img/esq.gif) no-repeat';
		break;

		case 'next':
			document.getElementById(but).style.background='url(../img/dret.gif) no-repeat';
		break;

		default:
			document.getElementById(but).style.background='url(../img/num.gif) no-repeat';

	}
}

function ckmail(cadena){
    if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(cadena)) { //testeja la expessio, si no ho fico aixi no funciona !?!?! :<
		return true;
	}
	return false;
}







function closeMenu(event) {

  var current, related;

  if (window.event) {                         // If we use IE
    current = this;
    related = window.event.toElement;
  }
  else {									  // Other web browsers
    current = event.currentTarget;
    related = event.relatedTarget;
  }

// If current and related aren't the same and one element does not contain the other
// then we hide the menu. If one contains the oher, no hide menu, because we want to
// be able to use the submenus
  if (current != related && !contains(current, related))
		for (i=1;i<=4;i++) {
			$("#submenu"+i).slideUp();
			document.getElementById('tit'+i).setAttribute("src","../img/menu_" +i+lang+ ".gif");
		}

}


function contains(a, b) {

  // Return true if node a contains node b.

  while (b.parentNode)
    if ((b = b.parentNode) == a)
      return true;
  return false;
}

function change_point_on(name){
	document.getElementById(name).setAttribute("src","../img/punt_on.gif");
}

function change_point_off(name){
	document.getElementById(name).setAttribute("src","../img/punt_off.gif");
}

function change_icon(icon,exit){
	switch(icon){
		case 'imprimir':
			if (exit == 0){
				document.getElementById('print_icon').setAttribute("src","../img/imprimir_down.gif");
			}else {
				document.getElementById('print_icon').setAttribute("src","../img/imprimir.gif");
			}
			break;

		case 'mapa':
			if (exit == 0){
				document.getElementById('mapa_icon').setAttribute("src","../img/mapa_down.gif");
			}else {
				document.getElementById('mapa_icon').setAttribute("src","../img/mapa.gif");
			}
			break;
		case 'hosteleria':
			if (exit == 0){
				document.getElementById('hosteleria_icon').setAttribute("src","../img/hosteleria_down.gif");
			}else {
				document.getElementById('hosteleria_icon').setAttribute("src","../img/hosteleria.gif");
			}
			break;
		case 'hoteles':
			if (exit == 0){
				document.getElementById('hoteles_icon').setAttribute("src","../img/hoteles_down.gif");
			}else {
				document.getElementById('hoteles_icon').setAttribute("src","../img/hoteles.gif");
			}
			break;
		default:
			break;
	}
}

function change_send_but(){
	document.getElementById('send_but').setAttribute("src","../img/enviar-on.gif");

}