﻿function getQuerystring(key, default_)
{
  if (default_==null) default_="";
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
} 
function LimiteCaracter(campo,totalpermitido,divalvo)
{
var alvo = document.getElementById(divalvo);
var bln = false;
//alert(campo.value.length);
    if(campo.value.length <= totalpermitido)
    bln= true;
    else
    {
    campo.value = campo.value.substr(0,totalpermitido);
    }
  //  alert(totalpermitido - campo.value.length));
  //  alert(bln);
    
    alvo.innerHTML =  (totalpermitido - campo.value.length)-1;
    return bln;
}
function Retorno(iddiv,alvo,seg)
{
    if (document.getElementById(iddiv) != null)
    {
		var divalvo = document.getElementById(iddiv);
		divalvo.innerHTML = "Retorno em "+ seg + " segundo" + ((seg > 1)? "s" : "") ;
		seg = seg - 1;
		var saida = "Retorno('"+iddiv+"','"+alvo+"',"+seg+")";  
		if (seg >= 0 )
			setTimeout(saida,1000);
		else
			window.location.href = alvo;
	}
}


function mostrartelas(o,div1,div2)
{
    var aba1 = document.getElementById(div1);
    var aba2 = document.getElementById(div2);
    if(o.selectedIndex == 0)
    {
        aba1.style.display = 'none';
        aba2.style.display = '';
    }
    else
    {
    
        aba1.style.display = '';        
        aba2.style.display = 'none';
    }
}
function limparcampos(fields,concatfield,validationsummary)
{
   var func = "ClearFields('"+fields+"','"+concatfield+"','"+validationsummary+"')";
    setTimeout(func,1000);
}
function ClearFields(fields,concatfield,validationsummary)
{
    var v_fields = fields.split(",");
    var vs = document.getElementById(validationsummary);
    
    alert(vs.id);
   if(vs.style.display == 'none')
   {
       
       for(var i = 0; i < v_fields.length; i++)
       {
        var field = document.getElementById(concatfield+v_fields[i]);
        alert(field);
        field.value = "";
        
       }
     
   }
  // else
  // {
    //
   // }
   // alert(vs.id +"\n"+ vs.onclick + "\n" + vs.style.display);
}

  var styleToSelect;
        function onOk() {
            $get('Paragraph1').className = styleToSelect;
        }
 
function ShowModalPopUpQx3(divIdModalPopup,divIdBackground)
{
    document.body.style.margin=0;
    document.body.style.padding=0; 
    
	var divfundo = document.getElementById(divIdBackground);
	var divcentro = document.getElementById(divIdModalPopup);
	var container = document.getElementById("DivPopUpContainer");
	if (typeof document.body.style.maxHeight == "undefined")  {
	    divfundo.style.position="absolute";
	}else {divfundo.style.position="fixed";}
    divfundo.style.top="0px";
    divfundo.style.left="0px";
    if (getQuerystring("Search")!="" || getQuerystring("Calendario")!=""){container.style.top="40em";}
	divfundo.style.display = "";
	divcentro.style.display = "";
	container.style.display = "";
	container.innerHTML ="<div id=\"" + divcentro.parentNode.id + "\">" + divcentro.parentNode.innerHTML + "</div>"
    divcentro.parentNode.parentNode.removeChild(divcentro.parentNode);
}

function closePopUpQx3(divIdModalPopup)
{   
    var divBackGround = document.getElementById("DivBackGroundQx3");
	var divContainer = document.getElementById("DivPopUpContainer");
	var divPopUp = document.getElementById(divIdModalPopup);
    divPopUp.parentNode.removeChild(divPopUp);
	divContainer.style.display = "none";
	divBackGround.style.display = "none";
	 
	window.location = window.location.url();
	 
	return false;
}

function telatoda(divIdBackground)
{
    var divfundo = document.getElementById(divIdBackground);
    var funcao = "telatoda('" + divIdBackground + "')";
    divfundo.style.height = Math.max(document.documentElement.clientHeight, document.body.scrollHeight)+"px";
   // divcentro.style.marginTop = (document.documentElement.clientHeight)*0.02+"%";
    setTimeout(funcao,1000);
}

function remover(label)
{
    var confirmarcao = confirm("Deseja remover este "+label+"?");
  // alert(confirmarcao);
    if(confirmarcao == true)
    {
        return true;
    }
    else
    {
        return false;
    }
    
}

/* CALENDARIO */

function legenda(doc,valor)
{
    if(valor != 0)
    {
        var mydiv  = document.createElement('div');
        mydiv.innerHTML = "<div class='legendapost'>( " + valor + " ) post"+((valor>1)?"s":"")+"</div>"; 
        doc.appendChild(mydiv);
        variavelglobal = doc;
    }
    else
    {
        if(doc.lastChild.innerHTML.length >20)
        {
            var filho  = doc.lastChild;
            doc.removeChild(filho);
        }
    }
}






