// JavaScript Document
function valida_dados(nomeform)
{
	if((nomeform.nome.value=="") || 
	   (nomeform.email.value=="") ||
	   (nomeform.assunto.value=="") ||
	   (nomeform.mensagem.value==""))
	{
		alert("Olá!\nTodos os campos devem ser preenchidos.");	
		return false;
	}
	//alert("Passei aqui!");
	if ((nomeform.email.value.indexOf('@',0)== -1) || 
	    (nomeform.email.value.indexOf('.',0)== -1))
	{
		alert("Por favor, digite um e-mail válido.");
		return false;
	}
	return true;
	
}

function valida_dadosContato()
{
	if(($('nome').value=="") || 
	   ($('email').value=="") ||
	   ($('assunto').value=="") ||
	   ($('mensagem').value==""))
	{
		alert("Olá!\nTodos os campos devem ser preenchidos.");	
		return false;
	}
	//alert("Passei aqui!");
	if (($('email').value.indexOf('@',0)== -1) || 
	    ($('email').value.indexOf('.',0)== -1))
	{
		alert("Por favor, digite um e-mail válido.");
		return false;
	}
	
	igoal_submitForm('contato','cl_contato.php')
	return false;
	
}

function sql_saveForm()
{
	var xForm = document.getElementById('save_Message');
	if(xForm.value>0) alert('Configuração efeturada com sucesso!');
	if(xForm.value==0) alert('Não foi possível efetuar a configuração. Houve um problema de gravação!');

}

function sql_saveMessage()
{
	var xForm = document.getElementById('save_Message');
	if(xForm.value>0) alert('Sua mensagem foi enviada com sucesso!');
	if(xForm.value==0) alert('Não foi possivel enviar sua mensagem!');

}

// Users

function valida_dados_users()
{
		var idForm0 = "post_idUsers";
		var idForm1 = "tx_nomeUsers";
		var idForm2 = "tx_emailUsers";
		var idForm3 = "tx_loginUsers";
		var idForm4 = "tx_senhaUsers";
	
    var xForm0 = document.getElementById(idForm0);
	var xForm1 = document.getElementById(idForm1);
	var xForm2 = document.getElementById(idForm2);
	var xForm3 = document.getElementById(idForm3);
	var xForm4 = document.getElementById(idForm4);

	if((xForm1.value=="") || 
	   (xForm3.value=="") ||
	   	   (xForm4.value==""))
	{
		alert("Todos os campos devem ser preenchidos.");	
		return false;
	}

	/*if ((nomeform.email.value.indexOf('@',0)== -1) || 
	    (nomeform.email.value.indexOf('.',0)== -1))
	{
		alert("Por favor, digite um e-mail válido.");
		return false;
	}*/
	
	if(confirmOperation('post_confirmSave', 'As alterações serão gravadas. \nDeseja prosseguir?'))
	{
		return true;
	}

	return false;
	
} 

var ar_idUsers = new Array();
var ar_nomeUsers = new Array();
var ar_emailUsers = new Array();
var ar_loginUsers = new Array();
var ar_senhaUsers = new Array();

var pos_arrayUsers = 0;

function inicializaArrayUsers()
{
	ar_idUsers.length = 0;
	ar_nomeUsers.length = 0;
	ar_emailUsers.length = 0;
	ar_loginUsers.length = 0;
    ar_senhaUsers.length = 0;

	pos_arrayUsers = 0;

}

function sql_arrayPushIdUsers(theValue)
{
	ar_idUsers.push(theValue);
}

function sql_arrayPushNomeUsers(theValue)
{
	ar_nomeUsers.push(theValue);
}
function sql_arrayPushEmailUsers(theValue)
{
	ar_emailUsers.push(theValue);
}
function sql_arrayPushLoginUsers(theValue)
{
	ar_loginUsers.push(theValue);
}
function sql_arquivoPushSenhaUsers(theValue)
{
	ar_senhaUsers.push(theValue);
}

