function confirmaExclusao() {
	if(confirm('Voc&ecirc; tem certeza que deseja excluir?')){
		this.href;
		return true;
	}else{
		return false;
	}
}

function showHideReg(id) {
 var obj = document.getElementById(id);
 if(obj.style.display == "") {
  obj.style.display = "none";
 } else {
  obj.style.display = "";
 }
}

function hide(id) {
 var obj = document.getElementById(id);
 obj.style.display = "none";
}

function show(id) {
 var obj = document.getElementById(id);
  obj.style.display = "";
}

function onChangeFocus(id)
{
	 id.style.backgroundColor='#FFFFAA';
}

function onLostFocus(id)
{
	 id.style.backgroundColor='#FFFFFF';
}

function validaSite(site){
	siteCampo = site.value;
    siteCampo=siteCampo.replace(/^http:\/\/?/,"")
    dominio=siteCampo
    caminho=""
    if(siteCampo.indexOf("/")>-1)
        dominio=siteCampo.split("/")[0]
        caminho=siteCampo.replace(/[^\/]*/,"")
    dominio=dominio.replace(/[^\w\.\+-:@]/g,"")
    caminho=caminho.replace(/[^\w\d\+-@:\?&=%\(\)\.]/g,"")
    caminho=caminho.replace(/([\?&])=/,"$1")
    if(caminho!="")dominio=dominio.replace(/\.+$/,"")
    siteCampo="http://"+dominio+caminho
    site.value = siteCampo;
}

function campoObrigatorio(id)
{
	if(id.value == "")
	{
		alert("Campo Obrigat&oacute;rio!");
		id.focus();
		return false;
	}
	return true;
}
function camposObrigatorios(valores)
{
	var obj;
	var i = 1;
	while(i<=valores.length)
	{
		obj = document.getElementById(valores[i]);
 		if(obj.value == "")
		{
			obj.focus();
			alert("Voc&ecirc; deve preencher todos os campos obrigat&oacute;rios");
			return false;
		}
		i++;
	}
	return true;
}
function validaEmail(email)
{
    parte1 = email.value.indexOf("@");
    parte2 = email.value.indexOf(".");
    parte3 = email.value.length;
    if (!(parte1 >= 1 && parte2 >= 3 && parte3 >= 5))
    {
	     alert ("O campo \"E-mail\" deve conter um endere&ccedil;o eletrônico v&aacute;lido!\nFormato: nome@seuprovedor.com");
	     email.focus();
	     return false;
    }
}
function criaArray(n)
{
	this.length = n;
	for(var i = 1;i<=n;i++)
	{
		this[i] = "";
	}
}

function validaCPF(cpfValor)
{
	var i;
	s = cpfValor.value;
	s = s.replace(/\./g,"");
	s = s.replace(/\-/g,"");
	var c = s.substr(0,9);
	var dv = s.substr(9,2);
	var d1 = 0;
	for (i = 0; i < 9; i++)
	{
		d1 += c.charAt(i)*(10-i);
	}
	if (d1 == 0)
	{
		alert("CPF Inv&aacute;lido");
		cpfValor.value="";
		cpfValor.focus();
		return false;
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9)
		d1 = 0;
	if (dv.charAt(0) != d1)
	{
		alert("CPF Inv&aacute;lido");
		cpfValor.focus();
		cpfValor.value="";
		return false;
	}
	d1 *= 2;
	for (i = 0; i < 9; i++)
	{
		d1 += c.charAt(i)*(11-i);
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9)
		d1 = 0;
	if (dv.charAt(1) != d1)
	{
		alert("CPF Inv&aacute;lido");
		cpfValor.value="";
		cpfValor.focus();
		return false;
	}
	return true;
}

