

/*
Disable right click script II (on images)- By Dynamicdrive.com
For full source, Terms of service, and 100s DTHML scripts
Visit http://www.dynamicdrive.com
*/

var clickmessage="¡Imagen protegida!"

function addRowToTable()
{
  var tbl = document.getElementById('tblSample');
  var lastRow = tbl.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  
  var row = tbl.insertRow(lastRow);
  
  // nueva columna
  var cellLeft = row.insertCell(0);
  cellLeft.align='left';
	var textNode = document.createElement("span");
	textNode.className ="style1 style6";
	textNode.innerHTML = "<br><strong>Viajero " + (lastRow+1) + ". " +"</strong><hr>";
	cellLeft.appendChild(textNode);
	  
  
  textNode = document.createElement("span");
	textNode.className ="style1 style6";
	textNode.innerHTML = "Nombre: ";
  cellLeft.appendChild(textNode);

  var el = document.createElement('input');
  el.type = 'text';
  //el.setAttribute("className", "txt");
  el.setAttribute("type", "text");
  el.setAttribute("name", "viajero");
  el.setAttribute("id", "viajero");
  el.setAttribute("size", "30");
	cellLeft.appendChild(el);
  

  textNode = document.createElement("span");
	textNode.className ="style1 style6";
	textNode.innerHTML = "&nbsp;*Tal como aparezca en DNI ó Pasaporte";
  cellLeft.appendChild(textNode);

  	var textNode = document.createElement("span");
	textNode.className ="style1 style6";
	textNode.innerHTML = '<div class="campoObligatorio" id="DIV_ERROR_viajero" name="DIV_ERROR_viajero" style="display:none;">El nombre del viajero es obligatorio</div>';
	cellLeft.appendChild(textNode);
	  
	
	var textNode = document.createElement("span");
	textNode.innerHTML = "&nbsp;&nbsp;&nbsp;";
	cellLeft.appendChild(textNode);
	
  textNode = document.createElement("span");
	textNode.className ="style1 style6";
	textNode.innerHTML = "<br>"+ "<br>"+ "Dirección: ";  
  cellLeft.appendChild(textNode);
  
    var dir = document.createElement('input');
  dir.type = 'text';
  //dir.setAttribute("className", "txt");
  dir.setAttribute("type", "text");
  dir.setAttribute("name", "direccion");
  dir.setAttribute("id", "direccion");
  dir.setAttribute("size", "60");

  cellLeft.appendChild(dir);
  
  textNode = document.createElement("span");
	textNode.className ="style1 style6";
	textNode.innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;Código Postal: ";
  cellLeft.appendChild(textNode);  
  
  var cp = document.createElement('input');
  cp.type = 'text';
  //cp.setAttribute("className", "txt");
  cp.setAttribute("type", "text");
  cp.setAttribute("name", "postal");
  cp.setAttribute("id", "postal");
  cp.setAttribute("size", "6");

  cellLeft.appendChild(cp);

    
  textNode = document.createElement("span");
	textNode.className ="style1 style6";
	textNode.innerHTML = "<br><br>Localidad: ";  
  cellLeft.appendChild(textNode);
  
    var lc = document.createElement('input');
  lc.type = 'text';
  //lc.setAttribute("className", "txt");
  lc.setAttribute("type", "text");
  lc.setAttribute("name", "localidad");
  lc.setAttribute("id", "localidad");
  lc.setAttribute("size", "20");

  cellLeft.appendChild(lc);
  
  textNode = document.createElement("span");
	textNode.className ="style1 style6";
	textNode.innerHTML = "&nbsp;&nbsp;Provincia: ";  
  cellLeft.appendChild(textNode);
  
    var pr = document.createElement('input');
  pr.type = 'text';
  //pr.setAttribute("className", "txt");
  pr.setAttribute("type", "text");
  pr.setAttribute("name", "provincia");
  pr.setAttribute("id", "provincia");
  pr.setAttribute("size", "20");

  cellLeft.appendChild(pr);
  
  textNode = document.createElement("span");
	textNode.className ="style1 style6";
	textNode.innerHTML = "&nbsp;&nbsp;País: ";    
  cellLeft.appendChild(textNode);
  
    var ps = document.createElement('input');
  ps.type = 'text';
  //ps.setAttribute("className", "txt");
  ps.setAttribute("type", "text");
  ps.setAttribute("name", "pais");
  ps.setAttribute("id", "pais");
  ps.setAttribute("size", "20");

  cellLeft.appendChild(ps);
  
  textNode = document.createElement("span");
	textNode.className ="style1 style6";
	textNode.innerHTML = "<br>"+ "<br>"+ "Teléfono: ";
  cellLeft.appendChild(textNode);
  
    var tel = document.createElement('input');
  tel.type = 'text';
  //tel.setAttribute("className", "txt");
  tel.setAttribute("type", "text");
  tel.setAttribute("name", "telefonov");
  tel.setAttribute("id", "telefonov");
  tel.setAttribute("size", "10");

  cellLeft.appendChild(tel);
  
  textNode = document.createElement("span");
	textNode.className ="style1 style6";
	textNode.innerHTML ="&nbsp;&nbsp;E-Mail: ";    
  cellLeft.appendChild(textNode);
  
    var ml = document.createElement('input');
  ml.type = 'text';
  //ml.setAttribute("className", "txt");
  ml.setAttribute("type", "text");
  ml.setAttribute("name", "email");
  ml.setAttribute("id", "email");
  ml.setAttribute("size", "20");

  cellLeft.appendChild(ml);
  
   textNode = document.createElement("span");
	textNode.className ="style1 style6";
	textNode.innerHTML = "<br>"+ "<br>"+ "DNI: ";    
  cellLeft.appendChild(textNode);
  
    var pp = document.createElement('input');
  pp.type = 'text';
  //pp.setAttribute("className", "txt");
  pp.setAttribute("type", "text");
  pp.setAttribute("name", "pasaporte");
  pp.setAttribute("id", "pasaporte");
  pp.setAttribute("size", "15");

  cellLeft.appendChild(pp);
  
   textNode = document.createElement("span");
	textNode.className ="style1 style6";
	textNode.innerHTML = "&nbsp;&nbsp;Fecha de Expedición: ";    
  cellLeft.appendChild(textNode);
  
    var expe = document.createElement('input');
  expe.type = 'text';
  //expe.setAttribute("className", "txt");
  expe.setAttribute("type", "text");
  expe.setAttribute("name", "expedicion");
  expe.setAttribute("id", "expedicion");
  expe.setAttribute("size", "10");

  cellLeft.appendChild(expe);
  
   textNode = document.createElement("span");
	textNode.className ="style1 style6";
	textNode.innerHTML = "&nbsp;&nbsp;Fecha de Caducidad: ";  
  cellLeft.appendChild(textNode);
  
    var cad = document.createElement('input');
  cad.type = 'text';
  //cad.setAttribute("className", "txt");
  cad.setAttribute("type", "text");
  cad.setAttribute("name", "caducidad");
  cad.setAttribute("id", "caducidad");
  cad.setAttribute("size", "10");

  cellLeft.appendChild(cad);
  
 
  textNode = document.createElement("span");
	textNode.className ="style1 style6";
	textNode.innerHTML = "<br><br>"+ "Fecha de nacimiento: ";  
  cellLeft.appendChild(textNode);
  
    var nac = document.createElement('input');
  nac.type = 'text';
  //nac.setAttribute("className", "txt");
  nac.setAttribute("type", "text");
  nac.setAttribute("name", "nacimiento");
  nac.setAttribute("id", "nacimiento");
  nac.setAttribute("size", "10");

  cellLeft.appendChild(nac);
  
  
   textNode = document.createElement("span");
	textNode.className ="style1 style6";
	textNode.innerHTML ="&nbsp;&nbsp;Nacionalidad: ";  
  cellLeft.appendChild(textNode);
  
    var lug = document.createElement('input');
  lug.type = 'text';
  //lug.setAttribute("className", "txt");
  lug.setAttribute("type", "text");
  lug.setAttribute("name", "nacionalidad");
  lug.setAttribute("id", "nacionalidad");
  lug.setAttribute("size", "20");

  cellLeft.appendChild(lug);
  
  
  textNode = document.createElement("span");
	textNode.className ="style1 style6";
	textNode.innerHTML = "&nbsp;&nbsp;Reside en España: ";  
  cellLeft.appendChild(textNode);

var lista = document.createElement('select');
  //lista.setAttribute("className", "txt");
  lista.setAttribute("name", "tipo");
  lista.setAttribute("id", "residente");
  lista.setAttribute("name", "residente");



var op1 = document.createElement('option');
var op2 = document.createElement('option');
var op3 = document.createElement('option');


op1.value = "_";
op2.value = "Si";
op3.value = "No";


var txt1 = document.createTextNode('-');
var txt2 = document.createTextNode('Si');
var txt3 = document.createTextNode('No');

op1.appendChild(txt1);
op2.appendChild(txt2);
op3.appendChild(txt3);

lista.appendChild(op1);
lista.appendChild(op2);
lista.appendChild(op3);

  
  cellLeft.appendChild(lista);
}

