/*
	Portal BANCO REAL - Arquivo de Desvio - Estrutura - Cartões PF / Cartões PJ / Crédito Imobiliário
*/

if(document.location.href.indexOf('/cartoes') !== -1){
	var str_tipo_path = '/cartoes/';
}
if(document.location.href.indexOf('/cartoes_pj') !== -1){
	var str_tipo_path = '/cartoes_pj/';
}
if(document.location.href.indexOf('/creditoimobiliario') !== -1){
	var str_tipo_path = '/creditoimobiliario/';
}

function fcn_retirar_ext(value,value_retirar){
	return value.substring(0,value.indexOf(value_retirar));
}


if(typeof(Menu) == 'object'){
	Menu.Get.BreadCrumb = function(){
		var str_return = '<ul id="cartoes_bread_crumb">\n';
		var int_count = 0, int_counter = null;

		// Faz o loop para pegar os itens padrões
		if(Menu.Self.UID == ''){
			int_counter = 0;

			for(Looper in Menu.Data){
				if(Menu.Data[Looper].Type == 'A'){
					int_counter++;
				}
			}
		}

		for(Looper in Menu.Data){
			if(Menu.Data[Looper].Type == 'A'){
				str_return += '<li' + ((int_count == 0) ? ' class="primeiro_item"' : '') + '>' + ((Menu.Self.UID == '' && (int_counter - 1) == int_count) ? '' : '<a href="' + Menu.Data[Looper].Link.BreadCrumb.URL + '"' + ((Menu.Data[Looper].Link.BreadCrumb.Target != '') ? ' target="' + Menu.Data[Looper].Link.BreadCrumb.Target + '"' : '') + ' title="' + Menu.Data[Looper].Label.BreadCrumb + '">') + Menu.Data[Looper].Label.BreadCrumb + ((Menu.Self.UID == '' && (int_counter - 1) == int_count) ? '' : '</a>') + '</li>\n';
				int_count++;
			}
		}

		if(Menu.Self.UID != ''){
			// Através do Self, faz a segunda parte do Bread-Crumb
			var arr_self_itens	= Menu.Self.UID.split('-');
			var str_item_uid		= '';
			var int_max_length		= ((arr_self_itens.length <= 2) ? arr_self_itens.length : 2);
			for(var int_count = 0; int_count < int_max_length; int_count++){
				str_item_uid += ((int_count != 0) ? ('-' + arr_self_itens[int_count]) : arr_self_itens[int_count]);

				str_return += '<li>' + ((Menu.Self.UID == str_item_uid || Menu.Data[str_item_uid].Link.MenuItem.URL == '') ? '' : '<a href="' + Menu.Data[str_item_uid].Link.MenuItem.URL + '"' + ((Menu.Data[str_item_uid].Link.MenuItem.Target != '') ? ' target="' + Menu.Data[str_item_uid].Link.MenuItem.Target + '"' : '') + ' title="' + Menu.Data[str_item_uid].Label.BreadCrumb + '">') + Menu.Data[str_item_uid].Label.BreadCrumb + ((Menu.Self.UID == str_item_uid || Menu.Data[str_item_uid].Link.MenuItem.URL == '') ? '' : '</a>') + '</li>\n';
			}
		}

		str_return += '</ul>';
		return str_return;
	}

	Menu.Get.MenuList = function(){
		var str_return = Menu.Get.ActionButton() + '<div id="iw_pb_menu">\n';


		str_return += '<ul class="iw_pb_menu_fathers">\n';

		var int_count = 0, arr_all_itens = [], arr_selected_item = [], Father_Looper = null;

		arr_all_itens['Fathers']	= 0;
		arr_all_itens['Sons']		= 0;
		arr_all_itens['Grandsons']	= 0;

		// Realiza o cálculo de quantos itens pais, filhos e netos existem e se o último deve ser mostrado como último item.
		for(Father_Looper in Menu.Data){
			if(Menu.Data[Father_Looper].Type != 'A' && Menu.Data[Father_Looper].UID.indexOf('-') === -1 && Menu.Data[Father_Looper].Display.MenuItem == 1){
				arr_all_itens['Fathers']++;
			}
		}

		delete Father_Looper;


		var Father_Looper = null, Son_Looper = null, Grandson_Looper = null, RE_Father = null, RE_Son = null, RE_Grandson = null, int_counter = 0;

		for(Father_Looper in Menu.Data){
			RE_Father = new RegExp('^([B-Z]{1,3}[0-9]{1,})$','');

			if((Menu.Data[Father_Looper].UID.match(RE_Father)) && Menu.Data[Father_Looper].Display.MenuItem){
				var str_son_return = '', int_son_counter = 0;
				RE_Son = new RegExp('^([B-Z]{1,3}[0-9]{1,})-([0-9]{1,})$','');
				arr_all_itens['Sons'] = 0;

				// Faz um loop nos filhos para pegar o número total deles
				for(Son_Looper in Menu.Data){
					if(Menu.Data[Son_Looper].UID.match(RE_Son) && Menu.Data[Son_Looper].Display.MenuItem && Menu.Data[Father_Looper].UID == Menu.Data[Son_Looper].UID.match(RE_Son)[1] && ((Menu.OpenClose == true) ? true : ((Menu.Self.UID.replace(/\-.*/,'') == Menu.Data[Son_Looper].UID.match(RE_Son)[1]) ? true : false))){
						arr_all_itens['Sons']++;
					}
				}

				for(Son_Looper in Menu.Data){

					if(Menu.Data[Son_Looper].UID.match(RE_Son) && Menu.Data[Son_Looper].Display.MenuItem && Menu.Data[Father_Looper].UID == Menu.Data[Son_Looper].UID.match(RE_Son)[1] && ((Menu.OpenClose == true) ? true : ((Menu.Self.UID.replace(/\-.*/,'') == Menu.Data[Son_Looper].UID.match(RE_Son)[1]) ? true : false))){

						var str_grandson_return = '', int_grandson_counter = 0;
						RE_Grandson = new RegExp('^([B-Z]{1,3}[0-9]{1,})-([0-9]{1,})-([0-9]{1,})$','');
						arr_all_itens['Grandsons'] = 0;

						// Faz um loop nos netos para pegar o número total deles
						for(Grandson_Looper in Menu.Data){
							if(Menu.Data[Grandson_Looper].UID.match(RE_Grandson) && Menu.Data[Grandson_Looper].Display.MenuItem && Menu.Data[Son_Looper].UID == (Menu.Data[Grandson_Looper].UID.match(RE_Grandson)[1] + '-' + Menu.Data[Grandson_Looper].UID.match(RE_Grandson)[2]) && (Menu.Self.UID == (Menu.Data[Grandson_Looper].UID.match(RE_Grandson)[1] + '-' + Menu.Data[Grandson_Looper].UID.match(RE_Grandson)[2]) || Menu.Data[Son_Looper].Link.MenuItem.URL == '')){
								arr_all_itens['Grandsons']++;
							}
						}

						var bln_show_grandson = false;

						for(Grandson_Looper in Menu.Data){
							if(Menu.Data[Grandson_Looper].UID.match(RE_Grandson) && Menu.Data[Grandson_Looper].Display.MenuItem && Menu.Data[Son_Looper].UID == (Menu.Data[Grandson_Looper].UID.match(RE_Grandson)[1] + '-' + Menu.Data[Grandson_Looper].UID.match(RE_Grandson)[2]) && (Menu.Self.UID == (Menu.Data[Grandson_Looper].UID.match(RE_Grandson)[1] + '-' + Menu.Data[Grandson_Looper].UID.match(RE_Grandson)[2]) || Menu.Data[Son_Looper].Link.MenuItem.URL == '')){
								if(Menu.Data[Grandson_Looper].UID.match(new RegExp('^([B-Z]{1,3}[0-9]{1,}-[0-9]{1,}-[0-9]{1,}).*$', ''))[1] == Menu.Self.UID && Menu.Data[Son_Looper].Link.MenuItem.URL == ''){
									bln_show_grandson = true;
								}
								str_grandson_return += '<li' + ((parseInt(int_grandson_counter + 1) == arr_all_itens['Grandsons']) ? ' class="iw_pb_menu_grandsons_last"' : '') + '><a href="' + Menu.Data[Grandson_Looper].Link.MenuItem.URL + '" target="' + ((Menu.Data[Grandson_Looper].Link.MenuItem.Target != '') ? Menu.Data[Grandson_Looper].Link.MenuItem.Target : '_self') + '" title="' + Menu.Data[Grandson_Looper].Label.MenuItem + '"><div class="iw_pb_menu_other_grandsons_itens' + ((Menu.Self.UID == Menu.Data[Grandson_Looper].UID || (Menu.Self.UID != Menu.Data[Grandson_Looper].UID && Menu.Self.UID.indexOf(Menu.Data[Grandson_Looper].UID + '-') !== -1)) ? ' cartoes_menu_selected' : '') + '">' + Menu.Data[Grandson_Looper].Label.MenuItem + '</div></a></li>';
								int_grandson_counter++;
							}
						}

						/*Montar filhos*/
						str_son_return += '<li ' + ((int_son_counter == 0 && arr_all_itens['Sons'] != 1) ? ' class="iw_pb_menu_sons_first"' : ((parseInt(int_son_counter + 1) == arr_all_itens['Sons']) ? ' class="iw_pb_menu_sons_last"' : ((bln_is_ie5p && Menu.Data[Son_Looper].Link.MenuItem.URL != '') ? ' class="iw_pb_menu_sons_last"' : ''))) + '><a href="' + ((Menu.Data[Son_Looper].Link.MenuItem.URL != '') ? ((Menu.isHP && !Menu.Data[Son_Looper].Link.MenuItem.URL.match(/^javascript\:/) && !Menu.Data[Son_Looper].Link.MenuItem.URL.match(/^http\:\:\/\//)) ? '/index_internas.htm?sUrl=' + Menu.Data[Son_Looper].Link.MenuItem.URL : Menu.Data[Son_Looper].Link.MenuItem.URL) : 'javascript:fcn_openclose_menu(\'cartoes_son_' + Menu.Data[Son_Looper].UID.replace('-', '_').toLowerCase() + '\', \'cartoes_grandson_' + Menu.Data[Son_Looper].UID.replace('-', '_').toLowerCase() + '\', \'cartoes_sepline_' + Menu.Data[Son_Looper].UID.replace('-', '_').toLowerCase() + '\', \'iw_pb_menu_other_sons_itens_' + ((Menu.Data[Son_Looper].Link.MenuItem.URL != '') ? 'b' : 'c') + '\');') + '" target="' + ((Menu.Data[Son_Looper].Link.MenuItem.Target != '') ? Menu.Data[Son_Looper].Link.MenuItem.Target : '_self') + '" title="' + Menu.Data[Son_Looper].Label.MenuItem + '"><div id="cartoes_son_' + Menu.Data[Son_Looper].UID.replace('-', '_').toLowerCase() + '"class="iw_pb_menu_other_sons_itens_' + ((Menu.Self.UID.match(RE_Grandson) && Menu.Self.UID.indexOf(Menu.Data[Son_Looper].UID + '-') !== -1 && Menu.Data[Son_Looper].Link.MenuItem.URL == '') ? 'a' : ((Menu.Data[Son_Looper].Link.MenuItem.URL != '') ? 'b' : 'c')) + (((Menu.Self.UID == Menu.Data[Son_Looper].UID || (Menu.Self.UID != Menu.Data[Son_Looper].UID && Menu.Self.UID.indexOf(Menu.Data[Son_Looper].UID + '-') !== -1)) && Menu.Data[Son_Looper].Link.MenuItem.URL != '') ? ' cartoes_menu_selected' : '') + '">' + Menu.Data[Son_Looper].Label.MenuItem + '</div></a>' + ((str_grandson_return != '') ? ((parseInt(int_son_counter + 1) != arr_all_itens['Sons']) ? '<div class="iw_pb_sep_line">&nbsp;</div>' : '') + '<ul id="cartoes_grandson_' + Menu.Data[Son_Looper].UID.replace('-', '_').toLowerCase() + '" class="iw_pb_menu_grandsons' + ((bln_show_grandson || (Menu.Self.UID != Menu.Data[Son_Looper].UID && Menu.Self.UID.indexOf(Menu.Data[Son_Looper].UID + '-') !== -1)) ? '' : ' iw_pb_menu_nodisplay') + '">' + str_grandson_return + '</ul><div id="cartoes_sepline_' + Menu.Data[Son_Looper].UID.replace('-', '_').toLowerCase() + '" class="iw_pb_sep_line' + ((bln_show_grandson || (Menu.Self.UID != Menu.Data[Son_Looper].UID && Menu.Self.UID.indexOf(Menu.Data[Son_Looper].UID + '-') !== -1)) ? '' : ' iw_pb_menu_nodisplay') + '"></div>' : '') + '</li>\n';

						int_son_counter++;
					}
				}

				str_style_size = (Menu.Data[Father_Looper].Lines == 2) ? (int_counter == 0) ?  'iw_pb_menu_first_father iw_pb_menu_two_lines' : 'iw_pb_menu_other_father_itens iw_pb_menu_two_lines' : (int_counter == 0) ? 'iw_pb_menu_first_father' : 'iw_pb_menu_other_father_itens';

				/*Monta Pai*/

				str_return += '<li class="' + ((parseInt(int_counter + 1) == arr_all_itens['Fathers']) ? ((str_son_return == '') ? 'iw_pb_menu_last_father' : 'iw_pb_menu_father') : 'iw_pb_menu_father') + '"' + ((parseInt(int_counter + 1) == arr_all_itens['Fathers']) ? ' style="height:100%;"' : '') + '><div id="MenuFather_'+int_counter+'" class="' + (((Menu.Self.UID.match(RE_Son) && Menu.Self.UID.indexOf(Menu.Data[Father_Looper].UID + '-') !== -1) || (Menu.Self.UID.match(RE_Grandson) && Menu.Self.UID.indexOf(Menu.Data[Father_Looper].UID + '-') !== -1) || (Menu.Self.UID == Menu.Data[Father_Looper].UID) && str_son_return != '') ? 'iw_pb_menu_fathers_itens_on' : 'iw_pb_menu_fathers_itens_off') + '"><div class="' + ((int_counter == 0) ? str_style_size : ((parseInt(int_counter + 1) == arr_all_itens['Fathers']) ? 'iw_pb_menu_last_father_item' + ((str_son_return != '') ? '_f' : '') : str_style_size)) + '"><a href="' + ((Menu.isHP) ? ((Menu.Data[Father_Looper].Link.MenuItem.URL.indexOf('javascript') == -1 && Menu.Data[Father_Looper].Link.MenuItem.URL.indexOf('http://') == -1 && (Menu.OpenClose != true) || (str_son_return == "")) ? ('/index_internas.htm?sUrl=' + Menu.Data[Father_Looper].Link.MenuItem.URL) : ((Menu.OpenClose == true) ? 'javascript:Menu.openAsGroup('+int_counter+');' : Menu.Data[Father_Looper].Link.MenuItem.URL)) : ((Menu.OpenClose == true) && (str_son_return != "") ? 'javascript:Menu.openAsGroup('+int_counter+');' :  Menu.Data[Father_Looper].Link.MenuItem.URL)) + ((Menu.OpenClose != true) || (str_son_return == "") ? '" target="' + ((Menu.isHP) ? ((Menu.Data[Father_Looper].Link.MenuItem.URL.indexOf('javascript') == -1 && Menu.Data[Father_Looper].Link.MenuItem.URL.indexOf('http://') == -1) ? ('portal') : ((Menu.Data[Father_Looper].Link.MenuItem.Target != '') ? Menu.Data[Father_Looper].Link.MenuItem.Target : '_self')) : ((Menu.Data[Father_Looper].Link.MenuItem.Target != '') ? Menu.Data[Father_Looper].Link.MenuItem.Target : '_self')) : '') + '"><img src="'+ str_tipo_path +'img/iw_menu/mn_itens/' + Menu.Data[Father_Looper].Image.MenuItem + '" title="" alt="' + Menu.Data[Father_Looper].Label.MenuItem + '" align="absmiddle" border="0"></a></div></div>' + ((str_son_return != '') ? '\n<ul' + ((Menu.OpenClose == true) && (Menu.Self.UID.indexOf(Menu.Data[Father_Looper].UID + '-') == -1) ? ' class="iw_pb_menu_sons iw_pb_menu_menu_openclose" id="MenuOpenClose_'+int_counter+'"' : ' class="iw_pb_menu_sons" id="MenuOpenClose_'+int_counter+'"') + '>' + str_son_return + '</ul>\n' : '') + ((parseInt(int_counter + 1) == arr_all_itens['Fathers']) ? ((str_son_return != '') ? '<div class="cartoes_menu_last_son_menu"></div>' : '') : '') + '</li>\n';

				int_counter++;
			}
		}

		str_return += '</ul>\n';
		str_return += ((bln_is_ie) ? '<img src="/cartoes/img/cartoes_estrutura/dot_branco.gif" width="181" height="3" style="margin-top:-3px;">' : '') + '</div>';
		return str_return;
	}

	Menu.Get.SiteMap = function(){

	}

	Menu.Get.ActionButton = function(){
		var str_return = '';

		// Adiciona a imagem (botão) principal de Cartões.
		str_return += ((Menu.Title[2] && Menu.Title[2] != '' && !Menu.isHP) ? '<a href="' + Menu.Title[2] + '" title="' + Menu.Title[1] + '" target="' + ((Menu.Title[3] != '') ? Menu.Title[3] : '_self') + '">' : '') + '<img src="' + str_tipo_path + 'img/iw_menu/' + Menu.Title[0] + '" title="" alt="' + Menu.Title[1] + '" border="0" class="cartoes_menu_botoes" style="margin-bottom:3px">' + ((Menu.Title[2] && Menu.Title[2] != '' && !Menu.isHP) ? '</a>' : '');

		// Adiciona o Botão de Ação

		if((Menu.Self.Image.ActionButton == '' || Menu.Self.Display.ActionButton == 0) && Menu.defaultActionButton.Image != ''){
			str_return += '' + ((Menu.defaultActionButton.Link.URL != '') ? '<a href="' + ((Menu.isHP) ? ((Menu.defaultActionButton.Link.URL.indexOf('javascript') == -1 && Menu.defaultActionButton.Link.URL.indexOf('http://') == -1) ? ('/index_internas.htm?sUrl=' + Menu.defaultActionButton.Link.URL) : Menu.defaultActionButton.Link.URL) : Menu.defaultActionButton.Link.URL) + '" target="' + ((Menu.isHP) ? ((Menu.defaultActionButton.Link.URL.indexOf('javascript') == -1 && Menu.defaultActionButton.Link.URL.indexOf('http://') == -1) ? ('portal') : ((Menu.defaultActionButton.Link.Target != '') ? Menu.defaultActionButton.Link.Target : '_self')) : ((Menu.defaultActionButton.Link.Target != '') ? Menu.defaultActionButton.Link.Target : '_self')) + '">' : '') + '<img src="'+  str_tipo_path +'img/iw_menu/mn_action_buttons/' + Menu.defaultActionButton.Image + '" title="" alt="' + Menu.defaultActionButton.Label + '" border="0" class="cartoes_menu_botoes">' + ((Menu.defaultActionButton.Link.URL != '') ? '</a>' : '') + '\n';
		}

		if(Menu.Self.UID != '' && Menu.Self.Image.ActionButton != ''){
			str_return += ((Menu.Self.Display.ActionButton === 1) ? '' + ((Menu.Self.Link.ActionButton.URL != '') ? '<a href="' + ((Menu.isHP) ? ((Menu.Self.Link.ActionButton.URL.indexOf('javascript') == -1 && Menu.Self.Link.ActionButton.URL.indexOf('http://') == -1) ? ('/index_internas.htm?sUrl=' + Menu.Self.Link.ActionButton.URL) : Menu.Self.Link.ActionButton.URL) : Menu.Self.Link.ActionButton.URL) + '" target="' + ((Menu.isHP) ? ((Menu.Self.Link.ActionButton.URL.indexOf('javascript') == -1 && Menu.Self.Link.ActionButton.URL.indexOf('http://') == -1) ? ('portal') : ((Menu.Self.Link.ActionButton.Target != '') ? Menu.Self.Link.ActionButton.Target : '_self')) : ((Menu.Self.Link.ActionButton.Target != '') ? Menu.Self.Link.ActionButton.Target : '_self')) + '">' : '') + '<img src="'+ str_tipo_path +'img/iw_menu/mn_action_buttons/' + Menu.Self.Image.ActionButton + '" title="" alt="' + ((Menu.Self.Label.ActionButton != '') ? Menu.Self.Label.ActionButton : Menu.Self.Label.MenuItem) + '" border="0" class="cartoes_menu_botoes">' + ((Menu.Self.Link.ActionButton.URL != '') ? '</a>' : '') + '\n' : '');
		}
		return str_return;
	}
}

// Abre / Fecha
function fcn_openclose_menu(str_father_id, str_son_id, str_sep_line_id, str_default_class){
	if((document.getElementById(str_son_id).style.display == 'none' || document.getElementById(str_son_id).style.display == '') && document.getElementById(str_father_id).className != 'iw_pb_menu_other_sons_itens_a'){
		document.getElementById(str_son_id).style.display			= 'block';
		document.getElementById(str_sep_line_id).style.display	= 'block';
		document.getElementById(str_father_id).className			= 'iw_pb_menu_other_sons_itens_a';
	}else{
		document.getElementById(str_son_id).style.display			= 'none';
		document.getElementById(str_sep_line_id).style.display	= 'none';
		document.getElementById(str_father_id).className			= str_default_class;
	}
}

function getCurrentStyle(obj_element){
	if(bln_is_ie){
		return obj_element.currentStyle;
	}else{
		return (document.defaultView.getComputedStyle(obj_element, null) || false);
	}
}

Menu.openAsGroup_CallBack = function(){return false;}

Menu.openAsGroup = function(int_menu_uid){
	var bln_continue = true, int_count = 0;

	while(bln_continue){
		if(document.getElementById('MenuOpenClose_' + int_count)){
			if(int_count != parseInt(int_menu_uid)){
				if(document.getElementById('MenuOpenClose_' + int_count).className.match(/iw\_pb\_menu\_menu\_openclose/)){
					document.getElementById('MenuFather_' + int_count).className = 'iw_pb_menu_fathers_itens_off';
					document.getElementById('MenuOpenClose_' + int_count).style.display = 'none';
				}
			}

			int_count++
		}else{
			bln_continue = false;
		}
	}

	bln_continue = null, int_count = null;

	if(getCurrentStyle(document.getElementById('MenuOpenClose_' + int_menu_uid)).display == 'none'){
		document.getElementById('MenuFather_' + int_menu_uid).className = 'iw_pb_menu_fathers_itens_on';
		document.getElementById('MenuOpenClose_' + int_menu_uid).style.display = 'block';
	}else{
		if(document.getElementById('MenuOpenClose_' + int_menu_uid).className.match(/iw\_pb\_menu\_menu\_openclose/)){
			document.getElementById('MenuFather_' + int_menu_uid).className = 'iw_pb_menu_fathers_itens_off';
			document.getElementById('MenuOpenClose_' + int_menu_uid).style.display = 'none';
		}
	}

	this.openAsGroup_CallBack();
}