function sql_pushFormsUsers()
{
	   var id_formTotal = "bd_totalRows_rs_Users";
	   var xFormTotal = document.getElementById(id_formTotal);
	   
	   inicializaArrayUsers();
	   
	   for(var i=0; i<xFormTotal.value;i++)
	   {
	   		var id_form0 = "bd_idUsers" + i;
		    var xForm = document.getElementById(id_form0);
			sql_arrayPushIdUsers(xForm.value);

	   		var id_form1 = "bd_nomeUsers"  + i;
		    var xForm = document.getElementById(id_form1);
			ar_nomeUsers.push(xForm.value);

	   		var id_form2 = "bd_emailUsers" + i;
		    var xForm = document.getElementById(id_form2);
			ar_emailUsers.push(xForm.value);

	   		var id_form3 = "bd_loginUsers" + i;
		    var xForm = document.getElementById(id_form3);
			ar_loginUsers.push(xForm.value);

			
	   		var id_form4 = "bd_senhaUsers" + i;
		    var xForm = document.getElementById(id_form4);
			ar_senhaUsers.push(xForm.value);


		}
		
		sql_arrayPopulateFormsUsers(0);

}


function sql_arrayPopulateFormsUsers(theArrayPos)
{
		if(ar_idUsers.length <= 0) return;
		
		var x = document.getElementById('post_idUsers');
		x.value = ar_idUsers[theArrayPos];
		
		var x = document.getElementById('tx_nomeUsers');
		x.value = ar_nomeUsers[theArrayPos];
		
		var x = document.getElementById('tx_emailUsers');
		x.value = ar_emailUsers[theArrayPos];
		
	    var x = document.getElementById('tx_loginUsers');
		x.value = ar_loginUsers[theArrayPos];
		
		
}

function sql_arrayResetFormsUsers()
{
	$('tx_nomeUsers').value="";		
	$('tx_emailUsers').value="";		
	$('tx_loginUsers').value="";		
}

function sql_arrayPopulateFormsUsersSelection(theValue)
{
	theArrayPos = 0;
	for(var i=0;i<ar_idUsers.length;i++)
	{
		if(ar_idUsers[i] == theValue) theArrayPos = i;
	}
		
	sql_arrayPopulateFormsUsers(theArrayPos);
}

// Noticias

function valida_dados_noticias()
{
		var idForm1 = "tx_titulo";
		var idForm2 = "ta_content";
		var idForm3 = "ta_sinopse";
	
	if(($(idForm1).value=="") ||  ($(idForm3).value=="") ||
	   ($(idForm2).value==""))	{
		alert("Todos os campos devem ser preenchidos.");	
		return false;
	}

	
	if(confirmOperation('post_confirmSave', 'As alterações serão gravadas. \nDeseja prosseguir?'))
	{
		igoal_submitFormAdmin('noticias','admin/noticias.php');
		//return true;
	}

	return false;
	
} 

var ar_idBlog = new Array();
var ar_tituloBlog = new Array();
var ar_contentBlog = new Array();
var ar_quemBlog = new Array();

//var pos_arrayAgenda = 0;

function inicializaArrayBlog()
{
	ar_idBlog.length = 0;
	ar_tituloBlog.length = 0;
	ar_contentBlog.length = 0;
	ar_quemBlog.length = 0;

	pos_arrayBlog = 0;

}

function sql_pushFormsBlog()
{
	   var id_formTotal = "bd_totalRows_rs_Blog";
	   var xFormTotal = $(id_formTotal).value;
	   inicializaArrayBlog();
	   
	   for(var i=0; i<xFormTotal;i++)
	   {
	   
	   		var id_form0 = "bd_idBlog" + i; 
			ar_idBlog.push($(id_form0).value);

	   		var id_form1 = "bd_tituloBlog"  + i;
			ar_tituloBlog.push($(id_form1).value);

	   		var id_form2 = "bd_contentBlog" + i;
			ar_contentBlog.push($(id_form2).value);

	   		var id_form3 = "bd_quemBlog" + i;
			ar_quemBlog.push($(id_form3).value);
			
		}
		
		sql_arrayPopulateFormsBlog(0); 

}


function sql_arrayPopulateFormsBlog(theArrayPos)
{
		if(ar_idBlog.length <= 0) return;

		$('post_idBlog').value = ar_idBlog[theArrayPos];

		$('tx_tituloBlog').value = ar_tituloBlog[theArrayPos];

		$('ta_contentBlog').value = ar_contentBlog[theArrayPos];
		
		$('tx_quemBlog').value = ar_quemBlog[theArrayPos];
		
		var id_form6 = 'bd_cbImagemBlog'+ theArrayPos; 
		var valueCB = parseInt($(id_form6).value);  
		if(valueCB) {$('cb_imagemBlog').checked = true;}
		else {$('cb_imagemBlog').checked = false; }

		

}

