// JavaScript Document
function toggleChecked(oElement) 
{ 
  oForm = oElement.form; 
  oElement = oForm.elements[oElement.name]; 
  if(oElement.length) 
  { 
    bChecked = oElement[0].checked; 
    for(i = 1; i < oElement.length; i++) 
      oElement[i].checked = bChecked; 
  } 
}
function toggleIndeterminate(oElement) 
{ 
  oForm = oElement.form; 
  oElement = oForm.elements[oElement.name]; 
  if(oElement.length) 
  { 
    bIndeterminate = false; 
    bChecked = true; 
    nChecked = 0; 
    for(i = 1; i < oElement.length; i++) 
      if(oElement[i].checked) 
        nChecked++; 
    if(nChecked < oElement.length - 1) 
    { 
      if(nChecked) 
        bIndeterminate = true; 
      else 
      { 
        bIndeterminate = false; 
        bChecked = false; 
      } 
    } 
    else 
    { 
      bIndeterminate = false; 
    } 
    oElement[0].indeterminate = bIndeterminate; 
    oElement[0].checked = bChecked; 
  } 
}
function isEmailAddr(email)
{
  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}
function validRequired(formField,fieldLabel)
{
	var result = true;
	
	if (formField.value == "")
	{
		alert('Por favor ingrese un valor valido para "' + fieldLabel +'".');
		formField.focus();
		result = false;
	}
	
	return result;
}
function allDigits(str)
{
	return inValidCharSet(str,"0123456789.");
}
function inValidCharSet(str,charset)
{
	var result = true;
	
	for (var i=0;i<str.length;i++)
		if (charset.indexOf(str.substr(i,1))<0)
		{
			result = false;
			break;
		}
	
	return result;
}
function validEmail(formField,fieldLabel,required)
{
	var result = true;
	
	if (required && !validRequired(formField,fieldLabel))
		result = false;
	if (result && ((formField.value.length < 3) || !isEmailAddr(formField.value)) )
	{
		alert("Please enter a valid email with the following format : yourname@yourdomain.com");
		formField.focus();
		result = false;
	}
  	return result;
}
function validNum(formField,fieldLabel,required)
{
	var result = true;

	if (required && !validRequired(formField,fieldLabel))
		result = false;
  
 	if (result)
 	{
 		if (!allDigits(formField.value))
 		{
 			alert('Please enter a valid value for the "' + fieldLabel +'" field.');
			formField.focus();		
			result = false;
		}
	} 
	
	return result;
}
function validRadio(oRadGrp)
{
     var myindex=-1;
	 if(oRadGrp.length==undefined)
	 {
	 	if(oRadGrp.checked){myindex=1};
	 }else{
		 for (var i=0;i<oRadGrp.length;i++){
			if(oRadGrp[i].checked)
			{
				myindex=i;
				break;
			}
		}
	}
    return myindex;
}	
function validInt(formField,fieldLabel,required)
{
	var result = true;

	if (required && !validRequired(formField,fieldLabel))
		result = false;
  
 	if (result)
 	{
 		var num = parseInt(formField.value,10);
 		if (isNaN(num))
 		{
 			alert('Por favor ingrese un valor valido para "' + fieldLabel +'".');
			formField.focus();		
			result = false;
		}
	} 
	
	return result;
}
function validatelogin(theForm)
{
	if (!validEmail(theForm.username,"Correo electronico",true))
		return false;

	if (!validRequired(theForm.password,"Clave"))
		return false;
}
function validatebuscar(op,forma)
{	
	var theForm = window.document.forms(forma);
	
	if (op == 0)
	{
		if (!validInt(theForm.dia,"Día",true)) return false;
		if (!validInt(theForm.mes,"Mes",true)) return false;
		if (!validInt(theForm.ano,"Año",true)) return false;
		if (!validateDate(theForm.mes.value+'/'+theForm.dia.value+'/'+theForm.ano.value,'U','F'))
		{
			alert('Debe proporcionar una fecha futura');
			return false;
		}
		if (!validInt(theForm.noches,"Noches",true)) return false;
		if (!validInt(theForm.personas,"Personas",true)) return false;
	}else if (op == 1)
	{
		if (!validRequired(theForm.nombre,"Nombre del hotel",true))
		return false;		
	}else if (op == 2)
	{
		if (!validRequired(theForm.ciudad,"Ciudad donde se encuentra el hotel",true))
		return false;
	}else if (op == 3)
	{
		if (!validRequired(theForm.estado,"Estado donde se encuentra el hotel",true))
		return false;		
	}
	
	theForm.tipo.value=op;
//	alert(theForm.tipo.value);
	theForm.submit();
}
var murl=""
function handleHttpResponse() {
  if (http.readyState == 4) {
    // Split the comma delimited response into an array
    //results = http.responseText.split(",");
	//document.getElementById("mensaje").innerHTML='<h2>'+http.responseText+'</h2>';
	//setTimeout("enviarpregunta(\"include/details.php\")",2000);
    //document.getElementById('city').value = results[0];
//    document.getElementById('ninos').value = 9;	
document.getElementById('form1').action = murl;	
//	document.getElementById('id').value = 2;	
//	https://eps.banorte.com/recibo
document.getElementById('form1').submit();
  }
}
function handleHttpResponsecampos() {
  if (http.readyState == 4) {
    // Split the comma delimited response into an array
    //results = http.responseText.split(",");
	//document.getElementById("mensaje").innerHTML='<h2>'+http.responseText+'</h2>';
	//setTimeout("enviarpregunta(\"include/details.php\")",2000);
    //document.getElementById('city').value = results[0];
//    document.getElementById('ninos').value = 9;	
document.getElementById('form1').action = murl;	
//	document.getElementById('id').value = 2;	
//	https://eps.banorte.com/recibo
document.getElementById('form1').submit();
  }
}
function handleHttpResponsetotales() {
  if (http.readyState == 4) {
    // Split the comma delimited response into an array
    //results = http.responseText.split(",");
//	document.getElementById("mensaje").innerHTML='<h2>'+http.responseText+'</h2>';
	//setTimeout("enviarpregunta(\"include/details.php\")",2000);
//    document.getElementById('t_iva').value = 150;
//    document.getElementById('ninos').value = 9;	
//document.getElementById('form1').action = murl;	
//	document.getElementById('id').value = 2;	
//	https://eps.banorte.com/recibo
//document.getElementById('form1').submit();
  }
}

