function blurLinks(){
	lnks=document.getElementsByTagName('a');
	for(var i=0;i<lnks.length;i++){
		lnks[i].onfocus=new Function('if(this.blur)this.blur()');
	}
}
function cMn(id, idChBox){
	getElm(id).style.display = ((getElm(id).style.display == '')?'none':'');
	if (idChBox != null) {
		if(getElm(id).style.display == 'none') {
			getElm(idChBox).checked = false;
		} else {
			getElm(idChBox).checked = true;
		}
	}
}
function clearField(field,text) {
	if(field.value==text) {
		field.value='';
	}
	field.select();
}
function inputField(field,text) {
	if(field.value=='') {
		field.value=text;
	}
}
function openCenteredWindow(contentURL,contentTitle,contentWidth,contentHeight,scrollBars,returnObj) {
	var winLeft = (screen.width - 1 - contentWidth) / 2;
	var winTop = (screen.height - 35 - contentHeight) / 2;
	if (winLeft < 0) {
		scrollBars = "yes";
		winLeft = 10;
		contentWidth = screen.width - 30;
	}
	if (winTop < 0) {
		scrollBars = "yes";
		winTop = 10;
		contentHeight = screen.height - 100;
	}
	if (scrollBars == 'yes') {
	    resizable=',resizable=yes';
	} else {
	    resizable=',resizable=no';
	}
	var NewWindow = window.document.open(contentURL,contentTitle,'scrollbars='+scrollBars+',width='+contentWidth+',height='+contentHeight+',top='+winTop+',left='+winLeft+',screenX='+winLeft+',screenY='+winTop+resizable);
	NewWindow.focus();
	if (returnObj) {
		return NewWindow;
	} else {
		return;
	}
}

function trim(inputString) {
	if (typeof inputString != "string") { 
		return inputString; 
	}
	var retValue = inputString;
	var ch = retValue.substring(0, 1);
	while (ch == " ") {
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}
	ch = retValue.substring(retValue.length-1, retValue.length);
	while (ch == " ") {
		retValue = retValue.substring(0, retValue.length-1);
		ch = retValue.substring(retValue.length-1, retValue.length);
	}
	while (retValue.indexOf("  ") != -1) {
		retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
	}
	return retValue;
}
function formataNomeCompleto(v) {
  return trim(v.toUpperCase());

/*
	ignored = new Array(7);
	ignored[0] = "de";
	ignored[1] = "des";
	ignored[2] = "da";
	ignored[3] = "das";
	ignored[4] = "do";
	ignored[5] = "dos";
	ignored[6] = "e";
	if(trim(v) == '') {
		return v;
	}
	v = v.toLowerCase();
	var novoValor = '';
	var e = v.split(" ");
	for(var i=0;i<e.length;i++) {
		var capitalize = true;
		for(var j=0;j<ignored.length;j++) {
			if(e[i] == ignored[j]) {
				capitalize = false;
			}
		}
		if(capitalize) {
			novoValor += e[i].substring(0,1).toUpperCase() + e[i].substring(1,e[i].length) + ' '		
		} else {
			novoValor += e[i] + ' ';
		}
	}
	return trim(novoValor);
*/
}
function openPopupTutorial(url,n,w,h,other){
	l=0;t=0;
	if(screen.availWidth > 800){
		l=30;
		t=30;
	}
	url=url.replace(/[ ]/g,'%20');
	popup=window.open(url,'pop_'+n,'left='+l+',top='+t+',width='+w+',height='+h+',scrollbars=1'+((other)?','+other:''));
	other=other||'';
	if(is.ie&&other.indexOf('fullscreen')!=-1){popup.moveTo(0,0);popup.resizeTo(screen.width,screen.height)}
	popup.focus();
}
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 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 isArray(obj){
	return(typeof(obj.length)=="undefined")?false:true;
}

function getRadioValue(radioGroup) {
    for (var i=0; i < radioGroup.length; i++) {
        if (radioGroup[i].checked) {return radioGroup[i].value}
    }
	return null;                  
}

function getAgeFromDate(birthDay){
   var today = new Date();
    
    return today.getFullYear() - birthDay.getFullYear() + 
      (birthDay.getMonth() > today.getMonth() ? -1 : 
      (birthDay.getMonth() == today.getMonth() && birthDay.getDate() > today.getDate() ? -1 : 0));
}

function validaCpfMaiorIdade(cpfElement,nomeMaeElement,dataNasc){
	var result = (String(nomeMaeElement.value) == "" || String(cpfElement.value) == "")&& getAgeFromDate(dataNasc) >= 18 ? false: true;
	
	var resultFields = (String(cpfElement.value) == "" && String(nomeMaeElement.value) == "") && getAgeFromDate(dataNasc) < 18 ? false: true; 
	
	if(!result){
		alert ('Os campos CPF e Nome da Mãe são obrigatórios para dependentes maiores de 18 anos.');
		cpfElement.focus();
		result = false;
	} 
	
	if (!resultFields){
		alert ('Os campos CPF ou Nome da Mãe são obrigatórios para dependentes menores de 18 anos.');
		cpfElement.focus();
		result = false;
	}
	return result;  
} 

/*
function validaCpfMaiorIdade(cpfElement,dataNasc){
	var result = cpfElement.value == "" && getAgeFromDate(dataNasc) >= 18 ? false: true;
	if(!result){
		alert ('O campo CPF é obrigatório para titulares ou dependentes com idade maior que 18 anos');
		cpfElement.focus();
	}
	return result;  
}
*/
