
/*
Copyright (C) DTDigital Pty Ltd :: www.dtdigital.com.au ::
Unauthorised modification / use is a criminal offence, and
will be prosecuted to the fullest extent permitted by law.
All Rights Reserved.
*/

NAVarr = new Array
(
	'navhome',
	'navabout',
	'navfabric',
	'navcollection',
	'navlocations',
	'navcare',
	'navcontact',
	'navbrochure',
	'navbrochure2',
	'navmembers',
	'collecnavdecor',
	'collecnavdrapery',
	'collecnavtp',
	'collecnavuphol',
	'collecnavview'
);


if (document.images)
{
	for (var NAVitem in NAVarr)
	{
		 for (var NAVicount=0; NAVicount < 2; NAVicount++)
		 {
				eval('b' + NAVarr[NAVitem] + NAVicount + ' = new Image()');
				eval('b' + NAVarr[NAVitem] + NAVicount + '.src = "assets/swap_' + NAVarr[NAVitem] + '_' + NAVicount + '.gif"');
		 }
	}
}


function BturnOn(imageName)
{
	MouseOverEffect(imageName, 1);
}


function BturnOff(imageName)
{
	MouseOverEffect(imageName, 0);
}


function MouseOverEffect(imageName, imageState)
{
	if (document.images)
	{
		var imageNumber = '';
		if (arguments.length > 2)
		{
			imageNumber = arguments[2];
		}

		var image = getEl(imageName + imageNumber);
		if (image)
		{
			image.src = eval('b' + imageName + imageState + '.src');
		}

		// document[imageName + imageNumber].src = eval('b' + imageName + imageState + '.src');
	}
}


function BturnOnInput(obj, imageName)
{
	if (obj.src)
	{
		obj.src = eval('b' + imageName + '1.src');
	}
}


function BturnOffInput(obj, imageName)
{
	if (obj.src)
	{
		obj.src = eval('b' + imageName + '0.src');
	}
}


function imgPopup(path)
{
	if (path)
	{
		window.open('utils_imagepopup.aspx?path=' + path, 'popup', 'width=400, height=300, toolbar=no, status=no, scrollbars=yes, resizable=yes');
	}
}


function ddRedirect(dd)
{
	if (dd.options[dd.selectedIndex].value != '')
	{
		self.location = dd.options[dd.selectedIndex].value;
	}
}


function resizeWindow(layoutAdjustmentW, layoutAdjustmentH)
{
	if ((document.images) && (document.theimage) && (document.theimage.width))
	{
		var imageW = document.theimage.width;
		var imageH = document.theimage.height;

		var screenW = screen.availWidth;
		var screenH = screen.availHeight;

		var resizeToScreen = false;

		if (imageW <= screenW)
		{
			resizeW = imageW;
		}
		else
		{
			resizeW = screenW;
			resizeToScreen = true;
		}

		if (imageH <= screenH)
		{
			resizeH = imageH;
		}
		else
		{
			resizeH = screenH;
			resizeToScreen = true;
		}

		var userAgent = navigator.userAgent;

		// Windows Adjustments
		if (userAgent.indexOf('Windows') != -1)
		{
			if (userAgent.indexOf('MSIE 5') != -1)
			{
				resizeW += 29;
				resizeH += 38;

				if (resizeToScreen)
				{
					resizeW -= 29;
				}
			}

			if (userAgent.indexOf('MSIE 6') != -1)
			{
				resizeW += 31;
				resizeH += 61;
			}

			if (userAgent.indexOf('Firefox') != -1)
			{
				resizeW += 8;
				resizeH += 56;

				if (resizeToScreen)
				{
					resizeW -= 8;
				}
			}

			if (userAgent.indexOf('Netscape/7') != -1) {
				resizeW += 8;
				resizeH += 36;

				if (resizeToScreen)
				{
					resizeW -= 8;
				}
			}
		}

		// Mac Adjustments
		if (userAgent.indexOf('Mac') != -1)
		{
			if (userAgent.indexOf('Safari') != -1)
			{
				resizeW += 0;
				resizeH += 23;
			}

			if (userAgent.indexOf('MSIE 5') != -1)
			{
				resizeW += 0;
				resizeH += 0;
			}

			if (userAgent.indexOf('Firefox') != -1)
			{
				resizeW += 0;
				resizeH += 18;
			}

			if (userAgent.indexOf('Netscape/7') != -1)
			{
				resizeW += 0;
				resizeH += 2;
			}
		}

		if (!isNaN(layoutAdjustmentW))
		{
			resizeW += layoutAdjustmentW;
		}

		if (!isNaN(layoutAdjustmentH))
		{
			resizeH += layoutAdjustmentH;
		}

		if (resizeToScreen)
		{
			window.moveTo(0, 0);
		}

		window.resizeTo(resizeW, resizeH);
	}
}


function WindowPopup(url)
{
	if (url)
	{
		window.open(url, 'WindowPopup', 'width=600, height=700, toolbar=0, scrollbars=1, location=0, menubar=1, resizeable=1, status=0');
		return false;
	}
}


