var ie = (window.navigator.appName == "Microsoft Internet Explorer");
var moz = (window.navigator.appName == "Mozilla" || window.navigator.appName == "Netscape");
var safari = ((navigator.userAgent.toLowerCase().indexOf("safari") > -1) || (navigator.userAgent.toLowerCase().indexOf("konqueror") > -1));
var opera = (navigator.userAgent.toLowerCase().indexOf("opera") > -1);


function markEdit (elemId)
{
	var elem = window.document.getElementById(elemId);
	elem.setAttribute ("editing", 1);
}

function unmarkEdit (elemId)
{
	var elem = window.document.getElementById(elemId);
	elem.removeAttribute ("editing");
}

function hide (hideElemId)
{
	var hideElem = window.document.getElementById(hideElemId);
	hideElem.style.display = "none";	
}

function show (showElemId)
{
	var showElem = window.document.getElementById(showElemId);
	showElem.style.display = "";
}

function showEdit (showElemId)
{
	var showElem = window.document.getElementById(showElemId);
	showElem.style.display = "";
}

function hideNotEdit (hideElemId, elemId)
{
	var elem = window.document.getElementById(elemId);
	if (elem.getAttribute ("editing") == null)
	{
		var hideElem = window.document.getElementById(hideElemId);
		hideElem.style.display = "none";	
	}
}

function outline (elemId)
{
	var elem = window.document.getElementById(elemId);
	elem.style.backgroundColor = "#f0f0ee";
//	elem.style.borderLeftStyle = "solid";
//	elem.style.borderLeftWidth = "1";
//	elem.style.borderRightColor = "#f0b000";
//	elem.style.borderRightStyle = "solid";
//	elem.style.borderRightWidth = "1";
//	elem.style.borderTopColor = "#f0b000";
//	elem.style.borderTopStyle = "solid";
//	elem.style.borderTopWidth = "1";
//	elem.style.borderBottomColor = "#f0b000";
//	elem.style.borderBottomStyle = "solid";
//	elem.style.borderBottomWidth = "1";
}

function unoutline (elemId, elemIdEdit)
{
	var elemEdit = window.document.getElementById(elemIdEdit);
	if (elemEdit.getAttribute ("editing") == null)
	{
		var elem = window.document.getElementById(elemId);
		elem.style.backgroundColor = "";
//		elem.style.borderLeftColor = "#f0b000";
//		elem.style.borderLeftStyle = "none";
//		elem.style.borderLeftWidth = "1";
//		elem.style.borderRightColor = "#f0b000";
//		elem.style.borderRightStyle = "none";
//		elem.style.borderRightWidth = "1";
//		elem.style.borderTopColor = "#f0b000";
//		elem.style.borderTopStyle = "none";
//		elem.style.borderTopWidth = "1";
//		elem.style.borderBottomColor = "#f0b000";
//		elem.style.borderBottomStyle = "none";
//		elem.style.borderBottomWidth = "1";
	}
}

function copyValueToInnerHtml (fromElem, toElem)
{
	var to = window.document.getElementById(toElem);
	var from = window.document.getElementById(fromElem);
	if (ie)
	{
		to.innerHTML = from.innerText;
	}
	else
	{
		to.innerHTML = from.value;
	}
}

function copyInnerHtmlToValue (fromElem, toElem)
{
	var to = window.document.getElementById(toElem);
	var from = window.document.getElementById(fromElem);
	if (ie)
	{
		to.innerText = from.innerHTML;
	}
	else
	{
		to.value = from.innerHTML;
	}
}

function copyInnerHtmlToInnerHtml (fromElem, toElem)
{
	var to = window.document.getElementById(toElem);
	var from = window.document.getElementById(fromElem);
	to.innerHTML = from.innerHTML;
}

function previewImg (fromFileBrowse, toImg)
{
	var to = window.document.getElementById(toImg);
	var from = window.document.getElementById(fromFileBrowse);
	if (from.value != "")
	{
		to.src = 'file://' + from.value;
	}
}

function previewDefaultImg (fromFileBrowse, toImg, linkDataElem)
{
	var to = window.document.getElementById(toImg);
	var from = window.document.getElementById(fromFileBrowse);
	if (from.value != "")
	{
		to.src = 'file://' + from.value;
		to.onmouseout = loadDefaultImg;
	}
	
	var linkData = window.document.getElementById (linkDataElem).value.split(":");
	if (linkData[4] != "none")
	{
		to.parentNode.href = linkData[0] + "?PID=" + linkData[1] + "&NIID=" + linkData[2];
	}
	else
	{
		to.parentNode.href = "";
	}
	to.parentNode.target = "_blank";
}

function previewHoverImg (fromFileBrowse, toImg)
{
	var to = window.document.getElementById(toImg);
	var from = window.document.getElementById(fromFileBrowse);
	if (from.value != "")
	{
		to.onmouseover = loadHoverImg;
	}
}


function loadDefaultImg (e)
{
	var srcElement;
	var normalizedEvent;
	
	if (ie)
	{
		srcElement = event.srcElement;
		normalizedEvent = event;
	}
	if (moz) 
	{
		srcElement = e.target;
		normalizedEvent = e;
	}

	var re = /ViewableImage/g;
	var idPrefix;
	idPrefix = srcElement.id.replace (re, "");
	var browseImg = window.document.getElementById(idPrefix + "BrowseImage");
	
	srcElement.src = 'file://' + browseImg.value;
}

function loadHoverImg (e)
{
	var srcElement;
	var normalizedEvent;
	
	if (ie)
	{
		srcElement = event.srcElement;
		normalizedEvent = event;
	}
	if (moz) 
	{
		srcElement = e.target;
		normalizedEvent = e;
	}

	var re = /ViewableImage/g;
	var idPrefix;
	idPrefix = srcElement.id.replace (re, "");
	var hoverImg = window.document.getElementById(idPrefix + "HoverImage");
	
	srcElement.src = 'file://' + hoverImg.value;
}

function revertDefaultImg (fromImg, toImg, linkDataElem)
{
	var to = window.document.getElementById(toImg);
	var from = window.document.getElementById(fromImg);
	if (from.src != "")
	{
		to.src = from.src;
		to.onmouseout = loadSavedDefaultImg;
	}
	
	var linkData = window.document.getElementById (linkDataElem).value.split(":");
	if (linkData[4] != "none")
	{
		to.parentNode.href = linkData[0] + "?PID=" + linkData[1] + "&NIID=" + linkData[2];
	}
	else
	{
		to.parentNode.href = "";
	}
	to.parentNode.target = "_blank";
}

function revertHoverImg (fromImg, toImg)
{
	var to = window.document.getElementById(toImg);
	var from = window.document.getElementById(fromImg);
	if (from.src != "")
	{
		to.onmouseover = loadSavedHoverImg;
	}
}


