/* *****************************************************************************************************
* HarrisonParrott Global JavaScript functions
* 4th August 2005 (AM)
* Modified 11th May 2009 to include Japanese language support to the drop down lists
* **************************************************************************************************** */

// generic error message display
function showError(fld, msg)
{
	fld.focus();
	alert(msg);
	return false;
}

function trim(sVal) {
	while(sVal.charAt(sVal.length-1)==' ')
		sVal=sVal.substring(0,sVal.length-1);

	while(sVal.charAt(0)==' ')
		sVal=sVal.substr(1,sVal.length);

	return sVal;
}

// pops a new dependant window with chrome removed
function popwin(surl) { 
	window.open(surl, 'newwin', 'dependent=yes,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no'); 
	return false;
}

// pops a window for audio or video clips
function popmedia(surl, w, h) { 
	window.open(surl, 'newwin', 'dependent=yes,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no,height='+h+'width='+w); 
	return false;
}

// pops a new browser window for external websites - suppresses href by returning false
function popsite(surl) {
	window.open(surl, 'newsite', ''); 
	return false;
}

// email checker
function isEmailFormatCorrect(strAddr) { 
	var ptn = /^[\w\d._%-]+@[\w\d._%-]+\.[\w\d._%-]{2,4}$/;
	return ptn.test(strAddr);
}

/** ******************************************************
* Search class
* ****************************************************** */
function hp_search()
{
	/** visitor has selected the quick search drop down
	* first character of the option value contains an a or a t
	* which signifies (a)rtists or (t)ouring type is selected 
	* @loc = contains '../' if this function is being called 
	* from an artist page located in /artists/
	*/
	this.quicksearch = function(loc)
	{
		var qs = document.getElementById('quicksearch');
		if(qs)
		{
			if(qs.options[qs.options.selectedIndex].value != '0')
			{
				var s = qs.options[qs.options.selectedIndex].value;
				var t = s.substr(0, 2);					// get the type identifier from the first character of the option value
				var id = s.substr(2, (s.length - 1));	// get the type id
				if(t == '_a')
					document.location.href = (loc + 'artists' + hp_language_extension + '.asp?t=' + id);
				else if(t == '_t')
				{
					document.location.href = (loc + 'touring' + hp_language_extension + '.asp?t=' + id);
				}
				else
				{
					document.location.href = s;
				}
			}
		}
	};

	this.text_search = function()
	{
		var fld = document.getElementById('hp-srch');
		if(fld)
		{
			var val = trim(fld.value);
			if(val == '')
				return showError(fld, 'Please enter something to search for.');
			else
				return true;
		}

	};

}

var hps;