

// Display OAList
function displayOAList(ctrlId)
{
    try
    {		
        var divObj=document.getElementById(ctrlId);
		if(ctrlId.toLowerCase()=="divddl")
		{
			divObj.innerHTML=this.ddlOAList;
		}
		else if(ctrlId.toLowerCase()=="divoalist")
		{
			divObj.innerHTML=this.OAlisthtml;
		}
        
    }
    catch(ex){
    }
}

// Return Generic Values as per passed key to the function
function returnGenericValue(key)
{    
    var GenInfo;
    var ListValues= genericList.split('|');                        
    for (var c=0;c<ListValues.length;c++)
    {
        if (ListValues[c].toString().length > 0)
        {
            GenInfo = ListValues[c].split('{}');                
            if(GenInfo[0].toLowerCase()==key)
            {
                break;
            }
        }
    }
    return GenInfo[1];
}

// Set print Image,Landing Page Image and cl_generic values like page title etc
function setGenericValues()
{
    try
    {          
    // Generic Values       	
        var GenInfo;
        var ListValues= this.genericList.split('|');		
        for (var c=0;c<ListValues.length;c++)
        {		
            if (ListValues[c].toString().length > 0)
            {				
                GenInfo = ListValues[c].split('{}');				
                var obj=document.getElementById(GenInfo[0].toLowerCase());				
                if(obj!=null)
                {
                obj.innerHTML=GenInfo[1];                
                }
            }
        }
		// set blank text in unaids priority
        var priorityObj=document.getElementById("unaids_priority_title");
        if(priorityObj !=null)
        {
            priorityObj.innerHTML="";
        }
        // set download image on the page
        var printObj=document.getElementById("showPrint");		
        if(printObj!=null)
        {	
			printObj.setAttribute("src",this.sLngImgsFolder+"Butt-download-openpopup-idle.png"); 		
        }
                    
        // set image on map component's place while it's loading.
        var loadImgObj=document.getElementById("ImgIDformap");
        if(loadImgObj!=null)
        {
			loadImgObj.setAttribute("src",this.ImageFolder+"circle_ball.gif"); 
        }
                     
        // Load Landing Page Image at the bottom
        var lngImgObj=document.getElementById("def_Img");
        if(lngImgObj!=null)
        {		
			lngImgObj.src=this.sLngImgsFolder+"defcfsimg.gif";
			lngImgObj.style.display="block";
			//lngImgObj.setAttribute("src",this.sLngImgsFolder+"defcfsimg.gif"); 			
        }        
        
        // Set the target for compare countries webpage
        var a_flink1=document.getElementById("a_AidsInfo");        
        if(a_flink1!=null)
        {
			var path="http://www.aidsinfoonline.org"
			a_flink1.setAttribute("href",path);
			a_flink1=document.getElementById("navigateMenuDB");
			a_flink1.setAttribute("href",path);
        }
        
        // Set the target for AIDS Info webpage
        var a_flink2=document.getElementById("a_CountryProfile");
        if(a_flink2!=null)
        {
			var path="factsheet.htm?lng_code="+this.lngcode;
			a_flink2.setAttribute("href",path);
			a_flink2=document.getElementById("navigateMenuCFS");
			a_flink2.setAttribute("href",path);
        }
        
        // Set the target for country factsheet webpage
        var a_flink3=document.getElementById("a_ComapreCountries");        
        if(a_flink3!=null)
        {
			var path="CompareCountry.htm?lng_code="+this.lngcode;
			a_flink3.setAttribute("href",path);
			a_flink3=document.getElementById("navigateMenuCC");
			a_flink3.setAttribute("href",path);
        }
        
       $("#divLandingPage").fadeTo("slow", 0.5);
    }    
    catch(ex){
    }
}


// get Country name using Area Id

function getCountryName(id)
{
    var AreaName="";
    try
    {    
        var ListValues; 
        var CodeName;        
        var AreaCodeName= AreaIDName.split('|');
        for (var c=0;c<AreaCodeName.length;c++)
        {
            if (AreaCodeName[c].toString().length > 0)
            {
                CodeName= AreaCodeName[c].split('{}');                
                if(CodeName[0]==id)
                {
                    AreaName=CodeName[1];					
                    break;
                }
            }
        }
     }
     catch(ex){
     }
     return AreaName;
}

// Auto export images for all countries
var IsFirstTimeExport=true;
var NoOfReadySwf;
function autoExportImages()
{    
    try
    { 
		var IsExported=false;
        var ListValues; 
        var CodeName;        
        var AreaCodeName= AreaIDName.split('|');
        for (var c=0;c<AreaCodeName.length;c++)
        {
            if (AreaCodeName[c].toString().length > 0)
            {
                CodeName= AreaCodeName[c].split('{}');				                
				if(this.IsFirstTimeExport)
				{
					this.IsFirstTimeExport=false;
					this.ctryID=CodeName[0];
					//this.NoOfReadySwf=0;
					this.exportImgcount=0;
					this.selectCountry(this.ctryID);
					this.showDiv("divProcess");						
					this.exportStart();					
					return;
				}
				else
				{
					if(CodeName[0]==this.ctryID)
					{
						IsExported=true;
						continue;
					}
					if(IsExported)
					{
						this.ctryID=CodeName[0];
						//this.NoOfReadySwf=0;
						this.selectCountry(this.ctryID);
						this.exportImgcount=0;
						this.showDiv("divProcess");						
						this.exportStart();											
						return;
					}
				}                
            }			
        }		
     }
     catch(ex){
     }     
}






 //for country selection 
 var IsCountrySelected="f";
 // Execute whenever country is selected on map flash component.
