function confirmaExclusao() {
	if(confirm('Você 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ório!");
		id.focus();
		return false;
	}
	return true;
}
function camposObrigatorios(valores)
{
	var obj;
	var i = 1;
	while(i<=valores.length+1)
	{
		obj = document.getElementById(valores[i]);
		if(obj.value == "")
		{
			obj.focus();
			alert("Você deve preencher todos os campos obrigatórios");
			return false;
		}
		i++;
	}
	return true;
}
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álido");
		cpfValor.value="";
		cpfValor.focus();
		return false;
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9)
		d1 = 0;
	if (dv.charAt(0) != d1)
	{
		alert("CPF Invá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álido");
		cpfValor.value="";
		cpfValor.focus();
		return false;
	}
	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ço eletrônico válido!\nFormato: nome@seuprovedor.com");
	     email.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á 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á 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á incorreto!\nFormato: hh:mm");
	     hora.focus();
	     return false;
    }
    return true;
}

function validaCNPJ(cnpjPass)
{
	CNPJ = cnpjPass.value;
	erro = new String;
	if (CNPJ.length < 18) erro += "É necessario preencher corretamente o número do CNPJ! \n\n";
	if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-"))
	{
		if (erro.length == 0) erro += "É necessário preencher corretamente o número do CNPJ! \n\n";
	}
	//substituir os caracteres que não são nú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ção de CNPJ suporta apenas nú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í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;
}
nereidFadeObjects = new Object();
nereidFadeTimers = new Object();

function sourceNum(obj){
	if ((document.documentElement.sourceIndex*1)+1)
	return obj.sourceIndex;
	else if (document.getElementsByTagName)
	var order=document.getElementsByTagName('*')
	for (var i_tem = 0; i_tem < order.length; i_tem++)
	if (order[i_tem]==obj)
	return i_tem;
}

function nereidFade(object, destOp, rate, delta){
	if (object.toString().indexOf('object') == -1){  //do this so I can take a string too
		setTimeout("nereidFade("+object+","+destOp+","+rate+","+delta+")",0);
		return;
	}
	if (!(object.filters||object.style.MozOpacity||object.style.opacity))
		return;
	var objOpac=object.filters? object.filters.alpha.opacity : object.style.MozOpacity? object.style.MozOpacity*100 : object.style.opacity? object.style.opacity*100 : null
	clearTimeout(nereidFadeTimers[sourceNum(object)]);

	diff = destOp-objOpac;
	direction = 1;
	if (objOpac!==null&&objOpac > destOp){
		direction = -1;
	}
	delta=Math.min(direction*diff,delta);
	if (object.filters)
		object.filters.alpha.opacity+=direction*delta;
	else if (object.style.MozOpacity)
		object.style.MozOpacity=(object.style.MozOpacity*1)+(direction*delta/100);
	else if (object.style.opacity)
		object.style.opacity=(object.style.opacity*1)+(direction*delta/100);

	objOpac=object.filters? object.filters.alpha.opacity : object.style.MozOpacity? object.style.MozOpacity*100 : object.style.opacity? object.style.opacity*100 : null

	if (objOpac!==null&&objOpac != destOp){
		nereidFadeObjects[sourceNum(object)]=object;
		nereidFadeTimers[sourceNum(object)]=setTimeout("nereidFade(nereidFadeObjects["+sourceNum(object)+"],"+destOp+","+rate+","+delta+")",rate);
	}
}

//--------------------------------------------------------------------
		
		
		
			

	

