
function setFocus(id) {
	document.getElementById(id).focus();
}

// Clears text in search box
function clearText() {
	alert("deprecated clearText() in script_utils.js");
	document.getElementById('searchBox').value='';
}

function searchBoxClicked()
{		
	var s = document.getElementById('searchBox');
	if (s.style.color != 'white')
	{
		s.value='';
		s.style.color = 'white';
		s.style.background = '#666';
	}
	window.focus(); // maybe this will help with the focus problem
	s.focus();
}
function searchBoxPrompt(prompt)
{
	var s = document.getElementById('searchBox');
	if (s.value == '')
	{
		s.value = prompt;
		s.style.color = '#333';
	}
}

// when a submit button is clicked, if the object with id is hidden, show it; if not, submit the form
function submit_action(id) {
	styleObj = document.getElementById(id).style;	
	if (styleObj.display == 'none') 
	{
		styleObj.display='inline';
		setFocus('rename_box');
		return false;
	}
	return true;
}	 		
	

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) {
	imgObj = document.getElementById(id);
	imgObj.src = target;
}

/*
swapIfContents()
*****************************
	- params
		newTarg: link to new HTML file
*/
function swapIfContents(newTarg) {
	var targFrame = window.frames[0];
	if ( targFrame ) {
	    targFrame.location = newTarg;   
	}
}		


function Print()
{
	document.body.offsetHeight;
	window.print();
}


/*
* automatically submit a form when the enter key is pressed
* place this snippet of code in any HTML input tag where you want to submit with enter key
* onkeypress="keySubmit(event.which, 'loginform')"
* note: 'loginform' happens to be an example name of the form
*/
function keySubmit(the_key, the_form) 
{ 
	if ( ! the_key )
	{
		the_key = event.keyCode;
	}

	if (the_key == 13)
	{
//		alert('Trying to submit '+ the_form);
		document.forms[the_form].submit();
	}
//	String.fromCharCode ( the_key )	can be used to show the actual char (if not whitespace)
}

/*
 * toggle between expanding or contracting a div element (show/hide)
 */
function expand(Id) 
{
	styleObj = document.getElementById(Id).style;
	if (styleObj.display == 'none') 
	{
		styleObj.display='';
	}
	else 
	{
		styleObj.display='none';
	}
}

function gotoForm (myForm) 
{ 
	var index = myForm.select.selectedIndex;
	if (myForm.select.options[index].value != "")
		location = myForm.select.options[index].value;
}


function getCookie(c_name)
{
	if (document.cookie.length>0)
 	{
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
	  { 
	    c_start=c_start + c_name.length + 1; 
	    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);						
	}	
}

