
// JvaScript Document
var last_category='';
var last_brand='';
var last_stype='';
var last_minp=0;
var last_maxp=0;


/* The following function creates an XMLHttpRequest object... */

function createRequestObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}

/* The variable http will hold our new XMLHttpRequest object. */
var http2 = createRequestObject();
var http3 = createRequestObject();
var http4 = createRequestObject();

function doClick(page){
		document.getElementById('content').innerHTML = '<div class="spacer"><br /><br /></div><div align="center" class="centercontent"><img align="center" src="img/loading.gif"></div><div class="spacer"><br /><br /></div>';
	http4.open('post',page);
	http4.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http4.onreadystatechange = handleClick;
	http4.send(null);
	}

function handleClick(){
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(http4.readyState == 4){ //Finished loading the response
	
		var response = http4.responseText;
		document.getElementById('content').innerHTML = '';
		document.getElementById('content').innerHTML = response;
	}
}




function doSearch(limit){
	document.getElementById('content').innerHTML = '<div class="spacer"><br /><br /></div><div align="center" class="centercontent"><img align="center" src="img/loading.gif"></div><div class="spacer"><br /><br /></div>';
	http3.open('post',  'search.php?');
	var s=limit;
	http3.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http3.onreadystatechange = handleSearch;
	http3.send('q='+document.search_form.q.value+'&s='+s);
	}

function handleSearch(){
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(http3.readyState == 4){ //Finished loading the response
	
		var response = http3.responseText;
		document.getElementById('content').innerHTML = response;
	}
}


function getProducts(category,brand,stype,minp,maxp){
	document.getElementById('content').innerHTML = '<div class="spacer"><br /><br /></div><div align="center" class="centercontent"><img align="center" src="img/loading.gif"></div><div class="spacer"><br /><br /></div>';
	last_category=category;
	last_brand=brand;
	last_stype=stype;
	last_minp=minp;
	last_maxp=maxp
	if(stype=="cat"){
		http2.open('post',  'products_cat.php?');
		http2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http2.onreadystatechange = handleGetProducts;
		http2.send('select_category='+category);
	}
	else if(stype=="cat_brand"){
		http2.open('post',  'products_cat_brand.php?');
		http2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http2.onreadystatechange = handleGetProducts;
		
		http2.send('select_category='+category+'&select_brand='+brand);
		
	}
	else if(stype=="brand"){
		http2.open('post',  'products_brand.php?');
		http2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http2.onreadystatechange = handleGetProducts;
		http2.send('select_brand='+brand);
	
	}
}

/* Function called to handle the list that was returned from the internal_request.php file.. */
function handleGetProducts(){
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(http2.readyState == 4){ //Finished loading the response
		var response2 = http2.responseText;
		document.getElementById('content').innerHTML = response2;
		
	}
	
}
function backToTop() {
    var x1 = x2 = x3 = 0;
    var y1 = y2 = y3 = 0;

    if (document.documentElement) {
        x1 = document.documentElement.scrollLeft || 0;
        y1 = document.documentElement.scrollTop || 0;
    }

    if (document.body) {
        x2 = document.body.scrollLeft || 0;
        y2 = document.body.scrollTop || 0;
    }

    x3 = window.scrollX || 0;
    y3 = window.scrollY || 0;

    var x = Math.max(x1, Math.max(x2, x3));
    var y = Math.max(y1, Math.max(y2, y3));

    window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));

    if (x > 0 || y > 0) {
        window.setTimeout("backToTop()", 50);
    }
}


function getProductsNew(category,brand,stype,minp,maxp){
	document.getElementById('content').innerHTML = '<div class="spacer"><br /><br /></div><div align="center" class="centercontent"><img align="center" src="img/loading.gif"></div><div class="spacer"><br /><br /></div>';
	last_category=category;
	last_brand=brand;
	last_stype=stype;
	last_minp=minp;
	last_maxp=maxp
	if(stype=="cat"){
		http2.open('post',  'products_cat_new.php?');
		http2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http2.onreadystatechange = handleGetProducts;
		http2.send('select_category='+category);
	}
	else if(stype=="cat_brand"){
		http2.open('post',  'products_cat_brand_new.php?');
		http2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http2.onreadystatechange = handleGetProducts;
		
		http2.send('select_category='+category+'&select_brand='+brand);
		
	}
	else if(stype=="brand"){
		http2.open('post',  'products_brand_new.php?');
		http2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http2.onreadystatechange = handleGetProducts;
		http2.send('select_brand='+brand);
	
	}
}