function loadSavedDefaultImg (e)
{
	var srcElement;
	var normalizedEvent;
	
	if (ie)
	{
		srcElement = event.srcElement;
		normalizedEvent = event;
	}
	if (moz) 
	{
		srcElement = e.target;
		normalizedEvent = e;
	}

	var re = /ViewableImage/g;
	var idPrefix;
	idPrefix = srcElement.id.replace (re, "");
	var browseImg = window.document.getElementById(idPrefix + "HiddenImage");
	
	srcElement.src = browseImg.src;
}

function loadSavedHoverImg (e)
{
	var srcElement;
	var normalizedEvent;
	
	if (ie)
	{
		srcElement = event.srcElement;
		normalizedEvent = event;
	}
	if (moz) 
	{
		srcElement = e.target;
		normalizedEvent = e;
	}

	var re = /ViewableImage/g;
	var idPrefix;
	idPrefix = srcElement.id.replace (re, "");
	var hoverImg = window.document.getElementById(idPrefix + "HiddenHoverImage");
	
	srcElement.src = hoverImg.src;
}

function copyImgSrc (fromImg, toImg)
{
	var to = window.document.getElementById(toImg);
	var from = window.document.getElementById(fromImg);
	to.src = from.src;
}

function previewLabel (fromInput, toAnchor, linkDataElem)
{
	var from = window.document.getElementById (fromInput);
	var to = window.document.getElementById (toAnchor);
	to.innerHTML = from.value;

	var linkData = window.document.getElementById (linkDataElem).value.split(":");
	if (linkData[4] != "none")
	{
		to.href = linkData[0] + "?PID=" + linkData[1] + "&NIID=" + linkData[2];
	}
	else
	{
		to.href = "";
	}
	to.target = "_blank";
}

function previewOptionalLabel (fromInput, toCell, toShowArea)
{
	var from = window.document.getElementById (fromInput);
	var to = window.document.getElementById (toCell);
	var toSA = window.document.getElementById (toShowArea);
	to.innerHTML = from.value;
	if (from.value != "")
	{
		toSA.style.display = "";
	}
}

function tenImageSelect (prefix, imageId)
{
	var img1 = window.document.getElementById (prefix + '_Image1');
	var img2 = window.document.getElementById (prefix + '_Image2');
	var img3 = window.document.getElementById (prefix + '_Image3');
	var img4 = window.document.getElementById (prefix + '_Image4');
	var img5 = window.document.getElementById (prefix + '_Image5');
	var img6 = window.document.getElementById (prefix + '_Image6');
	var img7 = window.document.getElementById (prefix + '_Image7');
	var img8 = window.document.getElementById (prefix + '_Image8');
	var img9 = window.document.getElementById (prefix + '_Image9');
	var img10 = window.document.getElementById (prefix + '_Image10');
	
	var click1 = window.document.getElementById (prefix + '_Click1');
	var click2 = window.document.getElementById (prefix + '_Click2');
	var click3 = window.document.getElementById (prefix + '_Click3');
	var click4 = window.document.getElementById (prefix + '_Click4');
	var click5 = window.document.getElementById (prefix + '_Click5');
	var click6 = window.document.getElementById (prefix + '_Click6');
	var click7 = window.document.getElementById (prefix + '_Click7');
	var click8 = window.document.getElementById (prefix + '_Click8');
	var click9 = window.document.getElementById (prefix + '_Click9');
	var click10 = window.document.getElementById (prefix + '_Click10');

	if (img1 != null)
	{
		if (imageId == 'Image1')
		{
			img1.style.display = "";
			click1.bgColor = '#ff7200';
		}
		else
		{
			img1.style.display = "none";
			click1.bgColor = '#686E78';
		}
	}
	if (img2 != null)
	{
		if ((img2 != null) && (imageId == 'Image2'))
		{
			img2.style.display = "";
			click2.bgColor = '#ff7200';
		}
		else
		{
			img2.style.display = "none";
			click2.bgColor = '#686E78';
		}
	}
	if (img3 != null)
	{
		if ((img3 != null) && (imageId == 'Image3'))
		{
			img3.style.display = "";
			click3.bgColor = '#ff7200';
		}
		else
		{
			img3.style.display = "none";
			click3.bgColor = '#686E78';
		}
	}
	if (img4 != null)
	{
		if ((img4 != null) && (imageId == 'Image4'))
		{
			img4.style.display = "";
			click4.bgColor = '#ff7200';
		}
		else
		{
			img4.style.display = "none";
			click4.bgColor = '#686E78';
		}
	}
	if (img5 != null)
	{
		if ((img5 != null) && (imageId == 'Image5'))
		{
			img5.style.display = "";
			click5.bgColor = '#ff7200';
		}
		else
		{
			img5.style.display = "none";
			click5.bgColor = '#686E78';
		}
	}
	if (img6 != null)
	{
		if ((img6 != null) && (imageId == 'Image6'))
		{
			img6.style.display = "";
			click6.bgColor = '#ff7200';
		}
		else
		{
			img6.style.display = "none";
			click6.bgColor = '#686E78';
		}
	}
	if (img7 != null)
	{
		if ((img7 != null) && (imageId == 'Image7'))
		{
			img7.style.display = "";
			click7.bgColor = '#ff7200';
		}
		else
		{
			img7.style.display = "none";
			click7.bgColor = '#686E78';
		}
	}
	if (img8 != null)
	{
		if ((img8 != null) && (imageId == 'Image8'))
		{
			img8.style.display = "";
			click8.bgColor = '#ff7200';
		}
		else
		{
			img8.style.display = "none";
			click8.bgColor = '#686E78';
		}
	}
	if (img9 != null)
	{
		if ((img9 != null) && (imageId == 'Image9'))
		{
			img9.style.display = "";
			click9.bgColor = '#ff7200';
		}
		else
		{
			img9.style.display = "none";
			click9.bgColor = '#686E78';
		}
	}
	if (img10 != null)
	{
		if ((img10 != null) && (imageId == 'Image10'))
		{
			img10.style.display = "";
			click10.bgColor = '#ff7200';
		}
		else
		{
			img10.style.display = "none";
			click10.bgColor = '#686E78';
		}
	}
}

function submitForm (formId)
{
	var form = window.document.getElementById(formId);
	form.submit();
}

function submitDelImageForm (formId, inputId)
{
	var proceed = window.confirm ("Are you sure you want to delete this image from the server?");
	if (proceed)
	{
		var input = window.document.getElementById(inputId);
		input.value = "true";
		var form = window.document.getElementById(formId);
		form.submit();
	}
}

function pageSelect()
{
	var pageSelectNode = window.document.getElementById ("ExistingPageRow");
	var templateSelectNode = window.document.getElementById ("TemplatePageRow");
	var customLinkSelectNode = window.document.getElementById ("CustomLinkRow");

	pageSelectNode.style["display"] = "";
	templateSelectNode.style["display"] = "none";
	customLinkSelectNode.style["display"] = "none";
}

