// ************************************************************
// Notify
// ************************************************************

// Starts the monitoring thread - scripts.js
document.onmousemove = GetMousePosition;

var NotifyDiv = null;
var NotifyTimeout = -1;
var NotifyOffsetX = -150;
var NotifyOffsetY = 20;

function CreateNotify(text)
{
	// Clears any pending timeouts
	if(NotifyTimeout!=-1)
	{
		window.clearTimeout(NotifyTimeout);
	}

	if(!NotifyDiv)
	{
		// Creates a div
		NotifyDiv = document.createElement('div');
		//NotifyDiv.className = 'loadingNotify'; //class that contains div style
		NotifyDiv.style.position = 'Absolute';
		NotifyDiv.style.fontWeight = 'bold';
		NotifyDiv.style.background = '#FFF';
		NotifyDiv.style.padding = '5px';
		NotifyDiv.style.margin = '10px';
		NotifyDiv.style.border = '2px solid #F00';
		
		document.body.appendChild(NotifyDiv);
	}

	// Updates the position
	NotifyDiv.style.left = currentMouseX + loginNotifyOffsetX + 'px';
	NotifyDiv.style.top  = currentMouseY + loginNotifyOffsetY + 'px';
	
	// Updates the text	
	NotifyDiv.innerHTML = text;
	
	// Schedules the notification destruction
	NotifyTimeout = window.setTimeout('DestroyNotify()', 2000);
}

function DestroyNotify()
{
	// Destroys the div and resets the parameters
	document.body.removeChild(NotifyDiv);
	NotifyDiv = null;
	NotifyTimeout = -1;
}

//show hide
function MM_findObj(n, d) { //v4.01 
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { 
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} 
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; 
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); 
if(!x && d.getElementById) x=d.getElementById(n); return x; 
} 

function showHideLayer(obj) { //v1.0
var v,obj; 
if ((obj=MM_findObj(obj))!=null) { 
	v=obj.style.display;

	if (v == 'none') {
		obj.style.display = '';
	}
	else {
		obj.style.display = 'none';
	}
 } 
}

function showHideItems(objId, imgId, mp3Id)
{ 
	var obj = document.getElementById(objId);
	var img = document.getElementById(imgId);
	var mp3 = document.getElementById(mp3Id);
	
	if(obj != null && img != null)
	{
		if(obj.style.display == 'block') 
		{
			obj.style.display = 'none';
			img.src = "../image/bt_expand.gif";
			if(mp3 != null) mp3.style.display = 'block';
		} 
		else 
		{
			obj.style.display = 'block';
			img.src = "../image/bt_retract.gif";
			if(mp3 != null) mp3.style.display = 'none';
		}
	}
}
function SetMenu(sender)
{
	if(sender)
	{
		var channel = sender.getAttribute("channel");
		HideAll();
		sender.className = "selectedPlaylistMenu";
		currentMenu = sender.id;
		
		if(sender.id == "MenuHome")
		{
			document.getElementById("imgMenuHomeArrow").src = "../image/arrow_model1-2.gif";
		}
		switch(sender.id)
		{
			case "MenuHome":
				getAjaxContentNoCache("menuContent", "ajax/genericAjax.aspx?view=PlaylistsMenuHomeView&channel=" + channel, true);
				break;
			case "MenuCategories":
				getAjaxContentNoCache("menuContent", "ajax/genericAjax.aspx?view=PlaylistsMenuCategoriesView&channel=" + channel + "&p1=0", true);
				break;
			case "MenuPlaylistsGenres":
				getAjaxContentNoCache("menuContent", "ajax/genericAjax.aspx?view=PlaylistsMenuGenresView&channel=" + channel + "&p1=0", true);
				break;
			case "MenuPlaylistsArtists":
				getAjaxContentNoCache("menuContent", "ajax/genericAjax.aspx?view=PlaylistsMenuArtistsView&channel=" + channel + "&p1=@", true);
				break;
		}
	}
}

function GetMenuItems()
{
	var output = [document.getElementById("MenuHome"), document.getElementById("MenuCategories"),
	  document.getElementById("MenuPlaylistsGenres"), document.getElementById("MenuPlaylistsArtists")];
	 
	return output;
}

//Checks or unchecks a collection of checkboxes
function checkAll(checkBoxes, checkAll)
{
	if(checkBoxes != null)
	{
		if(checkBoxes.length != null)
		{
			for(var i = 0; i < checkBoxes.length; i++)
			{
				checkBoxes[i].checked = checkAll;
			}
		}
		else
		{
			checkBoxes.checked = checkAll;
		}
	}
}

