﻿String.prototype.trim = function()
						{
							return this.replace( /^\s*/, "").replace( /\s*$/, "");
 						}

String.prototype.isDate = function()
						{
							var r = false;
							
							if(this.indexOf('/') > -1)
							{
								var dmy = this.split('/');
								
								if(dmy.length == 3 && _ValidaDataSplit(dmy[0],dmy[1],dmy[2]))
									r = true;
							}
							
							return r;
						}

function buscar(url,textoabuscar){
	if(textoabuscar==''){
		alert('Insira um ou mais termos de pesquisa.');
	}else{
		//window.location.href="/pesquisaresultado.aspx?k="+textoabuscar+"&cs=Neste%20Site&u="+url;		
		window.location.href="/pesquisaresultado.aspx?k="+textoabuscar;
	}
}

function mudaFonte(tipo,sNomeObj)
{
	// Testar o navegador mozilla
	objNavMozilla = !(document.all); 
	
	// Armazena o nome do navegador
	objNavNome = navigator.appName;
	 
	if(objNavMozilla || objNavNome == 'Opera') 
	{
		var objTamanhoFonte;
		
		if(document.getElementById(sNomeObj).style.fontSize == '')
		{
			objTamanhoFonte = 12;
		}
		else
		{
			objTamanhoFonte = document.getElementById(sNomeObj).style.fontSize.replace("px","");
		}
		
		if (tipo=="mais")
		{	
			if(objTamanhoFonte < 20)
			{
				document.getElementById(sNomeObj).style.fontSize = parseInt(objTamanhoFonte)+2 + 'px';
			}
		}
		else
		{
			if(objTamanhoFonte > 7)
			{
				document.getElementById(sNomeObj).style.fontSize = parseInt(objTamanhoFonte)-2 + 'px';
			}
		}
	
	}
	else
	{
		if(document.getElementById(sNomeObj).style.zoom == '')
		{
			document.getElementById(sNomeObj).style.zoom = 1;
		}
		
		
		if (tipo=="mais")
		{
			if(parseFloat(document.getElementById(sNomeObj).style.zoom) < 2)
			{		
				document.getElementById(sNomeObj).style.zoom = parseFloat(document.getElementById(sNomeObj).style.zoom) + .1;
			}		
		} 
		else 
		{
			if(parseFloat(document.getElementById(sNomeObj).style.zoom) > .2)
			{
				document.getElementById(sNomeObj).style.zoom = parseFloat(document.getElementById(sNomeObj).style.zoom) - .1;	
			}
		}

	}
	


	/*
		// Regras CSS para o Firefox, Safari e Opera
		alert(document.styleSheets.length);
		for(i=0;i<document.styleSheets.length;i++)
		{
			alert(document.getElementById(sNomeObj).style.zoom);
		}
		
		if(parseFloat(document.getElementById(sNomeObj).style.zoom) < 2)
		{		
			document.getElementById(sNomeObj).style.zoom = parseFloat(document.getElementById(sNomeObj).style.zoom) + .1;
		}

		//document.document.getElementById(sNomeObj).CssRules[0].style.fontSize = 20 + 'px' ;
	}
	else
	{
		document.styleSheets[0].rules[0].style.zoom = parseFloat(document.getElementById(sNomeObj).style.zoom) + .1;
	}*/
	
}

function _GetKeyCode(e)
{
	return e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
}

function _ORD(k)
{
	return String.fromCharCode(k);
}

function kp_Data()
{
	var e = window.event;
		
	if(!e)
		return true;

	var key = _GetKeyCode(e);
	var c = _ORD(key);
	var obj = e.srcElement;
	
	if(!isNaN(c) || c == '/' || key == 13) // 13 é o enter
	{
		var lastchar = obj.value.substring(obj.value.length-1,obj.value.length);
		var totalbars = obj.value.indexOf('/') >= 0 ? obj.value.split('/').length-1 : 1;

		if((obj.value.length == 2 || obj.value.length == 5) && lastchar != '/' && totalbars < 2 && c != '/')
			obj.value += '/';
		
		if(c == '/' && totalbars >= 2)
			return false;
		
		else if(key == 13)
			return true;
			
		else if(obj.value.length == 10)
			return false;
	}
	else
		return false;
}

function kp_Hora()
{
	var e = window.event;
		
	if(!e)
		return true;

	var key = _GetKeyCode(e);
	var c = _ORD(key);
	var obj = e.srcElement;
	
	if(!isNaN(c) || c == ':' || key == 13) // 13 é o enter
	{
		var lastchar = obj.value.substring(obj.value.length-1,obj.value.length);

		if(obj.value.length == 2 && lastchar != ':' && obj.value.indexOf(':') == -1 && c != ':')
			obj.value += ':';
		
		if(c == ':' && obj.value.indexOf(':') != -1)
			return false;
		
		else if(key == 13)
			return true;
			
		else if(obj.value.length == 5)
			return false;
	}
	else
		return false;
}

