
var forgotPasswordVisible = false; // Determines whether the forgot password section of the login box is shown.
var showLoad;

function onLoadRoutines() { // To be executed in the Onload of every page
	visibilitytoggle();
	showLoad = false;
}

function pageWidth() {return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ?       document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;} 
function pageHeight() {return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;} 

function displayWait() {
		if (self.pageYOffset) {
			yPos = self.pageYOffset;
		} else if (document.documentElement && document.documentElement.scrollTop){
			yPos = document.documentElement.scrollTop; 
		} else if (document.body) {
			yPos = document.body.scrollTop;
		}
		showLoad = true;
		$('shazamWait').style.position = 'absolute'
		$('shazamWait').style.top = yPos + pageHeight()/2 + "px";
		$('shazamWait').style.left = pageWidth()/2 +"px";
		

}


function showWait() {
if (showLoad != true)
	{ 
			showLoad = true;
			$('shazamWait').style.visibility = 'visible';
			$('shazamWait').style.height = '92px';
			intervalId = window.setInterval("displayWait()", 10);
	}
}

function hideWait() {

	if (showLoad != false)
	{
		window.clearInterval(intervalId)
		showLoad = false;
		$('shazamWait').style.visibility = 'hidden';
		$('shazamWait').style.height = '1px';
	}
	
}




var hotspots = document.getElementsByName('hotspot');
var toggles = document.getElementsByName('toggle');

function visibilitytoggle()
{
  for (var i = 0; i < hotspots.length; i++)
  {
  hotspots[i].someProperty = i;
  hotspots[i].onclick = function() {toggle(this.someProperty)};
  }
}

var loginBoxState = 0; // closed;

function toggleLogin()
{
	// remember, these are the possible parameters for Set_Cookie:
	// name, value, expires, path, domain, secure
	Set_Cookie( 'test', 'none', '', '/', '', '' );
	// if Get_Cookie succeeds, cookies are enabled, since 
	//the cookie was successfully created.
	if ( Get_Cookie( 'test' ) )
	{
		//document.write( 'cookies are currently enabled.' );
		/* 
		this is an example of a set cookie variable, if 
		you want to use this on the page or on another script 
		instead of writing to the page you would just check that value
		for true or false and then do what you need to do.
		*/
		cookie_set = true;
		// and these are the parameters for Delete_Cookie:
		// name, path, domain
		// make sure you use the same parameters in Set and Delete Cookie.
		Delete_Cookie('test', '/', '');
		
			// position sign in box to the correct location under the sign in link
	$('signin').style.top = Position.cumulativeOffset($('signInLink'))[1] + 25 + 'px';
	$('signin').style.left = Position.cumulativeOffset($('signInLink'))[0] - 130 + 'px';
	$('signin').style.visibility = 'visible';
//	new fx.Height($('signin'), {duration: 400}).toggle();
  if (loginBoxState == 0)
  {
    loginBoxState = 1; // open;
    $('searchtype').style.visibility = 'hidden';
    new fx.Height($('signin'), {duration: 400, onComplete: function() {$('loginusername').focus();}  }).custom(0, $('signin').scrollHeight);
  }
  else
  {
    loginBoxState = 0; // closed; 
    new fx.Height($('signin'), {duration: 400, onComplete: function() {$('searchtype').style.visibility = 'visible';}    }).custom($('signin').scrollHeight, 0);
  }
	}
	// if the Get_Cookie test fails, cookies 
	//are not enabled for this session.
	else
	{
		showMessagePopUp("Cookies are disabled in your browser.  You need to enable cookies in order to sign in");
	}

}

var openTab = "";

function toggleTab(outerDiv, innerDiv)
{
	if (innerDiv == openTab)
	{
		openTab = "";
		new fx.Height($(outerDiv), {duration: 400, onComplete: function() {
			$(outerDiv).innerHTML = "";
		} }).custom($(outerDiv).scrollHeight, 0);
	}
	else
	{
		oldHeight = $(outerDiv).scrollHeight;
		
		if (openTab != "")
		{
  		new fx.Height($(outerDiv), {duration: 400, onComplete: function() {
  			$(outerDiv).innerHTML = $(innerDiv).innerHTML;
        new fx.Height($(outerDiv), {duration: 400}).custom(0, $(outerDiv).scrollHeight);
  		} }).custom($(outerDiv).scrollHeight, 0);
		}
		else
		{
        $(outerDiv).innerHTML = $(innerDiv).innerHTML;
        new fx.Height($(outerDiv), {duration: 400}).custom(0, $(outerDiv).scrollHeight);
    }
		
	openTab = innerDiv;
	}    
}

function toggleForgotPassword()
{
	if (forgotPasswordVisible == true)
	{
		$('signin').style.background = "transparent url('/music/images/signin2.png') no-repeat";
		forgotPasswordVisible = false;
		$('forgot1').style.visibility = "hidden";
		$('forgot2').style.visibility = "hidden";
	}
	else
	{
		$('signin').style.background = "transparent url('/music/images/signin.png') no-repeat";
		forgotPasswordVisible = true;
		$('forgot1').style.visibility = "visible";
		$('forgot2').style.visibility = "visible";
	}
}


// **** Create-account Functions

	function updateOperator()
	{		
	   	var selectCountryIndex = $('locale').selectedIndex;
		var selectCountryValue = $('locale').options[selectCountryIndex].value;
	   	var msgData = "country=" + selectCountryValue;
	       new Ajax.Request('/music/web/operator-controller.htm', {method: 'post', parameters: msgData, onSuccess: function(sentMessage){
	           if(sentMessage.responseText !== undefined){
	               $('operatorSelect').innerHTML = sentMessage.responseText;
	               updateRegistrationMessage();        
	           }
	       }});                
	}
	
	function updateRegistrationMessage()
	{				
	   	var selectCountryIndex = $('locale').selectedIndex;
		updateRegistrationMessageWithCountry($('locale').options[selectCountryIndex].value);                       
	}
	
	function updateRegistrationMessageOnEditProfile()
	{	
		updateRegistrationMessageWithCountry($('locale').value);                       
	}
	
	function updateRegistrationMessageWithCountry(selectCountryValue)
	{
		var selectOperatorIndex = $('operatorId').selectedIndex;
		
		var selectOperatorValue;
		if (selectOperatorIndex!=null){		
	   	    selectOperatorValue = $('operatorId').options[selectOperatorIndex].value;
		}else{
	   		selectOperatorValue = $('operatorId').value;
		}
		
	   	var msgData = "country=" + selectCountryValue + "&operatorId=" + selectOperatorValue;
	       new Ajax.Request('/music/web/registration-message.htm', {method: 'post', parameters: msgData, onSuccess: function(sentMessage){       
	           if(sentMessage.responseText !== undefined){
	               $('registrationMessage').innerHTML = sentMessage.responseText;
	           }
	       }}); 
	}
	
	function checkUsername()
	{			
	   	var msgData = "username=" + $('username').value;
	       new Ajax.Request('/music/web/check-username.htm', {method: 'post', parameters: msgData, onSuccess: function(sentMessage){
	           if(sentMessage.responseText !== undefined){
	               $('usernameAvailableMessage').innerHTML = sentMessage.responseText;
	           }
	       }});                
	}
	
	function hideRegistrationHelp()
	{
		$('regHelpMsg').style.visibility = 'hidden';
	}
	
	function showRegistrationHelp(element, text)
	{
		$('regHelpMsg').style.position = "absolute";
		$('regHelpMsg').style.visibility = 'visible';
		$('regHelpMsg').style.top = Position.cumulativeOffset($(element))[1] + 'px';
		$('regHelpMsg').style.left = Position.cumulativeOffset($(element))[0] + 300 + 'px';
		$('regHelpMsg').innerHTML = text;
	}
		
