// readCookie function -- START
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

// readCookie function -- END
// *********************************************
// HashTable function -- START

function Hash()
{
	this.length = 0;
	this.items = new Array();
	for (var i = 0; i < arguments.length; i += 2) {
		if (typeof(arguments[i + 1]) != 'undefined') {
			this.items[arguments[i]] = arguments[i + 1];
			this.length++;
		}
	}
   
	this.removeItem = function(in_key)
	{
		var tmp_value;
		if (typeof(this.items[in_key]) != 'undefined') {
			this.length--;
			var tmp_value = this.items[in_key];
			delete this.items[in_key];
		}
	   
		return tmp_value;
	}

	this.getItem = function(in_key) {
		return this.items[in_key];
	}

	this.setItem = function(in_key, in_value)
	{
		if (typeof(in_value) != 'undefined') {
			if (typeof(this.items[in_key]) == 'undefined') {
				this.length++;
			}

			this.items[in_key] = in_value;
		}
	   
		return in_value;
	}

	this.hasItem = function(in_key)
	{
		return typeof(this.items[in_key]) != 'undefined';
	}
}

// HashTable function -- END
// *********************************************
// CEP Menu Variables Declaration -- START

var ezpath = '/cep/index.php/web/';

// About CEP Hash -- START
var WhatCEP = new Array(	new Hash('id',		'what_is_cep?',
																	 'name',	'Apa itu CEP?',
																	 'link',	ezpath + 'About-CEP/What-is-CEP/(language)/sin-MY'),
													
													new Hash('id',		'what_is_cep?',
																	 'name',	'&#20309;&#35859;&#31038;&#21306;&#21442;&#19982;&#35745;&#21010;&#65311;',
																	 'link',	ezpath + 'About-CEP/What-is-CEP/(language)/chi-CN'),

													new Hash('id',		'what_is_cep?',
																	 'name',	'&#2970;&#2990;&#3010;&#2965; &#2952;&#2975;&#3009;&#2986;&#3006;&#2975;&#3021;&#2975;&#3009;&#2980;&#3021; &#2980;&#3007;&#2975;&#3021;&#2975;&#2990;&#3021; (CEP)&#2958;&#2985;&#3021;&#2993;&#3006;&#2994;&#3021; &#2958;&#2985;&#3021;&#2985;?',
																	 'link',	ezpath + 'About-CEP/What-is-CEP/(language)/sin-TM')
												);


var WhyCEP = new Array(	new Hash('id',		'why_the_need_for_cep?',
																 'name',	'Mengapa CEP diperlukan?',
																 'link',	ezpath + 'About-CEP/Why-the-need-for-CEP/(language)/sin-MY'),
													
												new Hash('id',		'why_the_need_for_cep?',
																 'name',	'&#20026;&#20309;&#38656;&#35201;&#31038;&#21306;&#21442;&#19982;&#35745;&#21010;&#65311;',
																 'link',	ezpath + 'About-CEP/Why-the-need-for-CEP/(language)/chi-CN'),

												new Hash('id',		'why_the_need_for_cep?',
																 'name',	'&#2970;&#2990;&#3010;&#2965; &#2952;&#2975;&#3009;&#2986;&#3006;&#2975;&#3021;&#2975;&#3009;&#2980;&#3021; &#2980;&#3007;&#2975;&#3021;&#2975;&#2990;&#3021; (CEP)&#2959;&#2985;&#3021; &#2980;&#3015;&#2997;&#3016;&#2986;&#3021;&#2986;&#2975;&#3009;&#2965;&#3007;&#2993;&#2980;&#3009;?',
																 'link',	ezpath + 'About-CEP/Why-the-need-for-CEP/(language)/sin-TM')
												);