function kp_Int()
{
	var e = window.event;
		
	if(!e)
		return true;

	var key = _GetKeyCode(e);
	var c = _ORD(key);
	
	return key == 13 || !isNaN(c);
}

function kp_Moeda()
{
	var e = window.event;
		
	if(!e)
		return true;

	var key = _GetKeyCode(e);
	var c = _ORD(key);
	var obj = e.srcElement;
	
	return key == 13 || (c == ',' && obj.value.indexOf(',') == -1) || !isNaN(c);
}


function _ValidaDataSplit(d,m,y)
{
	var r = false;
	var u = 0;
	
	if(d && m && y && !isNaN(d) && !isNaN(m) && !isNaN(y))
	{
		if(m == 2) // Ultimo dia de fevereiro
			u = ((y % 4) == 0) ? 29 : 28;

		else if(m >= 1 && m <= 7)
			u = ((m % 2) == 0) ? 30 : 31;

		else if(m >= 8 && m <= 12)
			u = ((m % 2) == 0) ? 31 : 30;
			
		if(d >= 0 && d <= u)
			r = true;
	}
	
	return r;
}

function custom_DataValida(sender, args)
{
	args.IsValid = args.Value.isDate();
}

function custom_TermoCadastro(sender, args)
{
	var chk = document.getElementById('ctl00_PlaceHolderMain_chkTermo');
	
	args.IsValid = chk != null ? chk.checked : false;
}

function _GetQS(p)
{
	var url = self.location.href;
	
	if(!p || url.indexOf('?') < 0 || url.indexOf('?') == (url.length-1))
		return '';
		
	var qs = '&' + url.substring(url.indexOf('?')+1,url.length);
	
	if(qs.indexOf('&' + p) < 0)
		return '';
	
	var parametros = qs.split('&');
	
	var parametro;
	for(var i = 0; i < parametros.length; i++)
	{
		parametro = parametros[i];
		if(parametro.indexOf(p + '=') == 0)
			return parametro.substring(parametro.indexOf('=')+1,parametro.length);
	}
	
	return '';
}


function _GetFormLabel(obj, label)
{
	var nobrs = obj.getElementsByTagName('nobr');
	for(i = 0; i < nobrs.length; i++)
	{
		var nobr = nobrs[i];
		if(nobr.innerHTML.indexOf(label)==0)
			return nobr;
	}
}

function _GetRelativeFormField(nobr)
{
	if(nobr)
	{
		var tr = nobr.parentNode.parentNode.parentNode;
		var txt = tr.cells[1].childNodes[1].childNodes[0];
		return txt;
	}
	else
		return null;
}

function Debug(obj)
{
	var	debug = document.getElementById('Debug');
	
	if(obj && debug)
	{
		for(var i in obj)
			debug.innerHTML += '<div title="' + /*eval('obj.'+i) +*/ '">' + i + '</div>';
		debug.style.display = '';
	}
}

function RegistraValoremHDD(val, hddID)
{
	var hdd = document.getElementById(hddID);
	
	if(hdd)
		hdd.value = val;
}

function Blog_MudaPagina(page, hddID)
{
	RegistraValoremHDD(page, hddID);
	document.forms[0].action = document.forms[0].action + '#comentarios';
	document.forms[0].submit();
}

function Blog_EnviaComentarios()
{
	document.forms[0].action = document.forms[0].action + '#ecomentarios';	
}

function nav_MudaPagina(page, hddID)
{
	RegistraValoremHDD(page, hddID);
	document.forms[0].submit();
}


//----- Função que valida CNPJ ----//
String.prototype.isCNPJ = function(){
    var b = [6,5,4,3,2,9,8,7,6,5,4,3,2], c = this;
    if((c = c.replace(/[^\d]/g,"").split("")).length != 14) return false;
    for(var i = 0, n = 0; i < 12; n += c[i] * b[++i]);
    if(c[12] != (((n %= 11) < 2) ? 0 : 11 - n)) return false;
    for(var i = 0, n = 0; i <= 12; n += c[i] * b[i++]);
    if(c[13] != (((n %= 11) < 2) ? 0 : 11 - n)) return false;
    return true;
};

function mascaraCNPJ(obj,e)
	{
	 var keypress = window.event.keyCode;
	   if (keypress > 47 && keypress < 58 && obj.value.length < 18)
		{
		if (obj.value.length == 2) 
		   obj.value = obj.value + ".";
		if (obj.value.length == 6) 
		   obj.value = obj.value + ".";
		if (obj.value.length == 10) 
		   obj.value = obj.value + "/";
		if (obj.value.length == 15) 
		   obj.value = obj.value + "-";
		}
		else 
		event.returnValue = false;
}

