var CompCTID = "CompareCountries"
var CTAnalysis = "CountryAnalysis"
var Ranking = "Rankings"
var CTSummary = "CountrySummary"
var OwnConso = "OwnConso"
var myTypeWindow
var myExcelWindow
var UserPath
var LastReportID = -1
var UserGroupCaller
var AllreadyLogOff=0

var IndexLoc = top.location.toString()
IndexLoc = IndexLoc.replace("Index.htm", "")

function LogOff()
{
	AllreadyLogOff = 1	
	CloseChild()
	top.frames['big'].location = "../../logoff.aspx?Redirect=1"
}

function FrameUnLoad()
{
	if (AllreadyLogOff==0)
	{
		CloseChild()		
	
		bla = new String(top.frames['big'].location)			
		if (bla.search('.htm') == -1)
		{
			top.location = "../logoff.aspx?Redirect=0"
		}
	}
	AllreadyLogOff = 1	
}

function CloseChild()
{
	//Close the excel and change output format windows
	if (myExcelWindow && myExcelWindow.open && !myExcelWindow.closed) myExcelWindow.close();	
	if (myTypeWindow && myTypeWindow.open && !myTypeWindow.closed) myTypeWindow.close();
}		

function ChangeFrame(aLoc)
{
	top.frames['big'].frames['Main'].location = aLoc
}

function ChangeSelection(aButtonName, IsOwnConso)
{
	var aButton
	var aName
	var ImgName = new String(aButtonName)
	ImgName = ImgName.replace("Homes", "Home")
	ImgName = ImgName.replace("Adds", "Add")	
	ImgName = ImgName.replace("Searchs", "Search")		
	ImgName = ImgName + "Bleu.jpg"

	DeselectAllButtons()

	aButton = top.frames['big'].frames['Menu'].document.getElementById(aButtonName)
	aButton.src = "../Images/" + ImgName

	if (IsOwnConso == 1 )
	{
		UserGroupCaller = "CONSO"	
	}
	else
	{
		UserGroupCaller = "DATA"	
	}
}

function DeselectAllButtons()
{
	var myMenuFrame = top.frames['big'].frames['Menu']

	myMenuFrame.document.getElementById("Homes").src = "../Images/HomeGris.jpg"	
	myMenuFrame.document.getElementById("Country").src = "../Images/CountryGris.jpg"	
	myMenuFrame.document.getElementById("Criteria").src = "../Images/CriteriaGris.jpg"	
	myMenuFrame.document.getElementById("Conso").src = "../Images/ConsoGris.jpg"	
	myMenuFrame.document.getElementById("Adds").src = "../Images/AddGris.jpg"	
	myMenuFrame.document.getElementById("Searchs").src = "../Images/SearchGris.jpg"	
}

function GetExcel()
{
	//Get the Main frame content path
	var LocResult = new String(top.frames['big'].frames['Main'].location)
	LocResult = LocResult.toUpperCase()
	LocResult = LocResult.replace(".HTML", ".xls")
	LocResult = LocResult.replace(".PDF", ".xls")

	//Cl0se the excel window
	if (myExcelWindow && myExcelWindow.open && !myExcelWindow.closed) myExcelWindow.close();		
	//Reopen the excel window with the selected excel workbook
	myExcelWindow = window.open("../../GetExcel.aspx?XLS=" + LocResult, "Excel")
	//Set focus to the excel window
	myExcelWindow.document.focus()
}

function PDFArticleClick(aFileName)
{
	//Close the excel window
	if (myExcelWindow && myExcelWindow.open && !myExcelWindow.closed) myExcelWindow.close();		
	//Reopen the excel window with the selected excel workbook
	myExcelWindow = window.open(aFileName, "Excel")
	//Set focus to the excel window
	//myExcelWindow.document.focus()
}

function PDFClick(aFileName)
{
	//Close the excel window
	if (myExcelWindow && myExcelWindow.open && !myExcelWindow.closed) myExcelWindow.close();		
	//Reopen the excel window with the selected excel workbook
	myExcelWindow = window.open("../PDF/" + aFileName, "Excel")
	//Set focus to the excel window
	myExcelWindow.document.focus()
}

function GetPDF()
{
	//Get the Main frame content path
	var LocResult = new String(top.frames['big'].frames['Main'].location)
	LocResult = LocResult.toUpperCase()
		
	//Close the excel window
	if (myExcelWindow && myExcelWindow.open && !myExcelWindow.closed) myExcelWindow.close();				
	//Reopen the excel window with the selected excel workbook
	myExcelWindow = window.open("../../GetPDF.aspx?PDF=" + LocResult, "Excel")
	//Set focus to the excel window
	myExcelWindow.document.focus()
}

