var xmlHttp;
var codigolinha;
var codigousuario;


function callAjax(){
	if(window.ActiveXObject){
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}else if(window.XMLHttpRequest){
		xmlHttp = new XMLHttpRequest();
	}
}

// Utilizado para criar o efeito de loading
function loading(opt) {
	if (opt == true) {
		// A tag que receberá a img de loading
		var refer = gE('bgBody');
		// O tamanho da referida tag
		var referHeight = refer.offsetHeight;
		// Dizemos que os elementos dentro dela será alinhado ao centro
		refer.style.textAlign = 'center';
		// Criamos uma imagem, img.
		var img = document.createElement('img');
		// Informamos o caminho da img
		img.setAttribute('src','images/loading.gif');
		// Setamos um atributo ID na img criada
		img.setAttribute('id','loading');
		// Definimos seu tamanho
		img.setAttribute('width','20');
		// Definimos seu tamanho
		img.setAttribute('height','17');
		// Dizemos que o margin-top será a metada do tamanho da div
		img.style.marginTop = (referHeight /2) + 'px';
		// Evita que seja criada duas ou mais img de loading
		if (!document.getElementById('loading')) {
			// Insere a img na tag informada na variável refer
			refer.insertBefore(img, refer.firstChild);
		}
	} else if (opt == false) {
		// Referenciamos a img de login através de seu ID
		var imgLoading = gE('loading');
		// Removemos a img de loading
		if (imgLoading) {
			imgLoading.parentNode.removeChild(imgLoading);
		}
	}
}

function mostralinha(codigo,acao){
	var linha = document.getElementById(codigo);
	if(acao == "entra"){
		linha.className = "rowlinha3";
	}
	if(acao == "sai"){
		if(codigo%2){
			linha.className = "rowlinha1";
		}else{
			linha.className = "rowlinha2";		
		}
	}
}

function gE(ID) {
	return document.getElementById(ID);
}

// Utilizado para evitar de digitar: document.getElementsByTagName toda hora, tornando o processo mais prático
function gEs(tag) {
	return document.getElementsByTagName(tag);
}
// Utilizado para criar o fundo sobre a página (wiewport), body.
function exibirBgBody() {
	// Seleciona a tag body. item(0) por que só existe uma tag body
	var tagBody = gEs('body').item(0);
	// Pega os tamanhos atuais da página, como largura, altura, ...
	var sizesPage = getPageSize();
	// Vamos criar uma tag div
	var bgBody = document.createElement('div');
	// Setar o atributo ID a div criada
	bgBody.setAttribute('id','bgBody');
	// Essa div terá o tamanho exato da página
	bgBody.style.height = arrayPageSize[1] + 'px';
	// Essa div terá a largura exata da página
	bgBody.style.width = arrayPageSize[0] + 'px';
	// Evita criar a div novamente
	if (!gE('bgBody')) {
		tagBody.insertBefore(bgBody, tagBody.firstChild);
	}	
}

// Cria a div denominada como boxCad, a qual conterá o formulário de cadastro
function boxCad() {
	// Cria um 'container' que comportará o formulário de cadastro.
	var objBody = gEs('body').item(0);
	var sizesPage = getPageSize();
	var boxCad = document.createElement('div');
	boxCad.setAttribute('id','boxCad');
	var wPage = arrayPageSize[3]; // Largura total da página
	var hPage = arrayPageSize[2]; // tamanho total da página
	/*boxCad.style.width = (wPage / 2) + 'px'; // metade da largura da página*/
	boxCad.style.height = (wPage / 1) + 'px'; // metada da altura da página
	boxCad.style.marginTop = -(wPage / 3) + 'px'; // 1 quarto da largura
	//boxCad.style.marginLeft = -(wPage / 4) + 'px'; // 1 quarto da altura
	objBody.insertBefore(boxCad, objBody.lastChild);
}

