var arrActions = new Array();
arrActions[0] = new Array();
arrActions[0][0] = "company";
arrActions[0][1] = "/cm/companylookup.cfm";
arrActions[0][2] = "companyname";
arrActions[0][3] = "Company Name or Symbol";
arrActions[1] = new Array();
arrActions[1][0] = "news";
arrActions[1][1] = "/nc/searchresult.cfm";
arrActions[1][2] = "QUERY";
arrActions[1][3] = "News or Analysis by Keywords";
arrActions[2] = new Array();
arrActions[2][0] = "research";
arrActions[2][1] = "/nc/searchresult.cfm";
arrActions[2][2] = "QUERY";
arrActions[2][3] = "Research Monitor by Keyword";
arrActions[3] = new Array();
arrActions[3][0] = "ipo";
arrActions[3][1] = "/ipomonitor/searchresult.cfm";
arrActions[3][2] = "ipoSearch";
arrActions[3][3] = "Search Issuer or Advisor";
arrActions[4] = new Array();
arrActions[4][0] = "sukuk";
arrActions[4][1] = "/sukuk/searchresult.cfm";
arrActions[4][2] = "sukukSearch";
arrActions[4][3] = "Sukuk Monitor by Keyword";
arrActions[5] = new Array();
arrActions[5][0] = "private";
arrActions[5][1] = "/pe/default.cfm";
arrActions[5][2] = "peSearch";
arrActions[5][3] = "Private Equity Monitor by Keyword";
arrActions[6] = new Array();
arrActions[6][0] = "mutual";
arrActions[6][1] = "/mutual/searchresult.cfm";
arrActions[6][2] = "mfSearch";
arrActions[6][3] = "Mutual Fund Monitor by Keyword";
arrActions[7] = new Array();
arrActions[7][0] = "more";
arrActions[7][1] = "/cm/companylookup.cfm";
arrActions[7][2] = "companyname";
arrActions[7][3] = "";
arrActions[8] = new Array();
arrActions[8][0] = "project";
arrActions[8][1] = "/projects/projectLookUp.cfm";
arrActions[8][2] = "qryText";
arrActions[8][3] = "Project, Owner or Scope of Work";

function showSearch(num,prod)
{
	if (lastSelectedSearch != num)
	{
		window.document.getElementById("SearchLnk_"+arrActions[lastSelectedSearch][0]).className = "text";
		window.document.getElementById("SearchLnk_"+arrActions[num][0]).className = (prod == "ZI"?"header3":"textbold");
		if (window.document.getElementById("searchText").value.replace(/ /g,"") == "" || window.document.getElementById("searchText").value == arrActions[lastSelectedSearch][3])
		{
			window.document.getElementById("searchText").value = arrActions[num][3];
			selectFocusSearchField();
		}
		window.document.getElementById("header_search_btn").src = "/images/search_"+arrActions[num][0]+".gif";
		window.document.getElementById("searchForm").action = arrActions[num][1];
		lastSelectedSearch = num;
	}
	return false;
}

function submitSearch()
{
	if (window.document.getElementById("searchText").value != arrActions[lastSelectedSearch][3] && window.document.getElementById("searchText").value.replace(/ /g,"") != "")
	{
		window.document.getElementById(arrActions[lastSelectedSearch][2]).value = window.document.getElementById("searchText").value;
		if (arrActions[lastSelectedSearch][0] == "news")
			window.document.getElementById("category").value = "News";
		else
		{
			if (arrActions[lastSelectedSearch][0] == "research")
				window.document.getElementById("category").value = "Research";
			else
				window.document.getElementById("category").value = "";
		}
		return true;
	}
	else
		return false;
}

function clearSearchField()
{
	if (window.document.getElementById("searchText").value == arrActions[lastSelectedSearch][3])
		window.document.getElementById("searchText").value = "";
}

function selectFocusSearchField()
{
	window.document.getElementById("searchText").select();
	window.document.getElementById("searchText").focus();
}