var WhoCEP = new Array(	new Hash('id',		'who_is_involved?',
																 'name',	'Siapa yang terlibat?',
																 'link',	ezpath + 'About-CEP/Who-is-involved/(language)/sin-MY'),
													
												new Hash('id',		'who_is_involved?',
																 'name',	'&#35841;&#35813;&#21442;&#19982;&#65311;',
																 'link',	ezpath + 'About-CEP/Who-is-involved/(language)/chi-CN'),

												new Hash('id',		'who_is_involved?',
																 'name',	'&#2951;&#2980;&#3007;&#2994;&#3021; &#2991;&#3006;&#2992;&#3021; &#2952;&#2975;&#3009;&#2986;&#2975;&#3021;&#2975;&#3007;&#2992;&#3009;&#2965;&#3021;&#2965;&#3007;&#2993;&#3006;&#2992;&#3021;&#2965;&#2995;&#3021;?',
																 'link',	ezpath + 'About-CEP/Who-is-involved/(language)/sin-TM')
												);


var HowCEP = new Array(	new Hash('id',		'how_can_i_get_involved?',
																 'name',	'Bagaimana Saya Boleh Melibatkan Diri?',
																 'link',	ezpath + 'About-CEP/How-can-I-get-Involved/(language)/sin-MY'),
													
												new Hash('id',		'how_can_i_get_involved?',
																 'name',	'&#25105;&#35813;&#22914;&#20309;&#21442;&#19982;&#65311;',
																 'link',	ezpath + 'About-CEP/How-can-I-get-Involved/(language)/chi-CN'),

												new Hash('id',		'how_can_i_get_involved?',
																 'name',	'&#2984;&#3006;&#2985;&#3021; &#2958;&#2986;&#3021;&#2986;&#2975;&#3007; &#2952;&#2975;&#3009;&#2986;&#3006;&#2975;&#3009; &#2965;&#3018;&#2995;&#3021;&#2997;&#2980;&#3009;?',
																 'link',	ezpath + 'About-CEP/How-can-I-get-Involved/(language)/sin-TM')
												);


var AboutCEP = new Array(	new Hash('id',		'what_is_cep?',
																	 'name',	'What is CEP?',
																	 'link',	ezpath + 'About-CEP/What-is-CEP',
																	 'menu',	WhatCEP
																	 ),
													
													new Hash('id',		'why_the_need_for_cep?',
																	 'name',	'Why the need for CEP?',
																	 'link',	ezpath + 'About-CEP/Why-the-need-for-CEP',
																	 'menu',	WhyCEP
																	 ),

													new Hash('id',		'who_is_involved?',
																	 'name',	'Who is involved?',
																	 'link',	ezpath + 'About-CEP/Who-is-involved',
																	 'menu',	WhoCEP
																	 ),

													new Hash('id',		'how_can_i_get_involved?',
																	 'name',	'How can I get Involved?',
																	 'link',	ezpath + 'About-CEP/How-can-I-get-Involved',
 																	 'menu',	HowCEP
																	 ),

													new Hash('id',		'what_s_new',
																	 'name',	'What\'s New',
																	 'link',	ezpath + 'What-s-New'),

													new Hash('id',		'sunny_says',
																	 'name',	'SUnny Says',
																	 'link',	ezpath + 'SUnny-Says')
												 );

// About CEP Hash -- END
// *********************************************
// Highlights Hash -- START
var Highlights = new Array(	new Hash('id',		'our_news',
																		 'name',	'Our News',
																		 'link',	ezpath + 'Our-News'),
														
														new Hash('id',		'news_room',
																		 'name',	'News Room',
																		 'link',	ezpath + 'News-Room')
												 );

// Highlights Hash -- END
// *********************************************
// Fun Stuff Hash -- START
var Funstuff = new Array(	new Hash('id',		'fun_stuff',
																	 'name',	'Fun Stuff',
																	 'link',	ezpath + 'Fun-Stuff'),
													
													new Hash('id',		'multimedia_gallery',
																	 'name',	'Multimedia Gallery',
																	 'link',	ezpath + 'Fun-Stuff/Multimedia-Gallery'),

													new Hash('id',		'your_contributions',
																	 'name',	'Your Contributions',
																	 'link',	ezpath + 'Your-Contributions')
													
												 );