/* ========================================================================= */
/* ::::::::::::::::::: WARWICK FABRICS COLOUR PICKER TOOL :::::::::::::::::: */
/* ========================================================================= */
function SwitchFabricColourInDetailedViewTriggerUsingHtmlAnchor(index)
{
	SwitchFabricColourInDetailedViewTriggerUsingDropDownList(index);

	var select = getEl(FabricCodeDropDownListID);
	if (select)
	{
		select.selectedIndex = index;
	}
}


function SwitchFabricColourInDetailedViewTriggerUsingDropDownList(index)
{
	var div = getEl('cSelection');

	if (div)
	{
		var image = getEl(FabricHeroImageID);
		var colourname = getEl(FabricImageColourNameDivID);

		if (image)
		{
			image.src = FabricSmallImageLinksArray[index];
			image.alt = FabricImageAltTextsArray[index];
			image.title = image.alt;

			if (colourname)
			{
				// For IE.
				colourname.innerText = FabricImageColourNamesArray[index];

				// For Firefox.
				colourname.textContent = FabricImageColourNamesArray[index];
				
				// Thickbox fix.
				fabricColour = FabricImageColourNamesArray[index];
			}
		}

		var hyperlink = getEl(FabricPopupHyperLinkID);
		if (hyperlink)
		{
			hyperlink.href = FabricLargeImageLinksArray[index];
		}

		var hiddeninput = getEl(FabricProductIDHtmlInputHiddenID);
		if (hiddeninput)
		{
			hiddeninput.value = FabricImageProductIDsArray[index];
		}
	}
}


function SwitchFabricColourInListingView(index, fabricHeroImageID, fabricProductIDHtmlInputHiddenID, fabricHtmlAnchorIDsArray, fabricImageAltTextsArray, fabricSmallImageLinksArray, fabricImageProductIDsArray)
{
	var div = getEl('cSelection');

	if (div)
	{
		var productID = fabricImageProductIDsArray[index];

		var image = getEl(fabricHeroImageID);
		if (image)
		{
			image.src = fabricSmallImageLinksArray[index];
			image.alt = fabricImageAltTextsArray[index];
			image.title = image.alt;
		}

		var hiddeninput = getEl(fabricProductIDHtmlInputHiddenID);
		if (hiddeninput)
		{
			hiddeninput.value = productID;
		}

		if (fabricHtmlAnchorIDsArray.length > 0)
		{
			var link = getEl(fabricHtmlAnchorIDsArray[0]);
			if (link)
			{
				var href = link.href.replace(/ProductID\=[0-9]*/, 'ProductID=' + productID);
				link.href = href;

				for (var i = 1; i < fabricHtmlAnchorIDsArray.length; i++)
				{
					link = getEl(fabricHtmlAnchorIDsArray[i]);
					if (link)
					{
						link.href = href;
					}
				}
			}
		}
	}
}


function getEl(id)
{
	if (document.getElementById)
	{
		if (document.getElementById(id))
		{
			return document.getElementById(id);
		}
		else
		{
			return false;
		}
	}
	else
	{
		return false;
	}
}
/* ========================================================================= */


function showinfo(name)
{
	getEl(name).style.display = 'block';
}

var fabricName, fabricColour
function showimage()
{
	var imagepath = getEl('TB_Image').src;
	window.open('print-fabric.aspx?' + imagepath + '&amp;' + fabricName + '&amp;' + fabricColour);
}


function ValidateFabricResults(element)
{
	if (parseInt(element.value) > 0)
	{
		var cell = element.parentNode;
		var row = cell.parentNode;
		var inputs = row.getElementsByTagName('input') || document.all('input');

		for (var i = 0; i < inputs.length; i++)
		{
			var input = inputs[i];

			if (input.type == 'checkbox')
			{
				input.checked = true;
				CheckBoxClicked(input);
			}
		}
	}
}


function CheckBoxClicked(element)
{
	var cell = element.parentNode.parentNode;
	var row = cell.parentNode;
	var inputs = row.getElementsByTagName('input') || row.all('input');

	for (var i = 0; i < inputs.length; i++)
	{
		var input = inputs[i];

		if ((input.type == 'text') && (input.className == 'textbox08') && (input.value == ''))
		{
			input.value = '1';
		}
	}

	HideShowButton(row);
}


function HideShowButton(row)
{
	var inputs = row.parentNode.parentNode.parentNode.getElementsByTagName('input') || row.parentNode.parentNode.parentNode.all('input');
	var visible = false;

	for (var i = 0; i < inputs.length; i++)
	{
		var input = inputs[i];

		if ((input.type == 'checkbox') && input.checked)
		{
			visible = true;
			break;
			break;
		}
	}

	var button = getEl(AddToCartImageButtonID);
	if (button)
	{
		button.style.display = visible ? 'block' : 'none';
	}
}

