function IsNumeric(sText){
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}

function validar_cantidad_ped(min,max,actual,campo,linea){
	if (IsNumeric(document.getElementById(campo).value)){
		if (document.getElementById(campo).value<min){
			alert("La cantidad introducida es menor que el mínimo.\nThe quantity does not reach the  minimum allowed.\nLe montant que vous entrez est inférieur au minimum.");
			document.getElementById(campo).value=actual;
		}
		else{
			if (document.getElementById(campo).value>max){
			alert("La cantidad introducida sobrepasa el máximo permitido.\nThe quantity exceeds the maximum allowed.\nLe montant dépasse le maximum autorisé.");
			document.getElementById(campo).value=actual;
		} 
			else {
						UpdateArticulo(linea);
						return true;}
		}
	}
	else
	{
	alert("Debe introducir un valor numérico.\nYou must introduce a numerical value.\nVous devez entrer une valeur numérique.");
	document.getElementById(campo).value=actual;
	}
}


function validar_cantidad(min,max,campo){
	if (IsNumeric(document.getElementById(campo).value)){
		if (document.getElementById(campo).value<min){
			alert("La cantidad introducida es menor que el mínimo.\nThe quantity exceeds the minimum allowed.\nLe montant que vous entrez est inférieur au minimum.");
			document.getElementById(campo).value=min;
		}
		else{
			if (document.getElementById(campo).value>max){
			alert("La cantidad introducida sobrepasa el máximo permitido.\nThe quantity exceeds the maximum allowed.\nLe montant dépasse le maximum autorisé.");
			document.getElementById(campo).value=min;
		} 
			else {return true;}
		}
	}
	else
	{
	alert("Debe introducir un valor numérico.\nYou must introduce a numerical value.\nVous devez entrer une valeur numérique.");
	document.getElementById(campo).value=min;
	}
}

function comprobar_noSQLinj(str_valor){
	if (str_valor.length=0){
		alert("Empty String");
		return false;
	}
	else{
		if(str_valor.indexOf('&',0)<0){
		return true;
		}
		else{
		alert("SQLInjection Blocked");
		return false;
		}
	}
}

function iEnter(oEvento, oFormulario){
		var iAscii;

     if (oEvento.keyCode)
     		{
         iAscii = oEvento.keyCode;
        }
     else if (oEvento.which)
        {
         iAscii = oEvento.which;
         }
     else
     		{
         return false;
        }

     if (iAscii == 13)
     	{	
     		oFormulario.submit();
     		return true;
     	}
     else{
     	return false;
     }
}


function Valida_Login(formulario){
	if (formulario.txtNomUsuari.value!=""){
		if (formulario.txtPassword.value!=""){
			if((comprobar_noSQLinj(formulario.txtNomUsuari.value)) || (comprobar_noSQLinj(formulario.txtPassword.value))){
			formulario.submit();
			}
			else{
			window.location='Login.asp';		
			}
		}
		else{
			alert("Debe introducir un Password.\nYou must insert the Password.\nVous devez entrer un mot de passe");
		}
	}
	else {
		alert("Debe introducir un nombre de usuario.\nYou must insert the username.\nVous devez entrer un nom d'utilisateur.");
	}
}

function envio(form){
	var url;
	if (form.Ref.value!=""){
		if (form.Des.value!=""){
			alert("No es posible hacer búsquedas combinadas por descripción y referencia!\nIt is not possible to do combinated search!\nIl n'est pas possible de faire des recherches combinées!");
			}
		else{
				if (comprobar_noSQLinj(form.Ref.value)){
					url = "Busca.asp?ref=" + form.Ref.value
					url = url + "&tipo="
						if (form.Rtipo[1].checked){
							url = url + form.Rtipo[1].value;
							}
						else{
							url = url + form.Rtipo[0].value;
							}	
					parent.clasificacion.location.href=url;
				}				
			}
		}
	else{
		if(form.Des.value!=""){
			if (comprobar_noSQLinj(form.Des.value)){
				url = "Busca.asp?Des=" + form.Des.value
				url = url + "&tipo="
				if (form.Dtipo[1].checked){
					url = url + form.Dtipo[1].value;
					}
				else{
					url = url + form.Dtipo[0].value;
					}	
				parent.clasificacion.location.href=url;
			}
		}
	}
	return;
}


function iEnter_env(oEvento, oFormulario){
		var iAscii;

     if (oEvento.keyCode)
     		{
         iAscii = oEvento.keyCode;
        }
     else if (oEvento.which)
        {
         iAscii = oEvento.which;
         }
     else
     		{
         return false;
        }

     if (iAscii == 13)
     	{	
				envio(oFormulario);

     	}
     else{
     	return false;
     }
		 	
		
}


function imprimirframe() {
window.parent.frpedido.focus();
window.parent.frpedido.print();

} 


function corregir(){
	var url;
	url = "Bienvenida.asp?corregir=1";
	window.location.href=url;
}


function enviar_dades_cli(form){	
	form.action="CompDataCli.asp";
	form.submit();
}

function imprimiracuse() {
window.parent.fracuse.focus();
window.parent.fracuse.print();

} 

function logoutacuse(){
	var url;
	URL = "logout.asp";	
	window.top.location=URL;	
	
}
	