// **** End of Create-account functions


// **** Update-profile functions

						
	function validateMobileConfirm(obj) {
	  
	  var poststr = "validationCode=" + encodeURI( $("validationCode").value );

	  new Ajax.Request('/music/web/validate-mobile.htm', {method: 'validateMobileConfirm', parameters: poststr, onSuccess: function(alertMessage){
	          if(alertMessage.responseText !== undefined){
	               $('validationCodeMessage').innerHTML = alertMessage.responseText;
	           }
	       }}); 
	}
	  
	function updateOperator()
	{			
	   	var selectCountryIndex = $('locale').selectedIndex;
		var selectCountryValue = $('locale').options[selectCountryIndex].value;
	   	var msgData = "country=" + selectCountryValue;
	       new Ajax.Request('/music/web/operator-controller.htm', {method: 'post', parameters: msgData, onSuccess: function(sentMessage){
	           if(sentMessage.responseText !== undefined){
	               $('operatorSelect').innerHTML = sentMessage.responseText;
	               updateRegistrationMessage();        
	           }
	       }});                
	}
	
	function updateRegistrationMessage()
	{				
	   	var selectCountryIndex = $('locale').selectedIndex;
		var selectCountryValue = $('locale').options[selectCountryIndex].value;
		
		var selectOperatorIndex = $('operatorId').selectedIndex;
		
		var selectOperatorValue;
		if (selectOperatorIndex!=null){		
	   	    selectOperatorValue = $('operatorId').options[selectOperatorIndex].value;
		}else{
	   		selectOperatorValue = $('operatorId').value;
		}
		
	   	var msgData = "country=" + selectCountryValue + "&operatorId=" + selectOperatorValue;
	       new Ajax.Request('/music/web/registration-message.htm', {method: 'post', parameters: msgData, onSuccess: function(sentMessage){       
	           if(sentMessage.responseText !== undefined){
	               $('registrationMessage').innerHTML = sentMessage.responseText;
	           }
	       }});                        
	}
	
	function resendValidationSMS()
	{			
	   	var msgData = "username=" + $('username').value;
	       new Ajax.Request('/music/web/resend-validation-sms.htm', {method: 'post', parameters: msgData, onSuccess: function(sentMessage){
	           if(sentMessage.responseText !== undefined){
	               $('smsValidationMessage').innerHTML = sentMessage.responseText;
	           }
	       }});                
	}
					
	function addPersonalPage()
	{		
		alert("addPersonalPage being called");
	   	var msgData = "newPersonalPage=" + $('newPersonalPage').value;
	       new Ajax.Request('/music/web/add-personal-page.htm', {method: 'post', parameters: msgData, onSuccess: function(sentMessage){
	           alert(sentMessage.responseText);
	           if(sentMessage.responseText !== undefined){
	               $('validationCodeMessage').innerHTML = sentMessage.responseText;
	           }
	       }});                
	}
	
	var daysInMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	   function updateDOBDays() {
	
	   	yearindex=document.getElementById('dob_year_select').selectedIndex;
		if(document.getElementById('dob_year_select').options[yearindex].value % 4 == 0){
	       	daysInMonth[1]=29;
	       }
	    else{
	  	    	daysInMonth[1]=28;
	      	}
	    monthIndex=document.getElementById('dob_month_select').selectedIndex;
	    arrayindex=document.getElementById('dob_month_select').options[monthIndex].value; 
	       numDays=daysInMonth[arrayindex];
	       if(monthIndex==0){numDays=31}
	       numOptions=numDays+1;
	       document.getElementById('dob_day_select').options.length=numOptions; 
	       for(n=1;n<numOptions;n++){
	        document.getElementById('dob_day_select').options[n].text=n;
		}
	    return true;
	   }
	   
							    
// **** End of Update-profile functions
							
// **** Music Explorer Functions
							
function stopClipPlaying() {
	if (nowPlaying != "") {
		document.getElementById('mHF').src = "/music/images/generic/spacer.gif";
		nowPlaying = "";
	}
}

function musiverse_play(whichClipURL) {
 		document.getElementById('mHF').src = "/music/jsp/hidden_player.jsp?musicFileUrl=" + whichClipURL;
}

function musiverse_open(whichUrl) {
	var eleft = (screen.width - 1000) / 2;
	var etop = (screen.height - 600) / 2;
	var explorer = window.open(whichUrl,'explorer','width=1000,height=596,left='+eleft+',top='+etop+',toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,menubar=no');
	explorer.focus();
}

function musiverse_user(aUrl) {
	var leftpos = screen.width-840;
	if (leftpos<0) leftpos = 0;
	var	usernewwindow = window.open(aUrl + '?ICO=musicExplorer&ICL=userLink','usernewwindow','left='+leftpos+',top=0,width=840,height=650,toolbar=yes,location=yes,directories=yes,status=yes,scrollbars=yes,resizable=yes,menubar=yes');
   	usernewwindow.focus();
}

function musiverse_stop() {
	document.getElementById('mHF').src = "/music/images/generic/spacer.gif";
}

function embedPlayer(whichClip) {
document.write("<OBJECT id='mediaPlayer' name='mediaPlayer' width='320' height='285' classid='CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95' codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701' standby='Loading MS WM components...' type='application/x-oleobject'>");
document.write("<param name='fileName' value='"+whichClip+"'>");
document.write("<param name='animationatStart' value='false'>");
document.write("<param name='transparentatStart' value='false'>");
document.write("<param name='autoStart' value='true'>");
document.write("<param name='showControls' value='true'>");
document.write("<param name='loop' value='true'>");
document.write("<EMBED type='application/x-mplayer2' pluginspage='http://microsoft.com/windows/mediaplayer/en/download/' id='mediaPlayer' name='mediaPlayer' displaysize='4' autosize='-1' bgcolor='darkblue' showcontrols='true' showtracker='-1' showdisplay='0' showstatusbar='-1' videoborder3d='-1' width='320' height='285' src='"+whichClip+"' autostart='true' designtimesp='5311' loop='false'></EMBED>");
document.write("</OBJECT>");
}
							
// **** End of Music Explorer Functions


// **** Profile Page Functions



// **** Homepage Mobile Widget

	var mw1 = 0;
	var mw2 = 0;

	function showMobileWidget()	{
		displayMobileWidget();
		mw1 = 1;
	}
	
	function showMobileWidget2() {
		displayMobileWidget();
		mw2 = 1;
	}
	
	function displayMobileWidget() {
		$('mobileWidget').style.top = Position.cumulativeOffset($('mobileWidgetButton'))[1] + 20 + 'px';
		$('mobileWidget').style.left = Position.cumulativeOffset($('mobileWidgetButton'))[0] - 0 + 'px';
		$('mobileWidget').style.visibility = 'visible';
	}
	
	function hideMobileWidget2() {
		setTimeout("if (mw1 == 0){$('mobileWidget').style.visibility = 'hidden';}",500);
		mw2 = 0;
	}
	
	function hideMobileWidget()	{
		setTimeout("if (mw2 == 0){$('mobileWidget').style.visibility = 'hidden';}",500);
		mw1 = 0;
	}

// **** End of homepage Mobile Widget

function resizeTab(tabIdName, clearTab) {
	var tabLink = $(tabIdName+"Button");
	var tabDiv =  $(tabIdName+"Target");

	if ($(tabDiv).getStyle('height') == '0px') {
		tabLink.innerHTML = '<div class="showhide" onmouseover="this.style.cursor=\'pointer\'">Hide</div>';
		var heightAttributes = tabDiv.scrollHeight;
		new fx.Height(tabDiv, {duration: 400}).custom(0, heightAttributes);
	}
	else {
		tabLink.innerHTML = '<div class="showhide" onmouseover="this.style.cursor=\'pointer\'">Show</div>';
		var heightAttributes = 0;
		new fx.Height(tabDiv, {duration: 400, onComplete: function() {
		  if (clearTab) {
      	var clearArgs = tabIdName;
      	$(clearArgs+'Target').innerHTML = "";
    	}
      }
      
      }).custom(tabDiv.scrollHeight, heightAttributes);
	}
}


