//var ajax_transport = false;    
//var prev_page = '';
//var xmlHttp;
var load_msg = "<img src='http://www.compareireland.ie/images/loading_bar.gif' />";
var home_url = "http://www.compareireland.ie/";
var carsale_pg = "cars_for_sale_ajax_search.php";
var rate_pg = "clients_rating.php";
var hotel_pg = "hotels_booking_form.php";
var load_hotel_pg = "hotels_booking_result_inc.php";
////////////////////////////////////////
//hotel search form
function ewd_get_hotels(containerid,form_name)  {                				
	var content_show = document.getElementById(containerid);
	var load_div = document.getElementById("sp_"+containerid);
	content_show.style.visibility = "visible";
	load_div.innerHTML = load_msg;
	var callback = {
		success : function(o) {
			content_show.innerHTML = o.responseText;
			content_show.style.visibility = "visible";
			load_div.innerHTML = "";
		},
		failure : function(o) {
			content_show.innerHTML = o.responseText;
			content_show.style.visibility = "visible";
			content_show.innerHTML = "CONNECTION FAILED!";
		}
	}
	var url = home_url+hotel_pg;//alert(url);
	this.form = document.getElementById(form_name);
	YAHOO.util.Connect.setForm(this.form);	
	var request = YAHOO.util.Connect.asyncRequest('POST', url, callback);
}

//rate client
//get year
function rate_client(clientid,rate,bus_name,div){
	var content_show = document.getElementById(div);        
	content_show.style.visibility = "visible";
	content_show.innerHTML = load_msg;
	var callback = {
		success : function(o) {
			content_show.innerHTML = o.responseText;
			content_show.style.visibility = "visible";
		},
		failure : function(o) {
			content_show.innerHTML = o.responseText;
			content_show.style.visibility = "visible";
			content_show.innerHTML = "CONNECTION FAILED!";
		}
	}
	var url= home_url+rate_pg+"?clientid="+clientid +"&rate="+rate+"&bus_name="+bus_name+"&date=" + new Date().getTime();
	var conn = YAHOO.util.Connect.asyncRequest("GET", url, callback);
}
//get model
function get_model(inputx,div,mode){
	var input = inputx;
	var content_show = document.getElementById(div); 
	content_show.style.visibility = "visible";
	content_show.innerHTML = load_msg;
	var callback = {
		success : function(o) {
			content_show.innerHTML = o.responseText;
			content_show.style.visibility = "visible";
		},
		failure : function(o) {
			content_show.innerHTML = o.responseText;
			content_show.style.visibility = "visible";
			content_show.innerHTML = "CONNECTION FAILED!";
		}
	}
	var url= home_url+carsale_pg+"?srch_make="+ input + "&mode=" + mode + "&date=" + new Date().getTime();
	var conn = YAHOO.util.Connect.asyncRequest("GET", url, callback);
	get_year(input,'','sp_car_year','year');
	get_price(input,'','','','sp_car_price','price');
}

//get year
function get_year(make,model,div,mode){
	var content_show = document.getElementById(div);        
	content_show.style.visibility = "visible";
	content_show.innerHTML = load_msg;
	var callback = {
		success : function(o) {
			content_show.innerHTML = o.responseText;
			content_show.style.visibility = "visible";
		},
		failure : function(o) {
			content_show.innerHTML = o.responseText;
			content_show.style.visibility = "visible";
			content_show.innerHTML = "CONNECTION FAILED!";
		}
	}
	var url= home_url+carsale_pg+"?srch_make="+make +"&srch_model="+model+"&mode="+mode+"&date=" + new Date().getTime();
	var conn = YAHOO.util.Connect.asyncRequest("GET", url, callback);
	get_price(make,model,'','','sp_car_price','price');
}
//get prices
function get_price(make,model,yearfrom,yearto,div,mode){
	var content_show = document.getElementById(div);        
	content_show.style.visibility = "visible";
	content_show.innerHTML = load_msg;
	var callback = {
		success : function(o) {
			content_show.innerHTML = o.responseText;
			content_show.style.visibility = "visible";
		},
		failure : function(o) {
			content_show.innerHTML = o.responseText;
			content_show.style.visibility = "visible";
			content_show.innerHTML = "CONNECTION FAILED!";
		}
	}
	var url= home_url+carsale_pg+"?srch_make="+make+"&srch_model="+model+"&srch_yr_from="+yearfrom+"&srch_yr_to="+yearto+"&mode="+mode+"&date="+ new Date().getTime();
	var conn = YAHOO.util.Connect.asyncRequest("GET", url, callback);
}
//get email form
function get_car_email(carid,car_name,div,mode){
	var content_show = document.getElementById(div);
	//show_hide(content_show);
	content_show.style.display='';
	content_show.style.visibility = "visible";
	content_show.innerHTML = load_msg;
	var callback = {
		success : function(o) {
			content_show.innerHTML = o.responseText;
			content_show.style.visibility = "visible";
		},
		failure : function(o) {
			content_show.innerHTML = o.responseText;
			content_show.style.visibility = "visible";
			content_show.innerHTML = "CONNECTION FAILED!";
		}
	}
	var url= home_url+"cars_for_sale_send_email.php?car_id="+carid+"&used_cars="+car_name+"&type="+mode+"&date="+ new Date().getTime();
	var conn = YAHOO.util.Connect.asyncRequest("GET", url, callback);
}

//disable form element
function disable(what){ 
document.getElementById(what).disabled = true; 
}
//activate form element
function activate(what){ 
document.getElementById(what).disabled = false; 
}
//get input value
function input_value(what){ 
	var what = document.getElementById(what).value;
	return what;
}
//clear span
function clear_sp(what){ 
document.getElementById(what).innerHTML = ""; 
}
//show and hide div
function show_hide(div){
	var myrow = document.getElementById(div);//MM_findObj(div);
	myrow.style.display=myrow.style.display=='none' ? '' : 'none';
}
//count clicks
//var root = '';
var a = document.getElementsByTagName("a");
for(i = 0; i< a.length; i++)
  if(a[i].id != '')
	 a[i].onclick = count_link;
	 
function count_link() {
  i = new Image();
  i.src = home_url+'_click_count.php?id='+this.id+"&date="+ new Date().getTime();
  //alert(i.src);
  return true;
}
//swap img
function show_green(img,number){
	myarray = img.split(/\_/);
	if(myarray[1] > 0){
		for (var i = 0; i < myarray[1]; i++) {
			var imgx = document.getElementById(myarray[0]+"_"+(i+1));	
			imgx.src = home_url+"images/rating_over.gif";
		}
	}
}
function restore_stars(img,number){
	myarray = img.split(/\_/);
	if(myarray[1] > 0){
		for (var i = 0; i < myarray[1]; i++) {
			var imgx = document.getElementById(myarray[0]+"_"+(i+1));
			var imgy = document.getElementById("y_"+myarray[0]+"_"+(i+1)).value;
			imgx.src = imgy;
		}
	}
}



  