function OnSelect(next)
{
	// switch focus to next element
	var arr = document.getElementsByName(next) ;
	if (arr.length > 0)
	{
		arr[0].click() ;
	}
}

function OnEnter(next)
{
//	alert('OnEnter(' + next + ')') ;
    var key ;
	var evt = window.event ;

    if (document.layers) { key = evt.which ; } // Netscape
    if (document.all)    { key = evt.keyCode ; } // IE
	if (key == 13)
	{
		arr = document.getElementsByName(next) ;
		if (arr.length > 0)
		{
			arr[0].click() ;
		}
	}
}

function SetRequired(self, target)
{
	var elmTarget = document.getElementsByName('txt' + target)[0] ;
	var elmCaption = document.getElementsByName('lbl' + target)[0] ;
	if(self.value == '')
	{
		self.name = 'txtuser_newpassword' ;
		elmTarget.name = 'txtRepeat' ;
		elmCaption.innerHTML = 'Repeat password' ;
	}
	else
	{
		self.name = '_txtPassword' ;
		elmTarget.name = '_txtRepeat' ;
		elmCaption.innerHTML = elmCaption.innerHTML + ' <span style="color:red">*</span> ';
	}
}

function OnMail(suff, name, host)
{
	// Check params
	if (name == '')
	{
		alert("Sorry, no e-mail address known") ;
		return ;
	}

	// Build the address and get browser version	
	var addr = name + '@' + host + '.' + suff ;
	var iVersion = parseInt(navigator.appVersion) ;
	
	// IE7 quirk: doesn't support 'prompt'
	if (navigator.appName == "Microsoft Internet Explorer" && iVersion >= 7 && iVersion < 8)
	{
		if (confirm('Do you want to start your default email program to send a message to ' + addr + '?'))
		{
			document.location = 'mailto:' + addr ;
		}
	}
	else
	{
		if (prompt('Click Ok if you want to start your default email program to send a message to', addr))
		{
			document.location = 'mailto:' + addr ;
		}
	}
}

function OnSelect(strSelector, strVariable, strForm)
{
	document.getElementById(strVariable).value =
		document.getElementById(strSelector).value ;
	document.getElementById(strForm).submit() ;
}

function OnInfoPage(strDir, strPage, iWidth, iHeight)
{
	// Hvg 2010-04-23: supports optional params iWidth and iHeight
	if (iWidth == null) iWidth = 600 ;
	if (iHeight == null) iHeight = 400 ;
	window.open('../' + strDir + '/' + strPage, null, 'width=' + iWidth + ',height=' + iHeight + ',scrollbars=yes,resizable=yes') ;
}

function OnPicture(strPath, strName, iOr, strAlt, iWidth, iHeight, strNotice, strTable)
{
	strRelName =
		'../shared/getimage.php?n=' + strName +
		'&p=' + strPath +
		(strTable == null ? '' : '&t=' + strTable) +
		'&f=12' ;
	strTitle = (strNotice != null) ? strNotice : strAlt ;
	strCaption = (strNotice != null) ? strAlt : '' ;

	if (iWidth == 0 || iWidth == null)
	{
		iWidth = (iOr == 0) ? 600 : 400 ;
		iHeight = (iOr == 0) ? 400 : 600 ;
	}
	
	strProperties =
		'status=0,toolbar=0,location=0,menubar=0,' +
		'directories=0,resizable=1,scrollbars=0,' +
		'width=' + (iWidth + 50) +
		',height=' + (iHeight + 75) ;

	strDocument =
		'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">' +
		'\n<html>\n\t<head>\n\t\t<title>' + unescape(strTitle) + '</title>' +
		'\n\t\t<meta http-equiv=Content-Language content=en-gb>' +
		'\n\t\t<meta http-equiv=Content-Type content="text/html; charset=windows-1252">' +
		'\n\t\t<meta http-equiv="Expires" content="Tue, 28 Sep 2004 00:00:00 GMT">' +
		'\n\t\t<script type="text/javascript" language="JavaScript">' +
		'\n\t\t</script' +
		'\n\t</head>' +
		'\n\t<body style=\"text-align:center;background:skyblue;\">' ;

	if (navigator.userAgent.indexOf('Safari') == -1)
		strDocument +=
			'\n\t\t<img src=\"' + strRelName + '\" alt=\"A caption\"><br>' ;
	else
		strDocument +=
			'\n\t\tIt\'s Safari!<br>' +
			'\n\t\t<a href=\"' + strRelName + '\">Click here</a><br>' ;

	strDocument +=
		'\n\t\t<span style=\"text-align:center;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:10pt;\">' + unescape(strCaption) + '</span>' +
		'\n\t</body>\n</html>' ;
	wnd = window.open('./ph.html', 'FullSize', strProperties) ;
	wnd.document.write(strDocument) ;
	wnd.document.close() ;
}

