﻿function GetBaseAddress()
{
	//var baseaddress = "http://service.stkcheck.com/";
	//var baseaddress = "http://dev.service.stkcheck.com/";
	//var baseaddress = "http://localhost/StockCheck/";
	
	var baseaddress = window.location.protocol + "//" + window.location.host;
	var pathname = window.location.pathname;

	// the pathname starts with a "/" so we need to ignore that
	// when checking for an additional one that would seperate
	// the folder from the file name
	if (pathname.indexOf("/", 1) != -1)
	{
		baseaddress += pathname.substr(0, pathname.indexOf("/", 1) + 1);
	}
	else
	{
		baseaddress += "/";
	}

	//alert(baseaddress);

	return baseaddress;
}

function LogSearch()
{
	var guid;
	var partquery;
	var resultcount;
	var ip;

	guid = document.getElementById("hfStockCheckGUID").value;
	partquery = document.getElementById("hfPartQuery").value;
	resultcount = document.getElementById("hfResultCount").value;
	ip = document.getElementById("hfIPAddress").value;

	var req;

	if (window.XMLHttpRequest)													// Object of the current windows
	{
		req = new XMLHttpRequest();												// Firefox, Safari
	}
	else
	{
		if (window.ActiveXObject)													// ActiveX version
		{
			req = new ActiveXObject("Microsoft.XMLHTTP");		// Internet Explorer
		}
	}

	var url = GetBaseAddress() + "StockCheckLog.aspx";
	url = url + "?guid="+guid;
	url = url + "&partquery=" + partquery;
	url = url + "&resultcount=" + resultcount;
	url = url + "&ip=" + ip;
	url = url + "&eventtype=0";

	req.onreadystatechange = function()
	{
//		if (req.readyState == 4)
//		{
//			if (req.status == 200)
//			{
//				alert('OK Search');
//				alert(url);
//			}
//			else 
//			{
//				alert('Not OK');
//				alert(url);
//			}
//		}
	};

	//req.onreadystatechange = stateChanged;
	req.open("GET", url, true);
	req.send(null);
}

function LogClick(part, qty, invdate, eventtype, distid)
{
	var guid;
	var ip;
	
	guid = document.getElementById("hfStockCheckGUID").value;
	ip = document.getElementById("hfIPAddress").value;

	var req;

	if (window.XMLHttpRequest)													// Object of the current windows
	{
		req = new XMLHttpRequest();												// Firefox, Safari
	}
	else
	{
		if (window.ActiveXObject)													// ActiveX version
		{
			req = new ActiveXObject("Microsoft.XMLHTTP");		// Internet Explorer
		}
	}

	var url = GetBaseAddress() + "StockCheckLog.aspx";
	url = url + "?guid="+guid;
	url = url + "&part=" + part;
	url = url + "&qty=" + qty;
	url = url + "&invdate=" + invdate;
	url = url + "&ip=" + ip;
	url = url + "&eventtype=" + eventtype;
	url = url + "&distid=" + distid;

	req.onreadystatechange = function()
	{
//		if (req.readyState == 4)
//		{
//			if(req.status == 200)
//			{
//				alert('OK Click');
//				alert(url);
//			}
//			else
//			{
//				alert('Not OK Click');
//				alert(url);
//			}
//		}
	};

	//req.onreadystatechange = stateChanged;
	req.open("GET", url, true);
	req.send(null);
}

