function setnavbackground(mItem)
{
	var mItemID = "nav"+mItem;
	bg = document.getElementById(mItemID);
	if(window.getComputedStyle) {} else { }
	bg.style.backgroundImage = 'url(../images/nav_background.jpg)';
}
function setnavbackgroundout(mItem)
{
	var mItemID = "nav"+mItem;
	bg = document.getElementById(mItemID);
	if(window.getComputedStyle) {} else { }
	bg.style.backgroundImage = '';
}
function clickused()
{


	
	
}
function clickhire()
{


}
function clicknew()
{


}
function getBaseURL() {
    var url = location.href;  // entire url including querystring - also: window.location.href;
    var baseURL = url.substring(0, url.indexOf('/', 14));


    if (baseURL.indexOf('http://localhost') != -1) {
        // Base Url for localhost
        var url = location.href;  // window.location.href;
        var pathname = location.pathname;  // window.location.pathname;
        var index1 = url.indexOf(pathname);
        var index2 = url.indexOf("/", index1 + 1);
        var baseLocalUrl = url.substr(0, index2);

        return baseLocalUrl + "/";
    }
    else {
        // Root Url for domain name
        return baseURL + "/";
    }

}
function Instr(str,substr,start)
{
	var oStr = new String(str);
	return oStr.indexOf(substr,start);
}
function runsearch()
{
	var m = Instr(location.href,"second-hand",1);
	
	if(m > 0)
	{
		search_second_hand();
		search_second_hand_count();
	}
	else
	{
		//var params = "";
		//params="cat="+document.getElementById("sh_category").value;
		//params=params+"&man="+document.getElementById("sh_manuf").value;
		//window.location=getBaseURL()+"second-hand/?"+params;
		
		var form = document.createElement("form");
	    form.setAttribute("method", "post");
    	form.setAttribute("action",getBaseURL()+"second-hand/" );


        var hiddenField = document.createElement("input");
        hiddenField.setAttribute("type", "hidden");
        hiddenField.setAttribute("name", "cat");
        hiddenField.setAttribute("value", document.getElementById("sh_category").value);
        form.appendChild(hiddenField);
		document.body.appendChild(form);
		form.submit();

	}
}
function search_second_hand_count()
{
	var rootUrl  = getBaseURL();
	
	var http = new XMLHttpRequest();
	var url = rootUrl+"includes/get_sl_list_count.php";
	var params = "";
	params="cat="+document.getElementById("sh_category").value;
	params=params+"&man="+document.getElementById("sh_manuf").value;
	http.open("POST", url, true);

	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	document.getElementById("itemcount").innerHTML="";
	http.onreadystatechange = function() 
	{//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) 
		{
			
			document.getElementById("itemcount").innerHTML=http.responseText;
			//getresponseText
		}
	}
	http.send(params);
}
function search_second_hand()
{
	var rootUrl  = getBaseURL();
	
	var http = new XMLHttpRequest();
	var url = rootUrl+"includes/get_sl_list.php";
	var params = "";
	params="cat="+document.getElementById("sh_category").value;
	params=params+"&man="+document.getElementById("sh_manuf").value;
	http.open("POST", url, true);

	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	document.getElementById("sl_results").innerHTML="";
	http.onreadystatechange = function() 
	{//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) 
		{
			
			document.getElementById("sl_results").innerHTML=http.responseText;
			//getresponseText
		}
	}
	http.send(params);
}
function changeordersl()
{
	var rootUrl  = getBaseURL();
	
	var http = new XMLHttpRequest();
	var url = rootUrl+"includes/get_sl_list.php";
	var params = "";
	params="ord="+document.getElementById("sl_select").value;

	http.open("POST", url, true);

	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	document.getElementById("sl_results").innerHTML="";
	http.onreadystatechange = function() 
	{//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) 
		{
			
			document.getElementById("sl_results").innerHTML=http.responseText;
			//getresponseText
		}
	}
	http.send(params);
}
function getsecondhandsearch()
{
	var rootUrl  = getBaseURL();
	
	var http = new XMLHttpRequest();
	var url = rootUrl+"includes/get_sh_search_manu.php";
	var params = "";
	params="hostname="+window.location.hostname;

	http.open("POST", url, true);

	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");

	http.onreadystatechange = function() 
	{//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) 
		{
			
			document.getElementById("comboitems").innerHTML=http.responseText;
			//getresponseText
		}
	}
	http.send(params);
}
function getnewsearch()
{
	var rootUrl  = getBaseURL();
	
	var http = new XMLHttpRequest();
	var url = rootUrl+"includes/get_nm_search_manu.php";
	var params = "";
	params="hostname="+window.location.hostname;

	http.open("POST", url, true);

	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");

	http.onreadystatechange = function() 
	{//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) 
		{
			
			document.getElementById("comboitems").innerHTML=http.responseText;
			//getresponseText
		}
	}
	http.send(params);
}
function watchvideo(mID)
{
	var rootUrl  = getBaseURL();
	
	var http = new XMLHttpRequest();
	var url = rootUrl+"includes/getvideo.php";
	
	if(document.getElementById("wvd").innerHTML == "View images")
	{
		var url = rootUrl+"includes/getimages.php";
	}
	
	var params = "";
	params="id="+mID;

	http.open("POST", url, true);

	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");

	http.onreadystatechange = function() 
	{//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) 
		{
			
			document.getElementById("imagecontainer").innerHTML=http.responseText;
			if(document.getElementById("wvd").innerHTML == "Watch video")
			{
				document.getElementById("wvd").innerHTML = "View images";
			}
			else
			{
				document.getElementById("wvd").innerHTML = "Watch video";
				$('.nmmachineimg').cycle({
					fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
				});
			}
			
			//getresponseText
		}
	}
	http.send(params);
}
function floatlogin()
{
	var mTitle = "Login";
	$url="login.php";
	fb.start({ href:$url, rev:'width:300 height:150 scrolling:no infoPos:tc showClose:true enableDragResize:false padding:5', title:mTitle });
}
function contactus()
{

	var rootUrl  = getBaseURL();
	
	var http = new XMLHttpRequest();
	var url = rootUrl+"includes/contactus.php";
	var params = "";
	params="yourname="+document.getElementById("yourname").value;
	params=params+"&email="+document.getElementById("email").value;
	params=params+"&sponsor="+document.getElementById("sponsor").value;
	params=params+"&distid="+document.getElementById("distid").value;
	params=params+"&message="+document.getElementById("message").value;

	http.open("POST", url, true);

	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");

	http.onreadystatechange = function() 
	{//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) 
		{
			
			
				alert(http.responseText);
			
		}
	}
	http.send(params);
}
function loginsys()
{

	var rootUrl  = getBaseURL();
	
	var http = new XMLHttpRequest();
	var url = rootUrl+"includes/login.php";
	var params = "";
	params="1="+document.getElementById("username").value;
	params=params+"&2="+document.getElementById("password").value;

	http.open("POST", url, true);

	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");

	http.onreadystatechange = function() 
	{//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) 
		{
			
			//alert(http.responseText );
			if(http.responseText != "1")
			{
				alert("Incorrect details");
			}
			else
			{
				parent.document.location="secure_area.php";
			}
			//getresponseText
		}
	}
	http.send(params);
}
