﻿function ShowModal(_URL,_width,_height,_scroll)
{	
	//_scroll=1
	if(navigator.appVersion.indexOf("Windows NT 5.1")>0)
	{
	_height+=6
	}
	
	if(window.XMLHttpRequest) 
	{
	    //Para IE7
	    _height-=50
	}

	
	//window.open(_URL)
	return window.showModalDialog(_URL,window,'dialogWidth:'+_width+'px; dialogHeight:'+_height+'px; center:1; dialogHide:0; edge:sunken; help:0; resizable:1; scroll:'+ _scroll +'; status:1; unadorned:1;');
}

//Pega um variavel da Querystring
function QueryString(variavel){

qs=new Array()
variaveis=location.search.replace(/\x3F/,"").replace(/\x2B/g," ").split("&")

if(variaveis!=""){
 for(i=0;i<variaveis.length;i++){
 nvar=variaveis[i].split("=")
 qs[nvar[0]]=unescape(nvar[1])
 }
}
  if(qs[variavel]==undefined)
	return ""
  else
 return qs[variavel]
 
}

function SelecionarComboGaleriaEnsino(comboCategoria)
{
	try{
	indice = QueryString("indiceCombo");
	combo = eval("document.all." + comboCategoria);
	
	combo[indice].selected = true;
	}
	catch(e){}
}

function PesquisarGaleriaEnsino(comboCategoria)
{
	combo = eval("document.all." + comboCategoria);
	
	if(combo.options[combo.selectedIndex].text=="-- selecione --")
		window.location = "?";
	else
	{
		url = location.href.replace(location.search,"");
		filtro = "FilterField1=Categoria:ID&FilterValue1=" + encodeURI(combo.options[combo.selectedIndex].value) 
			+ "&indiceCombo=" + combo.selectedIndex;
		url = url + "?" + filtro;
	
		window.location = url;
	}
	
}

function PesquisarImprensaImagens(campoDescricao)
{
	campo = eval("document.all." + campoDescricao);
	
	if(campo.value=="")
		window.location = "?";
	else
	{
		url = location.href.replace(location.search,"");
		filtro = "FilterField1=NomeImagem&FilterValue1=" + encodeURI(campo.value); 
		
		url = url + "?" + filtro;
	
		window.location = url;
	}
	
}


function EnviarEmailImprensa(Area, ID)
{
	
	window.location = '/Paginas/Compartilhe.aspx?Area=' + Area + '&Link=' +  location.href

}

function MostrarMensagem(Mensagem){
	//Falta implementar Modal personalizado
	alert(Mensagem);
}
function ValidarForm()
{
	var retorno = false;
	if (typeof(Page_ClientValidate) == 'function') 
	{
		retorno = Page_ClientValidate();
	}	 
	else
		retorno = true;

	return retorno;
}

function EnviarFormulario(IdBotao){
	if(ValidarForm())
	{
		document.getElementById(IdBotao).click();
	}
}



/*FUNÇÃO PARA VALIDAR O PREÇO*/
function PutMilion (numero){
	var i=0;
	numero=numero.toString();
	numero=numero.replace(/[.]/g,"");
	numero=numero.replace(/[,]/g,"");
	tamanho = numero.length;
	numerosemdecimais = numero.substring(0, tamanho - 2);
	tamanhosemdecimais = tamanho - 2;
	decimais = numero.substring(tamanho - 2, tamanho);
	numeropontosdecimais = parseInt((tamanho - 2) / 3);
	numero2 = "";
	for(i=0; i<numeropontosdecimais*3; i+=3)
	  numero2 = "." + numerosemdecimais.substring(tamanhosemdecimais - i - 3, tamanhosemdecimais - i) + numero2;
	numero2 = numerosemdecimais.substring(0, tamanhosemdecimais - i) + numero2;
	numero2 = numero2 + "," + decimais;
	if(numero2.substr(0,1) == '.')
	{
	   tamanho = numero2.length;
	   numero2 = numero2.substr(1, tamanho - 1);
	}
	return (numero2);
}

function PutCents (numero){
	var i=0;
	numero=numero.toString();
	numero=numero.replace(/[.]/g,",");
	while ((numero.charAt(i) != ",") && (i < numero.length)) { i++; }
	if ((numero.length-i) > 2) { numero=numero.substr(0,i+3); }
	else
	{
		switch (numero.length - i)
		{
			case 0: numero+=",00"; break;
			case 1: numero+="00"; break;
			case 2: numero+="0"; break;
		}
	}
	return (numero);
}