function selectCountry(id)
{
	//alert (this.ctryID);
    try
    {       
       this.ctryID=id;       
       // after country selection first time.
       if(this.IsCountrySelected=="f")
       {
			// Enable the OA List
			EnableOAList();
			// Set the hover effect on OA Menu List.
			setHoverEffect();
			// It shows that country has selected once.
			this.IsCountrySelected="t";			
			// Load OAs, getting form QueryString
            if(this.QS_OAs!="null")
            {
                this.loadRequiredOAs();
            }
			else
			{
				
				// Load Default OAs only when no country has been sent from the QueryString
				var ctryIDInQS=this.queryStringValue("country_id").toUpperCase();

				if(ctryIDInQS=="NULL")
				{
					// Load Default OA component(Country Overview).
//ALI: Only load default components if it is the main cfs page, not country profile, to prevent loading of the country overview panel.
//					LoadDefaultComponent();
/////////////////////////////////////////////////////////////////////////
				}
			}
       }
       // pass country id to all shown OA component.       
       passCtryidToOA("divswoxpMovie");       
    }
    catch(ex){ 
    }    
}

function EnableOAList()
{
	// Remove faded effect from OA Menu List
	$("#divLandingPage").fadeTo("slow", 1);
	// Hide the image from bottom.
	$("#def_Img").hide();
	// Show the OA component
	$("#divComponent2").show();
	// Remove the hover effect for default slogan
	document.getElementById("divLandingPage").onmouseleave="";       
	// set text on unaids priority
	document.getElementById("unaids_priority_title").innerHTML=this.returnGenericValue("unaids_priority_title");           
	document.getElementById("def_slogan").innerHTML="";

}

       
        
// Display corresponding slogan on right portion of OAList while mouse pointer goes on OAList's Items
    function showSlogan(sOAText, sSlogan, event)
    {
        try
        {
            var oSlogan=document.getElementById("def_slogan");
            oSlogan.innerHTML=sSlogan.replace("#","'");                    
        }
        catch(ex){  
        }
    }
    
// Display Default Slogan
function ShowDefaultSlogan()
{
    try
    {
        var ListValues; 
        var GenInfo;
        var ListValues= genericList.split('|');                
        for (var c=0;c<ListValues.length;c++)
        {
            if (ListValues[c].toString().length > 0)
            {
                GenInfo = ListValues[c].split('{}');                
                if(GenInfo[0].toLowerCase()=="def_slogan")
                document.getElementById(GenInfo[0].toLowerCase).innerHTML=GenInfo[1];                
            }
        }
    }
    catch(ex){
    }
}    
    
    
// Code for selection or deselection theme & call the unload function.

    function ShowHideOA(mode,OAid,sTitle)
    {
        try
        {
            if(this.IsCountrySelected=="f")
            {
				alert("Select a country");
				return;
            }
            var imgID;
            var anchorID;
            var classSel;
            var classnormal;
                        
            // Select All handling            
            if (OAid == "ALL")
            {
                SelectAllOA();
                return;
            }
            
            imgID='imgClose_' + OAid;
            anchorID='td_' + OAid;
            classSel = "menu2_selected";
            classnormal = "menu2";
            
            if(OAid=='OA1' || OAid=='OA2')
            {
				classSel = "menu1_selected";
				classnormal = "menu1";
            }
            
            if(document.getElementById(imgID).style.display=="none" && mode=='S')
            {
                // Show Close icon
                document.getElementById(imgID).style.display="block";            
                // Show selected color
                document.getElementById(anchorID).className=classSel;
                // Show the OA Component               
                loadComponent(OAid,sTitle);  
                                                
            }
            else if(mode=='H')
            {
                // Hide Close icon
                document.getElementById(imgID).style.display="none";            
                // Show normal color
                document.getElementById(anchorID).className=classnormal;             
                // Hide the OA Component
                UnloadComponent(OAid);
            }   
            
        }
        catch(ex){    
        }                                   
    }

    
// Load Default Components
    function LoadDefaultComponent()
    {    
        try
        {
            var D_ComsInfo; 
            var D_Coms= strDefaultComponent.split('|');
            
            for (var cc=0;cc<D_Coms.length;cc++)
            {
                if (D_Coms[cc].toString().length > 0)
                {
                    D_ComsInfo = D_Coms[cc].split('{}');
                    ShowHideOA('S',D_ComsInfo[0],D_ComsInfo[1]);
                }
            }
         }
         catch(ex){   
         }
    }