function templateSelect()
{
	var pageSelectNode = window.document.getElementById ("ExistingPageRow");
	var templateSelectNode = window.document.getElementById ("TemplatePageRow");
	var customLinkSelectNode = window.document.getElementById ("CustomLinkRow");

	pageSelectNode.style["display"] = "none";
	templateSelectNode.style["display"] = "";
	customLinkSelectNode.style["display"] = "none";
}

function customLinkSelect()
{
	var pageSelectNode = window.document.getElementById ("ExistingPageRow");
	var templateSelectNode = window.document.getElementById ("TemplatePageRow");
	var customLinkSelectNode = window.document.getElementById ("CustomLinkRow");

	pageSelectNode.style["display"] = "none";
	templateSelectNode.style["display"] = "none";
	customLinkSelectNode.style["display"] = "";
}

function textStyleOnChange (srcElem)
{
	var customTextStyleRow = window.document.getElementById ("CustomTextStyleRow");

	customTextStyleRow.style["display"] = "none";

	if (srcElem.value == "custom")
	{
		customTextStyleRow.style["display"] = "";
	}
}

function itemTypeOnChange (srcElem)
{
	var imageTypeRow = window.document.getElementById ("ImageTypeRow");
	var textTypeRow = window.document.getElementById ("TextTypeRow");

	if (srcElem.value == "Text")
	{
		imageTypeRow.style["display"] = "none";
		textTypeRow.style["display"] = "";
	}
	else if (srcElem.value == "Image")
	{
		imageTypeRow.style["display"] = "";
		textTypeRow.style["display"] = "none";
	}
}

function customCreateSelect ()
{
	var navTemplateRow = window.document.getElementById ("NavTemplateRow").style["display"] = "none";
	var itemTypeRow = window.document.getElementById ("ItemTypeRow").style["display"] = "";
	var paddingRow = window.document.getElementById ("PaddingRow").style["display"] = "";
	var linkPropRow = window.document.getElementById ("LinkPropRow").style["display"] = "";
	var linkToRow = window.document.getElementById ("LinkToRow").style["display"] = "";
	var existingPageRow = window.document.getElementById ("ExistingPageRow").style["display"] = "";
	var templatePageRow = window.document.getElementById ("TemplatePageRow").style["display"] = "";
	var imageTypeRow = window.document.getElementById ("ImageTypeRow").style["display"] = "";
	var textTypeRow = window.document.getElementById ("TextTypeRow").style["display"] = "";
}

function templateCreateSelect()
{
	var navTemplateRow = window.document.getElementById ("NavTemplateRow").style["display"] = "";
	var itemTypeRow = window.document.getElementById ("ItemTypeRow").style["display"] = "none";
	var paddingRow = window.document.getElementById ("PaddingRow").style["display"] = "none";
	var linkPropRow = window.document.getElementById ("LinkPropRow").style["display"] = "none";
	var linkToRow = window.document.getElementById ("LinkToRow").style["display"] = "none";
	var existingPageRow = window.document.getElementById ("ExistingPageRow").style["display"] = "none";
	var templatePageRow = window.document.getElementById ("TemplatePageRow").style["display"] = "none";
	var imageTypeRow = window.document.getElementById ("ImageTypeRow").style["display"] = "none";
	var textTypeRow = window.document.getElementById ("TextTypeRow").style["display"] = "none";
}

function deleteLayeredImage (e)
{
	var srcElement;
	var normalizedEvent;
	
	if (ie)
	{
		srcElement = event.srcElement;
		normalizedEvent = event;
	}
	if (moz) 
	{
		srcElement = e.target;
		normalizedEvent = e;
	}

	if (srcElement.tagName.toLowerCase() == "img")
	{
		srcElement.parentNode.parentNode.removeChild(srcElement.parentNode);
	}
	else if (srcElement.tagName.toLowerCase() == "div")
	{
		srcElement.parentNode.removeChild(srcElement);
	}
}

function allowEditLayeredImages (elemId)
{
	var tempStamps = window.document.getElementById(elemId)
	var divs = tempStamps.getElementsByTagName("div");
	
	for (var i = 0; i < divs.length; i++)
	{
		divs[i].ondblclick = deleteLayeredImage;
		divs[i].onclick = selectLayeredImage;
		divs[i].style.cursor = "pointer";
	}
}

function disallowEditLayeredImages (elemId)
{
	var tempStamps = window.document.getElementById(elemId)
	var divs = tempStamps.getElementsByTagName("div");
	
	for (var i = 0; i < divs.length; i++)
	{
		divs[i].ondblclick = null;
		divs[i].onclick = null;
		divs[i].style.cursor = "";
	}
}

function addLayeredImage (e)
{
	var srcElement;
	var normalizedEvent;
	var yOffset;
	var xOffset;
	
	if (ie)
	{
		srcElement = event.srcElement;
		normalizedEvent = event;
		yOffset = normalizedEvent.offsetY + 68;
		xOffset = normalizedEvent.offsetX + 478;
	}
	if (moz) 
	{
		srcElement = e.target;
		normalizedEvent = e;
		yOffset = normalizedEvent.pageY;
		xOffset = normalizedEvent.pageX;
	}
	
	if ((srcElement.style.cursor == null) || (srcElement.style.cursor == ""))
		return;

	var re = /ViewableImage/g;
	var idPrefix;
	idPrefix = srcElement.id.replace (re, "");
	var contentFrame = window.document.getElementById(idPrefix + "TempStamps");
	var newImageDiv = document.createElement ("div");
	
	newImageDiv.style.position = "absolute";
	newImageDiv.style.top = yOffset;
	newImageDiv.style.left = xOffset;
	newImageDiv.ondblclick = deleteLayeredImage;
	newImageDiv.onclick = selectLayeredImage;
	newImageDiv.style.cursor = "pointer";
	
	var newInput = document.createElement("input");
	newInput.type = "hidden";
	newInput.name = idPrefix + "ImageStamp";
	re = /url\(/
	var filename = srcElement.style.cursor.replace (re, "");
	re = /\), pointer/
	filename = filename.replace(re, "");
	re = /cur/
	filename = filename.replace(re, "jpg");
	
	// now convert the coordinates into IE coordinates as the
	// server will store them in IE standard coordinates
	if (moz)
	{
		xOffset = xOffset + 2;
		yOffset = yOffset + 6;
	}

	newInput.value = filename + ":" + xOffset + ":" + yOffset + ":filename:pid:linktoniid:linkname:none";
	
	var newImage = document.createElement("img");
	newImage.src = filename;
	eval ("if (" + idPrefix + "stampHeight != null) newImage.style.height = " + idPrefix + "stampHeight;");
	eval ("if (" + idPrefix + "stampWidth != null) newImage.style.width = " + idPrefix + "stampWidth;");
	
	newImageDiv.appendChild(newImage);
	newImageDiv.appendChild(newInput);
	contentFrame.appendChild(newImageDiv);
	
	srcElement.style.cursor = "";
	
	selectLayeredImageThis(newImage);
}

