﻿/// <reference path="notification.css" />


function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

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_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
	obj.visibility=v; }
}

function openPopup(strOpen, StrCaption) {
    open(strOpen, StrCaption, "scrollbars=yes, status=1, width=650, height=450, top=200, left=330");
}

function openPopupTorpedo(strOpen, StrCaption) {
    open(strOpen, StrCaption, "scrollbars=yes, status=1, width=470, height=400, top=200, left=400");
}


function openPopupGrafico(strOpen, StrCaption) {
    open(strOpen, StrCaption, "scrollbars=yes, status=1, width=920, height=520, top=100, left=180");
}

function Mascaras(formato, objeto) {
    if (window.event.keyCode >= 48 && window.event.keyCode <= 57) {
        var campo = document.getElementById(objeto);

        if (formato == 'DATA') {
            separador = '/';
            conjunto1 = 2;
            conjunto2 = 5;
            if (campo.value.length == conjunto1)
                campo.value = campo.value + separador;

            if (campo.value.length == conjunto2)
                campo.value = campo.value + separador;
        }

        if (formato == 'FONE') {
            separador1 = '(';
            separador2 = ')';
            separador3 = '-';
            conjunto1 = 2;
            conjunto2 = 8;
            conjunto3 = 10;
            if (campo.value.length == conjunto1)
                campo.value = separador1 + campo.value + separador2;

            if (campo.value.length == conjunto2)
                campo.value = campo.value + separador3;

        }

        if (formato == 'FONESEMDDD') {
            separador = '-';
            conjunto1 = 4;
            conjunto2 = 4;
            if (campo.value.length == conjunto1)
                campo.value = campo.value + separador;

            if (campo.value.length == conjunto2)
                campo.value = campo.value + separador;
        }

        if (formato == 'ANIVERSARIO') {
            separador = '/';
            conjunto1 = 2;
            if (campo.value.length == conjunto1)
                campo.value = campo.value + separador;
        }


        if (formato == 'HORA') {
            separador = ':';
            conjunto1 = 2;
            if (campo.value.length == conjunto1)
                campo.value = campo.value + separador;
        }

        if (formato == 'CEP') {
            separador = '-';
            conjunto1 = 5;
            if (campo.value.length == conjunto1)
                campo.value = campo.value + separador;
        }

        if (formato == 'FONE') {
            separador1 = '(';
            separador2 = ')';
            separador3 = '-';
            conjunto1 = 2;
            conjunto2 = 8;
            conjunto3 = 10;
            if (campo.value.length == conjunto1)
                campo.value = separador1 + campo.value + separador2;

            if (campo.value.length == conjunto2)
                campo.value = campo.value + separador3;

        }

        if (formato == 'CPF') {
            separador = '.';
            separador1 = '-';
            conjunto1 = 3;
            conjunto2 = 7;
            conjunto3 = 11;
            if (campo.value.length == conjunto1)
                campo.value = campo.value + separador;

            if (campo.value.length == conjunto2)
                campo.value = campo.value + separador;

            if (campo.value.length == conjunto3)
                campo.value = campo.value + separador1;
        }

        if (formato == 'CNPJ') {
            separador = '.';
            separador1 = '/';
            separador2 = '-';
            conjunto1 = 2;
            conjunto2 = 6;
            conjunto3 = 10;
            conjunto4 = 15;

            if (campo.value.length == conjunto1)
                campo.value = campo.value + separador;

            if (campo.value.length == conjunto2)
                campo.value = campo.value + separador;

            if (campo.value.length == conjunto3)
                campo.value = campo.value + separador1;

            if (campo.value.length == conjunto4)
                campo.value = campo.value + separador2;

        }
    } else
        window.event.keyCode = 0;
}

	function RatePassword(pwd) {
		var strength  = GetPasswordStrength(pwd);
		var strengthPercent = ConvertToPercent(strength);
		document.getElementById("strengthdisplay").innerHTML = GetPasswordStrengthText(strengthPercent);
		var bardisplayGood = document.getElementById("bardisplayGood");
		var bardisplayBad = document.getElementById("bardisplayBad");
		var maxwidth = document.getElementById("bardisplayTable").width;
		var widthGood = 0;
		var widthBad = maxwidth;
		if (strengthPercent >= 80) {
			// anything above 80% is displayed as 100% good
			widthGood = maxwidth;
			widthBad = 0;
		} else if (strengthPercent >=0 && strengthPercent < 100) {
			// between zero and 100 display the ratio
			widthGood = (maxwidth * strengthPercent) / 100;
			widthBad = maxwidth - widthGood;
		}
		bardisplayGood.style.width = widthGood;
		bardisplayBad.style.width = widthBad;
	}
	
      function GetPasswordStrength(pwd) {
            // zero-length passwords cannot be rated
            if (pwd.length == 0) {
                  return -1;
            }
            // passwords that are too short are zero-strong
            if (pwd.length < 6) {
                  return 0;
            }
            var charsSpecial = "";
            var charsLowercase = "";
            var charsUppercase = "";
            var charsNumeric = "";
            var rating = 0;
            var bonus = 0;
            var i;
            
            // characters that follow each other in the alphabet are bad
            var charcode = pwd.charCodeAt(0); 
            for (i=1; i<pwd.length; i++) {
                  var diff = pwd.charCodeAt(i) - charcode;
                  charcode = pwd.charCodeAt(i);
                  if (diff == 1 || diff == -1) {
                        pwd = pwd.substring(0, i) + pwd.substring(i-1, i) + pwd.substring(i+1, pwd.length);
                  }
            }
            
            // put password characters into the right buckets
            for (i=0; i<pwd.length; i++) {
                  if (pwd.charCodeAt(i) >= 'a'.charCodeAt(0) && pwd.charCodeAt(i) <='z'.charCodeAt(0)) {
                        charsLowercase += pwd.substring(i, i+1);
                  } else if (pwd.charCodeAt(i) >= 'A'.charCodeAt(0) && pwd.charCodeAt(i) <='Z'.charCodeAt(0)) {
                        charsUppercase += pwd.substring(i, i+1);
                  } else if (pwd.charCodeAt(i) >= '0'.charCodeAt(0) && pwd.charCodeAt(i) <='9'.charCodeAt(0)) {
                        charsNumeric += pwd.substring(i, i+1);
                  } else {
                        charsSpecial += pwd.substring(i, i+1);
                  }
            }
                        
            rating = GetDistribution(charsLowercase);
            rating += GetDistribution(charsUppercase);
            rating += GetDistribution(charsNumeric);
            rating += GetDistribution(charsSpecial);
            
            if (charsLowercase.length > 0) bonus++;
            if (charsUppercase.length > 0) bonus++;
            if (charsNumeric.length > 0) bonus++;
            if (charsSpecial.length > 0) bonus++;
            
            rating = rating * (1 + ((bonus-1) / 4));
            return rating;
      }

	function ConvertToPercent(strength) {
		return 6*strength;
	}
		
	function GetDistribution(str) {
		var distribution = 0;
		var uniques = "";
		var i;
		for (i=0; i < str.length; i++) {
			if (uniques.indexOf(str.substring(i, i+1)) == -1) {
				uniques += str.substring(i, i+1);
			}
		}
		return uniques.length + ((str.length - uniques.length) / 5);
	}
	
	function GetPasswordStrengthText(strength) {
		if (strength == 0) {
			return "Muito Curta";
		} else if (strength > 0 && strength < 20) {
			return "Fraca";
		} else if (strength >= 20 && strength < 40) {
			return "Media";
		} else if (strength >= 40 && strength < 60) {
			return "Boa";
		} else if (strength >= 60 && strength < 80) {
			return "Forte";
		} else if (strength >= 80) {
			return "Muito Forte";
		} else {
			return "Nenhum";
		}
	}

