function emailCheck (emailStr)
{
	/* Verificar si el email tiene el formato user@dominio. */
	var emailPat=/^(.+)@(.+)$/ 

	/* Verificar la existencia de caracteres. ( ) < > @ , ; : \ " . [ ] */
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]" 

	/* Verifica los caracteres que son válidos en una dirección de email */
	var validChars="\[^\\s" + specialChars + "\]" 

	var quotedUser="(\"[^\"]*\")" 

	/* Verifica si la dirección de email está representada con una dirección IP Válida */ 

	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/

	/* Verificar caracteres inválidos */ 

	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	//domain, as opposed to ipDomainPat, shown above. */
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

	var matchArray=emailStr.match(emailPat)
	if (matchArray==null)
	{
		alert("La dirección de Email debe tener tanto @ como .")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	
	// Si el user "user" es valido 
	if (user.match(userPat)==null)
	{
		// Si no
		alert("El nombre de usuario no es válido.")
		return false
	}
	
	/* Si la dirección IP es válida */
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null)
	{
		for (var i=1;i<=4;i++)
		{
			if (IPArray[i]>255)
			{
				alert("IP de destino inválida")
				return false
			}
		}
		return true
	}
	
	var domainArray=domain.match(domainPat)
	if (domainArray==null)
	{
		alert("El dominio parece no ser válido.")
		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("La dicrección debe tener 3 letras si es ."com" o 2 si en de algún pais.");
	return false
	}*/
	
	if (len<2)
	{
		var errStr="La dirección es erronea"
		alert(errStr)
		return false
	}
	
	// La dirección de email ingresada es Válida
	return true;
}

function nwindow(mypage,myname,w,h,scroll,pos)
{
  if (pos=="random")
  {
	LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
	TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
  }
  else if (pos=="center")
  {
	LeftPosition=(screen.width)?(screen.width-w)/2:100;
	TopPosition=(screen.height)?(screen.height-h)/2:100;
  }
  else
  {
	LeftPosition=0;
	TopPosition=20;
  }

  settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
  win=window.open(mypage,myname,settings);

  if(win.focus)
  {
	win.focus();
  }
}

function redimensionar (ancho, alto)
{
  LeftPosition=(screen.width)?(screen.width-ancho)/2:100;
  TopPosition=(screen.height)?(screen.height-alto)/2:100;

  window.moveTo(LeftPosition,TopPosition);
  window.resizeTo(ancho,alto);
  window.focus();
}

function redondear(value, precision)
{
  value = "" + value //convert value to string
  precision = parseInt(precision);

  var whole = "" + Math.round(value * Math.pow(10, precision));
  var decPoint = whole.length - precision;

  if(decPoint != 0)
  {
	result = whole.substring(0, decPoint);
	result += ".";
	result += whole.substring(decPoint, whole.length);
  }
  else
  {
	result = 0;
	result += ".";
	result += whole.substring(decPoint, whole.length);
  }
  return (result);
}

function detenerError()
{
	return true
}
window.onerror=detenerError


var rector=3
var stopit=0 
var a=1

function init(which)
{
	stopit=0
	shake=which
	shake.style.left=0
	shake.style.top=0
}

function rattleimage()
{
	if ((!document.all&&!document.getElementById)||stopit==1)
		return
	if (a==1)
	{
		shake.style.top=parseInt(shake.style.top)+rector
	}
	else if (a==2)
	{
		shake.style.left=parseInt(shake.style.left)+rector
	}
	else if (a==3)
	{
		shake.style.top=parseInt(shake.style.top)-rector
	}
	else
	{
		shake.style.left=parseInt(shake.style.left)-rector
	}
	if (a<4)
		a++
	else
		a=1
	setTimeout("rattleimage()",50)
}

function stoprattle(which)
{
	stopit=1
	which.style.left=0
	which.style.top=0
}

