var total_ofertes = 0;
function agregar(x,idioma){
    if ((navigator.appName=='Microsoft Internet Explorer') && (parseInt(navigator.appVersion)>=4)) {
            window.external.AddFavorite('http://'+x,x);
    }else{
            if(navigator.appName == 'Netscape'){
                if (idioma == "es") alert('Presione Crtl+D para agregar este sitio en sus Bookmarks');
                else alert('Press Crtl+D for agree this site in your Bookmarks'); 
            }
    }
}

function enviar_formulari(idioma){
    var correcte = true;
    if (document.formulari.nom.value == ''){
        if (idioma == "es") alert("El campo NOMBRE es obligatorio");
        else alert("The field NAME is requerid");
        correcte= false;
    }
    if (document.formulari.email.value == ''){
        if (idioma == "es") alert("El campo EMAIL es obligatorio");
        else alert("The field EMAIL is requerid");
        correcte = false;
    }else{
        var er_email = /^(.+\@.+\..+)$/
        if(!er_email.test(document.formulari.email.value)) { 
           if (idioma == "es") alert("El campo E-MAIL no es válido.")
           else alert("The field E-MAIL isn't valid");
           correcte = false;
        }   
    }
   
    if (correcte){
        var agree = false;
        if (idioma == "es"){
		if (confirm("¿Desea enviar el formulario?")) agree = true;
	}else{
		if (confirm("Do you wish you send as form?")) agree = true;
	}
        if (agree){
	    document.formulari.action = "index.php?menu=92&ac=c";
            if (document.formulari.zona_web.value == "grupos" ) document.formulari.action = "index.php?menu=4&ac=c"; 
   	    if (document.formulari.zona_web.value == "agencias" ) document.formulari.action = "index.php?menu=7&ac=c";
            document.formulari.submit();
        }
    }
}    

// Per registrar usuari.
var cuadreRegistreIniciat = 1;

function initRegistre(){
    if (cuadreRegistreIniciat==1) document.f_registre.email_registre.value='';
    cuadreRegistreIniciat=0;
    document.f_registre.email_registre.style.color = "#707070";
}    
 
function registrar(idioma){
    var correcte = true;
    if (document.f_registre.email_registre.value == '' || document.f_registre.email_registre.value == 'mi@mail.com' || document.f_registre.email_registre.value == 'my@mail.com'){
        if (idioma == "es") alert("El campo EMAIL es obligatorio");
        else alert("The field EMAIL is requerid");
        correcte = false;
    }else{
        var er_email = /^(.+\@.+\..+)$/
        if(!er_email.test(document.f_registre.email_registre.value)) { 
              if (idioma == "es") alert("El campo E-MAIL no es válido.")
              else alert("The field E-MAIL isn't valid");
              correcte = false;
        }
    } 
    if (correcte){
        if (idioma == "es"){
            if (confirm("¿Deseas registrar-te?")){
                document.f_registre.action = "index.php";
                document.f_registre.submit();
            }
        }else{
            if (confirm("Do you wish register?")){
                document.f_registre.action = "index.php";
                document.f_registre.submit(); 
            }
        }  
    }
}
    
function NewWindow(mypage,myname,w,h,scroll,sta,res){
    var win = null; 
    LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    TopPosition = ((screen.height) ? (screen.height-h)/2 : 0)-10;
    settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',status='+sta+',resizable'+res+'';
    win = window.open(mypage,myname,settings);
}

function load(x,y,zoom){
      var map = new GMap2(document.getElementById("map"));
      map.addControl(new GSmallMapControl());
      map.addControl(new GMapTypeControl());
      GEvent.addListener(map, "moveend", function(){
        var center_actual = map.getCenter();
        var zoom_actual = map.getZoom();
        document.getElementById("coordenades").innerHTML = center_actual.toString();
        document.getElementById("zoom").innerHTML = zoom_actual;
        });
      map.setCenter(new GLatLng(x, y),zoom,G_HYBRID_MAP);  
}

// Google Map API (Marker).
var mapx = null;
var tinyIcon = null;
var markerOptions = null;

