function globalChecker(str,clp,expn,tocheck)
{
	
	if(document.getElementById(str+clp+ tocheck).checked == true)
	{
		document.getElementById(str+ expn + tocheck).checked=true;
		document.getElementById(str+ clp + tocheck).checked=true;

	}
	else
	{
		document.getElementById(str+ expn + tocheck).checked=false;
		document.getElementById(str+ clp + tocheck).checked=false;

	}
	return false
}

function checkchkbox(str)
{
	if(validObject(document.getElementById(str+'sel')))
	{document.getElementById(str+'sel').checked = document.getElementById(str+'rel').checked;
	}
	
}
function checkchkboxsel(str)
{
	document.getElementById(str).checked = document.getElementById(str+'sel').checked;
}

function showSearchForm(fil)
{
	selectionpopup();
	form_postForPlainText("selected.cfm?filtername="+fil,document.getElementById('buildlist'),callBackBcl2,null,null,contentObject);		
	return false;
}

function showSearchFormHome(fil)
{
	selectionpopup();
	form_postForPlainText("analytics/selected.cfm?filtername="+fil,document.getElementById('buildlist'),callBackBcl2,null,null,contentObject);		
	return false;
}


function SubmitSearchForm()
{
	
	selectionpopup();
	form_postForPlainText("selected.cfm?subsearch",document.getElementById('buildlist'),callBackBcl2,null,null,contentObject);		
	return false;
}

function selectionpopup()
{
		contentObjectContainer = "selecDiv";
		contentObject = "selecdivcontent";
		document.getElementById(contentObject).className = "regular";
		document.getElementById(contentObjectContainer).className = "regular";
		document.getElementById(contentObject).innerHTML = document.getElementById('loadercontentSel').innerHTML;	
}

function setRelatedForm(id)
{
	
		contentObject = "relateddiv";
		document.getElementById(contentObject).className = "regular";
		document.getElementById(contentObject).innerHTML = document.getElementById('loadercontent').innerHTML;
		form_postForPlainText("related.cfm?related="+id,document.getElementById('buildlist'),callBackBcl,null,null,contentObject);		
}
function callBackBcl(text,callingContext)
{
	callbackMain('loadercontent',text,callingContext);
}

function callBackBcl2(text,callingContext)
{
	callbackMain('loadercontentSel',text,callingContext);
}
function callbackMain(elementLoaded,text,callingContext)
{
	curText = window.document.getElementById(callingContext).innerHTML;
	curTextLoader = window.document.getElementById(elementLoaded).innerHTML;
	if(curText.indexOf('LoadingData.gif') != -1 && trim(curTextLoader) != '') {
		document.getElementById(elementLoaded).innerHTML = curText;
	}
	window.document.getElementById(callingContext).innerHTML = text;
	setJSFunctions(callingContext,text);	
}

function resizeflash(myHeight)
{

						if(navigator.appName.indexOf('Microsoft Internet')==-1) {
							document.embeds.flexswf2.height = myHeight;
						}
							else {
								document.getElementById('flexswf').height = myHeight; 
								}
}

function callenter(eventnum)
{	
	if(eventnum == 13)
	{
		showSearchForm(document.getElementById('filtername').value);
		document.getElementById('relateddiv').innerHTML='';
		document.getElementById('relateddiv').className='gone';
	}
	
	return false;
		
}

function setprimarysec()
{

	if(document.getElementById('sector_type').value ==  "primarysec")
		document.getElementById('sector_type').value = "primary";
	else
		document.getElementById('sector_type').value = "primarysec";
}

function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window.document.flexswf;
    } else {
        return document.flexswf2;
    }
}

function callApp(value) {
	if (value == 'sp_values')
	{
		var ids = document.getElementById(value).value.split(",");
		var selected_ids = new Array();
		for (i = 0; i < ids.length; i ++)
			if (document.getElementById("special_list" + ids[i]).checked)
				selected_ids.push(document.getElementById("special_list" + ids[i]).value);
		thisMovie("flexswf").updatelist(selected_ids.join());
	}
	else if(value != 'newlist')
		thisMovie("flexswf").updatelist(value);
	else
		thisMovie("flexswf").updatelist('');
}

function submittoflex(value,iden) {
	
	
	if(document.getElementById(value+iden).checked)
	{
		thisMovie("flexswf").updatelistSearch(value);
	}
	else
	{
		thisMovie("flexswf").DeletelistSearch(value);

	}
}

function setDef(text,iden)
{
	
	text=text.replace(/<.*?>/g,'');
	if(text != '')
		window.document.getElementById('defword'+ iden).className = "notgone";
	else
		window.document.getElementById('defword' + iden).className = "gone";
		
		window.document.getElementById('defdiv'+iden).innerHTML = text;

}


