var euro="€";

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
   var NChar="";
   for (i = 0; i < sText.length&&IsNumber; i++) 
      { 
	      Char = sText.charAt(i); 
	      if (ValidChars.indexOf(Char) >= 0 ) 
    	     {
				 NChar+=Char;
	         }else
			 {
				IsNumber=false;
			}
      }
   return NChar;
}

//second page, selection page

function subtotalcount(id)
{
		
		
	var obj1 = MM_findObj("amount_"+id);
	var obj2 = MM_findObj("price_"+id);
	var obj3 = MM_findObj("totalprice_"+id);
	//var weight = MM_findObj("w_"+id);
	//var total_w = MM_findObj("totalw_"+id);
	obj1.value=IsNumeric(obj1.value);
	precio=obj2.value.replace(",",".").replace(euro,"");
	
	cantidad=obj1.value.replace(",",".").replace(euro,"");
	
//	weight.value=weight.value.replace(",",".").replace(euro,"");
			
	if(cantidad.length==0)cantidad=0;
	if(!IsNumeric(cantidad))cantidad=0;
	operador="*";
	obj3.value=euro+eval(precio+"*"+cantidad).toFixed(2).replace(".",",");
//	total_w.value=eval(weight.value+"*"+cantidad).toFixed(2).replace(".",",");
	suma(); 
}

function suma()
{	
	
	var obj1 = MM_findObj("valornjr");
	var obj2;
	var obj3 = MM_findObj("total_price");			
	var vo = MM_findObj("fee");				
	//var total = MM_findObj("total_price");		
	//var tax_item = MM_findObj("tax");		
	var fee,tax,total_n,total_wt;
	elementos=obj1.value.split(",");
	suma_n=total_wt=0;
	for(i=0;i<=elementos.length-1;i++)
	{
		obj2 = MM_findObj("totalprice_"+elementos[i]);
		//total_w= MM_findObj("totalw_"+elementos[i]);
		valor_bx=obj2.value.replace(",",".").replace(euro,"").replace(/^\s*|\s*$/g,"")
		//total_w.value=total_w.value.replace(",",".").replace(euro,"").replace(/^\s*|\s*$/g,"")
		//total_wt=eval( total_wt+"+"+total_w.value);
		suma_n=eval( suma_n+"+"+valor_bx);
	}
	obj3.value=(euro+(suma_n.toFixed(2))).replace(".",",");
	//fee=total_wt>250?7.5:2.5;
//	vo.value=euro+fee.toFixed(2).replace(".",",");
	tax=0;
/*	tax=eval(suma_n+"*"+tax).toFixed(2);
	tax_item.value=tax.replace(".",",");*/
	total_n=eval(suma_n+"+"+fee+"+"+tax).toFixed(2);
	//total.value=euro+total_n.replace(".",",");
} 

function deleteitem(id,mesaje,mc)
{
	if(confirm(mesaje))
	window.location="auxfiles/sc.php?p_del="+id+"&mc="+mc;	
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
	if (val) { nm=val.id; if ((val=val.value)!="") {
  if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
	if (p<1 || p==(val.length-1)) errors+='- '+nm+' [var.l_valid_mail;htmlconv=no] \n';
  } else if (test!='R') { num = parseFloat(val);
	if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
	if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
	  min=test.substring(8,p); max=test.substring(p+1);
	  if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
	} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' [var.l_valid_required;htmlconv=no]\n'; }
  } if (errors) alert('[var.l_valid_errors;htmlconv=no]\n'+errors);
  document.MM_returnValue = (errors == '');
}