// Code for select all option displayed in OAList.

    function SelectAllOA()
    {
        try
        {
            var OAInfo; 
            var OAListitem = OAList.split('|');
            
            for (var cc=0;cc<OAListitem.length;cc++)
            {
                if (OAListitem[cc].toString().length > 0)
                {
                    OAInfo = OAListitem[cc].split('{}');
                    ShowHideOA('S',OAInfo[0],OAInfo[1]);
                }
            }
         }
         catch(ex){    
         }
    }
        
    
 // Code for set hover effect over  OAList.

    function setHoverEffect()
    {
        try
        {
        var OAInfo; 
        var OAListitem = fullinfo.split('|');                            
        for (var cc=0;cc<OAListitem.length;cc++)
           {
				if (OAListitem[cc].toString().length > 0)
				{
					 OAInfo = OAListitem[cc].split('{}');             
					 var oldStr="onmouseout=\"outClass('td_"+OAInfo[0]+"');\"";
					 var newStr=oldStr+" onmouseover=\"hoverClass('td_" + OAInfo[0] + "');\"";
					// alert("Old Str: "+oldStr+"\nNew Str: "+newStr);
					 OAlisthtml=OAlisthtml.replace(oldStr,newStr);             
					 oldStr="onclick='javascript:ShowHideOA(\"S\",\"" + OAInfo[0] + "\",\"" + OAInfo[1].replace("'","#") + "\")'";
					 newStr=oldStr+" onmouseover='javascript:showSlogan(\"" + OAInfo[1].replace("'","#") + "\",\"" + OAInfo[2].replace("'","#") + "\",event)'";
					 OAlisthtml=OAlisthtml.replace(oldStr,newStr);             
				 }
            }   
               
         var divObj=document.getElementById("divOAList");    
         divObj.innerHTML=OAlisthtml;		
         }
         catch(ex){    
         }
    } 
    
    
    
    //onmouseover=\"hoverClass(\\'td_" + OAItem[0] + "\\');\" 
    
// Unload a flash component but actually this function hides the component.   
    
function UnloadComponent(id)
{
    try
    {
		// var isExist=document.getElementById(id+"_1");
		var isExist=$("#"+id+"_1");
        if(isExist)
        {
	        isExist.slideToggle();
        }
    }
    catch(ex){ 
    }
}


// Create a flash component list dynamically & call the load function

function loadComponent(id,sTitle)

{
    try
    {
		sTitle=sTitle.replace("#","'");
        var isExist=document.getElementById(id+"_1");
        if(!isExist)
        {
            var name=new String();                        
            path=Flashfilepath;
            //path+="/"+filename+".swf";         
            path+="/OA.swf";         
            name=id + "_1";
            var obj=document.getElementById('divComponent2').childNodes[0];                                 
            var newinnerhtml;                       
                newinnerhtml="<li id='"+name+"' class='ui-state-default'><table class='outcome_component' style='border:1px solid #c4c1b9;' width='100%' cellspacing='0' cellpadding='0'>"+
                "<tr><td class='component_header' width='886px'>" + sTitle + "</td>"+
                "<td class='component_header' width='40px'><img id='Imgclose_"+name+"' src='"+ImageFolder+"close_panel.png' onclick=\"javascript:ShowHideOA('H','" + id + "');\" style='cursor:pointer' alt='Close' /></td>"+                
                "<td class='component_header' width='40px'><div id='draghandle-"+name+"' class='dd-handle'><img id='Imgdrag_"+name+"' src='"+ImageFolder+"drag.png' onmouseup=\"javascript:passCtryidToOA('IE');\" style='cursor:move' alt='Drag' /></div></td>"+                
                "<tr><td colspan='3' valign='top'>"+
                "<div style='padding-left:8px;' id='divParent"+id+"' align='center'> <div id='div"+id+ "'><img src='"+ImageFolder+"circle_ball.gif' alt='' /></div><div></td>"+ 
                "</td>"+
                "</tr></table></li>";
                
            // add OA component at the top of the list.                
            $("#ul1").prepend(newinnerhtml);
            $("#"+id+"_1").hide();
            // Load the Flash file            
            setTimeout("loadFlash('"+path+"','"+id+"','906px','197px')",2000);            
            $("#"+id+"_1").slideToggle();
        }

        else
        {                              
            // show the LI on the top of list 
            // Index of selected Li                     
            var curliIndex= $("#ul1 li").index(isExist);                                    
              // only proceed if it's not already on top
              if(curliIndex > 0) {
                // top LI                   
                
                    for(var index=curliIndex;index>0;index--)
                    {                
                        var temp = $("#ul1 li").get(index).outerHTML;
                        var PrevItem = $("#ul1 li").get(index-1).outerHTML;
                        $("#ul1 li").get(index).outerHTML=PrevItem;
                        $("#ul1 li").get(index-1).outerHTML=temp;                        
                    }
                   if(navigator.appName=="Microsoft Internet Explorer")
                   {                              
                        for(var index=curliIndex;index>=1;index--)
                        {
							var LiID= $("#ul1 li").get(index).id;                       
							var OAid=LiID.replace("_1","");
							setTimeout("loadFlash('"+path+"','"+OAid+"','906px','197px')",1000);            
                        }
                   }                          
                } 
//                alert(document.getElementById(id+"_1").innerHTML);
                setTimeout("loadFlash('"+path+"','"+id+"','906px','197px')",1000); 
                $("#"+id+"_1").slideToggle();                     
         }                         
    }
    catch(ex){
    }    
}

