function openWindow(url)
{
		openwin = this.open(url,"ctrlwindow","width=300,height=260,toolbar=no,scrollbars=no,resizable=no");
		openwin.focus();
}


function swapImage(oImg)
{
	var strOver  = "_up"
	var strOff = "_over"
	
	currImg = oImg.src;

	if (currImg.indexOf(strOver) != -1)
		oImg.src = currImg.replace(strOver,strOff)
	else
		oImg.src = currImg.replace(strOff,strOver)
}


function externalLinks()
{ 
	if (!document.getElementsByTagName) return; 
	
	var anchors = document.getElementsByTagName("a"); 
	for (var i=0; i<anchors.length; i++)
	{
		var anchor = anchors[i]; 
		if (anchor.getAttribute("href") && anchor.getAttribute("rel")) 
			anchor.target = anchor.getAttribute("rel"); 
	} 
}
window.onload = externalLinks;

function switchImage(img_id){
	var img = document.getElementById(img_id);
	if (img != null){
		var source = img.src;
		if (source.indexOf("_on") == -1){
			source = source.replace("_off", "_on");
		} else{
			source = source.replace("_on", "_off");
		}
		img.src = source;
	}
}

function renderPrice(price){
	price = parseInt(price)/100;
	if(price%1==0){
		price += '.00';
	} else {
		price += '0';
	}
	return price.replace('.', ',');
}

function calcPrice(){
	var loc = locs[parseInt($('#locId').val())];
	var amount = parseInt($('#amount').val());
	if(amount < 1 || isNaN(amount)){
		amount = 1;
		$('#amount').val(amount);
	}
	var total = amount * parseInt(loc['cost']);
	total = renderPrice(total);
	$('#costField').html(total);
	$('#cityField').html(loc['city']);
	$('#amountField').html(amount);
	if(amount == 1){
		$('#personField').html('persoon');
	} else {
		$('#personField').html('personen');
	}

}
var oldAmount = 1;
$(document).ready(function(){
	$('.loc').click(function(){
		var id = parseInt(this.id.split('_')[1]);
		var loc = locs[id];
		$('#infoCity').html(loc['city']);
		$('#infoLocation').html(loc['location']);
		$('#infoTime').html(loc['time']);
		$('#infoRetour').html(loc['retour']);
		$('#infoCost').html('&euro;&nbsp;'+renderPrice(loc['cost']).replace('.', ','));
		$('#pickupField').html(loc['city']);
		$('#locId').val(id);
		calcPrice();
		$('#reserveren').css({
			display:'block'
		});
	});
	var t = null;
	$('#amount').click(function(){
		this.select();
	});
	$('#amount').keydown(function(){
		clearTimeout(t);
		t = setTimeout(function(){
			calcPrice();
		}, 500);
	});
	
	$('#mask,#popup').click(function(){
		$('#mask,#popup').remove();
	});

});
