function check_date(field){
 var checkstr = "0123456789";
 var DateField = field;
 var Datevalue = "";
 var DateTemp = "";
 var seperator = "/";
 var day;
 var month;
 var year;
 var leap = 0;
 var err = 0;
 var i;
 err = 0;
 DateValue = DateField.value;
 for (i = 0; i < DateValue.length; i++) {
  if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
   DateTemp = DateTemp + DateValue.substr(i,1);
  }
 }
 if (DateTemp == "") {
  field.select();
  field.focus();
  return false;
 }
 DateValue = DateTemp;
 if (DateValue.length == 6) {
  DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2);
 }
 if (DateValue.length != 8) {
  err = 19;
 }
 year = DateValue.substr(4,4);
 if (year == 0) {
  err = 20;
 }
 month = DateValue.substr(2,2);
 if ((month < 1) || (month > 12)) {
  err = 21;
 }
 day = DateValue.substr(0,2);
 if (day < 1) {
  err = 22;
 }
 if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
  leap = 1;
 }
 if ((month == 2) && (leap == 1) && (day > 29)) {
  err = 23;
 }
 if ((month == 2) && (leap != 1) && (day > 28)) {
  err = 24;
 }
 if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
  err = 25;
 }
 if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
  err = 26;
 }
 if ((day == 0) && (month == 0) && (year == 00)) {
  err = 0; day = ""; month = ""; year = ""; seperator = "";
 }
 if (err == 0) {
  DateField.value = day + seperator + month + seperator + year;
  return true;
 } else {
  DateField.select();
  DateField.focus();
  return false; 
 }
}

function IsDigits(sText) {
 var ValidChars = "0123456789";
 var IsNumber=true;
 var Char;
 for (i = 0; i < sText.length && IsNumber == true; i++) { 
  Char = sText.charAt(i); 
  if (ValidChars.indexOf(Char) == -1) {IsNumber = false;}
 }
 return IsNumber;
}

function inputnotdigits(el,msg) {
 txt = el.value;
 el.value = txt = txt.split(' ').join('');
 if ((IsDigits(el.value))&&(isnotnull(el.value))) {
  return true
 } else {
  el.value = '';
  alert(msg);
  el.focus();
  return false;
 }
}

function inputnotdigitsorempty(el,msg) {
 txt = el.value;
 el.value = txt = txt.split(' ').join('');
 if ((IsDigits(el.value))||(!isnotnull(el.value))) {
  return true
 } else {
  el.value = '';
  alert(msg);
  el.focus();
  return false;
 }
}

function selectnotnull (el,msg) {
 if (el.selectedIndex == 0) {
  alert(msg);
  el.focus();
  return false;
 }
 return true;
}

function isnotnull(txt) {
 var texto = '';
 txt = txt.split(' ').join('');
 if (txt=='') {
  return false;
 } else {
  return true;
 }
}

function inputnotnull(el,msg) {
 if (!isnotnull(el.value)) {
  alert(msg);
  el.value = '';
  el.focus();
  return false;
 } else {
  return true;
 }
}

function inputnotnull_u(el,msg) {
 if (inputnotnull(el,msg)) {
  to_mayuscula(el);
  return true
 }
 return false;
}

function to_mayuscula(el) {
  var txt = el.value;
  el.value = txt.toUpperCase(txt);
}

function verificafecha (el,msg) {
 if (!check_date(el)) {
  alert(msg);
  el.focus();
  return false;
 } else {
  return true
 }
}

function inputisvalidemail(el,msg) {
 var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
 var addr = el.value;
 if(reg.test(addr) == false) {
  alert(msg);
  el.focus();
  return false;
 } else {
  return true;
 }
}

function checkifequal(el1,el2,msg) {
 var tx1 = el1.value;
 var tx2 = el2.value;
 tx1 = tx1.split(' ').join('');
 tx1 = tx1.toUpperCase(tx1);
 tx2 = tx2.split(' ').join('');
 tx2 = tx2.toUpperCase(tx1);
 if (tx1==tx2) {
  return true;
 } else {
  alert(msg);
  el1.focus();
  return false;
 }
}

