// JavaScript Document
//------------------------



function mail(texto){

    var mailres = true;            
    var cadena = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890@._-";
    
    var arroba = texto.indexOf("@",0);
    if ((texto.lastIndexOf("@")) != arroba) arroba = -1;
    
    var punto = texto.lastIndexOf(".");
                
     for (var contador = 0 ; contador < texto.length ; contador++){
        if (cadena.indexOf(texto.substr(contador, 1),0) == -1){
            mailres = false;
            break;
     }
    }

    if ((arroba > 1) && (arroba + 1 < punto) && (punto + 1 < (texto.length)) && (mailres == true) && (texto.indexOf("..",0) == -1))
     mailres = true;
    else
     mailres = false;
                
    return mailres;
}





function $(id){
	return document.getElementById(id);
}
function nuevoAjax()
{ 
	var xmlhttp=false; 
	try 
	{ 
		// Creacion del objeto AJAX para navegadores no IE
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
	}
	catch(e)
	{ 
		try
		{ 
			// Creacion del objet AJAX para IE 
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		catch(E) { xmlhttp=false; }
	}
	if (!xmlhttp && typeof XMLHttpRequest!="undefined") { xmlhttp=new XMLHttpRequest(); } 

	return xmlhttp; 
}
//--------------Cambiar en la BD
//---Ver imagen
function VerImagen(id){
	
}
//-----agregar productosa la cotizacion
function AgregarProductos(idproducto, idusuario, idcotizacion){
		var ajax=nuevoAjax();
		ajax.open("POST", "cot/detalle.php", true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("idproducto="+idproducto+"&idusuario="+idusuario+"&idcotizacion="+idcotizacion);
		//alert(idcotizacion);
		ajax.onreadystatechange=function()
		{
			if (ajax.readyState==4)
			{

				$('DivListaProductos').innerHTML=ajax.responseText;
				
			}
			
		}
		

}
function CambiarCantidad(idproducto, idusuario, idcotizacion, cantidad){
		var ajax=nuevoAjax();
		ajax.open("POST", "cot/detalle.php", true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("idproducto="+idproducto+"&idusuario="+idusuario+"&idcotizacion="+idcotizacion+"&cantidad="+cantidad);
		//alert(cantidad);
		ajax.onreadystatechange=function()
		{
			if (ajax.readyState==4)
			{

				$('DivListaProductos').innerHTML=ajax.responseText;
				
			}
			
		}
		

}

function VerProductos(idcategorias, idcotizacion){
		var ajax=nuevoAjax();
		ajax.open("POST", "cot/VerProductos.php", true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("idcategorias="+idcategorias+"&idcotizacion="+idcotizacion);
		$('DivVerProductos').innerHTML="Buscando productos...";
		ajax.onreadystatechange=function()
		{
			if (ajax.readyState==4)
			{

				$('DivVerProductos').innerHTML=ajax.responseText;
				
			}
			
		}
		

}


//******funciones para pedids

function PAgregarProductos(idproducto, idusuario, idpedido){
		var ajax=nuevoAjax();
		ajax.open("POST", "ped/detalle.php", true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("idproducto="+idproducto+"&idusuario="+idusuario+"&idpedido="+idpedido);
		//alert(idcotizacion);

		ajax.onreadystatechange=function()
		{
			if (ajax.readyState==4)
			{

				$('DivListaProductos').innerHTML=ajax.responseText;
				
			}
			
		}
		

}
function PCambiarCantidad(idproducto, idusuario, idpedido, cantidad){
		var ajax=nuevoAjax();
		ajax.open("POST", "ped/detalle.php", true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("idproducto="+idproducto+"&idusuario="+idusuario+"&idpedido="+idpedido+"&cantidad="+cantidad);
		//alert(cantidad);
		ajax.onreadystatechange=function()
		{
			if (ajax.readyState==4)
			{

				$('DivListaProductos').innerHTML=ajax.responseText;
				
			}
			
		}
		

}

function PVerProductos(idcategorias, idpedido){
		var ajax=nuevoAjax();
		ajax.open("POST", "ped/VerProductos.php", true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("idcategorias="+idcategorias+"&idpedido="+idpedido);
				$('DivVerProductos').innerHTML="Buscando productos...";
		ajax.onreadystatechange=function()
		{
			if (ajax.readyState==4)
			{

				$('DivVerProductos').innerHTML=ajax.responseText;
				
			}
			
		}
		

}


//Aceptar solo números y decimales
var nav4 = window.Event ? true : false;
function acceptNum(evt){
//Backspace = 8, Enter = 13, '0' = 48, '9' = 57, 
var key = nav4 ? evt.which : evt.keyCode;
return (key <= 13 || (key >= 48 && key <= 57)|| key==46);
}


