function MM_reloadPage(init) {
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function borrandodatos(){
       if (confirm ("¿ Deseas eliminar estos datos? "))
	     { return true ;}
		 else 
		 { return false ;}
		 }	
		 	   
function cambia(archivo) {
           if (archivo != "") {
             document.location=archivo;
                    } }

 
function buyItem(newItem, newPrice, newQuantity) {
		if (newQuantity <= 0) {
			rc = alert('La cantidad ingresada es incorrecta');
			return false;
		}
		if (confirm('¿Agregar '+newQuantity+' '+newItem+' al pedido?')) {
			index = document.cookie.indexOf("TheBasket");
			countbegin = (document.cookie.indexOf("=", index) + 1);
        		countend = document.cookie.indexOf(";", index);
	        	if (countend == -1) {
        	    		countend = document.cookie.length;
        		}
	                document.cookie="TheBasket="+document.cookie.substring(countbegin, countend)+"["+newItem+","+newPrice+"#"+newQuantity+"]";
               		// siguiente linea enviar al formulario, si es compra multiple quitar.
                 	top.location = "./index.php?id=32";
		       }
	          	return true;  
	          	}
	
	

function resetShoppingBasket() {
		index = document.cookie.indexOf("TheBasket");
		document.cookie="TheBasket=.";
                                     	}

				
function alterError(value) {
		if (value<=0.99) {
			newPounds = '0';
		} else {
			newPounds = parseInt(value);
		}
		newPence = parseInt((value+.0008 - newPounds)* 100);
		if (eval(newPence) <= 9) newPence='0'+newPence;
		newString = newPounds + '.' + newPence;
		return (newString);
	}
	
	
	
function showItems() {
		index = document.cookie.indexOf("TheBasket");
		countbegin = (document.cookie.indexOf("=", index) + 1);
        	countend = document.cookie.indexOf(";", index);
        	if (countend == -1) {
            		countend = document.cookie.length;
        	}
		fulllist = document.cookie.substring(countbegin, countend);
		totprice = 0;
		document.writeln('<form><table border="0" cellspacing="2" width="560" bgcolor="f5f5f5">');

document.writeln('<TR bgcolor="#c4e0f5"><TD width="250" height="25"><b>Producto</b></TD><TD width="80" align="right"><b>Cantidad</b></TD><TD width="120" align="right"><b>Costo x unidad</b></TD><td width="100" align="right"><b>Costo total</b><TD width="90" align="center"><b>Eliminar</b></TD></TR>');
		itemlist = 0;
		for (var i = 0; i <= fulllist.length; i++) {
			if (fulllist.substring(i,i+1) == '[') {
				itemstart = i+1;
			} else if (fulllist.substring(i,i+1) == ']') {
				itemend = i;
				thequantity = fulllist.substring(itemstart, itemend);
				itemtotal = 0;
				itemtotal = (eval(theprice*thequantity));
				temptotal = itemtotal * 100;
				var tax = itemtotal / 100 * (20 - 0);
    				tax = 0
				totprice = totprice + itemtotal + tax;
				itemlist=itemlist+1;
document.writeln('<tr bgcolor="#d3d3d3"><td>'+theitem+'</td><td align=right>'+thequantity+'</td><td align=right>'+theprice+'</td><td align=right>'+alterError(itemtotal)+'</td><td align=center><input TYPE="button" NAME="remove" VALUE="Quitar" onclick="javascript:removeItem('+itemlist+')"></td></tr>');
			} else if (fulllist.substring(i,i+1) == ',') {
				theitem = fulllist.substring(itemstart, i);
				itemstart = i+1;
			} else if (fulllist.substring(i,i+1) == '#') {
				theprice = fulllist.substring(itemstart, i);
				itemstart = i+1;
			}
		}
		document.writeln('<tr><td colspan=3><b>Subtotal</b></td><td align=right>MNX '+alterError(totprice)+'</td><td>&nbsp;</td></tr>');
		document.writeln('</TABLE>');		
	}
	
	


  function showItems2() {
        index = document.cookie.indexOf("TheBasket");
	countbegin = (document.cookie.indexOf("=", index) + 1);
   	countend = document.cookie.indexOf(";", index);
   	if (countend == -1)
   	 { countend = document.cookie.length; }
    fulllist = document.cookie.substring(countbegin, countend);
	totprice = 0;
	itemlist = 0;
	for (var i = 0; i <= fulllist.length; i++)
	 {
      if (fulllist.substring(i,i+1) == '[')
       { itemstart = i+1; }
      else if (fulllist.substring(i,i+1) == ']')
       {
       itemend = i;
	   thequantity = fulllist.substring(itemstart, itemend);
	   itemtotal = 0;
	   itemtotal = (eval(theprice*thequantity));
	   temptotal = itemtotal * 100;
	   var tax = itemtotal / 100 * (10 - 0);
           tax = 0;
	   totprice = totprice + itemtotal + tax;
	   itemlist=itemlist+1;
	   document.writeln('<INPUT TYPE="hidden" NAME="Producto'+itemlist+'" VALUE="'+theitem+'" SIZE="40">');
	   document.writeln('<INPUT TYPE="hidden" NAME="Cantidad'+itemlist+'" VALUE="'+thequantity+'" SIZE="40">')
	   document.writeln('<INPUT TYPE="hidden" NAME="ProductoTotal'+itemlist+'" VALUE="'+alterError(itemtotal)+'" SIZE="40">'); }
	  else if (fulllist.substring(i,i+1) == ',')
	   {
	   theitem = fulllist.substring(itemstart, i);
	   itemstart = i+1; }
	  else if (fulllist.substring(i,i+1) == '#')
	   {
	    theprice = fulllist.substring(itemstart, i);
	    itemstart = i+1; }
     }
   
    if (totprice <= 0) {
	 alert("Favor de verificar que haya servicios a contratar.");
	 top.location = "index.php?id=7"; }
	 
    document.writeln('<INPUT TYPE="hidden" NAME="Total" VALUE="'+alterError(totprice)+'" SIZE="40">');
  }
	
		
  function Total()
   { document.writeln(alterError(totprice)); }
    


function removeItem(itemno) {
		newItemList = null;
		itemlist = 0;
		for (var i = 0; i <= fulllist.length; i++) {
			if (fulllist.substring(i,i+1) == '[') {
				itemstart = i+1;
			} else if (fulllist.substring(i,i+1) == ']') {
				itemend = i;
				theitem = fulllist.substring(itemstart, itemend);
				itemlist=itemlist+1;
				if (itemlist != itemno) {
					newItemList = newItemList+'['+fulllist.substring(itemstart, itemend)+']';
				}
			}
		}
		index = document.cookie.indexOf("TheBasket");
		document.cookie="TheBasket="+newItemList;
		top.location = "./index.php?id=31";
	}

function clearBasket() {
		if (confirm('¿Desea terminar su solicitud?')) {
			index = document.cookie.indexOf("TheBasket");
			document.cookie="TheBasket=.";
			top.location = "./index.php";
		}
	}
	
					
function Enviar(form) {
for (i = 0; i < form.elements.length; i++) {
if (form.elements[i].type == "text" && form.elements[i].value == "") {
alert("Favor complete todos los campos del formulario"); form.elements[i].focus();
return false; }
}
form.submit();
}


function panino(){
var indice=document.form1.estado.options[document.form1.estado.selectedIndex].value;
var texto=new Array('Gastos de Envio $0,00','Gastos de Envio $100,00','Gastos de Envio $150,00');
document.getElementById("resumen").firstChild.nodeValue=texto[indice];
}

