function setFocus(id) {
	document.getElementById(id).focus();
}

// Clears text in search box
function clearText() {
	document.getElementById('searchbox').value='';
}

function searchBoxClicked()
{		
	clearText();
	if (document.getElementById('searchbox').style.color == 'gray')	
		document.getElementById('searchbox').style.color = 'black';				
}

// Called when the wish list rename or cancel button is clicked
function rename_action(action) {	
	var renameStyle = document.getElementById("rename").style;
	var cancelStyle = document.getElementById("cancel_button").style;
	var newStyle = document.getElementById("new_button").style;
	var deleteStyle = document.getElementById("delete_button").style;
	var copyStyle;
	var copyButton = true;
	
	try
	{
		copyStyle = document.getElementById("copy_button").style; // copy button is only for takeoff		
	}
	catch (e) 
	{
		copyButton = false;		
	}
	
	if (action == 'rename')
	{						
		if (renameStyle.display == 'none') // first click on rename button
		{
			// hide new, delete and copy buttons
			newStyle.display = 'none';
			deleteStyle.display = 'none';
			if (copyButton)
				copyStyle.display = 'none';
				
			// show rename text box and cancel button
			renameStyle.display='inline';
			cancelStyle.display='';
			setFocus('rename_box');
			return false; // dont't submit yet. need customer to fill in new name
		}
		else
			return true;
	}	
		
	else if (action == "cancel")
	{
		renameStyle.display='none';
		cancelStyle.display='none';
		newStyle.display = '';
		deleteStyle.display = '';
		if (copyButton)
			copyStyle.display = '';
	}
	
	return false;		
}	 		
	

function popWin(target,title,width,height) {
	window.open(target, title, "width=" + width + ",height=" + height + ",status=yes,resizable=no");
}
		
// Loads the zoomify window
function popZoom(prodCode) {
	window.open("/zoomwindow.html?code=" + prodCode,"zoom", "width=565,height=485,status=yes,resizable=no");
}

function swapImg(id, target) {
	var imgObj = document.getElementById(id);
	imgObj.src = target;
}

function Print()
{
	document.body.offsetHeight;
	window.print();
}

/*
 * toggle between expanding or contracting a div element (show/hide)
 */
function expand(Id) 
{
	var styleObj = document.getElementById(Id).style;
	if (styleObj.display == 'none') 
	{
		styleObj.display='';
	}
	else 
	{
		styleObj.display='none';
	}
}

function goto(form) 
{ 
	var index=form.select.selectedIndex;
	if (form.select.options[index].value != "")
		location=form.select.options[index].value;
}

function toggleField(val, j) 
{	
	document.getElementById('other_box' + j).value = '';
	if (val == 'other')
	{		
		document.getElementById('location_menu' + j).style.display = 'none';
		document.getElementById('location_menu' + j).value= '';
		document.getElementById('other_box' + j).style.display = '';		
		document.getElementById('drop' + j).style.display = '';		
		setFocus('other_box' + j);		
	}	
}

function showDropDown(j)
{	
	document.getElementById('other_box' + j).style.display = 'none';
	document.getElementById('other_box' + j).value = '';
	document.getElementById('drop' + j).style.display = 'none';
	document.getElementById('location_menu' + j).style.display = '';
	document.getElementById('sel' + j).selected = 'selected';
}

function showLoc(id)
{
	document.getElementById(id).style.display = '';
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
 	{
	  var c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
	  { 
	    c_start=c_start + c_name.length + 1; 
	    var c_end=document.cookie.indexOf(";",c_start);
	    if (c_end==-1) 
			c_end=document.cookie.length;
	    return unescape(document.cookie.substring(c_start,c_end));
	  } 
	}
	return "";
}

function deleteCookie(NameOfCookie)
{ 
	if (getCookie(NameOfCookie) != "")
		document.cookie = NameOfCookie + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

// stores scrollbar horizontal position on leaving a product list/search result page in cookie
function storeScrollbarPos()
{
	var browser=navigator.appName;
	if (browser=="Microsoft Internet Explorer")	
	  	var scrollbarPos = document.documentElement.scrollLeft;		
	else
	  	var scrollbarPos = window.pageXOffset;
	
	document.cookie = "scrollbarPos=" + scrollbarPos;		
}

// scrolls the page to where customer was on product list/search result page
function backToProductList()
{					
	if (getCookie('fromItemPage') == "true")
	{
		deleteCookie('fromItemPage');				
		if (getCookie('isNewSearch') == "true") // if customer is here after clicking submit on search form, don't scroll
		{						
			document.cookie = "isNewSearch=false; path=/";				
			return;
		}
				
		var scrollbarPos = getCookie('scrollbarPos');				
		if (scrollbarPos != "")		
			window.scrollTo(scrollbarPos, 0);						
	}	
}
