$(document).ready(function(){
  SexyLightbox.initialize({color:'white'});
});
function functionCargarHtml($x){
	if($x==1){
	  SexyLightbox.display('contenido/cate1.html?height=434&width=440');		
		}
	if($x==2){
	  SexyLightbox.display('contenido/cate2.html?height=434&width=440');		
		}
	if($x==3){
	  SexyLightbox.display('contenido/cate3.html?height=434&width=440');		
		}
	if($x==4){
	  SexyLightbox.display('contenido/cate4.html?height=434&width=440');		
		}
	  }
function eaAjax()
{ 
	var xmlhttp=false; 
	try 
	{ 
		// No IE
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
	}
	catch(e)
	{ 
		try
		{ 
			// IE 
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		catch(E) { xmlhttp=false; }
	}
	if (!xmlhttp && typeof XMLHttpRequest!="undefined") { xmlhttp=new XMLHttpRequest(); } 
	return xmlhttp; 
}
function limpiaForm(x)
{
	for(i=0; i<4; i++)
		{
			document.getElementById(x).elements[i].className="inputNormal";
		}
		document.getElementById('coment').className="inputNormal";
	
}
function trim(x){
	while(x.charAt(x.length-1)==" ") x=x.substr(0, x.length-1);
	while(x.charAt(0)==" ") x=x.substr(1, x.length-1);
	return x;
	}
function validaLongitud(valor, permiteVacio, minimo, maximo)
{
	var cantCar=valor.length;
	if(valor=="")
	{
		if(permiteVacio) return true;
		else return false;
	}
	else
	{
		if(cantCar>=minimo && cantCar<=maximo) return true;
		else return false;
	}
}
function campoError(campo)
{
	campo.className="inputError";
	error=1;
}
function eaIsEmail(str)
	{
	if (typeof(str)=='undefined')
	{
		return false;
	}
	var expr1 = /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/;
	if (!expr1.test(str)){
		return false;
	}
		return true;
	}
function validarMail(){
	limpiaForm("fsc");
	error=0;
	$empSC=trim(document.getElementById('empresaSC').value);
	$nameSC=trim(document.getElementById('nombreSC').value);
	$mailSC=trim(document.getElementById('mailSC').value);
	$fonoSC=trim(document.getElementById('fonoSC').value);
	$mens=trim(document.getElementById('coment').value);
	if(!validaLongitud($empSC,false,5,50)) campoError(document.getElementById('empresaSC'));
	if(!validaLongitud($nameSC,false,5,50)) campoError(document.getElementById('nombreSC'));
	if(!validaLongitud($mailSC,false,5,50)) campoError(document.getElementById('mailSC'));
	if(!validaLongitud($fonoSC,false,7,50)) campoError(document.getElementById('fonoSC'));
	if(!validaLongitud($mens,false,10,10000)) campoError(document.getElementById('coment'));
	if(!eaIsEmail($mailSC)) campoError(document.getElementById('mailSC'));
	if(error==1)
		{
			Sexy.error('<h1>Error al llenar los datos</h1><p>Int&eacute;ntalo de nuevo y ten en cuenta:<br><br>1.- Nombre debe tener mayor de 5 y menor 50 caracteres<br>2.- Debe escribir un mail v&aacute;lido.<br>3.- Debe al menos escribir un numero telef&oacute;nico.<br>4.- No puedes enviar un mail, sin mensaje.</p>');
		}
	else
		{			
			var ajax=eaAjax();
			ajax.open("POST","contenido/mailsend.php", true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.send("empresaC="+$empSC+"&nombreC="+$nameSC+"&mailC="+$mailSC+"&fonoC="+$fonoSC+"&contC="+$mens);
			
			ajax.onreadystatechange=function()
			{
				if (ajax.readyState==4)
				{
					var rpta=ajax.responseText;
					if(rpta=="OK")
					{
						Sexy.info('<h1>Envio Exitoso !!</h1><p>su solicitud ha sido enviado, pronto le daremos una respuesta.</P>');
						document.getElementById("fsc").reset();
					}
					else Sexy.alert('<h1>Error en el sistema</h1><p> Disculpe los inconvenientes, pronto solucionaremos el problema, si desea puede enviar un mensaje al administrador de la web.<br><br>el mail de la empresa es: cvera@gorasac.com</p>');
				}
			}
		}
	}
