// JavaScript Document
// JavaScript Document

//Create a boolean variable to check for a valid IE instance.
var xmlhttp = false;
//Check if we are using IE.
try {
//If the javascript version is greater than 5.
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
//If not, then use the older active x object.
try {
//If we are using IE.
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
//Else we must be using a non-IE browser.
xmlhttp = false;
}
}
//If we are using a non-IE browser, create a JavaScript instance of the object.
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
xmlhttp = new XMLHttpRequest();
}
//--------------------
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	} else if (obj.x)
	{
		curleft += obj.x;
	}
	return curleft;
}
function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	} else if (obj.y)
	{
		curtop += obj.y;
	}
	return curtop;
}

function addSubCategory (thevalue,SubCat,theObject,typeDiv, e)
{
	theObject.style.visibility = "visible";

	var serverPage = "subcatdropdown.php?cid=" + thevalue + "&typeDiv="+typeDiv+"&subcat="+SubCat

	xmlhttp.open("GET", serverPage);
	xmlhttp.onreadystatechange = function() 
	{
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			theObject.innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);

}
function addType (thevalue, theObject, type,  e)
{
	theObject.style.visibility = "visible";

	var serverPage = "typedropdown.php?scid=" + thevalue +"&type="+type
	
	xmlhttp.open("GET", serverPage);
	xmlhttp.onreadystatechange = function() 
	{
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			theObject.innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}

function showResult (frm)
{
	var qrystring = '' ;
	if (frm.SortField.value != '' && frm.SortOrder.value != '' )
	{
		qrystring = "&field="+frm.SortField.value+"&order="+frm.SortOrder.value
	}

	

	theObject = document.getElementById("showResultDiv") ; 

	var serverPage = "reviewresult.php?cid=" + frm.SearchCategory.value +"&scid="+frm.SearchSubCategory.value+"&type="+frm.Type.value+qrystring+"&review="+frm.GearReviewer.value+"&brand="+frm.brand.value ; //"&rating="+frm.GearRating.value+
//	alert(serverPage) ;
	//+"&key="+frm.KeyWord.value
	
	xmlhttp.open("GET", serverPage);
	xmlhttp.onreadystatechange = function() 
	{
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			theObject.innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}

function showResultBrand(frm)
{
	var qrystring = '' ;
	if (frm.SortField.value != '' && frm.SortOrder.value != '' )
	{
		qrystring = "&field="+frm.SortField.value+"&order="+frm.SortOrder.value
	}

	

	theObject = document.getElementById("showResultDiv") ; 

	var serverPage = "reviewresult.php?brand="+frm.search_brand.value ; //"&rating="+frm.GearRating.value+
//	alert(serverPage) ;
	//+"&key="+frm.KeyWord.value
	
	xmlhttp.open("GET", serverPage);
	xmlhttp.onreadystatechange = function() 
	{
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			theObject.innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}

	// --------------------------------------------------- // 

	/*
		The functions  addBrandDropDown and addBrandDropDownRequest
		are used to filter brand, but used on the different pages.
	*/
	function addBrandDropDown(frm,theObject,typeDiv, e)	
	{
		
		//Create a boolean variable to check for a valid IE instance.
		var xmlhttpBrand = false;
		//Check if we are using IE.
		try {
		//If the javascript version is greater than 5.
		xmlhttpBrand = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
		//If not, then use the older active x object.
		try {
		//If we are using IE.
		xmlhttpBrand = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
		//Else we must be using a non-IE browser.
		xmlhttpBrand = false;
		}
		}
		//If we are using a non-IE browser, create a JavaScript instance of the object.
		if (!xmlhttpBrand && typeof XMLHttpRequest != 'undefined') {
		xmlhttpBrand = new XMLHttpRequest();
		}
		
//		alert(frm);
//		return false;
		theObject.style.visibility = "visible";
		
		var catid = (frm.SearchCategory?frm.SearchCategory.value: (frm.requiredCategory?frm.requiredCategory.value:''))
		var scid = (frm.SearchSubCategory?frm.SearchSubCategory.value:(frm.requiredSubCategory?frm.requiredSubCategory.value:''))
		var typeid = (frm.Type?frm.Type.value: (frm.requiredType?frm.requiredType.value:''))
	
		var serverPage1 = "branddropdown.php?cid=" + catid + "&scid="+scid+"&type="+typeid;
	
		xmlhttpBrand.open("GET", serverPage1);
		xmlhttpBrand.onreadystatechange = function() 
		{
			if (xmlhttpBrand.readyState == 4 && xmlhttpBrand.status == 200) 
			{
				theObject.innerHTML = xmlhttpBrand.responseText;
			}
		}
		xmlhttpBrand.send(null);
	}

	function addBrandDropDownRequest(frm,theObject,typeDiv, e)
	{
		
		//Create a boolean variable to check for a valid IE instance.
		var xmlhttpBrand = false;
		//Check if we are using IE.
		try {
		//If the javascript version is greater than 5.
		xmlhttpBrand = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
		//If not, then use the older active x object.
		try {
		//If we are using IE.
		xmlhttpBrand = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
		//Else we must be using a non-IE browser.
		xmlhttpBrand = false;
		}
		}
		//If we are using a non-IE browser, create a JavaScript instance of the object.
		if (!xmlhttpBrand && typeof XMLHttpRequest != 'undefined') {
		xmlhttpBrand = new XMLHttpRequest();
		}
		
//		alert(frm);
//		return false;
		theObject.style.visibility = "visible";
	
		var serverPage1 = "branddropdown.php?cid=" + frm.requiredCategory.value + "&scid="+(frm.requiredSubCategory?frm.requiredSubCategory.value: '')+"&type="+(frm.requiredType?frm.requiredType.value: '');
	
		xmlhttpBrand.open("GET", serverPage1);
		xmlhttpBrand.onreadystatechange = function() 
		{
			if (xmlhttpBrand.readyState == 4 && xmlhttpBrand.status == 200) 
			{
				theObject.innerHTML = xmlhttpBrand.responseText;
			}
		}
		xmlhttpBrand.send(null);
	}
	// --------------------------------------------------- // 



function a(frm)
{
for(i=0; i<frm.elements.length; i++)
{
	alert(frm.elements[i].name + ' = '+frm.elements[i].type);	
}
	
}