//Returns an array with all values from checked checkboxes
function getCheckBoxesValues(checkBoxes)
{
	var values = new Array();
	
	if(checkBoxes != null)
	{
		if(checkBoxes.length != null)
		{
			for(var i = 0; i < checkBoxes.length; i++)
			{
				if(checkBoxes[i].checked)
					values.push(checkBoxes[i].value);
			}
		}
		else
		{
			if(checkBoxes.checked)
			{
				values.push(checkBoxes.value);
			}
		}
	}	
	return (values);
}

function SearchFocus()
{
	try
	{
		document.getElementById("keyword").focus();
	}
	catch(e)
	{
	}
}

function getRadioValue(obj)
{
	for(i = 0; i < obj.length; i++)
	{
		if(obj[i].checked)
		{
			return obj[i].value;
		}
	}
	return null;
}

function GetFilterType(obj)
{
	if(obj)
	{
		return obj.split(',')[0];
	}
}

function GetFilterValue(obj)
{
	if(obj)
	{
		return obj.split(',')[1];
	}	
}

function ValidateMyMusics()
{
	if(document.getElementById("dropGenres").value == -1)
	{
		alert("Selecione uma opção de filtro válida");
		return false;
	}
	return true;
}

function openWindow(url, name, options)
{
	if(typeof(name) == "undefined")
		name = "";
		
	if(typeof(options) == "undefined")
		options = "";
	
	window.open(url, name, options);
}


function GetBeginEndPage(currentPage, numPagesDisplayed, numberOfPages, beginEnd)
{
	var begin = 0;
	
	// Define primeiro link, o algoritmo procura deixar a pagina atual no meio
	begin = currentPage - parseInt(numPagesDisplayed / 2);
	
	if(begin < 0)
		begin = 0;
		
	var end = begin + numPagesDisplayed - 1;

	if(end > (numberOfPages - 1))
	{
		end = numberOfPages - 1;

		if(begin > 0)
		{
			begin = end - numPagesDisplayed + 1;

			if(begin < 0)
				begin = 0;
		}
	}
	
	beginEnd.begin = begin;
	beginEnd.end = end;
}

/****************************************************/
/* Function for locating the current mouse position */
/* Must receive an event to work in Mozilla         */
/****************************************************/
var currentMouseX;
var currentMouseY;
function GetMousePosition(e)
{
	var nn6 = document.getElementById && !document.all;
		
	var clientX = document.all ? event.clientX : e.clientX;
	var clientY = document.all ? event.clientY : e.clientY;

	var scrollLeft = nn6 ? window.pageXOffset : document.documentElement.scrollLeft;
	var scrollTop = nn6 ? window.pageYOffset : document.documentElement.scrollTop;	

	currentMouseX = clientX + scrollLeft;
	currentMouseY = clientY + scrollTop;
}

function ShowHideDivMusicDetails(id, musicDetails)
{
	var div = document.getElementById("divMusicDetails");
	
	var display = div.style.display;
	
	if(display == "none" || display == "")
	{
		CreateDivMusicDetails(div, musicDetails);
		
		div.style.position = 'absolute';
		div.style.left = '50px';	
		div.style.top = loginNotifyY + 'px';
		
		div.style.display = 'block';
	}
	else
	{
		div.style.display = 'none';
	}

}

function CreateDivMusicDetails(div, musicDetails)
{
	var arrayDetails = musicDetails.split(";");
	
	var html = '<div class="infos">';
	
	html += '<table border="0">';
	html += '<tr>';
	html += '<th colspan="2"><b>' + arrayDetails[0] + '</b></th>';
	html += '</tr>';
	html += '<tr>';
	html += '<th><b>Artista:</b></th>';
	html += '<td>' + arrayDetails[1] + '</td>';
	html += '</tr>';
	html += '<tr>';
	html += '<th><b>Autores:</b></th>';
	html += '<td>'+arrayDetails[2]+ '</td>';
	html += '</tr>';
	//html += '<tr>';
	//html += '<th></th>';
	//html += '<td>Compositor 2</td>';
	//html += '</tr>';
	html += '<tr>';
	html += '<th><b>Album:</b></th>';
	html += '<td>' + arrayDetails[3] + '</td>';
	html += '</tr>';
	html += '<tr>';
	html += '<th><b>Gravadora:</b></th>';
	html += '<td>' + arrayDetails[4] + '</td>';
	html += '</tr>';
	html += '<tr>';
	html += '<th><b>Ano:</b></th>';
	html += '<td>' + arrayDetails[5] + '</td>';
	html += '</tr>';
	html += '</table>';
	
	html += '</div>';
	
	div.innerHTML = html;
}

//document.onmousemove = GetMousePosition;

var loginNotifyTimeout = -1;
var loginNotifyOffsetX = -60;
var loginNotifyOffsetY = -60;
var loginNotifyX = 0;
var loginNotifyY = 0;


