﻿// JavaScript Document
//
// Company: Simple Brasil
// Author: Nicholas Sales
//
// -----------------------------------------------------------------------------------------
/*
Instructions:

retrieveData(divName, requestURL, requestMethod, requestAsynchronous, requestData)

string divName: DIV name to put contents.
string requestURL: server URL to request data
string requestMethod: 'POST' or 'GET', request method.
boolean requestAsynchronous: asyncronous(true) or syncronous (false) request.
string requestData: request parameters pairs (key=value format).
*/
//
function retrieveData(divName, requestURL, requestMethod, requestAsynchronous, requestData) {
	//
	http_request = false;
	/*
	begin of checking browser compatibility
	*/ 
	// Mozilla, Firefox, SeaMonkey, Safari
	if (window.XMLHttpRequest) {
		http_request = new XMLHttpRequest();
		// force response header as text/xml
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	// Internet Explorer
	} else if (window.ActiveXObject) {
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP") // Versão 6
		} catch(e) {
			try	{
				http_request = new ActiveXObject('Microsoft.XMLHTTP')  // Versão 5.5
			} catch(e) {
				//
			}
		}
	}
	/*
	end of browser compatibility
	*/
	document.body.style.cursor = "wait";
	http_request.open(requestMethod, requestURL, requestAsynchronous);
	http_request.onreadystatechange = function() {
		if (http_request.readyState == 4){
		    document.body.style.cursor = "auto";
		    
			var texto = http_request.responseText;
			texto = texto.replace(/\+/g," ");
			texto = unescape(texto);
			var conteudo = document.getElementById(divName);
			conteudo.innerHTML = texto;
		}
	}
	http_request.send(requestData);
}

var http_request2 = null;

function retrieveData2(requestURL, requestMethod, requestAsynchronous, requestData, funcionResult) {
	//
	http_request2 = null;
	/*
	begin of checking browser compatibility
	*/ 
	// Mozilla, Firefox, SeaMonkey, Safari
	if (window.XMLHttpRequest) {
		http_request2 = new XMLHttpRequest();
		// force response header as text/xml
		if (http_request2.overrideMimeType) {
			http_request2.overrideMimeType('text/xml');
		}
	// Internet Explorer
	} else if (window.ActiveXObject) {
		try {
			http_request2 = new ActiveXObject("Msxml2.XMLHTTP") // Versão 6
		} catch(e) {
			try	{
				http_request2 = new ActiveXObject('Microsoft.XMLHTTP')  // Versão 5.5
			} catch(e) {
				//
			}
		}
	}
	/*
	end of browser compatibility
	*/
	document.body.style.cursor = "wait";
	http_request2.open(requestMethod, requestURL, requestAsynchronous);
	http_request2.onreadystatechange = funcionResult;
	http_request2.send(requestData);
}

function js_KeyDown(e) {
	if (window.Event)
		return;

	event.returnValue = false
}

function js_Cut() {
	event.returnValue = false;
}

function js_Paste() {
	event.returnValue = false;
}

function js_BeforeFocus() {
	event.returnValue = false;
}

function js_Select() {
	event.returnValue = false;
}

function js_KeyPressed(e) {
	if (window.Event)
		return;

	event.returnValue = false
}

