// ** JavaScript Include File
// ** LocalAds
// **
// ** Common JavaScript Function for Look and Feel & Functionality
// ** March 2005

// *********************************************************************************************************
// ** To turn small letters in the postcodes into CAPITALS
// *********************************************************************************************************
function ToCaps(field_name)
{
	oldValue = document.getElementsByName(field_name)[0].value;
	newValue = oldValue.toUpperCase();
	document.getElementsByName(field_name)[0].value = newValue;
}

// *********************************************************************************************************
// ** Make text that is describing a CHECKBOX clickable
// *********************************************************************************************************
function extendCheckBox(box_id)
{
	if(document.getElementById(box_id).checked == true)
		document.getElementById(box_id).checked = false;
	else
		document.getElementById(box_id).checked = true;
}


		
// *********************************************************************************************************
// ** Sets the searchword input field to nothing when user sets focus, do it also on submit
// *********************************************************************************************************
function ValidateSearchBox(RelativeHTMLPath, ValidateLength)
{
	ValidateLength = false;
	if(typeof ValidateLength != "undefined")
		ValidateLength = true;

	if(ValidateLength == true)
	{
		
		SearchValue = document.getElementsByName("s_title")[0].value;
		if(!SearchValue)
			SearchValue = document.getElementsByName("s_title")[1].value;
		
		SearchValue = SearchValue.replace(/\s+/,"");
		if(SearchValue.length == 0)
		{
			window.location = RelativeHTMLPath + "browse";
			return false;
		}
		else if(SearchValue.length > 0 && SearchValue.length < 3)
		{
			alert("Please use at least three characters for your search.");
			return false;
		}
		else
		{
			return true;
		}
	}
	else
	{
		return true;
	}
}

// *********************************************************************************************************
// ** Disable the % or pound field for the bargain hunter 
// *********************************************************************************************************
function priceTrackerHandler(source)
{
	switch(source)
	{
		case "price":
			document.getElementById('tracker_percent').value = '';
		break;
		case "percent":
			document.getElementById('tracker_price').value = '';
		break;
	}
}	
// *********************************************************************************************************
// ** Function to jump to the listing of Ads through the categories and trigger the distance calculation
// *********************************************************************************************************
function CategoryListing(CatID)
{
	for(i=0; i < document.itemsSearch.s_local_national.length; i++)
	{
		if(document.itemsSearch.s_local_national[i].checked == true)
			HandlerLocNat = document.itemsSearch.s_local_national[i].value;
	}
	HandlerPostCode = document.itemsSearch.s_pcode.value;
	
	LinkTarget = "ViewCat.php?CatID=" + CatID + "&s_local_national=" + HandlerLocNat + "&s_pcode=" + HandlerPostCode;
	window.location.href = LinkTarget;
}

// *********************************************************************************************************
// ** Helper Window, looks like Windows help
// *********************************************************************************************************
function OpenHelp(target, menu, movefolderup)
{
	if(movefolderup == true)
		pathprefix = '../';
	else
		pathprefix = '';
	
	//Target
	if(menu == false)
		menu = '&menu=no';
	else
		menu = '';
	target = pathprefix + 'page?name=' + target + menu;
	
	//Position
	posX = screen.availWidth - 350;
	posY = 0;
	posHeight = Math.round(screen.availHeight*0.66);
	
	window.open(target, 'LocalAdsHelp', 'dependent=no, width=350, height=' + posHeight + ', menubar=no, location=no, resizeable=yes, scrollbars=yes, status=yes, toolbar=no, top=' + posY + ', left=' + posX);
}
