/**

 * $Author: marcelo $

 * $Revision: 1.8 $ $Date: 2003/05/14 19:00:38 $   

 * 

 * $Log: scripts.js,v $

 * Revision 1.8  2003/05/14 19:00:38  marcelo

 * Ops! Esqueci de tirar os alerts...

 *

 * Revision 1.7  2003/05/14 18:44:16  marcelo

 * Alteracao para que possa ser clicado em OK na Busca do menu lateral

 * sem se alterar o conteudo default de palavra chave.

 *

 * Revision 1.6  2003/04/30 16:15:53  nilton

 * asdf

 *

 */

// This function goes through the options for the given

// drop down box and removes them in preparation for

// a new set of values



function emptyList( box ) {

	// Set each option to null thus removing it

	while ( box.options.length ) box.options[0] = null;

}



// This function assigns new drop down options to the given

// drop down box from the list of lists specified



function fillList( box, arr ) {

	// arr[0] holds the display text

	// arr[1] are the values



	for ( i = 0; i < arr[0].length; i++ ) {



		// Create a new drop down option with the

		// display text and value from arr



		option = new Option( arr[0][i], arr[1][i] );



		// Add to the end of the existing options



		box.options[box.length] = option;

	}



	// Preselect option 0



	box.selectedIndex=0;

}



// This function performs a drop down list option change by first

// emptying the existing option list and then assigning a new set



function changeList( box ) {

	// Isolate the appropriate list by using the value

	// of the currently selected option

	list = lists[box.options[box.selectedIndex].value];



	// Next empty the slave list

	if (box.value != "-1"){

		box.form.cbmunicipio.disabled = false;

	}else {

		box.form.cbmunicipio.disabled = true;

	}



	emptyList( box.form.cbmunicipio );



	// Then assign the new list values

	if(list != null)

		fillList( box.form.cbmunicipio, list );

}



// This function validates a submit action, verifying if some fields were 

// written correctly, like "MODULO" and "MUNICIPIO".

//If dspalavra was not modified, changes its value to empty



function validaSubmit(){

	if (document.frmnewbusca.dspalavrachave.value == "Palavra-chave"){

		alert("Digite uma palavra chave para realizar a busca.")

		document.frmnewbusca.dspalavrachave.value = '';

		document.frmnewbusca.dspalavrachave.focus();

		return false;

	}

	else if (document.frmnewbusca.cbmodulo.value < 0){

		alert("Escolha o módulo para realizar a busca.")

		document.frmnewbusca.cbmodulo.focus();

		return false;

	} 

	else if(document.frmnewbusca.master.value < 0){

		alert("Escolha a abrangência para realizar a busca.")

		document.frmnewbusca.master.focus();

		return false;	

	}

	else if(document.frmnewbusca.municipio.value == ''){

		alert("Escolha o município para realizar a busca.")

		document.frmnewbusca.municipio.focus();

		return false;	

	}

	

	//If flag's false then you haven't entered anything

	if(document.frmnewbusca.palchaveflag.value == "false"){

		document.frmnewbusca.dspalavrachave.value = "";

	}	

	

	document.frmnewbusca.submit();

}



// sendGestour 1.0

// Autor: Evandro L. C. Boeing

// Criado em: 30/01/2003

// Funcao para indicacao do gestour

//

// Parametros:

// layout - caminho on se encontra o jsp



function sendGestour(layout){

    window.open("/webengine/servlet/Controller?command="+layout+"&modulo=email&mailType=montarIndique",'email','width=320,height=370,top=300,left=200,resizable,');

}



// sendLink 1.0

// Autor: Evandro L. C. Boeing

// Criado em: 30/01/2003

// Funcao para indicacao de paginas do gestour

//

// Parametros:

// layout - caminho on se encontra o jsp



function sendLink(layout){

    window.open("/webengine/servlet/Controller?command="+layout+"&modulo=email&mailType=montarLink",'email','width=320,height=310,top=300,left=200,resizable,');

}



// sendSugestao 1.0

// Autor: Evandro L. C. Boeing

// Criado em: 30/01/2003

// Funcao para envio de sugestoes sobre o gestour

//

// Parametros:

// layout - caminho on se encontra o jsp



function sendSugestao(layout){

    window.open("/webengine/servlet/Controller?command="+layout+"&modulo=email&mailType=montarSugestao",'email','width=400,height=500,top=300,left=200,resizable,');

}





function fillSelectFromArray(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) {

	var i, j;

	var prompt;

	if(itemArray == null) 

		selectCtrl.disabled=true;

	else

		selectCtrl.disabled=false;

	

		

	// empty existing items

	for (i = selectCtrl.options.length; i >= 0; --i) {

		selectCtrl.options[i] = null; 

	}

	

	

			

	prompt = (itemArray != null) ? goodPrompt : badPrompt;

	if (prompt == null) {		

		j = 0;

	}



	else {	

		selectCtrl.options[0] = new Option(prompt);

		j = 1;

	}

	

	if (itemArray != null) {

	// add new items

		for (i = 0; i < itemArray.length; i++) {

			selectCtrl.options[j] = new Option(itemArray[i][0]);

			if (itemArray[i][1] != null) {

				selectCtrl.options[j].value = itemArray[i][1]; 

		}



		j++;

	}

	

	

	// select first item (prompt) for sub list



	if(selectCtrl.length > 0) 

		selectCtrl.options[0].selected = true;

	else

		selectCtrl.disabled=true;





   }

}



