//Use a função  displayDatePicker('Objeto que vai receber a data');
/*
Exemplo:
<input name="ADate" OnKeyUp="mascara_data('data1');" id='data1'> 
<input type=button value="select" onclick="displayDatePicker('ADate');">

Para o uso de estilos:
Classes do Data:
Tabela = Classe do objeto tabela em geral
CabecalhoTabela = Cabecalho da tabela
Input = Botões
a3 = Dias Normais
a2 = Dias Selecionados
*/


var datePickerDivID = "datepicker";
var iFrameDivID = "datepickeriframe";

var dayArrayShort = new Array('Do', 'Se', 'Te', 'Qu', 'Qu', 'Se', 'Sa');
var dayArrayMed = new Array('Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sab');
var dayArrayLong = new Array('Domingo', 'Segunda', 'Terça', 'Quarta', 'Quinta', 'Sexta', 'Sabado');
var monthArrayShort = new Array('Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez');
var monthArrayMed = new Array('Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez');
var monthArrayLong = new Array('Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro');
  
// these variables define the date formatting we're expecting and outputting.
// If you want to use a different format by default, change the defaultDateSeparator
// and defaultDateFormat variables either here or on your HTML page.
var defaultDateSeparator = "/";		// common values would be "/" or "."
var defaultDateFormat = "dmy"	// valid values are "mdy", "dmy", and "ymd"
var dateSeparator = defaultDateSeparator;
var dateFormat = defaultDateFormat;

/**
This is the main function you'll call from the onClick event of a button.
Normally, you'll have something like this on your HTML page:

Start Date: <input name="StartDate"> 
<input type=button value="select" onclick="displayDatePicker('StartDate');">

That will cause the datepicker to be displayed beneath the StartDate field and
any date that is chosen will update the value of that field. If you'd rather have the
datepicker display beneath the button that was clicked, you can code the button
like this:

<input type=button value="select" onclick="displayDatePicker('StartDate', this);">

So, pretty much, the first argument (dateFieldName) is a string representing the
name of the field that will be modified if the user picks a date, and the second
argument (displayBelowThisObject) is optional and represents an actual node
on the HTML document that the datepicker should be displayed below.

In version 1.1 of this code, the dtFormat and dtSep variables were added, allowing
you to use a specific date format or date separator for a given call to this function.
Normally, you'll just want to set these defaults globally with the defaultDateSeparator
and defaultDateFormat variables, but it doesn't hurt anything to add them as optional
parameters here. An example of use is:

<input type=button value="select" onclick="displayDatePicker('StartDate', false, 'dmy', '.');">

This would display the datepicker beneath the StartDate field (because the 
displayBelowThisObject parameter was false), and update the StartDate field with
the chosen value of the datepicker using a date format of dd.mm.yyyy
*/
function displayDatePicker(dateFieldName, displayBelowThisObject,dpPosition, dtFormat, dtSep)
{
  var targetDateField = document.getElementsByName(dateFieldName).item(0);
  var defaultposition = 'right';
  // if we weren't told what node to display the datepicker beneath, just display it
  // beneath the date field we're updating
  if (!displayBelowThisObject)
    displayBelowThisObject = targetDateField;
  
  // if a date separator character was given, update the dateSeparator variable
  if (dtSep)
    dateSeparator = dtSep;
  else
    dateSeparator = defaultDateSeparator;
  
  // if a date format was given, update the dateFormat variable
  if (dtFormat)
    dateFormat = dtFormat;
  else
    dateFormat = defaultDateFormat;
  if( dpPosition )
     position = dpPosition;
  else
     position = defaultposition;
  if( position == 'right')
     var x = displayBelowThisObject.offsetLeft;
  else
    var x = displayBelowThisObject.offsetLeft - 150;

  var y = displayBelowThisObject.offsetTop + displayBelowThisObject.offsetHeight;
  
  // deal with elements inside tables and such
  var parent = displayBelowThisObject;
  while (parent.offsetParent) {
    parent = parent.offsetParent;
    x += parent.offsetLeft;
    y += parent.offsetTop;
  }
  
  drawDatePicker(targetDateField, x, y);
}


