//variables de ventanas
WindowHandle=0

function AbreVentana(popup,w,h,s) {
this.name="Principal"
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;

if (WindowHandle) {
	if (!WindowHandle.closed) {
		if (ns4) {
			WindowHandle.focus();
		}
		else {
			WindowHandle.close();
		}
	}
}
WindowHandle=window.open(popup,"","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars="+s+",resizable=no,width="+w+",height="+h+",top="+TopPosition+",left="+LeftPosition);
}

function CierraVentana() {
	if (WindowHandle) {
		if (!WindowHandle.closed) {
			WindowHandle.close();
		}
	}
}

function imprimeCorreo() {
	document.write("contactocliente@hotelforo.com");
}


/*************************************************************************************************************************************/
/* Funcion creaAjax : Crea un nuevo objeto Ajax, tanto si es explorer como si es otro explorador.                                    */
/* ***********************************************************************************************************************************/

function creaAjax(){
	var objetoAjax=false;
	try {
		/*Para navegadores distintos a internet explorer*/
		objetoAjax = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			/*Para explorer*/
			objetoAjax = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (E) {
			objetoAjax = false;
		}
	}
	
	if (!objetoAjax && typeof XMLHttpRequest!='undefined') {
		objetoAjax = new XMLHttpRequest();
	}
	return objetoAjax;
}

/*************************************************************************************************************************************/
/* Funcion FAjax : función que dado una url un id de capa unos valores y el metodo abre dicha url pasandole los valores por el metodo*/
/* ***********************************************************************************************************************************/
//url: nombre del php al que llama el jscript
//capa=nombre capa contenedora
//valores='IDDestino=$IDD'
//metodo=POST
function FAjax (url,capa,valores,metodo,elimina){
	var ajax=creaAjax();
	var capaContenedora = document.getElementById(capa);

	/*Creamos y ejecutamos la instancia si el metodo elegido es POST*/
	if(metodo.toUpperCase()=='POST'){
		ajax.open ('POST', url, true);
		ajax.onreadystatechange = function() {
		if (ajax.readyState==1) {
      if(!elimina){
			  capaContenedora.innerHTML="Cargando...<img src=images/loading.gif>";
      }
		}else
			if (ajax.readyState==4){
				if(ajax.status==200){
						document.getElementById(capa).innerHTML=ajax.responseText;
				}else 
					if(ajax.status==404){
						capaContenedora.innerHTML = "La direccion no existe";
					}else{
						capaContenedora.innerHTML = "Error: ".ajax.status;
					}
				}
			}
		ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		ajax.send(valores);
		return;
	}
	/*Creamos y ejecutamos la instancia si el metodo elegido es GET*/
	if (metodo.toUpperCase()=='GET'){
	  ajax.open ('GET', url, true);
		ajax.onreadystatechange = function() {
																if (ajax.readyState==1) {
																	capaContenedora.innerHTML="Cargando...";
																}else 
																	if (ajax.readyState==4){
																		if(ajax.status==200){
																			document.getElementById(capa).innerHTML=ajax.responseText;
																		}else 
																			if(ajax.status==404){
																				capaContenedora.innerHTML = "La direccion no existe";
																			}else{
																				capaContenedora.innerHTML = "Error: ".ajax.status;
																			}
																		}
																	}
																ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
																ajax.send(null);
																return
															}



}

function Validar(url,capa,ID,metodo,elimina)
{
	var i;
	var marcado1; 
  var marcado2;
  var valores=ID;
  var correcto=1;
  var valorPositivo, valorNegativo;
  //comprobar existencia de cada uno por separado

  if(document.forms[0].positivo){
    radioPositivo=document.formulario.positivo;
    //comprobar items chequeados
    marcado1=0;
    if(radioPositivo.length>1){
      for(i=0;i<radioPositivo.length;i++){
        if(radioPositivo[i].checked){
		      valorPositivo=radioPositivo[i].value;
          marcado1=1;
        }
	    }
    }
    //solo un item
    else if(radioPositivo.checked){
	    valorPositivo=radioPositivo.value;
      marcado1=1;
    }
  }

  if(document.forms[0].negativo){
    radioNegativo=document.forms[0].negativo;
    // items chequeados
    marcado2=0;
    if(radioNegativo.length>1){
      for(i=0;i<radioNegativo.length;i++){
        if(radioNegativo[i].checked){
		      valorNegativo=radioNegativo[i].value;
          marcado2=1;
        }
	    }
    }
    //solo un item
    else if(radioNegativo.checked){
	    valorNegativo=radioNegativo.value;
      marcado2=1;
    }
  }

  if(!marcado1 && !marcado2){
    alert('Por favor, debe seleccionar el comentario.');
    correcto=0;
		return false;
  }
  else{
    if(valorPositivo && !valorNegativo){
      valores+="&p="+valorPositivo;
    }
    else if(valorNegativo && !valorPositivo){
      valores+="&n="+valorNegativo;
    }
    else if(valorPositivo && valorNegativo){
      if(valorPositivo!=valorNegativo){
        alert('Por favor, no seleccione comentarios de diferentes autores.');
        correcto=0;
		    return false;
      }
      else{
        valores+="&p="+valorPositivo+"&n="+valorNegativo;
      }
    }
    if(correcto==1){
      _limpia();
      FAjax(url,capa,valores,metodo,elimina);
    }
  }
}


function cambiaTexto(texto,valor)
{
if(valor){
  var retorno=_compruebaPais(valor);
}
var objetoDIV = document.getElementById(texto);
if(!valor){
  if(texto=='COMENTARIOS' || texto=='ANNADIR'){
    objetoDIV.innerHTML = "";
  }
  else{
    objetoDIV.innerHTML = "<select class=combo><option value=0>Seleccione "+texto.toLowerCase()+"...</option></select>";
  }
}
else{
  if(texto=='campoOculto' && retorno==1){
    objetoDIV.innerHTML = "<div id=LOCALIDAD><select class=combo><option>Seleccione localidad...</option></select></div>";
  }
  else if(texto=='campoOculto' && retorno==0){
    objetoDIV.innerHTML = "<div id=LOCALIDAD style='visibility:hidden;'><select class=combo><option>Seleccione localidad...</option></select></div>";
  }

}

  return true;
}

function _compruebaPais(valor)
{
  if(valor==15){
    return 1;
  }
  else{
    return 0;
  }
}

function _limpia(){
document.getElementById("itemPAIS").innerHTML = "";
document.getElementById("comboPaises").innerHTML = "";
document.getElementById("itemPROVINCIA").innerHTML = "";
document.getElementById("PROVINCIA").innerHTML = "";
document.getElementById("itemLOCALIDAD").innerHTML = "";
document.getElementById("campoOculto").innerHTML = "";
document.getElementById("itemHOTEL").innerHTML = "";
document.getElementById("HOTEL").innerHTML = "";
return true;
}