// Replace target.innerHTML
function replaceSwfWithEmptyDiv(targetID,childID)
{
	var el = document.getElementById(targetID);
	if(el)
	{
		el.innerHTML="<div id='"+childID+"' align='center'></div>";
	}
}



// Load flash component as per defined parameters
function loadFlash(filepath,ID,W,H)
{
    try
    {         			
        // contains swf file path, width, height and SWF file ID
        // Baseurl: asolute url to root folder, configXML: releative url to matadatafile
        // both parameters are very necessary for each SWF component.
        if(ID=="swoxpMovie")
        {
			// MAP						
			var flashvar = {baseURL:this.baseURL,configXML: this.MDFilename, dataURL:this.dataFldr, areaConfigURL:this.FlashConfigFldr, fontURL: this.fontURL}
			//var flashvar = {flashvars: "baseURL="+ this.baseURL+"&configXML="+ this.MDFilename, menu: 'false',wmode:'transparent',play: 'false',loop: 'true',pluginspage:'http://adobe-flash-player.en.softonic.com/download#pathbar'};
        }
        else
        {
			// OAs
			replaceSwfWithEmptyDiv("divParent"+ID,"div"+ID);
			var flashvar = {baseURL:this.baseURL,configXML: this.MDFilename,areaID: ID, dataURL:this.dataFldr, areaConfigURL:this.FlashConfigFldr, fontURL: this.fontURL}
			//var flashvar = {flashvars: "baseURL="+ this.baseURL+"&configXML="+ this.MDFilename + "&areaID="+ ID, menu: 'false',wmode:'transparent',play: 'false',loop: 'true',pluginspage:'http://adobe-flash-player.en.softonic.com/download#pathbar'};
        }                      
       // var attr={data:filepath,width:W,height:H,id:ID};
        var attr={id:ID};
        var param= {wmode:'transparent',pluginspage:'http://www.adobe.com/go/getflashplayer'};        
        
        // Create a SWF object Dynamically.		
        ID="div"+ID;                       		
       // swfobject.createSWF(attr,flashvar,ID);              
        swfobject.embedSWF(filepath,ID,W,H,"10.0.0","expressInstall.swf",flashvar,param,attr);
     }
     catch(ex){      
     }          
}



// this method is callled after loading SWF file successfully.
// pass the country Id to the component

function swfReady(OAid)
{    
    try
    {				
		var swfObj=swfobject.getObjectById(OAid);
		if(swfObj)
		{
			swfObj.selectCountry(this.ctryID);
		}


		// Handling direct link to open a country page
		// Show Country selected in the Map component
		var ctryIDInQS=this.queryStringValue("country_id").toUpperCase();
//ADDED BY ALI.20110110
if (this.preset_country_id) {
ctryIDInQS = preset_country_id;
this.ctryID = preset_country_id;
this.selectCountry(this.ctryID);
}
///////////////////////
		if(ctryIDInQS!="NULL")
		{

			var swfObj1=swfobject.getObjectById("swoxpMovie");
			if(swfObj1)
			{
				swfObj1.selectCountry(this.ctryID);
			}
		}
	
	}
    catch(ex){   
    }
}

// load OAs, getting form querystring
function loadRequiredOAs()
{    
    var OAs=this.QS_OAs.split(',');    
    var OAInfo; 
    var OAListitem = OAList.split('|');
	for(var OAsIndex=0;OAsIndex<OAs.length;OAsIndex++)
    {   		
		for (var cc=0;cc<OAListitem.length;cc++)
		{
			if (OAListitem[cc].toString().length > 0)
			{			
				OAInfo = OAListitem[cc].split('{}');								
				if(OAs[OAsIndex].toString().length>0 && OAs[OAsIndex].toLowerCase()==OAInfo[0].toLowerCase())
				{
					ShowHideOA('S',OAInfo[0],OAInfo[1]);                    
				}            
			}
		}
	}
}


