/*****************FUNCION VALIDA_SOLICITUD_ANUNCIO*******************/
function valida_frm_solicita_anuncio()
{
	var e_su_nombre,e_apellidos,e_su_email,e_nombre_empresa,e_calle,e_colonia,e_cp,e_ciudad_municipio,e_categoria,e_subcategoria,e_url,e_descripcion,e_telefono_empresa,e_tipo_anuncio,e_capcha,e_num_ext;
	
	var su_nombre=document.frm_solicita_anuncio.su_nombre.value;
	var apaterno=document.frm_solicita_anuncio.apaterno.value;
	var amaterno=document.frm_solicita_anuncio.amaterno.value;
	var su_email=document.frm_solicita_anuncio.su_email.value;
	var empresa=document.frm_solicita_anuncio.empresa.value;
	var calle=document.frm_solicita_anuncio.calle.value;
	var colonia=document.frm_solicita_anuncio.colonia.value;
	var municipio=document.frm_solicita_anuncio.municipio.value;
	var cp=document.frm_solicita_anuncio.cp.value;
	var descripcion=document.frm_solicita_anuncio.descripcion.value;
	var lada_neg=document.frm_solicita_anuncio.lada_neg.value;
	var numero_neg=document.frm_solicita_anuncio.numero_neg.value;
	var captcha_code=document.frm_solicita_anuncio.captcha_code.value;
	var num_ext=document.frm_solicita_anuncio.num_ext.value;
	
	document.getElementById("e_su_nombre").innerHTML='&nbsp;';
	document.getElementById("e_apellidos").innerHTML='&nbsp;';
	document.getElementById("e_su_email").innerHTML='&nbsp;';
	document.getElementById("e_nombre_empresa").innerHTML='&nbsp;';
	document.getElementById("e_calle").innerHTML='&nbsp;';
	document.getElementById("e_colonia").innerHTML='&nbsp;';
	document.getElementById("e_cp").innerHTML='&nbsp;';
	document.getElementById("e_ciudad_municipio").innerHTML='&nbsp;';
	document.getElementById("e_categoria").innerHTML='&nbsp;';
	document.getElementById("e_subcategoria").innerHTML='&nbsp;';
	document.getElementById("e_url").innerHTML='&nbsp;';
	document.getElementById("e_descripcion").innerHTML='&nbsp;';
	document.getElementById("e_telefono_empresa").innerHTML='&nbsp;';
	document.getElementById("e_capcha").innerHTML='&nbsp;';
	document.getElementById("e_num_ext").innerHTML='&nbsp;';
	

	var categoria=document.frm_solicita_anuncio.categoria.value;
	var subcat1=document.frm_solicita_anuncio.subcat1.value;
	var subcat2=document.frm_solicita_anuncio.subcat2.value;
	var subcat3=document.frm_solicita_anuncio.subcat3.value;
	var subcat4=document.frm_solicita_anuncio.subcat4.value;
	var subcat5=document.frm_solicita_anuncio.subcat5.value;
	var subcat6=document.frm_solicita_anuncio.subcat6.value;
	var subcat7=document.frm_solicita_anuncio.subcat7.value;
	var subcat8=document.frm_solicita_anuncio.subcat8.value;
	var subcat9=document.frm_solicita_anuncio.subcat9.value;
	var subcat10=document.frm_solicita_anuncio.subcat10.value;
	var subcat11=document.frm_solicita_anuncio.subcat11.value;
	var subcat12=document.frm_solicita_anuncio.subcat12.value;
	var subcat13=document.frm_solicita_anuncio.subcat13.value;
	var subcat14=document.frm_solicita_anuncio.subcat14.value;
	var subcat15=document.frm_solicita_anuncio.subcat15.value;
	
	if(su_nombre.length>2)
	{
		e_su_nombre=false;
	}
	else
	{
		e_su_nombre=true;
		document.getElementById("e_su_nombre").innerHTML='El Nombre debe ser mayor a tres letras, favor de corregirlo';
	}
	
	if(apaterno.length==0 && amaterno.length==0)
	{
		e_apellidos=true;
		document.getElementById("e_apellidos").innerHTML='Favor de escribir al menos el Apellido Paterno';
	}
	else
	{
		if(apaterno.length==0 && amaterno.length>0)
		{
			e_apellidos=true;
		document.getElementById("e_apellidos").innerHTML='Favor de escribir el Apellido Paterno';
		}
		else
		{
			e_apellidos=false;
		}
	}
	
	if (validaMail(su_email))
	{
		e_su_email=false;
	}
	else	
	{
		e_su_email=true;
		document.getElementById("e_su_email").innerHTML+='Favor de escribir un Email Valido';	
	}
	
	if(empresa.length>3)
	{
		e_nombre_empresa=false;
	}
	else
	{
		e_nombre_empresa=true;
		document.getElementById("e_nombre_empresa").innerHTML='Favor de escribir el Nombre de su Empresa o Negocio';
	}
	
	if(calle.length>3)
	{
		e_calle=false;
	}
	else
	{
		e_calle=true;
		document.getElementById("e_calle").innerHTML='Favor de escribir la Calle o Avenida de su Empresa o Negocio';
	}
	if(num_ext.length>0)
	{
		e_num_ext=false;
	}
	else
	{
		e_num_ext=true;
		document.getElementById("e_num_ext").innerHTML='Favor de escribir el Número Exterior de su Empresa o Negocio';
	}
	
	if(colonia.length>3)
	{
		e_colonia=false;
	}
	else
	{
		e_colonia=true;
		document.getElementById("e_colonia").innerHTML='Favor de escribir la Colonia de su Empresa o Negocio';
	}
	
	if(cp.length>3)
	{
		e_cp=false;
	}
	else
	{
		e_cp=true;
		document.getElementById("e_cp").innerHTML='Favor de escribir correctamente el Codigo Postal de su Empresa o Negocio';
	}
	
	if(municipio!=0)
	{
		e_ciudad_municipio=false;
	}
	else
	{
		e_ciudad_municipio=true;
		document.getElementById("e_ciudad_municipio").innerHTML='Favor de Seleccionar la Ciudad o el Municipio';
	}
	
	if (categoria==0)
	{
		e_categoria=true;
		document.getElementById("e_categoria").innerHTML='Favor de Seleccionar una Categor&iacute;a';
	}
	else
	{
		e_categoria=false;
	}
	
	if (subcat1==0 && subcat2==0 && subcat3==0 && subcat4==0 && subcat5==0 && subcat6==0 && subcat7==0 && subcat8==0 && subcat9==0 && subcat10==0 && subcat11==0 && subcat12==0 && subcat13==0 && subcat14==0 && subcat15==0)
	{
		e_subcategoria=true;
		document.getElementById("e_subcategoria").innerHTML='Favor de Seleccionar una Subcategor&iacute;a';
	}
	else
	{
		e_subcategoria=false;
	}
	
	if(descripcion.length>3)
	{
		e_descripcion=false;
	}
	else
	{
		e_descripcion=true;
		document.getElementById("e_descripcion").innerHTML='Favor de escribir la información que se le solicita de su Empresa o Negocio';
	}
	
	if(captcha_code.length>3)
	{
		e_capcha=false;
	}
	else
	{
		e_capcha=true;
		document.getElementById("e_capcha").innerHTML='Olvido escribir las letras de la imagen, favor de escribirlas';
	}
	
	if (isPhoneNumber(lada_neg) && lada_neg.length>1 && isPhoneNumber(numero_neg) && numero_neg.length>6)
	{
		e_telefono_empresa=false;
	}
	else
	{
		e_telefono_empresa=true;
	document.getElementById("e_telefono_empresa").innerHTML+='Favor de Escribir o Corregir la Lada o el N&uacute;mero de Tel&eacute;fono';	
	}	
	if (e_su_nombre==false && e_apellidos==false && e_su_email==false&& e_nombre_empresa==false && e_calle==false && e_colonia==false && e_cp==false && e_ciudad_municipio==false && e_categoria==false && e_subcategoria==false && e_telefono_empresa==false && e_descripcion==false && e_capcha==false && e_num_ext==false)
	{
		document.frm_solicita_anuncio.submit();
	}
	else
	{
		alert("Favor de corregir los siguientes errores");
	}	
}