function GetPrint()
{
	//Get the Main frame content path
	var LocResult = new String(top.frames['big'].frames['Main'].location)
	LocResult = LocResult.toUpperCase()
		
	//If current file is not saved in the current user path result => nothing append	
	if (LocResult.search(UserPath) != -1)
	{		
		//Close the excel window
		if (myExcelWindow && myExcelWindow.open && !myExcelWindow.closed) myExcelWindow.close();				
		//Reopen the excel window with the selected excel workbook
		myExcelWindow = window.open("../../GetPrint.aspx?PRINT=" + LocResult, "Excel")
		//Set focus to the excel window
		myExcelWindow.document.focus()
	}
}

function Survey()
{
	window.open("https://applications.imd.ch/ViewsFlash/servlet/viewsflash?cmd=page&pollid=HEDIGER!WCY_Online_users")
}

function China()
{
	window.open("http://www.imd.ch/Learning-without-borders-China.cfm")
}

function IMD()
{
	window.open("http://www.imd.ch")
}

function WCC()
{
	window.open("http://www.imd.ch/research/centers/wcc/index.cfm")
}

function WCCActivities()
{
	window.open("http://www.imd.ch/research/centers/wcc/Special-Projects.cfm")
}
function WCCPartner()
{
	window.open("http://www.imd.ch/research/publications/wcy/Partner_institutes.cfm")
}
function NewRetriveValues(aCaller)
{
	UserGroupCaller = aCaller
	RetriveValues()
}

function RetriveValues()
{
	var Source, Level, Condition, Countries, lstCountries, DestDir
	var i
	
	if (UserGroupCaller == "DATA")
	{	
		Source = top.frames['big'].frames['Main'].document.forms[0]
		Level = Source.elements['txtLevel'].value
		
		if (Source.elements['txtCond'].value == "FROM LIST")
			Condition = Source.elements['lstCriteria'].value
		else
			Condition = Source.elements['txtCond'].value		
			
		DestDir = Source.elements['txtDest'].value
		lstCountries = Source.elements['lstCountries']
	}
	else
	{
		Source = top.frames['big'].frames['Main'].document.forms[0]
		Condition = Source.elements['lstCriteria'].value + "|" + Source.elements['txtTitle'].value
		DestDir = Source.elements['txtDest'].value		
		lstCountries = Source.elements['lstCountries']		
		Level = 0
	}
	
	if (lstCountries.multiple==1)
	{		
		Countries = ''
		for (i=0; i<lstCountries.length; i++)
		{
			if (lstCountries.options[i].selected == 1)
			{
				if (Countries.length > 0)
					Countries = Countries + "," + lstCountries.options[i].value 
				else
					Countries = Countries + lstCountries.options[i].value 
			}
		}
		
		if (Countries.length > 0)
		{
			Countries = "COUNTRY = " + Countries
		}		
	}
	else
	{
		Countries = lstCountries.value	
	}
		
	if (Countries.length > 0)
	{	
		if(Countries.length + Condition.length > 1975)
		{
			if (UserGroupCaller != "DATA")
			{
				Condition = Source.elements['txtTitle'].value
				Condition = Condition.substr(0, 50)				
				Condition = Source.elements['lstCriteria'].value + "|" + Condition
			}
		}

		top.frames['big'].frames['Main'].location = DestDir + '&Level=' + Level + '&Condition=' + Condition + '&Country=' + Countries
	}
}

function ManageGroups()
{
	UserGroupCaller = "DATA"
	top.frames['big'].frames['Main'].location = "UserGroups.aspx"
}

function ManageGroupsFromOwnConso()
{
	UserGroupCaller = "CONSO"	
	top.frames['big'].frames['Main'].location = "../" + CompCTID + "/UserGroups.aspx"
}

function ManageCritGroups()
{
	UserGroupCaller = "CONSO"	
	top.frames['big'].frames['Main'].location = "CritGroup.aspx"
}


function BackToAnalysis()
{
	if (UserGroupCaller == "DATA")
	{
		top.frames['big'].frames['Main'].location = "Index.aspx?XML=Structure.xml&Condition=OVERA&Level=0"
	}
	else
	{
		top.frames['big'].frames['Main'].location = "../" + OwnConso + "/Index.aspx"
	}		
}






function MapClick(aCond)
{
	var DestDir
	var Param
	
	if (aCond == 'Summary')
	{
		DestDir = 'CountrySummary'
		Param = ''
		top.frames['big'].frames['Main'].location = './' + DestDir + '/index.aspx' + Param	
	}
	else
	{
		DestDir = 'CompareCountries'
		
		if (aCond == "OVERA")
			Param = '?XML=Structure.xml&Condition=' + aCond + '&Level=0'		
		else
			Param = '?XML=Structure.xml&Condition=' + aCond + '&Level=1'
			
		top.frames['big'].frames['Main'].location = './' + DestDir + '/index.aspx' + Param	
	}
}