var backPath="../../../../../";
var functionsPath=backPath+"html/common/static/functions/";
var commonPath=backPath+"html/common/static/common/";
var imagePath=commonPath+"img/";

function languagePath(language){
	return backPath+"html/"+language+"/";
}
function functionLanguagePath(language){
	return languagePath(language)+"functions/";
}
function getPath(loc)
{
	if(loc.indexOf("situations") > -1)
		return "situations";
	if(loc.indexOf("functions") > -1)
		return "functions";
	if(loc.indexOf("story") > -1)
		return "story";
	return "situations";
}

function getType(loc)
{
	if(loc.indexOf("toon") > -1)
		return "toon";
	return "";
}

function goToSelection()
{
	document.location.href = "../path/" + getPath(location.search) + getType(location.href) + ".html";
}

function goHelp(jumps)
{
	
	var win;
	win = window.open(jumps + "functions/help/help.html","_help","toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=0,width=504,height=540,left=100,top=100");
	win.focus();

}

function goToEx()
{
	document.location.href = lnk;
}

function openVisualVocabulary(path)
{
	var win;
	win = window.open(path+"vocvis.htm","_vocvis","toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=0,width=420,height=476,left=100,top=100");
	win.focus();
}

function openReadings()
{
	var win;
	win = window.open("approfondimenti.htm","_readings","toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=0,width=500,height=460,left=100,top=100");
	win.focus();
}

function openMusic(theFile, theLevel)
{
	var win;
	win = window.open(functionsPath+"music/ap_"+theFile+"_"+theLevel+".htm","_readings","toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=0,width=460,height=420,left=100,top=100");
	win.focus();
}


function openTour(lang)
{
	var win;
	win = window.open("visita_guidata/GT_1.htm","_visita","toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=0,width=800,height=600,left=100,top=100");
	win.focus();
}


function openURL(theurl)
{
	var win;
	win = window.open(theurl,"_visita","toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=0,width=400,height=420,left=100,top=100");
	win.focus();
}

function openAutomatic()
{
	var win;
	win = window.open("../../../../../dizionario_auto/dizionario.htm","_glossario","toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=0,width=580,height=420,left=100,top=100");
	win.focus();
}

function openCorrelations(fileName)
{
	var win;
	win = window.open(functionsPath+"correlations/"+fileName+".htm" ,"_cef","toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=0,width=680,height=400,left=100,top=100");
	win.focus();
}

function gotoHelp(language)
{
	
	var win;
	win = window.open(functionLanguagePath(language)+ "help/help.html","_help","toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=0,width=504,height=540,left=100,top=100");
	win.focus();

}

function openCEF()
{
	var win;
	win = window.open("../../../common/static/functions/correlations/cef.htm","_cef","toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=0,width=680,height=400,left=100,top=100");
	win.focus();
}


function openGrammar(language)
{
	var win;
	win = window.open(functionLanguagePath(language)+"grammar/grammar.htm","_grammar","toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=0,width=650,height=530,left=100,top=100");
	win.focus();
}

function openPhonetics(language)
{
	var win;
	win = window.open(functionLanguagePath(language)+"phonetic/alfabeto/alfabeto.html","_phonetics","toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=0,width=520,height=470,left=100,top=100");
	win.focus();
}

function openGlossary(language)
{
	var win;
	win = window.open(functionLanguagePath(language)+"glossary/index.htm","_glossario","toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=0,width=520,height=420,left=100,top=100");
	win.focus();
}

function openPhraseologic(language)
{
	var win;
	win = window.open(functionLanguagePath(language)+"phraseologic/phraseologic.html","_dizFras","toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=0,width=740,height=420,left=100,top=100");
	win.focus();
}

function openSwf(name, level)
{
	var win;
	win = window.open(backPath+"html/common/static/common/l" + level + "/snd/" + name,"_flash","toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=0,width=180,height=20,left=100,top=100");
	win.focus();
}
function openUnitSwf(name, level)
{
	var win;
	win = window.open(name,"_flash","toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=0,width=180,height=20,left=100,top=100");
	win.focus();
}