function num_tel(num)
{
	if (isPhoneNumber(num))
	{
		
	}
	else
	{
		alert("No se aceptan LETRAS");
	}
}


/*********************************************************************/

function counter(texto)
{

	total=250 - texto.value.length;
	document.frm_solicita_anuncio.res_char.value=total;
	if(texto.value.length > 250)
	{
		document.frm_solicita_anuncio.descripcion.value=texto.value.substring(0, 250);
		total=250 - texto.value.length;
		document.frm_solicita_anuncio.res_char.value=total;
	}

}


function validaMail(Objeto)
  {  

     if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(Objeto)){	   
    return (true)
     } else {

			return (false);}
  }

function clear_div()
{
document.getElementById("e_capcha").innerHTML="";
}

/*funciones para validar numero de telefono */

var defaultEmptyOK = false
var phoneChars = "()-+ ";
function isPhoneNumber (s)
{   
	var modString;
    if (isEmpty(s)) 
       if (isPhoneNumber.arguments.length == 1) return defaultEmptyOK;
       else return (isPhoneNumber.arguments[1] == true);
    modString = stripCharsInBag( s, phoneChars );
    return (isInteger(modString))
}
function isEmpty(s)
{
	return ((s == null) || (s.length == 0))
}
function isInteger (s)
{   
	var i;
    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);
    
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if( i != 0 ) {
            if (!isDigit(c)) return false;
        } else { 
            if (!isDigit(c) && (c != "-") || (c == "+")) return false;
        }
    }
    return true;
}
function stripCharsInBag (s, bag)
{  
	var i;
    var returnString = "";

    // Buscar por el string, si el caracter no esta en "bag", 
    // agregarlo a returnString
    
    for (i = 0; i < s.length; i++)
    {   var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}
function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}
function show(val)
{
	if (val==0)
	{
	document.getElementById("div_f").style.display='none';
	}
	else
	{
	document.getElementById("div_f").style.display='block';
	}
}

