// JavaScript Document

window.addEvent('domready', function() {
	
	/*$$('.paypalform').each(function(el) {
		el.addEvent('submit',function(e) {
			
			if($('eula').checked) {
				return true;
			} else {
				e.stop();
				alert("You must agree to the end-user license agreement (step 2)");
			}					  
		});						
	});*/
	
	
	$$('.hint').each(function(el) {
		//el.href = "javascript:void(0);";
		el.addEvent('mouseover', function() {
			$('hintboks_' + el.name).setStyle('display','block');
			//alert("hint nr: " + el.name);							  
		});
		el.addEvent('mouseout', function() {
			$('hintboks_' + el.name).setStyle('display','none');
			//alert("hint nr: " + el.name);							  
		});
	});
	
	$$('.prodattrib').each(function(el) {
		el.addEvent('click',calcCost);		
	});
	
	
	$$('.currencybutton').each(function(el) {
		el.addEvent('click',function() {
			$$('.pricecontainer').setStyle('display','none');
			$$('.pricecontainer_' + el.name).setStyle('display','inline');
			$('activecurid').value = el.name;
			calcCost();
			//$$('.cursymbol').set('html',$('cursymbol_' + el.name).value);							 
		});
   });
});

function calcCost() {
			var totsum = 0;
			var prods = "";
			$$('.prodattrib').each(function(el2) {
				if(el2.checked) {
					totsum += parseInt($('price_' + el2.value).value);
					prods += "<p>&raquo; " + $('shortvalue_' + el2.value).value + "</p>";
				}
			});
			var testRatio = $('curratio_' + $('activecurid').value).value;
			var curratio = parseFloat(testRatio);
			//alert("testRatio = " + testRatio + ", curratio = " + curratio);
			$('totcost').set('html',$('cursymbol_' + $('activecurid').value).value + formatNumber(Math.round(totsum * curratio),0,',','','','','',''));
			$('cartattribs').set('html',prods);
			
			//alert("totsum = " + totsum);
}
// number formatting function
// copyright Stephen Chapman 24th March 2006, 22nd August 2008
// permission to use this function is granted provided
// that this copyright notice is retained intact

function formatNumber(num,dec,thou,pnt,curr1,curr2,n1,n2) {var x = Math.round(num * Math.pow(10,dec));if (x >= 0) n1=n2='';var y = (''+Math.abs(x)).split('');var z = y.length - dec; if (z<0) z--; for(var i = z; i < 0; i++) y.unshift('0'); if (z<0) z = 1; y.splice(z, 0, pnt); if(y[0] == pnt) y.unshift('0'); while (z > 3) {z-=3; y.splice(z,0,thou);}var r = curr1+n1+y.join('')+n2+curr2;return r;}

