function initMenu() {
  $('#menu ul').hide(); 
  $('#menu li a').click(
                         function() {
                                      var checkElement = $(this).next();	 
                                      if((checkElement.is('ul')) && (checkElement.is(':visible'))) {        
                                     		return false;
                                         } 
                                       if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
                                          $('#menu ul:visible').slideUp('normal');
                                          checkElement.slideDown('normal');
                                    	  /*$("#Compa").removeClass("ConLine1");*/
                                          return false;
                                       }									    
                                   }
                       );
    }
	
$(document).ready(function() {initMenu();});

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

function ValidarCaracteres(Cadena)
{  
  var checkOK = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú ";
  var checkStr = Cadena;
  var BAND = false;
  
 if(Cadena!='')
  { 
    for (i = 0; i < checkStr.length; i++) 
      {
           ch = checkStr.charAt(i);
             for (j = 0; j < checkOK.length; j++)
                 if (ch == checkOK.charAt(j))
                     break;     
          	  
			   if (j == checkOK.length) 
	             {
                   BAND = true;
                    break;
                 }//if
       }//fof
    }
   else
     {
      BAND=true;	 
	 }

 return (BAND);
}
//************************************************************
function mail(email)
{
  var Band=false;
  var b=/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/;
  
    if(b.test(email))
	{
	  Band=false;
	}
  else 
    {
	 Band=true;
	}
	 
 return (Band);
}


function Guardalos_JQuery(PARAMETROS,CAPA,URL)
{

  $.ajax({
        url:URL,
        async:true,
		data:PARAMETROS,
        contentType: "application/x-www-form-urlencoded",        
        dataType:"html",
        error: function(objeto, quepaso, otroobj){
            alert(quepaso);
        },
            global:true,
        ifModified:false,
        processData:true,
        success: function(datos){  			
		$("#"+CAPA).html(datos);					
        },
        timeout:200000,
        type: "POST"
     });
}

function EnviarMail(URL,CAPA,P){
	
 var T1=document.Form1.T1.value;//nombre*
 var T2=document.Form1.T2.value;//Mail*
 var T3=document.Form1.T3.value;//Telefono
 var T4=document.Form1.T4.value;//Puesto
// var T5=document.Form1.T5.value;//Industria Aplicacion*

 var T6=document.Form1.T6.value;//Compañia
/* 
 var T7=document.Form1.T7.value;//direccion
 var T8=document.Form1.T8.value;//Ciudad Estado
 var T9=document.Form1.T9.value;//Pais
 var T10=document.Form1.T10.value;//tiempo para comprar
 var T11=document.Form1.T11.value;//Como deseo contactar 
*/ 
 var T5="",T7="",T8="",T9="",T10="",T11="";
 var T12=document.Form1.T12.value;//Mensaje
 
 var Mensaguillo="";
 var RESP="";


 if(ValidarCaracteres(T1)==true){
    Mensaguillo+="\n     -> Nombre"; 
 }
 
 if(mail(T2)==true){
     Mensaguillo+="\n     -> Correo"; 	 
 }
/* 
 if(T3==''){
     Mensaguillo+="\n     -> Telefono"; 	 
 }
*/ 
 
 if(T4==''){
     Mensaguillo+="\n     -> Puesto / Departamento"; 	 
 }
   
 if(Mensaguillo==""){ 
 
  PARAMETROS="T1="+T1+"&T2="+T2+"&T3="+T3+"&T4="+T4+"&T5="+T5+"&T6="+T6+"&T7="+T7+"&T8="+T8+"&T9="+T9+"&T10="+T10+"&T11="+T11+"&T12="+T12+"&idi"+P;
  document.getElementById(CAPA).innerHTML="Espere enviando correo...";	
  Guardalos_JQuery(PARAMETROS,CAPA,URL)
  return false;
	
 }else{
	RESP="________________________________________\n"+"¡ Error !, al introducir los siguientes datos:\n";
	RESP+=Mensaguillo+"\n______________________________________________" +"\n¡ Por favor pulsa enter, rellena los datos y pruebe de nuevo"; 
	alert(RESP);
	return false;
 }

}//Fin del EnviarMail
//***************************************************************************

function CotizarForm(URL,CAPA,P){
	
 var T1=document.Form1.T1.value;//nombre*
 var T2=document.Form1.T2.value;//Mail*
 var T3=document.Form1.T3.value;//Telefono
 var T4=document.Form1.T4.value;//Puesto
 var T5=document.Form1.T5.value;//Industria Aplicacion*
 var T6=document.Form1.T6.value;//Compañia
 var T7=document.Form1.T7.value;//direccion
 var T8=document.Form1.T8.value;//Ciudad Estado
 var T9=document.Form1.T9.value;//Pais
 var T10=document.Form1.T10.value;//tiempo para comprar
 var T11=document.Form1.T11.value;//Como deseo contactar 
 var T12=document.Form1.T12.value;//requerimientos de su aplicación
 
 var Mensaguillo="";
 var RESP="";
 
 if(ValidarCaracteres(T1)==true){
    Mensaguillo+="\n     -> Nombre"; 
 }
 
 if(mail(T2)==true){
     Mensaguillo+="\n     -> E-Mail"; 	 
 }

/*
 if(T3==''){
     Mensaguillo+="\n     -> Telefono"; 	 
 }
*/ 
 
 if(T4==''){
     Mensaguillo+="\n     -> Puesto"; 	 
 }
   
 if(Mensaguillo==""){ 
  
  PARAMETROS="T1="+T1+"&T2="+T2+"&T3="+T3+"&T4="+T4+"&T5="+T5+"&T6="+T6+"&T7="+T7+"&T8="+T8+"&T9="+T9+"&T10="+T10+"&T11="+T11+"&T12="+T12+"&idi"+P;
  document.getElementById(CAPA).innerHTML="Espere enviando cotización...";	
  Guardalos_JQuery(PARAMETROS,CAPA,URL)
  //return false;
	
 }else{
	RESP="________________________________________\n"+"¡ Error !, al introducir los siguientes datos:\n";
	RESP+=Mensaguillo+"\n______________________________________________" +"\n¡ Por favor pulsa enter, rellena los datos y pruebe de nuevo"; 
	alert(RESP);
	return false;
 }
 
}//Fin CotizarForm

