String.prototype.espIndexOf = function(str,num){
	counter=0
	for(i=0; i < this.length; i++){
		if(this.charAt(i) == str){
			counter++
			if(counter == num){
				return i
			}
		}
	}
}
String.prototype.Val_replace = function(a,b) {
	var str = "";
	for (lS=0; lS < this.length; lS++){
		if (this.charAt(lS) == a) { str += b } else { str += this.charAt(lS) }
	}
	return str;
}
String.prototype.padLeft = function (nChar, character){
	retorno = new String();
	for(nC = this.length; nC < nChar; nC++){
		retorno += character.toString();
	}
	return retorno + this;
}
String.prototype.padRight = function (nChar, character){
	retorno = new String();
	for(nC = this.length; nC < nChar; nC++){
		retorno += character.toString();
	}
	return this + retorno;
}

tela = {
	moveTo : function(x,y) { window.scroll(x,y); },
	moveBy : function(x,y) { this.moveTo(this.sx()+x,this.sy()+y) },
	sx : function() { return (is.ie) ? (document.body.scrollLeft) : (window.pageXOffset) },
	sy : function() { return (is.ie) ? (document.body.scrollTop) : (window.pageYOffset) },
	dw : function() { return (is.ie) ? (document.body.scrollWidth) : (document.width) },
	dh : function() { return (is.ie) ? (document.body.scrollHeight) : (document.height) },
	ww : function() { return (is.ie) ? (document.body.clientWidth) : (window.innerWidth) },
	wh : function() { return (is.ie) ? (document.body.clientHeight) : (window.innerHeight) },
	sw : function() { return (screen.width) },
	sh : function() { return (screen.height) }
};

/*
function popup(pagina,largura,altura,nome,mais) {
	calcleft = (tela.sw() / 2) - (largura / 2);
	calctop = (tela.sh() / 2) - (altura / 2);
	pop = window.open(''+pagina+'',''+nome+'','width='+largura+',height='+altura+',left='+calcleft+',top='+calctop+',scrollbars=1'+((mais)?','+mais:''));
	pop.focus();
}
*/

function popup (sPage, sWidth, sHeight, sTitle, more) {
	//sPage = nome da página do popup
	//sWidth = largura em pixels do popup
	//sHeight = altura em pixels do popup
	var sFeatures="center: yes; status: no; dialogWidth: " + sWidth + "px; dialogHeight: " + sHeight + "px; scroll: no;" + more;

	var objPop = new Object();
	objPop.title = sTitle;
	objPop.pageToOpen = path + "content/" + modulo + "/" + sPage;
	objPop.path = path;
	var myReturn =  window.showModalDialog(path + "/common/popup.htm", objPop, sFeatures);
	if(myReturn && myReturn[0]) {
		document.location.reload();
	}
}

function returnValues(){
	parent.returnValue = arguments;
	window.close();
}

function fillTitle() {
	var charType = " ";
	for(i=0; i<1000; i++) {
		charType += ".";
	}
	return charType;
}

/*************** USADA PARA MOSTRAR UMA MENSAGEM QUANDO PASSA O MOUSE EM DETERMINADO TEXTO OU IMAGEM, SEMELHANTE AO COMANDO ALT="" DA TAG IMG ***************/
var myDiv = "";
function vivoAltOn(txt) {
	var body = 
		'<table>' +
		'	<tr>' +
		'		<td class="tip">'+txt+'</td>' +
		'	</tr>' +
		'</table>'
	;
	if (myDiv == ""){
		myDiv = document.createElement("DIV");
		document.body.appendChild(myDiv);
	}
	
	myDiv.innerHTML = body;
	myDiv.style.position = "absolute";
	myDiv.style.top = event.clientY;
	myDiv.style.left = event.clientX;
	myDiv.style.visibility = 'visible';
}

function vivoAltOff() {
	if (myDiv != "") {
		myDiv.style.visibility = 'hidden';
	}
}

function rollover(obj, src){
	eval("document." + obj + ".src='" + src + "'");
}

function changeMenu(id) {
	var off = path + "img/menu01.jpg";
	var on = path + "img/menu02.jpg";
	if(id.background == on) {
		id.background = off;
	} else {
		id.background = on;
	}
}

function sincronizarScrollLateral(gridHeader, gridBody) {
	if (gridBody.scrollLeft <= (parseInt(gridBody.style.width)-60)) { 
		gridHeader.scrollLeft = gridBody.scrollLeft;
	} else {
		gridBody.scrollLeft = parseInt(gridBody.style.width)-60;
	}
}


function changeClassMenuInterno(objTd, tipo) {
	if(tipo == "on") {
		objTd.className = "menuInternoOn";
	} else {
		objTd.className = "menuInterno";
	}
}

// PAGINACAO
function setPag(field1,field2,field3) {
	document.filtros.posPage.value = field1;
	document.filtros.nextBlock.value = field2;
	document.filtros.prevBlock.value = field3;
	document.filtros.orderType.value = (document.filtros.orderType.value=="DESC") ? "ASC" : "DESC";
	document.filtros.submit();
}

// ORDENAR
function orderBy(field) {
	if (document.filtros.order.value!="") document.filtros.lastOrderField.value = document.filtros.order.value;
	document.filtros.order.value = field;
	document.filtros.orderType.value = (document.filtros.orderType.value=="DESC") ? "ASC" : "DESC";
	document.filtros.submit();
}