function removeRowFromTable()
{
  var tbl = document.getElementById('tblSample');
  var lastRow = tbl.rows.length;
  if (lastRow > 1) tbl.deleteRow(lastRow - 1);
}


function disableclick(e) {
if (document.all) {
if (event.button==2||event.button==3) {
if (event.srcElement.tagName=="IMG"){
alert(clickmessage);
return false;
}
}
}
else if (document.layers) {
if (e.which == 3) {
alert(clickmessage);
return false;
}
}
else if (document.getElementById){
if (e.which==3&&e.target.tagName=="IMG"){
alert(clickmessage)
return false
}
}
}

function associateimages(){
for(i=0;i<document.images.length;i++)
document.images[i].onmousedown=disableclick;
}

	
function validarFormulario(){
	var ok=true;
	codigopostal=true;
	email=true;
	telefono=true;	
	movil=true;	
	
	// Validamos los campos requeridos
	//Nombre
	if(document.getElementById("contratante").value.length < 1) 
	{
        document.getElementById("DIV_ERROR_contratante").style.display="block";
		ok=false;
	}
	else document.getElementById("DIV_ERROR_contratante").style.display="none";
	
	//email
	if(document.getElementById("mail").value.length < 1) 
	{
		document.getElementById("DIV_ERROR_mail").innerHTML="El campo email es ogligatorio";        
		document.getElementById("DIV_ERROR_mail").style.display="block";
		ok=false;
		email=false;
	}
	else if(!validaEmail(document.getElementById("mail").value)) 
	{
		document.getElementById("DIV_ERROR_mail").innerHTML="El email introducido no es válido";        
		document.getElementById("DIV_ERROR_mail").style.display="block";
		ok=false;
		email=false;
	}
	
	//Telefono
	if(document.getElementById("telefono").value.length < 1) 
	{
		document.getElementById("DIV_ERROR_telefono").innerHTML="El teléfono es ogligatorio";        
		document.getElementById("DIV_ERROR_telefono").style.display="block";
		ok=false;
		telefono=false;
	}
	else if(!validaTelefono(document.getElementById("telefono").value)) 
	{
		document.getElementById("DIV_ERROR_telefono").innerHTML="El teléfono introducido no es válido";        
		document.getElementById("DIV_ERROR_telefono").style.display="block";
		ok=false;
		telefono=false;
	}			
	
	//Móvil
	if(document.getElementById("movil").value.length < 1) 
	{
		document.getElementById("DIV_ERROR_movil").innerHTML="El móvil es ogligatorio";        
		document.getElementById("DIV_ERROR_movil").style.display="block";
		ok=false;
		movil=false;
	}
	else if(!validaTelefono(document.getElementById("movil").value)) 
	{
		document.getElementById("DIV_ERROR_movil").innerHTML="El móvil introducido no es válido";        
		document.getElementById("DIV_ERROR_movil").style.display="block";
		ok=false;
		movil=false;
	}			

	if(document.getElementById("viaje").value.length < 1) 
	{
        document.getElementById("DIV_ERROR_viaje").style.display="block";
		ok=false;
	}
	else document.getElementById("DIV_ERROR_viaje").style.display="none";
				
				
	if(document.getElementById("inicio").value.length < 1) 
	{
        document.getElementById("DIV_ERROR_inicio").style.display="block";
		ok=false;
	}
	else document.getElementById("DIV_ERROR_inicio").style.display="none";
		
						
	if(document.getElementById("fin").value.length < 1) 
	{
        document.getElementById("DIV_ERROR_fin").style.display="block";
		ok=false;
	}
	else document.getElementById("DIV_ERROR_fin").style.display="none";

	seleccionado = false;
	var alojamiento = document.getElementsByName("alojamiento");
  for (var i=0; i<alojamiento.length; i++) {
     if (alojamiento[i].checked) {
        seleccionado = true;
     }
  }
	if (!seleccionado){
        document.getElementById("DIV_ERROR_seguro").style.display="block";
		ok=false;
	}
	else document.getElementById("DIV_ERROR_seguro").style.display="none";



	seleccionado = false;
	var alojamiento = document.getElementsByName("seguro");
  for (var i=0; i<alojamiento.length; i++) {
     if (alojamiento[i].checked) {
        seleccionado = true;
     }
  }
	if (!seleccionado){
        document.getElementById("DIV_ERROR_alojamiento").style.display="block";
		ok=false;
	}
	else document.getElementById("DIV_ERROR_alojamiento").style.display="none";


	seleccionado = false;
	var alojamiento = document.getElementsByName("cancelacion");
  for (var i=0; i<alojamiento.length; i++) {
     if (alojamiento[i].checked) {
        seleccionado = true;
     }
  }

	if (!seleccionado){
        document.getElementById("DIV_ERROR_cancelacion").style.display="block";
		ok=false;
	}
	else document.getElementById("DIV_ERROR_cancelacion").style.display="none";

	
	var viajeros = document.getElementsByName("viajero");
	var error_viajeros = document.getElementsByName("DIV_ERROR_viajero");
  for (var i=0; i<viajeros.length; i++) {
     if (viajeros[i].value.length < 1) {
     	error_viajeros[i].style.display="block";
     	ok=false;
     }
     else{
     	error_viajeros[i].style.display="none";
    }
  }
  
	seleccionado = false;
	var alojamiento = document.getElementsByName("pago");
  for (var i=0; i<alojamiento.length; i++) {
     if (alojamiento[i].checked) {
        seleccionado = true;
     }
  }
	if (!seleccionado){
        document.getElementById("DIV_ERROR_pago").style.display="block";
		ok=false;
	}
	else document.getElementById("DIV_ERROR_pago").style.display="none";


	seleccionado = false;
	var alojamiento = document.getElementsByName("RadioGroup1");
  for (var i=0; i<alojamiento.length; i++) {
     if (alojamiento[i].checked) {
        seleccionado = true;
     }
  }
	if (!seleccionado){
        document.getElementById("DIV_ERROR_RadioGroup1").style.display="block";
		ok=false;
	}
	else document.getElementById("DIV_ERROR_RadioGroup1").style.display="none";
							
	if(!document.getElementById("condiciones").checked) 
	{
        document.getElementById("DIV_ERROR_condiciones").style.display="block";
		ok=false;
	}
	else document.getElementById("DIV_ERROR_condiciones").style.display="none";
		
	if(email) document.getElementById("DIV_ERROR_mail").style.display="none";
	if(telefono) document.getElementById("DIV_ERROR_telefono").style.display="none";
	if(movil) document.getElementById("DIV_ERROR_movil").style.display="none";
	getElements();
	
	if(!ok) document.getElementById("DIV_ERROR_error").style.display="block";  
	else document.getElementById("DIV_ERROR_error").style.display="none";  
	
	return ok;
}	
	
	
	function getElements()
  {
	  var x=document.getElementsByTagName("input");
	  var viajeros = "";
	  var direcciones = "";
	  var postales = "";
	  var localidades = "";
	  var poblaciones = "";
	  var paises = "";
	  var pasaportes = "";
	  var telefonos = "";
    var emails = "";
	  var expediciones = "";
	  var caducidades = "";
	  var nacimientos = "";
	  var nacionalidades = "";
	  var residentes = "";
	  var provincias = "";
	  
	  for(i = 0; i<x.length; i++){
	  	if (x[i].name == "viajero" && x[i].value != "") viajeros = viajeros + x[i].value + "*";
	  	if (x[i].name == "direccion" && x[i].value != "") direcciones = direcciones + x[i].value + "*";
	  	if (x[i].name == "postal" && x[i].value != "") postales = postales + x[i].value + "*";
	  	if (x[i].name == "localidad" && x[i].value != "") localidades = localidades + x[i].value + "*";
	  	if (x[i].name == "poblacion" && x[i].value != "") poblaciones = poblaciones + x[i].value + "*";
	  	if (x[i].name == "pais" && x[i].value != "") paises = paises + x[i].value + "*";
	  	if (x[i].name == "pasaporte" && x[i].value != "") pasaportes = pasaportes + x[i].value + "*";
	  	if (x[i].name == "telefonov" && x[i].value != "") telefonos = telefonos + x[i].value + "*";
	  	if (x[i].name == "direccion" && x[i].value != "") direcciones = direcciones + x[i].value + "*";
	  	if (x[i].name == "email" && x[i].value != "") emails = emails + x[i].value + "*";
	  	if (x[i].name == "expedicion" && x[i].value != "") expediciones = expediciones + x[i].value + "*";
	  	if (x[i].name == "caducidad" && x[i].value != "") caducidades = caducidades + x[i].value + "*";
	  	if (x[i].name == "nacionalidad" && x[i].value != "") nacionalidades = nacionalidades + x[i].value + "*";
	  	if (x[i].name == "nacimiento" && x[i].value != "") nacimientos = nacimientos + x[i].value + "*";
	  	if (x[i].name == "provincia" && x[i].value != "") provincias = provincias + x[i].value + "*";
	  }
	  	  
		var x=document.getElementsByTagName("select");

	  for(i = 0; i<x.length; i++){
	  	if (x[i].name == "residente" && x[i].value != "") residentes = residentes + x[i].value + "*";
	  }	  
	  document.formulario.viajeros.value = viajeros;
	  document.formulario.direcciones.value = direcciones;
	  document.formulario.postales.value = postales;
	  document.formulario.localidades.value = localidades;
	  document.formulario.poblaciones.value = poblaciones;
	  document.formulario.paises.value = paises;
	  document.formulario.pasaportes.value = pasaportes;
	  document.formulario.telefonos.value = telefonos;
	  document.formulario.emails.value = emails;
	  document.formulario.expediciones.value = expediciones;
	  document.formulario.caducidades.value = caducidades;
	  document.formulario.nacimientos.value = nacimientos;
	  document.formulario.nacionalidades.value = nacionalidades;
	  document.formulario.residentes.value = residentes;
	  document.formulario.provincias.value = provincias;

 	}
 	
function validaEmail(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 validaTelefono(telefono){


	var RegExPatternX = new RegExp("[0123456789 -]"); 
	var errorMessage = 'El numero de telefono solo puede contener numeros, espacios y "-"';
	
	if(telefono != ""){ 
		if (telefono.match(RegExPatternX)) { 
		} 
		else {
			return false
		} 
	}
	return true;
}

function cerrarVentana(){
window.close() 
}  
