/**
 * @author dodii
 */

gotoVarejo = function(){
	document.location = 'portal.php?portal=v';
}

gotoCorporativo = function(){
	document.location = 'portal.php?portal=c';
}

goToMenu = function(idMenu, hashMenu){
	//alert(idMenu);
	ajaxGoTo('/index_novo/?area=6&mid='+idMenu+'&hash='+hashMenu,'menu_content');
}

goToHome = function(){
	ajaxGoTo('/index_novo/?area=0','menu_content');
}

goToEmpresa = function (){
	ajaxGoTo('/index_novo/?area=1','menu_content');
}

goToEmpresafromindex = function (){
	document.location = 'portal.php?portal=i&area=1';
}

goToRH = function (){
	ajaxGoTo('/index_novo/?area=2','menu_content');
}

goToRHfromindex = function (){
	document.location = 'portal.php?portal=i&area=2';
}

goToPromocoes = function(){
	ajaxGoTo('/index_novo/?area=3','menu_content');
}

goToPromocoesfromindex = function(){
	document.location = 'portal.php?portal=i&area=3';
}

goToImprensa = function(){
	ajaxGoTo('/index_novo/?area=4','menu_content');			
}

goToImprensafromindex = function(){
	document.location = 'portal.php?portal=i&area=4';	
}

goToContato = function(){
	ajaxGoTo('/index_novo/?area=5','menu_content');
}

goToContatofromindex = function(){
	document.location = 'portal.php?portal=i&area=5';
}

doLogin = function(usr, pwd, destination){
	document.getElementById('usr').value = usr;
	document.getElementById('pwd').value = pwd;
	document.getElementById('dst').value = destination.toLowerCase();
	document.getElementById('formAuxLogin').submit();
}

goToFiliais = function(){
	ajaxGoTo('/index_novo/?area=7','targetLinksContato');
}
goToMapa = function(){
	ajaxGoTo('/index_novo/?area=8','targetLinksContato');
}

goToConteudo = function(idConteudo, hashConteudo){
	ajaxGoTo('/index_novo/?area=9&cid='+idConteudo+'&hash='+hashConteudo,'menu_content');
}

goToCredenciamento = function(portal){
	ajaxGoTo('/index_novo/?area=12','subcontentDiv');
}

rewriteLinks = function(elemento) {
	var tag = String(elemento.tagName).toLowerCase();
	if(tag == 'a') {
		var partes_destino  = String(elemento.href).split('?');
		if(partes_destino.length < 2)
			return;
		var params 			= partes_destino[1];
//		alert('params = ' + params);
		var cid				= String(params).split('cid=');
		var v_hash			= String(params).split('hash=');
		if(cid.length > 1 && v_hash.length > 1) {
			cid	= String(cid[1]).split('&');
			cid	 = cid[0];

			v_hash	= String(v_hash[1]).split('&');
			v_hash	 = v_hash[0];

			/*elemento.setAttribute('href', '#');
			elemento.setAttribute('v_hash', v_hash);
			elemento.setAttribute('v_cid', cid);
			if(document.all) {
				elemento.onclick = function () {
					goToConteudo(this.getAttribute('v_cid'), this.getAttribute('v_hash'));
					return false;
				}
			}else
			elemento.setAttribute('onclick',  "goToConteudo(this.getAttribute('v_cid'), this.getAttribute('v_hash')); return false;");*/
			if((!elemento.getAttribute('target')) || String(elemento.getAttribute('target')).toLowerCase() != '_blank')
				elemento.setAttribute('href',"javascript:goToConteudo('"+cid+"','" + v_hash + "');");
		}
	}
	if(elemento.childNodes.length >0 ) {
		for(var i=0; i<elemento.childNodes.length; i++) {
			if(typeof(elemento.childNodes[i].tagName) != 'undefined') {
				rewriteLinks(elemento.childNodes[i]);
			}
		}
	}
}

carregouDiv = function(elemento) {
	rewriteLinks(elemento);
}