function callAjaxData(var_retorno, sincrono, url){
	try{
	    xmlhttp = new XMLHttpRequest();
	}catch(ee){
	    try{
	        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	    }catch(e){
	        try{
	            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	        }catch(E){
	            xmlhttp = false;
	        }
	    }
	}
	valor = '';
	xmlhttp.open("GET", url, sincrono);
	xmlhttp.onreadystatechange=function() {
	    if (xmlhttp.readyState==4){
			valor = xmlhttp.responseText;
			eval(var_retorno + '= unescape("' + escape(valor) + '")');
	    }
	}
	xmlhttp.send(null);
}


function append_date_time(nome_form, nome_campo, infos){
	var thetime=new Date();
	var nmonth=thetime.getMonth()+1;
	var ntoday=thetime.getDate();
	var nyear=thetime.getYear();
	var nhour=thetime.getHours();
	var nminute=thetime.getMinutes();
	var nsecond=thetime.getSeconds();
	document.forms[nome_form].elements[nome_campo].value += "\n"+ntoday+"/"+nmonth+"/"+nyear+" "+nhour+":"+nminute+":"+nsecond;
}

function ExcluirSelecionadas(CLICodigo, HOTCodigo, snippet, form){
	if(confirm('Deseja realmente excluir os ítens selecionados?')){
		a_excluir = "";
		for(i=0; i<document.forms[form].elements.length; i++){
			if(document.forms[form].elements[i].checked)
			a_excluir = a_excluir + document.forms[form].elements[i].value+",";
		}
		document.location.href='core.php?snippet='+snippet+'&CLICodigo='+CLICodigo+'&HOTCodigo='+HOTCodigo+'&acao=excluir&a_excluir='+a_excluir;
	}
}

function EditarPaginas(CLICodigo, HOTCodigo, snippet, formulario)
{
	a_alterar = "";
	for(i=0; i<document.forms[formulario].elements.length; i++){
		if(document.forms[formulario].elements[i].checked)
		a_alterar = document.forms[formulario].elements[i].value;
	}
	document.location.href='core.php?snippet='+snippet+'&CLICodigo='+CLICodigo+'&HOTCodigo='+HOTCodigo+'&MODCodigo='+a_alterar;

}

function EditarNoticias(CLICodigo, HOTCodigo, snippet, formulario)
{
	a_alterar = "";
	for(i=0; i<document.forms[formulario].elements.length; i++){
		if(document.forms[formulario].elements[i].checked)
		a_alterar = document.forms[formulario].elements[i].value;
	}
	document.location.href='core.php?snippet='+snippet+'&CLICodigo='+CLICodigo+'&HOTCodigo='+HOTCodigo+'&NOTCodigo='+a_alterar;

}

function EditarNoticiasCategorias(CLICodigo, HOTCodigo, snippet, formulario)
{
	a_alterar = "";
	for(i=0; i<document.forms[formulario].elements.length; i++){
		if(document.forms[formulario].elements[i].checked)
		a_alterar = document.forms[formulario].elements[i].value;
	}
	document.location.href='core.php?snippet='+snippet+'&CLICodigo='+CLICodigo+'&HOTCodigo='+HOTCodigo+'&CANCodigo='+a_alterar;

}

function EditarDepoimentos(CLICodigo, HOTCodigo, snippet, formulario)
{
	a_alterar = "";
	for(i=0; i<document.forms[formulario].elements.length; i++){
		if(document.forms[formulario].elements[i].checked)
		a_alterar = document.forms[formulario].elements[i].value;
	}
	document.location.href='core.php?snippet='+snippet+'&CLICodigo='+CLICodigo+'&HOTCodigo='+HOTCodigo+'&DEPCodigo='+a_alterar;

}

function EditarBanners(CLICodigo, HOTCodigo, snippet, formulario)
{
	a_alterar = "";
	for(i=0; i<document.forms[formulario].elements.length; i++){
		if(document.forms[formulario].elements[i].checked)
		a_alterar = document.forms[formulario].elements[i].value;
	}
	document.location.href='core.php?snippet='+snippet+'&CLICodigo='+CLICodigo+'&HOTCodigo='+HOTCodigo+'&BANCodigo='+a_alterar;

}

function EditarContatos(CLICodigo, HOTCodigo, snippet, formulario)
{
	a_alterar = "";
	for(i=0; i<document.forms[formulario].elements.length; i++){
		if(document.forms[formulario].elements[i].checked)
		a_alterar = document.forms[formulario].elements[i].value;
	}
	document.location.href='core.php?snippet='+snippet+'&CLICodigo='+CLICodigo+'&HOTCodigo='+HOTCodigo+'&DEPCodigo='+a_alterar;

}

function EditarUsuarios(CLICodigo, HOTCodigo, snippet, formulario)
{
	a_alterar = "";
	for(i=0; i<document.forms[formulario].elements.length; i++){
		if(document.forms[formulario].elements[i].checked)
		a_alterar = document.forms[formulario].elements[i].value;
	}
	document.location.href='core.php?snippet='+snippet+'&CLICodigo='+CLICodigo+'&HOTCodigo='+HOTCodigo+'&USUCodigo='+a_alterar;

}