/* **** Following imported from scripts3.js  */


<!--
//GENERAL ROUTINES ************************************************************

/*function onLoadRoutines() {
	visibilitytoggle();
	fixLinks();
	setUpMessagePopUp();
	showLoad = false;
}*/




/*function colorLink() {
for (i=0;i<document.links.length;i++) {
	if (document.links[i].href == location.href) {
		//  && document.links[i].href.indexOf("/Myhome/") == -1
		document.links[i].parentNode.className = "current";
	}
}
}*/

function c(whichID,whichMode,whichPage) {
	if (whichPage == 2) {
		location.href="/music/web/album?id="+whichID;
	} else if(whichPage == 3) {
	location.href="/music/web/artist?id="+whichID;
	} else {
		location.href="/music/web/track?id="+whichID;
	}
}

/*function rate(rating,refId,refType) {
document.forms['rating'].ratingValue.value = rating;
document.forms['rating'].contentKey.value = refId;
document.forms['rating'].contentTypeId.value = refType;
document.forms['rating'].submit();
}*/

/*function wopen(url, name, w, h) {

w += 32;
h += 96;
wleft = (screen.width - w) / 2;
wtop = (screen.height - h) / 2;
var win = window.open(url,
 name,
 'width=' + w + ', height=' + h + ', ' +
 'left=' + wleft + ', top=' + wtop + ', ' +
 'location=no, menubar=no, ' +
 'status=no, toolbar=no, scrollbars=no, resizable=no');
win.resizeTo(w, h);
win.moveTo(wleft, wtop);
win.focus();
}*/


function m(newMode) {
	if (location.href.indexOf('/mode/') != -1) {
		location.href = location.href.replace(/\/mode\/[^\/]*\//,"\/mode\/"+newMode+"\/");
	} else {
		location.href = location.href.replace(/\/portal/,"/portal/mode/"+newMode);
	}
}


//CLIP PREVIEW ****************************************************************

var nowPlaying = "";

function p(whichClipURL, whichID) {
	var listenElements;
	if (nowPlaying != whichID) {
		if (nowPlaying != "") {
			listenElements = document.getElementsByName(nowPlaying);
			for (x=0;x<listenElements.length;x++) {
				listenElements[x].lastChild.innerHTML = "listen";
			}
		}
		nowPlaying = whichID;
		listenElements = document.getElementsByName(whichID);
		for (x=0;x<listenElements.length;x++) {
			listenElements[x].lastChild.innerHTML = "loading";
		}
		$('mHF').src = "/music/jsp/hidden_player.jsp?musicFileUrl=" + whichClipURL;
	}
	else if (nowPlaying == whichID) {
		nowPlaying = "";
		listenElements = document.getElementsByName(whichID);
		for (x=0;x<listenElements.length;x++) {
			listenElements[x].lastChild.innerHTML = "listen";
		}
		$('mHF').src = "/music/images/generic/spacer.gif";
	}
}


function gp(whichClipURL, whichID) {
	var listenElements;
	if (nowPlaying != whichID) {
		if (nowPlaying != "") {
			listenElements = document.getElementsByName(nowPlaying);
			for (x=0;x<listenElements.length;x++) {
				listenElements[x].lastChild.innerHTML = '&nbsp;';
			}
		}
		nowPlaying = whichID;
		listenElements = document.getElementsByName(whichID);
		for (x=0;x<listenElements.length;x++) {
			listenElements[x].lastChild.innerHTML = '<img src="/music/images/s/buttons/loading.png">';
		}
		$('mHF').src = "/music/jsp/hidden_player.jsp?musicFileUrl=" + whichClipURL;
	}
	else if (nowPlaying == whichID) {
		nowPlaying = "";
		listenElements = document.getElementsByName(whichID);
		for (x=0;x<listenElements.length;x++) {
			listenElements[x].lastChild.innerHTML = '&nbsp;';
		}
		$('mHF').src = "/music/images/generic/spacer.gif";
	}
}

function p2() {
	var listenElements = document.getElementsByName(parent.nowPlaying);
	for (x=0;x<listenElements.length;x++) {
		if (listenElements[x].lastChild.innerHTML.match("loading.png") == 'loading.png')
		{
		 listenElements[x].lastChild.innerHTML = '<img src="/music/images/s/buttons/stop.png">';
	    }
	    else
		{
		 listenElements[x].lastChild.innerHTML = 'Stop';
	    }
	}
}

function stopClipPlaying() {
	if (nowPlaying != "") {
		document.getElementById('mHF').src = "/music/images/generic/spacer.gif";
		nowPlaying = "";
	}
}

function musiverse_play(whichClipURL) {
		document.getElementById('mHF').src = "/music/jsp/hidden_player.jsp?musicFileUrl=" + whichClipURL;
}

/*function musiverse_open(whichUrl) {
	var eleft = (screen.width - 1000) / 2;
	var etop = (screen.height - 600) / 2;
	var explorer = window.open(whichUrl,'explorer','width=1000,height=596,left='+eleft+',top='+etop+',toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,menubar=no');
	explorer.focus();
}*/

function musiverse_user(aUrl) {
	var leftpos = screen.width-840;
	if (leftpos<0) leftpos = 0;
	var	usernewwindow = window.open(aUrl + '?ICO=musicExplorer&ICL=userLink','usernewwindow','left='+leftpos+',top=0,width=840,height=650,toolbar=yes,location=yes,directories=yes,status=yes,scrollbars=yes,resizable=yes,menubar=yes');
	usernewwindow.focus();
}

function musiverse_stop() {
	document.getElementById('mHF').src = "/music/images/generic/spacer.gif";
}

//TOGGLE HOTSPOTS *************************************************************

var hotspots = document.getElementsByName('hotspot');
var toggles = document.getElementsByName('toggle');

function visibilitytoggle()
{
for (var i = 0; i < hotspots.length; i++)
{
hotspots[i].someProperty = i;
hotspots[i].onclick = function() {toggle(this.someProperty)};
}
	
}




function toggle(i) {

	

	  var toggleHide = function() {
	toggles[i].style.display = 'none';
}


if (toggles[i].style.display == 'none') {

toggles[i].style.display = '';
	oldheight=toggles[i].scrollHeight;
toggles[i].style.height='1px';

		
	new fx.Height(toggles[i], {duration: 400}).custom(0, oldheight);

 // if toggle is within marketplace resize marketplace as well.
 if ((hotspots[i].innerHTML.indexOf("marketplace") != -1) || (hotspots[i].innerHTML.indexOf("ringtones") != -1)) {		
	 
 var tabDiv =  $("marketPlaceTabTarget");
   var mkttee=tabDiv.scrollHeight;	
   new fx.Height(tabDiv, {duration: 400}).custom(mkttee, mkttee + oldheight);
 }


		if (hotspots[i].innerHTML.indexOf("comment") != -1) {
			document.forms['comment'].commentText.focus();
		}
	}
	else {

 oldheight=toggles[i].scrollHeight;
 
 		
 new fx.Height(toggles[i], {duration: 400}).toggle();
	
	// if toggle is within marketplace resize marketplace as well.
	if ((hotspots[i].innerHTML.indexOf("marketplace") != -1) || (hotspots[i].innerHTML.indexOf("ringtones") != -1)) {
	
   var tabDiv =  $("marketPlaceTabTarget");
   var mkttee=tabDiv.scrollHeight;	
   new fx.Height(tabDiv, {duration: 400, onComplete: function() {toggles[i].style.display = 'none';}}).custom(mkttee, mkttee - oldheight);
	}

	}
	var toggleButtons = hotspots[i].getElementsByTagName("img");
	if (toggleButtons.length > 0) {
		if (toggleButtons[0].getAttribute("src").indexOf("show_all_full.gif") != -1) {
			toggleButtons[0].setAttribute("src","/music/images/s/show_top_full.gif");
		}
		else if (toggleButtons[0].getAttribute("src").indexOf("show_top_full.gif") != -1) {
			toggleButtons[0].setAttribute("src","/music/images/s/show_all_full.gif");
		}
		else if (toggleButtons[0].getAttribute("src").indexOf("show_all.gif") != -1) {
			toggleButtons[0].setAttribute("src","/music/images/s/show_top.gif");
		}
		else if (toggleButtons[0].getAttribute("src").indexOf("show_top.gif") != -1) {
			toggleButtons[0].setAttribute("src","/music/images/s/show_all.gif");
		}
	}
	else {
		if (hotspots[i].innerHTML.indexOf("Read user reviews") != -1) {
			hotspots[i].innerHTML = 'Hide user reviews';
		}
		else if (hotspots[i].innerHTML.indexOf("Add a review") != -1){
			hotspots[i].innerHTML = '<strong>Cancel review<strong>';
		}
		else if (hotspots[i].innerHTML.indexOf("Hide user reviews") != -1) {
			hotspots[i].innerHTML = '<strong>Read user reviews</strong>';
		}
		else if (hotspots[i].innerHTML.indexOf("Cancel review") != -1){
			hotspots[i].innerHTML = '<strong>Add a review<strong>';
		}
		else if (hotspots[i].innerHTML.indexOf("Cancel review") != -1){
			hotspots[i].innerHTML = '<div class="explore_btn"><a href="#">&nbsp;</a><strong>Add a review</strong><div>';
		}
		else if (hotspots[i].innerHTML.indexOf("marketplace") != -1) {		
		  if (hotspots[i].innerHTML.indexOf("Show all") != -1){
					hotspots[i].innerHTML = '<span id=\"marketplace\"><div class="showhide" onmouseover="this.style.cursor=\'pointer\'">Show top 2</div></span>';
		}
		else if (hotspots[i].innerHTML.indexOf("Show top 2") != -1){
					hotspots[i].innerHTML = '<span id=\"marketplace\"><div class="showhide" onmouseover="this.style.cursor=\'pointer\'">Show all</div></span>';
		}
	  }
	  else if (hotspots[i].innerHTML.indexOf("ringtones") != -1) {		
		  if (hotspots[i].innerHTML.indexOf("Show all") != -1){
					hotspots[i].innerHTML = '<span id=\"ringtones\"><div class="showhide" onmouseover="this.style.cursor=\'pointer\'">Show 1</div></span>';
		}
		else if (hotspots[i].innerHTML.indexOf("Show 1") != -1){
					hotspots[i].innerHTML = '<span id=\"ringtones\"><div class="showhide" onmouseover="this.style.cursor=\'pointer\'">Show all</div></span>';
		}
	  }
	else if (hotspots[i].innerHTML.indexOf("Show top 5") != -1){
					hotspots[i].innerHTML = '<strong><div class="showhide" onmouseover="this.style.cursor=\'pointer\'">Show all</div></strong>';
		}
		else if (hotspots[i].innerHTML.indexOf("Show all") != -1){
					hotspots[i].innerHTML = '<strong><div class="showhide" onmouseover="this.style.cursor=\'pointer\'">Show top 5</div></strong>';
		}
 }
}

//COOKIES *********************************************************************

function setCookie(name, value) {
var expires = new Date();
var expiresDelay = 1000*60*60*24*365;
expires.setTime(expires.getTime() + expiresDelay);
document.cookie = name + "=" + escape(value) + "; path=\/; expires=" + expires.toGMTString();
}

function getCookie(name) {
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) return "";
} else
begin += 2;
var end = document.cookie.indexOf(";", begin);
if (end == -1)
end = dc.length;
return unescape(dc.substring(begin + prefix.length, end));
}

