// JavaScript Document
//////////////////////////////////////////////////////////////////////////////////////
//Ajax
function createXMLHTTP(){
	var ajax;
	try{
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	catch(e){
		try{
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
			alert(ajax);
		}
		catch(ex){
			try{
				ajax = new XMLHttpRequest();
			}
			catch(exc){
				 alert("Esse browser não tem recursos para uso do Ajax");
				 ajax = null;
			}
		}
		return ajax;
	}
	var arrSignatures = ["MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
	for (var i=0; i < arrSignatures.length; i++){
		try{
			var oRequest = new ActiveXObject(arrSignatures[i]);
			return oRequest;
		} 
		catch (oError){}
	}
	throw new Error("MSXML is not installed on your system.");
}

//////////////////////////////////////////////////////////////////////
//Função mask utilizada para criar máscararas para campos

function mask(o,opt){
    v_obj=o
    v_opt=opt
    setTimeout("execMask()",1)
}

function execMask(){
    v_obj.value=doMask(v_opt, v_obj.value)
}


//----------------------------------------------------------------------------------------------//

function doMask(option, value) {
	value = value.replace(/\D/g,"");
	
	switch (option) {
		case "phone": // (11) 1111-1111
			value=value.replace(/^(\d{2})(\d)/g,"($1) $2");
    		value=value.replace(/(\d{4})(\d)/,"$1-$2");
		break;
		case "vox": // 1111-11
			value=value.replace(/^(\d{4})(\d)/g,"$1-$2");
		break;
		case "hora": // 11:11
			value=value.replace(/^(\d{2})(\d)/g,"$1:$2");
		break;
		case "zipcode": // CEP: 11111-11
			value=value.replace(/^(\d{5})(\d)/g,"$1-$2");
		break;
		case "date": // 11/11/1111
			value=value.replace(/^(\d{2})(\d)/g,"$1/$2");
			value=value.replace(/(\d{2})(\d)/,"$1/$2");
		break;
		case "decimal": // ...111.111.111,11
			value = value.replace(/(\d)(\d{2})$/g, "$1,$2");
			value = value.replace(/(\d)(\d{3},\d{2})/g, "$1.$2");
			value = value.replace(/(\d)(\d{3}\.\d{3},\d{2})/g, "$1.$2");
		break;
		case "kilo": // ...1111,111
			value=value.replace(/(\d)(\d{3})$/g,"$1,$2");
		break;
		case "cpf": // 111.111.111-11
			value=value.replace(/^(\d{3})(\d)/g, "$1.$2");
			value=value.replace(/(\d{3})(\d)/, "$1.$2");
			value=value.replace(/(\d{3})(\d)/, "$1-$2");
		break;
		case "id": // RG: 11.111.111-1 || 11.111.111-x
			value=value.replace(/^(\d{2})(\d)/g, "$1.$2");
			value=value.replace(/(\d{3})(\d)/, "$1.$2");
			value=value.replace(/(\d{3})(\d|x)/, "$1-$2");
		break;
		case "cnpj": // CNPJ: 00.000.000/0000-00
			value=value.replace(/(\d)(\d{2})$/g, "$1-$2");
			value=value.replace(/(\d)(\d{4}-\d{2})/g, "$1/$2");
			value=value.replace(/(\d)(\d{3}\/\d{4}-\d{2})/g, "$1.$2");
			value=value.replace(/(\d)(\d{3}\.\d{3}\/\d{4}-\d{2})/g, "$1.$2");
		break;
	}
	return value;
}
function sanitize(obj, patt) {
	var objVal = obj.value;
	var objId = obj.id;
	var regex = new RegExp(patt, "g");
	
   objVal=objVal.replace(regex,"");  
   document.getElementById(objId).value= objVal; 
}
// Função utilizada para bloquear a digitação de caracteres que não sejam números
function noDigit( o ){
	var objVal = o.value;
	var objId = o.id;
	
    objVal=objVal.replace(/\D/g,"");  
    document.getElementById( objId ).value= objVal;  
}

//////////////////////////////////////////////////////////////////////////////////////
//Função para exibir data
var hoje = new Date();

function escreveData(){
	var NomeMes = new Array();
	NomeMes[0] = "janeiro";
	NomeMes[1] = "fevereiro";
	NomeMes[2] = "mar&ccedil;o";
	NomeMes[3] = "abril";
	NomeMes[4] = "maio";
	NomeMes[5] = "junho";
	NomeMes[6] = "julho";
	NomeMes[7] = "agosto";
	NomeMes[8] = "setembro";
	NomeMes[9] = "outubro";
	NomeMes[10] = "novembro";
	NomeMes[11] = "dezembro";
	
	var dia = hoje.getDate();
	var mes = hoje.getMonth();
	var ano = hoje.getYear();
	
	if (ano < 2000) { // Y2K Fix, Isaac Powell
		ano = ano + 1900;
	}
	if (dia < 10) {
		dia = "0" + dia;
	}
	
	return dia + " de " + NomeMes[mes] + " de " + ano;
}

function escreveDia (){
	var dias = hoje.getDay();
	var NomeDia = new Array();
	NomeDia[0] = "Domingo";
	NomeDia[1] = "Segunda-feira";
	NomeDia[2] = "Ter&ccedil;a-feira";
	NomeDia[3] = "Quarta-feira";
	NomeDia[4] = "Quinta-feira";
	NomeDia[5] = "Sexta-feira";
	NomeDia[6] = "S&aacute;bado";
	
	return NomeDia[dias];
}
//Função para exibir data
//////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////////////
//Funções Dreamweaver
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 MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//Funções Dreamweaver
//////////////////////////////////////////////////////////////////////////////////////*/

//////////////////////////////////////////////////////////////////////////////////////
///Saudação: Bom dia, tarde e noite
function escreveSaudacao(){
	var hours = hoje.getHours();
	var saudacao = "";
	if (hours >=0 && hours <12) {
		saudacao = "Bom dia"
	} else if (hours >=12 && hours <18) {
		saudacao = "Boa tarde"
	} else if (hours >=18) {
		saudacao = "Boa noite";
	}
	return saudacao;
}
///Saudação: Bom dia, tarde e noite
//////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////
///Iframe ajustável
function iframeAutoHeight(altura){
    //by Micox - elmicox.blogspot.com - elmicox.com - webly.com.br  
    if(navigator.appName.indexOf("Internet Explorer")>-1){ //ie sucks
        var func_temp = function(){
            var val_temp = altura.contentWindow.document.body.scrollHeight
            altura.style.height = val_temp + "px";
        }
        setTimeout(function() { func_temp() },100) //ie sucks
    }else{
        var val = altura.contentWindow.document.body.parentNode.offsetHeight
        altura.style.height= val + "px";
    }    
}
///Iframe ajustável
//////////////////////////////////////////////////////////////////////////////////////


$(function() { //Function executed after the page loads
	var dataExtensa = escreveDia() + ", " + escreveData();
	$("#saudacao").html(document.createTextNode(escreveSaudacao()));
	$("#date").html($.trim(dataExtensa));
	$("a[rel*=external]").attr("target", "_blank");
});


//////////////////////////////////////////////////////////////////////////////////////
//FORMS
//////////////////////////////////////////////////////////////////////////////////////
//Clear form
/*$.fn.clearForm = function() {
	return this.each(function() {
		var type = this.type, tag = this.tagName.toLowerCase();
      if (tag == 'form')
	      return $(':input',this).clearForm();
      if (type == 'text' || type == 'password' || tag == 'textarea')
			this.value = '';
      else if (type == 'checkbox' || type == 'radio')
         this.checked = false;
	   else if (tag == 'select')
         //this.selectedIndex = -1;
			this.selectedIndex = 0;
	});
};*/
//Clear form
//////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////
//Load combs ajax NOME
/*function loadCombos(url, idElm) {
	var params = $("#uf").val();
	var loadCombos = createXMLHTTP();
	//$("#"+idElm).html("Aguarde, carregando a cidade...");
   loadCombos.open("post", url, true);
   loadCombos.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   loadCombos.onreadystatechange=function(){
		if (loadCombos.readyState==4){// abaixo o texto do gerado no arquivo executa.asp e colocado no div
			$("#"+idElm).html(loadCombos.responseText);//substitui innerHTML
		}
	}
	loadCombos.send("codestado="+params);

}*/
//Load combs ajax NOME
//////////////////////////////////////////////////////////////////////////////////////
//FORMS
//////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////
///showHideSou
/*function showHideSou(param) {
	alert("param: "+param);
	alert("acessou showhidesou");
   var divMotorista = document.getElementById("Motorista");
   var divCarteiraHabilitacao = document.getElementById("CarteiraHabilitacao");

   if(param == "motoristapassageiro"){
		divMotorista.style.display = "";
		divCarteiraHabilitacao.style.display = "";
   }else if(param == "motorista"){
		divMotorista.style.display = "";
		divCarteiraHabilitacao.style.display = "";
	}
}*/
///showHideSou 
//////////////////////////////////////////////////////////////////////////////////////