/**
Draw the datepicker object (which is just a table with calendar elements) at the
specified x and y coordinates, using the targetDateField object as the input tag
that will ultimately be populated with a date.

This function will normally be called by the displayDatePicker function.
*/
function drawDatePicker(targetDateField, x, y)
{
  var dt = getFieldDate(targetDateField.value);
  
  // the datepicker table will be drawn inside of a <div> with an ID defined by the
  // global datePickerDivID variable. If such a div doesn't yet exist on the HTML
  // document we're working with, add one.
  if (!document.getElementById(datePickerDivID)) {
    // don't use innerHTML to update the body, because it can cause global variables
    // that are currently pointing to objects on the page to have bad references
    //document.body.innerHTML += "<div id='" + datePickerDivID + "' class='dpDiv'></div>";
    var newNode = document.createElement("div");
    newNode.setAttribute("id", datePickerDivID);
    newNode.setAttribute("class", "dpDiv");
    newNode.setAttribute("style", "visibility: hidden;");
    document.body.appendChild(newNode);
  }
  
  // move the datepicker div to the proper x,y coordinate and toggle the visiblity
  var pickerDiv = document.getElementById(datePickerDivID);
  pickerDiv.style.position = "absolute";
  pickerDiv.style.left = x + "px";
  pickerDiv.style.top = y + "px";
  pickerDiv.style.visibility = (pickerDiv.style.visibility == "visible" ? "hidden" : "visible");
  pickerDiv.style.zIndex = 10000;
  
  // draw the datepicker table
  refreshDatePicker(targetDateField.name, dt.getFullYear(), dt.getMonth(), dt.getDate());
}


/**
This is the function that actually draws the datepicker calendar.
*/
function refreshDatePicker(dateFieldName, year, month, day)
{
  // if no arguments are passed, use today's date; otherwise, month and year
  // are required (if a day is passed, it will be highlighted later)
  var thisDay = new Date();
  
  if ((month >= 0) && (year > 0)) {
    thisDay = new Date(year, month, 1);
  } else {
    day = thisDay.getDate();
    thisDay.setDate(1);
  }
  
  // the calendar will be drawn as a table
  // you can customize the table elements with a global CSS style sheet,
  // or by hardcoding style and formatting elements below
  var crlf = "\r\n";
  var TABLE = "<table width='210' border='0' cellspacing='0' cellpadding='5' cols='7' class='tabela_calendario'>" + crlf;
  var xTABLE = "</table>" + crlf;
  var TR = "<tr Align='Center' Class='calendario_linha'>";
  var TR_title = "<tr Align='Center'>";
  var TR_days = "<tr Align='Center' Class='calendario_linha'>";
  var TR_todaybutton = "<tr Align='Center' Class='calendario_linha'>";
  var xTR = "</tr>" + crlf;
  var TD = "<td  Class='l2'";	// leave this tag open, because we'll be adding an onClick event
  var TD_title = "<td colspan=5>";
  var TD_buttons = "<td>";
  var TD_todaybutton = "<td colspan=7>";
  var TD_days = "<td >";
  var TD_selected = "<td Class='calendario_selecionado' ";	// leave this tag open, because we'll be adding an onClick event
  var xTD = "</td>" + crlf;
  var DIV_title = "<div>";
  var DIV_selected = "<div>";
  var xDIV = "</div>";
  
  // start generating the code for the calendar table
  var html = TABLE;
  
  // this is the title bar, which displays the month and the buttons to
  // go back to a previous month or forward to the next month
  html += TR_title;
  html += TD_buttons + getButtonCode(dateFieldName, thisDay, -1, "<") + xTD;
  html += TD_title + DIV_title + monthArrayLong[thisDay.getMonth()] + " " + thisDay.getFullYear() + xDIV + xTD;
  html += TD_buttons + getButtonCode(dateFieldName, thisDay, 1, ">") + xTD;
  html += xTR;
  
  // this is the row that indicates which day of the week we're on
  html += TR_days;
  for(i = 0; i < dayArrayMed.length; i++)
    html += TD_days + dayArrayMed[i] + xTD;
  html += xTR;
  
  // now we'll start populating the table with days of the month
  html += TR;

  // first, the leading blanks
  for (i = 0; i < thisDay.getDay(); i++)
    html += TD + "&nbsp;" + xTD;

  // now, the days of the month
  do {
    dayNum = thisDay.getDate();
    TD_onclick = " onclick=\"updateDateField('" + dateFieldName + "', '" + getDateString(thisDay) + "');\">";

    if (dayNum == day)
      html += TD_selected + TD_onclick + DIV_selected + dayNum + xDIV + xTD;
    else
      html += TD + TD_onclick + dayNum + xTD;
    
    // if this is a Saturday, start a new row
    if (thisDay.getDay() == 6)
      html += xTR + TR;
    
    // increment the day
    thisDay.setDate(thisDay.getDate() + 1);
  } while (thisDay.getDate() > 1)
  
  // fill in any trailing blanks
  if (thisDay.getDay() > 0) {
    for (i = 6; i > thisDay.getDay(); i--)
      html += TD + "&nbsp;" + xTD;
  }
  html += xTR;
  
  // add a button to allow the user to easily return to today, or close the calendar
  var today = new Date();
  var todayString = "Today is " + dayArrayMed[today.getDay()] + ", " + monthArrayMed[today.getMonth()] + " " + today.getDate();
  html += TR_todaybutton + TD_todaybutton;
  html += "<button class='calendario_botao_interno' onClick='refreshDatePicker(\"" + dateFieldName + "\");'>Mês Atual</button> ";
  html += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
  html += "<button class='calendario_botao_interno' onClick='updateDateField(\"" + dateFieldName + "\");'>Fechar</button>";
  html += xTD + xTR;
  
  // and finally, close the table
  html += xTABLE;
  
  document.getElementById(datePickerDivID).innerHTML = html;
  // add an "iFrame shim" to allow the datepicker to display above selection lists
  adjustiFrame();
}


