function catObject(id,title,icon_min,icon_edit,icon_close,helpURL,list,scheme,hasJs) {
	this.id=id;
	this.title=title;
	this.icon_min=icon_min;
	this.icon_edit=icon_edit;
	this.icon_close=icon_close;
	this.helpURL = helpURL;
	this.list = list;
	this.scheme = scheme;
	this.hasJs = hasJs;
}
function searchCatObject(id,title,icon_min,icon_edit,icon_close,helpURL,list,scheme,hasJs,isContextOrHelp) {
	this.id=id;
	this.title=title;
	this.icon_min=icon_min;
	this.icon_edit=icon_edit;
	this.icon_close=icon_close;
	this.helpURL = helpURL;
	this.list = list;
	this.scheme = scheme;
	this.hasJs = hasJs;
	this.isContextOrHelp = isContextOrHelp;
}

function getDisplayIconHtml(icon,scheme) {
	var oppIcon = icon.match(/on/) ? icon.replace(/on/,'off') : icon.replace(/off/,'on');
	var color = getColorForScheme(scheme);
	var type = icon.replace(/_.*/,''); //edit_on.gif -> edit
	var alt = alt_texts[type];
	
	var iconClass = (type == "help") ? "portlet_header_help_icon" : "portlet_tool_icon";
	return "<img src='"+img_path+"icons/"+color+"/"+icon+"' title=\""+alt+"\" alt=\""+alt+"\" class='"+iconClass+"' onmouseover='changeIcon(this,\""+color+"/"+oppIcon+"\");' onmouseout='changeIcon(this,\""+color+"/"+icon+"\");' />";
}

function getDisplaySearchIconHtml(icon,scheme) {
	var oppIcon = icon.match(/on/) ? icon.replace(/on/,'off') : icon.replace(/off/,'on');
	var color = getColorForScheme(scheme);
	var type = icon.replace(/_.*/,''); //edit_on.gif -> edit
	var alt = alt_texts[type];
	
	var iconClass = "portlet_header_help_search_icon";
	return "<img src='"+img_path+"icons/"+color+"/"+icon+"' title=\""+alt+"\" alt=\""+alt+"\" class='"+iconClass+"' onmouseover='changeIcon(this,\""+color+"/"+oppIcon+"\");' onmouseout='changeIcon(this,\""+color+"/"+icon+"\");' />";
}

//  The following function the color for the given scheme
function getColorForScheme(scheme) {
	var color = "blue";
	if (scheme == "more") {
		color = "orange";
	} else if (scheme == "account" || scheme == "myaccount") {
		color = "red";
	} else if (scheme == "search") {
		color = "gray";
		} else if (scheme == "msd") {
		color = "green";
	}
		return color;
}