function divAlert(titleStr,msgStr,button1Text,button1Action,button2Text,button2Action,isDimmed,isGradient,hasOwnStyle)
{
 var alertStr = "";
 var backgroundclass = "noTitle";
 if (!isGradient) backgroundclass = "yesTitle";
 if (typeof(titleStr) !== "string") titleStr = "";
 var hasButton1 = typeof(button1Text) == "string" && typeof(button1Action) == "string";
 var hasButton2 = typeof(button2Text) == "string" && typeof(button2Action) == "string";

    alertStr = '<table border=0 class='+backgroundclass+'><tr><td class=alertTitle>'+titleStr+'</td><td class=x valign=top><a href=\'javascript:closeAlert()\'><img src=img/x-notif.jpg border=0></a></td></tr>';

 if (titleStr == "") alertStr += '<tr><td></td></tr><tr><td colspan=2 class=alertText>'+msgStr+'</td></tr>';
 else alertStr += '<tr><td class=alertSpace></td></tr><tr><td colspan=2 class=alertText>'+msgStr+'</td></tr>';

 if (hasButton1)
 {
        alertStr += '<tr><td colspan=2 class=alertButton>';

     if (hasButton1)  
        alertStr += '<input type=button value=\''+button1Text+'\' onClick=\''+button1Action+'\' />';

     if (hasButton2) 
        alertStr += '&nbsp;<input type=button value=\''+button2Text+'\' onClick=\''+button2Action+'\' />';

        alertStr += '</td></tr>';
 }
 
 alertStr += '<tr><td class=alertSpace></td></tr></table>';
 
 if (hasOwnStyle) {
     alertStr = msgStr;
 }


 if (!document.getElementById("divAlertID"))
 {
    newDiv = document.createElement("div");
    newDiv.id = "divAlertID";
    document.body.appendChild(newDiv);
 }

 document.getElementById("divAlertID").innerHTML = alertStr;

 cWidth = document.body.clientWidth; cHeight = document.body.clientHeight;
 document.getElementById("divAlertID").style.top = document.body.scrollTop + 100;
 document.getElementById("divAlertID").style.left = (cWidth / 2) - 260;
 document.getElementById("divAlertID").style.display = "block";

    if (isDimmed)
        Dimmer();
}

