function showhide( bahrid ) {
	if ( document.getElementById(bahrid).style.display == "none" ) {
		document.getElementById(bahrid).style.display = "";
	} else {
		document.getElementById(bahrid).style.display = "none";
	}
}

function bahr_show( bahrid ) {
	document.getElementById(bahrid).style.display = "";
}

function bahr_hide( bahrid ) {
	document.getElementById(bahrid).style.display = "none";
}



function PopUpWindow(sURL,iAncho,iAlto,sScrollbars,sResize,sToolbar,sDirectories,sMenuBar,sStatus,sVentana,sLocation){
	if (!sURL) sURL = 'http://www.bahomerental.com';
	if (!iAncho) iAncho = 500
	if (!iAlto) iAlto = 400
	if (!sScrollbars) sScrollbars = 'no'
	if (!sResize) sResize = 'yes'
	if (!sToolbar) sToolbar = 'no'
	if (!sDirectories) sDirectories = 'no'
	if (!sMenuBar) sMenuBar = 'no'
	if (!sStatus) sStatus = 'no'
	if (!sVentana) sVentana = 'no'
	if (!sLocation) sLocation = 'no'
	window.open(sURL,sVentana,'width=' + iAncho + ',height=' + iAlto + ',toolbar=' + sToolbar + ',directories=' + sDirectories + ',menubar=' + sMenuBar + ',status=' + sStatus + ',scrollbars=' + sScrollbars + ',resizable=' + sResize + ',left='+ ((screen.width/2)-(iAncho/2)) +',top='+ ((screen.height/2)-(iAlto/2)) +',location=' + sLocation + '');
}


function emailCheck (emailStr) {
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var firstChars=validChars
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom="(" + firstChars + validChars + "*" + ")"
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		alert("Dirección de email inválida !!")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	if (user.match(userPat)==null) {
	    alert("Dirección de email inválida !!")
	    return false
	}
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		  for (var i=1;i<=4;i++) {
		    if (IPArray[i]>255) {
		        alert("Dirección de email inválida !!")
			return false
		    }
	    }
	    return true
	}

	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert("Dirección de email inválida !!")
	    return false
	}
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
	    domArr[domArr.length-1].length>3) {
	   alert("Dirección de email inválida !!")
	   return false
	}

	if (domArr[domArr.length-1].length==3 && len<2) {
	   var errStr="Dirección de email inválida !!"
	   alert(errStr)
	   return false
	}

	return true;
}



function trim(arg) {
	var trimvalue = "";
	arglen = arg.length;
	if (arglen < 1) return trimvalue;
	i = 0;
	pos = -1;
	while (i < arglen) 
	{
		if (arg.charCodeAt(i) != 32 && !isNaN(arg.charCodeAt(i))) {
			pos = i;
			break;
		}
		i++;
	}
	var lastpos = -1;
	i = arglen;
	while (i >= 0)
	{
		if (arg.charCodeAt(i) != 32 && !isNaN(arg.charCodeAt(i))) 
		{
			lastpos = i;
			break;
		}
		i--;
	}
	trimvalue = arg.substring(pos,lastpos + 1);
	return trimvalue;
}



function ltrim(arg) 
{
	var trimvalue = "";
	arglen = arg.length;
	if (arglen < 1) return trimvalue;
	i = 0;
	pos = -1;
	while (i < arglen) 
	{
		if (arg.charCodeAt(i) != 32 && !isNaN(arg.charCodeAt(i))) 
		{
			pos = i;
			break;
		}
		i++;
	}
	trimvalue = arg.substring(pos,arglen-1);
	return trimvalue;
}


function rtrim(arg) {
	var trimvalue = "";
	arglen = arg.length;
	if (arglen < 1) return trimvalue;
	var lastpos = -1;
	i = arglen;
	while (i >= 0) 
	{
		if (arg.charCodeAt(i) != 32 && !isNaN(arg.charCodeAt(i))) 
		{
			lastpos = i;
			break;
		}
		i--;
	}
	trimvalue = arg.substring(0,lastpos+1);
	return trimvalue;
}



function ComprobarValor(Valor, Caracteres, Objeto)
{
	if(Valor != "" && Valor.length < Caracteres)
	{
		alert("El Campo " + Objeto.name + " deben tener al menos " + Caracteres + " caracteres")
		Objeto.focus()
		return false
	}
	return true
}


function SoloNumerico(e)
{	
	if ((event.keyCode < 48) || (event.keyCode > 57))
		event.keyCode = 0;
}


function isValidDate(dateStr,nomFecha) {
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
	var matchArray = dateStr.match(datePat);
	if (!nomFecha) 
		nomFecha = '' 
	else 
		nomFecha = ' ' + nomFecha
	if (matchArray == null) {
		alert('El campo ' + nomFecha + ' no es un formato de fecha valido.\nThe field ' + nomFecha + ' no is a date format.')
		return false;
	}
	day = matchArray[1];
	month = matchArray[3];
	year = matchArray[4];	
	if (month < 1 || month > 12) {
		alert("El mes debe ser entre 1 y 12\nThe month must be between 1 and 12");
		return false;
	}
	if (day < 1 || day > 31) {
		alert("El dia debe ser entre 1 y 31");
		return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		alert("El mes "+month+" no tiene 31 días!\nThe month "+month+" no have 31 days !")
		return false
	}
	if (month == 2) {
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) {
			alert("Febrero del año " + year + " no tiene " + day + " días !\nFebrary at " + year + " no have " + day + " days !");
			return false;
		}
	}
	if ((year < 1900) || (year > 2078))
	{
		alert("El año debe ser entre 1900 y 2078\nYear must be between 1900 and 2078");
		return false;		
	}
	return true;
}