function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}
var http = getHTTPObject(); // We create the HTTP Object
function validatelistar(op,forma,url,opc)
{
	var theForm = window.document.forms(forma);
	if (op == 0)
	{
		if (!validInt(theForm.dia,"Día",true)) return false;
		if (!validInt(theForm.mes,"Mes",true)) return false;
		if (!validInt(theForm.ano,"Año",true)) return false;
	if (!validateDate(theForm.mes.value+'/'+theForm.dia.value+'/'+theForm.ano.value,'U','F'))
		{
			alert('Debe proporcionar una fecha futura');
			return false;
		}
		if (!validInt(theForm.noches,"Noches",true)) return false;
		if (!validInt(theForm.personas,"Personas",true)) return false;
	}

if (opc==0)
{
  d2='&mes='+theForm.mes.value+'&dia='+theForm.dia.value+'&ano='+theForm.ano.value+'&personas='+theForm.personas.value+'&noches='+theForm.noches.value;
	murl=url+d2;

	http.open("GET",murl, true);
	http.onreadystatechange = handleHttpResponse;
	http.send(null);
//https://eps.banorte.com/recibo
	//theForm.tipo.value=op;
//	alert(theForm.tipo.value);
	//theForm.submit('prueba.php?id=1');
//	http.open("GET", 'reserv.php' + '?id='+escape(tidValue)+'&resp_id='+ridValue+'&preg_id='+pidValue+'&user_id='+uidValue, true);
}
else
{
	//theForm.action="https://eps.banorte.com/recibo";
/*	murl=url;
	http.open("GET",murl, true);
	http.onreadystatechange = handleHttpResponse;
	http.send(null);*/
	theForm.submit();
}

	
}



