function addLoadEvent(func) {
  	var oldonload = window.onload;
  	if (typeof window.onload != 'function') {
    	window.onload = func;
  	} else {
    	window.onload = function() {
      	oldonload();
      	func();
    	}
  	}
}
addLoadEvent(linkDropListsOnLoad);

//pick-ups 0 - 6
//crossover 0 - 8
//suv is 0 - 8 
//van is 0 - 15

function linkDropLists(source,targetId) 
{
	var opt = source.selectedIndex;
	
	if (source[opt].value != ' ') 
	{	
		var sel = document.getElementById(targetId);
		
		removeChildNodes(sel);
		
		switch(opt)
		{
			case 0:
				var numPass = 0;
				break;
			case 1:
				var numPass = 8;
			  	break;    
			case 2:
			  	var numPass = 6;
			  	break;
			case 3:
			  	var numPass = 8;
			  	break;
			case 4:
			  	var numPass = 15;
			  	break;				
			default:
			  	var numPass = null;
		}
		
		for (var i = 0; i < numPass + 1; i++) 
		{
			var opt = document.createElement("option");				
			sel.options.add(opt);
			opt.text = i;
			opt.value = i;
		}
	}
}

function linkDropListsOnLoad() 
{
	var vehType = document.getElementById('vehType');
	
	if (vehType) {
	
		var opt = vehType.selectedIndex;
		
		if (vehType[opt].value != ' ') {			
		
			var sel = document.getElementById('additionalPassengers');
			
			if (sel) {
			
				var curValue = sel.value;

				removeChildNodes(sel);
				
				switch(opt)
				{
					case 0:
						var numPass = 0;
						break;
					case 1:
						var numPass = 8;
					  	break;    
					case 2:
					  	var numPass = 6;
					  	break;
					case 3:
					  	var numPass = 8;
					  	break;
					case 4:
					  	var numPass = 15;
					  	break;				
					default:
					  	var numPass = null;
				}
				
				for (var i = 0; i < numPass + 1; i++) 
				{
					var opt = document.createElement("option");				
					sel.options.add(opt);
					opt.text = i;
					opt.value = i;
				}
				
				sel.value = curValue;
			}
		}		
	}
}

function removeChildNodes(ctrl)
{
  while (ctrl.childNodes[0])
  {
    ctrl.removeChild(ctrl.childNodes[0]);
  }
}
