// Merchant 1.x
// merchant.js
//
// (C) 2003 Multisoftek Bt. <webmaster@merchant.hu>
// All rights reserved.

function popup(name,url){
	var popup=window.open(url,name,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=640,height=568");
	popup.focus();
}

function popupbig(name,url){
	var popup=window.open(url,name,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=800,height=600");
   popup.focus();
}

function download(url){
   window.location=url;
}

function ad(a,b){
   value=1;
   for(i=1;i<=b;i++){
		value=value*a;
   }
   return value;
}

function val(s){
   for(i=0;i<s.length;i++){
		ch=s.substring(i,i+1);
		if(ch<"0"||ch>"9"){
	    	return 0;
		}
   }
   return parseInt(s);
}

function ipart(i){
   return Math.round(i-0.5);
}

function calcresprice(){
   if((val(document.resform.times.value)>0)&(val(document.resform.amount.value)>0)&(document.resform.type.selectedIndex>0)){
		reslevel=val(document.resform.amount.value)+eval("ress" + document.resform.type.selectedIndex);
		times=val(document.resform.times.value);
		if((reslevel>eval("resmax" + document.resform.type.selectedIndex))&(eval("resmax" + document.resform.type.selectedIndex)>0)){
	    	document.resform.amount.value=eval("resmax" + document.resform.type.selectedIndex)-eval("ress" + document.resform.type.selectedIndex);
	    	reslevel=eval("resmax" + document.resform.type.selectedIndex);
		}
		if(val(document.resform.amount.value)==0){
	    	resprice=0;
	    	restime=0;
		}else{
	    	oldreslevel=eval("ress" + document.resform.type.selectedIndex);
	    	if(eval("restype" + document.resform.type.selectedIndex)>0){
	        	resprice=5000*(reslevel*reslevel-oldreslevel*oldreslevel/2)*times;
				resprice=ipart(resprice*eval("restimes" + document.resform.type.selectedIndex));
				restime=ipart(resprice/1000/times/times)+1;
	    	}else{
	        	resprice=(1000+5000*(reslevel-oldreslevel))*times;
				resprice=ipart(resprice*eval("restimes" + document.resform.type.selectedIndex));
				restime=ipart(resprice/250/times/times)+1;
	    	}
		}
	}else{
		resprice=0;
		restime=0;
   } 
   document.resform.price.value=resprice;
   document.resform.time.value=restime;
}

function checkall(form,begin,end){
   var x=!(form.elements[begin].checked);
   for(var i=begin;i<end;i++){
		form.elements[i].checked=x;
   }
}