//
// -----------------------------------------------------------------------------------------
/*
 begin of tab checking functions
*/
VerifiqueTAB=true;
//
function Mostra(quem, tammax) {
	if ((quem.value.length == tammax) && (VerifiqueTAB)) {
		var i = 0, j = 0, indice = -1;
		for (i = 0; i < document.forms.length; i++) {
			for (j = 0; j < document.forms[i].elements.length; j++) {
				if (document.forms[i].elements[j].name == quem.name) {
					indice = i;
					break;
				}
			}
		if (indice != -1) break;
		}
		for (i = 0; i <= document.forms[indice].elements.length; i++) {
			if (document.forms[indice].elements[i].name == quem.name) {
				while ((document.forms[indice].elements[(i+1)].type == "hidden") &&	(i < document.forms[indice].elements.length)) {
					i++;
				}
				document.forms[indice].elements[(i+1)].focus();
				VerifiqueTAB=false;
				break;
			}
		}
	}
}
//
function PararTAB(quem) { VerifiqueTAB = false; }
//
function ChecarTAB() { VerifiqueTAB = true; }
//
//
/*
end of tab checking functions
*/
// -----------------------------------------------------------------------------------------
//
function Mascara(formato, keypress, objeto) {
	campo = objeto;
	//
	// CEP
	if (formato == 'cep') {
		separador = '-';
		conjunto1 = 5;
		if (campo.value.length == conjunto1) campo.value = campo.value + separador;
	}
	//
	// CPF
	if (formato == 'cpf') {
		separador1 = '.'; 
		separador2 = '-'; 
		conjunto1 = 3;
		conjunto2 = 7;
		conjunto3 = 11;
		if (campo.value.length == conjunto1) campo.value = campo.value + separador1;
		if (campo.value.length == conjunto2) campo.value = campo.value + separador1;
		if (campo.value.length == conjunto3) campo.value = campo.value + separador2;
	}
	//
	// date
	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;
	}
	//
	// phone
	if (formato == 'telefone'){
		separador1 = '(';
		separador2 = ')';
		separador3 = '-';
		conjunto1 = 0;
		conjunto2 = 3;
		conjunto3 = 8;
		if (campo.value.length == conjunto1) campo.value = campo.value + separador1;
		if (campo.value.length == conjunto2) campo.value = campo.value + separador2;
		if (campo.value.length == conjunto3) campo.value = campo.value + separador3;
	}
}
// -----------------------------------------------------------------------------------------
/*
begin of swap image functions
*/
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_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_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];}
}
/*
end of swap image functions
*/
//
// -----------------------------------------------------------------------------------------
//
// function to swap images on home
countSequencia = 0;
function animarSequenciaHome() {
	countSequencia++;
	MM_swapImage('img','','images/img_inicio_link_'+countSequencia+'_on.gif',1);
	if (countSequencia == 6) countSequencia = 0;
}
idSequencia = window.setInterval("animarSequenciaHome()", 4000);
//
// function to show a defined DIV element
function mostrarAlerta(mensagem, xPos, yPos) {
	document.getElementById(mensagem).style.visibility = "visible";
	document.getElementById(mensagem).style.marginTop = yPos;
	document.getElementById(mensagem).style.paddingTop = yPos;
	document.getElementById(mensagem).style.marginLeft = xPos;
	document.getElementById(mensagem).style.paddingLeft = xPos;
}
//
// funciton to hide a defined DIV
function esconderAlerta(mensagem) {
	document.getElementById(mensagem).style.visibility = "hidden";
}
//
// function to validate empty text fields
function avisotxt(formu, mensagem, xPos, yPos){
	if (formu.value == ""){
		mostrarAlerta(mensagem, xPos, xPos);
		formu.focus();
		return false;
	}
	return true;
}
//
// function to validate emails
function checkmail(formu, mensagem, xPos, Ypos) {
	if (!CheckValida(formu.value,'N')) {
		mostrarAlerta(mensagem, xPos, xPos);
		formu.focus();
		return false;
	}
	return true;
}
//
// function to validate email string
function CheckValida(obj, Vazio) {
	var permitido = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.@-_";
	var tamanho = obj.length;
	if (Vazio == 'S') {
		if (obj != "" && (obj.indexOf('@') == -1 || obj.indexOf('.') == -1))
			return false;
	} else {
		if (obj.indexOf('@')== -1 || obj.indexOf('.') == -1)
			return false;
	}
	for (i = 0; i <= tamanho+1; i++)
		if (permitido.indexOf(obj.charAt(i)) == -1)
			return false;
	return true;
}
//
// function to validate checkboxes
function verificachecked(formu, mensagem, xPos, yPos) {
	var conta = 0;
	var tamanho = formu.length;
	if (tamanho > 1) {
		for (var i = 0; i < tamanho; i++)
			if (formu[i].checked) conta++;
	} else
		if (formu.checked) conta++;
	//
	if (conta == 0) {
		mostrarAlerta(mensagem, xPos, xPos);
		(tamanho > 1) ? formu[0].focus() : formu.focus();
		return false;
	}
	return true;
}

// function fo validate numeric fields
function isnumber(formu, mensagem, xPos, yPos) {
	if (formu.value.length == 0) {
		mostrarAlerta(mensagem, xPos, xPos);
		formu.focus();
		return false;
	}
	RefString="1234567890,.-";
	for (var Count=0; Count < formu.value.length; Count++){
		TempChar = formu.value.substring (Count, Count+1);
		if (RefString.indexOf(TempChar, 0) == -1) {
			mostrarAlerta(mensagem, xPos, xPos);
			formu.focus();
			return false;
		}
	}
	return true;
}

