﻿/* The next two methods ensure that the search form is submit when enter is hit */
var ie = (document.all)?true:false;
var nn = (document.layers)?true:false;
var debug = true; // shows errors

function pop_up(URL,PopUpName,Width,Height)
{
	try
	{
		if (Width =="" || Width == null) Width =486;
		if (Height == "" || Height == null) Height =500;

		var features =
		',directories=0'+
		',location=0'   +
		',menubar=0'   +
		',scrollbars=1'+
		',status=0'   +
		',toolbar=0'   +
		',resizable=1' +
		',width=' + Width +
		',height=' + Height +
		',screenX=15'
		',screenY=15'
		',top=15'+
		',left=15';
		URL = URL.replace(/\s/,'%20');
		wind=window.open (URL, PopUpName, features);
		wind.focus();
	}
	catch(err){}
}

function wfKeyDown(e, ImageButtonId)
{
	var icode,ncode,key;
	try
	{
		if(ie)
		{
			icode = event.keyCode; ncode = 0;
			key=String.fromCharCode(event.keyCode);
		}
		if(nn)
		{
			icode = 0; ncode = e.which; key=String.fromCharCode(e.which);
		}
		if(icode == 13 || ncode == 13)
		{
			EnableImageForm(ImageButtonId); // sets a hidden value the identifies the exact form that the user intends to post
			
			if(ImageButtonId == 'SearchBikeText' && e != null)
			{
			    try
			    {
			    window.event.cancelBubble = true;
			    getFormElement("SearchForm_SearchText").value = e.srcElement.value;
			    return;
			    }
			    catch(err){}
			}
					
			// Only pressing enter on a text causes an automatic post. If this happens on a select
			// box we must take responsibility for posting the form
			if(e != null)
			{
				var eSrc = e.srcElement;
				if(eSrc.tagName == "SELECT")
				{
					// Submits the ImageButton Form
					SubmitImageButtonForm(ImageButtonId);	
				}
			}
		}
	}
	catch(err){if(debug)alert(err.message);}
	
	return;
}

function EnableImageForm(ImageButtonId)
{
	var WFInputImageId = null;
	try
	{
		WFInputImageId = document.getElementById("WFInputImageId");
		
		if(WFInputImageId != null)
		{
			// Set the name field
			WFInputImageId.name = "WFInputImageId";
						
			// Sets the hidden value
			WFInputImageId.value = ImageButtonId;
		}
	}
	catch(err){if(debug)alert(err.message);}
	
	// No return value
	return;
}


function SubmitImageButtonForm(ImageButtonId)
{
	var ImageButton = null;
	try
	{
		ImageButton = document.getElementById(ImageButtonId);
		if(ImageButton != null)
		{
			EnableImageForm(ImageButtonId); // sets a hidden value the identifies the exact form that the user intends to post
			ImageButton.click(); // simulate the click event
		}
	}
	catch(err){if(debug)alert(err.message);}
	
	return ImageButton;
}


function GetForm()
{
	var Form = null;
	try
	{
		form = document.getElementById("WFForm");
	}
	catch(err){if(debug)alert(err.message);}
	
	return form;
}

function ShowBike(URL,BikeId)
{
	var nUrl = URL + '?id=' + BikeId
	pop_up(nUrl,BikeId,760,720);
	return;
}

function pop_up(URL,PopUpName,Width,Height)
{
	try
	{
		if (Width =="" || Width == null) Width =486;
		if (Height == "" || Height == null) Height =500;

		var features =
		',directories=0'+
		',location=0'   +
		',menubar=0'   +
		',scrollbars=1'+
		',status=0'   +
		',toolbar=0'   +
		',resizable=1' +
		',width=' + Width +
		',height=' + Height +
		',screenX=15'
		',screenY=15'
		',top=15'+
		',left=15';
		URL = URL.replace(/\s/,'%20');
		wind=window.open (URL, PopUpName, features);
		wind.focus();
	}
	catch(err){}
}

function focusSearchBox(elem)
{
	elem.className = 'SearchTextBoxOn';
	var sb = $('Search1Form_SearchSubmitButton');
	sb.src = sb.src.replace('find.gif', 'find-blue-search.gif');
}

function blurSearchBox(elem)
{
	elem.className = 'SearchTextBox';
	var sb = $('Search1Form_SearchSubmitButton');
	sb.src = sb.src.replace('find-blue-search.gif', 'find.gif');
}