function validaNP(e,f){
	if(f.np.value.length<2){
		alert("El N/P debe tener al menos 2 caracteres.");
		f.np.focus();
	}
	else if((isNaN(f.qty.value)||(f.qty.value)<1)){
		alert("Debe ingresar una cantidad igual o superior a 1.");
		f.qty.focus();
	}
	else{
		confir=true;
		if(f.mk.value.length==0){
			var confir=confirm("No ha ingresado la marca para este N/P, si la desconoce, deje el espacio en blanco.");
			f.mk.focus();
		}
		if(confir){
			if(f.mk.value.length==0){
				f.mk.value='N/A';
			}

			f.action='/add2cart.php';
			e.disabled=true;
			f.submit();
		}
	}
}

function validaForm(e,f){
	var confir=true;
	if(f.np.value.length>0){
		var confir=confirm("Tiene un N/P digitado, y que no ha agregado a la cesta...\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){
		if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(f.email.value)){
			if((f.comentario.value.length>10)||(f.cnp.value==453)){
				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.");}
		f.email.focus();
	}
}

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 cesta...\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='produc.php';}
}
function chckMarca(f){
	var confir=true;
	if(f.mk.value.length==0){
		confir=confirm("No ha ingresado la marca para este N/P, si la desconoce solo presione Aceptar, caso contrario, Cancelar y rellene el espacio con la marca.");
		f.mk.focus();
	}
	if(confir){
		if(f.mk.value.length==0){
			f.mk.value='N/A';
		}
		f.submit();
		e.disabled=true;
	}
}
/*----------------------------------------------------------------*/
function validarEmail(valor) { 

if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor.user.value)){

valor.submit();

} else {

alert("La direccion de Email es incorrecta.");
valor.user.focus();
}

}

/*------------------------------------------------*/
function lookup(inputString) {
		if(inputString.length == 0) {
			$('#suggestions').hide();
		} else {
			$.post("prueba2.ajax.php", {queryString: ""+inputString+""}, function(data){
				if(data.length >0) {
					$('#suggestions').show();
					$('#autoSuggestionsList').html(data);
					
				}
			});
		}
	} 
	
	function fill(thisValue) {
		$('#inputString').val(thisValue);
		setTimeout("$('#suggestions').hide();", 200);
		$('#autoSuggestionsList').hide(data);
	}
/*_______________________________________________*/
	
function srchLimpiar(e){
	e.style.color="#E0691A";
	if(e.value=="Buscar componente On-Line..."){
		e.value="";
	}
	else{
		e.select();
	}
}

function srchCompletar(e){
	e.style.color="#C3C3C3";
	if(e.value==""){
		e.value="Buscar componente On-Line...";
	}
}
	
function buscando(f){
	if((f.keyword.value=="Buscar componente On-Line...")||(f.keyword.value=="")){
		alert("No ha ingresado nada para buscar.");
		return false;
	}
	else{
		f.buscar.disabled=true;
		return true;
	}
}

function buscado(f){
	if(f.key.value==""){
		alert("No ha ingresado nada para buscar.");
		return false;
	}
	else{
		document.getElementById("boton").value="Espere por favor...";
		alertLogout();
		f.enviar.disabled=true;
		f.disabled=true;
		return true;
	}
}


function activaUser(f,e){
	if(!isNaN(e.value)){
		if(e.value==0){
			f.tch.value='2';
		}
		f.submit();
	}
}

//_______________________________________

function explorarPermiso(permiso){
	var confir=confirm("El producto buscado no esta en nuestras bases de datos ni en las de nuestros proveedores mas cercanos, probablemente se encuentra obsoleto o esta fuera de Lineas de fabricacion, verificar la existencia en otros centros de acopio puede demorar algunos minutos, DESEA CONTINUAR?.");
	if(confir){
		permiso=1;
	}
		else{
			permiso=0;
		}

	return(permiso);
}