function ECSPYEN1_validate () {
 if (!selectnotnull(document.getElementById('vp_origen'),'Debe especificar origen')) return false;
 if (!selectnotnull(document.getElementById('vp_destino'),'Debe especificar destino')) return false;
 if (!verificafecha(document.getElementById('vp_fecha_ida'),'Debe ingresar una fecha de ida v\xe1lida')) return false;
 if (document.getElementById("vp_idayvuelta").checked) {
  if (!verificafecha(document.getElementById('vp_fecha_vuelta'), 'Debe ingresar una fecha de vuelta v\xe1lida')) return false;
 } else {
  document.getElementById('vp_fecha_vuelta').value="";
 }
 return true;
}

function ECSPYEN1_sendform () {
 frm = document.formSeleccionItinerario;
 if (ECSPYEN1_validate ()) {
  //if (confirm("Se va a enviar el formulario.\n\nEst\xe1 seguro que desea continuar?")) {
   frm.submit();
  //}
 }
}

function ECSPYEN1_fnonclick_ida() {
 frm = document.formSeleccionItinerario;
 frm.FECHAVTA.value = "";
 frm.FECHAVTA.disabled=true;
}

function ECSPYEN1_fnonclick_iyv() {
 frm = document.formSeleccionItinerario;
 frm.FECHAVTA.disabled=false;
}

var ECSPYET2_SEND = 0;

function ECSPYET2_onload() {
 var frm=document.formSeleccionHorario;
 for (var i=0;i<frm.length;i++) {
  element = frm.elements[i];
  str = element.name;
    if ((str=="ELIGE")&&(frm.elements[i].type=="radio")) {
	element.onclick = function () { ECSPYET2_onclick_radio(this.select())};
  }
 }
}

function ECSPYET2_onclick_radio () {
 if (ECSPYET2_SEND == 1) return;
 var img = document.getElementById("imagesubmit");
 var txt = img.src+"";
 txt = txt.replace('bt_continuar_gr','bt_continuar');
 img.src = txt;
 ECSPYET2_SEND = 1;
}

function ECSPYET2_sendform() {
 if (ECSPYET2_SEND == 1) {
  //if (confirm("Se va a enviar el formulario.\n\nEst\xe1 seguro que desea continuar?")) {
   document.formSeleccionHorario.submit();
  //}
 } else {
  alert('Debe seleccionar un horario.');
 }
}

function ECSPYET9_validate() {
 var t = '';
 frm = document.formDatosComprador;
 if (!selectnotnull(frm.TIPODOCLI,'Debe especificar el tipo de documento de identificaci\xf3n.')) return false;
 if (!inputnotnull(frm.DOCCLIENTE,'Debe especificar n\xfamero de documento de identidad.')) return false;
 if (!inputnotnull_u(frm.NOM1,'Debe ingresar nombre.')) return false;
 if (!inputnotnull_u(frm.APE1,'Debe ingresar apellido.')) return false;
 to_mayuscula(frm.APE2);
 if (!selectnotnull(frm.PAIS,'Debe especificar el pa\xeds.')) return false;
 if (!inputnotnull_u(frm.DOMIC,'Debe ingresar direcci\xf3n.')) return false;
 if (!inputnotdigitsorempty(frm.TELCOD11,'Debe ingresar c\xf3digo de pa\xeds v\xedlido.')) return false;
 if (!inputnotdigits(frm.TELCOL12,'Debe ingresar c\xf3digo de \xe1rea.')) return false;
 if (!inputnotdigits(frm.TELCOL13,'Debe ingresar n\xfamero de tel\xe9fono v\xe1lido.')) return false;
 if (!inputnotdigitsorempty(frm.TELCOD21,'Debe ingresar c\xf3digo de pa\xeds v\xe1lido.')) return false;
 if (!inputnotdigitsorempty(frm.TELCOL22,'Debe ingresar c\xf3digo de \xe1rea.')) return false;
 if (!inputnotdigitsorempty(frm.TELCOL23,'Debe ingresar n\xfamero de tel\xe9fono.')) return false;
 if (!inputnotdigitsorempty(frm.TELCOD31,'Debe ingresar c\xf3digo de pa\xeds v\xe1lido.')) return false;
 if (!inputnotdigitsorempty(frm.TELCOL32,'Debe ingresar c\xf3digo de \xe1rea.')) return false;
 if (!inputnotdigitsorempty(frm.TELCOL33,'Debe ingresar n\xfamero de tel\xe9fono.')) return false;
 if (!inputisvalidemail(frm.EMAIL,'Debe ingresar direcci\xf3n de email v\xe1lida.')) return false;
 if (!inputnotnull(frm.EMAIL2,'Debe ingresar nuevamente la direcci\xf3n de email.')) return false;
 if (!checkifequal(frm.EMAIL,frm.EMAIL2,'Las direcciones de email ingresadas no coinciden.')) return false;
 return true;
}