// Utilizado para criar o efeito de loading
function loading(opt) {
	if (opt == true) {
		// A tag que receberá a img de loading
		var refer = gE('bgBody');
		// O tamanho da referida tag
		var referHeight = refer.offsetHeight;
		// Dizemos que os elementos dentro dela será alinhado ao centro
		refer.style.textAlign = 'center';
		// Criamos uma imagem, img.
		var img = document.createElement('img');
		// Informamos o caminho da img
		img.setAttribute('src','img/imgLoading.gif');
		// Setamos um atributo ID na img criada
		img.setAttribute('id','loading');
		// Definimos seu tamanho
		img.setAttribute('width','126');
		// Dizemos que o margin-top será a metada do tamanho da div
		img.style.marginTop = (referHeight /2) + 'px';
		// Evita que seja criada duas ou mais img de loading
		if (!document.getElementById('loading')) {
			// Insere a img na tag informada na variável refer
			refer.insertBefore(img, refer.firstChild);
		}
	} else if (opt == false) {
		// Referenciamos a img de login através de seu ID
		var imgLoading = gE('loading');
		// Removemos a img de loading
		if (imgLoading) {
			imgLoading.parentNode.removeChild(imgLoading);
		}
	}
}

function removerDivs(quem) {
	var bgBody = gE('bgBody');
	var boxCad = gE('boxCad');
	bgBody.parentNode.removeChild(bgBody);
	if (boxCad) { // Por que ao clicar X (para deletar um registro) cria-se somente o encobridor e năo o boxCad	
		boxCad.parentNode.removeChild(boxCad);
	}
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 

}

function loadpage(){
	callAjax();
	xmlHttp.open("GET","searchtop.php",true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('contentmanager').innerHTML = "<div class='loading'>Loading....<div>";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('contentmanager').innerHTML = "";
				gE('contentmanager').innerHTML = xmlHttp.responseText+"<div id='content'></div>";
				rightpage();
			}
		}
	}
	xmlHttp.send(null);
}

function rightpage(){
	callAjax();
	xmlHttp.open("GET","rightpage.php",true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('rightcolumn').innerHTML = "Loading....";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('rightcolumn').innerHTML = "";
				gE('rightcolumn').innerHTML = xmlHttp.responseText;
//				searchtag('nothing','number');
			}
		}
	}
	xmlHttp.send(null);
}


function welcome(){
	callAjax();
	xmlHttp.open("GET","welcome.php",true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('rightcolumn').innerHTML = "Loading....";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('rightcolumn').innerHTML = "";
				gE('rightcolumn').innerHTML = xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(null);
}

function searchtag(id,kind){
	callAjax();

	if(kind == "number"){
		if(id == "nothing"){
			return false;
			xmlHttp.open("GET","searchtag.php",true);
		}else{
			if(id == "combo"){
					id = document.getElementById('ilness').value;
					if(id == "nothing"){
						return false;
					}
			}
			xmlHttp.open("GET","searchtag.php?tagid="+id,true);
		}
	}
	if(kind == "letter"){
			xmlHttp.open("GET","searchtag.php?tagletter="+id+"&kind=letter",true);
	}
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('content').innerHTML = "<div class='loading'>Searching....<div>";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('content').innerHTML = "";
				gE('content').innerHTML = xmlHttp.responseText;
				if(xmlHttp.responseText == ""){
					gE('content').innerHTML = "nothing was found";
				}
			}
		}
	}
	xmlHttp.send(null);
}

function callnewuser(){
	callAjax();
	xmlHttp.open("GET","newuser.php",true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('contentmanager').innerHTML = "Searching....";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('contentmanager').innerHTML = "";
				gE('contentmanager').innerHTML = xmlHttp.responseText;
				beamember();
			}
		}
	}
	xmlHttp.send(null);
}