function flexisready() {
	window.document.getElementById("submit_splist").className = "notgone";
	window.document.getElementById("submit_splist_disabled").className = "gone";
//	window.document.getElementById("searchbutton").className = "notgone";
}


function setMirror(text,rel){
	text=text.replace(/-->/g,'&rarr;');
	window.document.getElementById('mirrordiv'+rel).innerHTML = text;
	if(text != '')
		document.getElementById('divseperator'+rel).className="notgone";
	else
		document.getElementById('divseperator'+rel).className="gone";
}

function setCodes(s,p) {
	frm=document.getElementById('buildlist');
	with(frm) {
		sectorsindustry.value = s;
		sector_type.value = p;
	}
}
function IsNumericNumber(sText)
{
	var ValidChars = "0123456789.";
		var IsNumber=true;
			var Chart;
	var start=0;
			if(sText.length > 0){
		Chart=sText.charAt(0);
		if(Chart == '-' && sText.length > 1){
			start=1;
		}			
		for (i = start; i < sText.length && IsNumber == true; i++) 
					{ 
						Chart = sText.charAt(i); 
							if (ValidChars.indexOf(Chart) == -1) 
							{
								IsNumber = false;
							}
					}
	}
			return IsNumber;
}
function get_selected_indexes(ob){
	selected = new Array();
	for (var i = 0; i < ob.options.length; i++)
		if (ob.options[ i ].selected) 
			selected.push(ob.options[ i ].value);
	return selected;
}
function toggle_indicator(id)
	{
		with(window.document)
		{
			getElementById(previoustab + "_tab").className = "bcl_tab";
			getElementById(previoustab).className = "gone";
			getElementById(id + "_tab").className = getElementById(id + "_tab").className == "bcl_on" ? "bcl_tab" : "bcl_on";				
			getElementById(id).className = getElementById(id).className == "notgone" ? "gone" : "notgone";				
			previoustab = id;
			if (id == "ratios")
			{
				move_selection(previousratio + "field");
				getElementById("notes").className = "greytextsmall notgone";
				getElementById("notemark").className = "greytextsmall notgone";
				getElementById("fintabnotemark").className = "greytextsmall gone";
				getElementById("fintabnote").className = "gone";
			}
//			else if (id.indexOf("market") > -1)
//				move_selection(previousmarketdata + "_data");
			else
			{
				getElementById("notes").className = "greytextsmall gone";
				getElementById("notemark").className = "greytextsmall gone";
				getElementById("fintabnotemark").className = "greytextsmall notgone";				
				getElementById("fintabnote").className = "notgone";				
				if (previousfinancials != "")
					move_selection(previousfinancials);
				else
				{
					getElementById(previousratio + "field").className = "gone";
					//getElementById(previousmarketdata + "_data").className = "gone";
				}	
			}
			return false;
		}
	}
	function toggle_radio(id,type)
	{
		with(window.document)
		{
			if (type == "ratio")
			{
				if (previousratio == "")
					previousratio = previous;
				getElementById(previousratio).className = "";
				previousratio = id;
				move_selection(id + "field");
			}
/*			else if (type == "market")
			{
				getElementById(previousmarketdata).className = "";
				previousmarketdata = id;
				move_selection(id + "_data");
			}*/
			getElementById(id).className = "bold";
			return false;
		}
	}	
	function move_selection(id)
	{
		with(window.document)
		{
			if(previoustemplate != "")
				getElementById(previoustemplate).className = "gone";
			getElementById(id).className = "notgone";
			previoustemplate = id;
//			if (id.indexOf("ratio") <= -1 && id.indexOf("market") <= -1)
	//			previousfinancials = id;
		}
		return false;
	}
	function highlightthis(id, view)
	{
		with(window.document)
		{
			if (previous_selected_item_id != id && getElementById(id).className != "gone")
				if (view == "true")
				{
					getElementById(id).className = "highlighted";
				}
				else
					getElementById(id).className = "not_highlighted";
			return false;
		}
	}
	function selectthis(id, label, type)
	{
		if (id.search("_ratios") == -1 && id.search("_financials") == -1)
			currentSelectedItem = id + "_" + type;
		with(window.document)
		{
			if (id.search("selected") > -1)
			{
				getElementById(id).className = "bold";
				getElementById(id.replace("selected","specifyrange")).className = "bold range_link";	
			}	
			else	
			{
				getElementById(id).className = "highlighted";
			}
				
			if (previous_selected_item_id != "" && id != previous_selected_item_id)
			{
				if (previous_selected_item_id.search("selected") > -1)
					{
					getElementById(previous_selected_item_id).className = "not_bold";
					getElementById(previous_selected_item_id.replace("selected","specifyrange")).className = "not_bold range_link";	
					}
				else
					getElementById(previous_selected_item_id).className = "not_highlighted";
			}
			previous_selected_item_id = id;
			previous_selected_item_label = escape(unescape(label).replace("]","]</span>").replace("[","<span class=greytextsmall2>&nbsp;["));
			if (id.replace("selected","range") != current_rangebox && current_rangebox != "")
				getElementById(current_rangebox.replace("selected","range")).className = "gone range_box";
			return false;
		}
	}
	function move_selected_item_toright()
	{
		if (previous_selected_item_id != "")
		{
			if (number_of_selected_items >= 10)
			{
				alert("You can only select 10 indicators");
				return false;
			}
			with(window.document)
			{
				number_of_selected_items ++;
				if (validObject(getElementById("selected_" + currentSelectedItem)))
					getElementById("selected_" + currentSelectedItem).innerHTML = '<div class="item">' + unescape(previous_selected_item_label) + '</div><div class="range_link" onclick="return showhide_rangebox(' + "'range_" + currentSelectedItem + "');" + '" id ="specifyrange_' + currentSelectedItem + '">Specify Range</div></div><div class="range_box_holder"><div id="range_' + currentSelectedItem + '" class="range_box gone"><div class="close_link" onclick="return validate_range(' + "'" + currentSelectedItem + "'" + ');">X</div><div class="range_fields"><span class="range_word" style="font-weight:normal">Range</span>&nbsp;&nbsp;<input type="text" id="from_' + previous_selected_item_id + '" value="" style="width:50px">&nbsp;&nbsp;<span class="range_word" style="font-weight:normal">To</span>&nbsp;&nbsp;<input type="text" id="to_' + currentSelectedItem + '" value="" style="width:50px"></div></div>';
				else				
					getElementById("selected_items_display").innerHTML += '<div class="not_highlighted" style="padding:2px 2px; clear:both" id="selected_' + previous_selected_item_id + '_' + previoustab + '" onclick="return selectthis(' + "'selected_" + currentSelectedItem + "','" + unescape(previous_selected_item_label) + "'" + ')" ondblclick="selectthis(' + "'selected_" + currentSelectedItem + "','" + unescape(previous_selected_item_label) + "'" + ');move_selected_item_toleft();"><div class="item">' + unescape(previous_selected_item_label) + '</div><div class="range_link" onclick="return showhide_rangebox(' + "'range_" + currentSelectedItem + "');" + '" id ="specifyrange_' + currentSelectedItem + '">Specify Range</div></div><div class="range_box_holder"><div id="range_' + currentSelectedItem + '" class="range_box gone"><div class="close_link" onclick="return validate_range(' + "'" + currentSelectedItem + "'" + ');">X</div><div class="range_fields"><span class="range_word" style="font-weight:normal">Range</span>&nbsp;&nbsp;<input type="text" id="from_' + currentSelectedItem + '" value="" style="width:50px">&nbsp;&nbsp;<span class="range_word" style="font-weight:normal">To</span>&nbsp;&nbsp;<input type="text" id="to_' + currentSelectedItem + '" value="" style="width:50px"></div></div></div>';
				getElementById(previous_selected_item_id).className = "gone";
				getElementById("selected_" + currentSelectedItem).className = "notgone not_highlighted";
				all_selected_items += previous_selected_item_id + ","; 
				getElementById("selected_items").value += currentSelectedItem + ",";
				previous_selected_item_id = "";
				previous_selected_item_label = "";  
			}
			return false;
		}
	}
	function move_selected_item_toleft()
	{
		if (previous_selected_item_id != "" && previous_selected_item_id.search("selected_") > -1)
		{
			with(window.document)
			{
				filtered_id = previous_selected_item_id.replace("selected_","");
				filtered_id = filtered_id.replace(filtered_id.substring(filtered_id.search("_"), filtered_id.length), "");
				getElementById(previous_selected_item_id).innerHTML = "";
				number_of_selected_items --;
				getElementById(filtered_id).className = "not_highlighted notgone";
				getElementById(previous_selected_item_id).className = "gone";
				getElementById(previous_selected_item_id.replace("selected","range")).className = "gone range_box";
				replace_string = filtered_id + ",";
				all_selected_items = all_selected_items.replace(replace_string,"");
				arr = getElementById("selected_items").value.split(",");
				getElementById("selected_items").value = getElementById("selected_items").value.replace("," + previous_selected_item_id.replace("selected_",""),"");
				previous_selected_item_id = "";
				previous_selected_item_label = "";
			}
			return false;
		}
	}