// start load as per requirement whether default component should be loaded or not.
function startloading(status)
{
    try
    {     		
        //alert(Flashfilepath);
		// Load Map Flash Component
        loadFlash(Flashfilepath+"/mapview.swf",'swoxpMovie','422px','286px');     
        // Drag and Drop using Jquery    
        $(function() {	        	        	
			$( "#ul1" ).sortable({handle:'.dd-handle'});		
			$("#ul1").disableSelection();			    	
	    });
	    // End Drag and Drop using Jquery    	   	   
        // Load all OA components if user is admin;
        if(this.Admin=="t")
        {
			selectCountry(this.ctryID);
			SelectAllOA();
        } 
		// Load OAs, getting form QueryString		
		var ctryIDInQS=this.queryStringValue("country_id").toUpperCase();
		if(ctryIDInQS!="NULL")
        {
			this.selectCountry(this.ctryID);
        }

        // Load default OA Components
        if(status)
        {
            LoadDefaultComponent();
        }        
    }
    catch(ex){ 
    }
}

function showDiv(DivID)
{

    if(DivID=="divProcess")
    {
        document.getElementById("export_generating_pdf").style.display="block";
    }
    $("#"+DivID).css("position","absolute");
    $("#"+DivID).css("left",(screen.width/2-100)+"px");
    $("#"+DivID).css("top","190px");
    document.getElementById(DivID).style.zIndex=1200;
    document.getElementById("export_generating_pdf").innerHTML= returnGenericValue("export_generating_pdf")+" "+getCountryName(this.ctryID)+"...";        
    $("#"+DivID).fadeTo("slow",1);
}


var targetEPI="";
var targetSelected="";
var targetfullcfs="";
var exportImgcount=0;
// display a export to PDF option in child window
function goToPrintOption()
{
 // If country is not selected on the map component	
    if(this.IsCountrySelected=="f")
    {
        return;
    }
    // If Administrator
    if(this.Admin=="t")
    {
		if(this.ctryID=="NULL")
		{		
			this.autoExportImages();
		}
		else
		{
					//this.NoOfReadySwf=0;
					this.selectCountry(this.ctryID);
					this.showDiv("divProcess");
					this.exportImgcount=0;
					this.exportStart();
		}
    }
    // If Normal User(Pdf Download Option)
    else
    {        
        // get position to open child window.
                      
        var posx = screen.width/2-100;
	    var posy = screen.height/2-100;

	    // find the displayed OA component List                    
        var OAInfo;            
        var OAsListItem= OAList.split('|');        
        // Displayed OA component without any order;
        var DisplayedComponent="";         
        var AllOAItems="";           
        var footerInfo="";
        for (var cc=0;cc<OAsListItem.length;cc++)
        {
            if (OAsListItem[cc].toString().length > 0)
            {
                OAInfo = OAsListItem[cc].split('{}');                
                AllOAItems+=OAInfo[0]+"{}";                   
                var temp=this.returnNotes(OAInfo[0]);
                temp=replaceAll(temp,"&lt;br&gt;&lt;/br&gt;","");
                temp=replaceAll(temp,"&lt;","<");
                temp=replaceAll(temp,"&quot;","\"");
                temp=replaceAll(temp,"&gt;",">");
                footerInfo+=temp+"{}";
                if(document.getElementById("imgClose_"+OAInfo[0]).style.display=="block")
                {
                   DisplayedComponent+=OAInfo[0]+"|";
                }
             }
        }        
        // get OA Components Order in list            
        var list= document.getElementById("ul1");		        
        // contain components's name by order including hide component
	    var componentOrder="";
	        
	    if(list.childNodes.length > 0)
	    {	        	        	        
	        for(var itemIndex=0; itemIndex < list.childNodes.length; itemIndex++)
	        {	           
	            componentOrder += list.childNodes[itemIndex].getAttribute("id") + ("{}");
	        }
	    }	     
           // make a target URL with some query string needed for generating a PDF Document.               
        this.targetSelected="country_id="+this.ctryID+ "&lng_code="+ this.lngcode + "&AllOAitems="+AllOAItems
		+"&LoadedOAItems="+componentOrder+"&VisibleOAItems="+DisplayedComponent;
		this.targetfullcfs="country_id="+this.ctryID+ "&lng_code="+ this.lngcode + "&AllOAitems="+AllOAItems;
        this.targetEPI="country_id="+this.ctryID+ "&lng_code="+ this.lngcode;
        $("#imgclosedownload").attr("src",ImageFolder+"close_panel.png");		
        for(var i=1;i<4;i++)
        {
            $("#imgoption"+i).attr("src",ImageFolder+"checkbox-inactive.jpg");
        }
        $("#pdfBtn").attr("src",sLngImgsFolder+"butt-download-pdf-idle.jpg");       
        $("#divDownload imgclosedownload").show();
                        
        this.IsSelected=="f";
        this.selectedOption="no";
        //$("#divDownload").fadeTo("slow",1);
        this.OpenPopup();
        document.getElementById("export_generating_pdf").style.display="none";                 
    }    
}