function beamember(){
	callAjax();
	xmlHttp.open("GET","beamember.php",true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('rightcolumn').innerHTML = "Loading....";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('rightcolumn').innerHTML = "";
				gE('rightcolumn').innerHTML = xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(null);
}


function loginadmin(){
	callAjax();
	exibirBgBody();
	boxCad();
	xmlHttp.open("GET","loginadmin.php",true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('boxCad').innerHTML = "Searching....";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('boxCad').innerHTML = "";
				gE('boxCad').innerHTML = xmlHttp.responseText;
				gE('panelLoginbx').focus();
			}
		}
	}
	xmlHttp.send(null);
}

function loginadmin2(){
	callAjax();
	var login = gE('panelLoginbx').value;
	var password = gE('panelPassbx').value;
	xmlHttp.open("GET","dologin.php?loginadm="+login+"&passwordadm="+password,true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('admstatus').innerHTML = "Processing";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('admstatus').innerHTML = "";
				gE('admstatus').innerHTML = xmlHttp.responseText;
				if(xmlHttp.responseText != "Account Not Found Or Password Incorrect"){
					removerDivs();
					gE('whois').innerHTML = '<p><a href="#" onclick="javascript:showadmin('+xmlHttp.responseText+')" class="letters">admin</a> | <a href="#" onclick="javascript:loadpage()" class="letters">view site</a></p><p><a href="#" onclick="javascript:logout()" class="inputpass">LOG OUT</a></p>';
					showadmin(xmlHttp.responseText);
				}
			}
		}
	}
	xmlHttp.send(null);
}

function logout(){
	window.location.href = "index.php";
}

function loginuser(){
	callAjax();
	exibirBgBody();
	boxCad();
	xmlHttp.open("GET","loginuser.php",true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('boxCad').innerHTML = "Loading....";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('boxCad').innerHTML = "";
				gE('boxCad').innerHTML = xmlHttp.responseText;
				gE('panelLoginbx').focus();
			}
		}
	}
	xmlHttp.send(null);
}

function loginuser2(){
	callAjax();
	var login = gE('panelLoginbx').value;
	var password = gE('panelPassbx').value;
	xmlHttp.open("GET","dologinuser.php?loginadm="+login+"&passwordadm="+password,true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('admstatus').innerHTML = "Processing";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('admstatus').innerHTML = "";
				gE('admstatus').innerHTML = xmlHttp.responseText;
				if(xmlHttp.responseText != "Account Not Found Or Password Incorrect"){
					removerDivs();
					gE('whois').innerHTML = '<p><a href="#" onclick="javascript:showuser('+xmlHttp.responseText+')" class="letters">admin</a> | <a href="#" onclick="javascript:loadpage()" class="letters">view site</a></p><p><a href="#" onclick="javascript:logout()" class="inputpass">LOG OUT</a></p>';
					showuser(xmlHttp.responseText);
					codigousuario = xmlHttp.responseText;
				}
			}
		}
	}
	xmlHttp.send(null);
}

function showadmin(idadmin){
	callAjax();
	xmlHttp.open("GET","adm.php?idadmin="+idadmin,true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('contentmanager').innerHTML = "<div class='loading'>Searching....<div>";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('contentmanager').innerHTML = "";
				gE('contentmanager').innerHTML = xmlHttp.responseText;
				testimonials(idadmin);
			}
		}
	}
	xmlHttp.send(null);
}

function showuser(idadmin){
	callAjax();
	xmlHttp.open("GET","admuser.php?idadmin="+idadmin,true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('contentmanager').innerHTML = "<div class='loading'>Searching....<div>";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('contentmanager').innerHTML = "";
				gE('contentmanager').innerHTML = xmlHttp.responseText;
				testimonialsuser(idadmin,'');
				gE('menuuserid').value = idadmin;
			}
		}
	}
	xmlHttp.send(null);
}