function showTRs(num,num2,str,load,url)
{
	for(var i=1;i<=num2;i++)
	{
		var prev_className = window.document.getElementById("tabTitle"+i+"_"+str).className.replace("unselectedTabBlink","").replace("unselectedTab","").replace("selectedTab","");
		window.document.getElementById("tabTitle"+i+"_"+str).className = ((i==num)?"selectedTab":"unselectedTab")+prev_className;
		window.document.getElementById("tabData"+i+"_"+str).className = ((i==num)?"notgone":"gone");
	}	
	var tab_el = window.document.getElementById("content"+num+"_"+str);
	if (load && (tab_el.innerHTML.indexOf("Loading...")!= -1 || tab_el.innerHTML.indexOf("Loading ...")!= -1) && (tab_el.innerHTML.indexOf("zawya_loading_img2.")!= -1 || tab_el.innerHTML.indexOf("LoadingData.gif")!= -1) ){
		ajaxCaller.getPlainText(url,loadData,"content"+num+"_"+str);
	}
	return false;
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

// showhidestory div script
var cldNme = "gone";
function showhidestory(layer_ref,sourceurl,elt)
{
	if (cldNme == "notgone")
		cldNme = "gone";
	else
		cldNme = "notgone";
	if (cldNme == "notgone")
	{
		window.document.getElementById("storyframe").src = sourceurl;
		var tdElt = elt;
		while ((tdElt.tagName.toUpperCase() != "TD" || tdElt.id.indexOf("content") == -1) && tdElt != null)
			tdElt = tdElt.parentNode;
		if (tdElt != null && tdElt.clientHeight != "undefined" && parseInt(tdElt.clientHeight) > 333)
		{
			window.document.getElementById("storyframe").height = (parseInt(tdElt.clientHeight)-10)+"px";
			window.document.getElementById(layer_ref).style.top = (-parseInt(tdElt.clientHeight)-22)+"px";
		}
		//if (tdElt != null && tdElt.clientWidth != "undefined" && tdElt.clientWidth > 430)
		if (tdElt != null && tdElt.clientWidth != "undefined")
		{
			window.document.getElementById("storyframe").width = tdElt.clientWidth;
			window.document.getElementById(layer_ref).style.width = tdElt.clientWidth;
		}
	}
	else
		window.document.getElementById("storyframe").src = "/images/zawya_loading_img2.gif";
	window.document.getElementById(layer_ref).className = cldNme;
	return false;
}

// format numeric to formatted string with commas & decimals
// sample formatnum(3400.3940,2) returns "3,400.39"
function formatnum(num,dec)
{
	num = num.toFixed(dec);
	nStr = num;
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function get_usd_rate(value, dollarrate)
{
	if (value == 0)
		return 0;
	else
		return value / dollarrate;
}

function get_base_rate(value, dollarrate)
{
	return value * dollarrate;
}

function get_class(value)
{ 
	if (value > 0)
		return 'greenfont';
	else if (value < 0)
		return 'redfont';
	return 'blackfont';	
}

function trim(str)
{  
 	if(typeof(str) == "string")
 		return str.replace(/^\s*|\s*$/g,"");
	else 
		return str;
}

function IsNumeric(sText)
{
 	var ValidChars = "0123456789.";
 	var IsNumber=true;
  var Chart;
	for (i = 0; i < sText.length && IsNumber == true; i++) 
   { 
   	Chart = sText.charAt(i); 
     if (ValidChars.indexOf(Chart) == -1) 
     {
     	IsNumber = false;
     }
   }
  return IsNumber;
}
	
function isNumeric(x) {
	var RegExp = /^(-)?(\d*)(\.?)(\d*)$/; 
	var result = x.match(RegExp);
	if (result==null) 
		return false;
	else	
		return true;
}

var lastTeaserPage = "";
var lastTeaserObj = "";
var lastTeaserContainer = "";
function showTeaser(obj,page,divwrapper)
{
	if (typeof(divwrapper) == 'undefined' || typeof(divwrapper) == 'null' || divwrapper == '') divwrapper = "IndustryNewsTab";
	open_close = (obj.src.indexOf("/images/plus_icon.gif")!=-1?1:0);
	var container = window.document.getElementById(divwrapper);
	divArray = container.getElementsByTagName("DIV");
	for (var i=0;i<divArray.length;i++)
	{
		if (divArray[i].getAttribute("belongPage") == page)
			divArray[i].className = (open_close == 1?"notgone":"gone");
		else if (divArray[i].getAttribute("belongPage") == lastTeaserPage && open_close == 1 && divwrapper == lastTeaserContainer)
			divArray[i].className = "gone";
	}
	if (divwrapper != lastTeaserContainer && lastTeaserContainer != "")
	{
		var container = window.document.getElementById(lastTeaserContainer);
		divArray = container.getElementsByTagName("DIV");
		for (var i=0;i<divArray.length;i++)
		{
			if (divArray[i].getAttribute("belongPage") == lastTeaserPage)
				divArray[i].className = "gone";
		}
	}
	if (lastTeaserPage != page && open_close == 1)
		lastTeaserObj.src = "/images/plus_icon.gif";
	lastTeaserPage = page;
	lastTeaserObj = obj;
	lastTeaserContainer = divwrapper;
	obj.src = (open_close == 1?"/images/minus_icon.gif":"/images/plus_icon.gif");
}

function openAudioFile(v_file)
{

	zi=getCookie('ZI')
	if (zi!=null && zi=="true")
	{
//window.open("/audio/default.cfm?w=320&h=145&" + v_file ,"dubaieye","width=320,height=165,Status=no,Toolbar=no,Menubar=no,Location=no,Scrollbars=no");
	window.open("/audio/default.cfm?w=320&h=145&"  + v_file,"dubaieye","height=165,width=320,status=no,toolbar=no,titlebar=no,menubar=no,location=no");	
	} 
	else 
	{
    window.open("/audio/default.cfm?w=320&h=145&" + v_file ,"dubaieye","width=320,height=165,menubar=no,titlebar=no,Scrollbars=no,location=no,status=no");
		
	}

	
	return false;	
}
function GetInnerSize () {
	var x,y;
	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	return [x,y];
}
function ResizeToInner (w, h) {
	// make sure we have a final x/y value
	// pick one or the other windows value, not both
	var xx = window.screenLeft || window.screenX;
	var yy = window.screenTop || window.screenY;
	// for now, move the window to the top left
	// then resize to the maximum viewable dimension possible
	window.moveTo(0,0);
	window.resizeTo(screen.availWidth,screen.availHeight);
	// now that we have set the browser to it's biggest possible size
	// get the inner dimensions.  the offset is the difference.
	var inner = GetInnerSize();
	var ox = screen.availWidth-inner[0];
	var oy = screen.availHeight-inner[1];
	// now that we have an offset value, size the browser
	// and position it
	top.resizeTo(w+ox, h+oy);
	
	window.moveTo(xx,yy);
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    } 
  }
return ""
}