function stripHTML(htstring) {
htstring = htstring.replace(/(<([^>]+)>)/ig," ");
htstring = htstring.replace(/  /g," ");
return htstring;
}

/*function whatWidget() {
	if(lengthTotal == theArtistString.length || lengthTotal == theArtistString.length + theTrackString.length) {
		return theWidgetNone;
	}

	if((lengthTotal % 2) == 1) {
		return theWidgetOne;
	}	else {
		return theWidgetTwo;
	}
}*/

//*****************************************************************************

function embedPlayer(whichClip) {
document.write("<OBJECT id='mediaPlayer' name='mediaPlayer' width='320' height='285' classid='CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95' codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701' standby='Loading MS WM components...' type='application/x-oleobject'>");
document.write("<param name='fileName' value='"+whichClip+"'>");
document.write("<param name='animationatStart' value='false'>");
document.write("<param name='transparentatStart' value='false'>");
document.write("<param name='autoStart' value='true'>");
document.write("<param name='showControls' value='true'>");
document.write("<param name='loop' value='true'>");
document.write("<EMBED type='application/x-mplayer2' pluginspage='http://microsoft.com/windows/mediaplayer/en/download/' id='mediaPlayer' name='mediaPlayer' displaysize='4' autosize='-1' bgcolor='darkblue' showcontrols='true' showtracker='-1' showdisplay='0' showstatusbar='-1' videoborder3d='-1' width='320' height='285' src='"+whichClip+"' autostart='true' designtimesp='5311' loop='false'></EMBED>");
document.write("</OBJECT>");
}

//FIX LINKS *******************************************************************

var hideAlbums = ["Club Beats", "Club November", "Connexions Latina", "Dance Express", "DMC Commercial Collection", "DMC DJ Only", "Euro Express", "Exitos Express", "Hitdisc", "Hitsheet", "Pop Beats", "Pop Beats", "Pop Express", "Pop November", "Praisedisc", "Radio Express", "Radio Xtra", "Rock Express", "Sampler", "Shazam Dummy Product", "Street Beats", "The Reel", "TMC", "Underground Beats", "Urban Express", "US Beats", "XNC"];

var thisLink, invalidLink;

function fixLinks() {
	for (i=0;i<document.links.length;i++) {
		
		invalidLink = false;
		thisLink = document.links[i];
		
		if (thisLink.href.indexOf("/page/track/") != -1) {
			thisLink.href = thisLink.href.replace("/page/track/","/page/ctrack/");
		}
		
		if (thisLink.innerHTML == "" && thisLink.tagName != "AREA") {
			invalidLink = true;
		} else {
		
		for (j=0;j<hideAlbums.length;j++) {
			if (thisLink.innerHTML.indexOf(hideAlbums[j]) == 0) {
				invalidLink = true;
			}
		}
		
		}
		
		if (invalidLink) {
			 thisLink.href = "#";
			 thisLink.innerHTML = "[Compilation]";
		}
		
		if ((thisLink.href == location.href) && (thisLink.parentNode.tagName != "LI")) {
			// && thisLink.href.indexOf("/Myhome/") == -1
			thisLink.className = "current";
		}
		
	}
}

//check search forms **********************************************************

function checkSearch(aForm) {
	if (aForm.query.value == "" || aForm.query.value == "Search") {
		return false;
	}
	else
		return true;
}	



//TEMP ************************************************************************

function writeSupportEmail() {
	document.write("<a href='mailto:support@shazam.com'>support@shazam.com</a>");
}

//************************************************************************* -->

function setUpMessagePopUp() {

}