//Função utilizada na tela de cadastro
function GA_FinalizaCadastro(accountName)
{
	var url = window.opener.location.href;
	
	if(url.indexOf('&accountName') == -1)
		url += '&accountName=' + accountName
			
	window.opener.location.href = url;
	window.close();
}

function showIndique(obj)
{
	
	if(document.getElementById(obj).style.display == "block")
	{
		/*maisEmenos*/
		document.getElementById(obj).previousSibling.childNodes[0].innerHTML = "+ ";
		/*maisEmenos*/
		document.getElementById(obj).style.display = "none";
		document.getElementById(obj).nextSibling.style.display = "none";
		document.getElementById(obj).nextSibling.nextSibling.style.display = "none";
	}
	else
	{
		/*maisEmenos*/
		document.getElementById(obj).previousSibling.childNodes[0].innerHTML = "- ";
		/*maisEmenos*/
		document.getElementById(obj).style.display = "block";
		document.getElementById(obj).nextSibling.style.display = "block";
		document.getElementById(obj).nextSibling.nextSibling.style.display = "block";		
	}
				
}

function showReceber(obj)
{
	if(document.getElementById(obj).style.display == "block")
	{
		/*maisEmenos*/
		document.getElementById(obj).previousSibling.childNodes[0].innerHTML = "+ ";
		/*maisEmenos*/	
		document.getElementById(obj).style.display = "none";
		document.getElementById(obj).nextSibling.style.display = "none";
		document.getElementById(obj).nextSibling.nextSibling.style.display = "none";		
	}
	else
	{
		/*maisEmenos*/
		document.getElementById(obj).previousSibling.childNodes[0].innerHTML = "- ";
		/*maisEmenos*/		
		document.getElementById(obj).style.display = "block";
		document.getElementById(obj).nextSibling.style.display = "block";
		document.getElementById(obj).nextSibling.nextSibling.style.display = "block";		
	}
}

var janela = "";
var url = "http://sustentabilidade.bancoreal.com.br/especialroberto/default.aspx";
var orkut_url = "http://www.youtube.com/watch?v=p_nahFkR6aw";
var linkTitle = "Especial Roberto : insira sustentabilidade no seu dia a dia?";
var tags = "Site";
var annotation = "Vídeos, interatividades, jogos, dinâmicas sobre Sustentabilidade";

function delicious()
{
   janela = window.open("http://del.icio.us/post?v=4&noui&jump=close&url=" + url + "&title= " + linkTitle, "Delicious", "height=650, width=750");
}

function facebook()
{
  janela = window.open("http://www.facebook.com/sharer.php?src=bm&v=4&u=" + url + "&t=" + linkTitle, "Facebook", "height=650, width=750");
}

function orkut()
{
  janela = window.open("http://www.orkut.com/FavoriteVideos.aspx?u=" + orkut_url, "Orkut", "location=1, height=650, width=750");
}

function google()
{
  janela = window.open("http://www.google.com/bookmarks/mark?op=edit&annotation=" + annotation  + "&labels=" + tags + "&bkmk=" + url + "&title=" + linkTitle, "GoogleBookmarks", "height=650, width=750");
}

function twitter()
{
  janela = window.open("http://twitter.com/home?status= " + linkTitle + ": " + url, "Twitter", "height=650, width=750");
}

function flickr()
{
 janela = "";
}

function goto(url) {
	if(url != ""){
		window.location.href = url;
	}
}


/*Para paginacao - INICIO*/

function getQueryString() {
	var url = window.location.href;
	var separador = '?';
	var	QueryString = (url.indexOf(separador) > -1)? url.split(separador)[1] : '';
	return QueryString;
}



var PaginacaoPadrao = {
	nav : 0,
	links : [],
	init : function() {
		if (this.has()) this.applyQueryString();
	},
	has : function() {
		this.nav = document.getElementById('nav');
		return this.nav;
	},
	applyQueryString : function() {
		var q = getQueryString();
		//Tratamento
		q = q.replace(/(^page=\d*&?|&?page=\d*)/gi, '');
		this.links = this.nav.getElementsByTagName('a');
		for (var i = 0, n = this.links.length; i < n; i++)
			this.links[i].href = this.links[i].href + (q!=''? '&'+q : '');
	}
}
//Para chamar a paginacao, chame este método depois da <div id="nav">[paginacaoAqui]</nav>
//PaginacaoPadrao.init();
/*Para paginacao - FIM*/