function validaSeparador(separador)
{
	if((separador != '.') && (separador != '@') && !isNumber(separador) && !isChar(separador))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function validaCEP(cep)
{
    cepValue = cep.value;
	cepValue = cepValue.replace(/\-/g,"");
	parte1 = cepValue.length;
    if (parte1 < 8)
    {
	     alert ("O campo \"CEP\" est&aacute; incorreto!\nFormato: 99999-999");
	     cep.focus();
	     return false;
    }
    return true;
}
function validaData(data)
{
    dataValue = data.value;
	dataValue = dataValue.replace(/\//g,"");
	parte1 = dataValue.length;
    if (parte1 < 8)
    {
	     alert ("O campo \"Data\" est&aacute; incorreto!\nFormato: dd/mm/aaaa");
	     data.focus();
	     return false;
    }
    return true;
}
function validaHora(hora)
{
    horaValue = hora.value;
	horaValue = horaValue.replace(/\:/g,"");
	parte1 = horaValue.length;
    if (parte1 < 4)
    {
	     alert ("O campo \"Hora\" est&aacute; incorreto!\nFormato: hh:mm");
	     hora.focus();
	     return false;
    }
    return true;
}

function validaCNPJ(cnpjPass)
{
	CNPJ = cnpjPass.value;
	erro = new String;
	if (CNPJ.length < 18) erro += "&eacute; necessario preencher corretamente o n&uacute;mero do CNPJ! \n\n";
	if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-"))
	{
		if (erro.length == 0) erro += "&eacute; necess&aacute;rio preencher corretamente o n&uacute;mero do CNPJ! \n\n";
	}
	//substituir os caracteres que n&atilde;o s&atilde;o n&uacute;meros
	if(document.layers && parseInt(navigator.appVersion) == 4)
	{
	      x = CNPJ.substring(0,2);
	      x += CNPJ. substring (3,6);
	      x += CNPJ. substring (7,10);
	      x += CNPJ. substring (11,15);
	      x += CNPJ. substring (16,18);
	      CNPJ = x;
	}else
	{
	      CNPJ = CNPJ. replace (".","");
	      CNPJ = CNPJ. replace (".","");
	      CNPJ = CNPJ. replace ("-","");
	      CNPJ = CNPJ. replace ("/","");
	}
	var nonNumbers = /\D/;
	if (nonNumbers.test(CNPJ)) erro += "A verifica&ccedil;&atilde;o de CNPJ suporta apenas n&uacute;meros! \n\n";
	var a = [];
	var b = new Number;
	var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
	for (i=0; i<12; i++)
	{
		a[i] = CNPJ.charAt(i);
		b += a[i] * c[i+1];
	}
	if ((x = b % 11) < 2)
	{
		a[12] = 0;
	}else
	{
		a[12] = 11-x;
	}
	b = 0;
	for (y=0; y<13; y++)
	{
	    b += (a[y] * c[y]);
	}
	if ((x = b % 11) < 2)
	{
		a[13] = 0;
	}else
	{
		a[13] = 11-x;
	}
	if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13]))
	{
	      erro +="D&iacute;gito verificador com problema!";
	}
	if (erro.length > 0)
	{
		alert(erro);
		cnpjPass.focus();
		return false;
	}
return true;
}
// Custom event handler
function myCustomExecCommandHandler(editor_id, elm, command, user_interface, value)
{
	var linkElm, imageElm, inst;

	switch (command)
	{
		case "mceLink":
			inst = tinyMCE.getInstanceById(editor_id);
			linkElm = tinyMCE.getParentElement(inst.selection.getFocusElement(), "a");

			if (linkElm)
				alert("Link dialog has been overriden. Found link href: " + tinyMCE.getAttrib(linkElm, "href"));
			else
				alert("Link dialog has been overriden.");

			return true;

		case "mceImage":
			inst = tinyMCE.getInstanceById(editor_id);
			imageElm = tinyMCE.getParentElement(inst.selection.getFocusElement(), "img");

			if (imageElm)
				alert("Image dialog has been overriden. Found image src: " + tinyMCE.getAttrib(imageElm, "src"));
			else
				alert("Image dialog has been overriden.");

			return true;
	}

	return false; // Pass to next handler in chain
}
// Custom save callback, gets called when the contents is to be submitted
function customSave(id, content)
{
	alert(id + "=" + content);
}

function myFileBrowser (field_name, url, type, win) {

// alert("Field_Name: " + field_name + "\nURL: " + url + "\nType: " + type + "\nWin: " + win); // debug/testing

/* If you work with sessions in PHP and your client doesn't accept cookies you might need to carry
   the session name and session ID in the request string (can look like this: "?PHPSESSID=88p0n70s9dsknra96qhuk6etm5").
   These lines of code extract the necessary parameters and add them back to the filebrowser URL again. */

var cmsURL = window.location.pathname;      // script URL
var searchString = window.location.search;  // possible parameters
if (searchString.length < 1) {
    // add "?" to the URL to include parameters (in other words: create a search string because there wasn't one before)
    searchString = "?";
}

// newer writing style of the TinyMCE developers for tinyMCE.openWindow

tinyMCE.openWindow({
    file : cmsURL + searchString + "&type=" + type, // PHP session ID is now included if there is one at all
    title : "File Browser",
    width : 420,  // Your dimensions may differ - toy around with them!
    height : 400,
    close_previous : "no"
}, {
    window : win,
    input : field_name,
    resizable : "yes",
    inline : "yes",  // This parameter only has an effect if you use the inlinepopups plugin!
    editor_id : tinyMCE.getWindowArg("editor_id")
});
return false;
}



