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()				
	document.frames[0].location = "../../logoff.aspx?Redirect=1"
}

function FrameUnLoad()
{
	if (AllreadyLogOff==0)
	{
		CloseChild()			
	}
	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('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"	
}

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")

	//If current file is not saved in the current user path result => nothing append
	if (LocResult.search(UserPath) != -1)
	{
		//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()
	LocResult = LocResult.replace(".HTML", ".pdf")
	LocResult = LocResult.replace(".XLS", ".pdf")

	//If current file is not saved in the current user path result => nothing append
	if (LocResult.search(UserPath) != -1)
	{
		//Cl0se 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 IMD()
{
	window.open("http://www.imd.ch")
}

function WCC()
{
	window.open("http://www.imd.ch/research/centers/wcc/index.cfm")
}

function WCCOrder()
{
	window.open("https://www.imd.ch/research/centers/wcc/Order-WCC-Products.cfm?prog=")
}

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]
		
		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
	{
	}

	
	if (lstCountries.multiple==1)
	{		
		Countries = ''
	}
	else
	{
		Countries = lstCountries.value	
		if (Countries != '1' && Countries != '2' && Countries != '3' && Countries != '4' && Countries != '5' && Countries != '6' && Countries != '7' && Countries != '8' && Countries != '9' && Countries != '10' && Countries != '11')
		{
			Countries = ''
		}
	}
				
	if (Countries.length > 0)
	{
		if (Condition.search('No')==-1 )
		{
			top.frames['big'].frames['Main'].location = DestDir +  Condition + Countries + '.html'					
		}
		else
		{
			alert('Only Sample Criteria are available in Demo version.')		
		}
	}
	else
	{
		alert('Only WCC Predifined Groups are available in Demo version.')
	}
}

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	
	}
}