function showuser2(){
	callAjax();
	var idadmin = gE('menuuserid').value;
	xmlHttp.open("GET","admuser.php?idadmin="+idadmin,true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('contentmanager').innerHTML = "<div class='loading'>Searching....<div>";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('contentmanager').innerHTML = "";
				gE('contentmanager').innerHTML = xmlHttp.responseText;
				testimonialsuser(idadmin,'');
				gE('menuuserid').value = idadmin;
			}
		}
	}
	xmlHttp.send(null);
}

function showpagen(){
	callAjax();
	xmlHttp.open("GET","topindex.php?idadmin="+idadmin,true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('contentmanager').innerHTML = "<div class='loading'>Loading....<div>";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('contentmanager').innerHTML = "";
				gE('contentmanager').innerHTML = xmlHttp.responseText;
					testimonials(idadmin,'1');
			}
		}
	}
	xmlHttp.send(null);
}

function testimonials(id,what){
	callAjax();
	xmlHttp.open("GET","testimonialsadm.php?status="+what+"&id="+id,true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('contentarea').innerHTML = "<div class='loading'>Searching....<div>";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('contentarea').innerHTML = "";
				gE('contentarea').innerHTML = xmlHttp.responseText;
				welcome();
			}
		}
	}
	xmlHttp.send(null);
}


function testimonialsuser(id,what){
	callAjax();
	xmlHttp.open("GET","testimonialsuser.php?status="+what+"&id="+id,true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('contentarea').innerHTML = "<div class='loading'>Searching....<div>";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('contentarea').innerHTML = "";
				gE('contentarea').innerHTML = xmlHttp.responseText;
				welcome();
			}
		}
	}
	xmlHttp.send(null);
}

function createtestimonial(id,what){
	callAjax();
	xmlHttp.open("GET","newtestimonial.php?action="+what+"&id="+id,true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('contentarea').innerHTML = "<div class='loading'>Loading....<div>";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('contentarea').innerHTML = "";
				gE('contentarea').innerHTML = xmlHttp.responseText;
				selectkind(gE('kind').value);
			}
		}
	}
	xmlHttp.send(null);
}

function createtestimonialadm(id,what){
	callAjax();
	xmlHttp.open("GET","newtestimonialadm.php?action="+what+"&id="+id,true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('contentarea').innerHTML = "<div class='loading'>Loading....<div>";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('contentarea').innerHTML = "";
				gE('contentarea').innerHTML = xmlHttp.responseText;
				if(what != "update"){
					getusers();
				}
				selectkind(gE("kind").value);
			}
		}
	}
	xmlHttp.send(null);
}

function updateinfo(action,id){
	callAjax();
	exibirBgBody();
	boxCad();
	xmlHttp.open("GET","updateuser.php?userid="+id,true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('boxcad').innerHTML = "<div class='loading'>Loading form....<div>";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('boxCad').innerHTML = "";
				gE('boxCad').innerHTML = xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(null);
}


function deleteuser(action,id){
	callAjax();
	xmlHttp.open("GET","listusers.php?userid="+id+"&action="+action,true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('contentarea').innerHTML = "<div class='loading'>Processing....<div>";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('contentarea').innerHTML = "";
				gE('contentarea').innerHTML = xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(null);
}


function updateinfouser(action){
	callAjax();
	exibirBgBody();
	boxCad();
	id = gE('menuuserid').value;
	xmlHttp.open("GET","updateuser.php?userid="+id,true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('boxcad').innerHTML = "<div class='loading'>Loading form....<div>";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('boxCad').innerHTML = "";
				gE('boxCad').innerHTML = xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(null);
}

function updateinfo2(action,id){
	callAjax();
	var name = gE("name").value;
	var lastname = gE("lastname").value;
	var state = gE("state").value;
	var city = gE("city").value;
	var menuuserid2 = gE("menuuserid2").value;
	if(menuuserid2 == ""){
		menuuserid2 = "nada";
	}
	xmlHttp.open("GET","updateuser.php?userid="+id+"&name="+name+"&state="+state+"&lastname="+lastname+"&city="+city+"&action=update&menuuserid2="+menuuserid2,true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('boxcad').innerHTML = "<div class='loading'>Updating ....<div>";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('boxCad').innerHTML = "";
				gE('boxCad').innerHTML = xmlHttp.responseText;
				if(xmlHttp.responseText != "notuploaded"){
					removerDivs();
					if(id == 1){
						users();
					}
				}
			}
		}
	}
	xmlHttp.send(null);
}

function newuseradm(){
	callAjax();
	exibirBgBody();
	boxCad();
	xmlHttp.open("GET","newuseradm.php",true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('boxcad').innerHTML = "<div class='loading'>Loading form....<div>";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('boxCad').innerHTML = "";
				gE('boxCad').innerHTML = xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(null);
}

function newuseradm2(){
	callAjax();
	var name= gE('name').value;
	var lastname= gE('lastname').value;
	var city= gE('city').value;
	var state= gE('state').value;
	xmlHttp.open("GET","newuseradm.php?action=new&name="+name+"&lastname="+lastname+"&city="+city+"&state="+state,true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('statusnewuser').innerHTML = "<div class='loading'>Inserting users....<div>";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('statusnewuser').innerHTML = "";
				gE('statusnewuser').innerHTML = xmlHttp.responseText;
				removerDivs();
				getusers();
			}
		}
	}
	xmlHttp.send(null);
}