function selectLayeredImageThis (srcElement)
{
	var div;
	if (srcElement.tagName.toLowerCase() == "img")
	{
		div = srcElement.parentNode;
	}
	else
	{
		div = srcElement;
	}
	
	div.style.border = "2px solid blue";
	
	var re = /TempStamps/g;
	var idPrefix;
	idPrefix = div.parentNode.id.replace (re, "");
	var linkToSelect = window.document.getElementById(idPrefix + "LinkToSelect");

	var inputElem = div.getElementsByTagName("input");
	if (inputElem.length == 1)
	{
		var values = inputElem[0].value.split(":");
		if (values.length == 8)
			linkToSelect.value = values[3] + ":" + values[4] + ":" + values[5] + ":" + values[6] + ":" + values[7];
	}

	var divs = div.parentNode.getElementsByTagName("div");
	
	for (var i = 0; i < divs.length; i++)
	{
		if (divs[i] != div)
		{
			divs[i].style.border = "";
		}
	}
}


function selectLayeredImage (e)
{
	var srcElement;
	var normalizedEvent;
	
	if (ie)
	{
		srcElement = event.srcElement;
		normalizedEvent = event;
	}
	if (moz) 
	{
		srcElement = e.target;
		normalizedEvent = e;
	}

	selectLayeredImageThis (srcElement);
}


function updateSelectedStampLink (srcElem, prefix)
{
	var tempStamps = window.document.getElementById(prefix + "_TempStamps");

	var divs = tempStamps.getElementsByTagName("div");
	
	for (var i = 0; i < divs.length; i++)
	{
		if ((divs[i].style.border != null)
			&& (divs[i].style.border != ""))
		{
			var inputElem = divs[i].getElementsByTagName("input");
			if (inputElem.length == 1)
			{
				var values = inputElem[0].value.split(":");
				inputElem[0].value = values[0] + ":" + values[1] + ":" + values[2] + ":" + srcElem.value;
			}
		}
	}
}


function setImageCursor (elemId, cursorFile)
{
	var img = window.document.getElementById(elemId);
	
	img.style.cursor = 'url(' + cursorFile + '), pointer';
}

function clearImageCursor (elemId)
{
	var img = window.document.getElementById(elemId);
	
	img.style.cursor = '';
}

function copyStamps(fromId, toId)
{
	var from = window.document.getElementById(fromId);
	var to = window.document.getElementById(toId);
	
	to.innerHTML = from.innerHTML;
}

function clearStamps(elemId)
{
	var elem = window.document.getElementById(elemId);
	elem.innerHTML = "";
}

function createLinkedStamps(idPrefix, fromId, toId)
{
	var from = window.document.getElementById(fromId);
	var to = window.document.getElementById(toId);
	to.innerHTML = "";
	
	var divs = from.getElementsByTagName("div");
	
	for (var i = 0; i < divs.length; i++)
	{
		var inputElem = divs[i].getElementsByTagName("input");
		var values = inputElem[0].value.split(":");
		var newImageDiv = document.createElement ("div");
		
		newImageDiv.style.position = "absolute";
		newImageDiv.style.top = values[2];
		newImageDiv.style.left = values[1];

		var newAnchor = document.createElement("a");
		if (values[7] == "none")		
		{		
			newImageDiv.style.border = "3px solid pink";
			newAnchor.href = "";
			newAnchor.title = "Error! Link not set.";
		}
		else
		{		
			newAnchor.href = values[3] + "?PID=" + values[4] + "&NIID=" + values[5];
			newAnchor.title = values[6];
			
		}
		newAnchor.target = "_blank";
		newAnchor.onmouseover = changeHoverLabel;
		newAnchor.onmouseout = clearHoverLabel;
		
		var newImage = document.createElement("img");
		newImage.src = values[0];
		newImage.style.border = 0;
		eval ("if (" + idPrefix + "_stampHeight != null) newImage.style.height = " + idPrefix + "_stampHeight;");
		eval ("if (" + idPrefix + "_stampWidth != null) newImage.style.width = " + idPrefix + "_stampWidth;");
		
		newAnchor.appendChild(newImage);
		newImageDiv.appendChild(newAnchor);
		to.appendChild(newImageDiv);
	}
}

function changeHoverLabelThis (srcElement)
{
	var a;
	if (srcElement.tagName.toLowerCase() == "img")
	{
		a = srcElement.parentNode;
	}
	else
	{
		a = srcElement;
	}
	
	var re = /LinkedStamps/g;
	var idPrefix;
	idPrefix = a.parentNode.parentNode.id.replace (re, "");
	var hoverLabel = window.document.getElementById(idPrefix + "HoverLabel");
	
	hoverLabel.innerHTML = a.title;
}

function changeHoverLabel (e)
{
	var srcElement;
	var normalizedEvent;

	if (ie)
	{
		srcElement = event.srcElement;
		normalizedEvent = event;
	}
	if (moz) 
	{
		srcElement = e.target;
		normalizedEvent = e;
	}
	changeHoverLabelThis (srcElement);
}

function clearHoverLabelThis (srcElement)
{
	var a;
	if (srcElement.tagName.toLowerCase() == "img")
	{
		a = srcElement.parentNode;
	}
	else
	{
		a = srcElement;
	}
	
	var re = /LinkedStamps/g;
	var idPrefix;
	idPrefix = a.parentNode.parentNode.id.replace (re, "");
	var hoverLabel = window.document.getElementById(idPrefix + "HoverLabel");
	
	hoverLabel.innerHTML = "";
}

function clearHoverLabel (e)
{
	var srcElement;
	var normalizedEvent;
	
	if (ie)
	{
		srcElement = event.srcElement;
		normalizedEvent = event;
	}
	if (moz) 
	{
		srcElement = e.target;
		normalizedEvent = e;
	}

	clearHoverLabelThis (srcElement);
}

//----------------

var redirector = "";

function FindAll (root, idToFind) 
{  
	var nodes = root.childNodes;
	for (var i = 0; i < nodes.length; i++)
	{
		if (nodes[i].id == idToFind) 
		{
			return nodes[i];
		}
		else
		{
			if (nodes[i].hasChildNodes())
			{
				var tempNode = FindAll (nodes[i], idToFind);
				if (tempNode != null) return tempNode;
			}
		}
	}
	return null;
}

function FindFrames (root, idToFind)
{
	var iframes = root.getElementsByTagName ("iframe");
	var temp;
	for (var i = 0; i < iframes.length; i++)
	{
		if (iframes[i].id == idToFind) return iframes[i];
	}
	
	return null;
}

function BuildNodesCollection (element, idToFind)
{
	var retNodes = new Array();
	var nodes = element.childNodes;
	for (var i = 0; i < nodes.length; i++)
	{
		// if this node has the id we were looking for push it into the array
		if (nodes[i].id == idToFind) 
		{
			retNodes.push(nodes[i]);
		}
		// Now recurse through any children to see if they need to be added
		if (nodes[i].hasChildNodes())
		{
			var tempNode = BuildNodesCollection (nodes[i], idToFind);
			if (tempNode != null)
			{
				retNodes = retNodes.concat (tempNode);
				delete tempNode;
			}
		}
	}
	
	if (retNodes.length == 0)
	{
		return null;
	}
	else
	{
		return retNodes;
	}
}
	