function checkdivheight(){
alert(document.getElementById("outercontainer").height);
}

function submit_keyplayers_form(sector,ind_list){
	document.getElementById("sectors").value=sector;
	document.getElementById("industry").value=ind_list;
	document.getElementById("buildlist").submit();
	return false;	
}

function hideShowSelect(){
	if (document.getElementById&&document.documentElement.filters){
		var args=arguments;
	for (var i_tem = 0; i_tem < args.length; i_tem++)
		if (document.getElementById(args[i_tem]).style.visibility=='')
			document.getElementById(args[i_tem]).style.visibility='hidden';
		else
			document.getElementById(args[i_tem]).style.visibility='';
	}
}

var iframeCode = "";
function showFeedback(prod)
{	/*for (var frm=0;frm<document.forms.length;frm++)
		for (var con=0;con<document.forms[frm].length;con++)
			if (document.forms[frm][con].type.indexOf("select")>-1)
				document.forms[frm][con].style.display="none";*/
	var tab_el = window.document.getElementById("feedBackForm");
	if (typeof(c_F) == "object" && c_F[0])
	{
		var container = window.document.getElementById("feedBackWindow");
		iframeCode=c_cE("<iframe src=javascript:0 tabindex=-9 style=position:absolute;z-index:-1;width:514px;height:152px;left:0px;top:0px;filter:alpha(opacity=0)>","");
		container.insertBefore(iframeCode,tab_el);
	}
	if(tab_el.innerHTML.indexOf("Thank you for your feedback.") !=-1)
		tab_el.innerHTML = '<div class="loadimg"><img src="/images/LoadingData.gif" border="0" style="vertical-align:middle"> <font class="greytextsmall">Loading ...</font></div>';
	if (tab_el.innerHTML.indexOf("Loading ...")!= -1 && tab_el.innerHTML.indexOf("LoadingData.gif")!= -1)
		ajaxCaller.getPlainText('/zscripts/xml.cfm?feedback',loadDataFeedback,"feedBackForm");
	document.getElementById("feedbackArrowImg").src = "/images/"+prod+"_feedback_arrow_down.gif";
	document.getElementById("feedBackWindow").className = "notgone";
	if (!(tab_el.innerHTML.indexOf("Loading ...")!= -1 && tab_el.innerHTML.indexOf("LoadingData.gif")!= -1) && (typeof(c_F) == "object" && c_F[0]) && iframeCode != "")
	{
		iframeCode.style.width = tab_el.offsetWidth+42;
		iframeCode.style.height = tab_el.offsetHeight+12;
	}
	document.getElementById("feedBackHeaderBox").onclick = function(){hideFeedback(prod);};
	return false;
};