function validatecampos(op,forma,url)
{
	var theForm = window.document.forms(forma);
	d2='&mes='+theForm.mes.value+'&dia='+theForm.dia.value+'&ano='+theForm.ano.value+'&personas='+theForm.personas.value+'&noches='+theForm.noches.value;
	murl=url+d2;
	
	http.open("GET",murl, true);
	http.onreadystatechange = handleHttpResponsecampos;
	http.send(null);
}

function validatetotales(op,forma,url,oElement)
{
	var theForm = window.document.forms(forma);

	oForm = oElement.form; 
	

    oElement = oForm.elements[oElement.name]; 

var sumas=0;
 var sumastotal=0;
 var stotal=0;
 var s=0;
var mtotal;
var regcountjs=0;
var seleccion;
  if(oElement.length) 
  { 
//    bChecked = oElement[0].checked; 
 
    for(i = 1; i < oElement.length; i++)
	{
		seleccion='seleccion'+i;
		if(oElement[i].checked)
		 {
			 	miva='iva'+i;
				mtotal='total'+i;

				s=theForm[miva].value
				stotal=theForm[mtotal].value				
			sumastotal=sumastotal +(stotal*1);
			sumas= sumas + (s*1);
			regcountjs=regcountjs+1;
			theForm[seleccion].value="s";
		 }
		 else
		 {
			 theForm[seleccion].value="n";
		 }
	}
//      oElement[i].checked = bChecked; 
  } 
theForm.t_iva.value=sumas;
theForm.t_total.value=sumastotal;
theForm.t_ttotal.value=sumas+sumastotal;
theForm.regcount.value=regcountjs;
theForm.AltTax.value=sumas;
theForm.SubTotal.value=sumastotal;
theForm.Total.value=sumas+sumastotal;

}

function toggleChecked2(oElement,forma) 
{ 
  oForm = oElement.form; 
  oElement = oForm.elements[oElement.name]; 
	var theForm = window.document.forms(forma);
var sumas=0;
 var sumastotal=0;
 var stotal=0;
 var s=0;
var mtotal=0;
var regcountjs=0;


  if(oElement.length) 
  { 
    bChecked = oElement[0].checked; 
    for(i = 1; i < oElement.length; i++) 
	{
      oElement[i].checked = bChecked; 
	  if(bChecked)
	  {
		  miva='iva'+i;
				mtotal='total'+i;
				s=theForm[miva].value
				stotal=theForm[mtotal].value				
			sumastotal=sumastotal +(stotal*1);
			sumas= sumas + (s*1);
			regcountjs=regcountjs+1;
	  }
	}

  } 

theForm.t_iva.value=sumas;
theForm.t_total.value=sumastotal;
theForm.t_ttotal.value=sumas+sumastotal;
theForm.regcount.value=regcountjs;
theForm.AltTax.value=sumas;
theForm.SubTotal.value=sumastotal;
theForm.Total.value=sumas+sumastotal;

}

function pressvalidatebuscar(op,forma){
	// envoltura para funcionalidad con enter de búsquedas	
	if (window.event && window.event.keyCode == 13 ){
		window.event.keyCode = 0;
		return validatebuscar(op,forma);
		//alert(window.event.srcElement.name);
	}
	else{
		return window.event.keyCode;
	}
}
function selhotelcateg(op,forma)
{	
	/* selección de una de las familias del hotel
		se pone valor al campo hotelcateg y se
		realiza de nuevo la búsqueda */
	
	var theForm = window.document.forms(forma);
	theForm.hotelcateg.value = op;
	
	if(theForm.tipo.value==""){
		opfiltro=0;
		if(theForm.nombre.value != ""){ opfiltro=1; }
		else if(theForm.ciudad.value != ""){ opfiltro=2; }
		else if(theForm.estado.value != ""){ opfiltro=3; }
		theForm.tipo.value=opfiltro;
	}	
	/*// limpia filtros no usados
	theForm.nombre.value = "";
	theForm.ciudad.value = "";
	theForm.estado.value = "";
	*/		
	theForm.submit();
}
function detallehotel(id){
	var theForm = window.document.forms("forma_buscar_fechas");
	theForm.hotelid.value = id;		
	//alert("muestra detalle-->" +  id);
	theForm.action = "detalle.php";
	theForm.submit();
	return true;
}