function closeAlert()
{
    if (document.getElementById("divAlertID"))
        document.getElementById("divAlertID").style.display = "none";
    if (document.getElementById("dimmerDiv"))
        document.getElementById("dimmerDiv").style.display = "none";
        
    var selCount=document.getElementsByTagName("select")
    for (i=0; i<selCount.length; i++)
        selCount[i].style.visibility="visible";     
}

function Dimmer()
{
    if (!document.getElementById("dimmerDiv"))
    {
        newDiv2 = document.createElement("div");
        newDiv2.id = "dimmerDiv";
        document.body.appendChild(newDiv2);
    }
    if (document.body.clientHeight < document.body.scrollHeight) 
    {
        document.getElementById("dimmerDiv").style.height = document.body.scrollHeight + 'px';
    }
    document.getElementById("dimmerDiv").style.width = document.body.scrollWidth + 'px';
    // if (is_ie5 || is_ie6) {hideSelects()};
    document.getElementById("dimmerDiv").style.display = "block";
    var selCount = document.getElementsByTagName("select");
    for (i=0; i<selCount.length; i++)
        selCount[i].style.visibility = "hidden";  
}


	function showFlash(url, w, h) {
		var faixaCond = new SWFObject(url, "dhtml", "571", "306", "7", "#0a320c");
		faixaCond.addParam("wmode", "transparent");
		faixaCond.addParam("allowscriptaccess", "always");
		faixaCond.write("dhtml");
	}
	
	
	function showFlash2(url, w, h) {
		var faixaCond = new SWFObject(url, "dhtml", w, h, "7", "#0a320c");
		faixaCond.addParam("wmode", "transparent");
		faixaCond.addParam("allowscriptaccess", "always");
		faixaCond.write("dhtml");
	}
	
	
  function OcultaDiv(Layer)
  {
     document.getElementById(Layer).style.visibility='hidden';
  }


 jQuery(document).ready(function($) {
             $('a[rel*=facebox]').facebox({
                 loading_image: 'loading.gif',
                 close_image: 'closelabel.gif'
             })
         })

