	var isNN = (navigator.appName.indexOf("Netscape")!=-1);

	function selectAllOptions(selectBox)
	{
		for(var i=0; i<selectBox.options.length; i++)
		{
			selectBox.options[i].selected = true;
		}
	}

	function deselectAllOptions(selectBox)
	{
		for(var i=0; i<selectBox.options.length; i++)
		{
			selectBox.options[i].selected = false;
		}
	}

	function addEntryWithBlank(text, value, to)
	{
		var destOption = document.createElement("OPTION");
		destOption.setAttribute("value", value);
		var txtNode = document.createTextNode(text);
		destOption.appendChild(txtNode);
		to.appendChild(destOption);
	}
	
	function addUniqueEntry(text, value, to)
	{
		if(text == "")
			return false;
		
		var destOption = document.createElement("OPTION");
		destOption.setAttribute("value", value);
		var txtNode = document.createTextNode(text);
		destOption.appendChild(txtNode);

		for(var i=0;i<to.options.length;++i)
		{
			if(text == to.options[i].text)
			{
				alert("That SKU combination will create a duplicate entry. Please pick different attribute values.");
				return false;
			}
		}

		to.appendChild(destOption);
	}	

	function addEntry(text, value, to)
	{
		if(text == "" || value == "")
			return;

		var destOption = document.createElement("OPTION");
		destOption.setAttribute("value", value);
		var txtNode = document.createTextNode(text);
		destOption.appendChild(txtNode);
		/*
		for(var i=0;i<to.options.length;++i)
		{
			if(text.localeCompare(to.options[i].text) <= 0)
			{
				to.insertBefore(destOption, to.options[i]);
				return;
			}
		}
		*/
		to.appendChild(destOption);
	}
	
	//** Admin User Logon prompt. This function is used to confirm an admin user logon.
	
	function userLogonPrompt()
	{
		var ans; 
		ans=window.confirm('You are attempting to logon as a user that could be shopping on the site right now, Do you want to logon as that user?'); 

		return ans;
	}	
	
	
	function moveEntry(selectbox, option, to)
	{
		to.appendChild(selectbox.removeChild(option));
	}
	
	function moveEntries(from, to)
	{
		if(from.selectedIndex != -1)
		{
			if(to.options)
			{
				while(from.selectedIndex != -1)
				{
					moveEntry(from,from.options[from.selectedIndex],to);
				}
			}			
			else
			{
				to.value = from.options[from.selectedIndex].text;
			}
		}
		else
		{
			alert("Please select at least one value.");
		}
	}
	
	function moveLimitedEntries(from, to, name, limit)
	{
		var count = to.length;
		
		if(from.selectedIndex != -1)
		{
			for(var i=0; i<from.options.length; i++)
			{
				if(from.options[i].selected)
				{
					count++;
				} 
				if(count > limit)
				{
					alert("A limit of " + limit + " deparments may be assigned to " + name);
					return;
				}
			}
		}

		if(from.selectedIndex != -1)
		{
			if(to.options)
			{
				while(from.selectedIndex != -1)
				{
					moveEntry(from,from.options[from.selectedIndex],to);
				}
			}			
			else
			{
				to.value = from.options[from.selectedIndex].text;
			}
		}
		else
		{
			alert("Please select at least one value.");
		}
	}
	
	function moveEntriesWithSeqNo(from, to, seqNo)
	{
		var addOnText, addOnValue;
		
		if(seqNo)
		{
			addOnText = " - Seq#"+seqNo;
			addOnValue = "_"+seqNo;
		}
		else
		{
			addOnText = "";
			addOnValue="";
		}
		
		if(from.selectedIndex != -1)
		{
			if(to.options)
			{
				for(var i=from.selectedIndex; i<from.options.length; i++)
				{
					if(from.options[i].selected)
					{
						addEntry(from.options[i].text+addOnText,from.options[i].value+addOnValue,to);
					}
				}
				removeEntries(from);
			}			
			else
			{
				to.value = from.options[from.selectedIndex].text+addOnText;
			}
		}
		else
		{
			alert("Please select at least one value.");
		}
	}

	function removeEntries(from)
	{
		if(from.options)
		{
			while(from.selectedIndex != -1)
			{
				from.removeChild(from.options[from.selectedIndex]);
			}
		}
		else
		{
			from.value = "";
		}
	}

	function replaceEntry(from, to)
	{
		if(to.options.length > 0)
		{
			moveEntry(to, to.options[0], from);
		}
		moveEntry(from, from.options[from.selectedIndex], to);
	}
	
	function addSequenceNumber(seqNoSel)
	{
		var seqNo = parseInt(seqNoSel.options[seqNoSel.options.length - 1].text)+1;
		if(parseInt(seqNoSel.value) == (seqNo-1))
		{
			seqNoSel.options[seqNoSel.options.length] = new Option(seqNo, seqNo, true, true);
		}
	}
	
	function setImageSrc(image, imageSrc, dir)
	{
		if(imageSrc.match(/^[\/\\]/) != null)
		{
			image.src =  dir + imageSrc.replace("\\", "/");
			//image.src = "file://"+imageSrc.replace("\\", "/");
		}
		else
		{
			image.src =  dir + imageSrc.replace("\\", "/");
			//image.src = "file:///"+imageSrc.replace("\\", "/");
		}
	}
	
	function openPopup(url,width,height)
	{
		try
		{
			var newWindow = window.open(url,"","top=100,left=100,width="+width+",height="+height+",scrollbars=yes,menubar=no,toolbar=no,resizable=no");
			newWindow.opener = self;
		}
		catch(e)
		{
		}
	}
	
	function copyToOpener(destField,value)
	{
		try
		{
			opener.document.getElementById(destField).value = value;
			window.close();
		}
		catch(e)
		{
		}
	}
	
	function moveEntryFromList(dest, source)
	{
		var productDest = document.getElementById(dest);
		if(productDest.selectedIndex >=0){
			
			document.getElementById(source).value = productDest.options[productDest.selectedIndex].text;
		}
		removeEntries(productDest);
	}

	function updateImage(image, imageName, textTag, textValue, imageDir)
	{	
		setImageSrc(image, imageName, imageDir); 
		var matcharray = imageName.match(/([^\\\/]*)$/); 
		document.getElementById(textTag).innerHTML = textValue+' ('+matcharray[0]+'):';
	}
	
	function toggleRadio(destField) {
		try
		{
			radioField = document.getElementById(destField);
			radioField.checked = true;
		}
		catch(e)
		{
		}
	}
	
	
	function autoTab(input,len, e) 
	{

		var keyCode = (isNN) ? e.which : e.keyCode; 

		var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];

		if(input.value.length >= len && !containsElement(filter,keyCode)) 
		{

			input.value = input.value.slice(0, len);
			input.form[(getIndex(input)+1) % input.form.length].focus();

		}
	
		function containsElement(arr, ele) 
		{
			var found = false, index = 0;
			while(!found && index < arr.length)
			if(arr[index] == ele)
			{
				found = true;
			}
			else
			{
				index++;
			}
			return found;
		}
		
		function getIndex(input) 
		{
			var index = -1, i = 0, found = false;
			while (i < input.form.length && index == -1)
			if (input.form[i] == input)
			{
				index = i;
			}
			else 
			{
				i++;
			}
			return index;
		}
		return true;
	}

	
	function strltrim()
	{
		return this.replace(/^\s+/,'');
	}
	function strrtrim()
	{
		return this.replace(/\s+$/,'');
	}
	function strtrim()
	{
		return this.replace(/^\s+/,'').replace(/\s+$/,'');
	}
	
	function updatePicture(disp,img,name,imageDir)
	{
		//disp = The label id
		//img = The img src id
		//name = The file id
		var d = document.getElementById(disp);

		var i = document.getElementById(img);

		var n = document.getElementById(name);
			
		setImageSrc(i, n.value, imageDir);

		var imageDispName = d.firstChild;
		
		var matcharray = n.value.match(/([^\\\/]*)$/); 		
		
		var shortName = matcharray[0];

		imageDispName.nodeValue = "("+shortName+")";

		return shortName;
	}
	
	String.prototype.ltrim = strltrim;
	String.prototype.rtrim = strrtrim;
	String.prototype.trim = strtrim;
	