	function clearText(thefield){if (thefield.defaultValue== thefield.value)	thefield.value = ""} 						
	function insertText(thefield){if ( thefield.value == "" )	thefield.value = thefield.defaultValue} 						

//   <div class="cBoard">
// 		<div class="image"><img src="res/board01.gif"></div>
// 		<div class="name">FiberJet 2008</div>
// 	</div>

var shoeSizes = [
	[35, 35.5,  36,  37, 37.5,  38, 38.5,  39,  40,   41,   42,   43,   44,   45,   46, 46.5, 48.5,  99] , // EU
	[3.5,   4, 4.5,   5,  5.5,   6,  6.5,   7, 7.5,    8,  8.5,    9, 10.5, 11.5,   12, 12.5,   14,  99],  // US M
	[5,   5.5,   6, 6.5,    7, 7.5,    8, 8.5,   9,  9.5,   10, 10.5,   12,   13, 13.5,   14, 15.5,  99],  // US F
	[3,   3.5,   4, 4.5,    5, 5.5,    6, 6.5,   7,  7.5,    8,  8.5,   10,   11, 11.5,   12, 13.5,  99],  // UK M
	[2.5,   3, 3.5,   4,  4.5,   5,  5.5,   6, 6.5,    7,  7.5,    8,  9.5, 10.5,   11, 11.5,   13,  99],  // UK F
	[228, 231, 235, 238,  241, 245,  248, 251, 254,  257,  260,  267,  273,  279,  282,  286,  292, 999],  // Mondopoint
];

var idLanguage = 0;

function isValidEmail(address) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if (reg.test(address) == false) return false; else return true;
}

function boardToolSubmit() {
	count = 0;
	for (var i=0; i<boards.length; i++)
		if (boards[i].active) count++;
	
	if (!count) { alert(error[14]); accordion.display(0); return; }
	
	sex = $("sex").value=="1"?1:0;

	if (!(weight = $("weight").value).length) { alert(error[0]); return; } // Weight is not filled in!
	weight = parseFloat(weight);
	if (isNaN(weight)) { alert(error[1]);  return; } // Weight is not correctly filled in!
	if ($("uw").value=='1') weight = 0.45359237 * weight;
	if (weight<20 || weight>200) { alert(error[2]); return; } // Out of range!

	if (!(height = $("height").value).length) { alert(error[3]); return; } // Height is not filled in!
	height = parseFloat(height);
	if (isNaN(height)) { alert(error[4]); return; } // Height is not correctly filled in!
	if ($("uh").value=='1') height = 2.54 * height;
	if (height<50 || height>250) { alert(error[5]); return; } // Out of range!

	var idx = 0;
	if (!(shoesize = $("shoesize").value).length) { alert(error[6]); return; } // Shoesize not filled in!
	shoesize = parseFloat(shoesize);
	if ($("us").value==0) {
		if (shoesize<35 || shoesize>=48.5) { alert(error[7]); return; } // Out of range [EU]
	} else if ($("us").value==1) {
		if (sex==0) {
		 	if (shoesize<3.5 || shoesize>14) { alert(error[7]); return; }	// Out of range [US, M]
			idx = 1;
		} else {
			if (shoesize<5 || shoesize >15.5) { alert(error[7]); return; }  // Out of range [US, F]
			idx = 2;
		}
	} else {
		if (sex==0) {
			if(shoesize<3||shoesize>13.5) {alert(error[7]);return;}		// Out of range [UK, M]
			idx = 3;
		} else {
			if(shoesize<2.5||shoesize>13) {alert(error[7]);return;}		// Out of range [UK, F]
			idx=4;
		}
	}
	
	form = $("selector-form"); types = '';
	for(var i=0; i<12;i++) {
		if (form.elements.namedItem('type['+i+']').checked)
			types += (types.length==0?'':',')+i;
	}

	for(var i=1; i<shoeSizes[idx].length; i++)
		if (shoesize>=shoeSizes[idx][i-1]&&shoesize<shoeSizes[idx][i]) { shoesize = shoeSizes[5][i-1]; break; }
	
	if (!(age=$("age").value).length){alert(error[8]);return;} // Age is not filled in!
	age=parseInt(age);
	if (isNaN(age)){alert(error[9]);return;} // Age is not correctly filled in!
	if (age<10||age>90){alert(error[10]);return;} // Out of range

	if (!(email=$("email").value).length){alert(error[11]);return}
	if (!isValidEmail(email)){alert(error[12]);return;}

	$('btload').setStyle('display','');

	name = $("name").value;
	country = parseInt($("country").value);
	surftype = $("surftype").value;
	if (isNaN(country)) country = 0;

	querystring  = "http://"+document.domain+"/index.php?id=238&type=60&L=" + idLanguage;
	querystring += "&tx_commerce_pi8[weight]="+weight; // validated float
	querystring += "&tx_commerce_pi8[height]="+height; // validated float
	querystring += "&tx_commerce_pi8[shoesize]="+shoesize; // validated float
	querystring += "&tx_commerce_pi8[age]="+age; // validated integer
	querystring += "&tx_commerce_pi8[sex]="+sex; // validated bool
	querystring += "&tx_commerce_pi8[country]="+country; // validated interger
	querystring += "&tx_commerce_pi8[email]="+email; // validated email
	querystring += "&tx_commerce_pi8[name]="+name; // not validated
	querystring += "&tx_commerce_pi8[skill]="+parseInt($("skill").value);	// int
	querystring += "&tx_commerce_pi8[wave][1]="+parseInt($("wave_1").value);	// int
	querystring += "&tx_commerce_pi8[wave][2]="+parseInt($("wave_2").value);	// int
	querystring += "&tx_commerce_pi8[type]="+types;	// int list
	querystring += "&tx_commerce_pi8[surftype]="+surftype; // int

	htmlRequest = new Request({url:'index.php',
		evalResponse: true,
		onSuccess: function(response) {
			// activate last tab!!!!
			$('btload').setStyle('display','none');
			$('btres').set('text', '');
			$('btres').set('html', response);
			$('btres').setStyle('display', '');
			$('btlist').setStyle('display', 'none');
			accordion.options.block=[];
			accordion.display(2); 
			accordion.options.block=[2];
		}
	}).post(querystring);


}