function container_header(subsID,dropDownValue,catObj,scheme, namedanchor) {
	document.write('<div id="header_' + subsID + '" class="portlet_header"><div '+namedanchor+' class="portlet_header_left_shadow">');
	contentarea[subsID] = subsID;	// init
	var title = catObj.title;
	var catObjName = "cat_"+subsID;
	var usrlocale = "";
	if (scheme == scheme_more && catObj.list != '') {
		title = '';
	}
	html ='<span id="title_' + subsID + '" class="portlet_header_title">' + title + '</span>';
	if (catObj.helpURL != '') {
		html += "<span class='portlet_header_help' id='help_"+subsID+"'>";
		if(getCookie("TIBCOSessionID") == null){
			page_locale=page_locale.substring(1,6);
			if(catObj.isContextOrHelp == 'true'){
  if(UserLocale == "en_GB"){
                                usrlocale = "en_GB";
                             html += "<a href='Javascript:goToCMSHelpCenter(\""+catObj.helpURL+"\",\""+usrlocale+"\");'>";
                             html += getDisplaySearchIconHtml('help_off.gif',catObj.scheme);}


else if((UserLocale == "da_DK")||(UserLocale == "hu_HU")||(UserLocale == "de_AT")||(UserLocale == "fi_FI")||(UserLocale == "es_ES")||(UserLocale == "no_NO")||(UserLocale == "fr_CH")||(UserLocale == "de_CH")||(UserLocale == "nl_NL")||(UserLocale == "en_CA")||(UserLocale == "fr_BE")||(UserLocale == "fr_CA")||(UserLocale == "sv_SE")||(UserLocale == "et_EE")||(UserLocale == "en_IN")||(UserLocale == "pt_PT")||(UserLocale == "de_DE")||(UserLocale == "tr_TR")||(UserLocale == "nl_BE")||(UserLocale == "en_ZA")||(UserLocale == "en_AE")||(UserLocale == "is_IS")||(UserLocale == "en_IE")||(UserLocale == "iw_IL")||(UserLocale == "it_IT")||(UserLocale =="fr_FR")){

                                 usrlocale = UserLocale;
            html += "<a href='Javascript:goToCMSHelpCenter(\""+catObj.helpURL+"\",\""+usrlocale+"\");'>";
            html += getDisplaySearchIconHtml('help_off.gif',catObj.scheme);}

else if((UserLocale == "en_PK")||(UserLocale == "en_LB")||(UserLocale == "en_SA")){

                               usrlocale = "en_AE";
                    html += "<a href='Javascript:goToCMSHelpCenter(\""+catObj.helpURL+"\",\""+usrlocale+"\");'>";
                    html += getDisplaySearchIconHtml('help_off.gif',catObj.scheme);}

 else if(page_locale == "en_GB"){
                                usrlocale = "en_GB";
                              html += "<a href='Javascript:goToCMSHelpCenter(\""+catObj.helpURL+"\",\""+usrlocale+"\");'>";
                                html += getDisplaySearchIconHtml('help_off.gif',catObj.scheme);}

else if((page_locale == "da_DK")||(page_locale == "hu_HU")||(page_locale == "de_AT")||(page_locale == "fi_FI")||(page_locale== "es_ES")||(page_locale == "no_NO")||(page_locale== "fr_CH")||(page_locale== "de_CH")||(page_locale== "nl_NL")||(page_locale == "en_CA")||(page_locale  == "fr_BE")||(page_locale  == "fr_CA")||(page_locale  == "sv_SE")||(page_locale  == "et_EE")||(page_locale  == "en_IN")||(page_locale == "pt_PT")||(page_locale == "de_DE")||(page_locale == "tr_TR")||(page_locale == "nl_BE")||(page_locale == "en_ZA")||(page_locale == "en_AE")||(page_locale == "is_IS")||(page_locale == "en_IE")||(page_locale =="iw_IL")||(page_locale == "it_IT")||(page_locale=="fr_FR")){


                                usrlocale = page_locale;
        html += "<a href='Javascript:goToCMSHelpCenter(\""+catObj.helpURL+"\",\""+usrlocale+"\");'>";
        html += getDisplaySearchIconHtml('help_off.gif',catObj.scheme);}

 else if((page_locale == "en_PK")||(page_locale == "en_LB")||(page_locale == "en_SA")){
                                usrlocale = "en_AE";
                  html += "<a href='Javascript:goToCMSHelpCenter(\""+catObj.helpURL+"\",\""+usrlocale+"\");'>";
                  html += getDisplaySearchIconHtml('help_off.gif',catObj.scheme);}


else
                {
                                html += "<a href='Javascript:goToHelpCenter(\""+catObj.helpURL+"\",\""+usrlocale+"\");'>";
                                html += getDisplaySearchIconHtml('help_off.gif',catObj.scheme);
                }
                }
else {
if(UserLocale == "en_GB"){
                                usrlocale = "en_GB";
                         html += "<a href='Javascript:goToCMSContextHelp(\""+catObj.helpURL+"\",\""+usrlocale+"\");'>";
                                html += getDisplayIconHtml('help_off.gif',catObj.scheme);}


else if((UserLocale == "da_DK")||(UserLocale == "hu_HU")||(UserLocale == "fi_FI")||(UserLocale == "es_ES")||(UserLocale == "de_AT")||(UserLocale == "no_NO")||(UserLocale == "fr_CH")||(UserLocale == "de_CH")||(UserLocale == "nl_NL")||(UserLocale == "en_CA")||(UserLocale == "fr_BE")||(UserLocale == "fr_CA")||(UserLocale == "sv_SE")||(UserLocale == "et_EE")||(UserLocale == "en_IN")||(UserLocale == "pt_PT")||(UserLocale == "de_DE")||(UserLocale == "tr_TR")||(UserLocale == "nl_BE")||(UserLocale == "en_ZA")||(UserLocale == "en_AE")||(UserLocale == "is_IS")||(UserLocale == "en_IE")||(UserLocale == "iw_IL")||(UserLocale == "it_IT")||(UserLocale=="fr_FR")){


        usrlocale = UserLocale;
       html += "<a href='Javascript:goToCMSContextHelp(\""+catObj.helpURL+"\",\""+usrlocale+"\");'>";}


else if((UserLocale == "en_PK")||(UserLocale == "en_LB")||(UserLocale == "en_SA")){
                   usrlocale = "en_AE";
      html += "<a href='Javascript:goToCMSContextHelp(\""+catObj.helpURL+"\",\""+usrlocale+"\");'>";}

else if(page_locale == "en_GB"){
                                usrlocale = "en_GB";
                     html += "<a href='Javascript:goToCMSContextHelp(\""+catObj.helpURL+"\",\""+usrlocale+"\");'>";
                     html += getDisplayIconHtml('help_off.gif',catObj.scheme);}


else if((page_locale == "da_DK")||(page_locale == "hu_HU")||(page_locale == "de_AT")||(page_locale == "fi_FI")||(page_locale== "es_ES")||(page_locale == "no_NO")||(page_locale== "fr_CH")||(page_locale== "de_CH")||(page_locale== "nl_NL")||(page_locale == "en_CA")||(page_locale  == "fr_BE")||(page_locale  == "fr_CA")||(page_locale == "sv_SE")||(page_locale  == "et_EE")||(page_locale  == "en_IN")||(page_locale  == "pt_PT")||(page_locale == "de_DE")||(page_locale == "tr_TR")||(page_locale == "nl_BE")||(page_locale == "en_ZA")||(page_locale == "en_AE")||(page_locale == "is_IS")||(page_locale == "en_IE")||(page_locale == "iw_IL")||(page_locale == "it_IT")||(page_locale == "fr_FR")){

                            usrlocale = page_locale;
          html += "<a href='Javascript:goToCMSContextHelp(\""+catObj.helpURL+"\",\""+usrlocale+"\");'>";
          html += getDisplayIconHtml('help_off.gif',catObj.scheme);}

 else if((page_locale == "en_PK")||(page_locale == "en_LB")||(page_locale == "en_SA")){
                                usrlocale = "en_AE";
                 html += "<a href='Javascript:goToCMSContextHelp(\""+catObj.helpURL+"\",\""+usrlocale+"\");'>";
                 html += getDisplayIconHtml('help_off.gif',catObj.scheme);}





else
                        {
                                html += "<a href='Javascript:goToContextHelp(\""+catObj.helpURL+"\",\""+usrlocale+"\");'>";

                                html += getDisplayIconHtml('help_off.gif',catObj.scheme);
                        }
                        }
                }
 else
                {
                        if(catObj.isContextOrHelp == 'true')
                {
                        if(UserLocale == "en_GB"){
                                usrlocale = "en_GB";
                        html += "<a href='Javascript:goToCMSHelpCenter(\""+catObj.helpURL+"\",\""+usrlocale+"\");'>";
                                html += getDisplaySearchIconHtml('help_off.gif',catObj.scheme);}

else if((UserLocale == "da_DK")||(UserLocale == "hu_HU")||(UserLocale == "de_AT")||(UserLocale == "fi_FI")||(UserLocale == "es_ES")||(UserLocale == "no_NO")||(UserLocale == "fr_CH")||(UserLocale == "de_CH")||(UserLocale == "nl_NL")||(UserLocale == "en_CA")||(UserLocale == "fr_BE")||(UserLocale == "fr_CA")||(UserLocale == "sv_SE")||(UserLocale == "et_EE")||(UserLocale == "en_IN")||(UserLocale == "pt_PT")||(UserLocale == "de_DE")||(UserLocale == "tr_TR")||(UserLocale == "nl_BE")||(UserLocale == "en_ZA")||(UserLocale == "en_AE")||(UserLocale == "is_IS")||(UserLocale == "en_IE")||(UserLocale == "iw_IL")||(UserLocale == "it_IT")||(UserLocale == "fr_FR")){

                                usrlocale = UserLocale; 
             html += "<a href='Javascript:goToCMSHelpCenter(\""+catObj.helpURL+"\",\""+usrlocale+"\");'>";
             html += getDisplaySearchIconHtml('help_off.gif',catObj.scheme);}

else if((UserLocale == "en_PK")||(UserLocale == "en_LB")||(UserLocale == "en_SA")){
                                usrlocale = "en_AE";
                          html += "<a href='Javascript:goToCMSHelpCenter(\""+catObj.helpURL+"\",\""+usrlocale+"\");'>";
                          html += getDisplaySearchIconHtml('help_off.gif',catObj.scheme);}



                        else
                        {
                                html += "<a href='Javascript:goToHelpCenter(\""+catObj.helpURL+"\");'>";
                            html += getDisplaySearchIconHtml('help_off.gif',catObj.scheme);
                        }
                }
   else
                        {
                                if(UserLocale == "en_GB"){
                                usrlocale = "en_GB";
                          html += "<a href='Javascript:goToCMSContextHelp(\""+catObj.helpURL+"\",\""+usrlocale+"\");'>";
                          html += getDisplayIconHtml('help_off.gif',catObj.scheme);}

else if((UserLocale == "da_DK")||(UserLocale == "hu_HU")||(UserLocale == "de_AT")||(UserLocale == "fi_FI")||(UserLocale == "es_ES")||(UserLocale == "no_NO")||(UserLocale == "fr_CH")||(UserLocale == "de_CH")||(UserLocale == "nl_NL")||(UserLocale == "en_CA")||(UserLocale == "fr_BE")||(UserLocale == "fr_CA")||(UserLocale == "sv_SE")||(UserLocale == "et_EE")||(UserLocale == "en_IN")||(UserLocale == "pt_PT")||(UserLocale == "de_DE")||(UserLocale == "tr_TR")||(UserLocale == "nl_BE")||(UserLocale == "en_ZA")||(UserLocale == "en_AE")||(UserLocale == "is_IS")||(UserLocale == "en_IE")||(UserLocale == "iw_IL")||(UserLocale == "it_IT")||(UserLocale == "fr_FR")){

                                usrlocale = UserLocale;
html += "<a href='Javascript:goToCMSContextHelp(\""+catObj.helpURL+"\",\""+usrlocale+"\");'>";
html += getDisplayIconHtml('help_off.gif',catObj.scheme);}

else if((UserLocale == "en_PK")||(UserLocale == "en_LB")||(UserLocale == "en_SA")){
                                usrlocale = "en_AE";
                      html += "<a href='Javascript:goToCMSContextHelp(\""+catObj.helpURL+"\",\""+usrlocale+"\");'>";
                      html += getDisplayIconHtml('help_off.gif',catObj.scheme);}

                      else
                           {
                        html += "<a href='Javascript:goToContextHelp(\""+catObj.helpURL+"\",\""+usrlocale+"\");'>";
                    html += getDisplayIconHtml('help_off.gif',catObj.scheme);
                                }
                }
                }	


		
		html += '</a></span>';
	}
	
	var listElements = catObj.list.split("."); // list type is expected to be module.list-name. Eg: SwapModule.MoreNews
	var module = listElements[0];
	var listName = listElements[1];
	var selectedValue = "this.value";
	
	// this code for selectedID
	var selectedID = dropDownValue;
	html += '<span id="tools_'+subsID+'" class="portlet_tools">';
	if (catObj.icon_close == "remove") {
		html += "<a href='javascript:void(0);' onclick=\"displayBlock('" + mod_close + "','','"+subsID+"',"+catObjName+",'');\">";
		html += getDisplayIconHtml('remove_off.gif',catObj.scheme);
		html += '</a>';
	}
	if (catObj.icon_min == "max") {
		html += "<a href='javascript:void(0);' onclick=\"displayBlock('" + mod_maximize + "','"+dropDownValue+"','"+subsID+"',"+catObjName+",'');\">";
		html += getDisplayIconHtml('max_off.gif',catObj.scheme);
		html += '</a>';
	} else if (catObj.icon_min == "min") {
		html += "<a href='javascript:void(0);' onclick=\"displayBlock('" + mod_minimize + "','"+dropDownValue+"','"+subsID+"',"+catObjName+",'');\">";
		html += getDisplayIconHtml('min_off.gif',catObj.scheme);
		html += '</a>';	
	}
	html += "</span>";
	html += "<span class='portlet_header_dropdown' id='dropdown_" + subsID + "'>";
	if (catObj.list != '' && catObj.list != 'null') {
		html += "<select id='select_"+subsID+"' onchange=\"displayBlock('"+module+"',"+selectedValue+",'"+subsID+"',"+catObjName+",'');\" >";

		i = groupIndex[listName];
		while ( i < categoryList.length && categoryList[i].name != "##DUMMY-CATEGORY##" ) {
			var item = categoryList[i].name;
			var itemval = categoryList[i].catId;
			if(itemval == selectedID) {
					html += '<option value="' + itemval + '" selected>' + item + '</option>';
			} else{
					html += '<option value="' + itemval + '">' + item + '</option>';
			}
			i++;
		}
		html += '</select>';
	}
	html += '</span>';
	document.write(html+'</div></div>');
}

