/////////////////////////powered by punknomas@hotmail.com/////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
function objetoAjax(){
	var xmlhttp=false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
		   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
  		}
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}



function limpiar_carrito1()
{
	
	divresultado=document.getElementById('show_carrito_now');

	var Aleatorio=parseInt(Math.random()*99999999);

	ajax=new objetoAjax();

	ajax.open("GET","limpiar_carrito1.php?rand=" + Aleatorio,true);

	ajax.onreadystatechange=useHttpResponse;

	ajax.send(null) ;
	
}

function load_page(url,capa)

{

	

	divresultado=document.getElementById(capa);

	var Aleatorio=parseInt(Math.random()*99999999);

	ajax=new objetoAjax();

	ajax.open("GET",url +"?rand=" + Aleatorio,true);

	ajax.onreadystatechange=useHttpResponse;

	ajax.send(null)

}

function precio_igv(estado,total,saldo)
{
	if (estado=='si')
	{
	IGV=Number(total)*Number(0.19);
	imprimir=Number(IGV)+Number(total);
	if (saldo>=imprimir)
	{
	document.getElementById('capa_precio').innerHTML=imprimir.toFixed(2);
	document.getElementById('texto_igv').innerHTML='CON IGV';
	document.frmigv.igv.value=imprimir.toFixed(2)+"|"+estado;
	}
	else
	{
	alert('Monto con IGV es: '+imprimir.toFixed(2)+'\n Saldo actual: '+saldo+' \n Usted no cuenta con suficiente saldo para pagar con igv')	
	}
	
	}
	else
	{
	imprimir=Number(total);
	document.getElementById('capa_precio').innerHTML=imprimir.toFixed(2);	
	document.getElementById('texto_igv').innerHTML='SIN IGV';
	document.frmigv.igv.value=imprimir.toFixed(2)+"|"+estado;
	}
	
}


function precio_igv_registrado(estado,total)
{
	if (estado=='si')
	{
	IGV=Number(total)*Number(0.19);
	imprimir=Number(IGV)+Number(total);
	
	document.getElementById('capa_precio').innerHTML=imprimir.toFixed(2);
	document.getElementById('texto_igv').innerHTML='CON IGV';
	document.frmigv.igv.value=imprimir.toFixed(2)+"|"+estado;
	
	}
	else
	{
	imprimir=Number(total);
	document.getElementById('capa_precio').innerHTML=imprimir.toFixed(2);	
	document.getElementById('texto_igv').innerHTML='SIN IGV';
	document.frmigv.igv.value=imprimir.toFixed(2)+"|"+estado;
	}
	
}



function finalizar(capa)

{

	
	divresultado=document.getElementById(capa);

	igv=document.frmigv.igv.value;
	var Aleatorio=parseInt(Math.random()*99999999);

	ajax=new objetoAjax();
	comen=document.frmcomentario.comentario.value;
	ajax.open("GET","mete_producto1.php?formulario=true&igv="+igv+"&comentario="+comen+"&rand=" + Aleatorio,true);

	ajax.onreadystatechange=useHttpResponse;

	ajax.send(null)
}

function finikitar()