function checkAvailability() {
	count = 0;
	for (var i=0; i<boards.length; i++)
		if (boards[i].active) count++;
	
	if (!count) { alert(error[14]); accordion.display(0); return; }
 	skill = parseInt($("skill").value);
	if (skill==0) { alert(error[15]); accordion.display(0); return; }
// 	waveL = parseInt($("wave_1").value);
// 	waveH = parseInt($("wave_2").value);
// 	
// 	form = $("selector-form"); types = new array();
// 	for(var i=0; i<12;i++) {
// 		if (form.elements.namedItem('type['+i+']').checked)
// 			types.push(i);
// 	}
	return accordion.display(1);
}


function filterBoards(filter, val) {
	for (var i=0; i<boards.length; i++)
		boards[i].filter(filter, val);
}
  
var Board = new Class({
  
  
	initialize: function(name, image, tag, opt) {
		this.name = name;
		this.image = image;
		this.e = 0;
		
		switch(tag) {
			case 0:	this.tag="tag-new";
			case 1: this.tag="tag-bestseller";
			default: this.tag = 0;
		}
		
		this.btype = opt.btype;
		this.skill = opt.skill;
		this.wave = opt.wave;		
		this.active = true;
		this.filtered = new Array();
		this.filtered[0] = this.wave.slice();
		this.filtered[1] = this.skill.slice();
		this.filtered[2] = this.btype.slice();
	},
	
	render: function() {
		if (this.e) return this.e;
		div1 = new Element('div', {'class': 'image'});
		img = new Element('img', {'src': this.image});
		img.injectInside(div1);
		if (this.tag) {
			span = new Element('div', {'class': this.tag});
			span.injectInside(div1);
		}
		
		div2 = new Element('div', {'class': 'name'}).set('html', this.name);
		ret = new Element('div', {'class': 'cBoard'});
		div1.injectInside(ret);
		div2.injectInside(ret);
		this.e = ret;
		var morph = new Fx.Morph(this.e, {duration: 500, link: 'cancel'});
		this.e.addEvents({
			'onfilterin': function() {morph.start({'opacity': '1'})},
			'onfilterout':function() {morph.start({'opacity': '0.33'})}
		});
		return ret;
	},
	
	filter: function(filter, val) {
		var res = new Array();
		var ok = true;
		exclude = -1;
		switch(filter) {
			case 'slider1':
				if (val==5) res = this.skill;
				else res = this.skill.filter(function(item, index){return item == val;});
				this.filtered[0] = res;
				exclude = 0;
				break;
			case 'slider2':
				res = this.wave.filter(function(item,index){return item>=val.minpos && item <=val.maxpos;});
				this.filtered[1] = res;
				exclude = 1;
				break;
			case 'type':
				if (val.ref.checked) {
					if (val.id!=11) {
						if ((idx = this.btype.indexOf(val.id))==-1)
							this.filtered[2].erase(val.id);
						else if (this.filtered[2].indexOf(val.id)==-1) 
							this.filtered[2].push(val.id);
					} else {
						this.filtered[2].push(val.id);
					}
				} else {
					this.filtered[2].erase(val.id);
				}
				
				res = this.filtered[2];
				exclude=2;
				break;
		}
		
		ok = (res.length>0);
		
		if (ok) {
			for(var i=0; i<this.filtered.length; i++) {
				if (exclude==i) continue;
				if (($type(this.filtered[i])=='array') &&
					(this.filtered[i].length==0)) {
					ok = false; break;
				}
			}
		}
		if (ok) {
			this.e.fireEvent('onfilterin');
			this.active = true;
// 			this.e.setStyle('background', '#000000');
		} else {
			this.e.fireEvent('onfilterout');
			this.active = false;
// 			this.e.setStyle('background', '#FFFFFF');
		}
	}
	
  
  });
  
//   function oc(a) { var o={}; for (i=0;i<a.length;i++)o[a[i]]=''; return o;}
