// JavaScript Document
<!--// Validar las contadores
function validar_formulario(theForm, tipo, miembro){
	if(miembro == false){
		if(theForm.nombre.value == ""){
			alert('Deberá ingresar su nombre completo');
			theForm.nombre.focus();
			return false;
		}
		if(theForm.telefono.value == ""){
			alert('Deberá ingresar su número de telefono');
			theForm.telefono.focus();
			return false;
		}
		if(theForm.email.value == ""){
			alert('Deberá ingresar su correo electrónico');
			theForm.email.focus();
			return false;
		}
	}
	if(tipo ==1){
		if(theForm.habitaciones.value == "-1"){
			alert('Seleccione el número de habitaciones');
			theForm.habitaciones.focus();
			return false;
		}
		if(theForm.adultos.value == "-1"){
			alert('Seleccione el número de adultos');
			theForm.adultos.focus();
			return false;
		}
		if(confirm('¿Confirmar que los datos son correctos antes de enviar?')){
			submitform(theForm,URL_BASE+'design/enviar_form_hotel.php','process_ajax');
		}
	}return false;
}
//Validando fecha
function checkdate(input){
var validformat=/^\d{4}-\d{2}-\d{2}$/ //Basic check for format validity
var returnval=false
if (!validformat.test(input.value))
alert("Recuerde el formato debe ser AAAA-MM-DD. Porfavor corrija.")
else{ //Detailed check for valid date ranges
var monthfield=input.value.split("-")[1]
var dayfield=input.value.split("-")[2]
var yearfield=input.value.split("-")[0]
var dayobj = new Date(yearfield, monthfield-1, dayfield)
if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
alert("Fecha invalida. Por favor corrija.")
else
returnval=true
}
if (returnval==false) input.select()
return returnval
}
function retorno(){
	return false;	
}
function textCounter(field,maxlimit ) {
  if ( field.value.length > maxlimit )
  {
    field.value = field.value.substring( 0, maxlimit );
	mayornumber = maxlimit + 1;
    alert( 'Usted puede Ingresar unicamente ' + mayornumber + ' Caracteres');
    return false;
  }
 
}
c= function (tag) { // Crea un elemento
   return document.createElement(tag);
}
d = function (id) { // Retorna un elemento en base al id
   return document.getElementById(id);
}
e = function (evt) { // Retorna el evento
   return (!evt) ? event : evt;
}
f = function (evt) { // Retorna el objeto que genera el evento
   return evt.srcElement ?  evt.srcElement : evt.target;
}

<!--// Validar Email
function  ValidarEmail(item)
{
    var checkOK = "0123456789-.@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
    var checkStr = item.value;
    var allValid = true;
    var decPoints = 0;
    var posarroba = 0;
    var cantarroba=0;
    var allNum = "";
	
	for (i = 0;  i < checkStr.length;  i++)
	{
    	ch = checkStr.charAt(i);
    	for (j = 0;  j < checkOK.length;  j++)
      		if (ch == checkOK.charAt(j))
        	break;
    	if (j == checkOK.length)
    	{
      		allValid = false;
      		break;
		}
		if(ch == "@"){
		   allNum += "@";
		   posarroba = i;
		   cantarroba ++;
		}
		else if(ch == ".")
		{
			allNum += ".";
			decPoints++;
        }		
		else
		{
			allNum += ch;
		}
	}
	if(cantarroba > 1){
		allValid = false;
	}
	if(cantarroba <1){
		allValid = false;
	}
		
	if(posarroba == 0){
	    allValid = false;
	}
	if(decPoints < 1){
		allValid = false;
	}
	return (allValid);
}
function allSelect()
{
List = document.forms[0].elements["destinatarios[]"];
if (List.length && List.options[0].value == 'temp') return;
for (i=0;i<List.length;i++)
{
List.options[i].selected = true;
}
}
function poptastic(url, name)
{
    name=window.open(url, name,'height=700,width=760');
	if (window.focus) {name.focus()}
}
function validateRefer(theForm) {
	if (theForm.name.value == "") {
		alert("Ingrese su nombre");
		theForm.name.focus();
		return false;
	}
	if (theForm.email.value == "") {
         alert("Ingrese el correo electronico");
		 theForm.email.focus();
		 return (false);
    }
	if(!ValidarEmail(theForm.email)) {
    	alert("Correo Electronico Invalido");
		theForm.email.focus();
		return(false);
    }
	if ((theForm.message.value == "") || (theForm.message.value == "Escribe tu mensaje:")) {
		alert("Ingrese su mensaje");
		theForm.message.focus();
		return (false);
	}
	answer = confirm("Por favor revise la informacion antes de Continuar. Si esta seguro presione OK!! ");
	if (answer!=0){
		submitform(document.getElementById('sendfriend'),'includes/sendrefer.php','form');
		return false;
	}
	else
		return false;
}
var url = "http://www.bonergemejia.com/"; 
var title = "Bonerge Mejia, Tu Decano Amigo"; 

function addToFavorites() { 
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
}
function poptastic(url)
{
	newwindow=window.open(url, 'name','height=600,width=660,scrollbars=1');
	if (window.focus) {newwindow.focus()}
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function popcopy(url)
{
    newwindow=window.open(url, 'name','height=600,width=700,scrollbars=1');
	if (window.focus) {newwindow.focus()}
}
function poppromo(url)
{
    newwindow=window.open(url, 'name','height=500,width=500, scrollbars=yes');
	if (window.focus) {newwindow.focus()}
}
function cerrarPopup(pid)
   {
      document.getElementById(pid).style.visibility = 'hidden';
	  document.getElementById(pid).style.height = '0px';  
   }