function validaSugestao(){

	

	var validarCampos = validarCamposObrigatoriosDuvidas();

		

	if (validarCampos)

	{	

		var validarEmail = validarCampoEmail(document.form.from);

		 

		if (validarEmail)

		{	

			document.form.submit();

		}

	}	

}



function validarCamposObrigatoriosDuvidas()

{

	if (document.form.message.value == ""){

		alert("Por favor, digite sua mensagem.")

		document.form.message.value = '';

		document.form.message.focus();

		return false;

	}

	if (document.form.from.value == ""){

		alert("Por favor, digite seu endereço de e-mail.")

		document.form.from.value = '';

		document.form.from.focus();

		return false;

	}

	

	return true;

}



function validaIndique(){

	

	var validarCampos = validarCamposObrigatoriosIndique();

			

	if (validarCampos)

	{	

		var to = validarCampoEmail(document.form.to);		

	

		if (to)

		{

			var from = validarCampoEmail(document.form.from);		

			

			if (from)

			{

				document.form.submit();	

			}

		}

	}	

}



function validarCamposObrigatoriosIndique()

{

	if (document.form.toName.value == ""){

		alert("Por favor, digite o nome do destinatário.")

		document.form.toName.value = '';

		document.form.toName.focus();

		return false;

	}

	if (document.form.to.value == ""){

		alert("Por favor, digite o endereço de e-mail do destinatário.")

		document.form.to.value = '';

		document.form.to.focus();

		return false;

	}

	

	if (document.form.fromName.value == ""){

		alert("Por favor, digite o nome do remetente.")

		document.form.fromName.value = '';

		document.form.fromName.focus();

		return false;

	}

	if (document.form.from.value == ""){

		alert("Por favor, digite o endereço de e-mail do remetente.")

		document.form.from.value = '';

		document.form.from.focus();

		return false;

	}

			

	return true;

}



function validaGeral(){

	

	var validarCampos = validarCamposObrigatoriosGeral();

			

	if (validarCampos)

	{	

		var to = validarCampoEmail(document.frmGeral.to);		

	

		if (to)

		{

			var from = validarCampoEmail(document.frmGeral.from);		

			

			if (from)

			{

				document.frmGeral.submit();

			}

		}

	}	

}



function validarCamposObrigatoriosGeral()

{

	if (document.frmGeral.message.value == ""){

		alert("Por favor, digite sua mensagem.")

		document.frmGeral.message.value = '';

		document.frmGeral.message.focus();

		return false;

	}



	if (document.frmGeral.message.value.length > 5000){

		alert("A mensagem deve conter no máximo 5000 caracteres.")

		document.frmGeral.message.focus();

		return false;

	}

	

	if (document.frmGeral.fromName.value == ""){

		alert("Por favor, digite o nome do remetente.")

		document.frmGeral.fromName.value = '';

		document.frmGeral.fromName.focus();

		return false;

	}



	if (document.frmGeral.from.value == ""){

		alert("Por favor, digite o endereço de e-mail do remetente.")

		document.frmGeral.from.value = '';

		document.frmGeral.from.focus();

		return false;

	}

		

	return true;

}



function limpaGeral()

{	

	document.frmGeral.message.value = "";	

	document.frmGeral.fromName.value = "";

	document.frmGeral.cidade.value = "";

	document.frmGeral.uf.value= "AC";	

	document.frmGeral.from.value = "";	

	document.frmGeral.ddd.value = "";	

	document.frmGeral.telefone.value = "";	

	

	document.frmGeral.message.focus();

}



function validarCampoEmail(email){	

	var cont1 = 0;

	var cont2 = 0;

	

	for (var i = 0; i < email.value.length; i++)

	{	

		var c = email.value.charAt(i);

		 

		if (c == '@')

			cont1 ++;

		

		if (c == '.')

			cont2 ++;

	}

	

  	if (cont1 > 1 || cont1 == 0 || cont2 == 0)

  	{

  		alert("Endereço de e-mail inválido!");

  		email.value = '';

		email.focus();

		return false;

  	}

  	

  	if (email.value == "" || 

    	(email.value.indexOf('@', 0) == -1 &&

      	email.value.indexOf('.', 0) == -1))

  	{	

  		alert("Endereço de e-mail inválido!");

  		email.value = '';

		email.focus();

		return false;

  	} 

  	 

  	return true;

}



function validarDadosMandic()

{	

	var valido = false;

	

	if (document.FormName.login_username.value == "")

	{

		alert("Por favor, digite seu login.")

		document.FormName.login_username.value = "";

		document.FormName.login_username.focus();

		return false;

	}	

	else if (document.FormName.secretkey.value == "")

	{

		alert("Por favor, digite sua senha.")

		document.FormName.secretkey.value = "";

		document.FormName.secretkey.focus();

		return false;

	}		

	else

	{

		valido = true;						

	}	

	

	if (valido)

	{

		document.FormName.submit();

	}

}