
// ajax
var http = createRequestObject();	
function createRequestObject()
{
	var connect;
    var browser = navigator.appName;
    if(browser == 'Microsoft Internet Explorer') 
    {
    	try
    	{
    		connect = new ActiveXObject("Msxml2.XMLHTTP");
    	}
    	catch(e)
    	{
    		try
    		{
    			connect = new ActiveXObject("Microsoft.XMLHTTP");
    		}
    		catch(e){}
    	}    	
    }
    else
    {
        connect = new XMLHttpRequest();
    }
    return connect;
}

function display(url, id)
{
	document.getElementById(id).style.display = "block";
	preloader(id); // preloading image waiting
	http.open("GET", url, true);
	http.onreadystatechange = function(){handleResponse(id);}
	http.send(null);
}

function handleResponse(id)
{
	if(http.readyState == 4 && http.status == 200)
	{
    	document.getElementById(id).innerHTML = http.responseText;
    }
}
function rDisplay(url, child)
{
	http.open("GET", url, true);
	http.onreadystatechange = function(){rHandleResponse(child);}
	http.send(null);
}

function rHandleResponse(child)
{
	if(http.readyState == 4 && http.status == 200)
	{
		if(child==true) {
    		opener.document.getElementById('hinh_chonxe1').innerHTML = http.responseText;
			opener.document.getElementById('hinh_chonxe2').innerHTML = http.responseText;
		} else {
			document.getElementById('hinh_chonxe1').innerHTML = http.responseText;
			document.getElementById('hinh_chonxe2').innerHTML = http.responseText;
		}
    }
}

function isValidEmail(str)
{
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function switch_tab(tab_name,id,page,param,location,numtab)
{
	
	var i = 0;
	var tabid = "";	
	for (i = 0; i < numtab; i ++)
	{			
		if ((i + 1) == id)
		{			
			tabid = tab_name + id;	
			document.getElementById(tabid + "_off").style.display = "none";
			document.getElementById(tabid + "_on").style.display = "block";
		}
		else
		{
			tabid = i + 1;				
			tabid = tab_name + tabid;
			document.getElementById(tabid + "_off").style.display = "block";
			document.getElementById(tabid + "_on").style.display = "none";
		}
	}
	// get source
	url = "inc/" + page + ".php?" + param;
	// display on location
	display(url,location);
	
}

function menu_jump_ajax(page,param,location)
{
	// get source
	alert('test');
	//url = page + param;
	//alert(page + param);
	// display on location
	//display(url,location);
}

function menu_jump_ajax_car_info(id)
{
	if(id>0) {
		document.getElementById('rDetail').style.display='none';		
	} else {
		document.getElementById('rDetail').style.display='';
	}	// get source 
	url = 'load_car_img.php?type=sell&cat_id=' + id;
	//alert(url);
	// display on location
	display(url,'car_info');
}

function switch_page(page,param,location)
{
	// get source
	url = "inc/" + page + ".php?" + param;
	// display on location
	display(url,location);
}

function changeclass(id, newclass)
{
	document.getElementById(id).className = newclass;
}
function preloader(el)
{
	var preloader = document.getElementById(el);
	preloader.innerHTML = "<div align=left><img src='images/loading.gif'><br/><font style='color:#666666'>Please wait !</font></div>";
	
}
