/*# IMAGE CHANGER #*/
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_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 MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

/*# CONTA CARACTER #*/
function contaCaracter(campoVC,caracterN,limiteN) {
	if (campoVC.value.length > limiteN) {
		campoVC.value		= campoVC.value.substring(0,limiteN);
	} else {
		caracterN.value	= limiteN - campoVC.value.length;
	}
}

/*# IFRAME VIRTUAL #*/
function iframeVirtual(urlVC) {
/*	if (document.getElementById('iframeVirtual'))	{
		document.getElementById('iframeVirtual').removeNode(true);
	}
	
	var tempIFrame					= document.createElement('iframe');
		tempIFrame.style.border		='0px';
		tempIFrame.style.width		='600px';
		tempIFrame.style.height		='400px';
		
		tempIFrame.setAttribute('id','iframeVirtual');
		tempIFrame.setAttribute('name','iframeVirtual');
		tempIFrame.setAttribute('src',urlVC);
	
	IFrameObj						= document.body.appendChild(tempIFrame);*/
	codigo.location.href			= urlVC;
}

/*# MASCARA */
function mascarar(campoVC,mascaraVC) {
	var i		= document.getElementById(campoVC).value.length;
	var x		= mascaraVC.substring(0,1);
	var y		= mascaraVC.substring(i);

	if (y.substring(0,1) != x) {
		document.getElementById(campoVC).value += y.substring(0,1);
	}
}

/*# MASCARA MOEDA #*/
function mascaraMoeda(valor,cx) {
	if (valor) {
		var doc					= eval('document.all.'+cx);
		
		if (window.event.keyCode == 110 || window.event.keyCode == 188 || window.event.keyCode == 190 || window.event.keyCode == 194)	{
			doc.value			= valor.substr(0,(valor.length-1));
		} else {
			valor				= mascararCentavo(valor);
			
			if (mascararCentavo(valor).length > 2) {
				str				= valor.replace(".","");
				doc.value		= str.substr(0,(str.length-2))+"."+str.substr((str.length-2),str.length);
			} else {
				valor			= mascararCentavo(valor);
				
				if (valor.length == 1) {
					doc.value	= "0.0"+valor;
				} else {
					doc.value	= "0."+valor;
				}
			}
		}
	}
}

function mascararCentavo(valorMN) {
	if (valorMN.indexOf('0') == 0) {
		valorMN	= valorMN.replace('0.','');
		valorMN	= valorMN.replace('0.0','');
	}
	
	valorMN		= valorMN.replace('.','');

	return		valorMN;
}

/*#SO NUMERO#*/
function soNumero(eventoN) {
	if (document.all) {
		var teclaN = event.keyCode;
	} else if(document.layers) {
		var teclaN = eventoN.which;
	}
	
	if (teclaN >= 48 && teclaN <= 57) {
		return true;
	} else if (teclaN != 8) {
		if (document.all) {
			event.keyCode	= 0;
		} else if(document.layers) {
			eventoN.which	= 0;
		}
	} else {
		return true;
	}
}

/*# VERIFICA DATA #*/
function verificaData(campoVC) { 
	if (campoVC.value.length > 0) {  
		diaN = (campoVC.value.substring(0,2)); 
		mesN = (campoVC.value.substring(3,5)); 
		anoN = (campoVC.value.substring(6,10)); 
		erroN = 0; 
		
		if ((diaN < 01) || (diaN < 01 || diaN > 30) && (mesN == 04 || mesN == 06 || mesN == 09 || mesN == 11 ) || diaN > 31) { 
			erroN = 1; 
		} 

		if (mesN < 01 || mesN > 12 ) { 
			erroN = 1; 
		} 

		if (mesN == 2 && (diaN < 01 || diaN > 29 || (diaN > 28 && (parseInt(anoN / 4) != anoN / 4)))) { 
			erroN = 1; 
		} 

		if ((anoN < 1900) || (anoN>2078)){
			erroN = 1;
		}
		
		if (erroN == 1) { 
			campoVC.value	= '';
			campoVC.focus(); 
			alert("Por favor, preencha uma data válida!"); 
		}
	} 
}