// function fo validate numeric fields
function isnumber2(formu, mensagem, xPos, yPos) {
	RefString="1234567890,.-";
	for (var Count=0; Count < formu.value.length; Count++){
		TempChar = formu.value.substring (Count, Count+1);
		if (RefString.indexOf(TempChar, 0) == -1) {
			mostrarAlerta(mensagem, xPos, xPos);
			formu.focus();
			return false;
		}
	}
	return true;
}
//
// function to validate combobox fields
function avisoselect(formu, mensagem, xPos, yPos) {
	if (formu.selectedIndex == 0) {
		mostrarAlerta(mensagem, xPos, xPos);
		formu.focus();
		return false;
	}
	return true;
}
//
// function to validate password
/*function verificarSenha(formu, xPos, yPos) {
	var senha = formu.value;   
	var entrada = 0;   
	//
	if (senha.length < 8) entrada--; 
	if (!senha.match(/[a-z_]/i) || !senha.match(/[0-9]/)) entrada--;   
	if (!senha.match(/\W/)) entrada--;
	//
	if (entrada == 0) {   
			//mensagem = 'A Segurança de sua senha é: EXCELENTE';   
			mostrarAlerta("validacao_senhaexcelente", xPos, xPos);
	} else if (entrada == -1) {   
			//mensagem = 'A Segurança de sua senha é: BOM';
			mostrarAlerta("validacao_senhabom", xPos, xPos);
			formu.focus();
			return false;
	} else if (entrada == -2){   
			//mensagem = 'A Segurança de sua senha é: BAIXA';
			mostrarAlerta("validacao_senhabaixa", xPos, xPos);
			formu.focus();
			return false;
	} else if (entrada == -3){   
			//mensagem = 'A Segurança de sua senha é: MUITO BAIXA';
			mostrarAlerta("validacao_senhamuitobaixa", xPos, xPos);
			formu.focus();
			return false;
	}
	return true;
}
*/

function verificarSenha(formu, xPos, yPos) {
	var senha = formu.value;   
	var entrada = 0;   
		
	if (senha.length < 8) {   
			//mensagem = 'A Segurança de sua senha é: BOM';
			mostrarAlerta("validacao_senhabom", xPos, xPos);
			formu.focus();
			return false;
	}
	if (!senha.match(/[a-z_]/i) || !senha.match(/[0-9]/)) 
		entrada--;   

	if (entrada == 0) {   
			//mensagem = 'A Segurança de sua senha é: EXCELENTE';   
			mostrarAlerta("validacao_senhaexcelente", xPos, xPos);
	}  else if (entrada == -1){   
			//mensagem = 'A Segurança de sua senha é: BAIXA';
			mostrarAlerta("validacao_senhabaixa", xPos, xPos);
			formu.focus();
			return false;
	} /*else if (entrada == -3){   
			//mensagem = 'A Segurança de sua senha é: MUITO BAIXA';
			mostrarAlerta("validacao_senhamuitobaixa", xPos, xPos);
			formu.focus();
			return false;
	}*/
	return true;
}
//
// function to validate CPF numbers
function verificarCPF(formu, mensagem, xPos, yPos) {
	var quanti = "";
	num = formu.value.charAt(1);
	for (i=1; i <= 11; i++){
		quanti = quanti + num;
	}
	if (formu.value == quanti){
		mostrarAlerta(mensagem, xPos, xPos);
		formu.focus();
		return false;
	}
	//
	Valor = new Array();
	//
	var Tot = 0
	var Tot1 = 0
	var I = 1
	var Resto = 0
	var PriDig = 0
	var SegDi = 0
	var N = 1
	//
	while (I < 10) {
		Valor[I] = formu.value.charAt(I-1);
		Tot = Tot + (Valor[I] * (11 - I));
		Tot1 = Tot1 + (Valor[I] * (12 - I));
		I++;
	}
	Resto = Tot - (Math.floor(Tot/11) * 11);
	//
	if ((Resto == 0) || (Resto == 1)) {
		PriDig = 0;
	} else {
		PriDig = 11 - Resto;
	}
	//
	if ((PriDig != formu.value.charAt(9)) || (formu.value == "")){
		mostrarAlerta(mensagem, xPos, xPos);
		formu.focus();
		return false;
	}
	//
	Tot1 = Tot1 + (2 * PriDig);
	Resto = Tot1 - (Math.floor(Tot1/11) * 11);
	//
	if ((Resto == 0) || (Resto == 1)) {
	   SegDig = 0;
	}
	else{
	   SegDig = 11 - Resto;
	}
	//
	if ((SegDig != formu.value.charAt(10)) || (formu.value == "")){
		mostrarAlerta(mensagem, xPos, xPos);
		formu.focus();
		return false;
	}
	return true;
}