function load_map_destinos(x,y,zoom){
     mapx = new GMap2(document.getElementById("map"));
     mapx.addControl(new GSmallMapControl());
     mapx.setCenter(new GLatLng(x,y),zoom);

     //personalitzem els icons...
     tinyIcon = new GIcon();
     tinyIcon.image = "files/img3/mm_7g.png";
     //tinyIcon.shadow = "files/img3/mm_20_shadow.png";
     tinyIcon.iconSize = new GSize(7,7);
     //tinyIcon.shadowSize = new GSize(22,20);
     tinyIcon.iconAnchor = new GPoint(7,7);
     tinyIcon.infoWindowAnchor = new GPoint(5, 1);
     markerOptions = { icon:tinyIcon };

}

function dp(id,x,y){
     var marker = new GMarker( new GLatLng(x,y), markerOptions);
     GEvent.addListener(marker, "click", function() {
          //alert("marker ID> "+id);
	  selectPoblacio(id);
     });
     mapx.addOverlay(marker);
}

function mostrartext(x){
    if (document.getElementById("ocult_"+x).style.visibility!="visible"){
        document.getElementById("ocult_"+x).style.visibility="visible";
        document.getElementById("ocult_"+x).style.display="block";
    }else{
        document.getElementById("ocult_"+x).style.visibility="hidden";
        document.getElementById("ocult_"+x).style.display="none";
    }
}

function amagatext(x){
    document.getElementById("ocult_"+x).style.visibility="hidden";
    document.getElementById("ocult_"+x).style.display="none";
}

function abrir_url(x){
    window.open(x,"_blank");
}

function abrir_url_referer(referer,url){
    window.open("files/php/redireccionar.php?ref="+referer+"&anar="+url,"blank"); 
}       

//Map amb markets (hotels)
function load_top_map(x,y,zoom,punts){ 
      function createMarker(point, nom, id) {
        var marker = new GMarker(point);
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml("<b><a href='#ancle_"+id+"' onclick='javascript:mostrartext("+id+");'>"+nom+"</a></b>");
        });
        return marker;
      }
       
      var map = new GMap2(document.getElementById("map"));
      map.addControl(new GSmallMapControl());
      map.addControl(new GMapTypeControl());
      map.setCenter(new GLatLng(x,y),zoom,G_HYBRID_MAP);
      var p = eval(punts);
      var i = 0;
      for (i = 0; i < p.length; i++){
          map.addOverlay(createMarker(new GLatLng(p[i].px,p[i].py),p[i].pn,p[i].id));
      }    
}
       
// Rotació de quadre d'ofertes. (main-left)
function carrusel( id ) {
    
	    var o=document.getElementById( id );
	    var s0=o.childNodes.item(0);
        //alert(s0.id); 
	    transOpacity( s0.id, 100, 0, 1500);
	    setTimeout("correOferta('"+id+"')", 1500);
	    setTimeout("carrusel('"+id+"')", 5000);
        
}

function correOferta( id ) {
	var o=document.getElementById( id );
	var s0=o.childNodes.item(0);
    var navegador = navigator.appName
    if (navegador != "Microsoft Internet Explorer") {
        //if(s0.id!=""){   
	    o.removeChild( s0 );
	    o.appendChild( s0 );
	    setOpacity(100, document.getElementById( s0.id ));
        //}
    }
}

function asignar_total(total)
{
    total_ofertes = total;
}
// Cambiar idioma. (header-top)
function cambiar_idioma(){
	window.open('index.php?idioma='+document.getElementById("c_idioma").value,'_self');
}

// Validar usuari d'agencies
function validar_agencia(idi){
	if ( document.formulari_login.usuario.value == '' || document.formulari_login.clave.value == '' ){
		if (idi == "en") alert("The name of USER and PASSWORD is required!");
		else alert("El nombre de USUARIO y CLAVE són obligatorios!");
		return;
	}
	document.formulari_login.action = "index.php?menu=1"	
	document.formulari_login.submit();
}

var pos = 0;
function rotar_foto(x){
	if (img.length == 0){
		alert ("No hay imágenes disponibles");
	}	
	if (x == "seguent"){
		if ((pos+1) >= img.length) pos = 0;
		else pos++;
		element = document.getElementById("img_foto");
		element.src = img[pos];
	}
	if (x == "anterior"){
		if ((pos+-1) < 0) pos = (img.length - 1);
		else pos--;
		element = document.getElementById("img_foto");
		element.src = img[pos];
	}
}
//funcio per obtenir els GET de la URL
function gup( name ){
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp ( regexS );
    var tmpURL = window.location.href;
    var results = regex.exec( tmpURL );
    if( results == null ) return "";
    else return results[1];
}