function showMessagePopUp(aMessage) {
	
$("popup_msg_msg").innerHTML = '<div class="hd"><h2 class="white">alert</h2></div><div class="bd">' + aMessage + '<div class="cancel"><span class="links" onclick="hideMessagePopUp()";><br/><a href="#">> close</a></span></div></div>';
	lb = new lightbox();
lb.initCallable('popup_msg_msg');
lb.activate();
$('lightbox').style.width = '537px';
$('lightbox').style.height = '100px';


}

function hideMessagePopUp() {
	lb = new lightbox();
lb.initCallable('popup_msg_msg');
lb.deactivate();
}

function toggleRowVisibility(aRowID, onOrOff) {
if ($(aRowID).getStyle('display') == 'table-row') {
		if (onOrOff == 'off') {
			$(aRowID).setStyle({visibility: 'collapse'});
		}
		else {
			$(aRowID).setStyle({visibility: 'visible'});
		}
	}
	else {
		if (onOrOff == 'off') {
			$(aRowID).setStyle({display: 'none'});
		}
		else {
			$(aRowID).setStyle({display: 'block'});
		}
	}
}



/* Following imported from communities.js */

//var mainProfileAreaAnim;
//var myMusicSubAreaAnim;
var initRun = false;
var waitBody = '';
var requiredMajorVersion = 6;
var requiredMinorVersion = 0;
var requiredRevision = 0;

var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

if (hasReqestedVersion) {
 waitBody = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="155" height="110" id="loading" align="middle"><param name="wmode" value="transparent"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="/music/swf/loading.swf" /><param name="quality" value="high" /><embed src="/music/swf/loading.swf" quality="high" wmode="transparent" width="155" height="110" name="loading" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
} else {
waitBody = '<img src="/music/images/s/communities/loading.gif" alt="Loading...">';
}



function showMessageBox(aUserId) {
	if (aUserId != "") {
		document.msgForm.to.value = aUserId;
	}

	document.msgForm.reply.value = "";
	document.msgForm.message.value = "";
	toggleRowVisibility('messagereplybutton', 'off')
	  lb = new lightbox();
lb.initCallable('msg_box');
lb.activate();
$('lightbox').style.width = '537px';
$('lightbox').style.height = '400px';

	
}

function showReplyMessageBox(aUserId, aReplyId) {

	if (aUserId != "") {
		$('msgForm').to.value = aUserId;
	}
	$('msgForm').reply.value = aReplyId;
	$('msgForm').message.value = "";
	toggleRowVisibility('messagereplybutton', 'on')

lb = new lightbox();
lb.initCallable('msg_box');
lb.activate();
$('lightbox').style.width = '537px';
$('lightbox').style.height = '400px';

}

function hideMessageBox() {
	lb = new lightbox();
lb.initCallable('msg_box');
lb.deactivate();
}

function showReportAUserBox() {
lb = new lightbox();
lb.initCallable('raumsg_box');
lb.activate();
$('lightbox').style.width = '537px';
$('lightbox').style.height = '400px';

}

function hideReportAUserBox() {
lb = new lightbox();
lb.initCallable('raumsg_box');
lb.deactivate();
}

function removeElementById(id) {
       element = $( id );
       element.parentNode.removeChild( element );
}

function getChecked(aList) {
       for (i=0;i<aList.length;i++) {
         if (aList[i].checked) return aList[i];
       }
       return false;
}

function getReplyValue(aReplyId, boolChecked) {
	if (boolChecked) {
		return aReplyId;
	}
	return 0;
}

//var changeMusicSubTabSuccess = function(o){

//	var div = $(o.argument+'Target');
//	div.innerHTML = o.responseText;
//	if (myMusicSubAreaAnim.isAnimated()) myMusicSubAreaAnim.stop();
//	var heightAttributes = { height: { to: div.scrollHeight } };
//	myMusicSubAreaAnim = new YAHOO.util.Anim(div, heightAttributes, resizeAnimationTime (heightAttributes, YAHOO.util.Dom.getStyle(div, 'height')), YAHOO.util.Easing.easeBoth);
//	myMusicSubAreaAnim.animate();
//	hideWait();
//}

var changeTabFailure = function(o){
  hideWait();
  showMessagePopUp("Loading Failed");
  
}

function deleteMessage(aMsgId) {
	var msgAction = "community.MessageAction";
	var formAction = "/music/portal/mode/nocontainer/template/message_response";
	var msgData = "action="+msgAction+"&tag_content_id="+aMsgId+"&eventSubmit_doDeletemessage=";
	
	new Ajax.Request(formAction, {method: 'post', parameters: msgData, onSuccess: function(messageDeleted) {
if(messageDeleted.responseText !== undefined){
		showMessagePopUp(messageDeleted.responseText);
	}
	},
	onFailure: function(messageDeletedFailure) { }})
	//removeElementById(aMsgId);
}


function addFriendProfile(aUrl, userId, referUrl) {
	var msgData = "relationship_userb="+userId+"&relationship_type=FAVOURITE&relationship_action=add&referrerUri="+referUrl;
  new Ajax.Request(aUrl, {method: 'post', parameters: msgData});
	var friendElements = document.getElementsByClassName('addFriend'+userId);
	var friendSpan = friendElements[0];
	friendSpan.innerHTML = '<a href="#" onclick="removeFriendProfile(\''+aUrl+'\','+userId+',\''+referUrl+'\'); return false;"><img src="/music/images/s/buttons/del_sm_dark.png" alt=""/> remove as friend</a>';
friendSpan.addClassName('removeFriend'+userId);
friendSpan.removeClassName('addFriend'+userId);
}


function removeFriendProfile(aUrl, userId, referUrl) {
	var msgData = "relationship_userb="+userId+"&relationship_type=FAVOURITE&relationship_action=remove&referrerUri="+referUrl;
	new Ajax.Request(aUrl, {method: 'post', parameters: msgData});
	var friendElements = document.getElementsByClassName('removeFriend'+userId);
	var friendSpan = friendElements[0];
	friendSpan.innerHTML = '<a href="#" onclick="addFriendProfile(\''+aUrl+'\','+userId+',\''+referUrl+'\'); return false;"><img src="/music/images/s/buttons/add_sm_dark.png" alt=""/> add to friends</a>';
	friendSpan.removeClassName('removeFriend'+userId);
friendSpan.addClassName('addFriend'+userId);
}

function removeFriendFriend(userId, referUrl) {

	var msgAction = "registration.ModifyRelationshipAction";
	var msgData = "action="+msgAction+"&relationship_userb="+userId+"&relationship_type=FAVOURITE&relationship_action=remove&referrerUri="+referUrl;
	new Ajax.Request(msgAction, {method: 'post', parameters: msgData});
removeElementById("friend"+userId);
}

function deleteTag(aTagTimeStamp) {
	var msgAction = "/music/portal/template/profile/action/portlets.TagListAction/timestamp/"+aTagTimeStamp+"/eventsubmit_dohidetag/hide";
	//var request = YAHOO.util.Connect.asyncRequest('GET', msgAction, changeFriendCallBack);
	
	new Ajax.Request(msgAction, {method: 'get'});
	removeElementById("tag"+aTagTimeStamp);
}


function deleteTag(aTagTimeStamp,ueeUserId) {
	var msgAction = "/music/portal/template/profile/action/portlets.TagListAction/timestamp/"+aTagTimeStamp+"/eventsubmit_dohidetag/hide/uuee/"+ueeUserId ;
	//var request = YAHOO.util.Connect.asyncRequest('GET', msgAction, changeFriendCallBack);
	
	new Ajax.Request(msgAction, {method: 'get'});
	removeElementById("tag"+aTagTimeStamp);
}

function msgPanelHideCallback(e) { toggleRowVisibility('messagereplybutton', 'off'); }

function init() {
	//hideWait();

	initRun = true;
		
	if (window.location.hash.indexOf("#") > -1) {
		var myele =  $(window.location.hash.substr(1,window.location.hash.length)+"Button");
		myele.onclick();
	}
	var openme =  $("recommendationsTabButton");  //automatically open recommendations tab
		
	if (openme != null) openme.onclick();
}