function sql_arrayResetFormsBlog()
{
	$('tx_tituloBlog').value = "";
	$('ta_contentBlog').value = "";
	$('tx_quemBlog').value = "";
	$('cb_imagemBlog').checked = false;

}

function sql_arrayPopulateFormsBlogSelection(theValue)
{
	theArrayPos = 0;
	for(var i=0;i<ar_idBlog.length;i++)
	{
		if(ar_idBlog[i] == theValue) theArrayPos = i;
	}
		
	sql_arrayPopulateFormsBlog(theArrayPos);
}
// Users

function valida_dados_users()
{
		var idForm0 = "post_idUsers";
		var idForm1 = "tx_nomeUsers";
		var idForm2 = "tx_emailUsers";
		var idForm3 = "tx_loginUsers";
		var idForm4 = "tx_senhaUsers";
	
    var xForm0 = document.getElementById(idForm0);
	var xForm1 = document.getElementById(idForm1);
	var xForm2 = document.getElementById(idForm2);
	var xForm3 = document.getElementById(idForm3);
	var xForm4 = document.getElementById(idForm4);

	if((xForm1.value=="") || 
	   (xForm3.value=="") ||
	   	   (xForm4.value==""))
	{
		alert("Todos os campos devem ser preenchidos.");	
		return false;
	}

	/*if ((nomeform.email.value.indexOf('@',0)== -1) || 
	    (nomeform.email.value.indexOf('.',0)== -1))
	{
		alert("Por favor, digite um e-mail válido.");
		return false;
	}*/
	
	if(confirmOperation('post_confirmSave', 'As alterações serão gravadas. \nDeseja prosseguir?'))
	{
		igoal_submitFormAdmin('users','admin/users.php');
		//return true;
	}

	return false;
	
	
} 

var ar_idUsers = new Array();
var ar_nomeUsers = new Array();
var ar_emailUsers = new Array();
var ar_loginUsers = new Array();
var ar_senhaUsers = new Array();

var pos_arrayUsers = 0;

function inicializaArrayUsers()
{
	ar_idUsers.length = 0;
	ar_nomeUsers.length = 0;
	ar_emailUsers.length = 0;
	ar_loginUsers.length = 0;
    ar_senhaUsers.length = 0;

	pos_arrayUsers = 0;

}

function sql_arrayPushIdUsers(theValue)
{
	ar_idUsers.push(theValue);
}

function sql_arrayPushNomeUsers(theValue)
{
	ar_nomeUsers.push(theValue);
}
function sql_arrayPushEmailUsers(theValue)
{
	ar_emailUsers.push(theValue);
}
function sql_arrayPushLoginUsers(theValue)
{
	ar_loginUsers.push(theValue);
}
function sql_arquivoPushSenhaUsers(theValue)
{
	ar_senhaUsers.push(theValue);
}

function sql_pushFormsUsers()
{
	   var id_formTotal = "bd_totalRows_rs_Users";
	   var xFormTotal = document.getElementById(id_formTotal);
	   
	   inicializaArrayUsers();
	   
	   for(var i=0; i<xFormTotal.value;i++)
	   {
	   		var id_form0 = "bd_idUsers" + i;
		    var xForm = document.getElementById(id_form0);
			sql_arrayPushIdUsers(xForm.value);

	   		var id_form1 = "bd_nomeUsers"  + i;
		    var xForm = document.getElementById(id_form1);
			ar_nomeUsers.push(xForm.value);

	   		var id_form2 = "bd_emailUsers" + i;
		    var xForm = document.getElementById(id_form2);
			ar_emailUsers.push(xForm.value);

	   		var id_form3 = "bd_loginUsers" + i;
		    var xForm = document.getElementById(id_form3);
			ar_loginUsers.push(xForm.value);

			
	   		var id_form4 = "bd_senhaUsers" + i;
		    var xForm = document.getElementById(id_form4);
			ar_senhaUsers.push(xForm.value);


		}
		
		sql_arrayPopulateFormsUsers(0);

}