function ECSPYET9_sendform() {
 frm = document.formDatosComprador;
 if (ECSPYET9_validate()) {
  //if (confirm("Se va a enviar el formulario.\n\nEst\xe1 seguro que desea continuar?")) {
   frm.submit();
  //}
 }
}

var rchk=0;
var schk=0;
var veces=0;
function ECSPYET17_validate() {
 var frm=document.formDatosPasajeros;
 if(window.manifestNDocs) {
   if (!manifestNDocs()) return false;
} 
 for (var i=0;i<frm.length;i++) {
  element = frm.elements[i];
  str = element.name;
  if ((str.indexOf("TIDOC")==0)&&(frm.elements[i].type=="select-one")) {
   if (!selectnotnull(element,'Debe especificar el tipo de documento de identificaci\xf3n.')) return false;
  };
  if ((str.indexOf("DOCCL")==0)&&(frm.elements[i].type=="text")) {
   if (!inputnotnull(element,'Debe especificar n\xfamero de documento de identidad.')) return false;
  };
  if ((str.indexOf("NOM")==0)&&(frm.elements[i].type=="text")) {
   if (!inputnotnull_u(element,'Debe ingresar nombre.')) return false;
  }
  if ((str.indexOf("APEAA")==0)&&(frm.elements[i].type=="text")) {
   if (!inputnotnull_u(element,'Debe ingresar apellido.')) return false;
  }
  if ((str.indexOf("TELCA")==0)&&(frm.elements[i].type=="text")) {
   if (!inputnotdigitsorempty(element,'Debe ingresar c\xf3digo pa\xeds.')) return false;
  }
  if ((str.indexOf("TELCB")==0)&&(frm.elements[i].type=="text")) {
   if (!inputnotdigits(element,'Debe ingresar c\xf3digo de \xe1rea.')) return false;
  }
  if ((str.indexOf("TELCC")==0)&&(frm.elements[i].type=="text")) {
   if (!inputnotdigits(element,'Debe ingresar n\xfamero de tel\xe9fono.')) return false;
  }
  if ((str.indexOf("SEXO")==0)&&(frm.elements[i].type=="radio")) {
	rchk=rchk + 1;
	if (element.checked) {
		schk=schk + 1;
	} 
  }
  if ((str.indexOf("PAIS")==0)&&(frm.elements[i].type=="select-one")) {
	if (!selectnotnull(element,'Debe especificar el pa\xeds.')) return false;
  }
  if ((str.indexOf("OCUPA")==0)&&(frm.elements[i].type=="text")) {
   if (!inputnotnull_u(element,'Ingrese ocupaci\xf3n.')) return false;
  }
 }
 //if ((rchk==1)&&(schk==0)) {
 if (veces==0) veces=rchk / 2;
 if ((veces>0) && (veces!=schk)) {
	alert('Debe indicar sexo.');
	schk=0;
	return false;
 }
 return true;
}

function ECSPYET17_sendform() {
 frm = document.formDatosPasajeros;
 if (ECSPYET17_validate()) {
  //if (confirm("Se va a enviar el formulario.\n\nEst\xe1 seguro que desea continuar?")) {
   frm.submit();
  }
 else {
  rchk=0;
  schk=0;
  veces=0;
 }
}

