////////////////////////////////////////////////////////////
// Gadget IMS RADIO PLAYER V2 - Vista Widget Engine
// settings.js   
// ©2007 InfoMed Solutions (www.infomedsolutions.com)
////////////////////////////////////////////////////////////



var NumThemes = 100;
var currTheme = 1; 

function startup() 
{
    var currentSetting = System.Gadget.Settings.read("shortcutPath");
    if (currentSetting != "")
	envVar.innerText = currentSetting;	    
    var BackgroundTheme = System.Gadget.Settings.read("BackgroundTheme");
    if (BackgroundTheme != "")
		{
			bg.src = "images/bg" + BackgroundTheme + ".png";
			currTheme = BackgroundTheme;
			numSkin.value = currTheme;
		}
    System.Gadget.onSettingsClosing = SettingsClosing;
	displaySettings('radios');  
}

function setPrev()
{
    currTheme -= 1;
    if (currTheme <= 0) 
    currTheme = NumThemes;
	numSkin.value = currTheme;
    alert(currTheme);
    setTheme();
}

function setPrevten()
{
    currTheme -= 10;
    if (currTheme <= 0) 
    currTheme = NumThemes;
	numSkin.value = currTheme;
    alert(currTheme);
    setTheme();
}

function setNext()
{
    currTheme += 1;
    if (currTheme >= NumThemes)
    currTheme = 1;
	numSkin.value = currTheme;
    setTheme();
}

function setNexten()
{
    currTheme += 10;
    if (currTheme >= NumThemes)
    currTheme = 1;
	numSkin.value = currTheme;
    setTheme();
}

function setTheme()
{
         bg.src = "images/bg" + currTheme + ".png";
}

System.Gadget.onSettingsClosing = SettingsClosing;
         
function SettingsClosing(event) 
{
	if (event.closeAction == event.Action.commit) 
	{
      	BackgroundTheme = currTheme;
		System.Gadget.Settings.write ("BackgroundTheme", BackgroundTheme);
	}
	event.cancel = false;
}

function ajouter()
{
	document.getElementById('messageDiv').innerText = ""
	
	var nbRadios = 0;
	nbRadios = System.Gadget.Settings.read("nbRadios");
	if (nbRadios=="")
	{
		nbRadios==0;
	}
	
	// Récupération des valeurs :
	eNom = document.getElementById('lenom');
	eURL = document.getElementById('lurl');
	eImage = document.getElementById('limage');
	
	var ajoutOK = "";
	var fichier = "";
	var ext = "";
	
	// Ajout de la radio :
	if (eNom.value != "" && eURL.value!="" && eImage.value!="") 
	{
		fichier=eImage.value ;
		ext = fichier.substr(fichier.lastIndexOf(".")+1); 
		ext = ext.toLowerCase();
		
		if ((ext=="jpg") || (ext=="png") || (ext=="gif") || (ext=="jpeg") || (ext=="bmp"))
		{ 
			nbRadios += 1;
			System.Gadget.Settings.write("vNom"+nbRadios, eNom.value);
			System.Gadget.Settings.write("vURL"+nbRadios, eURL.value);
			System.Gadget.Settings.write("vImage"+nbRadios, eImage.value);
			ajoutOK = "ok";
		}
		else
		{
			ajoutOK = "PbFormat";
		}
	}
	else
	{
		ajoutOK="PbSaisie";
	}
	
	System.Gadget.Settings.write("nbRadios", nbRadios);
	
	// L'ajout est fait, on vide les champs :
	eNom.value=""
	eURL.value=""
	
	initStationList();
	
	switch( ajoutOK ) 
	{
		case 'ok' : document.getElementById('messageDiv').innerText = "Radio ajoutée / Station added"; break;
		case 'PbFormat' : document.getElementById('messageDiv').innerText ="Format d'image non supporté / Unsupported image file format" ; break;
		case 'PbSaisie' : document.getElementById('messageDiv').innerText = "Merci de renseignez tous les champs / Please fill all fields"; break;
	}

}

// Affiche le div sélectionné
function displaySettings(divId)
{
	document.getElementById('radios').style.visibility = "hidden";
	document.getElementById('themes').style.visibility = "hidden";
	document.getElementById('ims').style.visibility = "hidden";
	
	switch( divId ) 
	{
		case 'radios' : radiosLink.focus(); radios.style.visibility = "visible"; break;
		case 'themes' : themesLink.focus(); themes.style.visibility = "visible"; break;
		case 'ims' : ims.style.visibility = "visible"; break;
	}
}


