
// VERSAO DO BROWSER
//---------------------------------------------------------
function Browser() {
	
	var ua, s, i;
	
	this.isIE    = false;  // Internet Explorer
	this.isOP    = false;  // Opera
	this.isNS    = false;  // Netscape
	this.version = null;
	
	ua = navigator.userAgent;
	
	s = "Opera";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isOP = true;
		this.version = parseFloat(ua.substr(i + s.length));
		return;
	}
	
	s = "Netscape6/";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isNS = true;
		this.version = parseFloat(ua.substr(i + s.length));
		return;
	}
	
	// Treat any other "Gecko" browser as Netscape 6.1.
	
	s = "Gecko";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isNS = true;
		this.version = 6.1;
		return;
	}
	
	s = "MSIE";
	if ((i = ua.indexOf(s))) {
		this.isIE = true;
		this.version = parseFloat(ua.substr(i + s.length));
		return;
	}
}

var browser = new Browser();
//---------------------------------------------------------


function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
//---------------------------------------------------------

function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
//---------------------------------------------------------


function toDecimal (val) {

	sub = val.replace(",","V");
	sub = sub.replace(".","P");
	sub = sub.replace("P","");
	sub = sub.replace("V",".");

	return sub;

}
//---------------------------------------------------------

function toVal (valor) {
	valor = valor.toString();
	valor = valor.replace(".",",");

	if (valor.indexOf(',')<0) 
		valor = valor + ",00";

	return valor;
}

function toDecimal (val) {

	sub = val.replace(",","V");
	sub = sub.replace(".","P");
	sub = sub.replace("P","");
	sub = sub.replace("V",".");

	return sub;

}
//---------------------------------------------------------

function toggleCampos (frm,campos,disable) {
	
	///// HABILITA / DESABILITA CAMPOS ESCOLHIDOS SEPARADOS POR VIRGULA
	//// SE disable = 1, desabilita o campo, se = 0, habilita
	//// Se não estiver setado, faz toggle
	
    var campo = campos.split(",");
	
	for (i=0;i<document.forms.length;i++) {
      if (document.forms[i].name == frm) {
        for (j=0;j<document.forms[i].elements.length;j++) {
 
          var obj = document.forms[i].elements[j];
          var name = document.forms[i].elements[j].name;
          var id = document.forms[i].elements[j].id;

          for(g=0; g < campo.length; g++) {
          
	          if (name == campo[g] || id == campo[g]) {

	          	if (disable == 1) {
	          		if (obj.required == 'yes')
	          	    	obj.required = 'standby';
	          	    	
	          	    if (obj.type == 'select-one')
	          	    	obj.disabled = 1;
	          	    else
	          			obj.readonly = 1;
	          			
	          		obj.style.background = '#CCCCCC';
	          	}
	          	else if(disable == 0) {
	          		if (obj.required == 'standby')
	          			obj.required = 'yes';
	          			
	          		if (obj.type == 'select-one')
	          	    	obj.disabled = 0;
	          	    else	
		          		obj.readonly = 0;
		          		
	          		obj.style.background = '#FFFFFF';
	          	}
	          	else {
	          	
	          	
		          	if (obj.disabled != true) {
		          		if (obj.required == 'yes')
		          			obj.required = 'standby';
		          			
		          	    if (obj.type == 'select-one')
		          	    	obj.disabled = 1;
		          	    else
		          			obj.readonly = 1;
	          			
		          		obj.style.background = '#CCCCCC';
		          		
		          	}
		          	else {
		          		if (obj.required == 'standby')
		          			obj.required = 'yes';
			          			
		          		if (obj.type == 'select-one')
		          	    	obj.disabled = 0;
		          	    else	
			          		obj.readonly = 0;
		          		
		          		obj.style.background = '#FFFFFF';
		          		
		          	}
		          	
	          	
	          	}
	          	
	          }
          
          }
          
        }
        
      }
      
	}
	
}
//---------------------------------------------------------


function hideCampos (frm,campos) {
	
	///// MOSTRA / ESCONDE CAMPOS ESCOLHIDOS SEPARADOS POR VIRGULA

	var campo = campos.split(",");
	
	for(g=0; g < campo.length; g++) {
	
	  obj = document.getElementById(campo[g]);
		
	  if (obj) {
	
	  	if (obj.style.display =='block' || obj.style.display == '')
	  		obj.style.display = 'none';
	  	else if (obj.style.display == 'none')
	  		obj.style.display = 'block';
	  	
	  }
	
	}
	  
}
//---------------------------------------------------------

function getValor(obj_id) {
	
	return document.getElementById(obj_id).value;
	
}
//---------------------------------------------------------
function editarPropriedade(obj_id,prop,value) {
	document.getElementById(obj_id).prop = value;
}
//---------------------------------------------------------
function setFocus(frm_login,campo_login) {
	
	document.getElementById(campo_login).focus();
	document.getElementById(campo_login).select();	
}
//---------------------------------------------------------

/*************************************************/
/******************* POPUPS **********************/
/*************************************************/


function confirma(texto,label){
	
	Dialog.alert(texto, 
			{width:310, 
			 height:140, 
			 okLabel: label, 
			 ok:function(win) {debug("validate alert panel"); return true;}});
	
}
//---------------------------------------------------------

function mostraSelect(value)
{
	if(value == 1)
		document.getElementById('select_universidades').style.display = 'block';
	else
		document.getElementById('select_universidades').style.display = 'none';
	
}
//---------------------------------------------------------

function confirmaEnvio(id)
{
	div = document.getElementById(id);
	div.style.display = "block";
	var txt = '';
	txt = "<br /><center>Mensagem enviada com sucesso<br />";
	txt += "<p><a href='#'";
	txt += " onClick=\"javascript:fecharMsg('";
	txt += id;
	txt += "');\"";
	txt += ">Fechar</a></center>";

	div.innerHTML = txt;

}
//---------------------------------------------------------

function fecharMsg(id)
{
	document.getElementById(id).style.display = "none";
	
}
//---------------------------------------------------------

function changeMap(mapa) {
	
	document.getElementById('link1').className = '';
	document.getElementById('link2').className = '';
	document.getElementById('link3').className = '';
	
	document.getElementById('mapa').value = mapa;
	
	operador = 	'link'+mapa;
	aba = 		 document.getElementById(operador);
	receptor = 	 document.getElementById('img_mapa');
	
	aba.className = 	 'ativo';
	receptor.innerHTML = '<img src="resources/images/img_mapa'+mapa+'.gif" />';
	
}


