var aId = new Array;
var aCoX = new Array;
var aCoY = new Array;
var aType = new Array;
var count = -1;
var n = -1;

function addParking( id, cox, coy, type ) {

	var correctpx = 7;

	count++;
	aId[count] = id;
	aCoX[count] = (cox-correctpx)>0?(cox-correctpx):cox;
	aCoY[count] = (coy-correctpx)>0?(coy-correctpx):coy;
	aType[count] = type;
	n=count;
}

function getSelection() {
	var selection_string = "";
	var obj = document.parking_selection_form.parking_selection;
	
	for( count = 0; count < obj.length; count++ ) {
		if( obj[count].checked == true ) {
			if( selection_string != "" )
				selection_string += ";";
			selection_string += obj[count].value;
		}
	}
	
	return selection_string;
}

function isSelectionMatch( target, source ) {

	if( target == "" ) {
		return true;
	}
	if( source == "" ) {
		return false;
	}

	var result = true;
	var local_count = 0;
	target = target.split(";");
	for( local_count = 0; local_count < target.length; local_count++ ) {
		
		if( source.indexOf(target[local_count])==-1) {
			result = false;
		}
	}
	
	return result;
}

function drawParking() {

	hideParking();
	var selection = getSelection();
	for( count=0; count <= n; count++ ) {
		if( isSelectionMatch( selection, aType[count]) ) {

			if( document.getElementById("parking_selection_mc").checked == false && document.getElementById("parking_selection_hcp").checked == false && document.getElementById("parking_selection_free").checked == false )
			{
				if( aType[count] != "hcp" )
				{
					showParking(aId[count]);
				}
			}
			else
			{
				showParking(aId[count]);
			}
		}
	}
}

function drawFullParking() {
	hideParking();
	
	for( count=0; count <= n; count++ ) {
		if( aType[count] !="hcp" )
		{
			showParking(aId[count]);
		}
	}
	
	var obj = document.parking_selection_form.parking_selection;
	
	for( count = 0; count < obj.length; count++ ) {
		if( aType[count] !="hcp" )
		{
			obj[count].checked = false;
		}
	}
	
}

function hideParking() {
	for( count=0; count <= n; count++ ) {
		document.getElementById("parking_link"+aId[count]).style.display="none";
	}
}

function hideParkingInfo() {
	for( count=0; count <= n; count++ ) {
		document.getElementById("parking_info"+aId[count]).style.display="none";
	}
}

function showParking( id ) {
	
	var obj = document.getElementById("parking_link"+id).style;
	obj.top=aCoX[count]+"px";
	obj.left=aCoY[count]+"px";
	obj.display="block";
}

function showParkingInfo( id ) {
	hideParkingInfo();
	document.getElementById("parking_info"+id).style.display="block";
}