// pass selected country id to all displayed OA Component.
function passCtryidToOA(srcName)
{
     var OAinfo=null; 
     var OAsListItem= OAList.split('|');                   
         for (var cc=0;cc<OAsListItem.length;cc++)
         {
			   if (OAsListItem[cc].toString().length > 0)
			   {
					OAInfo = OAsListItem[cc].split('{}');                       
					// check each OA component whether it is displayed or not
					if(document.getElementById("imgClose_"+OAInfo[0]).style.display=="block")
					{            
						var obj= swfobject.getObjectById(OAInfo[0]);                                    
						if(srcName=="IE" && navigator.appName=="Microsoft Internet Explorer")
						{
						   setTimeout("loadFlash('"+path+"','"+OAInfo[0]+"','906px','237px')",1000);
						}
						else
						{
						   // Call Select Country method of OA component to refelect the data in OA component.                                     
						   obj.selectCountry(this.ctryID);                   
						}
					}       
			   }
        }
}


function exportStart()
{	
    var OAinfo=null; 
    var OAsListItem= OAList.split('|');             
    if (OAsListItem[this.exportImgcount].toString().length > 0)
    {
        OAInfo = OAsListItem[this.exportImgcount].split('{}');
        var obj= swfobject.getObjectById(OAInfo[0]);		
        if(obj)
        {			
		    obj.exportBitmap(this.ExportMapURl+"?OAid="+OAInfo[0]+"&country_id="+this.ctryID+"&lng_code="+this.lngcode);
        }
    }       
}

// This function is called after bitmap data has been posted to frmExportToBitmap.aspx.
function exportDone() 
{
// Next OA Component 
    this.exportImgcount++;
    // After export all OA images
    if(this.exportImgcount==13)
    {   
		this.closeDiv("divProcess");
		if(IsFirstTimeExport)
		{
			//alert("Images have been exported.");
		}
		else
		{
			this.autoExportImages();
		}
    }
    // Next OA's image export
    this.exportStart();
}

// Delay for mumber of mileseconds.
function sleep(delay)
{    
    var start = new Date().getTime();
    while (new Date().getTime() < start + delay);
}




// load Motion Charts
function loadCharts(filepath)
{
    try
    {           
        // Baseurl: asolute url to root folder, configXML: releative url to matadatafile
        // both parameters are very necessary for each SWF component.
           var flashvar = {debug:1,baseURL:this.baseURL,configXML: this.MDFilename,dataURL:this.dataFldr,areaConfigURL:this.FlashConfigFldr}                                        
           var attr={id: 'chart'};
           var params = {menu: false,wmode: 'transparent',play: false,loop: true,pluginspage:'http://adobe-flash-player.en.softonic.com/download#pathbar'};      
           swfobject.embedSWF(filepath,'divChart','920','660','10.0.0','expressInstall.swf',flashvar,params,attr);
        
     }
     catch(ex){
     }
}



// put hover effect on OAList for IE
//when mouse pointer comes over the OAlist.
function hoverClass(ID)
{
    try
    {       
        if(ID=="td_OA1" || ID=="td_OA2"){
		document.getElementById(ID).className="menu1hovered";        
        }
        else{
        document.getElementById(ID).className="menu2hovered";
        }      
    }
    catch(ex){
    }
}

//when mouse pointer goes out from the OAlist.
function outClass(ID)
{
    try
    {
		var imgID=ID.replace("td_","imgClose_");    
		var imgObj=document.getElementById(imgID);
		// if no OA is selected.
		if(imgObj.style.display=="none")
		{   
			if(ID=="td_OA1" || ID=="td_OA2"){
			document.getElementById(ID).className="menu1";
			}
			else{    
			document.getElementById(ID).className="menu2";        
			}
		}
		// if OA is selected.
		else
		{
			if(ID=="td_OA1" || ID=="td_OA2"){
			document.getElementById(ID).className="menu1_selected";
			}
			else{    
			document.getElementById(ID).className="menu2_selected";
			}
		}
    }
    catch(ex){  
    }
}



// Display big image which is showing within OA Component.

function ShowCOBigImage()
{
//ALI: COMMENTED OUT TO REPLACE WITH LINE THAT LOADS FROM CFS FOLDER, FOR PRODUCTION.
//	window.open("BigImage.htm?ctry_name="+getCountryName(this.ctryID)+"&ImgPath="+this.sLngImgsFolder + this.ctryID + "/co_big.png","null","width=1024,height=800,left=0,right=0,scrollbars=1,_blank");
	window.open("/cfs/BigImage.htm?ctry_name="+getCountryName(this.ctryID)+"&ImgPath="+this.sLngImgsFolder + this.ctryID + "/co_big.png","null","width=1024,height=800,left=0,right=0,scrollbars=1,_blank");
}






// Hide Download div
function closeDiv(DivID)
{
    $("#"+DivID).fadeTo("slow",0);
    if(DivID=="divDownload")
    {
        $("#"+DivID+" imgclosedownload").hide();
    }
    else if(DivID=="divProcess")
    {    
        document.getElementById("export_generating_pdf").style.display="none";
    }        
    setTimeout(function(){document.getElementById(DivID).style.zIndex=0},1000);    
}