function ChkNumber2 (campo, status){

	var numero, digitos="0123456789,.", Ok=true, virgula=false;
	if (campo.value == "") { Ok=false; }
	else
	{
		numero=campo.value.replace("-","");
		numero=numero.toString();
		numero=numero.replace(/[.]/g,"");
		numero=numero.replace(/[R$]/g,"");
		if (numero.length > 12) { Ok=false; }
		else
		{
			if ((digitos.indexOf(numero.charAt(0)) < 0) || (digitos.indexOf(numero.charAt(0)) > 9)) { Ok=false; }
			else
			{
				for (var i=1; ((i < numero.length) && (Ok)); i++)
				{
					if (digitos.indexOf(numero.charAt(i)) < 0) { Ok=false; }
					if (digitos.indexOf(numero.charAt(i)) == 10)
					{
						if (((numero.length-i) <= 3) && (!virgula)) { virgula=true; }
						else { Ok=false; }
					}
				}
			}
		}
		if (Ok) 
		{ 
			campo.value= PutMilion(PutCents(numero)); 
		}
		else
		{
			alert( "Valor incorreto: " + numero);
			campo.value="";
			campo.select();
		}
	}
	if (status) { return Ok; }
}
/*FIM*/

//Exemplo: OnBlur="VerificarValor(this);"
function VerificarValor(campo)
{
	ChkNumber2(campo,false);
}


//Exemplo: OnKeyPress="return ChecarNumero(this);"	
function ChecarNumero(e)
{

	if (document.all) // Internet Explorer
		var tecla = event.keyCode;

    if(tecla == 45)
        return true;

	if (tecla > 47 && tecla < 58) // numeros de 0 a 9
		return true;
	else
		{
			if (tecla != 8) // backspace
				//event.keyCode = 0;
				return false;
			else
				return true;
		}
}

//Exemplo: OnKeyPress="return ChecarValor(this);"	
function ChecarValor(e)
{

	if (document.all) // Internet Explorer
		var tecla = event.keyCode;


	if ((tecla > 47 && tecla < 58 ) // numeros de 0 a 9
		 || tecla == 44 //Somente para a virgula 
		 || tecla == 45 //Somente para o hifen 
		 || tecla == 46) //Somente para o ponto
		return true;
	else
		{
			if (tecla != 8) // backspace
				//event.keyCode = 0;
				return false;
			else
				return true;
		}

}

//Exemplo: OnKeyPress="return ChecarTelCep(this);"	
function ChecarTelCep(e)
{

	if (document.all) // Internet Explorer
		var tecla = event.keyCode;
		
	if ((tecla > 47 && tecla < 58 ) // numeros de 0 a 9
		 || tecla == 44 //Somente para a virgula 
		 || tecla == 46 //Somente para o ponto
		 || tecla == 45) //Somente para hifen
		return true;
	else
	{
		if (tecla != 8) // backspace
			//event.keyCode = 0;
			return false;
		else
			return true;
	}
		
}

//Exemplo: OnKeyPress="Mascara(this,"##/##/####")
function Mascara(src, mask) 
{
	var i = src.value.length;
	var saida = mask.substring(0,1);
	var texto = mask.substring(i)
	if (texto.substring(0,1) != saida) 
	{
		src.value += texto.substring(0,1);
	}
}	

	
function RetornarModal(valores)
{
	parametros = new Array();
	parametros = valores.split(";")
	parent.window.returnValue = parametros;
	parent.close();
}

function TratarRetornoModal(retornoModal, campos)
{
	arrayCampos = new Array();
	arrayCampos = campos.split(";");
	
	if(retornoModal!=null){
		for(i=0;i<retornoModal.length;i++)
		{

			try{
			    eval("document.all." + arrayCampos[i] + ".value = '" + retornoModal[i] + "';");
			}
			catch(e){
			}
		}
	}	
}

function TratarEnter(botao)
{
	var tecla = event.keyCode;
	if(tecla==13)
	{
		eval("document.all." + botao + ".click()");
		return false;
	}
	else
		return true;
}



function RetornarRadioSelecionado(nomeObjeto)
{
    selecionado = "";
            
    for (i=0; i<document.forms.length; i++) {
		for (j=0; j<document.forms[i].elements.length; j++) {
			if (document.forms[i].elements[j].name.indexOf(nomeObjeto)>=0 ) {
				
				if(document.forms[i].elements[j].checked)
				{
				    selecionado = document.forms[i].elements[j].value;
				    break;
				}
					
			}

		}
		
	}
    return selecionado;
}

ultima = "default";
function MostrarDiv(idDiv){
	if (ultima.length > 0)
		EsconderDiv(ultima);
	
	ultima = idDiv;
	
	document.getElementById(idDiv).style.display = 'block';			
}

function EsconderDiv(fechaDiv){	
	try{
	document.getElementById(fechaDiv).style.display = 'none';
	}catch(e){}
}