/**
Convenience function for writing the code for the buttons that bring us back or forward
a month.
*/
function getButtonCode(dateFieldName, dateVal, adjust, label)
{
  var newMonth = (dateVal.getMonth() + adjust) % 12;
  var newYear = dateVal.getFullYear() + parseInt((dateVal.getMonth() + adjust) / 12);
  if (newMonth < 0) {
    newMonth += 12;
    newYear += -1;
  }
  
  return "<button id='btn_"+ label +"' class='calendario_botao_interno' onClick='refreshDatePicker(\"" + dateFieldName + "\", " + newYear + ", " + newMonth + ");'>" + label + "</button>";
}


/**

Convert a JavaScript Date object to a string, based on the dateFormat and dateSeparator
variables at the beginning of this script library.
*/
function getDateString(dateVal)
{
  var dayString = "00" + dateVal.getDate();
  var monthString = "00" + (dateVal.getMonth()+1);
  dayString = dayString.substring(dayString.length - 2);
  monthString = monthString.substring(monthString.length - 2);
  
  switch (dateFormat) {
    case "dmy" :
      return dayString + dateSeparator + monthString + dateSeparator + dateVal.getFullYear();
    case "ymd" :
      return dateVal.getFullYear() + dateSeparator + monthString + dateSeparator + dayString;
    case "mdy" :
    default :
      return monthString + dateSeparator + dayString + dateSeparator + dateVal.getFullYear();
  }
}


/**
Convert a string to a JavaScript Date object.
*/
function getFieldDate(dateString)
{
  var dateVal;
  var dArray;
  var d, m, y;
  
  try {
    dArray = splitDateString(dateString);
    if (dArray) {
      switch (dateFormat) {
        case "dmy" :
          d = parseInt(dArray[0], 10);
          m = parseInt(dArray[1], 10) - 1;
          y = parseInt(dArray[2], 10);
          break;
        case "ymd" :
          d = parseInt(dArray[2], 10);
          m = parseInt(dArray[1], 10) - 1;
          y = parseInt(dArray[0], 10);
          break;
        case "mdy" :
        default :
          d = parseInt(dArray[1], 10);
          m = parseInt(dArray[0], 10) - 1;
          y = parseInt(dArray[2], 10);
          break;
      }
      dateVal = new Date(y, m, d);
    } else {
      dateVal = new Date(dateString);
    }
  } catch(e) {
    dateVal = new Date();
  }
  
  return dateVal;
}


