function disBtn(e,f){

	e.value='Espere...';

	e.disabled=true;

	f.submit();

}



function validaMail(i){

	if(/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.(\w{2,6}(?:\.\w{2})?)$/.test(document.getElementById(i).value)){

		return true;

	}

	else{

		document.getElementById(i).focus();

		document.getElementById(i).select();

		return false;

	}

}

function validarnp_(formulario){
	
if(formulario == ""){
	//document.getElementById("oc1").style.visibility="hidden";
    document.getElementById("oc2").style.visibility="hidden"; 
}else{
	//document.getElementById("oc1").style.visibility="visible";
    document.getElementById("oc2").style.visibility="visible"; 
	}
}

function validaNP(e,f){

	if(document.getElementById('np').value.length<2){

		alert("El N/P debe tener al menos 2 caracteres.");

		document.getElementById('np').focus();

	}

	else if((isNaN(document.getElementById('qty').value.length)||(document.getElementById('qty').value.length)<1)){

		alert("Debe ingresar una cantidad igual o superior a 1.");

		document.getElementById('qty').focus();

	}

	else{

		confir=true;

		if(document.getElementById('mk').value.length==0){

			var confir=confirm("No ha ingresado la marca para este N/P, si la desconoce, deje el espacio en blanco.");

			document.getElementById('mk').focus();

		}

		if(confir){

			if(document.getElementById('mk').value.length==0){

				document.getElementById('mk').value='N/A';

			}
			//f.action='/add2rfq.php';
			//e.disabled=true;
			//f.submit();
   // document.getElementById("oc1").style.visibility="hidden";
    document.getElementById("oc2").style.visibility="hidden"; 
	 xajax('/lib.ajax.php','responsehtml','accion=printhtmlproductos&inyect=add&quo='+document.getElementById("quo").value+"&np="+document.getElementById("np").value+"&mk="+document.getElementById("mk").value+"&qty="+document.getElementById("qty").value,'POST'); 
		/*document.getElementById("np").value="";
		document.getElementById("mk").value="";
		document.getElementById("qty").value="";	  
			  
*/
		}

	}

}



function chckNumPart(f){

	var confir=true;

	if(f.np.value.length>0){

		confir=confirm("Tiene un N/P digitado, y que no ha agregado a la solicitud...\n\nDebe presionar el boton 'Agregar N/P a la cesta' para esa accion. Si continua no se contara el numero de parte en cuestion.\n\nDesea continuar ?");

	}

	if(confir){location.href='/brand/';}

}
function cargaajax(){
	
		 xajax('/lib.ajax.php','codigo_div','frmcapcha='+document.getElementById('frmcapcha').value+'&accion=codigo','POST','CAP');
		 
		 xajax('/lib.ajax.php','email_div','email='+document.getElementById('email').value+'&accion=email','POST','mail'); 
		 	
}


function validaForm(e,f){
/*validamos el Correo*/	
cargaajax();	 
		/*if(document.getElementById("estadocorreo").value=="error"){
			document.getElementById('tableerrormail').style.backgroundColor="#850d10"; 
			document.getElementById('tableerror2mail').style.backgroundColor="#850d10"; 
			document.getElementById('email_div').innerHTML=""
			document.getElementById('email_div').innerHTML="<img src=http://www.latintronika.cl/images/chk_off.png width=15 height=15 />";
			//document.getElementById('mailerror').value="errormail"
            return false
		}
		if(document.getElementById("estadocapcha").value=="error"){

			document.getElementById('tableerror1').style.backgroundColor="#850d10"; 
			document.getElementById('tableerror2').style.backgroundColor="#850d10"; 
			document.getElementById('tableerror3').style.backgroundColor="#850d10"; 
			document.getElementById('codigo_div').innerHTML=""
            document.getElementById('codigo_div').innerHTML="<img src=http://www.latintronika.cl/images/chk_off.png width=15 height=15 />";
			//document.getElementById('codigoerror').value="errorcodigo"
	     	return false
		}	*/

			e.value='Espere...';
			e.disabled=true;
			f.submit();
			return true;
/*validamos el Correo*/
	if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(document.getElementById('email').value)){

		if((f.comentario.value.length>10)||(f.idnpss.value>0)||(f.np.value.length>2)){

	
			e.value='Espere...';
			e.disabled=true;
			f.submit();
	}else{

			alert("Debe agregar al menos un N/P, o escribir su requerimiento en el campo Descripcion (mas de 10 caracteres).");

		}

	}

	else{

		alert("Debe escribir una direccion Email valida para poder contactarle.");

	}

}
//Libreria Ajax agregada
//Libreria Ajax agregadas
function Ajax(){
         var objetoAjax=false;
         try {
          /*Para navegadores distintos a internet explorer*/
          objetoAjax = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
          try {
                   /*Para explorer*/
                   objetoAjax = new ActiveXObject("Microsoft.XMLHTTP");
                   }
                   catch (E) {
                   objetoAjax = false;
          }
         }

         if (!objetoAjax && typeof XMLHttpRequest!='undefined') {
          objetoAjax = new XMLHttpRequest();
         }
         return objetoAjax;
}