//
// fecha valida
function js_FechaValida(formu, val, mensagem, xPos, yPos) {
	var dia = val.substring(0,2);
	var s1  = val.substring(2,3);
	var mes = val.substring(3,5);
	var s2  = val.substring(5,6);
	var anio = val.substring(6,10);
    var result = true;
    
	if (val.length != 10 || // el formato de fecha es de 10 caracteres
			isNaN(dia) || // verificar el dia
			isNaN(mes) || // verificar el mes
			isNaN(anio) || // verificar el anio
			s1 != "/" || s2 != "/")  // verificar los separadores
		result = false;
	else
	if (anio < 1900 || anio > 2079) 
		result = false;
	else
	if (dia > 31 || mes > 12) 
		result = false;
	else {
	    var myDate = new Date(anio, mes - 1, dia);

	    /* Cuando una fecha es invalida, al convertirla a Date()
	       el mes (getMonth()) se recorre automaticamente, resultando
	       diferente de myMonthStr-1 */	
	    if (!(parseInt(myDate.getMonth()) == parseInt(mes - 1))) 
			result = false;
	}
	if (!result) {
	    mostrarAlerta(mensagem, xPos, xPos);
		formu.focus();
	}
	return result;
}

function js_Decimal(formu, mensagem, xPos, yPos) {
    var valor = formu.value;
    
	if (!(/^\d+(\,\d+)?$/.test(valor))) {
		mostrarAlerta(mensagem, xPos, xPos);
		formu.focus();
		return false;
	}
	return true;
}

function js_FechaNacimiento(formu, val, mensagem, xPos, yPos) {
    var hoyMenos18 = eval(document.forms[0].hoyMenos18.value);
    var fecNac, arr, fecha, result;
    
    fecha = document.forms[0].dt_birth_dd.value +"-"+ document.forms[0].dt_birth_mm.value +"-"+ document.forms[0].dt_birth_aaaa.value;
    if (fecha.length == 10) {
        arr = fecha.split('-');
        fecNac = eval( arr[2] +""+ arr[1] +""+ arr[0]);
        result = fecNac <= hoyMenos18;
    }
    else 
        result = false;
    if (!result) {
	    mostrarAlerta(mensagem, xPos, xPos);
		formu.focus();
	}
	return result;
}
//
// function to clear fields
function limpaavisotxt(formu, mensagem) {
	//formu.value = "";
	esconderAlerta(mensagem);
}
//
// function to focus a field
function focarCampo(formu){
	formu.focus();
}
//
// function to open a new window
function abrirJanela(arquivo, nome, largura, altura){
	window.open(arquivo,nome,'toolbar=0,location=0,status=1,menubar=0,scrollbars=1,resizable=0,width='+largura+',height='+altura+',top=30,left=30');
}
//
// function to verify screen resolutuion
function verificarResolulcao() {
	if (screen.width > 800 || screen.height > 600) //se for maior que 800x600
		document.getElementById("pagina").style.visibility = "visible";
}
//
// begin functions after page loaded
function iniciar() {
	// check browser resolution
	verificarResolulcao();
}
//
// função para iniciar determinado audio no Flash
function sendDataToFlash(pAudio) {
	if (document.all) {
		var flashMovie = window.document.audio;
		if (flashMovie.getVariable("_root.tocando") == "0")
			flashMovie.SetVariable("_root.recebe", pAudio);
	}
}
//
//
//
//
/*
-----------------------------------  START SCREENS
*/
//
//
//
// -----------------------------------------------------------------------------------------
// 
//
// send data to login screen
function acessarAgora() {
	clearInterval(idSequencia);
	retrieveData('conteudo','div_login.aspx','GET',true,null);
}
//
// -----------------------------------------------------------------------------------------
// login
//
function  js_RTrimX (cadena) {
  if (cadena == null)
     return "";
  var i= cadena.length - 1 ;
  if (i < 0)  
   return "";	

  while ((cadena.charAt(i) == ' ' || cadena.charCodeAt(i) == 10) && i >= 0)
   i--;
  if (i >= 0)
     return cadena.substring (0, i + 1);

  return "";
}

