//CONTROLLO SE NUMERO CON ALERT/////////////////////////////////////////////////////////////
function checkIsNaN(num, msg)
{
	var charTemp = '';
	var	icount;
	var valueTmp = num.value;
	
	for (icount = 0; icount < valueTmp.length; icount++)
	{
		if ((valueTmp.charAt(icount) != '.') && (valueTmp.charAt(icount) != ','))
		{
			charTemp += valueTmp.charAt(icount);	
		}
	}
	
	if (isNaN(charTemp))
	{
		window.alert('Il valore inserito nel campo "' + msg + '" deve essere un numero');
		num.focus();
	}
}

//VERIFICA CAMPI OBBLIGATORI IN MODULI CON UN SOLO PULSANTE SUBMIT////////////////////

function controlloCampi(nomeform, testo, valore)  
{
	if (nomeform.value == valore)
	{
		window.alert('Attenzione il campo "'+ testo +'" è obbligatorio');
		nomeform.focus();
		return false;
	}
	return true;
}
//////////////////////////////////////////////////////////////////////////////////////


//VERIFICA CAMPI OBBLIGATORI IN MODULI CON PIU' BUTTONS///////////////////////////////

function controlloCampiButton(nomeform, testo, nomeformSubmit, formAzione)   
{
	nomeformSubmit.azione.value = formAzione
	if (nomeform.value == '')
	{
		window.alert('Attenzione il campo "'+ testo +'" è obbligatorio');
		return false;
	}
	nomeformSubmit.submit();
}
//////////////////////////////////////////////////////////////////////////////////////


//VERIFICA FORMATO E-MAIL/////////////////////////////////////////////////////////////

//'obbligatorio' è un valore booleano che indica se il cap è obbligatorio

function controlloEmail(nomeform, obbligatorio) 
{
	var sEmail= nomeform.value
	
	if (obbligatorio == true && sEmail.length==0)
	{
			alert ('Attenzione il campo "E-mail" è obbligatorio');
			nomeform.focus();
			return false;
	
	}
	
	if ((sEmail.indexOf("@")== -1 || sEmail.indexOf(".")== -1) && sEmail != "") 
	{
		window.alert ('Il campo "E-mail" è stato compilato in modo errato');
		nomeform.focus();
		return false;
						
	}
	return true;
}
//////////////////////////////////////////////////////////////////////////////////////


//VERIFICA FORMATO CAP/////////////////////////////////////////////////////////////

//'obbligatorio' è un valore booleano che indica se il cap è obbligatorio

function controlloCap(nomeform, obbligatorio) 
{
	var sCap= nomeform.value
	
	if (obbligatorio == true && sCap.length==0)
	{
			alert ('Attenzione il campo "Cap" è obbligatorio');
			nomeform.focus();
			return false;
	
	}
	
	if ((sCap.length > 0 && sCap.length <5) || isNaN(sCap))
		{
			alert ('Il campo "Cap" è stato compilato in modo errato');
			nomeform.focus();
			return false;
		}
	return true;
}
//////////////////////////////////////////////////////////////////////////////////////


//CONFERMA CANCELLAZIONE DA FORM//////////////////////////////////////////////////////

function controlloCancellazione(nomeform, testo, nomeformSubmit, formAzione) 
{
	nomeformSubmit.azione.value = formAzione
	if (confirm('Attenzione hai scelto di cancellare "'+ testo +'"'))
	{
		nomeformSubmit.submit();
	}
}
//////////////////////////////////////////////////////////////////////////////////////


//CONFERMA CANCELLAZIONE DA BUTTON////////////////////////////////////////////////////

function controlloCancButton(actionRedirect, testo)
{
	if (confirm('Attenzione hai scelto di cancellare "'+ testo +'"'))
	{
		document.location.href = actionRedirect;
	}
}
//////////////////////////////////////////////////////////////////////////////////////


//ROLLOVER SULLE RIGHE ON CHECKBOX////////////////////////////////////////////////////

function changeColor(Rows) 
{
	if (Rows.checked)
	{
		while (Rows.tagName != 'TR')
		{
			Rows = Rows.parentNode;
		}
	Rows.className = 'H';
	}
	else
	{
		while (Rows.tagName != 'TR')
		{
			Rows = Rows.parentNode;
		}
		Rows.className = "";
	}
}
//////////////////////////////////////////////////////////////////////////////////////


//ROLLOVER SULLE RIGHE ON MOUSEOVER///////////////////////////////////////////////////

function changeColor1(Rows, set) 
{
				
	if ((set == 1) || (set == 3))
	{
		while (Rows.tagName != 'TR')
		{
			Rows = Rows.parentNode;
		}
		Rows.className = 'H';
	}
	else if (set == 2)
	{
		while (Rows.tagName != 'TR')
		{
			Rows = Rows.parentNode;
		}
		Rows.className = "";
	}
}

//////////////////////////////////////////////////////////////////////////////////////



//FUZIONE  CHE INSERISCE I TAG HTML IN UN CAMPO DI TESTO /////////////////////////
//per gli URL --> code = 'URL'
//per le e-mail --> code = '@'
//per il tag <BR> --> code = 'BR'
//per le immagini --> code = 'IMG'
//per il tag <B> ----> code = 'B'

