function onEnter(form, e, strParam) {
  var keycode;
  if (window.event) keycode = window.event.keyCode;
  else if (e) keycode = e.which;
  else return true;
  if (keycode == 13) {
    submit_form (form, strParam);
    return false;
  } else return true;
}

function setSearch()
{
var iSE = document.getElementById('searchtype').selectedIndex;
var sSN = document.getElementById('searchtype').options[iSE].value;
for (i=0; i< document.getElementById('searchtype').options.length; i++)
{ var sSN2 = document.getElementById('searchtype').options[i].value;
   document.getElementById(sSN2).style.display='none';
}
document.getElementById(sSN).style.display='inline';
}

function submit_form()
{	var arrArgs = submit_form.arguments;
	var oForm = arrArgs[0];
	var strParam = arrArgs[1];
	var strInput, strType;

	if (strParam == 'af')
	{	if ("[" + typeof(oForm.artistsearch.value) + "]"!="[undefined]")
		{	strInput = oForm.artistsearch.value
		}else
		{	strInput = '';
		}
		if (isWildcard(strInput) || isLengthShort(strInput))
		{ return false;
		}
		else
		{	window.location.href = "/search.aspx?collection=MusicArtistFeatures&query="+strInput+"&from=afindex";  
		}
	}else if (strParam == 'ss')
	{	if ("[" + typeof(oForm.query.value) + "]"!="[undefined]")
		{	strInput = oForm.query.value
		}else
		{	strInput = '';
		}
		if (isWildcard(strInput) || isLengthShort(strInput))
		{ return false;
		}
		else
		{	window.location.href = "/search.aspx?query="+strInput;
		}
	}else if (strParam == 'dl')
	{	if (("[" + typeof(oForm.artistsearch.value) + "]"!="[undefined]") && ("[" + typeof(oForm.titlesearch.value) + "]"!="[undefined]"))
		{	strInput = validateDownloadsForm(oForm.artistsearch.value, oForm.titlesearch.value)
			if (strInput != false) window.location.href = strInput;  
		}
	}else if (strParam == 'dlm')
	{	if (("[" + typeof(oForm.artistsearch.value) + "]"!="[undefined]") && ("[" + typeof(oForm.titlesearch.value) + "]"!="[undefined]"))
		{	strInput = validateDownloadsForm(oForm.artistsearch.value, oForm.titlesearch.value)
			if (strInput != false) window.open(strInput,"_blank");  
		}
	}else if (strParam == 'sp')
	{	if ("[" + typeof(oForm.text.value) + "]"!="[undefined]")
		{	strInput = oForm.text.value
		}else
		{	strInput = '';
		}
		if (isWildcard(strInput) || isLengthShort(strInput))
		{ return false;
		}
		else
		{	window.location.href = "http://shopping.ninemsn.com.au/results/shp/?bCatId=1915&text="+strInput;
		}
	}else if (strParam == 'gg')
	{	if ("[" + typeof(oForm.text.value) + "]"!="[undefined]")
		{	strInput = oForm.text.value
		}else
		{	strInput = '';
		}
		if (isWildcard(strInput) || isLengthShort(strInput))
		{ return false;
		}
		else
		{	window.location.href = "http://gigguide.ninemsn.com.au/music/search/?action=quickSearch&searchType=event&text="+strInput;
		}

	}
	return false;
}


function validateDownloadsForm(as, ts) 
{	var URL = "/od2redirect.asp?url=http://sib1.od2.com/common/config.asp?shop=52&associd=2&";
	var redirect = "";
		
	if (isWildcard(as) || isWildcard(ts))
	{	return false;
	}
	else if (as.length < 2 && ts.length < 2)
	{	return (!isLengthShort(as));
	}
	else
	{	if (as.length > 1 && ts.length == 0) 
		{	redirect = "redirect=searchartist&artistsearch=" + as;
		}
		else if (as.length == 0 && ts.length > 1) 
		{	redirect = "redirect=searchtitle&titlesearch=" + ts;
		}
		else if (as.length > 1 && ts.length > 1) 
		{	redirect = "redirect=searchartisttitle&artistsearch=" + as + "&titlesearch=" + ts;
		}
		else
		{	window.alert("Please provide either an artist name or album/track title with which to search.");
			return false;
		}
	}

	return URL + redirect;
}

 
function isLengthShort(w) 
{	if (w.length < 2) 
	{	window.alert("Please provide at least 2 valid characters as search criteria.");
		return true;
	}
	else {return false;}
}

function isWildcard(w)
{	var re   = /%|\?|\*/;
	if (re.test(w))
	{	window.alert("Wildcard characters %, ? and * are not permitted when searching.");
		return true;
	}
	else {return false;}
}