function resultLogin() {
    var msg;
    
    if (http_request2 != null) {
		if (http_request2.readyState == 4){
		    document.body.style.cursor = "auto";

			var texto = http_request2.responseText;
			texto = texto.replace(/\+/g," ");
			texto = unescape(texto);

            var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
            //var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;

            // Mozilla, Firefox, SeaMonkey, Safari
	        if (!isIE) {
			    var parser = new DOMParser();
                var doc = parser.parseFromString(texto, "text/xml");

                if (js_RTrimX(doc.documentElement.firstChild.textContent).length == 0) {
                    var result = doc.getElementsByTagName("Resultado");
                    var msg = (doc.getElementsByTagName("Mensaje"))[0].textContent;
                    
                    if (eval(result[0].textContent) == 2) {
                        var elem = document.getElementById("msgError");
                        
                        msg = msg.replace(/\+/g," ");
		                msg = unescape(msg);
                        elem.innerHTML = msg;
                    }
                    else 
                        document.frmPrincipal.submit();
                }
                else {
                    var elem = document.getElementById("msgError");
                    
                    elem.innerHTML = texto;
                }
			}
			else
			{
			    myXML.async = false;
			    myXML.loadXML(texto);
			    if (myXML.readyState.toLowerCase() == "complete") {
                    if (myXML.documentElement != null) {
                        result = myXML.documentElement.selectSingleNode("/Login/Resultado");
                        msg = myXML.documentElement.selectSingleNode("/Login/Mensaje").text;
                        if (eval(result.text) == 2) {
                            var elem = document.getElementById("msgError");
                            
                            msg = msg.replace(/\+/g," ");
			                msg = unescape(msg);
                            elem.innerHTML = msg;
                        }
                        else 
                            document.frmPrincipal.submit();
                    }
                    else {
                        var elem = document.getElementById("msgError");
                        
                        elem.innerHTML = texto;
                    }
		        }
		    }
		}
	}
}

//
// function to send login data
function enviarDadosLogin() {
	var nm_username = document.form.nm_username.value;
	var nm_password = document.form.nm_password.value;
	var recordarPwd = document.form.ic_remindpassword.checked? "1": "0";
	
	document.frmPrincipal.txtUserName_.value = nm_username;
    document.frmPrincipal.txtUserPass_.value = nm_password;
    document.frmPrincipal.recordarPassword_.value = recordarPwd;
	retrieveData2("VerificaLogin.aspx", "POST", true, "param1="+ nm_username +"&param2="+ nm_password, resultLogin);
}

//
// function to verify login form
function verificarCamposLogin() {
	avisotxt(document.form.nm_username, "valida_nomedeusuario", 0, 0) &&
	avisotxt(document.form.nm_password, "valida_senha", 0, 0) &&
	enviarDadosLogin();
}


//
// go to register screen
function cadastrar(msgError) {
    var param;
    
    param = "nm_name="+ document.frmPrincipal.nm_name.value;
    param += "&nm_surname="+ document.frmPrincipal.nm_surname.value;
    param += "&nm_username="+ document.frmPrincipal.nm_username.value;
    param += "&nm_password="+ document.frmPrincipal.nm_password.value;
    param += "&nm_email="+ document.frmPrincipal.nm_email.value;
    param += "&cd_code="+ document.frmPrincipal.cd_code.value; //code access
    param += "&ic_agree="+ document.frmPrincipal.ic_agree.value;
    param += "&msgError="+ msgError;

	retrieveData('conteudo','div_passo1.aspx','POST',true, param);
}

function mostrarRecuperar() {
    retrieveData('balao_lembretesenha', 'div_senha.aspx', 'POST', true, "");
    mostrarAlerta('balao_lembretesenha', 0, 0);
}