/**
Try to split a date string into an array of elements, using common date separators.
If the date is split, an array is returned; otherwise, we just return false.
*/
function splitDateString(dateString)
{
  var dArray;
  if (dateString.indexOf("/") >= 0)
    dArray = dateString.split("/");
  else if (dateString.indexOf(".") >= 0)
    dArray = dateString.split(".");
  else if (dateString.indexOf("-") >= 0)
    dArray = dateString.split("-");
  else if (dateString.indexOf("\\") >= 0)
    dArray = dateString.split("\\");
  else
    dArray = false;
  
  return dArray;
}

function updateDateField(dateFieldName, dateString)
{
  var targetDateField = document.getElementsByName(dateFieldName).item(0);
  if (dateString)
    targetDateField.value = dateString;
  document.getElementById(datePickerDivID).style.visibility = "hidden";
  adjustiFrame();
  
  // after the datepicker has closed, optionally run a user-defined function called
  // datePickerClosed, passing the field that was just updated as a parameter
  // (note that this will only run if the user actually selected a date from the datepicker)
  if ((dateString) && (typeof(datePickerClosed) == "function"))
    datePickerClosed(targetDateField);
}


/**
Use an "iFrame shim" to deal with problems where the datepicker shows up behind
selection list elements, if they're below the datepicker. The problem and solution are
described at:

http://dotnetjunkies.com/WebLog/jking/archive/2003/07/21/488.aspx
http://dotnetjunkies.com/WebLog/jking/archive/2003/10/30/2975.aspx
*/
function adjustiFrame(pickerDiv, iFrameDiv)
{
  if (!document.getElementById(iFrameDivID)) {
    // don't use innerHTML to update the body, because it can cause global variables
    // that are currently pointing to objects on the page to have bad references
    //document.body.innerHTML += "<iframe id='" + iFrameDivID + "' src='javascript:false;' scrolling='no' frameborder='0'>";
    var newNode = document.createElement("iFrame");
    newNode.setAttribute("id", iFrameDivID);
    newNode.setAttribute("src", "javascript:false;");
    newNode.setAttribute("scrolling", "no");
    newNode.setAttribute("frameborder", "0");
    document.body.appendChild(newNode);
  }
  
  if (!pickerDiv)
    pickerDiv = document.getElementById(datePickerDivID);
  if (!iFrameDiv)
    iFrameDiv = document.getElementById(iFrameDivID);
  
  try {
    iFrameDiv.style.position = "absolute";
    iFrameDiv.style.width = pickerDiv.offsetWidth;
    iFrameDiv.style.height = pickerDiv.offsetHeight;
    iFrameDiv.style.top = pickerDiv.style.top;
    iFrameDiv.style.left = pickerDiv.style.left;
    iFrameDiv.style.zIndex = pickerDiv.style.zIndex - 1;
    iFrameDiv.style.visibility = pickerDiv.style.visibility;
  } catch(e) {
  }
}


/*************************************************************************
* NOME: mascara.js                                                       *
* FUNÇÂO: Mascarar os campos dos formulários de cadastro                 *
* AUTOR: Gilnei Greco                                                    *
* DATA: 26/11/2003                                                       *
* OBS: Usar no evento onkeypress do input                                *
* Ex1:<input type=text id="cpf" name="cpf" ob="1" desc="O CPF" tipo="cpf"*
*     size="20" maxlength="14" onkeypress="return                        *
*     txtBoxFormat(document.testcad, 'cpf', '999.999.999-99', event);">  *
* EX2:<input type="text" id="fone" name="fone" ob="0" desc=""            *
*     tipo="fone" size="20" maxlength="14"                               *
*     onkeypress="return(TelefoneFormat(this,event));">                  *
*************************************************************************/