//_________________________________________________________________
function MostrarFilas(Fila) {
   // Almacenamos en "elementos" el objeto "Fila" recibido como parï¿½metro
   var elementos = document.getElementsByName(Fila);
    // Mostramos todos los objetos del mismo identificador
   // Con propiedad display = "" dejamos al navegador que ponga su tipo por defecto
   for (i = 0; i < elementos.length; i++){
      elementos[i].style.display ="";}
}


function OcultarFilas(Fila) {
   // Almacenamos en "elementos" el objeto "Fila" recibido como parï¿½metro
   var elementos = document.getElementsByName(Fila);
   // Ocultamos todos los objetos del mismo identificador
   for (k = 0; k < elementos.length; k++){
   elementos[k].style.display ="none";}
}

function verOcultarDetalles(id) {
	if(!document.getElementById(id)){
		return false;
	}
	else{
		var fila=document.getElementById(id);
		if (fila.style.display != "none"){
			fila.style.display = "none"; //ocultar fila
		}
		else {
			fila.style.display = ""; //mostrar fila
		}
	}
}


//___________________________
//valida fecha de nacimiento

function validaFecha(i){
	//if(/^((0?[1-9])|([12]\d)|(3[01]))\/((0?[1-9])|(1[0-2]))\/\d\d\d\d+$/.test(i)){
		return true;
	//}
	//else{return false;}
}

function cuentaVip(f){
	if(f.fechaNacimiento.value.length==0){
		if((f.pass.value==f.pass2.value && f.pass.value.length==0 && f.pass.value.length==0) || (f.pass.value==f.pass2.value && f.pass.value.length > 2 && f.pass.value.length > 2)){
					f.disabled=true;
					return true;
				}	
					else{
						alert('Las claves no coinciden o las claves no son mayores a 2 caracteres');
						return false;
					}
	}
		else{
			if(validaFecha(f.fechaNacimiento.value)){
				if((f.pass.value==f.pass2.value && f.pass.value.length==0 && f.pass.value.length==0) ||(f.pass.value==f.pass2.value && f.pass.value.length > 2 && f.pass.value.length > 2)){
					f.disabled=true;
					return true;
				}	
					else{
						alert('Las claves no coinciden o las claves no son mayores a 2 caracteres');
						return false;
					}
			}
						else{
							alert('La Fecha no corresponde al formato dd/mm/YYYY');
							return false;
						}
		}
}


	function alertLogout(){
		var fondo = null;
		try {
			fondo = window.document.createElement("<div class='anuncioFondo'>");
		}
		catch(err) {
			fondo = window.document.createElement("div");
			fondo.setAttribute("class", "anuncioFondo");
		}
	
		try {
			anuncio = window.document.createElement("<div class='anuncioBox'>");
		}
		catch(err) {
			anuncio = window.document.createElement("div");
			anuncio.setAttribute("class", "anuncioBox");
		}
		fondo.setAttribute('id','layer475');
		anuncio.setAttribute('id','layer476');
		//=====
		miImagen = document.createElement("img");
		miImagen.setAttribute("id","imagenUno"); 
		miImagen.setAttribute("src","/images/barra.gif");
		
		//====
		var cargar='<center><br><br><font color="white" size="10"><b>Buscando...</b></font><br><div><br><font color="white">Espere por favor...</font></div>';
		anuncio.innerHTML= cargar;
		window.document.body.appendChild(fondo);
		window.document.body.appendChild(anuncio);
		window.document.body.appendChild(miImagen);
		return true;
	}
	
	//alertLogout();
	//parent.window.document.getElementById('ingresaLoginBox').focus();