function OnPE(strPage, msg)
{
	document.location = strPage + "?parent=Members%27%20area&banner=Parts+exchange&selector=" + msg ;
}

function OnUnLoad(self) {}
function OnSubmit(self) {}

function OnLoad(self)
{
	// Show selection in menu display
	ResetAllMenus(self) ;
	
	// Set focus to ctrFocus, if any
	var ctr = document.getElementById('ctrFocus') ;
	if (ctr != null)
		ctr.focus() ;

	// Set radiobutton according to selector	
	strParams = document.location.search ;
	if ((idx = strParams.indexOf('selector')) > 0)
	{
		if ((idx = strParams.indexOf('=', idx)) > 0)
		{
			selector = strParams.substring(idx + 1, idx + 2) ;
			controls = document.getElementsByName('rbCategory') ;
			if(controls.length > 0)
			{
				controls[0].checked = (selector == 'm') ;
				controls[1].checked = (selector == 's') ;
				controls[2].checked = (selector == 'w') ;
			}

			controls2 = document.getElementsByName('_sltCategory') ;
			if(controls2.length > 0 && controls2[0].children.length > 0 && controls2[0].options.length > 0)
			{
				controls2[0].options[0].selected = (selector == 'w') ;
				controls2[0].options[1].selected = (selector == 'm') ;
				controls2[0].options[2].selected = (selector == 's') ;
			}
		}
	}
}

function Preview()
{
	var txtBrowser = document.getElementsByName('txtFilename')[0] ;
	var imgPreview = document.getElementsByName('imgPicture')[0] ;
	if (txtBrowser != null && imgPreview != null)
	{
		var str = txtBrowser.value ;
		str = 'file:///' + str.replace(/\\/g,'/') ;
		alert(str) ;
		imgPreview.src = str ;
		imgPreview.style['visibility'] = 'visible' ;
		alert(imgPreview.src) ;
	}
	else
	{
		alert('Sorry, this browser doesn\'t support a preview') ;
	}
}

function ResetAllMenus(except)
{
	for(i = 0; i < menuInfo.length; ++i)
	{
		SetVisibility(menuInfo[i], (except != null && except == menuInfo[i])) ;
	}
}
		
function SetVisibility(strBody, value)
{
	var tbody = document.getElementById(strBody) ;
	if (tbody != null)
	{
		tbody.style['display'] =
			value ? 'block' : 'none' ;
		SetIcon(strBody, !value) ;
	}
}

function SetIcon(strName, value)
{
	var img = document.images['img' + strName] ;
	if (value)
		img.src = '../images/icon_plus.gif' ;
	else
		img.src = '../images/icon_min.gif' ;
}

function OnClick(strSource, level, buttonOnly)
{
//	ResetAllMenus(null) ;
//	ToggleVisibility(strSource) ;
}
		
function ToggleVisibility(strBody) {}

/*
function ToggleVisibility(strBody)
{
	var tbody = document.getElementById(strBody) ;
	if (tbody != null)
	{
		tbody.style['display'] =
			(tbody.style['display'] == 'none') ? 'block' : 'none' ;
		SetIcon(strBody, (tbody.style['display'] == 'none')) ;
	}
}
*/