// Fun Stuff Hash -- END
// *********************************************
// Resources Hash -- START
var Resources = new Array(	new Hash('id',	'publications',
																		 'name',	'Publications',
																		 'link',	ezpath + 'Resources/Publications'),
													
														new Hash('id',		'podcast_vodcast',
																		 'name',	'Podcast / Vodcast',
																		 'link',	ezpath + 'Resources/Podcast-Vodcast'),
	
														new Hash('id',		'looking_for_something',
																		 'name',	'Looking for Something?',
																		 'link',	'/looking4something.php'),

														new Hash('id',		'calendar',
																		 'name',	'Our Events',
																		 'link',	'/calendar/calendar.php')
	
												 );

// Resources Hash -- END
// *********************************************
// Your-Opinion Hash -- START
var yourOpinion = new Array(	new Hash('id',		'public_survey',
																			 'name',	'Public Survey',
																			 'link',	'/survey/cep_survey.php?type=1'),
														
															new Hash('id',		'private_survey',
																			 'name',	'Private Survey',
																			 'link',	'/survey/cep_survey.php?type=2')
												 );

// Your-Opinion Hash -- END
// *********************************************

var navigateArray = new Array(
															new Hash('name',	'About CEP',
																			 'image',	'_about_cep',
																			 'link',	'',
																			 'menu',	AboutCEP
																			 ),
															
															new Hash('name',	'Highlights',
																			 'image',	'_highlights',
																			 'link',	'',
																			 'menu',	Highlights
																			 ),
															
															new Hash('name',	'Fun Stuff',
																			 'image',	'_fun_stuff',
																			 'link',	'',
																			 'menu',	Funstuff
																			 ),
															
															new Hash('name',	'Resources',
																			 'image',	'_resources',
																			 'link',	'',
																			 'menu',	Resources
																			 ),

															new Hash('name',	'Your Opinion',
																			 'image',	'_your_opinion',
																			 'link',	'',
																			 'menu',	yourOpinion
																			 )
															);

// CEP Menu Variables Declaration -- END
// *********************************************
// Check User Type -- START
function checkUser(){
	
	var IPBCheck = readCookie('ipb_stronghold');
	var UserGrp = readCookie('g_title');
	var UserID = readCookie('globalUserID');
	var _myflag = false;
	
	if(UserGrp != null && UserID != null){
		if(UserGrp != 'Crisis+Befriender+Admin' && UserGrp != 'Crisis+Befriender' && UserGrp != 'Calendar+Management')
			_myflag = true;
	}
	
	return _myflag;
}

// Check User Type -- END
// *********************************************
// Check Login Menu -- START

function checkLoginMenus(currMenu){
	var _myflag = true

	if(currMenu == 'looking_for_something' || currMenu == 'private_survey'){
		if(!checkUser())
			_myflag = false;
	}
	
	return _myflag;
}

// Check Login Menu -- END
// *********************************************
// Vertical Menu -- START

function verticalMenu(){

	var currentHash = '';
	var innerHash = '';
	var cepmenu_output = '';

	cepmenu_output += '<link rel="stylesheet" type="text/css" href="/css/dropdownverticalmenu.css" />';
	cepmenu_output += '<table width="150" height="200" border="0" cellpadding="0" cellspacing="0"  style="background-color:#2B9EAD" valign="top">';
	cepmenu_output += '<tr><td>';
	cepmenu_output += '<div id="menu"><div id="menu"><ul id="menu-root" class="level1 horizontal">';
	
	//level1-One Loop
	for (i=0; i<navigateArray.length; i++){
	
		cepmenu_output += '<li class="level1" id="level1-One">';
		cepmenu_output += '<img border="0" class="zero_padding" alt="" title="" src="/images/menu/menu' + navigateArray[i].items['image'] + '.jpg"/>';
		cepmenu_output += '<ul class="level2 dropdown" id="level1-One" style="position: absolute; top: 161px; left: 552px; visibility: hidden;">';
		
		currentHash = navigateArray[i].items['menu'];
	
		//level2-Two Loop
		for (j=0; j<currentHash.length; j++){
		
			if(checkLoginMenus(currentHash[j].items['id'])){
				cepmenu_output += '<li class="level2">';
				cepmenu_output += '<a class="divNavi" href="' + currentHash[j].items['link'] + '" id="' + currentHash[j].items['id'] + '">' + currentHash[j].items['name'] + '</a>';
				
				if(currentHash[j].items['menu']){
					cepmenu_output += '<ul class="level3 flyout" style="position: absolute; top: 0px; left: 0px; visibility: hidden;">';
					
					innerHash = currentHash[j].items['menu'];
					
					//level3-Three Loop
					for (k=0; k<innerHash.length; k++){
						cepmenu_output += '<li class="level3">';
						cepmenu_output += '<a class="divNavi" href="' + innerHash[k].items['link'] + '" id="' + innerHash[k].items['id'] + '">' + innerHash[k].items['name'] + '</a>';
						cepmenu_output += '</li>';
					}
					cepmenu_output += '</ul>';
				}
				
				cepmenu_output += '</li>';
			}
		}
	
		cepmenu_output += '</ul>';
		cepmenu_output += '</li>';
	}
	
	cepmenu_output += '</ul></div></td></tr></table>';
	
	return cepmenu_output;	
}

