/*Script para botão mouseover*/
function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
		if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
		for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
		if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
/*Fim do script para o botão mouseover*/


function abrepop(nome_pop, path, w, h, scroll){
	var janela = window.open(path,nome_pop,"height="+ Number(h) +",width="+ Number(w) +",status=no,toolbar=no,menubar=no,location=no, resizable=no, scrollbars="+scroll);
	//Jogando a janela no meio da tela
	var sWidth  = (screen.width / 2) - (Number(w) / 2);
	var sHeight = (screen.height / 2) - (Number(h) / 2);

	//movendo
	janela.moveTo(sWidth, sHeight) ;
}

/***********************************************
* Cool DHTML tooltip script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thecolor, thewidth){
	if (ns6||ie){
		if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
		if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
		tipobj.innerHTML=thetext
		enabletip=true
		return false
	}
}

function positiontip(e){
	if (enabletip){
		var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
		var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
		//Find out how close the mouse is to the corner of the window
		var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
		var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20

		var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000

		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge<tipobj.offsetWidth)
		//move the horizontal position of the menu to the left by it's width
		tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
		else if (curX<leftedge)
		tipobj.style.left="5px"
		else
		//position the horizontal position of the menu where the mouse is positioned
		tipobj.style.left=curX+offsetxpoint+"px"

		//same concept with the vertical position
		if (bottomedge<tipobj.offsetHeight)
		tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
		else
		tipobj.style.top=curY+offsetypoint+"px"
		tipobj.style.visibility="visible"
	}
}

function hideddrivetip(){
	if (ns6||ie){
		enabletip=false
		tipobj.style.visibility="hidden"
		tipobj.style.left="-1000px"
		tipobj.style.backgroundColor=''
		tipobj.style.width=''
	}
}

//Fim tooltip

function mostraOcultaCalendario(){
	texto = document.getElementById('oculta_calendario');
	div   = document.getElementById('div_calendario');

	if(div.style.display == 'block'){
		div.style.display = 'none';
		texto.innerHTML   = 'Mostrar calendário';
	}else{
		div.style.display = 'block';
		texto.innerHTML   = 'Ocultar calendário';
	}
}

//Imprimir partes de um objeto
function CallPrint(strid)

{

	var prtContent = document.getElementById(strid);

	var WinPrint = window.open('','Impressão',' "style:height=10,width=10,top=0,left=0"');

	WinPrint.document.write(prtContent.innerHTML);

	WinPrint.document.close();

	WinPrint.focus();

	WinPrint.print();

	WinPrint.close();

	//prtContent.innerHTML=strOldOne;
}

function select_go(obj){
	if(obj.value != ''){
		window.open(obj.value);
	}
}

function remontaLogin(){
	var string = "<form style=\"margin:0px\" onsubmit=\"logar_ajax('acao/ajax_login.php', 'div_login', 'id_login', 'id_senha'); return false;\">";
	string += "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\" class=\"txt_verde_11px\">";
	string += "<tr>";
	string += "<td align=\"right\">";
	string += "<font  class=\"txt_verde_11px\">Login:</font>";
	string += "</td>";
	string += "<td>";
	string += "<input type=text name=\"login\" id=\"id_login\" class=\"text\">";
	string += "</td>";
	string += "</tr>";
	string += "<tr>";
	string += "<td align=\"right\">";
	string += "<font class=\"txt_verde_11px\">Senha:</font>";
	string += "</td>";
	string += "<td>";
	string += "<input type=\"password\" name=\"senha\" id=\"id_senha\" class=\"text\" size=\"16\">";
	string += "<input type=\"image\" src=\"imagens/btn_ok_verde.gif\" align=\"absmiddle\" id=\"btn_ok_verde\" onMouseOut=\"MM_swapImgRestore();\" onMouseOver=\"MM_swapImage('btn_ok_verde','','imagens/btn_ok_verde_over.gif',1);\">";
	string += "</td>";
	string += "</tr>";
	string += "<tr>";
	string += "<td align=\"right\" colspan=\"2\">";
	string += "<a class=\"verde\" href=\"#\">Esqueci a minha senha</a>";
	string += "</td>";
	string += "</tr>";
	string += "</table>";
	string += "</form>";

	document.getElementById('div_login').innerHTML = string;

	document.getElementById('id_login').focus();
}

function link_select(selectID){
	select = document.getElementById(selectID);

	if(select.value != ''){
		location.replace(select.value);
	}
}

function defineEstiloCategoria(divID, corF, corT, texto){
	divID = document.getElementById(divID);
	corF = document.getElementById(corF);
	corT = document.getElementById(corT);
	texto = document.getElementById(texto);

	if(texto.value == ''){
		divID.innerHTML = 'Categoria';
	}else{
		divID.innerHTML = texto.value;
	}

	if(corF.value == ''){
		divID.style.backgroundColor = '#FFFFFF';
		corF.value = 'FFFFFF';
	}else{
		divID.style.backgroundColor = '#'+corF.value;
	}

	if(corT.value == ''){
		divID.style.color = '#555555';
		corT.value = '555555';
	}else{
		divID.style.color = '#'+corT.value;
	}
}

function confirmar(msg, evalTrue, evalFalse){
	if(confirm(msg)){
		eval(evalTrue);
	}else{
		eval(evalFalse);
	}
}

function verificaMapa(){
	pais = document.getElementById('pais');
	estado = document.getElementById('estado');
	cidade = document.getElementById('cidade');
	enderecocong = document.getElementById('enderecocong');

	numero = document.getElementById('numero');

	if(pais.value == '0'){
		alert('É necessário informar o PAÍS');
		pais.focus();
		return;
	}

	if(estado.value == '0'){
		alert('É necessário informar o ESTADO');
		estado.focus();
		return;
	}

	if(cidade.value == '0'){
		alert('É necessário informar a CIDADE');
		cidade.focus();
		return;
	}

	if(enderecocong.value == ''){
		alert('É necessário informar a ENDEREÇO');
		enderecocong.focus();
		return;
	}

	abrepop('mapa_teste','?secao=pop_mapa&pais='+pais.value+'&estado='+pais.value+'&cidade='+cidade.value+'&logradouro='+enderecocong.value+'&numero='+numero.value,550,580);
}

//Verifica o valor digitado
function VerValorDigit(numero,moeda) {
	var objRegExp = /[^0-9]+/g;
	var valor = numero.value;
	valor = valor.replace(objRegExp,"");

	var re0 = /^[0-9\\/]+$/;

	if (!re0.test(valor)){
		valor = valor.substring(0,valor.length-1);
	}
	var tamanho = valor.length
	var milhar,centavos;

	if ((moeda == "US") || (moeda == "DR")){
		milhar=',';
		centavos='.';
	} else {
		milhar='.';
		centavos=',';
	}

	if (tamanho <= 5 && tamanho > 2){
		numero.value = valor.substring(0,valor.length - 2) + centavos + valor.substring(valor.length -2,valor.length);
	} else if (tamanho >= 6){
		var quociente = (tamanho - 2) / 3;
		var aux = 5;
		while (quociente >= 1){
			if ( (valor.length - aux) != 0 ){
				valor = valor.substring(0,valor.length - aux) + milhar + valor.substring(valor.length - aux, valor.length);
			}
			aux += 4;
			quociente--;
		}
		numero.value = valor.substring(0,valor.length - 2) + centavos + valor.substring(valor.length -2,valor.length);
	} else {
		numero.value = valor;
	}
}

///////MÁSCARAS////////
function mascara(o,f){
	v_obj=o
	v_fun=f
	setTimeout("execmascara()",1)
}

function execmascara(){
	v_obj.value=v_fun(v_obj.value)
}

//Somente números
function soNumeros(v){
	return v.replace(/\D/g,"");
}

//Botão que, após clicar, desativa o mesmo e aparece outro letreiro... X-)
function submitAguarde(botao, texto_pos, formulario){
	botao.disabled = true;
	botao.value    = texto_pos;
	document.formulario.submit();
}

function blink_text(id, cor1, cor2){
	obj = document.getElementById(id);

	if(obj.style.color == cor1){
		obj.style.color = cor2;
	}else{
		obj.style.color = cor1;
	}
}

/*SCRIPT PARA SCROLL MANUAL HORIZONTAL CUSTOMIZÁVEL*/
var waktu=0;