function EditarHotsite(CLICodigo, HOTCodigo, snippet, formulario)
{
	a_alterar = "";
	for(i=0; i<document.forms[formulario].elements.length; i++){
		if(document.forms[formulario].elements[i].checked)
		a_alterar = document.forms[formulario].elements[i].value;
	}
	document.location.href='core.php?snippet='+snippet+'&CLICodigo='+CLICodigo+'&HOTCodigo='+'&_HOTCodigo='+a_alterar;

}

function DestacarSelecionadas(CLICodigo, snippet, form){
	if(confirm('Deseja realmente alterar o status de destaque dos ítens selecionados?')){
		a_destacar = "";
		for(i=0; i<document.forms[form].elements.length; i++){
			if(document.forms[form].elements[i].checked)
			a_destacar = a_destacar + document.forms[form].elements[i].value+",";
		}
		document.location.href='core.php?snippet='+snippet+'&CLICodigo='+CLICodigo+'&acao=destacar&a_destacar='+a_destacar;
	}
}

function AbrirAdmin(url){
	janAdmin = window.open(url, 'janAdmin', 'width=787, height=500, left=1, top=1, scrollbars=yes, resizable=1');
}

function AbreJanela(URL, width, height, top, left, scroll){
	//	window.showModalDialog(URL,ArgValues,'dialogHeight: '+height+'px; dialogWidth: '+width+'px; dialogTop: '+top+'px; dialogLeft: '+left+'px; edge: Raised; scroll: '+scroll+'; unadorned: Yes; center: No; help: No; resizable: No; status: No;');
	janGraph = window.open(URL, 'janela_popup', 'width='+width+', height='+height+', left='+left+', top='+top+', scrollbars='+scroll+', resizable=1');
}

///////////// Seleciona todos os checkbox
var checkflag = "false";
function check(field) {
	if (checkflag == "false") {
		for (i = 0; i < field.length; i++) {
			field[i].checked = true;
		}
		checkflag = "true";
		return true;
	}
	else {
		for (i = 0; i < field.length; i++) {
			field[i].checked = false;
		}
		checkflag = "false";
		return true;
	}
}

function mascaraCampo(objForm, strField, sMask, evtKeyPress) {
	var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;
	if(document.all) { // Internet Explorer
		nTecla = evtKeyPress.keyCode; }
	else if(document.layers) { // Nestcape
		nTecla = evtKeyPress.which;
	}
	sValue = objForm[strField].value;
	// Limpa todos os caracteres de formatação que
	// já estiverem no campo.
	sValue = sValue.toString().replace( "-", "" );
	sValue = sValue.toString().replace( "-", "" );
	sValue = sValue.toString().replace( ".", "" );
	sValue = sValue.toString().replace( ".", "" );
	sValue = sValue.toString().replace( ",", "" );
	sValue = sValue.toString().replace( ",", "" );
	sValue = sValue.toString().replace( "/", "" );
	sValue = sValue.toString().replace( "/", "" );
	sValue = sValue.toString().replace( "(", "" );
	sValue = sValue.toString().replace( "(", "" );
	sValue = sValue.toString().replace( ")", "" );
	sValue = sValue.toString().replace( ")", "" );
	sValue = sValue.toString().replace( " ", "" );
	sValue = sValue.toString().replace( " ", "" );
	fldLen = sValue.length;
	mskLen = sMask.length;
	i = 0;
	nCount = 0;
	sCod = "";
	mskLen = fldLen;
	while (i <= mskLen) {
		bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ","))
		bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))
		if (bolMask) {
			sCod += sMask.charAt(i);
			mskLen++; }
		else {
			sCod += sValue.charAt(nCount);
			nCount++;
		}
		i++;
	}
	objForm[strField].value = sCod;
	if (nTecla != 8) { // backspace
		if (sMask.charAt(i-1) == "9") { // apenas números...
			return ((nTecla > 47) && (nTecla < 58)); 
		} // números de 0 a 9
		else { // qualquer caracter...
			return true;
		}
	}
	else {
		return true;
	}
}

function MascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (whichCode == 13) return true;
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1){ 
		if(whichCode == 37 || whichCode == 39 || whichCode == 17 || whichCode == 8 || whichCode == 46){
			
		}
		else{
			return false; // Chave inválida
		}
	}
	else{
	    len = objTextBox.value.length;
	    for(i = 0; i < len; i++)
	        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
	    aux = '';
	    for(; i < len; i++)
	        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
	    aux += key;
	    len = aux.length;
	    if (len == 0) objTextBox.value = '';
	    if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
	    if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;
	    if (len > 2) {
	        aux2 = '';
	        for (j = 0, i = len - 3; i >= 0; i--) {
	            if (j == 3) {
	                aux2 += SeparadorMilesimo;
	                j = 0;
	            }
	            aux2 += aux.charAt(i);
	            j++;
	        }
	        objTextBox.value = '';
	        len2 = aux2.length;
	        for (i = len2 - 1; i >= 0; i--)
	        objTextBox.value += aux2.charAt(i);
	        objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
	    }
	    return false;
	}
}