//Per il TAG <FONT> si utilizza la funzione AddColorCode()
function AddColorCode(code, sForm) {
	sString = '<font color="' + code + '">'
	formatText(sForm, sString, '</font>');	
}

// Per gli altri TAG
function AddCode(code, sForm) {

	//Per i link
	if (code == "URL") {
		insertText = prompt("Inserisci il testo del collegamento:", "");
							
			if ((insertText != null) && (insertText != "") && (code == "URL")){
				insertCode = prompt("Inserisci l'indirizzo del sito:", "http://");
									
					if ((insertCode != null) && (insertCode != "") && (insertCode != "http://")){
						if (confirm("Il link è esterno?")){					
							sString= '<a href="' + insertCode + '" target="_blank">' + insertText + '</a>';
						}
						else {
							sString= '<a href="' + insertCode + '">' + insertText + '</a>';
						}
						formatText(sForm, '', sString);
					}
			}
	}
	
	//Per le e-mail
	if (code == "@") {
		insertCode = prompt("Inserisci l' e-mail:", "");
			
		if ((insertCode != null) && (insertCode != "")){					
			sString = '<a href="mailto:' + insertCode + '">' + insertCode + '</a>';
			formatText(sForm, '', sString);
		}
		
	}
	
	//Per il TAG <BR>
	if ((code == "BR") || (code == 13)) {
		formatText(sForm, '', '<br>');	
	}

	//Per il TAG <IMG>
	if (code == "IMG") {	
		insertCode = prompt("Inserisci il nome della foto con l'estensione:", "");
					
			if ((insertCode != null) && (insertCode != "")){					
				sString = '<img src="'+insertCode+'" align="left" border="0">';
				formatText(sForm, '', sString);
			}			
	}
	
	//Per inserire una foto di un prodotto
	if (code == "PRO") {	
		insertCode = prompt("Inserisci il nome della foto del prodotto con l'estensione:", "");
					
			if ((insertCode != null) && (insertCode != "")){					
				sString = '<img src="http://www.kasatua.com/visualizzazione/immagini/'+insertCode+'" align="left" border="0">';
				formatText(sForm, '', sString);
			}			
	}
	
	//Per il TAG <B>
	if (code == "B") {
		formatText(sForm, '<b>', '</b>');	
	}
	
	//Per inserire la barra nelle Newsletter
	if (code == "BARRA") {	
		sString = '<br><br><br><img src="http://www.kasatua.com/images/barra_news.gif" align="left" border="0"><br><br>';
		formatText(sForm, '', sString);
	}			
		
}

//inserisce i tags specificati all'inizio e alla fine del testo selezionato
function formatText(textEl, tagstart, tagend) {
	if (textEl.createTextRange && textEl.caretPos) {
	var caretPos = textEl.caretPos;
	caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? tagstart + textE1 + tagend : tagstart + textE1 + tagend;
	textEl.focus();		
	}
}

//ottiene la posizione di una porzione di testo selezionato
function getActiveText(textEl) {
	if (textEl.createTextRange)
	textEl.caretPos = document.selection.createRange().duplicate();
	textE1 = (document.all) ? document.selection.createRange().text : document.getSelection();
}

//mostra la playlist
var temporizza = 0;
function PlayList(url) {
	
	clearTimeout(temporizza); 
				
	if (window.XMLHttpRequest) {
		http_request1 = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		http_request1 = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		alert("Attenzione si è verificato un problema con l\' oggetto XMLHTTP!");
		return false;
	}
	
	http_request1.open('GET', url, true);

	http_request1.setRequestHeader("Content-Type", "text/plain; charset=ISO-8859-1");
	http_request1.setRequestHeader("Charset","ISO-8859-1");
	http_request1.setRequestHeader("Encoding","ISO-8859-1");

	http_request1.send(null);
	
	http_request1.onreadystatechange = function() {
		
		if (http_request1.readyState == 4){
	   
        	if (http_request1.status == 200){
					
				if(http_request1.responseXML){
						
					var items = http_request1.responseXML.getElementsByTagName("track");				
					
					var photo = "tmp/OnAir.jpg?q=" + Math.floor(Math.random()*10000);
					
					document.getElementById("playlist10").src = photo;
					
					if (document.getElementById("playlist0"))						
						document.getElementById("playlist0").src = photo;
					
					
					for (icount = 0; icount < 10; icount++)	{
						
						var title = items[icount].getElementsByTagName("title").item(0).firstChild.data;
						var annotation = items[icount].getElementsByTagName("annotation").item(0).firstChild.data;
												
						if (icount == 0){
							document.getElementById("title10").innerHTML = title; 
							document.getElementById("annotation10").innerHTML = annotation;								
						}	
												
						if (document.getElementById("title" + icount)) 					
							document.getElementById("title" + icount).innerHTML = title; 
						
						if (document.getElementById("annotation" + icount)) 
							document.getElementById("annotation" + icount).innerHTML = annotation; 												
					}	
				}
			}	
		}		
	
	};	
	
	temporizza = setTimeout('PlayList("playlist.asp")',10000);
}
			
//////////////////////////////////////////////////////////////////////////////////