function openGames(language)
{
	
	var win;
	win = window.open(functionLanguagePath(language)+"games/htm/giochi.htm","_game","toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=0,width=504,height=540,left=100,top=100");
	win.focus();

}

/*
function toggleVisible(objId)
{
	var obj;
	obj = eval("document." + objId);
	alert(obj)

	obj = document.getElementById(objId);

	if(obj != null && obj != undefined)
	{
		if(obj.style.display == "" || obj.style.display == "none")
			obj.style.display = "block";
		else
			obj.style.display = "none";
		
		return;
	}
	//document.getElementbyid
	if(obj.style.visibility == "" || obj.style.visibility == "hidden")
		obj.style.visibility = "visible";
	else
		obj.style.visibility = "hidden";
}
*/
function toggleButton(btn)
{
	var src; 
	var ext; 
	src = btn.src.substring(btn.src.length - 8, btn.src.length);
	if(src.indexOf(".gif") > 0)
		ext = "gif";
	if(src.indexOf(".jpg") > 0)
		ext = "jpg";
	if(src == ("_off." + ext))
		src = btn.src.substring(0, btn.src.length - 8) + "." + ext;
	else
		src = btn.src.substring(0, btn.src.length - 4) + "_off." + ext;

	btn.src = src;
}

function switchButtonTo(btn, state)
{
	var src = btn.src.substring(btn.src.length - 8, btn.src.length);
/*
	alert(btn.src.substring(btn.src.length - 8, btn.src.length));
	alert(btn.src.substring(0, btn.src.length - 8) + ".gif");
	alert(btn.src.substring(0, btn.src.length - 4) + "_off.gif");
*/
	if(state == "on")
	{
		if(src == "_off.gif")
			src = btn.src.substring(0, btn.src.length - 8) + ".gif";
		else
			src = btn.src;
	}
	else if(state == "off")
	{
		if(src == "_off.gif")
			src = btn.src;
		else
			src = btn.src.substring(0, btn.src.length - 4) + "_off.gif";
	}
	btn.src = src;
}

function getFlash()
{
	var lnk;
	var win;
	lnk = "http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash&Lang=Italian"

	win = window.open(lnk,"_flash","toolbar=1,location=1,directories=0,menuBar=1,scrollbars=1,resizable=1,width=650,height=470,left=100,top=100");
	win.focus();
}

function launchPluginWizard()
{
	var win;
    win = window.open("http://www.javasonics.com/plugins/wizard.html", "_javasonics","toolbar=1,location=0,directories=0,menuBar=0,scrollbars=1,resizable=0,width=400,height=400,left=100,top=100");
    win.focus();
}
		
function toggleVisible(szDivID) // 1 visible, 0 hidden
{
    if(document.layers)	   //NN4+
    {
    	if(document.layers[szDivID].visibility == "hide" || document.layers[szDivID].visibility == "")
    		document.layers[szDivID].visibility = "inherit";
    	else
    		document.layers[szDivID].visibility = "hide";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.style.visibility = (obj.style.visibility == "" || obj.style.visibility == "hidden") ? "visible" : "hidden";
    }
        else if(document.all)	// IE 4
    {
        document.all[szDivID].style.visibility = (document.all[szDivID].style.visibility == "hidden" || document.all[szDivID].style.visibility == "") ? "visible" : "hidden";
    }     
}


function gotoLevelSettings(language, style){
	document.location=backPath+"html/"+language+"/settings.html";
}

function gotoStyleSettings(language){
	document.location=backPath+"html/"+language+"/settings.html";
}

function gotoPath(language, style, level, path){
	document.location=backPath+"html/"+language+"/"+style+"/"+"l"+level+"/"+path+".html";
}

function gotoLanguageSettings(language){
	document.location=backPath+"html/"+language+"/lang.html";
}