// Change img of pdfButton for hovereffect
function changeDownloadImage(source,IsHover)
{
    var imgName;
    if(source.id=="pdfBtn" && IsHover=='t')
    {
        imgName="butt-download-pdf-rollover.jpg";
    }
    else if(source.id=="pdfBtn" && IsHover=='f')
    {
        imgName="butt-download-pdf-idle.jpg";
    }
    else if(source.id=="showPrint" && IsHover=='t')
    {
        imgName="Butt-download-openpopup-rollover.png";
    }
    else if(source.id=="showPrint" && IsHover=='f')
    {
        imgName="Butt-download-openpopup-idle.png";
    }
    var btnObj=document.getElementById(source.id);	
    btnObj.setAttribute("src",this.sLngImgsFolder+imgName);
}

// set information for pdf document 

function sendInfoForPdf()
{

	if(this.selectedOption !="imgoption1" && this.selectedOption !="imgoption2" & this.selectedOption !="imgoption3")
    {
        return;
    }
    var pdfURL="http://158.232.15.29/CFS/downloadpdf.htm";  //"http://92.52.112.217/downloadpdf.htm";
    var option="";
    var PdfDocDetails="";
    if(this.selectedOption =="imgoption1")
    {
        PdfDocDetails=this.targetSelected
        option="selecteditems";
    }
    else if(this.selectedOption =="imgoption2")
    {
        PdfDocDetails=this.targetfullcfs;
        option="fullcfs";
    }
    else if(this.selectedOption =="imgoption3")
    {
        PdfDocDetails=this.targetEPI;
        option="epi";
    }      
    PdfDocDetails+="&pdfoption="+option;
    pdfURL+="?"+PdfDocDetails; 
	window.open(pdfURL,"null","width=500,height=400,left=0,right=0,scrollbars=1,_blank");
}


var selectedOption="no";
var IsSelected="f";
// check/uncheck the pdf option
function ImageToggle(source)
{
    var Img;
    var i;
    //if any option is check then uncheck
    for(i=1;i<4;i++)
    {
         Img = $("#imgoption"+i).attr("src");
         Img=Img.substr(Img.lastIndexOf("/")+1);
         if(Img=="checkbox-active.jpg")
            {
				 $("#imgoption"+i).attr("src",this.ImageFolder +"checkbox-inactive.jpg");
				 break; 
			}
    }
    // check the selected option
    selectedOption=source.id;
    var FullimgName= source.src;
    var imgName=FullimgName.substr(FullimgName.lastIndexOf("/")+1);
    if(imgName=="checkbox-inactive.jpg")
    {
        source.src=FullimgName.replace(imgName,"checkbox-active.jpg");
    }
    $("#hl").hide();
    this.IsSelected="t";
}

// Return notes as per OAid
function returnNotes(OAid)
{
	var notes="";
	var OAinfo=null; 
	var OAListitem = fullinfo.split('|');
    for (var cc=0;cc<OAListitem.length;cc++)
    {
       if (OAListitem[cc].toString().length > 0)
       {
          OAInfo = OAListitem[cc].split('{}');             
          if(OAInfo[0]==OAid)
          {
				notes=OAInfo[3];
				break;
          }
       }
    } 
return notes;  
}
   

// Information Icon
function infoButtonPressed(OAid)
{
	var IpopObj=document.getElementById("divCallout");
	if(IpopObj.style.display == "block")
	{
		IpopObj.style.display="none";	
	}
    var objLI;
    objLI = document.getElementById(OAid + "_1");
	var curleft = curtop = 0;
	if (objLI.offsetParent) 
	{
	    do {
			curleft += objLI.offsetLeft;
			curtop += objLI.offsetTop;
	       } while (objLI = objLI.offsetParent);
	}

    //alert("Left: " + curleft + "\n" + "Top: " + curtop);

    var note=returnNotes(OAid);
    note=replaceAll(note,"&lt;br&gt;&lt;/br&gt;","<br />")
    note=replaceAll(note,"&lt;","<");
    note=replaceAll(note,"&quot;","\"");
    note=replaceAll(note,"&gt;",">");
    //note=replaceAll(note,"&lt;/a&gt;","</a>");
    ShowCallout(note,OAid,curleft,curtop);
    
    
}


// Replace all occurence of substring in string

function replaceAll(txt, replace, with_this) 
{  
    return txt.replace(new RegExp(replace, 'g'),with_this);
}

// Select an item from dropdown list in comparecountry.aspx

function selectedValue(item)
{
	var parentObj= document.getElementById("innertd1");
	var childObj= document.getElementById("td_"+item);
	parentObj.innerHTML= childObj.innerHTML;
	//this.hideItems();
	var chartObj=document.getElementById('chart');
	chartObj.selectOutcomeArea(item);
}

// remove the iPopup
function removeIpopup(e) 
{
    if(e.srcElement.id!="divCalloutText")
    {
		 HideCallout(); 
    }
 }
 
 // hide & show the dropdown element for all browser(compare country)