function horizontal_scroll_esq(){
	frame_name.scrollBy(-2,0);waktu=setTimeout('horizontal_scroll_esq()',5);
}
function horizontal_scroll_dir(){
	frame_name.scrollBy(2,0);waktu=setTimeout('horizontal_scroll_dir()',5);
}
function horizontal_scroll_sai() {
	clearTimeout(waktu);
}

//Funções para o upload baf em flash http://www.masrizal.com/index.cfm?fuseaction=idea.download_detail&ProductID=php_flashupload_eval&msg=Thank%20you%20for%20your%20evaluation%20request%2E%3Cbr%3EYour%20download%20link%20has%20been%20sent%20to%3A%20rtamura%40gmail%2Ecom&CFID=23498853&CFTOKEN=97788422
/*function ShowStatus_F(iFlashUploadStatus)
{
if (iFlashUploadStatus==1) {alert("------- ENVIO COMPLETO --------")};
else if (iFlashUploadStatus==-1) alert("ERRO: Envio cancelado");
else if (iFlashUploadStatus==-2) alert("ERRO: IO error");
else if (iFlashUploadStatus==-3) alert("ERRO: Security error");
else if (iFlashUploadStatus==-4) alert("ERRO: HTTP Error");

if (iFlashUploadStatus==2) document.body.style.cursor="wait"; // uploading
else document.body.style.cursor="";
}*/
/*
function Upload()
{
var objFlash;
var iFlashUploadResult;

if(navigator.appName.indexOf("Microsoft") != -1)  objFlash = window.<?=$HTTP_POST_VARS["FlashUploadName"]?>;
else objFlash = window.document.<?=$HTTP_POST_VARS["FlashUploadName"]?>;

iFlashUploadResult=objFlash.FlashUpload_DoUpload();
if (iFlashUploadResult)
{
// uploading
}
else
{
alert("Please select file to upload first");
}
}*/
////////////////
var xImage = 0;
function changeImageV1() {
	document.getElementById('imagetobechanged').src = images[xImage];
	var maxIMAGES = Number(document.getElementById('maxIMAGES').value - 1);
	if(xImage == maxIMAGES){
		xImage = 0;
	}else{
		xImage+=1;
	}
}
