
// ad_popup
function openAd1()
{
url="page.aspx?p=ad_popup";
url="ad_popup.rha";
if(document.referrer=='')
	open(url, "ad1", "width=274,height=402,scrollbars=no,resizable=no" );
}



// ==========================================
//  COMPANIES
// ==========================================


var invit = " Search company...";
//var ask =   " Please enter a query";
var ask =   " Enter a query";


// HISTO RECO/PRICE POPUP

function openRecoHist(ric){
	window.open("getRecoHisto.aspx?ric="+ric,"Recommendation","width=430,height=150,scrollbar=yes,resizable=yes");
}

// GOTO SECTOR VIEW

function gotoSectorView(sector){
	//var d = new Date();
	//var year = d.getFullYear()
	//var defaultView = "overview";
	document.location = "sectorview.rha?sector="+escape(sector);

}
// DISCLAIMER POPUP

function openDisclosures(lang,field,value,size)
{ 
	var xpath="";
	var s="";

	if(lang!="fr")
		lang="en";
	if(field!="")
		xpath = "&comp=xpath:/disclosures/company[@" + field + "=\"" + escape(value) + "\"]";
	switch(size)
	{
		case "small":
			s = "width=500,height=200,";break;
		case "medium":		
		default:
			s = "width=700,height=500,";
	}
	url="disclosures.rha?lang="+lang+xpath;
	open(url, "disclosures"+size, s+"scrollbars=yes,resizable=yes" );
}

function openCB(isin)
{
    //url="page.aspx?p=cb_details&c=cb_details{isin=" + isin+ "}";
    url="cb_details.rha?isin=" + isin;
    document.location = url;
};

function openCompany(page,ric)
{
    //url="page.aspx?p=" + page+ "&c=" + page+ "{ric=" + ric + "}&c=comppub{company=" + ric + "}";
    url=page+ ".rha?ric=" + ric ;
    document.location = url;
};

function openFinancialGraph(page,ric,rowLabel, backTo)
{
	//url="page.aspx?p=" + page+ "&c=" + page+ "{ric=" + ric + "}&c=comppub{company=" + ric + "}";
    url=page+ ".rha?ric=" + ric + "&rowLabel=" + rowLabel + "&backTo=" + backTo ;
    document.location = url;
}

function CheckCoverage(state, page, ric)
{
if(state=="stop")
 alert("Please note that the company is no longer covered by SG Pan-European Research.");
else if(state=="suspended")
 alert("Pending recruitment of a new analyst, the coverage of this stock is momentarily suspended.");
else
      openCompany(page,ric);
}

function searchCompany(page, cont)
{
	f = document.forms.fgui;
	if(f.elements.code.value == '' || f.elements.code.value == invit  || f.elements.code.value == ask)
	{
		f.elements.code.value = ask; 
		f.elements.code.focus();
	}  
	else
	{
		var strcode =  escape(f.elements.code.value);  //encode the code query 
		f.elements.c.value = cont + "{code=" + strcode + "}";
		//alert(f.elements.c.value);
		//f.action = "page.aspx?p=" + page;
		f.action = page +".rha";
  		f.submit();		
  	}
}

// 2009_01_12-GDU: Index Watch pages - Bloomberg Search 
function searchIndexByBloom(page)
{
	f = document.forms.fgui;
	if(f.elements.bloomcode.value == '' || f.elements.bloomcode.value == invit  || f.elements.bloomcode.value == ask)
	{
		f.elements.bloomcode.value = ask; 
		f.elements.bloomcode.focus();
	}  
	else
	{
		var strcode =  escape(f.elements.bloomcode.value);  //encode the code query 
		f.method="GET";
		f.elements.c.disabled = true; // disable container filed to clean url
		f.action = page + ".rha?bloomcode="+ strcode;
		//alert(f.action);
  		f.submit();		
	}
}




/**
* Called from the home page serching a publication by title area.
* On the the form submit, the publication sceen is displayed.
*/
function searchPublication(page, cont)
{
		f = document.forms.fgui;
		if(f.elements.hTitle.value == '' || f.elements.hTitle.value == invit  || f.elements.hTitle.value == ask)
		{
			f.elements.hTitle.value = ask; 			
			f.elements.hTitle.focus();			
		}  
		else
		{
			var strcode =  escape(f.elements.hTitle.value);  //encode the code query 
			f.elements.c.value = cont + "{hTitle=" + strcode + "}";			
			
			if(f.elements.ric)
				f.elements.ric.value = '';
			
			f.action = page +".rha";
  		f.submit();		
  	}
};

function clearField()
{
		f = document.forms.fgui.elements.code;
		if(f.value == invit | f.value == ask)
		{
			f.value = '';
		}

//document.getElementbyId('T_companies').Format();
//S_resizeScrollTable(document.getElementById('D_scrollTable'));
};