function showOrhideElement(e)
{
    var srcEl = e.srcElement? e.srcElement : e.target;	
    if(srcEl.id=="innertd1" || srcEl.id=="innertd2" || srcEl.id=="ddlimg")
    {	
        this.showItems();
    }
    else
    {
        this.hideItems();
    }
}

function hideItems()
{  
	ItemsId="td_OA";
    for(var i=2;i<13;i++)
    {
		var obj;
		obj=document.getElementById(ItemsId+i);
		obj.style.display="none";
    }
}   

    
function showItems()
{
	ItemsId="td_OA";
	for(var i=2;i<13;i++)
	{
		var obj;
		obj=document.getElementById(ItemsId+i);
		obj.style.display="block";
	}
}

// Infomation while click on InfoButton on OAs
function ShowCallout(toolTip, src, curLeft, curTop)
{  
    var divCallout = document.getElementById("divCallout");
    divCallout.style.left=(curLeft + 926 - 470) + "px";
    divCallout.style.top=(curTop+210) + "px";
    document.getElementById("divCalloutText").innerHTML = toolTip;
    if(divCallout.style.display != "block")
    {
       divCallout.style.display = "block";             
    }
}

function HideCallout()
{
    try{    
        document.getElementById("divCallout").style.display = "none";            
    }
    catch(ex){
        alert("Error: HideCallout()");
    }
}

// Inactive page while clicking on download button

function ApplyMaskingDiv()
	{   
		var MaskedDiv =  document.getElementById('MaskedDiv');
		
		if(MaskedDiv)
		{
			// include a temporary iframe to make the ddl invisible/un-accessible
			var iFrameHtml = "<iframe style='position: absolute; display: block; background-color: #ffffff; " +
								"z-index: -1; width: 100%; height: 100%; top: 0; left: 0; filter: mask();' >" + "</iframe>";                                        
								  
			// Masking the whole screen    
			if(window.ActiveXObject){
				MaskedDiv.innerHTML += iFrameHtml;
			}            
			MaskedDiv.style.display = '';
			MaskedDiv.style.visibility = 'visible';
			MaskedDiv.style.top = '0px';
			MaskedDiv.style.left = '0px';
			MaskedDiv.style.width = "100%"; //document.documentElement.clientWidth + 'px';    
			MaskedDiv.style.height = "100%"; //document.documentElement.clientHeight+ 'px';        
		}
	}
 
	function RemoveMaskingDiv()
	{    
		var MaskedDiv = document.getElementById('MaskedDiv'); 
	   
		if(MaskedDiv)
		{
			// Remove the masking from the screen    
			MaskedDiv.style.display = 'none';
			MaskedDiv.innerHTML = "";
		}
	}
 
	function OpenPopup()
	{
		var divPopup = document.getElementById("divDownload");
		if(divPopup)
		{
			ApplyMaskingDiv();
			GetWindowCentered(divPopup,200,200);
			divPopup.style.display = 'block';
		}
		return false;
	}
 
	function ClosePopup()
	{
		var divPopup =  document.getElementById("divDownload");
 
		if(divPopup)
		{
			divPopup.style.display = 'none';	
		}
		RemoveMaskingDiv();		
		return false;
	}
 
	function GetWindowCentered(ctlPopup, popupWidth, popupHeight)
	{
		var availHeight = 0;
		var availWidth = 0;
		
		if(typeof(window.innerWidth) == 'number'){
			availHeight = window.innerHeight;
			availWidth = window.innerWidth;
		}else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
			availHeight = document.documentElement.clientHeight;
			availWidth = document.documentElement.clientWidth;
		}else if(document.body && (document.body.clientWidth || document.body.clientHeight)){
			availHeight = document.body.clientHeight;
			availWidth = document.body.clientWidth;
		}
        //ADDED BY JO, TO FIX PROBLEM WITH DOWNLOAD BUTTON LOCATION
		var divMainBox = document.getElementById("Div1");
		var WinTop = divMainBox.offsetTop;
		
		if(WinTop <= 0) {
			WinTop = getTopPosition(divMainBox);
		}
		WinTop += 75;

		//var WinTop = (availHeight - popupHeight)/2;
		var WinLeft = (availWidth - popupWidth)/2;   

		//if(WinTop < 0) WinTop = 0;
		if(WinLeft < 0) WinLeft = 0;    
		
		ctlPopup.style.top = WinTop + "px";
		ctlPopup.style.left = WinLeft + "px";
	}
	
	function getTopPosition(obj){
    var topValue= 0;
    while(obj){
	topValue+= obj.offsetTop;
	obj= obj.offsetParent;
    }
    return topValue;
}

	// Once data has fully loaded
	
	function dataReady(OAId)
	{
		//alert("data ready: " + OAId);
		//if(this.Admin=="t")
		//{
		//	this.NoOfReadySwf++;
		//	if(this.NoOfReadySwf==12)
		//	{
		//		this.showDiv("divProcess");						
		//		this.exportStart();
		//	}
		//}
	}

	
		
