//-------------------------------------------------------------------
// 	Vehicle Comparision Javascript Functions
//	vehicles to be compared are selected based on ticking checkboxes
//	there are two types of vehicles which can be compared: cars and campervans
//		the checkboxes are named prefix_id
//-------------------------------------------------------------------

//retrieve the selected ids based on the prefix
//	if nothing is selected then return -1
//	max = the number of checkboxes which have been generated
//	TODO: what if only 1 vehicle is selected - should this stil display???
function getVehicleCompareIds(prefix) {
	var ele = null;
	var strId = '';
	var i = 1;
	var ids='';	//build up the list of ids to be returned
	
	var tags = document.getElementsByTagName("INPUT");
	var i=0;
	
	prefix+='_';
	
	while(i < tags.length){ 
		if (tags[i].type == 'checkbox')
		{
			strId = tags[i].id;

			if (strId.indexOf(prefix)==0)
			{
				ele = document.getElementById(strId);
				if (ele.checked)
				{
					ids+=ele.id.substring(ele.id.lastIndexOf('_')+1) + ',';
				}
			}
		}		
		i++ ;	
	}
	
	//either remove the last comma or if nothing has been selected, return -1
	if (ids.length==0)
		ids = -1;
	else
		ids = ids.substring(0,ids.length-1);	

	return ids;
}	//end function - getVehicleCompareIds()


//type=car or campervan
function CompareVehicles(prefix,type){
	var compareIds = getVehicleCompareIds(prefix);	
//	var url='/campervanhire/Pages/CampervanComparison.aspx?type='+type+'&ids='+compareIds;
	var url='/campervanhire/Pages/CampervanComparison.aspx?ids=';

	if (compareIds == '-1')
		alert("Please select a vehicle to compare");
	else if (compareIds.split(',').length>5)
		alert("Sorry you may only compare up to 5 vehicles at any one time");
	else
	{
		if (type=='car')
			url = '/carhire/Pages/CarComparison.aspx?ids=';
		document.location.href = url + compareIds;
//		document.location.href = url;
	}
		//display msg	
}


function setCondenseCompareState(obj,id)
{
	//Set the class of the outer span element:
	//the active class will highlight the vehicle title and display image
	if(obj.checked)							
		document.getElementById(id).className = "active";
	else
		document.getElementById(id).className = "inactive";
}