/*# BUSCA VERIFICAR #*/
function buscaVerificar(){
	var erroVC		= '';
	
	if (document.buscaFRM.termoVC.value.length < 3) {
	 	erroVC	= erroVC + '- Digite ao menos 3 CARACTERES.\n';
	}
	
	if (erroVC.length == 0) {
		return true;
	} else {
		alert('ATENÇÃO!\n\n' + erroVC);
		return false;
	}
}

function gravaBusca(it_tipo, vc_termo) {
    iframeVirtual('/temp/conta_busca.asp?vc_termo=' + vc_termo + '&it_tipo=' + it_tipo);
    return false;
}

/*# VOLTAR #*/
function voltar() { 
	javascript:history.back();
}

/*# CADASTRO #*/
function cadastro(actB,areaID) {
	if (actB == 1) {
		logoff(0);
	}

	setTimeout('top.location.href=\'?actA=9&actB='+actB+'&areaID=' + areaID + '\'',3000);
}

/*# BANNER #*/
function banner(bannerID) {
    codigo.location.href = '/codigos/banner.asp?bannerID=' + bannerID;
}

/*# LOGOFF #*/
function logoff(actA) {
    codigo.location.href = '/codigos/logoff.asp?actA=' + actA;
}

/*# EVENTO #*/
function evento(actB,areaID,secaoID) { 
	top.location.href='?actA=15&actB='+actB+'&areaID='+areaID+'&secaoID='+secaoID;
}

/*# CLASSIFICADO #*/
function classificado(actB,areaID,secaoID) { 
	top.location.href='?actA=16&actB='+actB+'&areaID='+areaID+'&secaoID='+secaoID;
}

/*# MENSAGEM #*/
function mensagem(mensagemID,fecharIT) {
    codigo.location.href = '/codigos/mensagem.asp?mensagemID=' + mensagemID + '&fecharIT=' + fecharIT;
}


function verificar_indiqueSite(){

	var vc_erro	=	'';
	if(document.getElementById('nomeVCI').value == '') {vc_erro	+=	'- Seu Nome\n';}
	if(document.getElementById('emailVCI').value == ''){vc_erro 	+=	'- Seu E-mail\n';}
	if(document.getElementById('nome2VCI').value == ''){vc_erro 	+=	'- Nome do amigo\n';}
	if(document.getElementById('email2VCI').value == ''){vc_erro += 	'- E-mail do amigo\n';}
	if(vc_erro.length > 0){
		alert('- ATENÇÃO \n \nPreencha os seguintes campos: \n'+vc_erro);
	}else{
		document.indicacaoFRM.submit();
	}
}

/*FUNÇÃO PARA EXPANDIR BANNERS*/
function bannerExpansivel(obj)
{
	if(obj.style.overflow=='hidden'){
		vc_overflow = 'visible';
	}else{
		vc_overflow = 'hidden';
	}
	obj.style.overflow = vc_overflow;
}

function carregaImagem(id_site, id_tema){

	switch(id_site){
		case 2:
			document.all.inicial.src = 'imagens/inicial_beef'+id_tema+'.gif';
			break;
		case 3:
			document.all.inicial.src = 'imagens/inicial_farm'+id_tema+'.gif';
			break;
		case 4:
			document.all.inicial.src = 'imagens/inicial_milk'+id_tema+'.gif';
			break;
		case 5:
			document.all.inicial.src = 'imagens/inicial_cafe'+id_tema+'.gif';
			break;
	}

}


function getAjax() {
    http_request = false;
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            // set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType("text/html; charset=windows-1252");
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) { }
        }
    }
    if (!http_request) {
        alert('Desculpe, seu navegador é incompatível com este recurso.');
        return false;
    }
    return http_request;
}


function carregaUltimasMyPoint() {
    url = 'mypoint/ultimasAtividades.aspx';
    req = getAjax();
    req.onreadystatechange = function() {
        content = '';
        if (req.readyState == 4 && req.status == 200)
            content = req.responseText;
        document.getElementById('tdUltimasMyPoint').innerHTML = content;
    }

    req.open('GET', url, true);
    req.send(null);
}

function getel(doc, id) {
    return doc.getElementById(id);
}

function el(id) {
    return getel(document, id);
}

function fechaMpDest() {
    var expire = new Date();
    expire.setTime(new Date().getTime() + 3600000 * 24 * 5000);
    ck = 'noMPdest=1;path=/;expires=' + expire.toGMTString();
    document.cookie = ck;
    el('imgMpDest').style.display = 'none'
}
