// Abre janela popup
function clickPop(url,nome,opcoes) {
  window.open(url,nome,opcoes);
}

function envia(c){
	if (this.selectedIndex==0) return false;
	else scrollBy(null,docH()-50);
}

// Manipulacao de SELECTs
function mOption(strId, strText, className) {
  this.id = strId;
  this.text = strText;
	this.className = className;
}

function fSetOptions(vOptions, fSelect, strSelected) {
  fSelect.length = vOptions.length;
    for (i=0; i<vOptions.length; i++) {
      fSelect.options[i].value = vOptions[i].id;
      fSelect.options[i].text = vOptions[i].text;
	  if(vOptions[i].className)fSelect.options[i].className = vOptions[i].className;
      if (vOptions[i].id==strSelected) {
        fSelect.options[i].selected=true;
      }
   }
}

function Print(){
	if (is.ns){
		window.print();
	}else{
		var webBrowser = '<object id="WebBrowser1" width=0 height=0 classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>';
		d.body.insertAdjacentHTML('beforeEnd', webBrowser);
		WebBrowser1.ExecWB(6,2);
		WebBrowser1.outerHTML = '';
	}
}

function ehDinheiro(n) {
	var result = true;
	var tam = 20;

	n = String(n);
	for (var i=0; i<tam; ++i) {
		n = n.replace(".","");
	}
	//result = result && (n.length>3 && n.length <= tam+1);
	result = result && (n.length>1 && n.length <= tam);
	result = result && (n.charAt(n.length-3)==",");
	for (var i=0; i<n.length; ++i) {
		result = result && (!isNaN(n.charAt(i)) || n.charAt(i)==",");
	}

	return result;
}

function tiraDuvidas(id){
	openPopup('/amilportal/site/tiraduvidas/tira_duvidas.jsp?codigo=ID'+id,'Duvidas',500,350,false,false);
}

function abreTiraDuvidas(id){
	openPopup('/amilportal/site/tiraduvidas/tira_duvidas.jsp?codigo='+id,'Duvidas',600,500,false,false);
}

function checkUpdateSelect( f , s , ts, tf, ti, o )
{
	if( s.selectedIndex > 0 )
	{
		UpdateSelect(ts,tf,s[s.selectedIndex].value,o);
		f[ts].selectedIndex=ti;
	}
}

function lTrim(str)
{
   if (str.lenght == 0){
      return "";
   }
   
   var whitespace = new String(" \t\n\r");
   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      var j=0;
      var i = s.length;
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1){
      	j++;
      }
      s = s.substring(j, i);
   }
   return s;
}

function rTrim(str)
{
   if (str.lenght == 0){
      return "";
   }
   var whitespace = new String(" \t\n\r");
   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      var i = s.length - 1;

      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1){
      	i--;
      }
      s = s.substring(0, i+1);
   }
   return s;
}

function trim(str)
{
   return rTrim(lTrim(str));
}

String.prototype.checkNumber = function(msg, campo){
	if (isNaN(this)){
		DFchangeClassFocus( msg , campo);
		return false;
	}
	return true;
};

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; 
  if(d.images){ 
  	if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; 
    for(i=0; i<a.length; i++) {
	    if (a[i].indexOf("#")!=0){ 
	    	d.MM_p[j]=new Image; 
	    	d.MM_p[j++].src=a[i];
	    }
	}
  }
}

function MM_findObj(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_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); 
  return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; 
  document.MM_sr=new Array; 
  for(i=0;i<(a.length-2);i+=3) {
    if ((x=MM_findObj(a[i]))!=null){
    	document.MM_sr[j++]=x; 
    	if(!x.oSrc) x.oSrc=x.src; 
    	x.src=a[i+2];
    }
  }
}

function showDiv(layer_ref) {
    //alert('as: '+layer_ref);
    if (document.all) {
        eval( "document.all." + layer_ref + ".style.visibility = \'visible\'");
        //document.all.fotoFundo.style.visibility = 'visible' ;
    }
    if (document.layers) { //IS NETSCAPE 4 or below
        document.layers[layer_ref].visibility = 'visible';
    }
    if (document.getElementById && !document.all) {
        maxwell_smart = document.getElementById(layer_ref);
        maxwell_smart.style.visibility = 'visible';
    }
}

function hideDiv(layer_ref) {
    //alert('as: '+layer_ref);
    if (document.all) {
        eval( "document.all." + layer_ref + ".style.visibility = \'hidden\'");
    }
    if (document.layers) { //IS NETSCAPE 4 or below
        document.layers[layer_ref].visibility = 'hidden';
    }
    if (document.getElementById && !document.all) {
        maxwell_smart = document.getElementById(layer_ref);
        maxwell_smart.style.visibility = 'hidden';
    }
}

// function to show element using visibility and display
function showVD(layer_ref) {
        //alert('as: '+layer_ref);
        if (document.all) {
            eval( "document.all." + layer_ref + ".style.visibility = \'visible\'");
            eval( "document.all." + layer_ref + ".style.display = \'block\'");
        }
        if (document.layers) { //IS NETSCAPE 4 or below
            document.layers[layer_ref].visibility = 'visible';
            document.layers[layer_ref].display = 'block';
        }
        if (document.getElementById && !document.all) {
            maxwell_smart = document.getElementById(layer_ref);
            maxwell_smart.style.visibility = 'visible';
            maxwell_smart.style.display = 'block';
        }
  }

 // function to show element using visibility and display
 function hideVD(layer_ref) {
        //alert('as: '+layer_ref);
        if (document.all) {
            eval( "document.all." + layer_ref + ".style.visibility = \'hidden\'");
            eval( "document.all." + layer_ref + ".style.display = \'none\'");
        }
        if (document.layers) { //IS NETSCAPE 4 or below
            document.layers[layer_ref].visibility = 'hidden';
            document.layers[layer_ref].display = 'none';
        }
        if (document.getElementById && !document.all) {
            maxwell_smart = document.getElementById(layer_ref);
            maxwell_smart.style.visibility = 'hidden';
            maxwell_smart.style.display = 'none';
        }
  }    