// Janela PopUP
// Versao 1.0 (15.10.06)
function popup(url) 
	{
 		janela = window.open(url, "", "width=300, height=300, left=200, top=100");
		janela.focus();
	}
//trim	
String.prototype.trim = function()
{
return this.replace(/^\s*/, "").replace(/\s*$/, "");
}
// Opcao da Enquete
// Versao 1.0 (26.01.07)
function vlr(obj)
{
	document.frm_enquete.opcao.value = obj;
}
	
function validaForm(idform,destino)
{
	if(destino == null)
		destino = 'dados';
	var form       = document.getElementById(idform);
	var param      = '';
	var attributo  = '';
	var str        = '';
	var arquivos   = false;
	var valor      = '';
	
	for (i = 0; i < form.length; i++)
	{	
		//verifica se o campo deve ser validado
		atributo = form[i].getAttribute('validar');
		if (atributo != null)
		{
			if(form[i].name.indexOf('FCKeditor') != -1)
			{
				form[i].value = FCKeditorAPI.GetInstance(form[i].name).GetXHTML();
				if(getClearText(form[i].value).trim() == '')
				{
					str += ('O campo ' + atributo.toUpperCase() + ' é obrigatório!\n');
				}
			}
			else
			{
				if(atributo != '' && form[i].value.trim() == '')
				{
					str += ('O campo ' + atributo.toUpperCase() + ' é obrigatório!\n');
				}
			}
		}
		
		if(param != '')
		{
			param += '&';
		}
		
		if(form[i].type == 'radio' || form[i].type == 'checkbox')
		{
			if(form[i].checked)
			{
				valor = form[i].value.replace(/&/gi,'#E#').replace(/"/gi,'\\"');
				param += form[i].name + '=' + encodeURI(valor);
			}
		}
		else
		{
			if(form[i].type == 'select-multiple')
			{
				for(var j=0; j<form[i].options.length; j++)
				{
					if(form[i].options[j].selected == true)
					{
						if(param != '')
						{
							param += '&';
						}
						valor = form[i].options[j].value.replace(/&/gi,'#E#').replace(/"/gi,'\\"');
						param += form[i].name + '=' + encodeURI(valor);
					}
				}
			}
			else
			{
					valor = form[i].value.replace(/&/gi,'#E#').replace(/"/gi,'\\"');
					param += form[i].name + '=' + encodeURI(valor);
			}
		}
	}
	if(str == '')
	{
		rqpost(form.action, param, destino);
	}
	else
	{
		alert(str);
	}
}	
	
/*function cargaInicial(){

	if(navigator.userAgent.toLowerCase().indexOf("msie") != -1)
	{
		pageS('./include/menu.php','menu',false);
		pageS('./include/menu_rapido.php','menulink',false);
		pageS('./home.php','dados',false);
	}
	else
	{
		page('./include/menu.php','menu',false);
		setTimeout('page(\'./include/menu_rapido.php\',\'menulink\',false)',1000);
		setTimeout('page(\'./home.php\',\'dados\',false)',3000);
	}
}*/

function categorias(idCat){
	var categorias = document.getElementsByTagName('ul');
	for(var i=0;i<categorias.length;i++){
		if(categorias[i].id != ''){
			if(categorias[i].id == 'categCont'+idCat)
				categorias[i].style.display = '';
			else
				categorias[i].style.display = 'none';
		}
	}
}

function setAtivo(itemMenu){
    var itens = document.getElementsByTagName('LI');
    for(var i=0; i< itens.length; i++){
        if(itens[i].className == 'ativo')
            itens[i].className = '';
    }
    if(itemMenu != '')
        document.getElementById(itemMenu).className = 'ativo';
    //itemMenu.parentNode.className = 'ativo';

}


function ajustaLarguras(){
	var embed;
	var wid;
	var hei;
	var taxaWid;
	var taxaHei;
	var heiPai;
	var widPai;
	var difHei, difWid;
	var pai;
	var objetos = document.getElementsByTagName('OBJECT');
	var tmp;
	var direcao;

	objetos = document.getElementsByTagName('EMBED');
	for(var i=0; i< objetos.length; i++){
		wid     = parseInt(objetos[i].width);
		hei     = parseInt(objetos[i].height);
		taxaWid = wid/hei;
		taxaHei = hei/wid;
		tmp     = objetos[i];
		if(objetos[i].parentNode.id == 'popup'){
		    continue;
        }
		if(objetos[i].id == ""){
			for(j=0; j<=5; j++){
				if(isNaN(parseInt(tmp.parentNode.width)))
				{
					tmp = tmp.parentNode;
				}
				else
				{
					pai = tmp.parentNode;
					heiPai = parseInt(pai.height);
					widPai = parseInt(pai.width);
					direcao = tmp.parentNode.getAttribute('direcao');
					
					difHei = heiPai - hei;
					difWid = widPai - wid;
					if (direcao == 'v' && pai.parentNode.parentNode.childNodes.length > 1)
						pai.style.height = 'auto';

					if(difHei<=difWid){
						wid = Math.round((heiPai-25) / taxaHei);
						objetos[i].setAttribute('width',wid,0);
						objetos[i].setAttribute('height',heiPai-25,0);	  
					}
					else{
						hei = Math.round(widPai / taxaWid);
						objetos[i].setAttribute('width',widPai,0);
						objetos[i].setAttribute('height',hei,0);
						pai.style.height = '';
					}
					break;
				}
			}
		}
	}
}
function validaEnter(form,event) 
{ 
	var key, str, len;
	key = event.charCode;
	if (key==null || key==0){
		key = event.keyCode;
	}
	
	if(key == 13)
	{ 
		validaForm(form);
	}
	return true;
}

function senha(idCampoUser){
	campo = document.getElementById(idCampoUser);
	usuario = campo.value;
	if(usuario.trim() == ''){
		alert('Por favor informe o nome de usuário.');
		return;
	}
	if(confirm('Uma nova senha será gerada e enviada para seu e-mail cadastrado. \n Deseja continuar?'))
		page('./include/novasenha.php?user='+usuario,'dados',false);
}

function altsenha(frm){
	var nsenha = document.getElementById('novasenha')
    var nsenha1 = document.getElementById('novasenha1')
    nsenha.style.display = '';
    nsenha1.style.display = '';
    nsenha.setAttribute('validar','Nova senha');
    nsenha1.setAttribute('validar','Confirmação de senha');

}

function fechaTempo(id,tempo){
    obj = document.getElementById(id);
    setTimeout('obj.parentNode.removeChild(obj)',(tempo * 1000));
}

function verifData(campo,limite){
	var valido = /^(((([1-9])|((0[1-9])|([12][0-9]))|(3[01]))[\/]((0[13578])|([13578])|(1[02])))|((([1-9])|([0-2][0-9])|(30))[\/]((0[469])|([469])|(11)))|(([1-9])|([0-2][0-9])[\/]((2|02))))[\/][1-9]\d{3}$|^[1-9]\d{3}$/;
	if(campo.value.trim() != ""){
		if(campo.value.match(valido) == null){
			alert('Por Favor informe uma data válida.');
			campo.value='';
		}
        else if(limite != undefined){
            var ano = campo.value.substring(6,10);
            if(parseInt(ano) < limite){
                alert('Por Favor informe uma data a partir de 01/01/'+limite);
        			campo.value='';
            }
        }
    }
}

function maskdata(input, event)
{
	var key, str, len;
	key = event.charCode;
	if (key==null){
		key = event.keyCode;
	}
	if(!((key >= 48 && key <= 57)||( key == 13)))
	{ 
		key = event.keyCode;
		if((key >=36 && key <=40) || (key == 8) || (key == 9))
		{
			return true;
		}
		return false;
	}
	str = input.value;
	if (str!='') 
	{
		len = str.length;
		if ((len==5)||(len==2))
		{
			str += "/";
		}
	}
	input.value = str;
}

function verifHora(campo){
	var valor = campo.value;
    if(valor.trim() != ""){
    	if(valor.length == 5){
    		arr = valor.split(':');
    		if(arr[0] < 24 && arr[1] < 60)
    			return 
    	}
    	alert('Por Favor informe uma hora válida.');
    	campo.value='';
    }
}

function maskhora(input, event)
{ 
	var key, str, len;
	key = event.charCode;
	if (key==null){
		key = event.keyCode;
	}
	if(!((key >= 48 && key <= 57)||( key == 13)))
	{ 
		key = event.keyCode;
		if((key >=36 && key <=40) || (key == 8) || (key == 9))
		{
			return true;
		}
		return false;
	}
	str = input.value;
	if (str!='') 
	{
		len = str.length;
		if ((len==2))
		{ 
			str += ":"; 
		}
	}
	input.value = str;
}

function noEnter(event)
{
	var key, str, len;
	key = event.charCode;
	if (key==null || key==0){
		key = event.keyCode;
	}
	if(key == 13)
		return false;
    else
    	return true;

}

function removepopup(){
    try{
    	$('popup').setStyle('display', 'none');
    	$('ifrpopup').setStyle('display', 'none');
    } catch(e){}
    try{
    	$('popup').setStyles('display: none; width:0; height:0; visibility:hidden;');
    	$('ifrpopup').setStyles('display: none; width:0; height:0; visibility:hidden;');
    } catch(e){}
    try{
    	$('popup').remove();
    	$('ifrpopup').remove();
    } catch(e){}
}


function fix_flash() {
    // loop through every embed tag on the site
    var embeds = document.getElementsByTagName('embed');
    for(i=0; i<embeds.length; i++)  {
        embed = embeds[i];
        var new_embed;
        // everything but Firefox & Konqueror
        if(embed.outerHTML) {
            var html = embed.outerHTML;
            // replace an existing wmode parameter
            if(html.match(/wmode\s*=\s*('|")[a-zA-Z]+('|")/i))
                new_embed = html.replace(/wmode\s*=\s*('|")window('|")/i,"wmode='transparent'");
            // add a new wmode parameter
            else
                new_embed = html.replace(/<embed\s/i,"<embed wmode='transparent' ");
            // replace the old embed object with the fixed version
            embed.insertAdjacentHTML('beforeBegin',new_embed);
            embed.parentNode.removeChild(embed);
        } else {
            // cloneNode is buggy in some versions of Safari & Opera, but works fine in FF
            new_embed = embed.cloneNode(true);
            if(!new_embed.getAttribute('wmode') || new_embed.getAttribute('wmode').toLowerCase()=='window')
                new_embed.setAttribute('wmode','transparent');
            embed.parentNode.replaceChild(new_embed,embed);
        }
    }
    // loop through every object tag on the site
    var objects = document.getElementsByTagName('object');
    for(i=0; i<objects.length; i++) {
        object = objects[i];
        var new_object;
        // object is an IE specific tag so we can use outerHTML here
        if(object.outerHTML) {
            var html = object.outerHTML;
            // replace an existing wmode parameter
            if(html.match(/<param\s+name\s*=\s*('|")wmode('|")\s+value\s*=\s*('|")[a-zA-Z]+('|")\s*\/?\>/i))
                new_object = html.replace(/<param\s+name\s*=\s*('|")wmode('|")\s+value\s*=\s*('|")window('|")\s*\/?\>/i,"<param name='wmode' value='transparent' />");
            // add a new wmode parameter
            else
                new_object = html.replace(/<\/object\>/i,"<param name='wmode' value='transparent' />\n</object>");
            // loop through each of the param tags
            var children = object.childNodes;
            for(j=0; j<children.length; j++) {
                if(children[j].getAttribute('name').match(/flashvars/i)) {
                    new_object = html.replace(/<param\s+name\s*=\s*('|")flashvars('|")\s+value\s*=\s*('|")[^'"]*('|")\s*\/?\>/i,"<param name='flashvars' value='"+children[j].getAttribute('value')+"' />");
                }
            }
            // replace the old embed object with the fixed versiony
            object.insertAdjacentHTML('beforeBegin',new_object);
            object.parentNode.removeChild(object);
        }
    }
}