{
if (document.form1.txt_empresa.value=='')
{
alert('Debe ingresar el nombre de su empresa')
document.form1.txt_empresa.focus();
 return false; 
}

if (document.form1.txt_ruc.value=='')
{
alert('Debe ingresar su RUC')
document.form1.txt_ruc.focus();
 return false; 
}
 if (document.form1.txt_ruc.value.length < 11)
  {
    alert("El ruc debe ser de 11 digitos");
   document.form1.txt_ruc.focus();
 return false; 
  }


if (document.form1.txt_oficina.value=='')
{

alert('Debe ingresar el telefono de su oficina')
document.form1.txt_oficina.focus();
 return false; 

}


  
/*if (document.form1.txt_web.value=='')
{

alert('Debe ingresar la direccion de su sitio web')
document.form1.txt_web.focus();
 return false; 

}*/
/*
if (document.form1.txt_direccion.value=='')
{
alert('Debe ingresar su direccion')
document.form1.txt_direccion.focus();
 return false; 
}
*/

if (document.form1.txt_nombres.value=='')
{
alert('Debe ingresar su Nombre')
document.form1.txt_nombres.focus();
 return false; 
}

if (document.form1.txt_apellidos.value=='')
{
alert('Debe ingresar su apellido')
document.form1.txt_apellidos.focus();
 return false; 
}

if (document.form1.txt_email.value=='')
{
alert('Debe ingresar su Email')
document.form1.txt_email.focus();
 return false; 
}

if ((document.form1.txt_email.value.indexOf ('@', 0) == -1)||(document.form1.txt_email.value.length < 5))
	{ 
    alert("Escriba una dirección de correo válida en el campo \"Email\" Ej: nombre@correo.com"); 
    document.form1.txt_email.focus();
     return false; 
  }
  
 if (document.form1.txt_telefonos.value=='')
{
alert('Debe ingresar su Telefono')
document.form1.txt_telefonos.focus();
 return false; 
}

 if (document.form1.txt_telefonos.value.length < 7)
  {
    alert("El telefono debe tener como minimo 7  digitos");
   document.form1.txt_telefonos.focus();
 return false; 
  }
  
  
   if (document.form1.txt_celular.value=='')
{
alert('Debe ingresar su celular')
document.form1.txt_celular.focus();
 return false; 
}

if (document.form1.txt_celular.value.length < 8)
{
    alert("El Celular debe tener como minimo 8  digitos");
   document.form1.txt_celular.focus();
 return false; 
  }

	emp=document.form1.txt_empresa.value;
	ruc=document.form1.txt_ruc.value;
	ofi=document.form1.txt_oficina.value;
	web=document.form1.txt_web.value;
	dir=document.form1.txt_direccion.value;
	nom=document.form1.txt_nombres.value;
	ape=document.form1.txt_apellidos.value;
	ema=document.form1.txt_email.value;
	tel=document.form1.txt_telefonos.value;
	cel=document.form1.txt_celular.value;
	

	divresultado=document.getElementById('show_carrito_now');

	var Aleatorio=parseInt(Math.random()*99999999);
	
	ajax=new objetoAjax();

	ajax.open("GET","show_carro.php?empresa="+emp+"&ruc="+ruc+"&oficina="+ofi+"&web="+web+"&direccion="+dir+"&nombres="+nom+"&apellidos="+ape+"&email="+ema+"&telefonos="+tel+"&celular="+cel+"&igv="+igv+"&finikitar=true&rand=" + Aleatorio,true);

	ajax.onreadystatechange=useHttpResponse;

	ajax.send(null)
}




function add_carrito(cantidad,codigo,capa,tabla)

{

	divresultado=document.getElementById(capa);

	var Aleatorio=parseInt(Math.random()*99999999);

	ajax=new objetoAjax();

	ajax.open("GET","mete_producto.php?cantidad="+cantidad+"&codigo="+codigo+"&tabla="+tabla+"&rand=" + Aleatorio,true);

	ajax.onreadystatechange=useHttpResponse;

	ajax.send(null)

}




function editar_cantidad(linea,codigo)

{

	divresultado=document.getElementById('editar'+linea+'cantidad');

	var Aleatorio=parseInt(Math.random()*99999999);

	ajax=new objetoAjax();

	ajax.open("GET","editar_cantidad.php?div="+linea+"&codigo="+codigo+"&rand=" + Aleatorio,true);

	ajax.onreadystatechange=useHttpResponse;

	ajax.send(null)

}



function editar_cantidad_save(cantidad,linea,capa)
{

	divresultado=document.getElementById(capa);

	var Aleatorio=parseInt(Math.random()*99999999);

	ajax=new objetoAjax();

	ajax.open("GET","mete_producto.php?cantidad="+cantidad+"&linea="+linea+"&rand=" + Aleatorio,true);

	ajax.onreadystatechange=useHttpResponse;

	ajax.send(null)
	

}


function eliminar_carrito(url,capa)

{
	divresultado=document.getElementById(capa);

	var Aleatorio=parseInt(Math.random()*99999999);

	ajax=new objetoAjax();

	ajax.open("GET",url +"&rand=" + Aleatorio,true);

	ajax.onreadystatechange=useHttpResponse;

	ajax.send(null)

}

function useHttpResponse() {

	

   if (ajax.readyState == 4) 

   {

   		 if(ajax.status == 200) 

		{

			divresultado.innerHTML=ajax.responseText;

			

		}

  } 

  else 

  {

  divresultado.innerHTML = '<br /><br /><br /><div align=center style="font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#F6A019">Cargando...<br /><img  src="images/loading.gif" /></div>';
  

  }


}


function useHttpResponses() {

	

   if (ajax.readyState == 4) 

   {

   		 if(ajax.status == 200) 

		{

			divresultado.innerHTML=ajax.responseText;

			

		}

  } 

  else 

  {

  divresultado.innerHTML = '<br /><br /><br /><div align=center style="font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#F6A019">Cargando...<br /><img  src="images/loading.gif" /></div>';
  

  }


}