//função que dado um formato, mascara o campo unput do form
function txtBoxFormat(strField, sMask, evtKeyPress) {
	var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;
	
	var nTecla = evtKeyPress.keyCode  ? evtKeyPress.keyCode  :
		evtKeyPress.charCode ? evtKeyPress.charCode :
			evtKeyPress.which    ? evtKeyPress.which    : void 0;
	
	if (nTecla != 8 && nTecla != 9) {
		
	 if((nTecla > 47 && nTecla < 58)) {
		 
			sValue = strField.value;
			sValue = sValue.toString().replace( ":", "" );
			sValue = sValue.toString().replace( ":", "" );
			sValue = sValue.toString().replace( ":", "" );
			sValue = sValue.toString().replace( "-", "" );
			sValue = sValue.toString().replace( "-", "" );
			sValue = sValue.toString().replace( "-", "" );
			sValue = sValue.toString().replace( ".", "" );
			sValue = sValue.toString().replace( ".", "" );
			sValue = sValue.toString().replace( ".", "" );
			sValue = sValue.toString().replace( ".", "" );
			sValue = sValue.toString().replace( ".", "" );
			sValue = sValue.toString().replace( ".", "" );
			sValue = sValue.toString().replace( "/", "" );
			sValue = sValue.toString().replace( "/", "" );
			sValue = sValue.toString().replace( "(", "" );
			sValue = sValue.toString().replace( "(", "" );
			sValue = sValue.toString().replace( ")", "" );
			sValue = sValue.toString().replace( ")", "" );
			sValue = sValue.toString().replace( " ", "" );
			sValue = sValue.toString().replace( " ", "" );
			fldLen = sValue.length;
			mskLen = sMask.length;
			
			i = 0;
			nCount = 0;
			sCod = "";
			mskLen = fldLen;
			
			while (i <= mskLen) {
				bolMask = ((sMask.charAt(i) == ":") || (sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
				bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))
				if (bolMask) {
					sCod += sMask.charAt(i);
					mskLen++; 
				} else {
					sCod += sValue.charAt(nCount);
					nCount++;
				}

				i++;
			}
			
			strField.value = sCod;
			
			if (nTecla != 8) { // backspace
				if (sMask.charAt(i-1) == "9") { // apenas números...
					return ((nTecla > 47) && (nTecla < 58));  // números de 0 a 9
				} else { // qualquer caracter...
					return true;
				} 
			} else {
				//alert(nTecla);
				return true;
			}
		
	 } else {

		 if (nTecla != 8) {

			 return false;		 
		
		 } else {
			 
			sValue = strField.value;
			sValue = sValue.toString().replace( ":", "" );
			sValue = sValue.toString().replace( ":", "" );
			sValue = sValue.toString().replace( ":", "" );
			sValue = sValue.toString().replace( "-", "" );
			sValue = sValue.toString().replace( "-", "" );
			sValue = sValue.toString().replace( "-", "" );
			sValue = sValue.toString().replace( ".", "" );
			sValue = sValue.toString().replace( ".", "" );
			sValue = sValue.toString().replace( ".", "" );
			sValue = sValue.toString().replace( ".", "" );
			sValue = sValue.toString().replace( ".", "" );
			sValue = sValue.toString().replace( ".", "" );
			sValue = sValue.toString().replace( "/", "" );
			sValue = sValue.toString().replace( "/", "" );
			sValue = sValue.toString().replace( "(", "" );
			sValue = sValue.toString().replace( "(", "" );
			sValue = sValue.toString().replace( ")", "" );
			sValue = sValue.toString().replace( ")", "" );
			sValue = sValue.toString().replace( " ", "" );
			sValue = sValue.toString().replace( " ", "" );
			fldLen = sValue.length;
			mskLen = sMask.length;
			
			i = 0;
			nCount = 0;
			sCod = "";
			mskLen = fldLen;
			
			while (i <= mskLen) {
				bolMask = ((sMask.charAt(i) == ":") || (sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
				bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))
				if (bolMask) {
					sCod += sMask.charAt(i);
					mskLen++; 
				} else {
					sCod += sValue.charAt(nCount);
					nCount++;
				}

				i++;
			}
			
			strField.value = sCod;
			
			if (nTecla != 8) { // backspace
				if (sMask.charAt(i-1) == "9") { // apenas números...
					return ((nTecla > 47) && (nTecla < 58));  // números de 0 a 9
				} else { // qualquer caracter...
					return true;
				} 
			} else {
				//alert(nTecla);
				return true;
			}
			
		 }
		
	 }
	 
	}
	
}
//função que formata o campo de telefone tanto(99)999-9999 quanto (99)9999-9999   


