wMax640x480 = 640-15;
wMax800x600 = 800-10;
hMax640x480 = 480-70;
hMax800x600 = 600-70;

//Filtra Width
function FW(w){
	if ( (screen.width == 640) && (w >= wMax640x480) ){
		return wMax640x480;
	}
	else if ( (screen.width == 800) && (w >= wMax800x600) ){
		return wMax800x600;
	}
	else{
		return w;
	}
}

//Filtra Left
function FL(w){
	if ( (screen.width == 640) && (w >= wMax640x480) ){
		return 0;
	}
	else if ( (screen.width == 800) && (w >= wMax800x600) ){
		return 0;
	}
	else{
		return (screen.width-w)/2;
	}
}

//Filtra Height
function FH(h){
	if ( (screen.height == 480) && (h >= hMax640x480) ){
		return hMax640x480;
	}
	else if ( (screen.height == 600) && (h >= hMax800x600) ){
		return hMax800x600;
	}
	else{
		return h;
	}
}

//Filtra Top
function FT(h){
	if ( (screen.height == 480) && (h >= hMax640x480) ){
		return 0;
	}
	else if ( (screen.height == 600) && (h >= hMax800x600) ){
		return 0;
	}
	else{
		//altura da tela - (altura da janela + altura menu iniciar)
		return (screen.height-(h+50) )/2;
	}
}

function AbreJanelaNova(url, nomeJanela, w, h, resize)
{
	newWindow = window.open(url,nomeJanela,'width='+FW(w)+',height='+FH(h)+',top='+FT(h)+',left='+FL(w)+',location=0,directories=0,status=no,menuBar=no,scrollbars=yes,resizable='+resize+',maximize='+resize);
	newWindow.focus();
}

function AbreJanela(url, nomeJanela, w, h, resize)
{
	newWindow = window.open(url,nomeJanela,'width='+FW(w)+',height='+FH(h)+',top='+FT(h)+',left='+FL(w)+',location=0,directories=0,status=no,menuBar=no,scrollbars=yes,resizable='+resize+',maximize='+resize);
	newWindow.focus();
}

function AbreJanelaGrande(url, nomeJanela)
{
	AbreJanelaNova(url, nomeJanela, '600', '500', 'yes');
}

function AbreJanelaMedia(url, nomeJanela)
{
	AbreJanelaNova(url, nomeJanela, '400', '300', 'yes');
}


function AbreJanelaMediaGrande(url, nomeJanela)
{
	AbreJanelaNova(url, nomeJanela, '490', '540', 'yes');
}

function AbreJanelaPequena(url, nomeJanela)
{
	AbreJanelaNova(url, nomeJanela, '250', '150', 'yes');
}

function abreJanelaFerramentas(url)
{
	AbreJanelaNova(url, 'f', '790', '500', 'yes');
}

function abreJanelaFerramentas(url, nomeJanela)
{
	AbreJanelaNova(url, nomeJanela, '790', '500', 'yes');
}

/*
	Abre a página que é o chat de conversação
*/
function AbreJanelaSalaChat(url)
{
	newWindow = window.open(url,'ChatSalaAtual','width=300,height=300,scrollbars=1');
	newWindow.focus();
}

/*
	Abre a página de logoff das salas de chat.
	usada quando fechado o browser
*/
function ChatSalaSair()
{
	try
	{
		window.open("ChatWebSair.aspx","ChatSair","width=30,height=30");
	}catch(ex){}	
}




//Função que escreve em um determinando elemento de acordo como Navegador
function MSinnerHTML(ID,Texto){
	if (navigator.userAgent.indexOf('Gecko') != -1){ 
	    document.getElementById(ID).innerHTML = Texto; 
    } else {
		document.all[ID].innerHTML = Texto;
	}
}
																												