function xajax(url,capa,valores,metodo,js)
{
          var ajax=Ajax();
          var capaContenedora = document.getElementById(capa);

if(metodo=='POST'){
         ajax.open ('POST', url, true);
         ajax.onreadystatechange = function() {
         if (ajax.readyState==1) {
                          capaContenedora.innerHTML="<img src=/images/loading.gif>";
         }
         else if (ajax.readyState==4){
                   if(ajax.status==200)
                   {
                        document.getElementById(capa).innerHTML=ajax.responseText;
			
						if(js=="mail"){
							if(document.getElementById("mailerror").value=="errormail")
							{
							document.getElementById('tableerrormail').style.backgroundColor="#850d10"; 
							document.getElementById('tableerror2mail').style.backgroundColor="#850d10"; 
							document.getElementById('estadocorreo').value ="error";
							}else{								
							document.getElementById('tableerrormail').style.backgroundColor=""; 
							document.getElementById('tableerror2mail').style.backgroundColor=""; 	
							document.getElementById('estadocorreo').value ="";	
							}
							
						}
						if(js=="CAP"){
							if(document.getElementById("codigoerror").value=="errorcodigo")
							{
							document.getElementById('tableerror1').style.backgroundColor="#850d10"; 
							document.getElementById('tableerror2').style.backgroundColor="#850d10"; 
							document.getElementById('tableerror3').style.backgroundColor="#850d10"; 
							document.getElementById('estadocapcha').value ="error";
							}else{								
							document.getElementById('tableerror1').style.backgroundColor=""; 
							document.getElementById('tableerror2').style.backgroundColor=""; 
							document.getElementById('tableerror3').style.backgroundColor="";  	
							document.getElementById('estadocapcha').value ="";
							}
							
						}
						
                   }
                   else if(ajax.status==404)
                                             {

                            capaContenedora.innerHTML = "La direccion no existe";
                                             }
                           else
                                             {
                            capaContenedora.innerHTML = "Error: ".ajax.status;
                                             }
                                    }
                  }
         ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
         ajax.send(valores);
         return;
}
if (metodo=='GET'){

         ajax.open ('GET', url, true);
         ajax.onreadystatechange = function() {
         if (ajax.readyState==1) {
                                      capaContenedora.innerHTML="<img src=/images/loading.gif>";
         }
         else if (ajax.readyState==4){
                   if(ajax.status==200){
                                             document.getElementById(capa).innerHTML=ajax.responseText;
                   }
                   else if(ajax.status==404)
                                             {

                            capaContenedora.innerHTML = "La direccion no existe";
                                             }
                                             else
                                             {
                            capaContenedora.innerHTML = "Error: ".ajax.status;
                                             }
                                    }
                  }
         ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
         ajax.send(null);
         return
}
} 
//Libreria Ajax agregada
//Libreria Ajax agregada
/***********************************************************************/
/***********************************************************************/
/***********************************************************************/
/***********************************************************************/
/***********************************************************************/
/***********************************************************************/
function xajaxSubmit(capa,metodo)
{
          var ajax=Ajax();
          var capaContenedora = document.getElementById(capa);

if(metodo=='POST'){
         ajax.open ('POST', '/lib.ajax.php', true);
         ajax.onreadystatechange = function() {
         if (ajax.readyState==1) {
                          //capaContenedora.innerHTML="<img src=/images/loading.gif>";
         }
         else if (ajax.readyState==4){
                   if(ajax.status==200)
                   {
                        cadenaTexto=ajax.responseText;
						fragmentoTexto = cadenaTexto.split('|');
						if((cadenaTexto=="ok|ok")){
									   /**/
if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(document.getElementById('email').value)){
if((document.getElementById('comentario').value.length>10)||(document.getElementById('idnpss').value >0)||(document.getElementById('np').value.length>2)){
						    document.getElementById('envio2').value='Espere...';
							document.getElementById('envio2').disabled=true;
			                document.getElementById('frmRFq').submit();
						}else{
							alert("Debe agregar al menos un N/P, o escribir su requerimiento en el campo Descripcion (mas de 10 caracteres).");

                }
}else{
     alert("Debe escribir una direccion Email valida para poder contactarle.");
}

									   
									   /**/
									   
									   
				        }else{

		if(fragmentoTexto[0]=="error"){
			document.getElementById('tableerrormail').style.backgroundColor="#850d10"; 
			document.getElementById('tableerror2mail').style.backgroundColor="#850d10"; 
			document.getElementById('email_div').innerHTML=""
			document.getElementById('email_div').innerHTML="<img src=http://www.latintronika.cl/images/chk_off.png width=15 height=15 />";
            return false
		}
		if(fragmentoTexto[1]==="error"){

			document.getElementById('tableerror1').style.backgroundColor="#850d10"; 
			document.getElementById('tableerror2').style.backgroundColor="#850d10"; 
			document.getElementById('tableerror3').style.backgroundColor="#850d10"; 
			document.getElementById('codigo_div').innerHTML=""
            document.getElementById('codigo_div').innerHTML="<img src=http://www.latintronika.cl/images/chk_off.png width=15 height=15 />";
	     	return false
		}	
		
				       }
						
                   }
                   else if(ajax.status==404)
                                             {

                            capaContenedora.innerHTML = "La direccion no existe";
                                             }
                           else
                                             {
                            capaContenedora.innerHTML = "Error: ".ajax.status;
                                             }
                                    }
                  }
         ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
         ajax.send('frmcapcha='+document.getElementById('frmcapcha').value+'&email='+document.getElementById('email').value+'&accion=globalcom');
         return;
}
if (metodo=='GET'){

         ajax.open ('GET', url, true);
         ajax.onreadystatechange = function() {
         if (ajax.readyState==1) {
                                      capaContenedora.innerHTML="<img src=/images/loading.gif>";
         }
         else if (ajax.readyState==4){
                   if(ajax.status==200){
                                             document.getElementById(capa).innerHTML=ajax.responseText;
                   }
                   else if(ajax.status==404)
                                             {

                            capaContenedora.innerHTML = "La direccion no existe";
                                             }
                                             else
                                             {
                            capaContenedora.innerHTML = "Error: ".ajax.status;
                                             }
                                    }
                  }
         ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
         ajax.send(null);
         return
}
} 
//Libreria Ajax agregada
//Libreria Ajax agregada