//***************************************************************************
//************************************** Datos del Imagenes y Testo Botones
var Conta=0;

function JImg(PARAMETROS,CAPA,URL)
{

  $.ajax({
        url:URL,
        async:true,
		data:PARAMETROS,
        contentType: "application/x-www-form-urlencoded",       
        dataType:"html",
        error: function(objeto, quepaso, otroobj){
            //alert(quepaso);
        },
            global:true,
        ifModified:false,
        processData:true,
        success: function(datos){  			
		$("#"+CAPA).html(datos);					
        },
        timeout:200000,
        type: "POST"
     });
}


function Tiempo(){

var array=[0,1,2];
var Parra="",Parra2="",ParraBT="",ParraBTb="",ParraBTb2="";

switch(Conta){

 case 0: Conta++; Parra="Id="+array[0]; Parra2="IdT="+array[0]; 
         
 		   ParraBT="IdBC=0";
 		  ParraBTb="IdBN=1";
		 ParraBTb2="IdBN=2";
		 
		  JImg(ParraBT,'Boton1','CambioImg.php');
		 JImg(ParraBTb,'Boton2','CambioImg.php');
		 JImg(ParraBTb2,'Boton3','CambioImg.php');
		 
		 break;
 case 1: Conta++; Parra="Id="+array[1]; Parra2="IdT="+array[1]; 
 
 		   ParraBT="IdBC=1";
 		  ParraBTb="IdBN=0";
		 ParraBTb2="IdBN=2";
		  
		  JImg(ParraBT,'Boton2','CambioImg.php');
		 JImg(ParraBTb,'Boton1','CambioImg.php');
		 JImg(ParraBTb2,'Boton3','CambioImg.php');         
		 
		 
		 break; 
 case 2: Conta++; Parra="Id="+array[2]; Parra2="IdT="+array[2];
 
  		   ParraBT="IdBC=2";
 		  ParraBTb="IdBN=0";
		 ParraBTb2="IdBN=1";
		  
		  JImg(ParraBT,'Boton3','CambioImg.php');
		 JImg(ParraBTb,'Boton1','CambioImg.php');
		 JImg(ParraBTb2,'Boton2','CambioImg.php');  
         
		 break; 
default: Conta=0; 
         Parra="Id="+array[0]; Parra2="IdT="+array[0];
 		 
		   ParraBT="IdBC=0";
 		  ParraBTb="IdBN=1";
		 ParraBTb2="IdBN=2";
		 
		  JImg(ParraBT,'Boton1','CambioImg.php');
		 JImg(ParraBTb,'Boton2','CambioImg.php');
		 JImg(ParraBTb2,'Boton3','CambioImg.php');		 
		 
         break;
}

JImg(Parra,'ImagenImg','CambioImg.php');
JImg(Parra2,'Textos','CambioImg.php');

}

function LlamadaTiempo(){
setInterval(Tiempo,2000);
}

/*Busuqedas*/

function BuscarKey(event){
 
  if(event.which || event.keyCode){
	if ((event.which == 13) || (event.keyCode == 13)) {
          
		  var txtBus=document.TBusF.TBus.value;
           var txtGo=document.TBusF.TGo.value;
		     var URL="sp-buscar.php";
		   
		   if((txtBus=="") || (txtBus.length<2)){			   
			RESP="________________________________________\n"+"¡ Error !, en buscar:\n";
	        RESP+="- Debe de introducir una palabra a buscar y mayor a dos caracteres ";
			RESP+="\n______________________________________________" +"\n¡ Por favor pulsa enter, rellena los datos y pruebe de nuevo"; 
	        alert(RESP);
		   }else{
			window.location.href=URL+"?TGo="+txtGo+"&TBus="+txtBus;   
		   }
		   
	}
  } 
}

function Busquedas(){

var URL="sp-buscar.php";
var txtBus=document.TBusF.TBus.value;
var txtGo=document.TBusF.TGo.value;

       if(txtBus=="" || txtBus.length<2){
			RESP="________________________________________\n"+"¡ Error !, en buscar:\n";
	        RESP+="- Debe de introducir una palabra a buscar y mayor a dos caracteres ";
			RESP+="\n______________________________________________" +"\n¡ Por favor pulsa enter, rellena los datos y pruebe de nuevo"; 
	        alert(RESP);   
		   }else{
			window.location.href=URL+"?TGo="+txtGo+"&TBus="+txtBus;   
		   }
}


