var btnSearch;

function handleEnter (field, event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
		var i;
		for (i = 0; i < field.form.elements.length; i++)
			if (field == field.form.elements[i])
				break;
		i = (i + 1) % field.form.elements.length;
		field.form.elements[i].focus();
		return false;
	} 
	else
		return true;
}

function Event_OnKeyPress(ButtonID) {
	btnSearch = window.document.getElementById(ButtonID);
	var eventChooser = 0;
    eventChooser = event.keyCode;
	if(eventChooser == 13)
		btnSearch.click();
}

function ViewProductImage(item){
    url = 'ViewProductImage.aspx?item=' + item;
    openWindow(url, 'Product', 600, 400)
}

function openWindow(sUrl, sWindowName, iWidth, iHeight) 
{
	if (sUrl == "UNDER_CONSTRUCTION") {
		return alert("This part is under construction.");
	}
	else
	{
		var objWin;
		var objOptions;
		//make it locate at center of the page.
		var WidthX = (screen.availWidth/2) - (iWidth/2)
		var HeightY = (screen.availHeight/2) - (iHeight/2)
		objOptions = 'status=no,menubar=no,scrollbars=yes,resizable=no,toolbar=no';
		objOptions = objOptions + ',width=' + iWidth;
		objOptions = objOptions + ',height=' + iHeight;
		objOptions = objOptions + ',left=' + WidthX + ',top=' + HeightY;
		objWin = window.open( '', sWindowName, objOptions );
		if (objWin != null) {
		//set the url.
		objWin.location = sUrl;
		//set focus to the popup
		objWin.focus();
		}
	}
}

var oldItem = 1;	// previous row
var oldcolor;		// color of previous row			
var ObjectID = "";	// store Object ID of row chooses
var RowColor;		// store color default of row			
var oldClassColor;	// store background color of previous row
var RowID = "";
			
function setColorStyle(item,str) {
	// check if not click on current row
	if (item != oldItem) {
		// reset color of previous row when click on other row 
		if(oldItem != 1)	
			oldItem.style.backgroundColor = oldcolor;
				
		oldItem = item;			// update old row
		oldcolor = RowColor;	// update old color
		
		// set color on row selected
		item.style.backgroundColor = "#eee8aa";
		oldClassColor = item.style.backgroundColor;
		// store user ID had been selected	
		ObjectID = str;
	}
}
			
function setHref(item,str) {
	item.location.href = str + "&row=" + ObjectID;
}	
					
function changeColorStyle(item) {
	// get color default of row
	RowColor = item.style.backgroundColor;
	oldClassColor = item.style.backgroundColor;
	// set color on row when mouse over			
	item.style.backgroundColor = "#EDFEFC";
}
			
function resetColorStyle(item) {
	// reset old background color of current row
	item.style.backgroundColor = oldClassColor;
}