function setFilter()
{     

// Small Cap size 
       var re_size = "";
	  	var ssize = document.fgui.size;

	  	if(ssize)
	  	{
			  	switch(ssize.options[ssize.selectedIndex].value)
			  	{
			  			case "large":re_size="no";break;
			  			case "small":re_size="yes";break;
			  			default:re_size="";
			  	}
	  	}

// Recommandations 
	var re_reco = "";
  	var sreco = document.fgui.reco;
  	if(sreco)
  	{
		  	switch(sreco.options[sreco.selectedIndex].value)
		  	{
		  			case "buy":re_reco="Buy";break;
		  			case "hold":re_reco="Hold";break;
		  			case "sell":re_reco="Sell";break;
		  			default:re_reco="";
		  	}
  	}

// Premium
 	var re_prem = "";
 	var sprem = document.fgui.premium;
 	if(sprem)
	{
		 	if(sprem.checked) 
		 		re_prem = "yes"; 	 		
	}			 	
			
	var r = document.getElementById('T_companies').rows;
	
	// A Quoi sert cette ligne ?? : Affichage d'une compagnie en status bar...
	//try{
	//	window.status = r(4).cells(0).innerText ;
	//}catch(ex){}
	
	var m="";		
	for(var i=0;i<r.length;i++)
	{		
		//f1 = r(i).small?r(i).small.match(re_size):true;
		//f2 = r(i).premium?r(i).premium.match(re_prem):true;		
		// f3 = r(i).reco?(r(i).reco.match(re_reco)==re_reco):true;

		f1 = re_size==""?true:r(i).small==re_size;
		f2 = re_prem==""?true:r(i).premium==re_prem;
		f3 = re_reco==""?true:r(i).reco==re_reco;
			
		r(i).style.display = f1 && f2 && f3 ? "block":"none";
						
	}

	
		
document.getElementById('T_companies').Format();
S_resizeScrollTable(document.getElementById('D_scrollTable'));

};


function clearFilter()
{
       t = document.getElementById('T_companies');
		r = t.rows;
		for(var i=1;i<r.length;i++)
		{
				r(i).style.display="block";
		}
t.Format();
S_resizeScrollTable(document.getElementById('D_scrollTable'));
f = document.fgui;
if(f.size)f.size.selectedIndex = 0;
if(f.reco)f.reco.selectedIndex = 0;
if(f.premium)f.premium.checked = false;

};

function ExportGrids()
{
url = 'ExportGrids.aspx?ric=' + document.fgui.ric.value;
//alert(url);
window.location = url;
//open(url, "excel", "width=640,height=480,scrollbars=yes,resizable=yes" );

}

function ExportSectorView()
{
url = "ExportSectorView.aspx";
url += "?sector=" + escape(document.getElementById("hSector").value);
url += "&view=" + document.getElementById("sView").value;
if(document.getElementById("sYear"))
   url += "&year=" + document.getElementById("sYear").value;
else
   url += "&year=2004"; //dummy year, since not actually used

//alert(url);
//window.location = url;
open(url, "excel", "width=640,height=480,scrollbars=yes,resizable=yes" );

}


// ==========================================
// ANALYSTS
// ==========================================


// goAnalysts create an URL for the analysts page, with parameter presets
// searchEmail : default selection for the name search (applies to search and list containers)
//               use null if no selection
// searchSector: default selection for the sector search (applies to search an list containers)
//               use null if no selection
// email       : email of analyst bio to display (applies to the bio container)
//               use null if no bio to display
function goAnalysts(searchEmail, searchSector, email)
{
  f = document.forms.fgui;
  s_param = "";
  baseUrl = "analysts.rha?"
  c_analystsBio = "c=analyst_details";

  if (searchEmail == null) {
    if (f.sr_email == null) {
      searchEmail = "";
    } else {
      searchEmail = f.sr_email.value;
    }
  }
  if (searchEmail != "") s_param = "email=" + searchEmail;
  
  if (searchSector == null) {
    if (f.sr_sector == null) {
      searchSector = "";
    } else {
      searchSector = f.sr_sector.value;
    }
  }
  
  if (searchSector != "") 
  {
		if(s_param != "") s_param += "&";
			
		s_param += "sector=" + escape(searchSector);	
	}
	 
 if (email == "" & searchEmail != "") {email = searchEmail;}
 
 if (email != "") {

	 if(s_param != "") s_param += "&";
   
		c_analystsBio = c_analystsBio + "{email=" + email + "}&";
		s_param += c_analystsBio;
		s_param += "code=" + email;
	}
	
  document.location = baseUrl + s_param;
}

// ==========================================
// PUBLICATIONS
// ==========================================