function FindAllDoc (root, idToFind)
{
	return BuildNodesCollection(root.body, idToFind);
}
	
var imageLocation = null;

var hasUserCookie = false;
if (window.location.protocol.toLowerCase() == "https:")
{
	imageLocation = GetSmartHref (true, "/images");
	if (window.document.cookie.indexOf ("UserID=") > -1)
		hasUserCookie = true;
}
else
{
	imageLocation = GetSmartHref (false, "/images");
}


function CancelBubble (e)
{
	if (ie) window.event.cancelBubble = true;
	if (moz) e.stopPropagation();
}

function CumulativeParentOffset (element)
{
	var ret = new Array (2);
//	var ret = new Array (3);
	var tempRet;
	
	if ((element != null) && (element.offsetParent != null))
	{
		tempRet = CumulativeParentOffset (element.offsetParent);
		ret[0] = element.offsetLeft + tempRet[0];
		ret[1] = element.offsetTop + tempRet[1];
//		ret[2] = tempRet[2] + " " + element.tagName + "(Left=" + element.offsetLeft + ", Top=" + element.offsetTop + ")";
		delete tempRet;
	}
	else if (element != null)
	{
		ret[0] = element.offsetLeft;
		ret[1] = element.offsetTop;
//		ret[2] = element.tagName + "(Left=" + element.offsetLeft + ", Top=" + element.offsetTop + ")";
	}
	else
	{
		ret[0] = 0;
		ret[1] = 0;
//		ret[2] = "";
	}
	
	return ret;
}

function OffsetElement (elementToOffset, elementOffsetFrom, xdistance, ydistance)
{
	var cumlOffset = CumulativeParentOffset(elementOffsetFrom.offsetParent);
	
//	alert ("Left = " + elementOffsetFrom.offsetLeft);
//	alert ("Top = " + elementOffsetFrom.offsetTop);
//	alert ("Left Cuml = " + cumlOffset[0]);
//	alert ("Top Cuml = " + cumlOffset[1]);

	elementToOffset.style.left = cumlOffset[0] + elementOffsetFrom.offsetLeft + xdistance;
	elementToOffset.style.top = cumlOffset[1] + elementOffsetFrom.offsetTop + ydistance;
//	alert (cumlOffset[2]);
}

function UnderlineOnMouseOver (srcSpanElement)
{
	srcSpanElement.style.textDecoration = "underline";
}

function NoUnderlineOnMouseOut (srcSpanElement)
{
	srcSpanElement.style.textDecoration = "none";
}

function ClickableRowOnMouseOver(srcElement)
{
	srcElement.style.backgroundColor = "#e3eeaa";
}

function ClickableRowOnMouseOut(srcElement)
{
	srcElement.style.backgroundColor = "";
}

function ClickableImageMouseOver(srcImageElement)
{
}

function ClickabelImageMouseOut(srcImageElement)
{
}

function SelectableElementOnMouseOver (srcElement)
{
	if (srcElement.selected == null)
	{
		srcElement.style.color = "#993333";
	}
	else
	{
		srcElement.style.color = "#993333";
	}
	srcElement.style.cursor = "pointer";
}

function SelectableElementOnMouseOut (srcElement)
{
	if (srcElement.selected == null)
	{
		srcElement.style.color = "#666666";
	}
	else
	{
		srcElement.style.color = "#993333";
	}	
	srcElement.style.cursor = "default";
}

function SelectableElementOnClick (srcElement)
{
	srcElement.selected = true;
	srcElement.style.color = "#ffffff";
}

function ClearAllSelectableElements (srcElement, tag)
{
	var collAnchors = srcElement.getElementsByTagName(tag);
	
	if (collAnchors != null)
	{
		if (collAnchors.length != null)
		{
			for (var i=0; i < collAnchors.length; i++)
			{
				collAnchors[i].style.color = "white";
				collAnchors[i].selected = null;
			}
		}
		else
		{
			collAnchors.style.color = "white";
			collAnchors.selected = null;
		}
	}
}

function ClearAllAlphaNavSelectableElements (srcElement, tag)
{
	var collAnchors = srcElement.getElementsByTagName(tag);
	
	if (collAnchors != null)
	{
		if (collAnchors.length != null)
		{
			for (var i=0; i < collAnchors.length; i++)
			{
				collAnchors[i].style.color = "#666666";
				collAnchors[i].selected = null;
			}
		}
		else
		{
			collAnchors.style.color = "#666666";
			collAnchors.selected = null;
		}
	}
}

function SaveValueOnKeyDown (e)
{
	var srcElement;
	var normalizedEvent;
	
	if (ie)
	{
		srcElement = event.srcElement;
		normalizedEvent = event;
	}
	if (moz) 
	{
		srcElement = e.target;
		normalizedEvent = e;
	}

	// let all keys other than alphanumeric keys pass thru
	if (normalizedEvent.keyCode < 47) return;
	if ((normalizedEvent.keyCode >= 91) && (normalizedEvent.keyCode <= 93)) return;
	if ((normalizedEvent.keyCode >= 112) && (normalizedEvent.keyCode <= 165)) return;
	if (normalizedEvent.keyCode >= 246) return;

	srcElement.savedValue = srcElement.value;
}

function OnBackspaceKeydown(e)
{
	var srcElement;
	var normalizedEvent;
	
	if (ie)
	{
		srcElement = event.srcElement;
		normalizedEvent = event;
	}
	if (moz) 
	{
		srcElement = e.target;
		normalizedEvent = e;
	}

	if (normalizedEvent.keyCode == 8)
	{
		if (srcElement.value.length == 0)
		{
			var targetElementId;
			if (srcElement.id == "TelNumLastFour") 
				targetElementId = "TelNumFirstThree";
			else if (srcElement.id == "TelNumFirstThree") 
				targetElementId = "TelNumAreaCode";
			else if (srcElement.id == "PostalCodeOptionalPart") 
				targetElementId = "PostalCode";
			else
				return;
				
			var element = window.document.getElementById (targetElementId);
			element.focus();
			if (ie)
			{
				var textRange = element.createTextRange();
				textRange.move ("character", element.value.length);
				textRange.select();
			}
		}
	}

	SaveValueOnKeyDown (e);
}

function IssueMissTypedWarning (srcElement)
{
	var savedColor = srcElement.style.backgroundColor;
	if (srcElement.OriginalColor == null)
	{
		srcElement.OriginalColor = savedColor;
	}
	
	if (savedColor.toLowerCase() == "red")
	{
		srcElement.style.backgroundColor = "#ffffa0";
	}
	else
	{
		srcElement.style.backgroundColor = "red";
	}
		
	var timerID = window.setTimeout ("UndoMissTypedWarning(\"" + srcElement.id + "\")", 50);
}