function hideFeedback(prod)
{	/*for (var frm=0;frm<document.forms.length;frm++)
		for (var con=0;con<document.forms[frm].length;con++)
			if (document.forms[frm][con].type.indexOf("select")>-1)
				document.forms[frm][con].style.display="";*/
	if (typeof(c_F) == "object" && c_F[0] && iframeCode != "")
	{
		iframeCode.removeNode(1);
		iframeCode = "";
	}
	document.getElementById("feedbackArrowImg").src = "/images/"+prod+"_feedback_arrow_right.gif";
	document.getElementById("feedBackWindow").className = "gone";
	document.getElementById("feedBackHeaderBox").onclick = function(){showFeedback(prod);};
	return false;
};

function submitFeedBack(url,fObj,callBack)
{
	var feedbackDefault1 = "When you make suggestions for improvements or changes well include this in our regular product testing and updates to provide the best possible solution for you.";
	var feedbackDefault2 = "When you ask us a question our customer support team will go out of their way to help clarify any queries you have.";
	var feedbackDefault3 = "When you send us an update well quickly amend any changes you request.";
	var feedbackDefault4 = "When you complain youll be contacted by our team to help resolve any concerns you may have.";
	var feedbackDefault5 = "When you sing our praises well know what were doing right and well repeat it.";	
	var tmp = fObj.feedback.value.replace(/,/g,"");
	tmp = tmp.replace(/'/g,"");
	if (fObj.feedback.value.replace(/ /g,"") == "" || tmp == feedbackDefault1 || tmp == feedbackDefault2 || tmp == feedbackDefault3 || tmp == feedbackDefault4 || tmp == feedbackDefault5)
	{
		window.document.getElementById("feedBackError").innerHTML = "Enter your feedback";
		return false
	}
	else if (!checkEmail(fObj.email.value))
	{
		window.document.getElementById("feedBackError").innerHTML = "Email address is incorrect";
		return false;
	}
	form_postForPlainText(url,fObj,callBack);	
	window.document.getElementById("feedBackForm").innerHTML = '<div class="loadimg"><img src="/images/LoadingData.gif" border="0" style="vertical-align:middle"> <font class="greytextsmall">Sending ...</font></div>';
	if (typeof(c_F) == "object" && c_F[0] && iframeCode != "")
	{
		iframeCode.style.width = window.document.getElementById("feedBackForm").offsetWidth+42;
		iframeCode.style.height = window.document.getElementById("feedBackForm").offsetHeight+12;
	}
	return false;	
}

function returnSubmitFeedback()
{
	window.document.getElementById("feedBackForm").innerHTML = '<div align="center" class="MPHeaderOrange" style="padding:40px 0px;"><strong>Thank you for your feedback.</strong></div>';
	if (typeof(c_F) == "object" && c_F[0] && iframeCode != "")
	{
		iframeCode.style.width = window.document.getElementById("feedBackForm").offsetWidth+42;
		iframeCode.style.height = window.document.getElementById("feedBackForm").offsetHeight+12;
	}
	window.setTimeout(hideFeedback,3000);
	return false;
}

function clearFeedback(num,obj,fobj)
{
	for (var i = 0; i < fobj.feedbackType.length; i ++)
		if (fobj.feedbackType[i].checked == true)
			switch (i)
			{
				case 0:
					var feedbackDefault = "When you make suggestions for improvements or changes, we'll include this in our regular product testing and updates to provide the best possible solution for you.";
					break;
				case 1:
					var feedbackDefault = "When you ask us a question, our customer support team will go out of their way to help clarify any queries you have.";
					break;
				case 2:
					var feedbackDefault = "When you send us an update we'll quickly amend any changes you request.";
					break;
				case 3:
					var feedbackDefault = "When you complain you'll be contacted by our team to help resolve any concerns you may have.";			
					break;
				case 4:
					var feedbackDefault = "When you sing our praises we'll know what we're doing right and we'll repeat it.";	
					break;
			}
	if (num == 1 && obj.value == feedbackDefault)
		obj.value = "";
	else if (num == 2 && obj.value == "")
		obj.value = feedbackDefault;
}

function SwitchFeedbackType(num,field)
{
	switch (num)
	{
		case 1:
			window.document.getElementById(field).value = "When you make suggestions for improvements or changes, we'll include this in our regular product testing and updates to provide the best possible solution for you.";
			break;
		case 2:
			window.document.getElementById(field).value = "When you ask us a question, our customer support team will go out of their way to help clarify any queries you have.";
			break;
		case 3:
			window.document.getElementById(field).value = "When you send us an update we'll quickly amend any changes you request.";
			break;
		case 4:
			window.document.getElementById(field).value = "When you complain you'll be contacted by our team to help resolve any concerns you may have.";			
			break;
		case 5:
			window.document.getElementById(field).value = "When you sing our praises we'll know what we're doing right and we'll repeat it.";	
			break;
	}
}

function loadDataFeedback(text,callingContext,headers,arrParams)
{
	if (text.replace(/ /g,"") != "")
	{
		if (window.document.URL.toLowerCase().indexOf("/story.cfm")!=-1)
			var docTitle = "Story page";
		else if (window.location.pathname.toLowerCase() == "/" || window.location.pathname.toLowerCase().substr(0,12) == "/default.cfm")
			var docTitle = "Homepage";
		else
			var docTitle = ((window.document.title.toLowerCase().indexOf(" - zawya.com")!=-1)?window.document.title.substr(0,window.document.title.toLowerCase().indexOf(" - zawya.com")):window.document.title);
		if (docTitle == "Zawya.com | Middle East Business News and Company Directory") docTitle = "";
		window.document.getElementById(callingContext).innerHTML = text;
		window.document.getElementById("feedbackPageTitle").value = docTitle;
		window.document.getElementById("current_url").value = window.document.URL;
		if (typeof(c_F) == "object" && c_F[0] && iframeCode != "")
		{
			iframeCode.style.width = window.document.getElementById(callingContext).offsetWidth+42;
			iframeCode.style.height = window.document.getElementById(callingContext).offsetHeight+12;
		}
	}
}

function checkEmail(str)
{
	if (str.indexOf('@',0)==-1 ||
			str.indexOf('@',0)== 0 ||
			str.indexOf('/',0)>-1 ||
			str.indexOf(':',0)>-1 ||
			str.indexOf(';',0)>-1 ||
			str.indexOf('[',0)>-1 ||
			str.indexOf(']',0)>-1 ||
			str.indexOf('{',0)>-1 ||
			str.indexOf('}',0)>-1 ||
			str.indexOf('.',0)==-1) 
			return false;
	return true;
}

function SetFlashHeight(flashDivId,flashDivHeight){
if(isLoaded)
	document.getElementById(flashDivId).style.height=flashDivHeight+'px' ;
}
function loadsponsor() { 
	isLoaded = 1;
	var el = document.getElementById('FlashDiv'); 
	if (el) el.style.display = 'block';  
}	

function toggleslidediv(img,divid) { img.src =  img.src.indexOf('collapse') != -1 ? "/images/btn_expand.gif" : "/images/btn_collapse.gif"; document.getElementById(divid).style.display = ''; }

function afterslide(el) {
	if (el.offsetHeight < 5)
		el.style.display = 'none';
}
function toggleCoverage(imgnm,divid) {
	toggleslidediv(document.getElementById(imgnm),divid); 
	Spry.Effect.Slide(divid, {duration: 500, from: '1px', to: '100%', toggle: true, finish: afterslide});
}