//não utilizada em 11/02/2004
//passa-se os segundos e essa func. retorna uma mensagem
//de quanto tempo irá durar o download.
function getMin(sec)
{
	var hora = 0
    var minuto = 0
    var segundo = 0
    var resp = " "

    if(sec <= 1) return ("1 segundo")
	
	hora	= Math.floor (sec/3600)
    minuto	=  Math.floor((sec - (ore * 3600))/60)
    segundo = Math.floor (sec - ((ore*3600) + (minuti * 60)))

    if(sec > 86400) return ("mais de 1 Dia!")                      
    else if(sec  >=  3600) tempo = hora + " hora(s) " + minuto + " min(s). " + segundo + " seg(s). "                                                                                                               
    else if( sec< 3600 & sec >=60) tempo = minuto + " minuto(s) " + segundo + " seg(s). "
    else resp = segundo + " segundo(s)"
    
    return(resp)
}

/*
	No C# é horrivel seta o foco em algum elemento do fomulario.
	Esta função procura um control e poem o focu nele
*/
function jsSetFocus(control_name)
{
	try
	{
		for (i = 0; i < document.forms[0].elements.length; i++)
			if 	(document.forms[0].elements[i].id.indexOf(control_name) > -1)
			{
				document.forms[0].elements[i].focus();
				break;
			}
	} catch (ex) {}
	
	return;
}

/*
	Retorna o indice do control que se esta procurando no formulário.
	OBS: Se não econtrar retornará -1.
*/
function jsFindControl(control_name)
{
	iReturn = -1;
	try
	{
		for (i = 0; i < document.forms[0].elements.length; i++)
			if 	(document.forms[0].elements[i].id.indexOf(control_name) > -1)
			{
				iReturn = i;
				break;
			}
	} catch (ex) {}
	
	return iReturn;
}

/*
	Retorna o indice do control que se esta procurando no formulário. 
	IMPORTANTE: Abusca é efetuada de traz para frente no formulário 
	OBS: Se não econtrar retornará -1.
*/
function jsFindControlDesc(control_name)
{
	iReturn = -1;
	try
	{
		for (i = document.forms[0].elements.length-1; i >= 0; i--)
			if 	(document.forms[0].elements[i].id.indexOf(control_name) > -1)
			{
				iReturn = i;
				break;
			}
	} catch (ex) {}
	
	return iReturn;
}

/*
	Retorna um Array de indices dos controls que se esta procurando no formulário. 
	OBS: Se não econtrar retornará -1.
*/
function jsFindControlArray(control_name)
{
	objArray = new Array();

	count = 0;
	try
	{
		for (i = document.forms[0].elements.length-1; i >= 0; i--)
			if 	(document.forms[0].elements[i].id.indexOf(control_name) > -1)
			{
				objArray[count] = i;
				count++;
			}
	} catch (ex) {}
	
	return objArray;
}

function replaceString(oldS,newS,fullS) 
{
	// Replaces oldS with newS in the string fullS
	for (var i=0; i<fullS.length; i++)
	{
		if (fullS.substring(i,i+oldS.length) == oldS)
		{
			fullS = fullS.substring(0,i)+newS+fullS.substring(i+oldS.length,fullS.length);
		}
	}
	
	return fullS;
}

/*
	(De)Seleciona os control que se esta procurando no formulário de acordo com o parâmetro control_checked.
*/
function CheckAllControls(control_name, control_checked)
{
	try
	{
		for (i = 0; i < document.forms[0].elements.length; i++)
			if 	(document.forms[0].elements[i].id.indexOf(control_name) > -1)
			{
				document.getElementById(document.forms[0].elements[i].id).checked = control_checked;
			}
	} catch (ex) {}
	
	return !control_checked;
}

function SelecionaApenasUm(control_name, parent_name)
{
	try
	{
		for (i = 0; i < document.forms[0].elements.length; i++)
			if 	(document.forms[0].elements[i].id.indexOf(parent_name) > -1)
			{
				if (document.forms[0].elements[i].id.indexOf(control_name) > -1)
					document.getElementById(document.forms[0].elements[i].id).checked = true;
				else
					document.getElementById(document.forms[0].elements[i].id).checked = false;
			}
	} catch (ex) {}
}