function sendMessage(aMessage,aTo,aVisibility,aReplyId) {
	hideMessageBox();
	var msgAction = "community.MessageAction";
  var formAction = "/music/portal/mode/nocontainer/template/message_response";
	var msgData = "action="+msgAction+"&message="+aMessage+"&message_recipient_id="+aTo+"&message_visability="+aVisibility+"&message_reply_id="+aReplyId+"&eventSubmit_doSendmessage=true";
	new Ajax.Request(formAction, {method: 'post', parameters: msgData, onSuccess: function(sentMessage) {
	if(sentMessage.responseText !== undefined){
		showMessagePopUp(sentMessage.responseText);}}})
}

function setTempMessage(tmsg) {
	Temp_Message = tmsg;
}

function getTempMessage() {
	return(Temp_Message);
}

function setTempUsername(tusr) {
	Temp_Username = tusr;
}

function getTempUsername() {
	return(Temp_Username);
}

function blockUser(aUserId, aReferUrl) {
var msgAction = "registration.ModifyRelationshipAction";
var msgData = "action="+msgAction+"&relationship_userb="+aUserId+"&relationship_type=BLOCKED&relationship_action=add&referrerUri="+aReferUrl;
new Ajax.Request(msgAction, {method: 'post', parameters: msgData});
var blockSpans = document.getElementsByClassName('block'+aUserId, 'span');
for (i=0;i<blockSpans.length;i++) {
 blockSpans[i].innerHTML = '<a href="/music/web/update-profile.htm?openSection=blocked#blocked">Blocked</a><br />';
}
}

function changeSubTabArea(aUrl, tabIdName) {

	showWait();
	var timeNow = new Date().getTime();
	var div = $(tabIdName+'Target');
	var heightAttributes = 0;
	new fx.Height(div, {duration: 400}).custom(0, heightAttributes);
	new Ajax.Request( aUrl+'&t='+timeNow,{ method: 'get',  onSuccess: function(tabAreaContent){
	var div = $(tabIdName+'Target');
	div.innerHTML = tabAreaContent.responseText;
	var heightAttributes = div.scrollHeight;
	new fx.Height(div, {duration: 400}).custom(0, heightAttributes);
	hideWait();
  
  },
	onFailure: function(ctfailure){
  
  showMessagePopUp("Loading Failed");
}});
	hideWait();
}

function changeTagList(aUrl) {
  showWait();
	var timeNow = new Date().getTime();
	new Ajax.Request (aUrl+'&t='+timeNow, {method: 'get', onSuccess: function(tagListChangeSuccess){
  var div = $('tag_list');
	if(tagListChangeSuccess.responseText !== undefined){
		div.innerHTML = tagListChangeSuccess.responseText;
	}
},
onFailure: function(tagListChangeFailure){
  hideWait();
  showMessagePopUp("Loading Failed");
}}
)

hideWait();
}

function sendReportAUserMessage(aUser, aMessage) {

	hideReportAUserBox();
	var msgAction = "community.ContactAdminAction";
	var formAction = "/music/portal/mode/nocontainer/template/message_response";
	var msgData = "action="+msgAction+"&message="+aUser+" - "+aMessage+"&admin_message_type=report_user";
	new Ajax.Request (formAction, {method: 'post', parameters: msgData, onSuccess: function (reportAUserSuccess) {
	if(reportAUserSuccess.responseText !== undefined){
		showMessagePopUp(reportAUserSuccess.responseText);
  }}})
}

var clearArgs = "";

var clearTargetHandler = function(tabIdName) {
	$(clearArgs+'Target').innerHTML = "";
}



function resizeAMGTab(tabIdName, clearTab) {

	var tabLink = $(tabIdName+"Button");
	var tabDiv =  $(tabIdName+"Target");
	
	if ($(tabDiv).getStyle('height') == '100px') {
	tabLink.innerHTML = '<div class="showhide" onmouseover="this.style.cursor=\'pointer\'">hide</div>';
		var heightAttributes = tabDiv.scrollHeight;
		new fx.Height(tabDiv, {duration: 400}).custom(100, heightAttributes);
	}
	else {
		tabLink.innerHTML = '<div class="showhide" onmouseover="this.style.cursor=\'pointer\'">show</div>';
		var heightAttributes = 100;
		new fx.Height(tabDiv, {duration: 400}).custom(tabDiv.scrollHeight, heightAttributes);
	}
}


function resizeAMGTabDisc(tabIdName, clearTab) {

	var tabLink = $(tabIdName+"Button");
	var tabDiv =  $(tabIdName+"Target");
	  
if ($(tabDiv).getStyle('height') == '100px') {
		tabLink.innerHTML = '<div class="showhide" onmouseover="this.style.cursor=\'pointer\'">Hide</div>';
		var heightAttributes = tabDiv.scrollHeight;
		new fx.Height(tabDiv, {duration: 400}).custom(100, heightAttributes);
	}

	else {
		tabLink.innerHTML = '<div class="showhide" onmouseover="this.style.cursor=\'pointer\'">More</div>';
		var heightAttributes = 100;
		new fx.Height(tabDiv, {duration: 400}).custom(tabDiv.scrollHeight, heightAttributes);
	}
}


function resizeMarketplace(tabIdName, clearTab) {
var tabLink1 = $(tabIdName+"Button1");
	var tabLink2 = $(tabIdName+"Button2");
	if ($(tabIdName+"Button3")) {
  	var tabLink3 = $(tabIdName+"Button3");
	}
	var tabDiv =  $(tabIdName+"Target");
	if ($(tabDiv).getStyle('height') == '0px') {
		tabLink1.innerHTML = '<div class="showhide" onmouseover="this.style.cursor=\'pointer\'">Hide Marketplace</div>';
		tabLink2.innerHTML = '<div class="showhide" onmouseover="this.style.cursor=\'pointer\'">Hide Marketplace</div>';
  	if ($(tabIdName+"Button3")) {
    		tabLink3.innerHTML = "View Tracklisting";
  	}
  	var heightAttributes = tabDiv.scrollHeight;
	}
	else {
		tabLink1.innerHTML = '<div class="showhide" onmouseover="this.style.cursor=\'pointer\'">Show Marketplace</div>';
		tabLink2.innerHTML = "";
		if ($(tabIdName+"Button3")) {
    		tabLink3.innerHTML = "";
		}
  	var heightAttributes = 0;
	}
	new fx.Height(tabDiv, {duration: 400}).toggle();
}

var responseSuccess = function(o){
	var div = $(o.argument+'Target');
	div.innerHTML = o.responseText;
	hideWait();
	resizeTab(o.argument, false);
};

var recommendationsLoaded = false;
var recommendationsTabContent;