function UndoMissTypedWarning (srcElementId)
{
	var srcElement = window.document.getElementById (srcElementId)
	srcElement.style.backgroundColor = srcElement.OriginalColor;
}

function ValidationResult (isValid, errorMessage)
{
	this.isValid = isValid;
	this.errorMessage = errorMessage;
	this.toString = ValidationResultToString;
}

function ValidationResultToString()
{
	return "IsValid: " + this.isValid + "\nErrorMessage :" + this.errorMessage + "\n";
}

function DisableAllInputButtonsInDocument ()
{
	var inputColl = window.document.getElementsByTagName ("input");
	
	if (inputColl != null)
	{
		if (inputColl.length != null)
		{
			for (var i=0; i < inputColl.length; i++)
			{
				if ((inputColl[i].type.toLowerCase() == "submit") ||
					(inputColl[i].type.toLowerCase() == "button"))
				{
					inputColl[i].disabled = true;
				}
			}
		}
		else
		{
			if ((inputColl.type.toLowerCase() == "submit") ||
				(inputColl.type.toLowerCase() == "button"))
			{
				inputColl.disabled = true;
			}
		}
	}
}

function SetSubmitAction (srcElement)
{
	// when the buttons are disabled the browser does not send their name/value
	// pairs in the post request.  Thus simulate sending the name/value pair
	// of the clicked button by setting the name/value pair of the action hidden input
	// control
	window.document.getElementById ("Action").name = srcElement.getAttribute("name");
	window.document.getElementById ("Action").setAttribute("value", srcElement.getAttribute("value"));
}

function GetSmartHref (secure, urlPostfix)
{
	var protocol = "http://";
	if (secure == true)
	{
		protocol = "https://";
	}
	
	if (window.location.pathname.substr (0, "/CMS/".length).toLowerCase() == "/CMS/")
	{
		return protocol + window.location.host + "/CMS" + urlPostfix;
	}
	else if (window.location.pathname.substr (0, "/CMS/".length).toLowerCase() == "/CMS/")
	{
		return protocol + window.location.host + "/CMS" + urlPostfix;
	}
	else
	{
		return protocol + window.location.host + urlPostfix;
	}
}


function getPathFromFilename (path)
{
	var indexFilenameSeperator = path.lastIndexOf ('/');
	if (indexFilenameSeperator != -1)
		return path.substr (0, indexFilenameSeperator);
	else
		return "";
}

function getImageLocationRedirector()
{
	var tempPath = window.location.pathname.toLowerCase();
	if (tempPath.lastIndexOf ('/secure/') == -1)
	{
		// not found
		return "";
	}
	else
	{
		// found secure
		return "../";
	}
}

function OnClickGotoTable(page)
{
	window.location = page;
}

function OnClickGotoCreateAccount(srcElement)
{
	window.parent.document.getElementById("SignupButton").click();
}

function ParentGotoPage(page)
{
	window.parent.location = page;
	if (ie) window.event.returnValue = false;
	if (moz) return false;
}

function Trim(str)
{
	var tempValue = str;
	var re = /^\s*/;
	tempValue = tempValue.replace (re, "");
	re = /\s*$/;
	tempValue = tempValue.replace (re, "");
	return tempValue;
}

function GetQueryVariableValue (varName)
{
	var query = window.location.search;
	var re = new RegExp (varName + "=", "i");
	var matchResult = query.match(re);
	if (matchResult != null)
	{
		var querySubstring = query.substr (matchResult.lastIndex);
		re = /&|#/;
		matchResult = querySubstring.match (re);
		if (matchResult != null)
		{
			return querySubstring.substr (0, matchResult.index);
		}
		else
		{
			return querySubstring
		}
	}
	else
	{
		return null;
	}
}

// ------------------------------------ Login.aspx --------------------------------------------
function LoginOnClick (e)
{
	var srcElement;
	var normalizedEvent;
	
	if (ie)
	{
		srcElement = event.srcElement;
		normalizedEvent = event;
	}
	if (moz) 
	{
		srcElement = e.target;
		normalizedEvent = e;
	}

	var errorMessage = "The following entries do not conform to the user account requirements.  Please correct them and re-submit the login request.<br><br>";
	
	var validationResult = new ValidationResult (true, errorMessage);
	ValidateLoginInfo(srcElement, validationResult);
	
	if (validationResult.isValid == false)
	{
		normalizedEvent.returnValue = false;
		window.document.getElementById ("ErrorMessage").innerHTML = validationResult.errorMessage;
		window.document.getElementById ("ErrorMessageRow").style.display = "";
		if (!safari) window.document.getElementById ("ErrorMessage").scrollIntoView (true);
		delete validationResult;
		return false;
	}
	else
	{
		SetSubmitAction (srcElement);
	}
	delete validationResult;
}


// ---------------------  Script file used by UserInfo.aspx and its derivates (CreateAccount.aspx)--------------------------------
function EmailIDOnKeyUpValidate(e)
{
	var srcElement;
	var normalizedEvent;
	
	if (ie)
	{
		srcElement = event.srcElement;
		normalizedEvent = event;
	}
	if (moz) 
	{
		srcElement = e.target;
		normalizedEvent = e;
	}

	// let all keys other than alphanumeric keys pass thru
	if (normalizedEvent.keyCode < 47) return;
	if ((normalizedEvent.keyCode >= 91) && (normalizedEvent.keyCode <= 93)) return;
	if ((normalizedEvent.keyCode >= 112) && (normalizedEvent.keyCode <= 165)) return;
	if (normalizedEvent.keyCode >= 246) return;

	// The regexp for a valid email addres is: /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
	// The following regexp is an expression that encapsulated what happens when the user is entering an email address
	// and not all the parts of the email address have been typed yet.
	var re = /^\w+([-+.]($|\w+))*(@(\w+([-.]($|\w+))*(\.(\w+([-.]($|\w+))*)?)?)?)?$/;
	var tempValue = srcElement.value;
	var matchResult = tempValue.match (re);
	
	if (matchResult == null)
	{
		srcElement.value = srcElement.savedValue;
		// need to warn the user somehow that this character was ignored and why
		IssueMissTypedWarning (srcElement);
		normalizedEvent.returnValue = false;
		return false;
	}
}

function TelNumAreaCodeOnKeyUpValidateAndTab(e)
{
	var srcElement;
	var normalizedEvent;
	
	if (ie)
	{
		srcElement = event.srcElement;
		normalizedEvent = event;
	}
	if (moz) 
	{
		srcElement = e.target;
		normalizedEvent = e;
	}

	// let all keys other than alphanumeric keys pass thru
	if (normalizedEvent.keyCode < 47) return;
	if ((normalizedEvent.keyCode >= 91) && (normalizedEvent.keyCode <= 93)) return;
	if ((normalizedEvent.keyCode >= 112) && (normalizedEvent.keyCode <= 165)) return;
	if (normalizedEvent.keyCode >= 246) return;

	var re = /^\d{0,3}$/;
	var tempValue = srcElement.value;
	var matchResult = tempValue.match (re);
	
	if (matchResult == null)
	{
		srcElement.value = srcElement.savedValue;
		// need to warn the user somehow that this character was ignored and why
		IssueMissTypedWarning (srcElement);
		normalizedEvent.returnValue = false;
		return false;
	}
	else if (srcElement.value.length == 3)
	{
		window.document.getElementById ("TelNumFirstThree").focus();
		normalizedEvent.returnValue = false;
		return false;
	}
}