/*
	Não permite que o usuário ultrapasse o número de caracteres 
	no objeto (campo texto) "obj" definido em "maxLength"
	Retorna o número de caracteres digitados
*/
function jsMaxLength(obj, maxLength)
{
	if (obj.value.length > maxLength)
		obj.value = obj.value.substring(0, maxLength);
	return obj.value.length;
}

/*
	Pega as posições x e y do canto superior esquerdo 
	de qualquer controle
*/
function getOffsetTop(elm) {
	var mOffsetTop = elm.offsetTop;
	var mOffsetParent = elm.offsetParent;
	while(mOffsetParent) {
		mOffsetTop += mOffsetParent.offsetTop;
		mOffsetParent = mOffsetParent.offsetParent;
	}
 	return mOffsetTop;
}

function getOffsetLeft(elm) {
	var mOffsetLeft = elm.offsetLeft;
	var mOffsetParent = elm.offsetParent;
	while(mOffsetParent) {
		mOffsetLeft += mOffsetParent.offsetLeft;
		mOffsetParent = mOffsetParent.offsetParent;
	}
	return mOffsetLeft;
}

function getOffsetRight(elm) {
	var mOffsetRight = getOffsetLeft(elm) + elm.offsetWidth;

	return mOffsetRight;
}


function JsDelete()
{
	if (confirm ("Tem certeza que deseja excluir?"))
	{return true;}
	else
	{return false;}
}

//Função para trocar o estilo de um determinado controle
function jsReplaceStyle(obj, newStyle)
{
	obj.className = newStyle;
	//obj.style = newStyle;
}
	
	
	// ############### Inicio da função jsTrataData ################################
// Função:  Valida campos do tipo data, verificando se o ano é bissexto ou não.
// E retorna true se válido ou false (com mensagem na tela) se não válido
//
// Entrada: jDia -> Valor referente ao dia da data
// Entrada: jMes -> Valor referente ao mês da data
// Entrada: jAno -> Valor referente ao ano da data
// Saída: True -> se a data é válida
//		  False -> se a data não é válida
// 			  false caso o usuário clique no botão Cancelar
// Ex de chamada: jsTrataData(jTheForm.fDataNascimentoDia,jTheForm.fDataNascimentoMes,jTheForm.fDataNascimentoAno)

function jsTrataData(jDia,jMes,jAno)
{		
		// Alterações - Stéfano Santos - verifica se data é diferente de nulo
		if (jDia.value == "")
    	{
			alert('Escolha um dia válido!');
	        jDia.focus();
			return true;
	    }
		if (jMes.value == "")
    	{
			alert('Escolha um mês válido!');
	        jMes.focus();
			return true;
	    }
		if (jAno.value == "")
    	{
			alert('Escolha um ano válido!');
	        jAno.focus();
			return true;
	    }
		// fim das alterações
		
		ano = parseInt(jAno.value);
		if (ano > 2000)
		{
			while (ano > 2000)
			{
				ano = (ano - 4);
			}
			if (ano == 2000)
			{
				dia = 29; // ano bissexto
			}
		}
		else if (ano < 2000)
		{
			while (ano < 2000)
			{
				ano = (ano + 4);
			}
			if (ano == 2000)
			{
				dia = 29; // ano bissexto
			}
		}
		if (ano == 2000)
		{
			dia = 29; // ano bissexto
		}else{
			dia = 28;
		}
		if ( (parseInt(jMes.value) == 4) || (parseInt(jMes.value) == 6) || (parseInt(jMes.value) == 9) || (parseInt(jMes.value) == 11) )
    	{
			if (parseInt(jDia.value) > 30)
			{
				alert('Escolha uma data válida!');
		        jDia.focus();
				return true;
			}
	    }
		else if ( (parseInt(jMes.value) == 2) && (parseInt(jDia.value) > parseInt(dia) ) )
		{
			alert('Escolha uma data válida!');
	        jDia.focus();
			return true;
		}
		return false;
}	

    //funcao para formatar qualquer campo.Ex.:cep,cpf,telefone,cnpj. 
    function formata(src, mask) 
    { // Uso: campo.Attributes.Add("onkeypress", "formata(this,###.###.###-#)");
        var i = src.value.length; 
        var saida = mask.substring(0,1); 
        var texto = mask.substring(i) 
        if (texto.substring(0,1) != saida) 
        { 
            src.value += texto.substring(0,1); 
        } 
    }
  