/*******************************************************************************************************/
/********************************************************/

function rowOverEffect(object) 
{
  if (object.className == 'dataTableRow') object.className = 'dataTableRowOver';
}

function rowOutEffect(object)
{
  if (object.className == 'dataTableRowOver') object.className = 'dataTableRow';
}
function show_subcat(subcat)
{
	for (i=1;i<16;i++)
	{
	document.getElementById("div_subcat"+i).style.display="none";
	}
	document.frm_solicita_anuncio.subcat1.value=0;
	document.frm_solicita_anuncio.subcat2.value=0;
	document.frm_solicita_anuncio.subcat3.value=0;
	document.frm_solicita_anuncio.subcat4.value=0;
	document.frm_solicita_anuncio.subcat5.value=0;
	document.frm_solicita_anuncio.subcat6.value=0;
	document.frm_solicita_anuncio.subcat7.value=0;
	document.frm_solicita_anuncio.subcat8.value=0;
	document.frm_solicita_anuncio.subcat9.value=0;
	document.frm_solicita_anuncio.subcat10.value=0;
	document.frm_solicita_anuncio.subcat11.value=0;
	document.frm_solicita_anuncio.subcat12.value=0;
	document.frm_solicita_anuncio.subcat13.value=0;
	document.frm_solicita_anuncio.subcat14.value=0;
	document.frm_solicita_anuncio.subcat15.value=0;
	
	if (subcat=="Arte y Cultura")
	{	
		document.getElementById("div_subcat1").style.display="block";
	}
	
	if (subcat=="Automóviles")
	{
		document.getElementById("div_subcat2").style.display='block';
	}
	
	if (subcat=="Bienes Raíces")
	{
		document.getElementById("div_subcat3").style.display='block';
	}
	
	if (subcat=="Compras")
	{
		document.getElementById("div_subcat4").style.display='block';
	}
	
	if (subcat=="Computación e Internet")
	{
		document.getElementById("div_subcat5").style.display='block';
	}
	
	if (subcat=="Comunicación y Publicidad")
	{
		document.getElementById("div_subcat6").style.display='block';
	}
	
	if (subcat=="Deportes")
	{
		document.getElementById("div_subcat7").style.display='block';
	}
	
	if (subcat=="Educación")
	{
		document.getElementById("div_subcat8").style.display='block';
	}
	
	if (subcat=="Entretenimiento y Ocio")
	{
		document.getElementById("div_subcat9").style.display='block';
	}
	
	if (subcat=="Hogar")
	{
		document.getElementById("div_subcat10").style.display='block';
	}
	
	if (subcat=="Negocios")
	{
		document.getElementById("div_subcat11").style.display='block';
	}
	
	if (subcat=="Salud")
	{
		document.getElementById("div_subcat12").style.display='block';
	}
	
	if (subcat=="Servicios")
	{
		document.getElementById("div_subcat13").style.display='block';
	}
	
	if (subcat=="Sociedad")
	{
		document.getElementById("div_subcat14").style.display='block';
	}
	
	if (subcat=="Turismo y Viajes")
	{
		document.getElementById("div_subcat15").style.display='block';
	}
}