function TelNumFirstThreeOnKeyUpValidateAndTab(e)
{
	var srcElement;
	var normalizedEvent;
	
	if (ie)
	{
		srcElement = event.srcElement;
		normalizedEvent = event;
	}
	if (moz) 
	{
		srcElement = e.target;
		normalizedEvent = e;
	}

	if (normalizedEvent.keyCode < 47) return;
	if ((normalizedEvent.keyCode >= 91) && (normalizedEvent.keyCode <= 93)) return;
	if ((normalizedEvent.keyCode >= 112) && (normalizedEvent.keyCode <= 165)) return;
	if (normalizedEvent.keyCode >= 246) return;

	var re = /^\d{0,3}$/;
	var tempValue = srcElement.value;
	var matchResult = tempValue.match (re);
	
	if (matchResult == null)
	{
		srcElement.value = srcElement.savedValue;
		// need to warn the user somehow that this character was ignored and why
		IssueMissTypedWarning (srcElement);
		normalizedEvent.returnValue = false;
		return false;
	}
	else if (srcElement.value.length == 3)
	{
		window.document.getElementById ("TelNumLastFour").focus();
		normalizedEvent.returnValue = false;
		return false;
	}
}

function TelNumLastFourOnKeyUpValidate(e)
{
	var srcElement;
	var normalizedEvent;
	
	if (ie)
	{
		srcElement = event.srcElement;
		normalizedEvent = event;
	}
	if (moz) 
	{
		srcElement = e.target;
		normalizedEvent = e;
	}

	// if the user hit the enter key - let it pass thru to affect the submit and the validation that happens on the
	// submit
	if (normalizedEvent.keyCode < 47) return;
	if ((normalizedEvent.keyCode >= 91) && (normalizedEvent.keyCode <= 93)) return;
	if ((normalizedEvent.keyCode >= 112) && (normalizedEvent.keyCode <= 165)) return;
	if (normalizedEvent.keyCode >= 246) return;

	var re = /^\d{0,4}$/;
	var tempValue = srcElement.value;
	var matchResult = tempValue.match (re);
	
	if (matchResult == null)
	{
		srcElement.value = srcElement.savedValue;
		// need to warn the user somehow that this character was ignored and why
		IssueMissTypedWarning (srcElement);
		normalizedEvent.returnValue = false;
		return false;
	}
}

function ValidateUserName (srcElement, validationResult)
{
	var re;
	var matchResult;

	// Username is require - it must be a valid email address
	var userName = window.document.getElementById("UserInformation_Username");
	userName.style.backgroundColor = "#ffffa0";
	if ((userName.value != null) && (userName.value != ""))
	{
		re = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
		matchResult = userName.value.match (re);
		
		if (matchResult == null)
		{
			validationResult.isValid = false;
			userName.style.backgroundColor = "#dfad7b";
			validationResult.errorMessage += "- Email ID: specify a valid email address (e.g. someone@somedomain.com).<br>";
		}
	}
	else
	{
		validationResult.isValid = false;
		userName.style.backgroundColor = "#dfad7b";
		validationResult.errorMessage += "- Email ID: please specify your email address.<br>";
	}
}

function ValidateLoginInfo (srcElement, validationResult)
{
	var re;
	var matchResult;
	// First validate that all the required fields have values

	// Username is require - it must be a valid email address
	ValidateUserName (srcElement, validationResult);

	// Password is a required field that must be 8-20 characters long
	var password = window.document.getElementById("UserInformation_Password");
	password.style.backgroundColor = "#ffffa0";
	if ((password.value != null) && (password.value != "") && (password.value.length > 7))
	{
		re = /^\S+$/;
		matchResult = password.value.match (re);
		
		if (matchResult == null)
		{
			validationResult.isValid = false;
			password.style.backgroundColor = "#dfad7b";
			validationResult.errorMessage += "- Password: specify a password that is between 8-20 characters long and without any whitespace characters.<br>";
		}
	}
	else
	{
		if (srcElement.form.id != "UserInfoForm")
		{
			validationResult.isValid = false;
			password.style.backgroundColor = "#dfad7b";
			validationResult.errorMessage += "- Password: please specify a password for your account that is between 8-20 characters long and without any whitespace characters.<br>";
		}
	}
}

function ValidateUserInfo (srcElement, validationResult)
{
	var re;
	var matchResult;
	// First validate that all the required fields have values
	ValidateLoginInfo (srcElement, validationResult);
	
	// Now get a reference to the password control for use in this function
	var password = window.document.getElementById("UserInformation_Password");
	// Password confirmation is a required field and must match the password field
	var confirmPassword = window.document.getElementById("UserInformation_ConfirmPassword");
	confirmPassword.style.backgroundColor = "#ffffa0";
	if ((confirmPassword.value == null) || (confirmPassword.value == "") || (confirmPassword.value != password.value))
	{
		// The following is the NOT OF ((confirmPassword.value == "") && (srcElement.form.id == "UserInfoForm"))
		if ((confirmPassword.value != "") || (srcElement.form.id != "UserInfoForm"))
		{
			validationResult.isValid = false;
			password.style.backgroundColor = "#dfad7b";
			password.value = "";
			confirmPassword.style.backgroundColor = "#dfad7b";
			confirmPassword.value = "";
			validationResult.errorMessage += "- Password & Confirmation: Your password and its confirmation do not match.<br>";
		}
	}
}

function UpdateUserInfoOnClick (e)
{
	var srcElement;
	var normalizedEvent;
	
	if (ie)
	{
		srcElement = event.srcElement;
		normalizedEvent = event;
	}
	if (moz) 
	{
		srcElement = e.target;
		normalizedEvent = e;
	}

	window.document.getElementById ("ErrorMessageRow").style.display = "none";
	window.document.getElementById ("NotificationMessageRow").style.display = "none";

	var errorMessage = "The following entries do not conform to the user account requirements.  Please correct them and re-submit the user information update request.<br><br>";
	
	var validationResult = new ValidationResult (true, errorMessage);
	ValidateUserInfo(srcElement, validationResult);
	
	if (validationResult.isValid == false)
	{
		window.document.getElementById ("ErrorMessage").innerHTML = validationResult.errorMessage;
		window.document.getElementById ("ErrorMessageRow").style.display = "";
		if (!safari) window.document.getElementById ("ErrorMessage").scrollIntoView (true);
		normalizedEvent.returnValue = false;
		delete validationResult;
		return false;
	}
	else
	{
		SetSubmitAction (srcElement);
	}
	delete validationResult;
}