function PositionLoginNotify(e)
{
	var nn6 = document.getElementById && !document.all;

	var clientX = document.all ? event.clientX : e.clientX;
	var clientY = document.all ? event.clientY : e.clientY;

	var scrollLeft = nn6 ? window.pageXOffset : document.documentElement.scrollLeft;
	var scrollTop = nn6 ? window.pageYOffset : document.documentElement.scrollTop;

	loginNotifyX = clientX + scrollLeft + loginNotifyOffsetX;
	loginNotifyY = clientY + scrollTop + loginNotifyOffsetY;
	
	if(loginNotifyX<0) loginNotifyX = 0;
	if(loginNotifyY<0) loginNotifyY = 0;

	return(true);
}

function PermiteNumeros()
{
  var tecla = window.event.keyCode;
  tecla     = String.fromCharCode(tecla);
  if(!((tecla >= "0") && (tecla <= "9")))
  {
    window.event.keyCode = 0;
  }
}


/*For pop-up email*/
function validateName(obj)
{
	name = document.getElementById(obj).value;
	if (name == "" )
	{
		CreateNotify("Preencha todos os campos 'Nome' corretamente");
		return false;
	}
	return true;
}


function validateEmail(obj)
{

	emailAdress = document.getElementById(obj).value;
	
	if (emailAdress == "")
	{
		CreateNotify("Preencha todos os campos 'Email' corretamente");
		return false;
	}
	// { } ( ) < > [ ] | \ /
	if ((emailAdress.indexOf("{")>=0) || (emailAdress.indexOf("}")>=0) || (emailAdress.indexOf("(")>=0)
		|| (emailAdress.indexOf(")")>=0) || (emailAdress.indexOf("<")>=0) || (emailAdress.indexOf(">")>=0)
		|| (emailAdress.indexOf("[")>=0) || (emailAdress.indexOf("]")>=0) || (emailAdress.indexOf("|")>=0)
		|| (emailAdress.indexOf("\"")>=0) || (emailAdress.indexOf("/")>=0) )
	{
		CreateNotify("Preencha todos os campos 'Email' corretamente");
		return false;
	}
	// & * $ % ? ! ^ ~ ` ' "
	if ((emailAdress.indexOf("&")>=0) || (emailAdress.indexOf("*")>=0) || (emailAdress.indexOf("$")>=0) || (emailAdress.indexOf("%")>=0)
	|| (emailAdress.indexOf("?")>=0) || (emailAdress.indexOf("!")>=0) || (emailAdress.indexOf("^")>=0) || (emailAdress.indexOf("~")>=0)
	|| (emailAdress.indexOf("`")>=0) || (emailAdress.indexOf("'")>=0) )
	{
		CreateNotify("Preencha todos os campos 'Email' corretamente");
		return false;
	}
		// , ; : = #
	if ((emailAdress.indexOf(",")>=0) || (emailAdress.indexOf(";")>=0) || (emailAdress.indexOf(":")>=0) || (emailAdress.indexOf("=")>=0)
	|| (emailAdress.indexOf("#")>=0) )
	{
		CreateNotify("Preencha todos os campos 'Email' corretamente");
		return false;
	}
	// procura se existe apenas um @
	if ( (emailAdress.indexOf("@") < 0) || (emailAdress.indexOf("@") != emailAdress.lastIndexOf("@")) )
	{
		CreateNotify("Preencha todos os campos 'Email' corretamente");
		return false;
	}
	// verifica se tem pelo menos um ponto após o @
	if (emailAdress.lastIndexOf(".") < emailAdress.indexOf("@"))
	{
		CreateNotify("Preencha todos os campos 'Email' corretamente");
		return false;
	}
	return true;
}

function sendEmail(i)
{
		var objName;
		var objEmail;
		for (var count = 0; count < i; count++)
		{
			objName = "name" + count;			
			objEmail = "email" + count;
			if(!validateName(objName))
			{
				CreateNotify("Preencha todos os campos 'Nome' corretamente");
				return false;
			}
			else if(!validateEmail(objEmail)) 
			{
				
				CreateNotify("Preencha todos os campos 'Email' corretamente");
				return false;
			}
		}
		document.forms["frmPop"].submit();

}

function closePopup(url)
{
	window.opener.location.href = url + "&action=account";
	window.close();
}



function AbrirPopup(url)
{
	window.open(url,"Cartão","width=730, height=700,resizable = no,scrollbars = no, status = yes");	
}


function AutoRefresh()
{
	tempo = 30000
	setTimeout("javascript:getAjaxContentNoCache('ContentDestaque','ajax/genericAjax.aspx?view=MyDestaqueView&p1=0&p2=3&channel=24',true);getAjaxContentNoCache('DestaqueDetalhes','ajax/genericAjax.aspx?view=ArtistNullView&p1=0&channel=24',true);AutoRefresh();",tempo)	
}