function getusers(){
	callAjax();
	xmlHttp.open("GET","selectuser.php",true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('useroftest').innerHTML = "<div class='loading'>Loading users....<div>";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('useroftest').innerHTML = "";
				gE('useroftest').innerHTML = xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(null);
}

function whoischecked(whatis){
	callAjax();	
	var text = gE('text').value;
	var video = gE('video').value;
	var audio = gE('audio').value;	
	var iduser = gE('iduser').value;
	var kind = gE('kind').value;
	var title = gE('title').value;	
	var notag = gE('notag').value;
	var selectedvalues = "";
	
	for (i=0; i<document.myform.checkgroup.length; i++){
	if (document.myform.checkgroup[i].checked==true)
		selectedvalues = selectedvalues+document.myform.checkgroup[i].id+",";
	}	
	
	var myresult = replace(audio,'&','#');
	var audio = myresult;
	
	var mynewtext = replace(text,'&','#');
	var text = mynewtext;	
	
	var alldata = "audio="+audio+"&text="+text+"&video="+video+"&kind="+kind+"&title="+title+"&notag="+notag+"&variavel="+selectedvalues;
	xmlHttp.open("POST","testimonialsuser.php?iduser="+iduser+"&action="+whatis,true)
	xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('contentarea').innerHTML = "<div class='loading'>Processing....<div>";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('contentarea').innerHTML = "";
				gE('contentarea').innerHTML = xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(alldata);	
}

function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}


function whoischeckedadm(whatis){
	callAjax();	
	if(whatis != "update"){
		var theuser = gE('theuser').value;	
	}
	var text = gE('text').value;
	var video = gE('video').value;
	var audio = gE('audio').value;	
	var iduser = gE('iduser').value;
	var kind = gE('kind').value;
	var title = gE('title').value;	
	var notag = gE('notag').value;
	var selectedvalues = "";
	for (var i=0; i<document.myform.checkgroup.length; i++){
	if (document.myform.checkgroup[i].checked==true){
			selectedvalues = selectedvalues+document.myform.checkgroup[i].id+",";
		}
	}		

	var myresult = replace(audio,'&','#');
	var audio = myresult;
	
	var mynewtext = replace(text,'&','#');
	var text = mynewtext;
	
	if(whatis != "update"){
	var alldata = "theuser="+theuser+"&audio="+audio+"&text="+text+"&video="+video+"&kind="+kind+"&title="+title+"&notag="+notag+"&variavel="+selectedvalues;
	}else{
	var alldata = "audio="+audio+"&text="+text+"&video="+video+"&kind="+kind+"&title="+title+"&notag="+notag+"&variavel="+selectedvalues;		
	}
	xmlHttp.open("POST","testimonialsadm.php?iduser="+iduser+"&action="+whatis,true);
	xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('contentarea').innerHTML = "<div class='loading'>Processing....<div>";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('contentarea').innerHTML = "";
				gE('contentarea').innerHTML = xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(alldata);	
}