// goPublications create an URL for the publications page, with parameter presets
// producttype : default selection for the type search (applies to search and list containers)
//               use null if no selection
// product     : default selection for the product search (applies to search and list containers)
//               use null if no selection
// stock       : default selection for the stock search (applies to search and list containers)
//               use a RIC code or null if no selection
// analyst     : default selection for the analyst search (applies to search and list containers)
//               use an email or null if no selection
// sector      : default selection for the sector search (applies to search and list containers)
//               use null if no selection
function goPublications(page, container, producttype, product, stock, analyst, sector)
{
  f = document.forms.fgui;

  s_param = "";

  if (producttype == null) {
    if (f.sr_producttype == null) {
      producttype = "";
    } else {
      producttype = f.sr_producttype.value;
    }
  }
  if (producttype != "") s_param = "producttype=" + producttype + ";";

  if (product == null) {
    if (f.sr_product == null) {
      product = "";
    } else {
      product = f.sr_product.value;
    }
  }
  if (product != "") s_param = s_param + "product=" + product + ";";

  if (stock == null) {
    if (f.sr_ric == null) {
      stock = "";
    } else {
      stock = f.sr_ric.value;
    }
  }
  if (stock != "") s_param = s_param + "ric=" + stock + ";";

  if (analyst == null) {
    if (f.sr_analyst == null) {
      analyst = "";
    } else {
      analyst = f.sr_analyst.value;
    }
  }
  if (analyst != "") s_param = s_param + "analyst=" + analyst + ";";

  if (sector == null) {
    if (f.sr_sector == null) {
      sector = "";
    } else {
      sector = f.sr_sector.value;
    }
  }
  if (sector != "") s_param = s_param + "sector=" + sector + ";";

  baseUrl = "/page.aspx?p=" + page;
  s_param = s_param.substr(0, s_param.length-1);

  if (s_param != "") {
    for (i = 0; i < container.length; i++) baseUrl += "&c=" + container[i] + "{" + s_param + "}";
  }

//  alert(baseUrl);
//  alert(s_param);

  document.location = baseUrl;
}


// ----------------------------------------------
// EXTENSIBLE COMBOBOXES
// ----------------------------------------------


	var openDiv=null;  // current open div
	
	// ----------------------------------------------
	// Reduce open div and extend current div
	// ----------------------------------------------	
	function extendDiv(me)
	{
		  if(openDiv!=null)
		  {
			openDiv.style.width=null; // manage custom xwidth
			openDiv.className="reducedDiv";
		  }
		  openDiv=me;
		  me.className="extendedDiv";
		  if(me.getAttribute('xwidth')) // manage custom xwidth
		  {
			me.style.width=me.getAttribute('xwidth');
		  }
	}
	
	 // global timer
	var clock; 
	
	// ----------------------------------------------
	// Lauch Timer and then reduce open div after 25"
	// ----------------------------------------------	
	function reduceDiv(me)
	{
		 clearTimeout(clock);
		 clock = setTimeout("doReduction()",25000);
	}
	
	// ---------------------	
	// Reduce open Div
	// ---------------------	
	function doReduction()
	{
		 if(openDiv!=null)
		 {
		  openDiv.style.width=null; // manage custom xwidth
		  openDiv.className="reducedDiv";
		  openDiv=null;
		 }
	
	}

	// ------------------------------------------	
	// Can be called by others containers
	// ------------------------------------------	
	function reduceAllCombo()
	{
		 for(var i=1;i<6;i++)
		 {
		  var div = document.getElementById("div"+i);
		  if(div)div.className="reducedDiv";
		  else break;
		 }
	}




// ----------------------------------------------
// WAITING TICKER (not used yet)
// ----------------------------------------------


var waiting_timer;
var waiting_pos;
var waiting_msg;
var waiting_target;
function startWaiting(text, speed, target_id)
{
	pos=0;
	waiting_msg=text;
	waiting_target = target_id
	waiting_timer = setInterval("Waiting()",speed);
}
function Waiting()
{
	if(pos>=waiting_msg.length)pos=0;
	var s1 = waiting_msg.substring(pos,waiting_msg.length)
	var s2 = waiting_msg.substring(0, pos);
	var out = s1 + " " + s2
	pos++;
	var target = document.getElementById(waiting_target)
	if(target)
		target.innerText = out;
	else
		stopWaiting();			
}

function stopWaiting()
{
	if(waiting_timer)clearInterval(waiting_timer);
}


function createXMLHttpRequest() 
{
	try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
	try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
	try { return new XMLHttpRequest(); } catch(e) {}
	alert("XMLHttpRequest not supported");
	return null;
}
/*						 
function callback (url, login, pwd, remind)
{
		try
	{
		var xhReq = createXMLHttpRequest();
		
		xhReq.onreadystatechange = function() 
		{
			//alert(xhReq.responseText);
		};
		
		xhReq.open("POST", url, true);
		
		var params = "username=" + login + "&password=" + pwd + "&unid=" +Math.random() + (remind=='yes'?"&remind=" + remind:"") ;
		
		xhReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
		
		xhReq.setRequestHeader("Content-length", params.length);
		
		xhReq.send(params);
		
	}
	catch(e)
	{
		alert(e.message);
	}
}*/