function TelefoneFormat(Campo, e) {
	var key = '';
	var len = 0;
	var strCheck = '0123456789';
	var aux = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	
	if (whichCode == 13 || whichCode == 8 || whichCode == 0)
	{
		return true;  // Enter backspace ou FN qualquer um que não seja alfa numerico
	}
	key = String.fromCharCode(whichCode);
	if (strCheck.indexOf(key) == -1){
		return false;  //NÃO E VALIDO
	}
	
	aux =  Telefone_Remove_Format(Campo.value);
	
	len = aux.length;
	if(len>=10)
	{
		return false;	//impede de digitar um telefone maior que 10
	}
	aux += key;
	
	Campo.value = Telefone_Mont_Format(aux);
	return false;
}

function  Telefone_Mont_Format(Telefone)
{
	var aux = len = '';
	
	len = Telefone.length;
	if(len<=9)
	{
		tmp = 5;
	}
	else
	{
		tmp = 6;
	}
	
	aux = '';
	for(i = 0; i < len; i++)
	{
		if(i==0)
		{
			aux = '(';
		}
		aux += Telefone.charAt(i);
		if(i+1==2)
		{
			aux += ')';
		}
		
		if(i+1==tmp)

		{
			aux += '-';
		}
	}
	return aux ;
}

function  Telefone_Remove_Format(Telefone)
{
	var strCheck = '0123456789';
	var len = i = aux = '';
	len = Telefone.length;
	for(i = 0; i < len; i++)
	{
		if (strCheck.indexOf(Telefone.charAt(i))!=-1)
		{
			aux += Telefone.charAt(i);
		}
	}
	return aux;
}

//função que dado um formato, mascara o campo input do form (MODIFICADA PARA OUTROS BROWSERS)
function FormatBox(strField, sMask, evtKeyPress) {
    var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;
	alert('TESTE');
    if(document.layers)	   //NN4+
    {
       sValue =document.layers[strField].value;
       nTecla = evtKeyPress.which;
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(strField);
        sValue =obj.value;
        nTecla = evtKeyPress.keyCode;
    }
    else if(document.all)	// IE 4
    {
        sValue =document.all[strField].value;
        nTecla = evtKeyPress.keyCode;
    }

      sValue = sValue.toString().replace( "-", "" );
      sValue = sValue.toString().replace( "-", "" );
      sValue = sValue.toString().replace( ".", "" );
      sValue = sValue.toString().replace( ".", "" );
      sValue = sValue.toString().replace( ":", "" );
      sValue = sValue.toString().replace( ":", "" );
      sValue = sValue.toString().replace( "/", "" );
      sValue = sValue.toString().replace( "/", "" );
      sValue = sValue.toString().replace( "(", "" );
      sValue = sValue.toString().replace( "(", "" );
      sValue = sValue.toString().replace( ")", "" );
      sValue = sValue.toString().replace( ")", "" );
      sValue = sValue.toString().replace( " ", "" );
      sValue = sValue.toString().replace( " ", "" );
      fldLen = sValue.length;
      mskLen = sMask.length;

      i = 0;
      nCount = 0;
      sCod = "";
      mskLen = fldLen;

      while (i <= mskLen) {
        bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"));
        bolMask = (bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))) ;
        bolMask = (bolMask || (sMask.charAt(i) == ":")) ;
        if (bolMask) {
          sCod += sMask.charAt(i);
          mskLen++; }
        else {
          sCod += sValue.charAt(nCount);
          nCount++;
        }

        i++;
      }

    if(document.layers)	   //NN4+
    {
        document.layers[strField].value= sCod;

    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj1 = document.getElementById(strField);
        obj1.value= sCod;
    }
    else if(document.all)	// IE 4
    {
        document.all[strField].value= sCod;
    }

      if (nTecla != 8) { // backspace
        if (sMask.charAt(i-1) == "9") { // apenas números...
          return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
        else { // qualquer caracter...
          return true;
        } }
      else {
        return true;
      }
    }