function bannerTop(){
		var fondo = null;
		try {
			fondo = window.document.createElement("<div class='anuncioFondo2'>");
		}
		catch(err) {
			fondo = window.document.createElement("div");
			fondo.setAttribute("class", "anuncioFondo2");
		}

		try {
			anuncio = window.document.createElement("<div class='anuncioBox2'>");
		}
		catch(err) {
			anuncio = window.document.createElement("div");
			anuncio.setAttribute("class", "anuncioBox2");
		}
		fondo.setAttribute('id','layer475');
		anuncio.setAttribute('id','layer476');
		//=====
		//miImagen = document.createElement("img");
		//miImagen.setAttribute("id","imagenUno"); 
		//miImagen.setAttribute("src","/images/barra.gif");
		//====
		var cargar='<center><form method="POST" action="banner.php" target="banner"><table border="0" width="100%"><tr><td rowspan="5"><img src="/images/finding.gif" border="0"/></td></tr><tr><td align="center" colspan="3"><h3>¿Qu&eacute; necesitas?</h3></td></tr><tr><td>Mail:</td><td><input type="text" name="mail" /></td></tr><tr><td>Solicitud:</td><td><textarea name="textoIngresado" COLS=40></textarea></td><tr><tr><td colspan="3" align="center"><input type="submit" value="Solicitar" class="submit" name="enviar" onClick="setTimeout(\'cancelLoginBox();\',1000);alert(\'Gracias por su solicitud.\')">&nbsp;<input type="button" value="Cancelar" onClick="cancelLoginBox()" class="submit"></td></tr></table></form></center>';//<input type="hidden" name="direccion" value="'+direccion+'">
		anuncio.innerHTML= cargar;
		window.document.body.appendChild(fondo);
		window.document.body.appendChild(anuncio);
		//window.document.body.appendChild(miImagen);
		return true;
	}
	
function cancelLoginBox(){
	document.body.removeChild(document.getElementById('layer475'));
	document.body.removeChild(document.getElementById('layer476'));
} 

function closeDiv() {
document.getElementById("banner_nav").style.display = "none";
return false;
//document.body.removeChild(document.getElementById('banner_nav'));
}

//====================================================

function FeedBack(){
	 var fondo = null;
	 try {
	  fondo = window.document.createElement("<div class='anuncioFondoFeed'>");
	 }
	 catch(err) {
	  fondo = window.document.createElement("div");
	  fondo.setAttribute("class", "anuncioFondoFeed");
	 }

	 try {
	  anuncio = window.document.createElement("<div class='anuncioBoxFeed'>");
	 }
	 catch(err) {
	  anuncio = window.document.createElement("div");
	  anuncio.setAttribute("class", "anuncioBoxFeed");
	 }
	 fondo.setAttribute('id','layer475');
	 anuncio.setAttribute('id','layer476');
	 //=====
	 miImagen = document.createElement("img");
	 miImagen.setAttribute("id","imagenUno"); 
	 miImagen.setAttribute("src","/images/cargando.gif");
	 
	 //====
	var cargar='<form method="post" target="frameIngresosugerencia" action="feedback.php" name="prueba" id="prueba"><table border="0" width="530" height="283" bgcolor="#E6E6E6"><tr bgcolor="#045FB4"><th align="center" colspan="2" height="40"><font color ="#FFFFFF"><i>SUGERENCIAS</i></font></th></tr><tr><td align="right" height="40" width="30%"><h5><b>Ingrese mail:</b></h5></td><td><Input type="text" name="email" title="Ingrese su mail"></td></tr><tr><td align="right"><h5><b>Ingrese aqui su sugerencia:</b></h5></td><td><textarea name="suger" title="Ingrese aqui su sugerencia" rows="7" cols="40" ></textarea></td></tr><tr><td >&nbsp;</td><td height="30"><input type="button" value="Enviar sugerencia " name="enviar" onClick="Valid(this.form);">&nbsp;<input type="reset" value=" Limpiar ">&nbsp;<input align="center" type="button" value=" Cancelar " onClick="cancelLoginBox()"></td></tr></table></form>';
	 anuncio.innerHTML= cargar;
	 window.document.body.appendChild(fondo);
	 window.document.body.appendChild(anuncio);
	 //window.document.body.appendChild(miImagen);
	 return true;
	}
	
function Valid(f){
	if(f.suger.value.length<=5){
		alert('Tiene que tener por lo menos 6 caracteres');
		return false;
	}
	 
	else{
		if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(f.email.value)){
			setTimeout('cancelLoginBox();',1000);
			alert('Gracias por su sugerencia.');
			f.submit();
			return true;
		}
		else{
			alert("Debe escribir una direccion Email valida para poder contactarle.")
			return false;
		}
	}			
}