function update_container_header(subsID,dropDownValue,catObj,scheme) {
	var title = catObj.title;
	if (scheme == scheme_more && catObj.list != '') {
		title = '';
	}

	// update the title first
	document.getElementById('title_' + subsID).innerHTML = unescape(title);

	var html = "";

	// update the help icon
	if (catObj.helpURL != '') {
		html = "<a href='"+catObj.helpURL+"'>";
		html += getDisplayIconHtml('help_off.gif',scheme);
		html += '</a>';
		document.getElementById("help_"+subsID).innerHTML = html;
	}
	html = "";
	var catObjName = "cat_"+subsID;
	if (catObj.icon_close == "remove") {//TODO: change mod_close to mod_remove
		html += "<a href='javascript:void(0);' onclick=\"displayBlock('" + mod_close + "','','"+subsID+"',"+catObjName+",''); \" >";
		html += getDisplayIconHtml('remove_off.gif',scheme);
		html += '</a>';
	}
	if (catObj.icon_min == "max") {
		//'maximize','','ssd23',catObj,''
		html += "<a href='javascript:void(0);' onclick=\"displayBlock('" + mod_maximize + "','"+dropDownValue+"','"+subsID+"',"+catObjName+",''); \" >";
		html += getDisplayIconHtml('max_off.gif',scheme);
		html += '</a>';
	}else if (catObj.icon_min == "min") {
		html += "<a href='javascript:void(0);' onclick=\"displayBlock('" + mod_minimize + "','"+dropDownValue+"','"+subsID+"',"+catObjName+",''); \" >";
		html += getDisplayIconHtml('min_off.gif',scheme);
		html += '</a>';
	}
	document.getElementById("tools_"+subsID).innerHTML = html;

	html = "";
	if (catObj.list != '' && catObj.list != 'null') {	

		var listElements = catObj.list.split("."); // list type is expected to be module.list-name. Eg: SwapModule.MoreNews
		var module = listElements[0];
		var listName = listElements[1];
		var selectedValue = "this.value";
	
		// this code for selectedID
		var selectedID = dropDownValue;
		html += "<select id='select_"+subsID+"' onchange=\"displayBlock('"+module+"',"+selectedValue+",'"+subsID+"',"+catObjName+",'')\" >";

		i = groupIndex[listName];
		while ( i < categoryList.length && categoryList[i].name != "##DUMMY-CATEGORY##" ) {
			var item = categoryList[i].name;
			var itemval = categoryList[i].catId;
			
			if(itemval == selectedID) {
					html += '<option value="' + itemval + '" selected>' + item + '</option>';
			} else{
					html += '<option value="' + itemval + '">' + item + '</option>';
			}
			i++;
		}
		html += '</select>';
	}
	document.getElementById("dropdown_" + subsID).innerHTML = html;
}