// função que mostra ou oculta um DIV
// O Primeiro argumento 'szDivID' é o nome do DIV
// O segundo argumento 'iState' é o estado, 1 visivel, 0 não visivel
function veBox(szDivID) // 1 visible, 0 hidden
{
    if(document.layers)	   //NN4+
    {
       if(document.layers[szDivID].visibility == "show"){
           document.layers[szDivID].visibility = "hide";
        }else{
        document.layers[szDivID].visibility = "show";
        }
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        if(obj.style.visibility == "visible"){
           obj.style.visibility = "hidden";
        }else{
        obj.style.visibility = "visible";
        }
    }
    else if(document.all)	// IE 4
    {
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
        if(document.all[szDivID].style.visibility == "visible"){
           document.all[szDivID].style.visibility = "hidden";
        }else{
           document.all[szDivID].style.visibility = "visible";
        }
    }
}

function MostraDiv(Elemento, Indice)
{
	var DIV = document.getElementById(Elemento)
	if (DIV.innerHTML != "") {
		DIV.innerHTML = ""
	} else {
		DIV.innerHTML = Indice
	}
}

function criaOption(f,e,newValue,newText){

var objSelect=document.forms[f].elements[e];
var objOption = document.createElement("option");
objOption.text = newText
objOption.value = newValue

if(document.all && !window.opera){
  objSelect.add(objOption);
  objSelect.options[objSelect.length-1].selected=true;
  }
 else
  {objSelect.add(objOption, null);
    objSelect.options[objSelect.length-1].selected=true;};

}

function veBoxErro(szDivID,largura,altura)
{
    if(document.layers)	   //NN4+
    {
       document.layers[szDivID].top=(screen.height - altura) /2.7;
       document.layers[szDivID].left=(screen.width - largura) /2;
       document.layers[szDivID].width=largura;
       document.layers[szDivID].height=altura;
       if(document.layers[szDivID].visibility == "show"){
           document.layers[szDivID].visibility = "hide";
        }else{
        document.layers[szDivID].visibility = "show";
        }
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.style.top=(screen.height - altura) /2.7;
        obj.style.left=(screen.width - largura) /2;
        obj.style.width=largura;
        obj.style.height=altura;
        if(obj.style.visibility == "visible"){
           obj.style.visibility = "hidden";
        }else{
        obj.style.visibility = "visible";
        }
    }
    else if(document.all)	// IE 4
    {
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
        document.all[szDivID].style.top=(screen.height - altura) /2.7;
        document.all[szDivID].style.left=(screen.width - largura) /2;
        document.all[szDivID].style.width=largura;
        document.all[szDivID].style.height=altura;
        if(document.all[szDivID].style.visibility == "visible"){
           document.all[szDivID].style.visibility = "hidden";
        }else{
           document.all[szDivID].style.visibility = "visible";
        }
    }
}
	function lib_bwcheck(){ //Browsercheck (needed)
		this.ver=navigator.appVersion
		this.agent=navigator.userAgent
		this.dom=document.getElementById?1:0
		this.opera5=this.agent.indexOf("Opera 5")>-1
		this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
		this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
		this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
		this.ie=this.ie4||this.ie5||this.ie6
		this.mac=this.agent.indexOf("Mac")>-1
		this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
		this.ns4=(document.layers && !this.dom)?1:0;
		this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
		return this
	}
	var bw_cursor = new lib_bwcheck()
	
	function mostra_cursor(event, imagem, largura, altura) {
		var scrolled=bw_cursor.ns4||bw_cursor.ns6?"window.pageYOffset":"document.body.scrollTop";
		xpos=event.clientX;
		ypos=event.clientY;
		document.getElementById("iframe_movel").style.visibility="visible";
		document.getElementById("iframe_movel").style.position="absolute";
		document.getElementById("iframe_movel").style.left=xpos-160;
		document.getElementById("iframe_movel").style.top=ypos+eval(scrolled);
		document.getElementById("imagem_iframe_movel").src = imagem;
		document.getElementById("imagem_iframe_movel").width = largura;
		document.getElementById("imagem_iframe_movel").height = altura;
	}
	function esconde_cursor() {
		document.getElementById("iframe_movel").style.visibility="hidden";
	}