function clear_indicators(itemsfromedit)
{	
	if (itemsfromedit != "")
		all_selected_items = itemsfromedit;
	with(window.document)
	{
		if (all_selected_items != "")
		{
			var arr = all_selected_items.split(",");
			/*if (getElementById("sharia").checked)
			{
				for (i = 0; i < (arr.length - 1); i ++)
					if (s_fields.join().indexOf(arr[i]) != -1 || ratio_fields_notSharia.join().indexOf(arr[i]) == -1)
						getElementById(arr[i]).className = "notgone";
			}
			else
			{*/
				for (i = 0; i < arr.length; i ++)	
					if (arr[i] != "")
						getElementById(arr[i]).className = "notgone";
			//}
			getElementById("selected_items_display").innerHTML = "";
			number_of_selected_items = 0;
			previous_selected_item_id = "";
			previous_selected_item_label = "";
			current_rangebox = "";
			getElementById("selected_items").value = ",";
			selected_items_temp = "";
		}
	}
	return false;
}
function validate_range(id)
{
	with(window.document)
	{
		var from = getElementById("from_" + id);
		var to = getElementById("to_" + id);
		if (!IsNumericNumber(from.value) || !IsNumericNumber(to.value))
		{
			alert("Range should be of numeric value");
			return false;
		}
		if (parseInt(from.value) > parseInt(to.value) && to.value.replace(/ /g,"") != "")
		{
			alert("Your lower range is greater than upper range");
			return false;
		}
		getElementById("range_" + id).className = "gone";
		if (getElementById("selected_items").value.search(id) > -1)
			getElementById("selected_items").value = getElementById("selected_items").value.replace(getElementById("selected_items").value.substring(getElementById("selected_items").value.search(id),getElementById("selected_items").value.indexOf(",", getElementById("selected_items").value.search(id))), id);
		if (from.value.replace(/ /g,"") != "" && to.value.replace(/ /g,"") != "")
		{
			getElementById("specifyrange_" + id).innerHTML = '<span class="range_word">Range&nbsp;&nbsp;' + from.value + "&nbsp;&nbsp;To&nbsp;&nbsp;" + to.value + '</span>';
			getElementById("selected_items").value = getElementById("selected_items").value.replace(id, id + "from" + from.value + "to" + to.value);
		}
		else if (from.value.replace(/ /g,"") != "" && to.value.replace(/ /g,"") == "")
		{
			getElementById("specifyrange_" + id).innerHTML = '<span class="range_word">Range from&nbsp;&nbsp;' + from.value + '</span>';
			getElementById("selected_items").value = getElementById("selected_items").value.replace(id, id + "from" + from.value);
		}
		else if (from.value.replace(/ /g,"") == "" && to.value.replace(/ /g,"") != "")
		{
			getElementById("specifyrange_" + id).innerHTML = '<span class="range_word">Range up to&nbsp;&nbsp;' + to.value + '</span>';
			getElementById("selected_items").value = getElementById("selected_items").value.replace(id, id + "to" + to.value);
		}
		else
			getElementById("specifyrange_" + id).innerHTML = '<span class="range_word">Specify Range</span>';
		return false;
	}
}
function showhide_rangebox(id)
{
	if (current_rangebox != "" && id != current_rangebox)
		window.document.getElementById(current_rangebox).className = "gone range_box";
	window.document.getElementById(id).className = "notgone range_box";
	window.document.getElementById(id.replace("range","from")).focus();
	current_rangebox = id;
}
function refresh_indicators()
{
	var tkn = selected_items.split(",");
	for (i = 0; i < tkn.length; i ++)
		if (tkn[i] != "")
			window.document.getElementById(tkn[i].substr(0,tkn[i].indexOf("_"))).className = "not_highlighted gone";
}

function clear_all()
{
	var special_list_ids = document.getElementById("sp_values").value.split(",");
	for (i = 0; i < special_list_ids.length; i ++)
		document.getElementById("special_list" + special_list_ids[i]).checked = false;
}

function submitSearchSector(eventnum)
{
	if(eventnum == 13)
	{
		showSearchForm(document.getElementById('searchsector').value);
		return false;
	}
	return true;
}

function clearCountry(num)
{
	for (i = 1; i <= num; i++)
		window.document.getElementById("country" + i).checked = false;
}

function clearExchange(num)
{
	for (i = 1; i <= num; i++)
		window.document.getElementById("exchange" + i).checked = false;
}