function sql_arrayPopulateFormsUsers(theArrayPos)
{
		if(ar_idUsers.length <= 0) return;
		
		var x = document.getElementById('post_idUsers');
		x.value = ar_idUsers[theArrayPos];
		
		var x = document.getElementById('tx_nomeUsers');
		x.value = ar_nomeUsers[theArrayPos];
		
		var x = document.getElementById('tx_emailUsers');
		x.value = ar_emailUsers[theArrayPos];
		
	    var x = document.getElementById('tx_loginUsers');
		x.value = ar_loginUsers[theArrayPos];
		
		
}

function sql_arrayResetFormsUsers()
{
	$('tx_nomeUsers').value="";		
	$('tx_emailUsers').value="";		
	$('tx_loginUsers').value="";		
}

function sql_arrayPopulateFormsUsersSelection(theValue)
{
	theArrayPos = 0;
	for(var i=0;i<ar_idUsers.length;i++)
	{
		if(ar_idUsers[i] == theValue) theArrayPos = i;
	}
		
	sql_arrayPopulateFormsUsers(theArrayPos);
}

// Noticias

function valida_dados_noticia()
{
		var idForm1 = "tx_titulo";
		var idForm2 = "ta_content";
		var idForm3 = "ta_sinopse";
	
	if(($(idForm1).value=="") ||  ($(idForm3).value=="") ||
	   ($(idForm2).value==""))	{
		alert("Todos os campos devem ser preenchidos.");	
		return false;
	}

	
	if(confirmOperation('post_confirmSave', 'As alterações serão gravadas. \nDeseja prosseguir?'))
	{
		igoal_submitFormAdmin('users','admin/noticias.php');
		//return true;
	}

	return false;
	
} 

var ar_idNoticia = new Array();
var ar_tituloNoticia = new Array();
var ar_contentNoticia = new Array();
var ar_sinopseNoticia = new Array();

//var pos_arrayAgenda = 0;

function inicializaArrayNoticia()
{
	ar_idNoticia.length = 0;
	ar_tituloNoticia.length = 0;
	ar_contentNoticia.length = 0;
	ar_sinopseNoticia.length = 0;

	pos_arrayNoticia = 0;

}

function sql_pushFormsNoticias()
{
	   var id_formTotal = "bd_totalRows_rs_noticias";
	   var xFormTotal = $(id_formTotal).value;
	   inicializaArrayNoticia();
	   
	   for(var i=0; i<xFormTotal;i++)
	   {
	   
	   		var id_form0 = "bd_idNoticia" + i; 
			ar_idNoticia.push($(id_form0).value);

	   		var id_form1 = "bd_tituloNoticia"  + i;
			ar_tituloNoticia.push($(id_form1).value);

	   		var id_form2 = "bd_contentNoticia" + i;
			ar_contentNoticia.push($(id_form2).value);

	   		var id_form3 = "bd_sinopseNoticia" + i;
			ar_sinopseNoticia.push($(id_form3).value);
			
		}
		
		sql_arrayPopulateFormsNoticia(0); 

}


function sql_arrayPopulateFormsNoticia(theArrayPos)
{
		if(ar_idNoticia.length <= 0) return;

		$('post_idNoticia').value = ar_idNoticia[theArrayPos];

		$('tx_titulo').value = ar_tituloNoticia[theArrayPos];

		$('ta_content').value = ar_contentNoticia[theArrayPos];
		
		$('ta_sinopse').value = ar_sinopseNoticia[theArrayPos];	

}

function sql_arrayResetFormsNoticia()
{
	$('tx_titulo').value = "";
	$('ta_content').value = "";
	$('ta_sinopse').value = "";

}

function sql_arrayPopulateFormsNoticiaSelection(theValue)
{
	theArrayPos = 0;
	for(var i=0;i<ar_idNoticia.length;i++)
	{
		if(ar_idNoticia[i] == theValue) theArrayPos = i;
	}
		
	sql_arrayPopulateFormsNoticia(theArrayPos);
}

function set_btNovo()
{
	var x = document.getElementById('post_btNovo');
	x.value = true;
}

function confirmOperation(theForm,theMsg)
{
    var x = document.getElementById(theForm);

	if(confirm(theMsg))
	{
		x.value = true;
		return true;
	}
	
	x.value = false;
	return false;
}