//
// function to send password
function enviarSenha() {
    var param;
    
    param = "nm_usuario="+ document.form.nm_usuario.value +"&nm_email="+ document.form.nm_email.value;
	if (checkmail(document.form.nm_email, "validacao_digiteseuemailcorretamente", 0, 0) &&
	    avisotxt(document.form.nm_usuario, "validacao_digiteumnomedeusuario", 0, 0)) { 
		    retrieveData('balao_lembretesenha','div_senhaenviada.aspx','POST',true, param);
		    //window.setTimeout("esconderAlerta('balao_lembretesenha')", 2000);
	}
}
//
// -----------------------------------------------------------------------------------------
// step 1
//
// function to verify all step 1 form
function verificarCamposPasso1() {
	avisotxt(document.form.nm_name, "validacao_digiteseunome", 0, 0) &&
	avisotxt(document.form.nm_username, "validacao_digiteumnomedeusuario", 0, 0) &&
	avisotxt(document.form.nm_password, "validacao_digiteumasenha", 0, 0) &&
	verificarSenha(document.form.nm_password, 0, 0) &&
	checkmail(document.form.nm_email, "validacao_digiteseuemail", 0, 0) &&
	avisotxt(document.form.cd_code, "validacao_digiteocodigodoacesso", 0, 0) &&
	verificachecked(document.form.ic_agree, "validacao_enecessarioaceitarasregras", 0, 0) &&
	enviarDadosPasso1();
}
//
// function to send data to step 1 screen
function enviarDadosPasso1() {
	document.frmPrincipal.nm_name.value = document.form.nm_name.value;
	document.frmPrincipal.nm_surname.value = document.form.nm_surname.value;
	document.frmPrincipal.nm_username.value = document.form.nm_username.value;
	document.frmPrincipal.nm_password.value = document.form.nm_password.value;
	document.frmPrincipal.nm_email.value = document.form.nm_email.value;
	document.frmPrincipal.cd_code.value = document.form.cd_code.value; //code access
	document.frmPrincipal.ic_agree.value = document.form.ic_agree.value;
	//
	retrieveData('conteudo','div_antesdecomecar.aspx','GET',true,null);
}
//
// -----------------------------------------------------------------------------------------
// before start
//
// function to load content of step 2
function aceitar() {
    var param;
    
    param = "&nm_address="+ document.frmPrincipal.nm_address.value;
	param += "&cd_number="+ document.frmPrincipal.cd_number.value;
	param += "&barrio="+ document.frmPrincipal.barrio.value;
	param += "&nm_complement="+ document.frmPrincipal.nm_complement.value;
	param += "&cep1="+ document.frmPrincipal.cep1.value;
	param += "&cep2="+ document.frmPrincipal.cep2.value;
	param += "&nm_city="+ document.frmPrincipal.nm_city.value;
	param += "&sg_state="+ document.frmPrincipal.sg_state.value;
	param += "&ic_gender="+ document.frmPrincipal.ic_gender.value;
	param += "&fecNacimiento="+ document.frmPrincipal.fecNacimiento.value;
	param += "&cd_cpf="+ document.frmPrincipal.cd_cpf.value;
    param += "&msgError=";
    
	retrieveData('conteudo','div_passo2.aspx','POST',true, param);
}
//
// function to retorn to step 1
function recusar() {
	retrieveData('conteudo','div_passo1.aspx','GET',true,null);
}
//
// -----------------------------------------------------------------------------------------
// step 2
//
// function to verify step 2 form
function verificarCamposPasso2() {
    var fechaNac = document.form.dt_birth_dd.value +"/"+ document.form.dt_birth_mm.value +"/"+ document.form.dt_birth_aaaa.value;
    
	avisotxt(document.form.nm_address, "validacao_digiteoendereco", 0, 0) &&
	avisotxt(document.form.cd_number, "validacao_digiteonumero", 0, 0) &&
	avisotxt(document.form.nm_neighborhood, "validacao_digiteobairro", 0, 0) &&
	isnumber(document.form.cd_cep1, "validacao_digiteocep", 0, 0) &&
	isnumber(document.form.cd_cep2, "validacao_digiteocep", 0, 0) &&
	avisotxt(document.form.nm_city, "validacao_digiteonomedacidade", 0, 0) &&
	avisoselect(document.form.sg_state, "validacao_selecioneoestado", 0, 0) &&
	verificachecked(document.form.ic_gender, "validacao_selecioneosexo", 0, 0) &&
	isnumber(document.form.dt_birth_dd, "validacao_digiteasuadatadenascimento", 0, 0) &&
	isnumber(document.form.dt_birth_mm, "validacao_digiteasuadatadenascimento", 0, 0) &&
	isnumber(document.form.dt_birth_aaaa, "validacao_digiteasuadatadenascimento", 0, 0) &&
	js_FechaValida(document.form.dt_birth_dd, fechaNac, "validacao_datadenascimentoinvalida", 0, 0) &&
	js_FechaNacimiento(document.form.dt_birth_dd, fechaNac, "validacao_datadenascimentoinvalida18", 0, 0) &&
	verificarCPF(document.form.cd_cpf, "validacao_digiteoseucpf", 0, 0) &&
	enviarDadosPasso2();
}
//
// function to send data to step 2 screen
function enviarDadosPasso2() {
    var fechaNac = document.form.dt_birth_dd.value +"/"+ document.form.dt_birth_mm.value +"/"+ document.form.dt_birth_aaaa.value;
    
	document.frmPrincipal.nm_address.value = document.form.nm_address.value;
	document.frmPrincipal.cd_number.value = document.form.cd_number.value;
	document.frmPrincipal.barrio.value = document.form.nm_neighborhood.value;
	document.frmPrincipal.nm_complement.value = document.form.nm_complement.value;
	document.frmPrincipal.cep1.value = document.form.cd_cep1.value;
	document.frmPrincipal.cep2.value = document.form.cd_cep2.value;
	document.frmPrincipal.nm_city.value = document.form.nm_city.value;
	document.frmPrincipal.sg_state.value = document.form.sg_state.options[document.form.sg_state.selectedIndex].value;
	document.frmPrincipal.ic_gender.value = document.form.ic_gender[0].checked? 
	                                        document.form.ic_gender[0].value:
	                                        document.form.ic_gender[1].value;
	document.frmPrincipal.fecNacimiento.value = fechaNac;
	document.frmPrincipal.cd_cpf.value = document.form.cd_cpf.value;
	
	//
	var param;
	
	param = "cd_ddd="+ document.frmPrincipal.cd_ddd.value
	param += "&cd_cellphone="+ document.frmPrincipal.cd_cellphone.value;
	param += "&nm_doctor="+ document.frmPrincipal.nm_doctor.value;
	param += "&cd_crm="+ document.frmPrincipal.cd_crm.value;
	param += "&nm_schedule_sms_week="+ document.frmPrincipal.nm_schedule_sms_week.value;
	param += "&nm_schedule_sms_weekend="+ document.frmPrincipal.nm_schedule_sms_weekend.value;
	param += "&nm_howmany="+ document.frmPrincipal.nm_howmany.value;
	param += "&dt_treatment_beginning="+ document.frmPrincipal.dt_treatment_beginning.value;
	param += "&vl_howmuch="+ document.frmPrincipal.vl_howmuch.value;
	param += "&msgError=";
	
	retrieveData('conteudo','div_passo3.aspx','POST', true, param);
}
//
// -----------------------------------------------------------------------------------------
// step 3
//

