function Navigate(sUrl)
{
	window.navigate(sUrl);
}

function Launch(sUrl)
{
	window.open(sUrl, null, '');
}

function Trim(sString)
{
	return sString.replace(/(?:^\s+)|(?:\s+$)/g, "");
}

function Print()
{
	alert("Please print this page in 'landscape'.");
	window.print();
}

function Back()
{
	window.history.back();
}

function TransformXmlString(sInputXml, sXslPath)
{
	var sOutput, oXmlDoc, oXsltDoc;
	try
	{
		//	load the xml into a dom
		oXmlDoc = new ActiveXObject("msxml2.domdocument");
		oXmlDoc.async = false;
		oXmlDoc.loadXML(sInputXml);

		//	load the stylesheet into a dom
		oXsltDoc = new ActiveXObject("msxml2.domdocument");
		oXsltDoc.async = false;
		oXsltDoc.load(sXslPath);
		sOutput = oXmlDoc.transformNode(oXsltDoc);
	}
	catch(e)
	{
		sOutput = "";
		alert("Error: " + e.description);
	}
	finally
	{
		oXmlDoc = null;
		oXsltDoc = null;
	}
	return sOutput;
}

function TransformXml(sInputXml, sXsl)
{
	var sOutput, oXmlDoc, oXsltDoc;
	try
	{
		//	load the xml into a dom
		oXmlDoc = new ActiveXObject("msxml2.domdocument");
		oXmlDoc.async = false;
		oXmlDoc.loadXML(sInputXml);

		//	load the stylesheet into a dom
		oXsltDoc = new ActiveXObject("msxml2.domdocument");
		oXsltDoc.async = false;
		oXsltDoc.loadXML(sXsl);

		sOutput = oXmlDoc.transformNode(oXsltDoc);
	}
	catch(e)
	{
		sOutput = "";
		alert("Error: " + e.description);
	}
	finally
	{
		oXmlDoc = null;
		oXsltDoc = null;
	}
	return sOutput;
}

function HighLightButton()
{
	var c = window.event.srcElement;
	c.style.color = "yellow";
}

function UnHighLightButton()
{
	var c = window.event.srcElement;
	c.style.color = "white";
}

function logon()
{
	var xmlHttp, strURL;
	var sLogonXml;
	lblAction.innerText="";
	
	if ((txtUserId.value == "") || (txtPassword.value == ""))
	{
		lblAction.innerText = "Username/password not recognised! Login aborted"
		return;
	}
	
	try
	{
		sLogonXml = "<root><userid>" + txtUserId.value + "</userid><password>"  + txtPassword.value + "</password></root>";
		var xmlDoc2 =  new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc2.loadXML(sLogonXml);
		xmlHttp = new ActiveXObject("msxml2.XMLHTTP");
		//	post xml request for information
		strURL = "GetLogon.asp";
		//alert(strURL);
		xmlHttp.Open("POST", strURL, false);
		xmlHttp.send(xmlDoc2);
		//alert(xmlHttp.responseXML.xml);			
		var bsuccess =xmlHttp.responseXML.selectSingleNode("//success").text;
		if (bsuccess=="True")
			navigate("../Admin/Default.asp");
		else
			{
				lblAction.innerText = xmlHttp.responseXML.selectSingleNode("//message").text;	
				txtUserId.value="";
				txtPassword.value="";
			}
		
	}
	catch(e)
	{
		alert("Error: " + e.description);
	}
	finally
	{
		xmlHttp = null;
	} 
}
function clearField()
{
	txtUserId.value="";
	txtPassword.value="";
	lblAction.innerText="";
}

function PercentageStroke()
{
	var keycode = event.keyCode;
	if ((keycode >= 48 && keycode <= 57) || (keycode >= 96 && keycode <= 105))
	{
		var s = new String(event.srcElement.value);
		if (s.length >= 3)
		{
			event.returnValue = false;
		}
		return;
	}

	switch (keycode)
	{
		//case 33: // page up
		//case 34: // page down
		case 38: // arrow up
			var c = event.srcElement.parentElement;
			var r = c.parentElement;
			var pr = r.previousSibling;
			if (pr != null)
			{
				if (pr.cells[1] != null)
				{
					pr.cells[1].firstChild.focus();
					pr.cells[1].firstChild.select();
				}
			}
			break;
		case 13: // enter
		case 40: // arrow down
			var c = event.srcElement.parentElement;
			var r = c.parentElement;
			var pr = r.nextSibling;
			if (pr != null)
			{
				if (pr.cells[1] != null)
				{
					pr.cells[1].firstChild.focus();
					pr.cells[1].firstChild.select();
				}
			}
			break;
		case 37: // arrow left
			break;
		case 39: // arrow right
			break;
		case 8:
		case 9:
		case 16:
		case 18:
		case 46:
		case 112:
		case 115:
		case 116: // F5
		case 189: // -
			break;
		default:
			event.returnValue = false;
			break;
	}
	
	return;
}

function PercentageEnter()
{
	window.event.srcElement.style.backgroundColor = "#bedcb9";
	return;
}

function PercentageExit()
{
	window.event.srcElement.style.backgroundColor = "white";
	return;
}

function doSearch()
{
	if ((frmSearch.txtSearch.value == "") || (frmSearch.txtSearch.value.length < 3))
		return;
	else	
		Navigate('ProductList.asp?Search=' + frmSearch.txtSearch.value);					
}

/*

function GetCookie(name) {

	var start = document.cookie.indexOf(name+"=");
	var len = start+name.length+1;
	if ((!start) && (name != document.cookie.substring(0,name.length))) 
		return null;
	if (start == -1) 
		return null;
		
	var end = document.cookie.indexOf(";",len);
	if (end == -1) end = document.cookie.length;
		return unescape(document.cookie.substring(len,end));

}

function SetCookie(name,value,expires,path,domain,secure) {
	document.cookie = name + "=" +escape(value) +
		( (expires) ? ";expires=" + expires.toGMTString() : "") +
		( (path) ? ";path=" + path : "") +
		( (domain) ? ";domain=" + domain : "") +
		( (secure) ? ";secure" : "");
}

function DeleteCookie(name,path,domain) {
	if (GetCookie(name)) document.cookie = name + "=" +
		( (path) ? ";path=" + path : "") +
		( (domain) ? ";domain=" + domain : "") +
		";expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function GetCookie(sName)
{
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0])
      return unescape(aCrumb[1]);
  }

  // a cookie with the requested name does not exist
  return null;
}


*/

function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
} return null;
}

function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}


function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
// This cookie is history
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" +
exp.toGMTString();
}


function getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