// Vertical Menu -- END
// *********************************************
// Horizontal Menu -- START

function horizontalMenu(){
	var currentHash = '';
	var innerHash = '';
	var cepmenu_output = '';

	cepmenu_output += '<link rel="stylesheet" type="text/css" href="/css/dropdownmenu.css" />';
	cepmenu_output += '<table width="100%" height="40" border="0" cellpadding="0" cellspacing="0" style="background-color:#2B9EAD" valign="top">';
	cepmenu_output += '<tr><td style="padding-left:0px">';
	cepmenu_output += '<div id="menu"><ul id="menu-root" class="level1 horizontal">';
	
	//level1-One Loop
	for (i=0; i<navigateArray.length; i++){
	
		cepmenu_output += '<li class="level1" id="level1-One">';
		cepmenu_output += '<img border="0" class="zero_padding" alt="" title="" src="/images/menu/menuh' + navigateArray[i].items['image'] + '.jpg"/>';
		cepmenu_output += '<ul class="level2 dropdown" id="level1-One" style="z-index: 1; position: absolute; top: 0px; left: 0px; visibility: hidden;">';
		
		//level2-Two Loop
		currentHash = navigateArray[i].items['menu'];
		for (j=0; j<currentHash.length; j++){

			if(checkLoginMenus(currentHash[j].items['id'])){
				cepmenu_output += '<li class="level2">';
				cepmenu_output += '<a href="' + currentHash[j].items['link'] + '">' + currentHash[j].items['name'] + '</a>';
				
				if(currentHash[j].items['menu']){
					cepmenu_output += '<ul class="level3 flyout" style="position: absolute; top: 0px; left: 135px; visibility: hidden;">';
					
					//level3-Three Loop
					innerHash = currentHash[j].items['menu'];
					for (k=0; k<innerHash.length; k++){
						cepmenu_output += '<li class="level3">';
						cepmenu_output += '<a href="' + innerHash[k].items['link'] + '" >' + innerHash[k].items['name'] + '</a>';
						cepmenu_output += '</li>';
					}
					cepmenu_output += '</ul>';
				}
				
				cepmenu_output += '</li>';
			}
		}
	
		cepmenu_output += '</ul>';
		cepmenu_output += '</li>';
	}
	
	cepmenu_output += '</ul></div></td></tr></table>';
	
	return cepmenu_output;
}

// Horizontal Menu -- END
// *********************************************
if (document.location.href.indexOf("/mailinglist/admin/") == -1){
	if (document.location.href.indexOf("/forums/") == -1)
		document.write(verticalMenu());
	else{
		if(document.location.href.indexOf("/forums/admin/") == -1)
			document.write(horizontalMenu());
	}
}

// Generate Menu -- END
//alert(document.getElementById("menu"));
//if(document.getElementById("menu") != null)
	document.write('<script language="JavaScript" src="/scripts/cep_3rd_headervertical_ez.js"></script>');
