function sfHover(id) {
	try {
		var sfEls = document.getElementById(id).getElementsByTagName("li");
		for (var i = 0; i < sfEls.length; i++) {
			sfEls[i].onmouseover = function () {
				this._className = this.className;
				this.className += " sfhover";
			}
			sfEls[i].onmouseout = function () {
				this.className = this._className;
			}
		}
	}
	catch (e) {
		alert(e);
	}
}

function SearchState() {

	if ((state = document.getElementById("postalcode").value) != '') {
	}
	else {
		state = document.getElementById('state').value;
	}

	window.location.href = "zoek-requiem-uitvaartondernemer.aspx?state=" + state.toString();
}

function go(id, count1, count2, returnUrl, target)
{
	var xmlRequest;
	
	xmlRequest = new XmlRequest();
	xmlRequest.ServerPage = applicationPath + "XmlHttp/CountStats.aspx";
	xmlRequest.Execute(
	"<root>" + 
		"<id>" + id + "</id>" +
		"<count1>" + count1 + "</count1>" +
		"<count2>" + count2 + "</count2>" +
	"</root>");
	if (typeof(target) == "string")
		window.open(returnUrl, "", "", target);
	else
		window.location.href = returnUrl;
}

function PreviewBook(target)
{
	var xmlRequest,
		url;
	
	xmlRequest = new XmlRequest();
	xmlRequest.ServerPage = applicationPath + "XmlHttp/GetPreviewURL.aspx";
	url = xmlRequest.ExecuteScalar("<root />");
	if (typeof(url) == "string")
		window.open(url, "", "", target);
	else
		alert("Van dit Afscheidsboek is geen preview beschikbaar");
}

function ExecuteAndErrors(serverPage, xml)
{
	var httpRequest,
		xmlRequest,
		errors;
	
	xmlRequest = new XmlRequest(serverPage, null);
	//xmlRequest.Debug = true;
	try
	{
		if ((httpRequest = xmlRequest.ExecuteRequest(xml)) != null)
		{
			if ((errors = responseErrors(httpRequest)) != 0)
				alert(evaluateXPath(httpRequest.responseXML, "response/error"));
		}
	}
	catch (exception)
	{
		document.body.innerHTML = exception.message;
	}
	return errors;
}

function AddToShoppingCart(itemID)
{
	var cartItemID,
		xmlHttp;

	xmlHttp = XmlHttpObject();
	xmlHttp.open("POST", applicationPath + "XmlHttp/AddToShoppingCart.aspx", false);
	xmlHttp.send("<root><itemid>" + itemID + "</itemid><quantity>1</quantity></root>");
	if (XmlHttpResponse(xmlHttp, document.body, false) == 0)
		ShoppingCart();
}

function ExecuteNextStep(xml)
{
	var xmlRequest;
	
	xmlRequest = new XmlRequest();
	xmlRequest.ServerPage = applicationPath + "XmlHttp/NextStep.aspx";
	window.location.href = xmlRequest.ExecuteScalar(xml, document.body);
}

function NextStep(current)
{
	ExecuteNextStep("<root current=\"" + current + "\" />");
}

function GotoStep(next)
{
	ExecuteNextStep("<root next=\"" + next + "\" />");
}

function ExecuteAndRefresh(serverPage, xml)
{
	var xsltDocument,
		httpRequest,
		xmlDocument,
		xmlRequest,
		div;
	
	if ((div = document.getElementById("shoppingcart_placeholder")) != null)
	{
		xmlRequest = new XmlRequest(serverPage, applicationPath + "Checkout/IE5.0/Shoppingcart.xsl");
		//xmlRequest.Debug = true;
		try
		{
			if ((httpRequest = xmlRequest.ExecuteRequest(xml)) != null)
			{
				if (responseErrors(httpRequest) == 0)
				{
					if ((xmlDocument = httpRequest.responseXML) != null)
					{
						if ((xsltDocument = xmlRequest.LoadStyleSheet()) != null)
						{
							xmlRequest.TransformNodeToElement(div, xmlDocument, xsltDocument);
						}
					}
				}
				else
					alert(pulkError(httpRequest));
			}
		}
		catch (exception)
		{
			div.innerHTML = exception.message;
		}
	}
}

function DeleteItem(id)
{
	ExecuteAndRefresh(applicationPath + "XmlHttp/DeleteItem.aspx", "<root id=\"" + id.toString() + "\" />");
}

function CheckFill(id, value)
{
	ExecuteAndRefresh(applicationPath + "XmlHttp/DeleteItem.aspx", "<root action=\"fill\" value=\"" + (value ? "1" : "0") + "\" id=\"" + id.toString() + "\" />");
}

function CheckFingerprintSet(id, value)
{
	ExecuteAndRefresh(applicationPath + "XmlHttp/DeleteItem.aspx", "<root action=\"finger\" value=\"" + (value ? "1" : "0") + "\" id=\"" + id.toString() + "\" />");
}

function CheckRingSizer(id, value)
{
	ExecuteAndRefresh(applicationPath + "XmlHttp/DeleteItem.aspx", "<root action=\"ring\" value=\"" + (value ? "1" : "0") + "\" id=\"" + id.toString() + "\" />");
}

function DeleteWishcard(id)
{
	ExecuteAndRefresh(applicationPath + "XmlHttp/DeleteItem.aspx", "<root action=\"delcard\" id=\"" + id.toString() + "\" />");
}

function DeleteLinten(id)
{
	ExecuteAndRefresh(applicationPath + "XmlHttp/DeleteItem.aspx", "<root action=\"dellint\" id=\"" + id.toString() + "\" />");
}

function SetSize(id, value)
{
	ExecuteAndRefresh(applicationPath + "XmlHttp/DeleteItem.aspx", "<root action=\"size\" value=\"" + value + "\" id=\"" + id.toString() + "\" />");
}

function ShoppingCart()
{
	window.location.href = "winkelmandje";
}

function RenderProductDetails(itemID) {
	var xsltDocument,
		httpRequest,
		xmlDocument,
		xmlRequest,
		xml,
		div;

	if ((div = document.getElementById("productdetails_placeholder")) != null) {
		xmlRequest = new XmlRequest(applicationPath + "Thuiswinkel/ProductDetails.ashx", applicationPath + "Thuiswinkel/ProductDetails.xsl");
		//xmlRequest.Debug = true;
		try {
			xml = "<root id=\"" + itemID.toString() + "\" />";
			if ((httpRequest = xmlRequest.ExecuteRequest(xml)) != null) {
				if (responseErrors(httpRequest) == 0) {
					if ((xmlDocument = httpRequest.responseXML) != null) {
						if ((xsltDocument = xmlRequest.LoadStyleSheet()) != null) {
							xmlRequest.TransformNodeToElement(div, xmlDocument, xsltDocument);
						}
					}
				}
				else
					alert(pulkError(httpRequest));
			}
		}
		catch (exception) {
			div.innerHTML = exception.message;
		}
	}
}