var Rating = Class.create("Rating");
var __ratings = [];
Rating.prototype = {
	clickCallback: null,
	initialize: function(nome_form, nome_rating, valor_maximo, valor_inicial) //, tipoSI)
	{
		this.valorMaximo = valor_maximo;
		this.valorInicial = valor_inicial;
                               // this.tipoRating = tipoSI; 
		this.nomeCampo = nome_rating;
		this.form = document.forms[nome_form];
		__ratings[this.nomeCampo]=this;
	},
	gerarHtml: function()
	{
var legenda;
		var html="";//"<input type=\"text\" name=\"" + this.nomeCampo + "\" value=\"" + this.valorInicial + "\"><br>";
		for(var i = 0; i < this.valorMaximo; ++i)
		{
			var imagem = Rating.IMAGEM_OFF;
			if(i < this.valorInicial)
				imagem = Rating.IMAGEM_ON;
/*
if (this.tipoRating=="sat")
{
if (i == 0) html+="<img title=\"Muito insatisfeito\" onclick=\"Rating.computarClick('" + this.nomeCampo+"');\" onmouseover=\"Rating.atualizar('" + this.nomeCampo + "', " + (i+1) + ");\" id=\"" + this.nomeCampo + "_" + i + "\" src=\"" + imagem + "\" />";
else if (i==1)
html+="<img title=\"Insatisfeito\" onclick=\"Rating.computarClick('" + this.nomeCampo+"');\" onmouseover=\"Rating.atualizar('" + this.nomeCampo + "', " + (i+1) + ");\" id=\"" + this.nomeCampo + "_" + i + "\" src=\"" + imagem + "\" />";
else if (i==2)
html+="<img title=\"Satisfeito\" onclick=\"Rating.computarClick('" + this.nomeCampo+"');\" onmouseover=\"Rating.atualizar('" + this.nomeCampo + "', " + (i+1) + ");\" id=\"" + this.nomeCampo + "_" + i + "\" src=\"" + imagem + "\" />";
else if (i==3)
html+="<img title=\"Muito satisfeito\" onclick=\"Rating.computarClick('" + this.nomeCampo+"');\" onmouseover=\"Rating.atualizar('" + this.nomeCampo + "', " + (i+1) + ");\" id=\"" + this.nomeCampo + "_" + i + "\" src=\"" + imagem + "\" />";
}  */
//else
//{
if (i == 0) html+="<img style='cursor:pointer' title=\"Irrelevante\" onclick=\"Rating.computarClick('" + this.nomeCampo+"');\" onmouseover=\"Rating.atualizar('" + this.nomeCampo + "', " + (i+1) + ");\" id=\"" + this.nomeCampo + "_" + i + "\" src=\"" + imagem + "\" />";
else if (i==1)
html+="<img  style='cursor:pointer'  title=\"Pouco importante\" onclick=\"Rating.computarClick('" + this.nomeCampo+"');\" onmouseover=\"Rating.atualizar('" + this.nomeCampo + "', " + (i+1) + ");\" id=\"" + this.nomeCampo + "_" + i + "\" src=\"" + imagem + "\" />";
else if (i==2)
html+="<img  style='cursor:pointer'  title=\"Importante\" onclick=\"Rating.computarClick('" + this.nomeCampo+"');\" onmouseover=\"Rating.atualizar('" + this.nomeCampo + "', " + (i+1) + ");\" id=\"" + this.nomeCampo + "_" + i + "\" src=\"" + imagem + "\" />";
else if (i==3)
html+="<img  style='cursor:pointer' title=\"Muito importante\" onclick=\"Rating.computarClick('" + this.nomeCampo+"');\" onmouseover=\"Rating.atualizar('" + this.nomeCampo + "', " + (i+1) + ");\" id=\"" + this.nomeCampo + "_" + i + "\" src=\"" + imagem + "\" />";
else if (i == 4)
html+="<img  style='cursor:pointer' title=\"Muito importante\" onclick=\"Rating.computarClick('" + this.nomeCampo+"');\" onmouseover=\"Rating.atualizar('" + this.nomeCampo + "', " + (i+1) + ");\" id=\"" + this.nomeCampo + "_" + i + "\" src=\"" + imagem + "\" />";

//}
		}
		return html;
	}
};

Rating.IMAGEM_OFF = "Controls/boximage/RatingNaoAtivo.gif";
Rating.IMAGEM_ON = "Controls/boximage/RatingAtivo.gif";

Rating.get = function(nomeCampo)
{
	return __ratings[nomeCampo];
}

Rating.atualizar = function(nomeCampo, novoValor)
{
	var r = Rating.get(nomeCampo);
	if(r==null) return;
	var campo_form = r.form[r.nomeCampo];
	if(campo_form == null) return;
	campo_form.value = novoValor;
	for(var i = 0; i < r.valorMaximo; ++i)
	{
		var imagem = document.getElementById(r.nomeCampo+"_"+i);
		if(imagem!=null)
		{
			imagem.src = i < novoValor ? Rating.IMAGEM_ON : Rating.IMAGEM_OFF;
		}
	}	
}
Rating.computarClick = function(nomeCampo)
{

	var r = Rating.get(nomeCampo);
	//alert(nomeCampo.value);
	
	if(r == null) return;
	if(r.clickCallback!=null)
		r.clickCallback();
}

//Gerar rating para satisfação e importância
function gerarImportancia(nm_form, nm_campo) //, tipoSI)
{//   alert(nm_campo);
	var si = new Rating(nm_form, nm_campo, 5, 0) //, tipoSI);
	document.write( si.gerarHtml());
	return
}
function sendComment(){

    divAlertComment.style.display = "";
    return false;
}


window.onload = function(){
    var page = window.location.file(); 
    if ( page.toLowerCase() == "default.aspx" || page == "")
    {
        var popups = document.getElementsByClassName("divPopUpBlog");
        var divComment = document.getElementById("DivPopUpIdQx3");
        var divNewPost = document.getElementById("DivPopUpIdQx3Post");

        if (popups != "")
        {
            popups[0].style.display = "";
            divPopUpID =  ( (divComment != null) ? "DivPopUpIdQx3" : "DivPopUpIdQx3Post")
            ShowModalPopUpQx3(divPopUpID,"DivBackGroundQx3");
            telatoda("DivBackGroundQx3");
        }      
    }
    
}
