<!--

/********************************************************
 Make this IE7 Compatible ;)
 http://ajaxian.com/archives/ajax-on-ie-7-check-native-first
*********************************************************/
createRequestObject = function() {
	var xmlhttp;
		/*@cc_on
	@if (@_jscript_version>= 5)
			try {xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
					try {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}
					catch (E) {xmlhttp = false;}
			}
	@else
		xmlhttp = false;
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest != "undefined") {
			try {xmlhttp = new XMLHttpRequest();} catch (e) {xmlhttp = false;}
	}
	return xmlhttp;}

var calcProductOptionPrice = function(V_ID, VOG_ID, VVO_ID) {

	var docRoot = document.getElementsByTagName("input");
	var control;
	var strQuery = '';

	// Loop through the DOM and find all VOG hidden fields 
	for (var i = 0; i < docRoot.length - 1; i++)
	{
		control = docRoot[i];
		if(control.getAttribute('type')) 
		{
			var attribType = control.getAttribute('type');
			if ((attribType.indexOf("hidden") != -1)  ||  attribType.toLowerCase() == "hidden")
			{
				if(control.getAttribute('id')) 
				{
					var attribID = control.getAttribute('id');
					if ((attribID.indexOf("hidVOG_") != -1))
					{
						if (attribID.substring(7) == VOG_ID)
						{
							// This is the selected item to set to the selected value
							control.value = VVO_ID;
							if (VVO_ID != 0) document.getElementById('hidVOGQty_' + VOG_ID).value = document.getElementById('cmbQty_' + VVO_ID).options[document.getElementById('cmbQty_' + VVO_ID).selectedIndex].value; else document.getElementById('hidVOGQty_' + VOG_ID).value = 0;
							strQuery += '&' + attribID + '=' + control.value + '|' + document.getElementById('hidVOGQty_' + VOG_ID).value;
						}
						else
							// Item value taken from the hidden field
							strQuery += '&' + attribID + '=' + control.value + '|' + document.getElementById('hidVOGQty_' + attribID.substring(7)).value;
					}
				}
			}
		}
	}

	var http = createRequestObject();

	http.open('get', '/actions/product_calculate_price.asp?V_ID=' + V_ID + strQuery, true);

	http.onreadystatechange = function() {
		if(http.readyState == 4){
			var response = http.responseText;
			window.document.getElementById('pProdPrice').innerHTML = response;
			window.document.getElementById('V_Price').value = response;
			window.document.getElementById('V1').value = V_ID;
		}
	}

	http.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	http.send(null);
}

var clearSelectedOptions = function(V_ID, VOG_ID) {
	
	var docRoot = document.getElementsByTagName("input");
	var control;
	var strQuery = '';

	// Loop through the DOM and find all VOG hidden fields 
	for (var i = 0; i < docRoot.length - 1; i++)
	{
		control = docRoot[i];
		if(control.getAttribute('type')) 
		{
			var attribType = control.getAttribute('type');
			if ((attribType.indexOf("hidden") != -1)  ||  attribType.toLowerCase() == "hidden")
			{
				if(control.getAttribute('id')) 
				{
					var attribID = control.getAttribute('id');
					if ((attribID.indexOf("hidVOG_") != -1))
					{
						if (attribID.substring(7) == VOG_ID)
							control.value = '';
					}
				}
			}
		}
	}

	// Recalculate the price
	calcProductOptionPrice(V_ID, VOG_ID, 0);
}

var changeVersion = function(PT_ID, P_ID, V_ID) {

	var http = createRequestObject();

	// Redirect to the product page with the selected version
	http.open('get', '/actions/version_selection.asp?PT_ID=' + PT_ID + '&P_ID=' + P_ID + '&V_ID=' + V_ID, true);

	http.onreadystatechange = function() {
		if(http.readyState == 4){
			var response = http.responseText;
			location.href = response + '#aAddToBasket';
		}
	}

	http.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	http.send(null);
}

var submitToBasket = function() {

	var numLineCount = window.document.getElementById('numLineCount').value;
	var V1 = window.document.getElementById('V1').value;
	var V_ID = window.document.getElementById('V_ID').value;
	var Q1 = window.document.getElementById('Q1_' + V1).options[window.document.getElementById('Q1_' + V1).selectedIndex].value;
	
	var DepositApplied = 0;
	if (window.document.getElementById('chkDeposit' + V1) != null)
		if (window.document.getElementById('chkDeposit' + V1).checked == true)
			DepositApplied = 1;
	
	var InstallationApplied = 0;
	if (window.document.getElementById('chkInstallation' + V1) != null)
		if (window.document.getElementById('chkInstallation' + V1).checked == true)
			InstallationApplied = 1;

	var docRoot = document.getElementsByTagName("input");
	var control;
	var strQuery = '';

	// Loop through the DOM and find all VOG hidden fields 
	for (var i = 0; i < docRoot.length - 1; i++)
	{
		control = docRoot[i];
		if(control.getAttribute('type')) 
		{
			var attribType = control.getAttribute('type');
			if ((attribType.indexOf("hidden") != -1)  ||  attribType.toLowerCase() == "hidden")
			{
				if(control.getAttribute('id')) 
				{
					var attribID = control.getAttribute('id');
					if ((attribID.indexOf("hidVOG_") != -1))
					{
						if (control.value != 0)
							strQuery += '&' + attribID + '=' + control.value + '|' + document.getElementById('hidVOGQty_' + attribID.substring(7)).value;
					}
				}
			}
		}
	}

	var http = createRequestObject();

	http.open('get', '/actions/product_add_to_basket.asp?version=' + V1 + '&quantity=' + Q1 + '&depositapplied=' + DepositApplied + '&installationapplied=' + InstallationApplied + strQuery, true);

	http.onreadystatechange = function() {
		if(http.readyState == 4){
			var response = http.responseText;
			window.document.location.reload(true)
		}
	}
	http.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	http.send(null);

}

var changeRegionSelection = function () {

	var http = createRequestObject();

	http.open('get', '/actions/change_region_selection.asp?region_id=' + window.document.getElementById('RegionSelection').options[window.document.getElementById('RegionSelection').selectedIndex].value, true);

	http.onreadystatechange = function() {
		if(http.readyState == 4){
			var response = http.responseText;
			
			window.document.getElementById('spaRegionSelectionInfo').innerHTML = '';

			var aryListItems = response.split(';');
			var aryResponseItems = '';

			for(iLoopA = window.document.getElementById('SalesSiteSelection').options.length - 1; iLoopA >= 0 ; iLoopA--)
				window.document.getElementById('SalesSiteSelection').options[iLoopA] = null;

			for (iLoopA = 0; iLoopA < aryListItems.length - 1; iLoopA++)
			{
				aryResponseItems = aryListItems[iLoopA].split(':');

				var optVersionOption = document.createElement("option");
				optVersionOption.value = aryResponseItems[0];
				optVersionOption.text = aryResponseItems[1];

				window.document.getElementById('SalesSiteSelection').options.add(optVersionOption);
			}

			if ((aryListItems.length - 1) == 0)
			{
				var optVersionOptionUnavailable = document.createElement("option");
				optVersionOptionUnavailable.value = '0';
				optVersionOptionUnavailable.text = 'Regional delivery unavailable';

				window.document.getElementById('SalesSiteSelection').options.add(optVersionOptionUnavailable);
				window.document.getElementById('spaRegionSelectionInfo').innerHTML = '<p>Regional delivery is unavailable for your region.  You can still make an order through this site, however you will only be able to pick up the items direct from a sales site.</p>';
			}
		}
	}

	http.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	http.send(null);

}

var setImageZoom = function(imgSubImageBox) {

	// Get the current main image and the selected sub image
	var imgCurrentMainImage = window.document.getElementById('imgMainProdImage');
	var imgSelectedSubImage = window.document.getElementById(imgSubImageBox);

	if (imgCurrentMainImage != null)
	{
		var imgCurrentMainImage_Src = imgCurrentMainImage.src.substring(imgCurrentMainImage.src.indexOf('large/') + 6);
		var imgSelectedSubImage_Src = imgSelectedSubImage.src.substring(imgSelectedSubImage.src.indexOf('medium/') + 7);
	
		// Set the main image to the selected sub image and the sub image to the replaced main image
		window.document.getElementById('imgMainProdImage').src = '/images/products/large/' + imgSelectedSubImage_Src;
		window.document.getElementById(imgSubImageBox).src = '/images/products/medium/' + imgCurrentMainImage_Src;
	}
	
}

var setProductDeposit = function(chkBoxToCheck, P_DepositRate) {
	if (chkBoxToCheck.checked == true)
		window.document.getElementById('hidDepositRate').value = P_DepositRate;
	else
		window.document.getElementById('hidDepositRate').value = '0';
	
}


var deliveryOptionClick = function(optSelected) {

	if (optSelected == 'optPickup')
	{
		window.document.getElementById('cmbRegion').disabled = true;
		window.document.getElementById('cmbDistrib').disabled = false;
	}
	else
	{
		window.document.getElementById('cmbRegion').disabled = false;
		window.document.getElementById('cmbDistrib').disabled = true;
	}
}

var setDeliveryOption = function(VersionCountValue) {
	
	var version = window.document.getElementById('version' + VersionCountValue);
	var quantity = window.document.getElementById('quantity' + VersionCountValue);
	
	var url = '/popups/delivery_options.asp?version=' + version.value + '&quantity=' + quantity.value
	
	var params = parseQuery('ibox?height=350&amp;width=600&amp;overlaycolor=#000000&amp;showtitle=false;showclosebutton=false'.substr(5,999));
	if (showIbox(url, 'Delivery Options', params))
	{
		showBG();
		window.onscroll = maintPos;
		window.onresize = maintPos;
	}
	return false;
}

var deliveryOption_Continue = function(V_ID, Quantity) {

	var http = createRequestObject();
	
	var deliveryOption = 0;
	var deliveryOptionValue = '';
	
	if (window.document.getElementById('optLocalDelivery').checked == true)
	{
		deliveryOption = 1;
		deliveryOptionValue = window.document.getElementById('cmbRegion').options[window.document.getElementById('cmbRegion').selectedIndex].value;
	}
	else
	{
		deliveryOption = 2
		deliveryOptionValue = window.document.getElementById('cmbDistrib').options[window.document.getElementById('cmbDistrib').selectedIndex].value;
	}

	var url = '/actions/product_add_to_basket.asp?version=' + V_ID + '&quantity=' + Quantity + '&depositapplied=0&installationapplied=0&deliveryoption=' + deliveryOption + '&deliveryoptionvalue=' + deliveryOptionValue;

	http.open('get', url, true);

	http.onreadystatechange = function() {
		if(http.readyState == 4){
			var response = http.responseText;
			window.document.location.reload(true)
		}
	}
	http.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	http.send(null);

}

/**********************************
BASKET FUNCTIONS
**********************************/


//--><!]]>