var http = createRequestObject();
lastUrl = '';
var current_url;

function scroll_to(id){
    $.scrollTo(id, 1000);
}

// NDK Loading
var ie45,ns6,ns4,dom;
if (navigator.appName=="Microsoft Internet Explorer") ie45=parseInt(navigator.appVersion)>=4;
else if (navigator.appName=="Netscape"){  ns6=parseInt(navigator.appVersion)>=5;  ns4=parseInt(navigator.appVersion)<5;}
dom=ie45 || ns6;

var timershow=false;
var curx=-200;
var cury=200;
var win_w=window.innerWidth ? window.innerWidth : document.body.offsetWidth;
var mid_w=win_w/2;
var timershow1=window.setInterval("stayMiddle()",1);

function getobj(id) {
el = document.all ? document.all[id] :   dom ? document.getElementById(id) :   document.layers[id];
return el;
}
function show_Loading() {
	obj = getobj('LoadingDiv');
	if (timershow) window.clearTimeout(timershow);
	timershow=window.setInterval("nshow()",1);
}

function hide_Loading() {
	obj = getobj('LoadingDiv');
	if (timershow) window.clearTimeout(timershow);
	timershow=window.setInterval("nhide()",1);
}
function moveobj(obj,x,y) {
	obj.style.left=x + "px";
	obj.style.top=y+ "px";
	curx=x;
	cury=y;
}

function stayMiddle() {
	if (document.documentElement && document.documentElement.scrollTop)
		var pY =  document.documentElement.scrollTop;
	else if (document.body)
		var pY =  document.body.scrollTop;

	obj = getobj('LoadingDiv');
	newy = cury+((pY-cury)/16)+12;
	moveobj(obj,curx, newy);
}

function nshow() {
	obj = getobj('LoadingDiv');
	newx = curx+((mid_w-curx)/16)-7;
	moveobj(obj,newx, cury);
}
function nhide() {
	obj = getobj('LoadingDiv');
	newx = curx+((0-curx)/16)-15;
	moveobj(obj,newx, cury);
}
// End NDK Loading



function createRequestObject() {
	var xmlhttp;
	try { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); }
	catch(e) {
    try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
	catch(f) { xmlhttp=null; }
  }
  if(!xmlhttp&&typeof XMLHttpRequest!="undefined") {
	xmlhttp=new XMLHttpRequest();
  }
	return  xmlhttp;
}

function sendRequest(current_url) {
	try{
		var current_url = encodeURIComponent(current_url);
		http.open('POST',  'defaul.aspx');
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http.onreadystatechange = ajaxload;
		http.send('url='+current_url);
		show_Loading();
		document.getElementById("loading").innerHTML = "<center><b>Loading ...</b></center>";
		document.getElementById("loading").style.display = "block";
	}
	catch(e){}
	finally{}
}

function ajaxload() {
	try {
		if((http.readyState == 4)&&(http.status == 200)){
			document.getElementById("loading").style.display = "none";
			hide_Loading();
			scroll_to('#top');
			hideddrivetip();
			//hide_first_div();
			var response = http.responseText;
				document.getElementById("ajax_show").innerHTML = response;
				document.getElementById("ajax_show").style.display = "";
		}
  	}
	catch(e){}
	finally{}
}

function getVar(url,cnt)
{
	url=url+'#';
	url=url.split('#');
	if (!url[1]) window.location.href = '#Home';
	url=url[1];
	url=url+'/';
	url=url.split('/');
	url=url[cnt];
	if (!url)
		return '';
	return url;
}

function loadPage() {
	var act = getVar(window.location.href,0);
	if (act) {
		current_url=top.location.href;
		current_url=current_url+'#';
		current_url=current_url.split('#');
		current_url=current_url[1];
		if (current_url) sendRequest(current_url);
	}
}

function urlCheck()
{
	url=window.location.href;
	if (url.indexOf('?') != -1 ) {
		url_temp = url.split('?');
		top.location.href = url_temp[0];
		clearInterval(document.onLoad);
	}
	if (url != '' && url!=lastUrl)
	{
		loadPage();
		lastUrl=url;
	}
}

function toggle( targetId ){
			if (document.getElementById){
				target = document.getElementById( targetId );
  			if (target.style.display == "none"){
  				target.style.display = "";
  			} else {
  				target.style.display = "none";
  			}
			}
}

function changeTitle(title) { 
	document.title = 'QUANG MINH AUTO INTERIOR - '+title; 
	/* scroll_to('#top'); */
}