function resultInsert() {
    var msg;
    
    if (http_request2 != null) {
		if (http_request2.readyState == 4){
		    document.body.style.cursor = "auto";
		    
		    var OK = 1;
            var ERROR_GRAL = 2;
            var USUARIO_EXISTE = 3;
            var LOTE_NO_EXISTE = 4;
            var LOTE_EN_USO = 5;
            var NO_EMAIL = 6;
            var texto;
            
			texto = http_request2.responseText;
			texto = texto.replace(/\+/g," ");
			texto = unescape(texto);
			
			var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
			
			// Mozilla, Firefox, SeaMonkey, Safari
	        if (!isIE) {
			    var parser = new DOMParser();
                var doc = parser.parseFromString(texto, "text/xml");

                if (js_RTrimX(doc.documentElement.firstChild.textContent).length == 0) {
                    result = eval((doc.getElementsByTagName("Resultado"))[0].textContent);
                    msg = (doc.getElementsByTagName("Mensaje"))[0].textContent;
                    var elem;
                        
                    msg = msg.replace(/\+/g," ");
		            msg = unescape(msg);
		            if (result != OK) {
		                document.getElementById("imgClock").style.visibility = "hidden";
		                document.getElementById("enviarDatos").style.display = "";
		            }
                    switch (result) {
                        case OK:
                            document.frmAcceso.submit();
                            break;
                        case NO_EMAIL:
                            document.getElementById("imgEnviar").src = "images/bt_acessar1.gif";
                            document.getElementById("imgEnviar").onclick = "javascript:js_Accesar();"
                        case ERROR_GRAL:
                            elem = document.getElementById("msgError3");
                            elem.innerHTML = msg;
                            break;
                        case USUARIO_EXISTE:
                        case LOTE_NO_EXISTE:
                        case LOTE_EN_USO:
                            cadastrar(msg);
                            break;
                    }
                }
                else {
                    document.getElementById("imgClock").style.visibility = "hidden";
		            document.getElementById("enviarDatos").style.display = "";
                    
                    var elem = document.getElementById("msgError3");
                    
                    elem.innerHTML = texto;
                }
            }
			else
			{
			    myXML.async = false;
			    myXML.loadXML(texto);
			    if (myXML.readyState.toLowerCase() == "complete") {		    
                    if (myXML.documentElement != null) {
                        result = eval(myXML.documentElement.selectSingleNode("/Login/Resultado").text);
                        msg = myXML.documentElement.selectSingleNode("/Login/Mensaje").text;
                        var elem;
                        
                        msg = msg.replace(/\+/g," ");
			            msg = unescape(msg);
			            if (result != OK) {
			                document.getElementById("imgClock").style.visibility = "hidden";
			                document.getElementById("enviarDatos").style.display = "";
			            }
                        switch (result) {
                            case OK:
                                document.frmAcceso.submit();
                                break;
                            case NO_EMAIL:
                                document.getElementById("imgEnviar").src = "images/bt_acessar1.gif";
                                document.getElementById("imgEnviar").onclick = "javascript:js_Accesar();"
                            case ERROR_GRAL:
                                elem = document.getElementById("msgError3");
                                elem.innerHTML = msg;
                                break;
                            case USUARIO_EXISTE:
                            case LOTE_NO_EXISTE:
                            case LOTE_EN_USO:
                                cadastrar(msg);
                                break;
                        }
                    }
                    else {
                        document.getElementById("imgClock").style.visibility = "hidden";
			            document.getElementById("enviarDatos").style.display = "";
                        
                        var elem = document.getElementById("msgError3");
                        
                        elem.innerHTML = texto;
                    }
		        }
		    }
		}
	}
}