function AddressPostalCodeOnKeyUpValidateAndTab (e)
{
	var srcElement;
	var normalizedEvent;
	
	if (ie)
	{
		srcElement = event.srcElement;
		normalizedEvent = event;
	}
	if (moz) 
	{
		srcElement = e.target;
		normalizedEvent = e;
	}

	if (normalizedEvent.keyCode < 47) return;
	if ((normalizedEvent.keyCode >= 91) && (normalizedEvent.keyCode <= 93)) return;
	if ((normalizedEvent.keyCode >= 112) && (normalizedEvent.keyCode <= 165)) return;
	if (normalizedEvent.keyCode >= 246) return;
	
	var re = /^\d{0,5}-?\d{0,4}$/;
	var tempValue = srcElement.value;
	var matchResult = tempValue.match (re);
	
	if (matchResult == null)
	{
		normalizedEvent.returnValue = false;
		srcElement.value = srcElement.savedValue;
		// need to warn the user somehow that this character was ignored and why
		IssueMissTypedWarning (srcElement);
		return false;
	}
}

function AddressPostalCodeOptionalPartOnKeyUpValidate (e)
{
	var srcElement;
	var normalizedEvent;
	
	if (ie)
	{
		srcElement = event.srcElement;
		normalizedEvent = event;
	}
	if (moz) 
	{
		srcElement = e.target;
		normalizedEvent = e;
	}

	if (normalizedEvent.keyCode < 47) return;
	if ((normalizedEvent.keyCode >= 91) && (normalizedEvent.keyCode <= 93)) return;
	if ((normalizedEvent.keyCode >= 112) && (normalizedEvent.keyCode <= 165)) return;
	if (normalizedEvent.keyCode >= 246) return;
	
	var re = /^\d{0,4}$/;
	var tempValue = srcElement.value;
	var matchResult = tempValue.match (re);
	
	if (matchResult == null)
	{
		normalizedEvent.returnValue = false;
		srcElement.value = srcElement.savedValue;
		// need to warn the user somehow that this character was ignored and why
		IssueMissTypedWarning (srcElement);
		return false;
	}
}

function ValidateRegistrationInfo (srcElement, validationResult)
{
	var re;
	var matchResult;
	// First validate that all the required fields have values
	var customerFirstName = window.document.getElementById("CustomerFirstName");
	var customerLastName = window.document.getElementById("CustomerLastName");
	customerFirstName.style.backgroundColor = "#ffffa0";
	customerLastName.style.backgroundColor = "#ffffa0";
	if ((customerFirstName.value == null) || (customerFirstName.value == ""))
	{
		validationResult.isValid = false;
		customerFirstName.style.backgroundColor = "#dfad7b";
		validationResult.errorMessage += "- Your First Name: please specify.<br>";
	}
	
	if ((customerLastName.value == null) || (customerLastName.value == ""))
	{
		validationResult.isValid = false;
		customerLastName.style.backgroundColor = "#dfad7b";
		validationResult.errorMessage += "- Your Last Name: please specify.<br>";
	}
	
	ValidateUserName (srcElement, validationResult);
	
	// Telephone number parts are required, of certain lenght and must be digits
	// Do not show too many error messages with respect to telephone numbers hence recurse the validation
	var telNumAreaCode = window.document.getElementById("TelNumAreaCode");
	telNumAreaCode.style.backgroundColor = "#ffffa0";
	var telNumberFirstThree = window.document.getElementById("TelNumFirstThree");
	telNumberFirstThree.style.backgroundColor = "#ffffa0";
	var telNumberLastFour = window.document.getElementById("TelNumLastFour");
	telNumberLastFour.style.backgroundColor = "#ffffa0";
	
	var telErrorMessage = null;
	
	if ((telNumAreaCode.value != null) && (telNumAreaCode.value != ""))
	{
		re = /^\d{3}$/;
		matchResult = telNumAreaCode.value.match (re);
		
		if (matchResult == null)
		{
			validationResult.isValid = false;
			telNumAreaCode.style.backgroundColor = "#dfad7b";
			telErrorMessage = "- Tel. # : specify a valid telephone number including area code.<br>";
		}
	}
	else
	{
		validationResult.isValid = false;
		telNumAreaCode.style.backgroundColor = "#dfad7b";
		telErrorMessage = "- Tel. # : specify a valid telephone number including area code.<br>";
	}

	if ((telNumberFirstThree.value != null) && (telNumberFirstThree.value != ""))
	{
		re = /^\d{3}$/;
		matchResult = telNumberFirstThree.value.match (re);
		
		if (matchResult == null)
		{
			validationResult.isValid = false;
			telNumberFirstThree.style.backgroundColor = "#dfad7b";
			telErrorMessage = "- Tel. # : specify a valid telephone number including area code.<br>";
		}
	}
	else
	{
		validationResult.isValid = false;
		telNumberFirstThree.style.backgroundColor = "#dfad7b";
		telErrorMessage = "- Tel. # : specify a valid telephone number including area code.<br>";
	}

	if ((telNumberLastFour.value != null) && (telNumberLastFour.value != ""))
	{
		re = /^\d{4}$/;
		matchResult = telNumberLastFour.value.match (re);
		
		if (matchResult == null)
		{
			validationResult.isValid = false;
			telNumberLastFour.style.backgroundColor = "#dfad7b";
			telErrorMessage = "- Tel. # : specify a valid telephone number including area code.<br>";
		}
	}
	else
	{
		validationResult.isValid = false;
		telNumberLastFour.style.backgroundColor = "#dfad7b";
		telErrorMessage = "- Tel. # : specify a valid telephone number including area code.<br>";
	}
	
	if (telErrorMessage != null)
	{
		validationResult.errorMessage += telErrorMessage;
	}
}

function SubmitRegistrationOnClick (e)
{
	var srcElement;
	var normalizedEvent;
	
	if (ie)
	{
		srcElement = event.srcElement;
		normalizedEvent = event;
	}
	if (moz) 
	{
		srcElement = e.target;
		normalizedEvent = e;
	}

	window.document.getElementById ("ErrorMessageRow").style.display = "none";
	window.document.getElementById ("NotificationMessageRow").style.display = "none";

	var errorMessage = "The following entries do not conform to the form requirements.  Please correct them.<br><br>";
	
	var validationResult = new ValidationResult (true, errorMessage);
	ValidateRegistrationInfo(srcElement, validationResult);
	
	if (validationResult.isValid == false)
	{
		normalizedEvent.returnValue = false;
		window.document.getElementById ("ErrorMessage").innerHTML = validationResult.errorMessage;
		window.document.getElementById ("ErrorMessageRow").style.display = "";
		if (!safari) window.document.getElementById ("ErrorMessage").scrollIntoView (true);
		delete validationResult;
		return false;
	}
	else
	{
		SetSubmitAction (srcElement);
	}
	delete validationResult;
}
