/* Função Maximizar/Minimizar */
function Maximizar(bloco,imagem) { 
	if((bloco.style.display=='')||(bloco.style.display=='block')) {
			bloco.style.display='none';
			imagem.src='imagens/bt_maximizar.gif';
	} else {
			bloco.style.display='block';
			imagem.src='imagens/bt_minimizar.gif';
	}
}



/* Função Aumentar/Diminuir a fonte */

function sizeFont (elem, acao){
    // tamanho inicial da fonte (em px)
    var tamInic = 12;
    // Tamanho mínimo da [b]fonte (em px)
    var tamMin = 9;
    // Tamanho máximo da fonte (em px)
    var tamMax = 20;
    // Pega o tamanho da fonte. Se não foi setada ainda (primeira vez que a função é executada) terá como tamanho padrão 'tamInic'.
    if (document.getElementById(elem).style.fontSize == "") {
            var tamFonte = tamInic;
    }else{
            var tamFonte = parseInt(document.getElementById(elem).style.fontSize);
            }
            switch (acao){
                // Aumenta o tamanho, enquanto foi menor que 'tamMax'
                case '+':
                        if (tamFonte < tamMax)
                                document.getElementById(elem).style.fontSize = (tamFonte + 2) + "px";
                break;
                // Diminui o tamanbo, enquanto for maior que 'tamMin'
                case '-':
                        if (tamFonte > tamMin)
                                document.getElementById(elem).style.fontSize = (tamFonte - 2) + "px";
                break;
            }
}
/* Função Aumentar/Diminuir a fonte */

function UploadFoto(usuario)
{
    var url = 'UploadFoto.aspx?usuario=' + usuario;
    showPopWin(url, 500, 250, UploadComplete);
}

function UploadComplete() {
    PageMethods.ImagemCliente();
    __doPostBack('','');
}

function ValidarCPF(source, arguments)
{
    //alert(arguments.Value);
    cpf = arguments.Value;
    
    arguments.IsValid = true;

    if (cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999")
    {
        arguments.IsValid = false;
    } 
    else 
    {
        add = 0;

        for (i=0; i < 9; i ++)
            add += parseInt(cpf.charAt(i)) * (10 - i);

        rev = 11 - (add % 11);

        if (rev == 10 || rev == 11)
            rev = 0;

        if (rev != parseInt(cpf.charAt(9)))
            arguments.IsValid = false;
        else {
            add = 0;

            for (i = 0; i < 10; i ++)
                add += parseInt(cpf.charAt(i)) * (11 - i);

            rev = 11 - (add % 11);

            if (rev == 10 || rev == 11)
                rev = 0;

            if (rev != parseInt(cpf.charAt(10)))
                arguments.IsValid = false;
        }
    }
}

function removeHint(campo, hint)
{
    //alert(campo);
    //alert(document.getElementById(campo).value);
    if (document.getElementById(campo).value == hint)
        document.getElementById(campo).value = "";
}

function putHint(campo, hint)
{
    //alert(campo);
    //alert(document.getElementById(campo).value);
    if (document.getElementById(campo).value == "")
        document.getElementById(campo).value = hint;
}

function AbrirFechar(bloco) {

	if((bloco.style.display=='') || (bloco.style.display=='block')) {
	    bloco.style.display='none';
	} else {
    	bloco.style.display='block';
    }
    
}

function ehIPad()
{
    var detect = navigator.userAgent.toLowerCase();
    var OS,browser,version,total,thestring;

    if (checkIt('konqueror')){
        browser = "Konqueror";
        OS = "Linux";
    }
    else if (checkIt('safari')) browser = "Safari";
    else if (checkIt('omniweb')) browser = "OmniWeb";
    else if (checkIt('opera')) browser = "Opera";
    else if (checkIt('webtv')) browser = "WebTV";
    else if (checkIt('icab')) browser = "iCab";
    else if (checkIt('msie')) browser = "Internet Explorer";
    else if (!checkIt('compatible')){
        browser = "Netscape Navigator";
        version = detect.charAt(8);
    }
    else browser = "An unknown browser";

    if (!version) version = detect.charAt(place + thestring.length);
    if (!OS){
        if (checkIt('linux')) OS = "Linux";
        else if (checkIt('x11')) OS = "Unix";
        else if (checkIt('mac')) OS = "Mac";
        else if (checkIt('win')) OS = "Windows";
        else OS = "an unknown operating system";
    }

    //alert(browser);
    //alert(version);
    //alert(OS);

    //alert(navigator.platform);

    if (navigator.userAgent.match(/iPad/i)  != null)
        return true;
    else
        return false;
        //alert('IPAD');
}

function checkIt(string){
    place = detect.indexOf(string) + 1;
    thestring = string;
    return place;
}

var tooltip=function(){
	var id = 'tt';
	var top = 3;
	var left = 3;
	var maxw = 300;
	var speed = 10;
	var timer = 20;
	var endalpha = 95;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	return{
		show:function(v,w){
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				t = document.createElement('div');
				t.setAttribute('id',id + 'top');
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				b = document.createElement('div');
				b.setAttribute('id',id + 'bot');
				tt.appendChild(t);
				tt.appendChild(c);
				tt.appendChild(b);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';
			c.innerHTML = v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				t.style.display = 'none';
				b.style.display = 'none';
				tt.style.width = tt.offsetWidth;
				t.style.display = 'block';
				b.style.display = 'block';
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(e){
			var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
			var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
			tt.style.top = (u - h) + 'px';
			tt.style.left = (l + left) + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();
