function openWindow(urlDestino, width, height){
  var x = (screen.width-width)/2;
  var y = (screen.height-height)/2;
  var op='scrollbars=1,resizable=1,menubar=0,statusbar=0,location=0,toolbar=0,width='+width+',height='+height+',left='+x+',top='+y;
  window.open(urlDestino,"Warning",op).focus();
};

function compareDiscs(id1, id2) {
  var p1=parseFloat(document.getElementById("discP"+id1).value); 
  var p2=parseFloat(document.getElementById("discP"+id2).value);  
  return p1<p2;
};

function calcDiscount(grpCont) {
   var discV=new Array();
   var discT=0;
   var price=document.getElementById("curPrice").firstChild.nodeValue;
   for (i=1; i<grpCont+1; i++) {
     var grp="group"+i;
     for (j=0; j<document.getElementsByName(grp).length; j++) {
       var id=document.getElementsByName(grp)[j].value;
       document.getElementById("disc"+id).style.visibility="hidden";
       if (document.getElementsByName(grp)[j].checked) discV.push(id);
    }
   }
   discV.sort(compareDiscs);

   for (i=0; i<discV.length; i++) {
     document.getElementById("disc"+discV[i]).style.visibility="visible";
     var percent=document.getElementById("discP"+discV[i]).value; 
     var disc=parseFloat(parseFloat(price)-parseFloat(discT))*parseFloat(percent)/100;	 
     discT=parseFloat(discT)+parseFloat(disc);
     document.getElementById("discV"+discV[i]).firstChild.nodeValue=disc.toFixed(2);
   }
   
   document.getElementById("curDisc").firstChild.nodeValue=(parseInt(discT*100)/100).toFixed(2);
   document.getElementById("endPrice").firstChild.nodeValue=(parseInt((parseFloat(price)-parseFloat(discT))*100)/100).toFixed(2);
};    