function selectkind(id){
	if(id == 1){
		gE('divaudio').style.display = 'block';
		gE('divvideo').style.display = 'none';
	}

	if(id == 2){
		gE('divaudio').style.display = 'none';
		gE('divvideo').style.display = 'block';
	}

	if(id == 3){
		gE('divaudio').style.display = 'none';
		gE('divvideo').style.display = 'none';
	}

}

function users(){
	callAjax();
	xmlHttp.open("GET","listusers.php",true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('contentarea').innerHTML = "<div class='loading'>Searching....<div>";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('contentarea').innerHTML = "";
				gE('contentarea').innerHTML = xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(null);
}

function listtags(){
	callAjax();
	xmlHttp.open("GET","listtags.php",true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('contentarea').innerHTML = "<div class='loading'>Searching....<div>";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('contentarea').innerHTML = "";
				gE('contentarea').innerHTML = xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(null);
}

function accept(id,action){
	callAjax();
	if(action == "accept" || action == "delete"){
	xmlHttp.open("GET","testimonialsadm.php?action="+action+"&id="+id,true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('contentarea').innerHTML = "<div class='loading'>Wait....<div>";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('contentarea').innerHTML = "";
				gE('contentarea').innerHTML = xmlHttp.responseText;
			}
		}
	}	
	}
	if(action == "reject"){
	exibirBgBody();
	boxCad();
	xmlHttp.open("GET","reasonreject.php?id="+id,true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('boxCad').innerHTML = "<div class='loading'>Wait....<div>";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('boxCad').innerHTML = "";
				gE('boxCad').innerHTML = xmlHttp.responseText;
			}
		}
	}
	}
	xmlHttp.send(null);
}

function newtag(action,id,word){
	exibirBgBody();
	boxCad();
	xmlHttp.open("GET","newtag.php?action="+action+"&id="+id+"&word="+word,true);		
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('boxCad').innerHTML = "<div class='loading'>Wait....<div>";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('boxCad').innerHTML = "";
				gE('boxCad').innerHTML = xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(null);
}	

function newtag2(action,id){
	if(action == "update"){
		var newname = gE('tagname').value;
		xmlHttp.open("GET","listtags.php?action=update&newname="+newname+"&id="+id,true);		
	}
	if(action == "new"){
		var tag = gE('tagname').value;		
		xmlHttp.open("GET","listtags.php?action=new&tag="+tag,true);	
	}
	if(action == "newtag"){
		var tag = gE('tagname').value;		
		xmlHttp.open("GET","testimonialsadm.php?action=newtag&tag="+tag+"&id="+id,true);	
	}	
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('boxCad').innerHTML = "<div class='loading'>Wait....<div>";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('boxCad').innerHTML = "";
				gE('boxCad').innerHTML = xmlHttp.responseText;
				removerDivs();
				if(action != "newtag"){
					listtags();
				}else{
					testimonials('','1');
				}
			}
		}
	}
	xmlHttp.send(null);
}	



function reject(id){
	callAjax();
	var reason = gE('reason').value;
	var what = "reject";
	xmlHttp.open("GET","testimonialsadm.php?action="+what+"&id="+id+"&reason="+reason,true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 1){
			gE('contentarea').innerHTML = "<div class='loading'>Searching....<div>";
		}
		if(xmlHttp.readyState == 4){
			if(xmlHttp.status == 200){
				gE('contentarea').innerHTML = "";
				gE('contentarea').innerHTML = xmlHttp.responseText;
				removerDivs();
			}
		}
	}
	xmlHttp.send(null);
}

function cancel(){
	removerDivs();
}