function emailCheck (emailStr) {
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=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("Direccion Email parece incorrecta (verifique la @ y .'s)");
	return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	for (i=0; i<user.length; i++) {
	if (user.charCodeAt(i)>127) {
	alert("El nombre de usuario en el Email contiene caracteres invalidos.");
	return false;
	   }
	}
	for (i=0; i<domain.length; i++) {
	if (domain.charCodeAt(i)>127) {
	alert("El nombre de dominio en el Email contiene caracteres invalidos.");
	return false;
	   }
	}
	if (user.match(userPat)==null) {
	alert("El nombre del usuario no es valido.");
	return false;
	}
	
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
	for (var i=1;i<=4;i++) {
	if (IPArray[i]>255) {
	alert("La IP destino es invalida!");
	return false;
	   }
	}
	return true;
	}
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
	if (domArr[i].search(atomPat)==-1) {
	alert("El nombre de dominio no es valido.");
	return false;
	   }
	}
	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].search(knownDomsPat)==-1) {
	alert("La direccion de Email debe terminar en un dominio conocido o las dos letras del pais");
	return false;
	}
	if (len<2) {
	alert("A la direccion de Email le falta el nombre del host.");
	return false;
	}
	return true;
}

function doOutlineOnly(targetId) {
  var targetElement;
  targetElement = document.getElementById(targetId);
     if (targetElement.style.display == "none") {
        targetElement.style.display = "";
     } else {
        targetElement.style.display = "none";
	}
}

function doOutlineOnlyMarcas(targetId, text) {
  var targetElement;
  var texto;
  targetElement = document.getElementById(targetId);
  texto = document.getElementById(text);
     if (targetElement.style.display == "none") {
        targetElement.style.display = "";
		texto.innerHTML= "<< Marcas Destacadas";
     } else {
        targetElement.style.display = "none";
		texto.innerHTML= ">> M&aacute;s marcas";
	}
}

function doOutlineOnlyFiltros(targetId, text) {
  var targetElement;
  var texto;
  targetElement = document.getElementById(targetId);
  texto = document.getElementById(text);
     if (targetElement.style.display == "none") {
        targetElement.style.display = "";
		texto.innerHTML= "Ocultar las marcas";
     } else {
        targetElement.style.display = "none";
		texto.innerHTML= "Todas las marcas";
	}
}

//FUNCIONES AJAX SANTIAGO ALVAREZ (28-Sep-2009)
//CREACION DE OBJETO DE SERVIDOR VIRTUAL PARA AJAX
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
		{
			// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
		}
	catch (e)
		{
			// Internet Explorer
			try
				{
					xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			    }
			catch (e)
				{
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
		  }
	return xmlHttp;
}


function VerificaMail(str)
{
	if (str.length==0)
		{
			document.getElementById("txtMail").innerHTML="";
			return;
		}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
		{
			//alert ("Your browser does not support AJAX!");
			alert ("El Navegador no puede presentar la informaci\xf3n");
			return;
		}
	var url="funciones/verificaMail.asp";
	url=url+"?q="+str;
	xmlHttp.onreadystatechange=function(){ 
		if (xmlHttp.readyState==1)
			{
				document.getElementById("txtMail").innerHTML='...';
			}
		if (xmlHttp.readyState==4)
			{
				document.getElementById("txtMail").innerHTML=xmlHttp.responseText;
			}
	}
	xmlHttp.open("POST",url,true);
	xmlHttp.send(url);
}

function insertaUsuario(forma)
{
	var dia;
	var mes;
	var anio;
	var genero;
	dia = forma.dia.options[forma.dia.selectedIndex].value;
	mes = forma.mes.options[forma.mes.selectedIndex].value;
	anio = forma.ano.options[forma.ano.selectedIndex].value;
	genero = forma.genero.options[forma.genero.selectedIndex].value;
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
		{
			//alert ("Your browser does not support AJAX!");
			alert ("El Navegador no puede presentar la informaci\xf3n");
			return;
		}
	var url="funciones/insertaUsuarioMiniRegistro.asp";
	url=url+"?nombre="+forma.nombre.value+"&apellido="+forma.apellido.value+"&email="+forma.email.value+"&pass="+forma.pass.value+"&ano="+anio+"&mes="+mes+"&dia="+dia+"&genero="+genero;
	xmlHttp.onreadystatechange=function(){ 
		if (xmlHttp.readyState==1)
			{
				document.getElementById("procesando").style.display="";
				document.getElementById("formMiniRegistro").style.display="none";
				document.getElementById("respuesta").innerHTML='Registrando ...';
			}
		if (xmlHttp.readyState==4)
			{
				document.getElementById("respuesta").innerHTML=xmlHttp.responseText;
			}
	}
	xmlHttp.open("POST",url,true);
	xmlHttp.send(url);
	document.getElementById("procesando").style.display="none";
	document.getElementById("respuesta").style.display="";
	document.getElementById("titulo2").style.display="none";
	document.getElementById("titulo1").innerHTML="<strong>&iexcl;FELICITACIONES!</strong>";
}

function validaUserFormMini(form1){
	var msg = "";
	if(form1.nombre.value ==""){
		msg += "Debe Completar el campo Nombre\n";
	}
	if(form1.apellido.value ==""){
		msg += "Debe Completar el campo Apellido\n";
	}
	var correovalido = emailCheck (form1.email.value);
	if ((form1.email.value == null) || (form1.email.value == "") || (correovalido==false)) {
		msg += "Correo electr\xf3nico es obligatorio\n";
	}
	if(form1.ano.value == 0){
		msg +="Debe elegir un A\xf1o\n";
	}
	if(form1.mes.value == 0){
		msg +="Debe elegir un Mes\n";
	}
	if(form1.dia.value == 0){
		msg +="Debe elegir un D\xeda\n";
	}
	if(form1.genero.value == 0){
		msg +="Debe elegir un G\xe9nero\n";
	}
	if(form1.pass.value ==""){
		msg +="Debe Completar el campo Contrase\xf1a\n";
	}
	if (msg != "") {
		alert(msg);
	} else {
		//form1.submit();
		//document.getElementById("procesando").style.display="";
		insertaUsuario(form1);
	}
}