function loadTab(tabIdName, userName) {
		if ($(tabIdName+'Target').innerHTML != "") {
			resizeTab(tabIdName, true);
		}
		else {
			var page = "";
			var timeNow = new Date().getTime();
			switch (tabIdName){
				case "myFriendsTab":
					page = "/music/jsp/communities/myfriends.jsp?u="+userName+"&t="+timeNow;
					break;
				case "myMessagesTab":
					page = "/music/jsp/communities/messages.jsp?u="+userName+"&t="+timeNow;
					
					
					// set message notification at top of screen to "0 messages"
					// 17/12/07 Removed as this caused the page to fail if the user is not logged in, and resets the message counter even when you look at another user's profile
					//var msgarea = $('msgnotify');
	      			//msgarea.innerHTML = '<span class="notify"><a href="/music/portal/page/default/template/profile#myMessagesTab" title="0 messages">0 messages</a></span>';
					break;
					
				case "recommendationsTab":
					page = "/music/web/myrecommendations";
					break;
				case "myReviewsTab":
					page = "/music/jsp/communities/reviews.jsp?u="+userName+"&t="+timeNow;
			}
			showWait();
			
			var tdiv = $(tabIdName+'Target');
			
			if ((recommendationsLoaded == true) && (tabIdName == "recommendationsTab"))
			{
			  tdiv.innerHTML = recommendationsTabContent;
        hideWait();
        resizeTab(tabIdName, false);
      }
      else
      {
			new Ajax.Request(page, {method: 'get', onSuccess: function(loadedTab) {
    
			
    		tdiv.innerHTML = loadedTab.responseText;
    		if (tabIdName == "recommendationsTab")
    		{
          recommendationsTabContent = loadedTab.responseText;
        }
	   		hideWait();
	   		recommendationsLoaded = true;
	        resizeTab(tabIdName, false);
    		}, onFailure: function(failedTab) {
        	hideWait();
        	showMessagePopUp("Loading Failed");
    		}})
    	}
		}

}

function warninghide(divref) {
	state = 'hidden';
	if (document.all) { 
	eval( "document.all." + divref + ".style.visibility = state");
	}
	if (document.layers) { 
	document.layers[divref].visibility = state;
	}
	if ($ && !document.all) {
	divobj = $(divref);
	divobj.style.visibility = state;
	}
}

function warningshow(divref) {
	state = 'visible';
	if (document.all) { 
	eval( "document.all." + divref + ".style.visibility = state");
	}
	if (document.layers) { 
	document.layers[divref].visibility = state;
	}
	if ($ && !document.all) {
	divobj = $(divref);
	divobj.style.visibility = state;
	}
}

function resizeAnimationTime (aAnimObject, aHeightSize) {
	return Math.abs(aAnimObject.height.to-aHeightSize.substring(0,aHeightSize.length-2))/300;
}


