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 abreJanelaFerramentasWeb(url)
{
	AbreJanelaNova(url, 'f', '805', '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;
}

/*
	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;
}	

function MM_findObjCustom(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObjCustom(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayersCustom() { //v6.0
  var i,p,v,obj,args=MM_showHideLayersCustom.arguments;
  for (i=0; i<(args.length-2); i+=3) 
	if ((obj=MM_findObjCustom(args[i]))!=null) {
		v=args[i+2];//
		if (obj.style) { 
			obj=obj.style;
			v=(v=='show')?'visible':(v=='hide')?'hidden':v; 

			px = args[i+3];
			py = args[i+4];
			if ((v == 'visible')&&(py!=null)&&(!isNaN(px)))
			{
				obj.top = py;
				obj.left = px+125;
			}
		}
		obj.visibility=v;
  }
}

function ChecarTurma(obj)
{
	if (self[obj]==undefined)
	{
		alert("Turma não Iniciada.");
		return false;
	}
	return true;
}