function solicitaCartel(auto,accion, actDireccion)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
		{
			alert ("El Navegador no puede presentar la informaci\xf3n");
			return;
		}
	var url="funciones/guardaSolicCartel.asp";
	url=url+'?accion='+accion+'&idv='+auto;
	xmlHttp.onreadystatechange=function(){ 
		if (xmlHttp.readyState==1)
			{
				document.getElementById("deseaCartel").style.display="none";
				document.getElementById("respuesta").innerHTML='Actualizando ...';
			}
		if (xmlHttp.readyState==4)
			{
				document.getElementById("respuesta").innerHTML=xmlHttp.responseText;
			}
	}
	xmlHttp.open("POST",url,true);
	xmlHttp.send(url);
	document.getElementById("titulo2").style.display="none";
	if (actDireccion=='yes'){
		document.getElementById("direccion").style.display="";
	}
	if (accion=='yes'){
		if (actDireccion=='no'){
			document.getElementById("respuesta").style.display="";
		}
	}
	else{
		location.href="micuenta.asp";
	}
}

function actDirUser(forma)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
		{
			alert ("El Navegador no puede presentar la informaci\xf3n");
			return;
		}
	var url="funciones/actDirUser.asp";
	//url=url+"?dir="+forma.direccion.value+'&accion='+accion+'&actualizar='+forma.actionNow.value+'&idv='+forma.idVeh.value;
	url=url+"?dir="+forma.direccion.value;
	xmlHttp.onreadystatechange=function(){ 
		if (xmlHttp.readyState==1)
			{
				document.getElementById("deseaCartel").style.display="none";
				document.getElementById("respuesta").innerHTML='Actualizando ...';
			}
		if (xmlHttp.readyState==4)
			{
				document.getElementById("respuesta").innerHTML=xmlHttp.responseText;
			}
	}
	xmlHttp.open("POST",url,true);
	xmlHttp.send(url);
	document.getElementById("respuesta").style.display="";
	document.getElementById("titulo2").style.display="none";
	document.getElementById("direccion").style.display="none";
	//document.getElementById("titulo1").innerHTML="<strong>&iexcl;FELICITACIONES!</strong>";
	//location.href="micuenta.asp";
}

function validaacDirUser(form1, que){
	var msg = "";
	if(form1.direccion.value ==""){
		msg += "Por favor ingresa tu direcci\xf3n\n";
	}
	if (msg != "") {
		alert(msg);
	} else {
		actDirUser(form1,que);
	}
}


function validaUserForm(form1){
	var msg = "";
	if(form1.nombre.value ==""){
		msg += "Debe Completar el campo Nombre\n";
	}
	if(form1.apellido.value ==""){
		msg += "Debe Completar el campo Apellido\n";
	}
	var correovalido = emailCheck (form1.email.value);
	if ((form1.email.value == null) || (form1.email.value == "") || (correovalido==false)) {
		msg += "Correo electrónico es obligatorio\n";
	}
	if(form1.ano.value == 0){
		msg +="Debe elegir un A\xf1o\n";
	}
	if(form1.mes.value == 0){
		msg +="Debe elegir un Mes\n";
	}
	if(form1.dia.value == 0){
		msg +="Debe elegir un D\xeda\n";
	}
	if(form1.genero.value == 0){
		msg +="Debe elegir un G\xe9nero\n";
	}
	if(form1.pais.value == 0){
		msg +="Debe elegir un Pa\xeds\n";
	}
	if(form1.ciudad.value == 0){
		msg +="Debe elegir una Ciudad\n";
	}
	if(form1.direccion.value ==""){
		msg +="Debe Completar el campo Direcci\xf3n\n";
	}
	if(form1.telefono.value ==""){
		msg +="Debe Completar el campo Tel\xe9fono\n";
	}
	if(form1.telefono2.value ==""){
		msg +="Debe Completar el campo Celular\n";
	}
	if(form1.pass.value ==""){
		msg +="Debe Completar el campo Contrase\xf1a\n";
	}
	if(form1.confirmar.value != form1.pass.value){
		msg +="No se puede confirmar su contrase\xf1a\n";
	}
	if (msg != "") {
		alert(msg);
	} else {
		form1.submit();
	}
}

function validarFormularioEnvio(form1){
	var enviar = true;
	if(form1.nombre_contacto.value ==""){
		alert("Debe Completar el campo Nombre");
		form1.nombre_contacto.focus();
		enviar = false;
		return false;
	}
	var correovalido = emailCheck (form1.email.value);
	if ((form1.email.value == null) || (form1.email.value == "") || (correovalido==false)) {
		//alert("Debe completar el correo electrónico");
		enviar = false;
		form1.email.focus();
		return false;
	}
	if(form1.telefono.value ==""){
		alert("Debe Completar el campo Teléfono");
		form1.telefono.focus();
		enviar = false;
		return false;
	}
	if(form1.comentario.value ==""){
		alert("Debe Completar el campo Comentarios");
		form1.comentario.focus();
		enviar = false;
		return false;
	}
	if (enviar == true){
		//form1.submit;
		enviarContacto(form1);
	}
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}