var downloaded_expanded_form = false;
function expand_form() {
	if ( downloaded_expanded_form )
		show_expanded_form_html();
	else
		download_form(get_make(), get_model());
}
function download_form(make, model) {
	downloaded_expanded_form = true;
	var xhr;
	if (window.XMLHttpRequest) { 
		xhr = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		xhr = new ActiveXObject("Microsoft.XMLHTTP");  // Internet Explorer 
	} else {
		return;
	}
	xhr.onreadystatechange = function() { 
			if (xhr.readyState == 4 ) {
				if ( xhr.status == 200 ) {
					var div = document.createElement('div');
					div.innerHTML = xhr.responseText;
					show_expanded_form_html();
					document.getElementById('big_form_ph').appendChild(div);
				}
			}
		} // end function
	xhr.open('GET', '/metasearch/make_picture.php?make='+make+'&model='+model, true);
	xhr.send(null);
}
function show_expanded_form_html() {
	document.getElementById('big_form_ph').style.display = 'block';

	floatList('big_form_ph','FloatSearch').check();
	pl_focused++;
}
function hide_form() {
	document.getElementById('big_form_ph').style.display = 'none';
	pl_focused = 0;
}
function make_selected() {
	_select_make(document.getElementById(get_make_id()).selectedIndex);
}
function select_make_and_model(make_id,model_id) {
	_select_model(model_id);
	select_make2(make_id);
	submit_if_ms();
}
function model_selected() {
	var s = document.getElementById(get_model_id());
	_select_model(s.options[s.selectedIndex].value);
}
function get_make() {
	return document.getElementById(get_make_id()).selectedValue;
}
function get_model() {
	return document.getElementById(get_model_id()).selectedValue;
}
function select_row(row_id, model_row_elem) {
	var elem = document.getElementById(row_id);
	if ( elem == model_row_elem || elem == null )
		return elem;
	else if ( model_row_elem != null )
		model_row_elem.style.background = model_row_elem.prev_color;

	elem.prev_color       = elem.style.background;
	elem.style.background = '#ff0000';
	
	return elem;
}
var model_row_elem, current_model;
function select_model(model_id) {
	_select_model(model_id);
	set_selected(document.getElementById(get_model_id()), model_id);
}
function select_model3(model_id) {
	select_model(model_id);
	submit_if_ms();
}
function submit_if_ms() {
	if (document.getElementById(get_make_id())!=null) { // in meta search
		document.forms['search_form_1'].submit();
		loading_func(null);
	}
}
function _select_model(model_id) {
	if ( current_model == model_id )
		return;
	current_model = model_id;
	model_row_elem = select_row('mod_'+model_id, model_row_elem);
	
}
var pl_focused = 0;
function combo_blur() {
	if (pl_focused==0)
		hide_form();
}
function pl_focus() {
	show_expanded_form_html();
}
function pl_blur() {
	if (pl_focused==0)
		hide_form();
}
var make_row_elem, current_make;
function select_make(make_id) {
	select_make2(make_id, 'ANY');
}
function select_make2(make_id,selected_model) {
	_select_make(make_id);
	set_selected(document.getElementById(get_make_id()), make_id);
	
	MakeModel.populateModel(get_make_id(), get_model_id(), get_model_label_id(), selected_model);
}
function get_make_id() {
	return document.getElementById('make1') == null ? 'make' : 'make1';
}
function get_model_id() {
	return document.getElementById('model1') == null ? 'model' : 'model1';
}
function get_model_label_id() {
	return document.getElementById('model_label1') == null ? 'model_label' : 'model_label1';
}
function loadModelsList(make_id) {
	var xhr;
	if (window.XMLHttpRequest) { 
		xhr = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		xhr = new ActiveXObject("Microsoft.XMLHTTP");  // Internet Explorer 
	} else {
		return;
	}
	xhr.onreadystatechange = function() { 
			if (xhr.readyState == 4 ) {
				if ( xhr.status == 200 ) {
					var div = document.getElementById('models_list');
					div.innerHTML = xhr.responseText;
					select_model(current_model);
				}
			}
		} // end function
	xhr.open('GET', '/metasearch/model_picture.php?make='+make_id, true);
	xhr.send(null);
} // end function loadModelsList
function _select_make(make_id) {
	make_row_elem = select_row('mak_'+make_id, make_row_elem);
	if ( make_id == current_make && make_id != 'ANY' )
		return;
	current_make = make_id;

	loadModelsList(make_id);
}
function set_selected(elem, value) {
	for (var i=0; i < elem.options.length ; i++ ) {
		if ( elem.options[i].value == value ) {
			elem.selectedIndex = i;
			break;
		}
	}
}
function getY( oElement ){
	var iReturnValue = 0;
	while( oElement != null ) {
		iReturnValue += oElement.offsetTop;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}
function getX( oElement ){
	var iReturnValue = 0;
	while( oElement != null ) {
		iReturnValue += oElement.offsetLeft;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}
var nn=(navigator.appName.indexOf("Netscape")!=-1);
var dD=document,dH=dD.html,dB=dD.body,px=dD.layers?'':'px';
function floatList(id,top_id){
	var A=dD.getElementById?dD.getElementById(top_id):dD.all?dD.all[top_id]:dD.layers[top_id];
	var L=dD.getElementById?dD.getElementById(id):dD.all?dD.all[id]:dD.layers[id];
	this[id+'O']=L;
	if(dD.layers) 
		L.style=L;

	if (L.style.display=='none')
		return;

	L.check = function () {
			var float_height = L.offsetHeight;
			
			this.style.top  = getY(A) + 'px';
			this.style.left = (getX(A)+A.offsetWidth) + 'px';
			
			setTimeout(this.id+'O.check()',80);
		};
	return L;
} // end function floatList