function TextBoxNumero(obj, e, allowDecimal, allowNegative)
{
   //retorna somente numeros, e permite negativos e decimal 
	var key;
	var isCtrl = false;
	var keychar;
	var reg;
		
	if(window.event) {
		key = e.keyCode;
		isCtrl = window.event.ctrlKey;
	}
	else if(e.which) {
		key = e.which;
		isCtrl = e.ctrlKey;
	}

	if (isNaN(key)) return true;
	
	keychar = String.fromCharCode(key);
	
	// check for backspace or delete, or if Ctrl was pressed
	if (key == 8 || isCtrl)
	{
		return true;
	}

	reg = /\d/;
	var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
	var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
	
	return isFirstN || isFirstD || reg.test(keychar);
}

function $(id) {
	return document.getElementById(id);
}

/************************************************************************************************************/
/*                                                                                                          */
/*                      Funções Utilizadas Nas Aspx da Avaliacao - AreaAvaliacao							*/
/*                                                                                                          */
/************************************************************************************************************/

function cancelF5(event)    
{
	var key;
	var isCtrl = false;
	     
	if(window.event)
	{
		if (window.event && (window.event.keyCode == 116))        
		{            
			window.event.keyCode = null;            
			window.event.cancelBubble = true;            
			window.event.returnValue = false;            
			return false;        
		}    
	}
	else if(event.which) 
	{		
		if (event.which == 116)        
		{   
			event.cancelBubble = true;
			event.stopPropagation();
			event.preventDefault();
			return false;        
		}   
	}             
}   

function cancelCtrl(event)
{
    if(window.event && window.event.ctrlKey)
    {
		window.event.cancelBubble = true;            
		window.event.returnValue = false;  
		return false;
	}
	else if(event.which) 
	{		
		if (event.ctrlKey)        
		{   
			event.cancelBubble = true;
			event.stopPropagation();
			event.preventDefault();
			return false;        
		}   
	}         
}

function cancelAlt(event)
{
    if(window.event && window.event.altKey)
    {//IE
		window.event.cancelBubble = true;
		window.event.returnValue = false;
		return false;
    }
    else if(event.which) 
    {//Mozilla
		if (event.altKey)
		{
			event.cancelBubble = true;
			event.stopPropagation();
			event.preventDefault();
			return false;
		}
    }
}
 
function cancelContextMenu(event)  
{        
	if (window.event)        
	{            
		window.event.cancelBubble = true;            
		window.event.returnValue = false;            
		return false;        
	}  
	else if(event.which) 
	{		
		event.cancelBubble = true;
		event.stopPropagation();
		event.preventDefault();
		return false;        
	}
}

 function cancelBack(event)    
 {        
	if (window.event && (window.event.keyCode == 8) && (window.event.srcElement))        
	{            
		window.event.cancelBubble = true;            
		window.event.returnValue = false;            
		return false;        
	}    
	else if(event.which) 
	{		
		if (event.which == 8)        
		{   
			event.cancelBubble = true;
			event.stopPropagation();
			event.preventDefault();
			return false;        
		}   
	}       
}        
function cancelDragDrop()    
{        
	window.event.returnValue = false;    
}

function cancelFullScreen(event)    
{        
	if (window.event && (window.event.keyCode == 122))        
	{           
		window.event.keyCode = null;            
		window.event.cancelBubble = true;            
		window.event.returnValue = false;            
		return false;        
	}
	else if(event.which) 
	{		
		if (event.which == 122)        
		{   
			event.cancelBubble = true;
			event.stopPropagation();
			event.preventDefault();
			return false;        
		}   
	}        
	   
}
function handleKeys(event)    
{        
    cancelF5(event);
	cancelBack(event);        
	cancelFullScreen(event);    
	cancelCtrl(event);
	cancelAlt(event);
}
  
  
  
  
    
