// JavaScript Document

function UseSettingPage()
{
	//vars
	this.stringUtility 	= null;
	this.param 			= null;
	this.msgDefault 	= "Por favor, ";
	
	//==================================================================================================================================

	//construct vars
	this.setParam 	= function(pr) { this.param = pr; }
	
	//==================================================================================================================================
	
	this.setAlert = function(upper, msg)
	{
		msg = this.msgDefault + msg.toString();
		msg = (upper ? msg.toUpperCase() : msg);
		
		alert(msg);	
	}

	//==================================================================================================================================

	this.setFocus = function(input)
	{
		document.getElementById(input).focus();
	}

	//==================================================================================================================================

	this.ValidateLogin = function()
	{
		var frm = this.param;
		
		if (frm.uname.value.length == 0)
		{
			this.setAlert(false, "preencha o login.");
			frm.uname.focus();
			return false;
		}
		
		if (frm.upass.value.length == 0)
		{
			this.setAlert(false, "preencha a senha.");
			frm.upass.focus();
			return false;
		}
			
		return true;
	}

	//==================================================================================================================================

	this.ValidateAddUser = function()
	{
		var frm = this.param;
		
		if (frm.nome.value.length == 0)
		{
			this.setAlert(false, "preencha o nome.");
			frm.nome.focus();
			return false;
		}
		
		if (frm.uname.value.length == 0)
		{
			this.setAlert(false, "preencha o login.");
			frm.uname.focus();
			return false;
		}
		
		if (frm.upass.value.length == 0)
		{
			this.setAlert(false, "preencha a senha.");
			frm.upass.focus();
			return false;
		}
	
		return true;
	}

	//==================================================================================================================================
	
	this.ValidateAddClient = function()
	{
		var frm = this.param;
		
		if(frm.pfpj[0].checked)
		{
			if(frm.nome.value.length == 0)
			{
				this.setAlert(false, "preencha o nome.");
				frm.nome.focus();
				return false;
			}
			
			if(frm.cpf.value.length == 0)
			{
				this.setAlert(false, "preencha o CPF.");
				frm.cpf.focus();
				return false;
			}
			else
			{
				if(!this.validaCPF(frm.cpf.value))
				{
					this.setAlert(false, "preencha corretamente o CPF");
					frm.cpf.focus();
					return false;
				}
			}
		}
		else
		{
			if(frm.razao_social.value.length == 0)
			{
				this.setAlert(false, "preencha a razão social.");
				frm.razao_social.focus();
				return false;
			}
			
			if(frm.cnpj.value.length == 0)
			{
				this.setAlert(false, "preencha o CNPJ.");
				frm.cnpj.focus();
				return false;
			}
			else
			{
				if(!this.validaCNPJ(frm.cnpj.value))
				{
					this.setAlert(false, "preencha corretamente o CNPJ");
					frm.cnpj.focus();
					return false;
				}
			}
			
			if(frm.responsavel.value.length == 0)
			{
				this.setAlert(false, "preencha o responsavel.");
				frm.responsavel.focus();
				return false;
			}
		}
		
		if(frm.endereco.value.length == 0)
		{
			this.setAlert(false, "preencha o endereço.");
			frm.endereco.focus();
			return false;
		}
		
		if(frm.bairro.value.length == 0)
		{
			this.setAlert(false, "preencha o bairro.");
			frm.bairro.focus();
			return false;
		}

		if(frm.cidade.value.length == 0)
		{
			this.setAlert(false, "preencha a cidade.");
			frm.cidade.focus();
			return false;
		}

		if(frm.estado.value.length == 0)
		{
			this.setAlert(false, "preencha o estado.");
			frm.estado.focus();
			return false;
		}
		
		if(frm.cep.value.length == 0)
		{
			this.setAlert(false, "preencha o CEP.");
			frm.cep.focus();
			return false;
		}
		else
		{
			if(frm.cep.value.length < 8)
			{
				this.setAlert(false, "o CEP deve conter 8 caracteres.");
				frm.cep.focus();
				return false;
			}
		}

		return true;
	}
	
	//==================================================================================================================================
	
	this.ViewContract = function(string, el)
	{
		var aArray = string.split("@@");
		var optionName = el.options[el.selectedIndex].text;
		
		
		
		switch(aArray[0])
		{
			case("clientes"):
			
				//***********************************************************************
				var conteudo = document.getElementById("contract-Clientes").value;
				
				if(document.getElementById("modelCLi").value == "")
				{
					document.getElementById("modelCLi").value = conteudo;
				}
				else
				{
					conteudo = document.getElementById("modelCLi").value;
				}
				
				for(var a = 0; a < conteudo.length; a++)
				{
					conteudo = conteudo.replace("<NOME_CONTRATANTE>", optionName);
				}
				document.getElementById("contract-Clientes").value = conteudo;
				document.getElementById("contract-Clientes___Frame").src = "../../resource/classes/class.fckeditor/editor/fckeditor.html?InstanceName=contract-Clientes&amp;Toolbar=Basic";
				//***********************************************************************
				
				document.getElementById("clientes").style.display = "block";
				document.getElementById("profissionais").style.display = "none";
			break;
			case("profissionais"):
			
				//***********************************************************************
				var conteudo = document.getElementById("contract-Profissionais").value;
				
				if(document.getElementById("modelProf").value == "")
				{
					document.getElementById("modelProf").value = conteudo;
				}
				else
				{
					conteudo = document.getElementById("modelProf").value;
				}
				
				for(var a = 0; a < conteudo.length; a++)
				{
					conteudo = conteudo.replace("<NOME_CONTRATANTE>", optionName);
				}
				document.getElementById("contract-Profissionais").value = conteudo;
				document.getElementById("contract-Profissionais___Frame").src = "../../resource/classes/class.fckeditor/editor/fckeditor.html?InstanceName=contract-Profissionais&amp;Toolbar=Basic";
				//***********************************************************************
				
				document.getElementById("clientes").style.display = "none";
				document.getElementById("profissionais").style.display = "block";
			break;
		}
	}
	
	//==================================================================================================================================
	
	this.ViewEtiqueta = function(bool)
	{
		if(bool)
		{
			var browserName = navigator.appName; 
			
			document.getElementById("overFlowPDF").style.display = "block";
			
			if(browserName.indexOf("Microsoft") == -1)
			{
				document.getElementById("centerContent").style.width 		= "740px";
				document.getElementById("centerContent").style.height 		= "549px";
				document.getElementById("centerContent").style.marginTop 	= "-274px";
				document.getElementById("centerContent").style.marginLeft 	= "-370px";
			}
			else
			{
				document.getElementById("centerContent").style.width 		= "740px";
				document.getElementById("centerContent").style.height 		= "549px";
				document.getElementById("centerContent").style.marginTop 	= "-274px";
				document.getElementById("centerContent").style.marginLeft 	= "-370px";
			}
		}
	}
	
	//==================================================================================================================================
	
	this.ValidateFornecedor = function()
	{
		var frm = this.param;
		
		if(frm.nome.value.length == 0)
		{
			this.setAlert(false, "preencha o nome.");
			frm.nome.focus();
			return false;
		}

		/*
		if(frm.cpf.value.length == 0)
		{
			this.setAlert(false, "preencha o CPF.");
			frm.cpf.focus();
			return false;
		}
		else
		{
			if(!this.validaCPF(frm.cpf.value))
			{
				this.setAlert(false, "preencha corretamente o CPF");
				frm.cpf.focus();
				return false;
			}
		}
		
		if(frm.data_nascimento.value.length == 0)
		{
			this.setAlert(false, "preencha a data de nascimento.");
			frm.data_nascimento.focus();
			return false;
		}
		*/
		
		/*
		if(frm.rg.value.length == 0)
		{
			this.setAlert(false, "preencha o RG.");
			frm.rg.focus();
			return false;
		}
		
		*/
		
		/*
		if(frm.cep.value.length == 0)
		{
			this.setAlert(false, "preencha o CEP.");
			frm.cep.focus();
			return false;
		}
		else
		{
			if(frm.cep.value.length < 8)
			{
				this.setAlert(false, "o CEP deve conter 8 caracteres.");
				frm.cep.focus();
				return false;
			}
		}
		*/
		
		/*
		if(frm.endereco.value.length == 0)
		{
			this.setAlert(false, "preencha o endereço.");
			frm.endereco.focus();
			return false;
		}

		if(frm.complemento.value.length == 0)
		{
			this.setAlert(false, "preencha o complemento.");
			frm.complemento.focus();
			return false;
		}

		if(frm.numero_complemento.value.length == 0)
		{
			this.setAlert(false, "preencha o numero do complemento.");
			frm.numero_complemento.focus();
			return false;
		}

		if(frm.bairro.value.length == 0)
		{
			this.setAlert(false, "preencha o bairro.");
			frm.bairro.focus();
			return false;
		}

		if(frm.cidade.value.length == 0)
		{
			this.setAlert(false, "preencha a cidade.");
			frm.cidade.focus();
			return false;
		}
		*/

		if(frm.telefone_1.value.length == 0)
		{
			this.setAlert(false, "preencha o telefone 1.");
			frm.telefone_1.focus();
			return false;
		}
		
		/*
		if(frm.telefone_2.value.length == 0)
		{
			this.setAlert(false, "preencha o telefone 2.");
			frm.telefone_2.focus();
			return false;
		}
		*/
		
		/*
		if(frm.celular.value.length == 0)
		{
			this.setAlert(false, "preencha o celular.");
			frm.celular.focus();
			return false;
		}
		*/

		if(frm.email.value.length == 0)
		{
			this.setAlert(false, "preencha o e-mail.");
			frm.email.focus();
			return false;
		}
		
		/*
		if(frm.drt.value.length == 0)
		{
			this.setAlert(false, "preencha o DRT.");
			frm.drt.focus();
			return false;
		}
		
		if(frm.obs.value.length == 0)
		{
			this.setAlert(false, "preencha as observações.");
			frm.obs.focus();
			return false;
		}
		*/
		
		/*
		if(frm.altura.value.length == 0)
		{
			this.setAlert(false, "preencha a altura.");
			frm.altura.focus();
			return false;
		}

		if(frm.busto.value.length == 0)
		{
			this.setAlert(false, "preencha o busto.");
			frm.busto.focus();
			return false;
		}

		if(frm.cintura.value.length == 0)
		{
			this.setAlert(false, "preencha a cintura.");
			frm.cintura.focus();
			return false;
		}

		if(frm.sapato.value.length == 0)
		{
			this.setAlert(false, "preencha o sapato.");
			frm.sapato.focus();
			return false;
		}

		if(frm.quadril.value.length == 0)
		{
			this.setAlert(false, "preencha o quadril.");
			frm.quadril.focus();
			return false;
		}

		/*
		if(frm.cabelos.value.length == 0)
		{
			this.setAlert(false, "preencha o cabelo.");
			frm.cabelos.focus();
			return false;
		}

		if(frm.idioma.value.length == 0)
		{
			this.setAlert(false, "preencha o idioma.");
			frm.idioma.focus();
			return false;
		}

		if(frm.manequim.value.length == 0)
		{
			this.setAlert(false, "preencha o manequim.");
			frm.manequim.focus();
			return false;
		}
		*/

		return true;
	}

	//==================================================================================================================================

	this.ValidateFornecedor2 = function()
	{
		var frm = this.param;
		
		if(frm.nome.value.length == 0)
		{
			this.setAlert(false, "preencha o nome.");
			frm.nome.focus();
			return false;
		}

		if(frm.cpf.value.length == 0)
		{
			this.setAlert(false, "preencha o CPF.");
			frm.cpf.focus();
			return false;
		}
		else
		{
			if(!this.validaCPF(frm.cpf.value))
			{
				this.setAlert(false, "preencha corretamente o CPF");
				frm.cpf.focus();
				return false;
			}
		}
		
		if(frm.data_nascimento.value.length == 0)
		{
			this.setAlert(false, "preencha a data de nascimento.");
			frm.data_nascimento.focus();
			return false;
		}
		
		/*
		if(frm.rg.value.length == 0)
		{
			this.setAlert(false, "preencha o RG.");
			frm.rg.focus();
			return false;
		}
		
		*/
		
		if(frm.cep.value.length == 0)
		{
			this.setAlert(false, "preencha o CEP.");
			frm.cep.focus();
			return false;
		}
		else
		{
			if(frm.cep.value.length < 8)
			{
				this.setAlert(false, "o CEP deve conter 8 caracteres.");
				frm.cep.focus();
				return false;
			}
		}
		
		if(frm.endereco.value.length == 0)
		{
			this.setAlert(false, "preencha o endereço.");
			frm.endereco.focus();
			return false;
		}

		if(frm.complemento.value.length == 0)
		{
			this.setAlert(false, "preencha o complemento.");
			frm.complemento.focus();
			return false;
		}

		if(frm.numero_complemento.value.length == 0)
		{
			this.setAlert(false, "preencha o numero do complemento.");
			frm.numero_complemento.focus();
			return false;
		}

		if(frm.bairro.value.length == 0)
		{
			this.setAlert(false, "preencha o bairro.");
			frm.bairro.focus();
			return false;
		}

		if(frm.cidade.value.length == 0)
		{
			this.setAlert(false, "preencha a cidade.");
			frm.cidade.focus();
			return false;
		}

		if(frm.telefone_1.value.length == 0)
		{
			this.setAlert(false, "preencha o telefone 1.");
			frm.telefone_1.focus();
			return false;
		}
		
		/*
		if(frm.telefone_2.value.length == 0)
		{
			this.setAlert(false, "preencha o telefone 2.");
			frm.telefone_2.focus();
			return false;
		}
		*/

		if(frm.celular.value.length == 0)
		{
			this.setAlert(false, "preencha o celular.");
			frm.celular.focus();
			return false;
		}

		if(frm.email.value.length == 0)
		{
			this.setAlert(false, "preencha o e-mail.");
			frm.email.focus();
			return false;
		}
		
		/*
		if(frm.drt.value.length == 0)
		{
			this.setAlert(false, "preencha o DRT.");
			frm.drt.focus();
			return false;
		}
		
		if(frm.obs.value.length == 0)
		{
			this.setAlert(false, "preencha as observações.");
			frm.obs.focus();
			return false;
		}
		*/

		if(frm.altura.value.length == 0)
		{
			this.setAlert(false, "preencha a altura.");
			frm.altura.focus();
			return false;
		}

		if(frm.busto.value.length == 0)
		{
			this.setAlert(false, "preencha o busto.");
			frm.busto.focus();
			return false;
		}

		if(frm.cintura.value.length == 0)
		{
			this.setAlert(false, "preencha a cintura.");
			frm.cintura.focus();
			return false;
		}

		if(frm.sapato.value.length == 0)
		{
			this.setAlert(false, "preencha o sapato.");
			frm.sapato.focus();
			return false;
		}

		if(frm.quadril.value.length == 0)
		{
			this.setAlert(false, "preencha o quadril.");
			frm.quadril.focus();
			return false;
		}

		/*
		if(frm.cabelos.value.length == 0)
		{
			this.setAlert(false, "preencha o cabelo.");
			frm.cabelos.focus();
			return false;
		}
		*/

		if(frm.idioma.value.length == 0)
		{
			this.setAlert(false, "preencha o idioma.");
			frm.idioma.focus();
			return false;
		}

		if(frm.manequim.value.length == 0)
		{
			this.setAlert(false, "preencha o manequim.");
			frm.manequim.focus();
			return false;
		}
		
		document.getElementById("formulario").style.display = "none";
		document.getElementById("msg").style.display = "block";

		return true;
	}

	//==================================================================================================================================
	
	this.ValidateNews = function()
	{
		var frm = this.param;
		
		if(frm.title_news.value.length == 0)
		{
			this.setAlert(false, "preencha o titulo da notícia.");
			frm.title_news.focus();
			return false;
		}
		
		if(frm.date_news.value.length == 0)
		{
			this.setAlert(false, "preencha a data de publicação.");
			frm.date_news.focus();
			return false;
		}

		if(frm.description_news.value.length == 0)
		{
			this.setAlert(false, "preencha a notícia.");
			frm.description_news.focus();
			return false;
		}
		
		return true;
	}
	
	//==================================================================================================================================

	this.ValidateCasting = function(form)
	{
		var count = 0;
		var frm	  = form;
		
		for(var a = 0; a < frm.length; a++)
		{
			if(frm[a].name.indexOf("profissionais[]") > -1)
			{
				if(frm[a].checked)
				{
					count++;
				}
			}
		}
		
		if(count === 0)
		{
			//*** ALERT
			this.setAlert(false, "selecione um item para gerar um casting.");
			
			return false;
		}
		
		return true;
	}
	
	//==================================================================================================================================
	
	this.ValidateSendCasting = function(form)
	{
		if(form.email.value.length == 0)
		{
			this.setAlert(false, "preencha o e-mail.");
			form.email.focus();
			return false;
		}
		else
		{
			if(!(this.IsMail(form.email.value)))
			{
				this.setAlert(false, "preencha o e-mail corretamente.");
				form.email.focus();
				return false;
			}
		}
		
		return true;
	}
	
	//==================================================================================================================================
	
	this.ValidateClient = function()
	{
		var frm = this.param;
		
		if(frm.nome_fantasia.value.length == 0)
		{			
			this.setAlert(false, "preencha o nome fantasia.");
			frm.nome_fantasia.focus();
			return false;
		}

		if(frm.contato.value.length == 0)
		{			
			this.setAlert(false, "preencha o contato.");
			frm.contato.focus();
			return false;
		}
		
		if(frm.telefone_1.value.length == 0)
		{			
			this.setAlert(false, "preencha o telefone.");
			frm.telefone_1.focus();
			return false;
		}
		
		/*
		if(frm.razao_social.value.length == 0)
		{			
			this.setAlert(false, "preencha a Razão Social.");
			frm.razao_social.focus();
			return false;
		}

		if(frm.contato.value.length == 0)
		{			
			this.setAlert(false, "preencha o contato.");
			frm.contato.focus();
			return false;
		}

		if(frm.data_nascimento.value.length == 0)
		{			
			this.setAlert(false, "preencha a data de Nascimento.");
			frm.data_nascimento.focus();
			return false;
		}

		if(frm.cnpj.value.length == 0)
		{			
			this.setAlert(false, "preencha o CNPJ.");
			frm.cnpj.focus();
			return false;
		}
		else
		{
			if(!this.validaCNPJ(frm.cnpj.value))
			{
				this.setAlert(false, "preencha corretamente o CNPJ.");
				frm.cnpj.focus();
				return false;
			}
		}

		if(frm.endereco.value.length == 0)
		{			
			this.setAlert(false, "preencha o endereço.");
			frm.endereco.focus();
			return false;
		}

		if(frm.complemento.value.length == 0)
		{			
			this.setAlert(false, "preencha o complemento.");
			frm.complemento.focus();
			return false;
		}
		
		if(frm.bairro.value.length == 0)
		{			
			this.setAlert(false, "preencha o bairro.");
			frm.bairro.focus();
			return false;
		}
		
		if(frm.cidade.value.length == 0)
		{
			this.setAlert(false, "preencha a cidade.");
			frm.cidade.focus();
			return false;
		}

		if(frm.email.value.length == 0)
		{
			this.setAlert(false, "preencha o e-mail.");
			frm.email.focus();
			return false;
		}
		else
		{
			if(!(this.IsMail(frm.email.value)))
			{
				this.setAlert(false, "preencha o e-mail corretamente.");
				frm.email.focus();
				return false;
			}
		}

		if(frm.senha.value.length == 0)
		{
			this.setAlert(false, "preencha a senha.");
			frm.senha.focus();
			return false;
		}
		*/
		
		return true;
	}
	
	//==================================================================================================================================
	
	this.ViewNewModelo = function(input)
	{
		if(input.checked)
		{
			document.getElementById("modelosID").disabled = true;
			document.getElementById("newModelo").disabled = false;
		}
		else
		{
			document.getElementById("modelosID").disabled = false;
			document.getElementById("newModelo").disabled = true;
		}
	}
	
	//==================================================================================================================================
	
	this.ViewElement = function(element)
	{
		var iHeight  = 0;
		var oElement = document.getElementById(element);
		
		$(document).ready
		(
			function()
			{
				$("#" + element).animate
				(
					{height: ((oElement.style.height == "250px") ? 0 : 250)}, 700
				);
			}
		);
	}
	
	//==================================================================================================================================
	
	this.AlterPhotoCasting = function(source, id)
	{
		if(source.length > 0)
		{
			var url 	= "http://www.mktworld.com.br/";
			var aValues = source.split("[@@]");
			
			document.getElementById(aValues[0]).src 	= "../../../" + aValues[1].toString();
			document.getElementById(aValues[0]).width 	= 140;
			document.getElementById(aValues[0]).height 	= 135;
			
			if(aValues[0].indexOf("onePhoto_") > -1)
			{
				document.getElementById("image1_" + id.toString()).value = url + aValues[1].toString();
			}
	
			if(aValues[0].indexOf("twoPhoto_") > -1)
			{
				document.getElementById("image2_" + id.toString()).value = url + aValues[1].toString();
			}
			
			if(aValues[0].indexOf("threePhoto_") > -1)
			{
				document.getElementById("image3_" + id.toString()).value = url + aValues[1].toString();
			}
		}
	}
	
	//==================================================================================================================================
	
	this.IsMail = function(elm)
	{
		//*** REGULAR EXPRESSION
		var sRegExp = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
		
		//*** RETURN
		return sRegExp.test(elm);
	}	
	
	//==================================================================================================================================

	this.NotChars = function(event)
	{
	    if (window.event) 
		{
	        //ie
	        key = event.keyCode;
	    } 
		else if (event.which) 
		{
	        //netscape
	        key = event.which;
	    }
	    
		if (key != 8 || key != 13 || key < 48 || key > 57)
		{
	        return ( ( ( key > 47 ) && ( key < 58 ) ) || ( key == 8 ) || ( key == 13 ) );
  		}
	        
	    return true;
	}

	//==================================================================================================================================

	this.CompleteAjaxLoadPage = function(DivLinked, ContentForAjax)
	{
		if (!ContentForAjax)
		{
			document.getElementById(DivLinked).innerHTML = "";
		}
		else
		{
			document.getElementById(DivLinked).innerHTML =  ContentForAjax;
		}
	}

	//==================================================================================================================================
	
	this.RedirectConfirm = function(msg, url)
	{
		if(window.confirm(msg.toUpperCase()))
		{
			window.location.href = url;
		}
		else
		{
			return false;
		}
	}
	
	//==================================================================================================================================

	this.AjaxLodPage = function(Div, Message, LoadPage)
	{
		if (LoadPage.length != 0)
		{
			//new ajax Object
			var ajax = new Ajax();
			
			//Linked menssage in Div
			this.CompleteAjaxLoadPage(Div, Message);
			
			//set content in Ajax Object.Method
			ajax.set_receive_handler
			( 
				function(load)
				{
					if (!load)
					{
						document.getElementById(Div).style.color = "#0000ff";
						document.getElementById(Div).innerHTML = "Opss, ocorreu um erro. Contate o Administrador do sistema.<br><br>";
					}
					else
					{
						document.getElementById(Div).innerHTML =  load;
					}
				}
			);
			
			//send for ajax
			ajax.send(LoadPage); 
		}
		else
		{
			//Linked menssage in Div
			this.CompleteAjaxLoadPage(Div, null);
	
		}
	}

	//==================================================================================================================================

	this.TipoCadastro = function(bool)
	{
		var none 	= "none";
		var block 	= "block";
		
		if(bool)
		{
			//PJ ***************************************************************************
			document.getElementById("razao_social_li").style.display 		= block;
			document.getElementById("razao_social_liInput").style.display 	= block;
			document.getElementById("resposavel_li").style.display 			= block;
			document.getElementById("resposavel_liInput").style.display 	= block;
			document.getElementById("cnpj_li").style.display 				= block;
			document.getElementById("cnpj_liInput").style.display 			= block;
			
			//*** DISPLAY INPUT
			document.getElementById("razao_social").disabled 			= false;
			document.getElementById("responsavel").disabled 			= false;
			document.getElementById("cnpj").disabled 					= false;
			
			//PF ***************************************************************************
			document.getElementById("nome_li").style.display 		= none;
			document.getElementById("nome_liInput").style.display 	= none;
			document.getElementById("cpf_li").style.display 		= none;
			document.getElementById("cpf_liInput").style.display 	= none;
			
			//*** DISPLAY INPUT
			document.getElementById("nome").disabled 				= true;
			document.getElementById("cpf").disabled 				= true;
		}
		else
		{
			//PF ***************************************************************************
			document.getElementById("nome_li").style.display 		= block;
			document.getElementById("nome_liInput").style.display 	= block;
			document.getElementById("cpf_li").style.display 		= block;
			document.getElementById("cpf_liInput").style.display 	= block;
			
			//*** DISPLAY INPUT
			document.getElementById("nome").disabled 				= false;
			document.getElementById("cpf").disabled 				= false;
			
			//PJ ***************************************************************************
			document.getElementById("razao_social_li").style.display 		= none;
			document.getElementById("razao_social_liInput").style.display 	= none;
			document.getElementById("resposavel_li").style.display 			= none;
			document.getElementById("resposavel_liInput").style.display 	= none;
			document.getElementById("cnpj_li").style.display 				= none;
			document.getElementById("cnpj_liInput").style.display 			= none;
			
			//*** DISPLAY INPUT
			document.getElementById("responsavel").disabled 			= true;
			document.getElementById("cnpj").disabled 					= true;
			document.getElementById("razao_social").disabled			= true;
		}
	}
	
	
	//==================================================================================================================================

	this.validaCNPJ = function(form)
	{
		//VALIDACAO CNPJ -> OS PARAMETOS DEVEM CONTER (".","-","/") PARA VALIDACAO
		CNPJ = form;
		erro = new String;
		 if (CNPJ.length < 14) erro += "É necessario preencher corretamente o número do CNPJ! \n\n"; 
		 if (CNPJ.length > 14) erro += "É necessario preencher corretamente o número do CNPJ! \n\n"; 
		
		// if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")) {
		 //if (erro.length == 0) erro += "É necessário preencher corretamente o número do CNPJ! \n\n";
		 //}
		 
			//substituir os caracteres que não são números
			if(document.layers && parseInt(navigator.appVersion) == 4){
				x = CNPJ.substring(0,2);
				x += CNPJ. substring (3,6);
				x += CNPJ. substring (7,10);
				x += CNPJ. substring (11,15);
				x += CNPJ. substring (16,18);
				CNPJ = x;
			} else {
				CNPJ = CNPJ. replace (".","");
				CNPJ = CNPJ. replace (".","");
				CNPJ = CNPJ. replace ("-","");
				CNPJ = CNPJ. replace ("/","");
			}
			var nonNumbers = /\D/;
			if (nonNumbers.test(CNPJ)) erro += "A verificação de CNPJ suporta apenas números! \n\n"; 
			var a = [];
			var b = new Number;
			var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
			for (i=0; i<12; i++){
				   a[i] = CNPJ.charAt(i);
				   b += a[i] * c[i+1];
			}
			if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
	
			b = 0;
			for (y=0; y<13; y++) {
				   b += (a[y] * c[y]); 
			}
	
			if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
	
			if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])){
				   erro +="Dígito verificador com problema!";
			}
	
			if (erro.length > 0)
			{
				return false;
			} 
			else 
			{
				return true;
			}
	}

	//==================================================================================================================================
	
	this.validaCPF = function(form)
	{
		//CPF VALIDAÇÃO
		cpf = form;
		erro = new String;
		 if (cpf.length < 11) erro += "Sao necessarios 11 digitos para verificacao do CPF! \n\n"; 
		 var nonNumbers = /\D/;
		 if (nonNumbers.test(cpf)) erro += "A verificacao de CPF suporta apenas numeros! \n\n"; 
		 if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
				 erro += "Numero de CPF invalido!"
	   }
	   
	   var a = [];
	   var b = new Number;
	   var c = 11;
	   for (i=0; i<11; i++)
	   {
			   a[i] = cpf.charAt(i);
			   if (i < 9) b += (a[i] * --c);
	   }
	   
	   if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
	   b = 0;
	   c = 11;
	   for (y=0; y<10; y++) b += (a[y] * c--); 
	   if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
	   if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
			   erro +="Digito verificador com problema!";
	   }
	   
	   if (erro.length > 0)
	   {
		 return false;
	   }
	   else
	   {
		 return true;
	   }
	}
	
	//==================================================================================================================================
	
	this.JumpChage = function(url)
	{
		window.location.href = url;
	}
	
	//==================================================================================================================================
	
	this.Masks = function(tipo, campo, teclaPress)
	{
		if (window.event)
		{
			var tecla = teclaPress.keyCode;
		}
		else
		{
			var tecla = teclaPress.which;
		}
	
		
		var s = new String(campo.value);
		
		// Remove todos os caracteres à seguir: ( ) / - . e espaço, para tratar a string denovo.
		s = s.replace(/(\.|\(|\)|\/|\-| )+/g,'');
	
		tam = s.length + 1;
	
		if ( tecla != 9 && tecla != 8 )
		{
			switch (tipo)
			{
			
				case 'CPF' :
					if (tam > 3 && tam < 7)
						campo.value = s.substr(0,3) + '.' + s.substr(3, tam);
					if (tam >= 7 && tam < 10)
						campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,tam-6);
					if (tam >= 10 && tam < 12)
						campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,3) + '-' + s.substr(9,tam-9);
				break;
	
				case 'CNPJ' :
		
					if (tam > 2 && tam < 6)
						campo.value = s.substr(0,2) + '.' + s.substr(2, tam);
					if (tam >= 6 && tam < 9)
						campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,tam-5);
					if (tam >= 9 && tam < 13)
						campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,tam-8);
					if (tam >= 13 && tam < 15)
						campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,4)+ '-' + s.substr(12,tam-12);
				break;
	
				case 'TEL' :
					if (tam > 2 && tam < 4)
						campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,tam);
					if (tam >= 7 && tam < 11)
						campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,4) + '-' + s.substr(6,tam-6);
				break;
	
				case 'DATE' :
					if (tam > 2 && tam < 4)
						campo.value = s.substr(0,2) + '/' + s.substr(2, tam);
					if (tam > 4 && tam < 11)
						campo.value = s.substr(0,2) + '/' + s.substr(2,2) + '/' + s.substr(4,tam-4);
				break;
			
				case 'CEP' :
					if (tam > 5 && tam < 7)
						campo.value = s.substr(0,5) + '-' + s.substr(5, tam);
				break;
				
			}
		}
	}
	
	//==================================================================================================================================
	
	this.stripCharsNotInBag = function(bag, campo)
	{
		//*** LEGEND => bag = "0123456789";
		var temp="";
		
		if (campo == null) { temp = this; }
		if (campo != null) { temp = campo.value; }
	
		var result = "";
		
		for(i = 0; i < temp.length; i++)
		{
			character = temp.charAt(i);
			
			if (bag.indexOf(character) != -1)
			{
				result += character;
			}
		}
		
		if ((campo != null) && (campo.value != result))
		{
			campo.value=result;
		}
		
		return result;
	}
	
	//==================================================================================================================================
	
	this.ValueRealNumber = function(campo, decimal)
	{
		//*** CAL CLASS stripChars
		String.prototype.stripCharsNotInBag = this.stripCharsNotInBag;
		
		//*** DEFAULT DECIMAL
		var decimalNum = 2;
	
		//*** SELECT DECIMAL
		if (decimal != null) { decimalNum = decimal; }
	
		//*** CONFIG DECIMAL => CALL FORMAT.NUMBER
		var temp = FormatNumber((campo.value.stripCharsNotInBag("0123456789") / Math.pow(10, decimalNum)), decimalNum, true, false, true);
	
		//*** RETURN VALUE FORMAT
		if (campo.value != temp) { campo.value = temp; }
	}
	
	//==================================================================================================================================
	
	this.FormatNumber = function(num, decimalNum, bolLeadingZero, bolParens, bolCommas)
	{
		//*** IS NUMBER
        if(isNaN(parseInt(num))) { return "NaN"; }
	
		//*** REQUEST NUMBER
		var tmpNum = num;

		//*** GET SIGN OF NUMBER
		var iSign = (num < 0 ? -1 : 1);
	
		//*** ADJUST NUMBER
		tmpNum  *= Math.pow(10, decimalNum);
		tmpNum 	 = Math.round(Math.abs(tmpNum))
		tmpNum 	/= Math.pow(10,decimalNum);
		
		//*** READJUST FOR SIGN
		tmpNum 	*= iSign;
	
		//*** CREATE STRING
		var tmpNumStr = new String(tmpNum);
	
		// SEE IF WE NEED TO STRIP OUT THE LEADING ZERO OR NOT.
		if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
		{
			if (num > 0)
			{
				tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
			}
			else
			{
				tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
			}
		}

		tmpNumStr = tmpNumStr.replace(/\./g,",");
	
		// Complete all decimal places
		if (decimalNum > 0) 
		{
			var iStart = tmpNumStr.indexOf(",");
			
			if (iStart < 0)
			{
				tmpNumStr += ",";
				iStart = tmpNumStr.indexOf(",");
			}
	
			for (i = (decimalNum - (tmpNumStr.length - iStart)); i >= 0; i--) 
			{
				tmpNumStr += "0";
			}
		}
	
		// See if we need to put in the commas
		if (bolCommas && (num >= 1000 || num <= -1000)) 
		{
			var iStart = tmpNumStr.indexOf(",");
			
			if (iStart < 0)
			{
				iStart = tmpNumStr.length;
			}
	
			iStart -= 3;
			while (iStart >= 1) 
			{
				tmpNumStr = tmpNumStr.substring(0,iStart) + "." + tmpNumStr.substring(iStart,tmpNumStr.length);
				iStart -= 3;
			}
		}
	
		// See if we need to use parenthesis
		if (bolParens && num < 0)
		{
			tmpNumStr = "(" + tmpNumStr.substring(1, tmpNumStr.length) + ")";
		}
	
		// Return our formatted string!
		return tmpNumStr;
	}
	
	//==================================================================================================================================
	
	this.BlockNoneElement = function(div, type)
	{
		if(type)
		{
			document.getElementById(div).style.display = "block";
		}
		else
		{
			document.getElementById(div).style.display = "none";
		}
	}
}