//VERIFICA O NÍVEL DE SEGURANÇA DE UMA SENHA
function verifica_senha(txt, alvo, label) {
	var numeros = '0123456789';
	var letras = 'abcdefghijklmnoprstuvwxz';
	var maiusculas = 'ABCDEFGHIJKLMNOPQRSTUVWXZ';
	var especiais = '!@#$%&*(){[}]?:><áéíóúàèòùãõÁÉÍÓÚÀÈÌÒÙÃÕ';
	var nota = 0;
	var ver_numeros = false;
	var ver_letras = false;
	var ver_maiusculas = false;
	var ver_especiais = false;
	var x;
	
	for (x=0;x<txt.length;x++) {
		if (numeros.indexOf(txt[x]) >= 0 && ver_numeros == false){ 
			nota++;
			ver_numeros = true;
		}
		if (letras.indexOf(txt[x]) >= 0 && ver_letras == false){ 
			nota++;
			ver_letras = true;
		}
		if (maiusculas.indexOf(txt[x]) >= 0 && ver_maiusculas == false){ 
			nota++;
			ver_maiusculas = true;
		}
		if (especiais.indexOf(txt[x]) >= 0 && ver_especiais == false){ 
			nota++;
			ver_especiais = true;
		}
	}
	if (txt.lenght >= 6) nota++;
	
	if(txt == '')
		document.getElementById(alvo).innerHTML = label;
	else if (nota == 0) 
		document.getElementById(alvo).innerHTML = '<font color="#CC0000"><b>Nível da Senha: Muito Fraca</b></font>';
	else if (nota == 1)  
		document.getElementById(alvo).innerHTML = '<font color="#FF9900"><b>Nível da Senha: Fraca</b></font>';
	else if (nota == 2)
		document.getElementById(alvo).innerHTML = '<font color="#CCCC00"><b>Nível da Senha: Regular</b></font>';
	else if (nota == 3)
		document.getElementById(alvo).innerHTML = '<font color="#0000CC"><b>Nível da Senha: Boa</b></font>';
	else if (nota >= 4)
		document.getElementById(alvo).innerHTML = '<font color="#00AA00"><b>Nível da Senha: Muito Boa</b></font>';
	
}

function verifica_senha2(senha1, senha2, alvo) {
	
	var s1 = document.getElementById(senha1).value;
	var s2 = document.getElementById(senha2).value;
	
	if (s2 == '') {
		document.getElementById(alvo).innerHTML = '';
	} else if (s1 == s2) {
		document.getElementById(alvo).innerHTML = '<font color="#00AA00"><b>Senhas Iguais</b></font>';
	} else {
		document.getElementById(alvo).innerHTML = '<font color="#AA0000"><b>Senhas Diferentes</b></font>';
	}
	
}

/*
 *  Alterações Daniel 
 *	Dia 05/04/2010  
 */

function bloqueia_campos(campo) {
	
	document.getElementById(campo).disabled = true;
	document.getElementById(campo).title = '';
	document.getElementById(campo).style.backgroundColor = '#fefefe';
	document.getElementById(campo).style.borderColor = '#eeeeee';
	
}

function libera_campos(campo1, campo2) {
	
	var Varcampo1 = document.getElementById(campo1).value;
	var Varcampo2 = document.getElementById(campo2).value;
	
	if(Varcampo1 == '') {
		
		bloqueia_campos(campo2);
		
	} else {

		document.getElementById(campo2).disabled = false;
		document.getElementById(campo2).title = 'Confirme a Senha';
		document.getElementById(campo2).style.backgroundColor = '';
		document.getElementById(campo2).style.borderColor = '';

	}
	
}


function opengaleria(object){

var url = "<iframe src='incorpar_galeria.php?id="+ object +"' frameborder='0' width='100%' height='100%' marginwidth='0' marginheight='0'></iframe>";

document.getElementById("container_galeria").style.width = 650 + "px";
document.getElementById("container_galeria").style.height = 800 + "px";

document.getElementById("container_galeria").innerHTML = url;
	
}