function verifica_fechas(fechaa,fechab)//si fechaa es mayor que fechab devolverá true, sino false
{ 
	var fecha_uno=new Array;
	var fecha_dos=new Array;
	fecha_uno=fechaa.split('/');
	fecha_dos=fechab.split('/');
	if(fecha_uno[2]<fecha_dos[2]) return false;
	else if(fecha_uno[2]==fecha_dos[2]&&fecha_uno[1]<fecha_dos[1]) return false;
	else if(fecha_uno[2]==fecha_dos[2]&&fecha_uno[1]<=fecha_dos[1]&&fecha_uno[0]<fecha_dos[0]) return false;
	else return true;
	
} 

function quita_marco(Nflash,Tw,Th)
{
	//Nflash -> nombre del flash
	//Tw -> ancho del video
	//Th -> alto del video
	document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='"+Tw+"' height='"+Th+"'>");
	document.write("<param name='movie' value='"+Nflash+"'>");
	document.write("<param name='quality' value='high'>");
	document.write("<embed src='"+Nflash+"' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='"+Tw+"' height='"+Th+"''></embed>");
	document.write("</object>");
}

function marcar_select(valor, elemento)
{
	var obj = document.getElementById(elemento);
	for(var i=0; i<obj.options.length; i++)
	{
		if(obj.options[i].value == valor)
		{
			obj.options[i].selected = 1;
		}
		else
		{
			obj.options[i].selected = 0;
		}
	}
}

function marcar_select_multiple(valor, elemento)
{
	var obj = document.getElementById(elemento);
	var valores = valor.split("|");

	if (valor != '')
	{
		for(var j=0; j<valores.length; j++)
		{
			for(var i=0; i<obj.options.length; i++)
			{
				if(obj.options[i].value == valores[j])
				{
					obj.options[i].selected = 1;
				}
			}
		}
	}
	else
	{
		for(var i=0; i<obj.options.length; i++)
		{
			obj.options[i].selected = 0;
		}			
	}
}

function vercapa_correo(user_correo)
{
	xajax_cargar_userCorreo(user_correo);	
}

function cerrar_userCorreo ()
{
	document.getElementById("capa_userCorreo").style.display = "none";
	document.getElementById("capa_userCorreo").innerHTML = "";
}

function solicitud_userCorreo(user_id)
{
	xajax_enviar_form_userCorreo(user_id);
	document.getElementById("capa_userCorreo").innerHTML = '<table width="273" height="139" border="0" cellpadding="0" cellspacing="0" style="border:#990000 1px solid"><tr><td style="vertical-align:top"><table width="100%" height="26" border="0" cellpadding="0" cellspacing="0" style="background:#D60000"><tr><td width="12">&nbsp;</td><td class="txt_12" style="color:#FFFFFF"><? echo htmlentities($idioma["RECUPERAR CLAVE DE ACCESO"]); ?></td><td width="36"><a href="#" onclick="cerrar_userCorreo();"><img src="../../images/close.gif" width="36" height="26" border="0" /></a></td></tr></table><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td style="text-align:center; padding:45px 0px 0px 0px"><img src="../../administracion/images/cargando_peq.gif" /></td></tr></table></td></tr></table>';
}

function abrir_registro(valor)
{
	document.getElementById('div_registro').style.position = 'fixed';
	document.getElementById('div_registro').style.top = document.documentElement.clientHeight/2 - document.getElementById('div_registro').offsetHeight/2;
	
	document.getElementById("div_registro").style.display = "block";
	document.getElementById("fr_registro").src = "registro.php?valor="+valor;
}	

function cerrar_registro()
{
	document.getElementById("div_registro").style.display = "none";
	document.getElementById("fr_registro").src = "";
}

function abrir_anunciate()
{
	
	document.getElementById('div_anunciate').style.position = 'fixed';
	document.getElementById('div_anunciate').style.top = document.documentElement.clientHeight/2 - document.getElementById('div_anunciate').offsetHeight/2;
	
	document.getElementById("div_anunciate").style.display = "block";
	document.getElementById("fr_anunciate").src = "anunciate.php";
}	

function cerrar_anunciate()
{
	document.getElementById("div_anunciate").style.display = "none";
	document.getElementById("fr_anunciate").src = "";
}