// function to send data to step 3 screen
function verificarCamposPasso3() {
    var fechaNac = document.form.dt_treatment_beginning.value;
    
    isnumber2(document.form.cd_ddd, "validacao_numerodecelularinvalido", 0, 0) &&
	isnumber2(document.form.cd_cellphone, "validacao_numerodecelularinvalido", 0, 0) &&
	avisotxt(document.form.dt_treatment_beginning, "validacao_digiteadatadeinicio", 0, 0) &&
	js_FechaValida(document.form.dt_treatment_beginning, fechaNac, "validacao_datainicialdetratamentovalida", 0, 0) &&
	avisotxt(document.form.vl_howmuch, "validacao_digiteoprecodomaco", 0, 0) &&	
	js_Decimal(document.form.vl_howmuch, "validacao_valordomacodecigarroinvalido", 0, 0) &&
	enviarDadosPasso3();
}
//
// function to send data to step 3 screen
//
//
function enviarDadosPasso3() {
	document.frmPrincipal.cd_ddd.value = document.form.cd_ddd.value;
	document.frmPrincipal.cd_cellphone.value = document.form.cd_cellphone.value;
	document.frmPrincipal.nm_doctor.value = document.form.nm_doctor.value;
	document.frmPrincipal.cd_crm.value = document.form.cd_crm.value;
	document.frmPrincipal.nm_schedule_sms_week.value = document.form.nm_schedule_sms_week.options[document.form.nm_schedule_sms_week.selectedIndex].value;
	document.frmPrincipal.nm_schedule_sms_weekend.value = document.form.nm_schedule_sms_weekend.options[document.form.nm_schedule_sms_weekend.selectedIndex].value;
	document.frmPrincipal.nm_howmany.value = document.form.nm_howmany.value;
	document.frmPrincipal.dt_treatment_beginning.value = document.form.dt_treatment_beginning.value;
	document.frmPrincipal.vl_howmuch.value = document.form.vl_howmuch.value;
	var parametros, i;
	
	parametros ="";
	for (i = 0; i < document.frmPrincipal.elements.length; i++) {
	    parametros += document.frmPrincipal.elements[i].name +"="+ document.frmPrincipal.elements[i].value +"&";
	}
	
    document.getElementById("enviarDatos").style.display = "none";
    document.getElementById("imgClock").style.visibility = "visible";
	
	retrieveData2("InsertarDatos.aspx", "POST", true, parametros, resultInsert);
}
//
// -----------------------------------------------------------------------------------------
// register 1
//
// function to verify register 1 form
function verificarCamposRegistro1() {
	enviarDadosRegistro1();
}
//
// function to send data to register 1 screen
function enviarDadosRegistro1() {
	var motivo1 = document.form.motivo1.value;
	var motivo2 = document.form.motivo2.value;
	var motivo3 = document.form.motivo3.value;
	var motivo4 = document.form.motivo4.value;
	var motivo5 = document.form.motivo5.value;
	var motivo6 = document.form.motivo6.value;
	var motivo7 = document.form.motivo7.value;
	//
	retrieveData('conteudo','div_registro2.asp','POST',true,"motivo1="+motivo1+"&motivo2="+motivo2+"&motivo3="+motivo3+"&motivo4="+motivo4+"&motivo5="+motivo5+"&motivo6="+motivo6+"&motivo7="+motivo7);
}
//
// -----------------------------------------------------------------------------------------
// register 2
//
// function to verify register 2 form
function verificarCamposRegistro2() {
	enviarDadosRegistro2();
}
//
// function to send data to register 2 screen
function enviarDadosRegistro2() {
	var motivo8 = document.form.motivo8.value;
	var motivo9 = document.form.motivo9.value;
	var motivo10 = document.form.motivo10.value;
	var motivo11 = document.form.motivo11.value;
	var nm_motivoproprio = document.form.nm_motivoproprio.value;
	var nm_motivoinclui = document.form.nm_motivoinclui.value;
	//
	alert("Acesso ao Bmod!");
	// line below is used to send data to Bmod accesss
	//document.location.href = "teste.aspx?motivo8="+motivo8+"&motivo9="+motivo9+"&motivo10="+motivo10+"&motivo11="+motivo11+"&nm_motivoproprio="+nm_motivoproprio+"&nm_motivoinclui="+nm_motivoinclui;
}
//
//
//
//
/*
-----------------------------------  END OF SCREENS
*/
//
//
//