/***********************************************
*
**/
function GoToComp1(TabId)
{
	var aCompSel = $(TabId).getElementsByClassName('ComboComp1') ;
	
	var s_Val = $F(aCompSel[0]) ;
	
	// alert(s_Val) ;
	
	var s_Target = '' ;
	if(aFullAuditUrls[s_Val] == null)
	{
		if(aChart[s_Val] != null)
			s_Target = aChart[s_Val] ;
	}
	else
		s_Target = aFullAuditUrls[s_Val] ;
	
	// alert(s_Target) ;
	
	if(s_Target != '')
		document.location.href = s_Target ;
}

/***********************************************
*
**/
function InitCompetitors(TabId)
{
	var aCompDiv = $(TabId).getElementsByClassName('CompParam') ;
	
	// comp1 link
	var SpanComp1Link = document.createElement('span') ;
	Element.extend(SpanComp1Link);
	SpanComp1Link.innerHTML = '<a href="#" onclick="GoToComp1(\''+ TabId +'\'); return false"><img src="img/common/icons/external.gif" width="10" height="10" border="0" /></a>' ;
	SpanComp1Link.setStyle({margin:'0px 5px'}) ;
	aCompDiv[0].appendChild(SpanComp1Link) ;
	
	
	// comp1
	var SelComp1 = document.createElement('select') ;
	Element.extend(SelComp1);
	SelComp1.name = "comp1" ;
	SelComp1.addClassName("ComboComp1") ;
	SelComp1.addClassName("comp_combo") ;
	var iSelectedIndex ;
	aAuditUrls.each(function(AuditItem)
	{
		if(AuditItem.key == TabData[TabId].GetCompetitor1())
			iSelectedIndex = SelComp1.options.length ;
			
		var oDate = new Date();
		var sDate = '' ;
		aItemIdx = AuditItem.key.split('_');
		intTimeStamp = aItemIdx[2] ;
		var sLang = AuditLang.toLowerCase() ;
		if(H_ShortDateFormat[sLang] == null)
			sLang = 'fr';
		// H_ShortDateFormat is a global var
		sDate = '('+oDate.dateFormat(H_ShortDateFormat[sLang], sLang, intTimeStamp) + ')' ;
		/*if(AuditLang.toLowerCase() == 'fr')
			sDate = '('+oDate.dateFormat('d/m/Y', 'fr', intTimeStamp) + ')' ;
		else
			sDate = '('+oDate.dateFormat('m/d/Y', 'en', intTimeStamp) + ')' ;
		*/
		SelComp1.options[ SelComp1.options.length ] = new Option('audit '+sDate+': ' + AuditItem.value, AuditItem.key) ;
	} );
	
	aChart.each(function(ChartItem)
	{
		if(ChartItem.key == TabData[TabId].GetCompetitor1())
			iSelectedIndex = SelComp1.options.length ;
			
		aItemIdx = ChartItem.key.split('_');
		sRank = aItemIdx[1] ;
	
		SelComp1.options[ SelComp1.options.length ] = new Option(sRank + ': ' + ChartItem.value, ChartItem.key) ;
	} );
	SelComp1.selectedIndex = iSelectedIndex ;
	aCompDiv[0].appendChild(SelComp1) ;
	
	// vs
	var SpanVs = document.createElement('span') ;
	Element.extend(SpanVs);
	SpanVs.innerHTML = txt_VersusAbbr ;
	SpanVs.setStyle({margin:'0px 10px'}) ;
	aCompDiv[0].appendChild(SpanVs) ;
	
	// comp2
	var SelComp2 = document.createElement('select') ;
	Element.extend(SelComp2);
	SelComp2.name = "comp2" ;
	SelComp2.addClassName("ComboComp2") ;
	SelComp2.addClassName("comp_combo") ;
	
	aCompetitorSet.each(function(CompItem)
	{
		if(CompItem.key == TabData[TabId].GetCompetitor2())
			iSelectedIndex = SelComp2.options.length ;
			
		SelComp2.options[ SelComp2.options.length ] = new Option(CompItem.value, CompItem.key) ;
	} );
	
	aChart.each(function(item)
	{
		if(item.key == TabData[TabId].GetCompetitor2())
			iSelectedIndex = SelComp2.options.length ;
			
		aItemIdx = item.key.split('_');
		sRank = aItemIdx[1] ;
			
		if(item.key != 0)
			SelComp2.options[ SelComp2.options.length ] = new Option(sRank + ': ' + item.value, item.key) ;
	} );
	SelComp2.selectedIndex = iSelectedIndex ;
	aCompDiv[0].appendChild(SelComp2) ;
	
	// OK Btn
	var BtnOk = document.createElement('a');
	Element.extend(BtnOk);
	BtnOk.addClassName('bt_simple2') ;
	// BtnOk.addClassName('bt_small') ;
	BtnOk.setStyle({marginLeft:'10px', float: 'none', display: 'inline', padding: '1px 5px'}) ;
	BtnOk.onclick = UpdateCompetitor ;
	BtnOk.setAttribute('TabId', TabId) ;
	BtnOk.TabId = TabId ;
	BtnOk.innerHTML = txt_Ok ;
	aCompDiv[0].appendChild(BtnOk) ;
}

/***********************************************
*
**/
function UpdateCompetitor()
{
	var TabId = '';
	if(this.getAttribute('TabId'))	TabId = this.getAttribute('TabId') ;
	else if(this.TabId)				TabId = this.TabId ;
	
	var CompCombo1 = $(TabId).getElementsByClassName('ComboComp1') ;
	TabData[TabId].SetCompetitor1($F(CompCombo1[0])) ;
	
	var CompCombo2 = $(TabId).getElementsByClassName('ComboComp2') ;
	TabData[TabId].SetCompetitor2($F(CompCombo2[0])) ;
	
	UpdateCurrentTab();
}