function webTag(wt_Action, wt_tagTypeID, wt_contentTypeId, wt_contentKey, wt_referrerUri) {
	
var msgAction = "community.MessageAction";
var formAction = "/music/portal/mode/nocontainer/template/message_response";
var msgData = "action="+wt_Action+"&tagTypeID="+wt_tagTypeID+"&contentTypeID="+wt_contentTypeId+"&contentKey="+wt_contentKey+"&referrerUri="+wt_referrerUri;
new Ajax.Request (formAction, {method: 'post', parameters: msgData, onSuccess: function(webTagSuccess) {
if(webTagSuccess.responseText !== undefined){
		$('webtag_status').innerHTML=webTagSuccess.responseText;
}},
onFailure: function(webTagFailure){
	if(webTagFailure.responseText !== undefined){
		$('webtag_status').innerHTML=webTagSuccess.responseText;
}}})
}
		
		
 
  
  function iTunesCurrency(TLCurr){
     if (TLCurr == "GBP") {
      return("&pound; ");
    }
    if ((TLCurr == "USD") || (TLCurr == "USD") || (TLCurr == "AUD")) {
      return("$ ");
    }
    if (TLCurr == "EUR") {
      return("&euro; ");
    }
    return("");
  }
  
 function iTunesPrice(TLCurr, price) {
    if ((TLCurr == "GBP") || (TLCurr == "USD") || (TLCurr == "AUD") || (TLCurr == "EUR"))
    {
      return(price)
    }
    else
    {
      return "";
    }
  }
  
 
 var iTunesTrackingURL = 'http://clkuk.tradedoubler.com/click?p=23708&a=1332301&url=';
 
	function iTunesTrack(iTunesObject)
	{
		//$('iTunes').style.height = "1";
		//$('iTunes').remove();
		eval(iTunesObject);
		if (iTunesObject.resultCount > 0)
		{
			iTunesHidden = false;
			for (resultCount=0; resultCount < 1; resultCount++)
			{
			    var storeURL = iTunesTrackingURL + escape(iTunesObject.results[resultCount].trackViewUrl + partnerId);
			    var listenURL = iTunesObject.results[resultCount].previewUrl;
			    iTunesRow_col_1 = '<a title="buy from iTunes" target="_blank" href="' + storeURL + '"><img src="/music/images/itunes.png" alt="Buy from iTunes" width="69" height="25"></a>';
				iTunesRow_col_2 = '<a target="_blank" title="buy from iTunes" href="' + storeURL + '"><img src="' + iTunesObject.results[resultCount].artworkUrl60 +'" alt="Buy from iTunes" width="60" height="60"></a>';
	         	iTunesRow_col_3 = iTunesObject.results[resultCount].artistName + ' - ' + iTunesObject.results[resultCount].trackName;
	         	iTunesRow_col_4 = iTunesCurrency(iTunesObject.results[resultCount].currency) + iTunesPrice(iTunesObject.results[resultCount].currency,iTunesObject.results[resultCount].trackPrice.toPrecision(2)); 
				if (iTunesObject.results[resultCount].trackPrice < 0)
 		     {
          iTunesRow_col_4 = "";
        }
        iTunesRow_col_5 = '<a target="_blank" title="listen in iTunes"  href="' + listenURL + '"><img src="/music/images/s/itunes_listen.png" alt="Listen" width="22" height="22"></a>';
				iTunesRow_col_6 = '<a target="_blank" title="buy from iTunes" href="' + storeURL + '"><img src="/music/images/s/buttons/buy.png" alt="Buy from iTunes" width="44" height="19"></a><br/>';
			}
				$('iTunesLinkContent_col_1').innerHTML = iTunesRow_col_1;
			   	$('iTunesLinkContent_col_2').innerHTML = iTunesRow_col_2;
			   	$('iTunesLinkContent_col_3').innerHTML = iTunesRow_col_3;
			   	$('iTunesLinkContent_col_4').innerHTML = iTunesRow_col_4;
			   	$('iTunesLinkContent_col_5').innerHTML = iTunesRow_col_5;
			   	$('iTunesLinkContent_col_6').innerHTML = iTunesRow_col_6;
			   	
			}
	else {
		iTunesHidden = true;
				iTunesRow_col_1 = '<img src="/music/images/itunes.png" alt="iTunes" width="69" height="25">';
				iTunesRow_col_2 = '&nbsp;';
	         	iTunesRow_col_3 = 'This track is not currently available from the iTunes store';
				iTunesRow_col_4 = '&nbsp;'; 
				iTunesRow_col_5 = '&nbsp;';
				iTunesRow_col_6 = '&nbsp;';
				
				$('iTunesLinkContent_col_1').innerHTML = iTunesRow_col_1;
			   	$('iTunesLinkContent_col_2').innerHTML = iTunesRow_col_2;
			   	$('iTunesLinkContent_col_3').innerHTML = iTunesRow_col_3;
			   	$('iTunesLinkContent_col_4').innerHTML = iTunesRow_col_4;
			   	$('iTunesLinkContent_col_5').innerHTML = iTunesRow_col_5;
			   	$('iTunesLinkContent_col_6').innerHTML = iTunesRow_col_6;
}
	}
	
	function iTunesAlbum(iTunesObject)
	{
	//	$('iTunes').style.height = "1";
	//	$('iTunes').remove();
		eval(iTunesObject);
		
		if (iTunesObject.resultCount > 0)
		{
			for (resultCount=0; resultCount < 1; resultCount++)
			{
			  	var storeURL = iTunesTrackingURL + escape(iTunesObject.results[resultCount].collectionViewUrl + partnerId);
 			iTunesRow_col_1 = '<a target="_blank" title="buy from iTunes" href="' + storeURL + '"><img src="/music/images/itunes.png" alt="Buy from  " width="69" height="25"></a>';
				iTunesRow_col_2 = '<a target="_blank" title="buy from iTunes" href="' + storeURL + '"><img src="' + iTunesObject.results[resultCount].artworkUrl60 +'" alt="Buy from iTunes" width="60" height="60"></a>';
				iTunesRow_col_3 = iTunesObject.results[resultCount].artistName + ' - '  + iTunesObject.results[resultCount].collectionName;;
				iTunesRow_col_4 = iTunesCurrency(iTunesObject.results[resultCount].currency) + iTunesPrice(iTunesObject.results[resultCount].currency,iTunesObject.results[resultCount].collectionPrice.toPrecision(3));
				if (iTunesObject.results[resultCount].collectionPrice < 0)
 		     {
          iTunesRow_col_4 = "";
        }
        iTunesRow_col_5 = '&nbsp;';
 			iTunesRow_col_6 = '<a target="_blank" title="buy from iTunes" href="' + storeURL + '"><img src="/music/images/s/buttons/buy.png" alt="Buy from iTunes" width="44" height="19"></a>';
 		}
 		
 		   
 			$('iTunesLinkContent_col_1').innerHTML = iTunesRow_col_1;
			   	$('iTunesLinkContent_col_2').innerHTML = iTunesRow_col_2;
			   	$('iTunesLinkContent_col_3').innerHTML = iTunesRow_col_3;
			   	$('iTunesLinkContent_col_4').innerHTML = iTunesRow_col_4;
			   	$('iTunesLinkContent_col_5').innerHTML = iTunesRow_col_5;
			   	$('iTunesLinkContent_col_6').innerHTML = iTunesRow_col_6;
			   	
		}
	else {
iTunesHidden = true;
iTunesRow_col_1 = '<img src="/music/images/itunes.png" alt="iTunes" width="69" height="25">';
				iTunesRow_col_2 = '&nbsp;';
	         	iTunesRow_col_3 = 'This product is not currently available from the iTunes store';
				iTunesRow_col_4 = '&nbsp;'; 
				iTunesRow_col_5 = '&nbsp;';
				iTunesRow_col_6 = '&nbsp;';
				
				$('iTunesLinkContent_col_1').innerHTML = iTunesRow_col_1;
			   	$('iTunesLinkContent_col_2').innerHTML = iTunesRow_col_2;
			   	$('iTunesLinkContent_col_3').innerHTML = iTunesRow_col_3;
			   	$('iTunesLinkContent_col_4').innerHTML = iTunesRow_col_4;
			   	$('iTunesLinkContent_col_5').innerHTML = iTunesRow_col_5;
			   	$('iTunesLinkContent_col_6').innerHTML = iTunesRow_col_6;
}
}
	
	function iTunesArtist(iTunesObject)
	{
		$('iTunes').style.height = "1";
		$('iTunes').remove();
		eval(iTunesObject);
		if (iTunesObject.resultCount > 0)
		{
			for (resultCount=0; resultCount < 1; resultCount++)
			{
			  	var storeURL = iTunesTrackingURL + escape(iTunesObject.results[resultCount].artistViewUrl  + partnerId);
 			iTunesRow_col_1 = '<a target="_blank" title="buy from iTunes" href="' + storeURL + '"><img src="/music/images/itunes.png" alt="Buy from iTunes" width="69" height="25"></a>';
				iTunesRow_col_2 = '&nbsp;';
 			iTunesRow_col_3 = iTunesObject.results[resultCount].artistName;
				iTunesRow_col_4 = '&nbsp;'; 
				iTunesRow_col_5 = '&nbsp;';
				iTunesRow_col_6 = '<a target="_blank" title="buy from iTunes" href="' + storeURL + '"><img src="/music/images/s/buttons/buy.png" alt="Buy from iTunes" width="44" height="19"></a>';
		}
		 
}
else {
iTunesHidden = true;

}
}
	
		

	function changeLocale() {         
	 // redirect the user to this url adding the parameter l=locale to localize the response. 
		var idx = document.forms['locale_form'].locale.selectedIndex;
  		var alocale = document.forms['locale_form'].locale[idx].value;

		if (alocale != '') {

			var startURL = document.location.href;
			var startPos = startURL.indexOf("&l=");
			if (startPos > 0)
			{
				var subStringOne = startURL.substring(0, startPos+3);
				var subStringTwo = startURL.substring(startPos+8);
				document.location.href = subStringOne+alocale+subStringTwo;
				
			}
			else
			{
				var url = document.location.href + '&l='+alocale;
				document.location.href = url;
			}
	}
}

		
	function showMarketPlace(mp_musicObjectId, mp_musicObjectType, mp_DivId, mp_artistString, mp_addonSourceKey, mp_addonSourceTypeId, mp_addonsProductsFloat, mp_musicObjectTitle, mp_firstArtistName)
	  {
    //showWait();
    	iTunesHidden = true;
    	var msgAction = "/music/web/marketplace.do";
    	mp_artistString = escape(mp_artistString);
    	mp_firstArtistName = escape(mp_firstArtistName);
    	var msgData = "action="+msgAction+"&musicObjectId="+mp_musicObjectId+"&musicObjectType="+mp_musicObjectType+"&template=marketplace"+"&mode=nocontainer"+"&artistString="+mp_artistString+"&addonSourceKey="+mp_addonSourceKey+"&addonSourceTypeId="+mp_addonSourceTypeId+"&addonsProductsFloat="+mp_addonsProductsFloat+"&musicObjectTitle="+mp_musicObjectTitle+"&firstArtistName="+mp_firstArtistName;    
    new Ajax.Request(msgAction, {
      method: 'post',
      parameters: msgData, 
      onSuccess: function(mktplace){ 
		     var div = $(mp_DivId);
      	   div.innerHTML = mktplace.responseText;
      	   	visibilitytoggle();
      	 //	$('iTunesRowDiv').style.visibility = "visible";    	   
			 //  $('iTunesRowDiv').style.visibility = "hidden";
			    if (mp_musicObjectType != "PeoplePerson")
			    {
				   iTunesScript = document.createElement("script");
				   iTunesScript.setAttribute("type", "text/javascript");
				   iTunesScript.setAttribute("src",iTunesSearchScriptURL);
				   document.getElementsByTagName('head')[0].appendChild(iTunesScript);
				}		   		  	
      }
      });
  };




/*
Script Name: Javascript Cookie Script
Author: Public Domain, with some modifications
Script Source URI: http://techpatterns.com/downloads/javascript_cookies.php
Version 1.1.1
Last Update: 4 October 2007

Changes:
1.1.1 fixes a problem with Get_Cookie that did not correctly handle case
where cookie is initialized but it has no "=" and thus no value, the 
Get_Cookie function generates a NULL exception. This was pointed out by olivier, thanks

1.1.0 fixes a problem with Get_Cookie that did not correctly handle
cases where multiple cookies might test as the same, like: site1, site

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
*/

// this fixes an issue with the old method, ambiguous values 
// with this test document.cookie.indexOf( name + "=" );

// To use, simple do: Get_Cookie('cookie_name'); 
// replace cookie_name with the real cookie name, '' are required
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ) 
	{
		return null;
	}
}

/*
only the first 2 parameters are required, the cookie name, the cookie
value. Cookie time is in milliseconds, so the below expires will make the 
number you pass in the Set_Cookie function call the number of days the cookie
lasts, if you want it to be hours or minutes, just get rid of 24 and 60.

Generally you don't need to worry about domain, path or secure for most applications
so unless you need that, leave those parameters blank in the function call.
*/
function Set_Cookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	// if the expires variable is set, make the correct expires time, the
	// current script below will set it for x number of days, to make it
	// for hours, delete * 24, for minutes, delete * 60 * 24
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	//alert( 'today ' + today.toGMTString() );// this is for testing purpose only
	var expires_date = new Date( today.getTime() + (expires) );
	//alert('expires ' + expires_date.toGMTString());// this is for testing purposes only

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

