// JavaScript Document

/* MÁSCARAS ***********************************************************************************/

mascaraMoeda = function (e, obj) {
	var tecla = (window.event) ? e.keyCode : e.which;
	var cDec = 2;
	var cMil = 3;
	var vOriginal = "";
	var vFinal = "";
	var tam = "";
	var cont = 0;
	var result = false;


	var tecla = (window.event) ? e.keyCode : e.which;
	
	if (tecla != 9) {
		var v = obj.value;
			
		v = v.replace(/\D/g,"");             //Remove tudo o que não é dígito
		v = v.replace(/^(0+)/g,"");
		
		if (v.length == 0) v = "000";
		else if (v.length == 1) v = "00" + v;
		else if (v.length == 2) v = "0" + v;
		
		if (v.length < 4) v = v.replace(/(\d{2})$/,",$1");
		else if (v.length < 6) v = v.replace(/(\d{2})(\d{2})$/,"$1,$2");
		else if (v.length < 9) v = v.replace(/(\d{1})(\d{3})(\d{2})$/,"$1.$2,$3");
		else if (v.length < 12) v = v.replace(/(\d{1})(\d{3})(\d{3})(\d{2})$/,"$1.$2.$3,$4");
		else if (v.length < 15) v = v.replace(/(\d{1})(\d{3})(\d{3})(\d{3})(\d{2})$/,"$1.$2.$3.$4,$5");
		
		obj.value = v;
	}
}

mascaraData = function (e, obj) {
	var tecla = (window.event) ? e.keyCode : e.which;
	var result = false;
	
	if ((tecla >= 48 && tecla <= 57) || (tecla >= 96 && tecla <= 105) || tecla== 9 || tecla == 8 || tecla == 46 || tecla == 110) {
    	result = true;
		
		if (tecla != 8) {
			if (obj.value.length == 2)
				obj.value += "/";
			
			if (obj.value.length == 5)
				obj.value += "/";
		}
	}
	
	return result;
}

mascaraHora = function (e, obj) {
	var tecla = (window.event) ? e.keyCode : e.which;
	var result = false;
	
	if ((tecla >= 48 && tecla <= 57) || (tecla >= 96 && tecla <= 105) || tecla== 9 || tecla == 8 || tecla == 46 || tecla == 110) {
    	result = true;
		
		if (tecla != 8)
			if (obj.value.length == 2)
				obj.value += ":";
	}
	
	return result;
}

mascaraFone = function (e, obj) {
	var tecla = (window.event) ? e.keyCode : e.which;
	
	if (tecla != 9) {
		var v = obj.value;
			
		v = v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
		v = v.replace(/(\d{4})(\d)/,"$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
		
		obj.value = v;
	}
}

soNumeros = function (e) {
	var key;
	var keychar;
	var reg;
	
	if (window.event) {
		// for IE, e.keyCode or window.event.keyCode can be used
		key = e.keyCode; 
	}
	else if (e.which) {
		// netscape, firefox 
		key = e.which; 
	}
	else {
		// no event, so pass through
		return true;
	}

	if (key == 8 || key == 9 || key == 46 || key == 17 || key == 116 || (key >= 96 && key <= 105))
		return true;

	keychar = String.fromCharCode(key);
	reg = /[^\d-]/;

	return !reg.test(keychar);
}

var interesse = {
	iniciar: function() {
		if (!$get("divFundo")) {
			var objBody = document.getElementsByTagName("body").item(0);
			var div = document.createElement("div");
	
			div.setAttribute('id','divFundo');		
	
			with (div.style) {
				height = getPageSize()[1] + "px";//"100%";
				width = "100%";
				top = "0px";
				position = "absolute";
				backgroundColor = "#000";
				filter = "alpha(opacity=75)";
				opacity = ".75";
				zIndex = 0;
				visibility = "hidden";
			}
		
			objBody.appendChild(div);
		}
	},
	
	abrir: function() {
		interesse.iniciar();

		$get("divFundo").style.visibility = "visible";
		$get("divInteresse").style.display = "block";
		
		with ($get("divControle")) {
			style.display = "block";
			style.zIndex = 1;
			style.left = ((getPageSize()[0] - clientWidth) / 2) + "px";
			style.top = ((document.all) ? document.documentElement.scrollTop : window.pageYOffset) +
				((getPageSize()[3] - clientHeight) / 2) + "px";
		}
	},
		
	fim: function() {
		$get("divFundo").style.visibility = "hidden";
		$get("divInteresse").style.display = "none";
		$get("divIndique").style.display = "none";
		
		with ($get("divControle")) {
			style.display = "none";
			style.zIndex = 1;
			style.left = "0px";
			style.top = "0px";
		}
		
		for (x=0; x<Page_Validators.length; x++) {
			Page_Validators[x].style.display = "none";
		}
		
		try {
			$get("txtNomeInteresse").value = '';
			$get("txtEmailInteresse").value = '';
			$get("txtFoneInteresse").value = '';
			$get("txtMsgInteresse").value = '';
			$get("botEnviarInteresse").disabled = false;
		} catch(e) {}
	}
}

var indique = {
	iniciar: function() {
		if (!$get("divFundo")) {
			var objBody = document.getElementsByTagName("body").item(0);
			var div = document.createElement("div");
	
			div.setAttribute('id','divFundo');		
	
			with (div.style) {
				height = getPageSize()[1] + "px";//"100%";
				width = "100%";
				top = "0px";
				position = "absolute";
				backgroundColor = "#000";
				filter = "alpha(opacity=75)";
				opacity = ".75";
				zIndex = 0;
				visibility = "hidden";
			}
		
			objBody.appendChild(div);
		}
	},
	
	abrir: function() {
		indique.iniciar();

		$get("divFundo").style.visibility = "visible";
		$get("divIndique").style.display = "block";

		with ($get("divControle")) {
			style.display = "block";
			style.zIndex = 1;
			style.left = ((getPageSize()[0] - clientWidth) / 2) + "px";
			style.top = ((document.all) ? document.documentElement.scrollTop : window.pageYOffset) +
				((getPageSize()[3] - clientHeight) / 2) + "px";
		}
	},
		
	fim: function() {
		$get("divFundo").style.visibility = "hidden";
		$get("divInteresse").style.display = "none";
		$get("divIndique").style.display = "none";
		
		with ($get("divControle")) {
			style.display = "none";
			style.zIndex = 1;
			style.left = "0px";
			style.top = "0px";
		}
		
		for (x=0; x<Page_Validators.length; x++) {
			Page_Validators[x].style.display = "none";
		}
		
		try {
			$get("txtNomeRemetente").value = '';
			$get("txtEmailRemetente").value = '';
			$get("txtNomeDestinatario").value = '';
			$get("txtEmailDestinatario").value = '';
			$get("txtMsgIndique").value = '';
			$get("botEnviarIndique").disabled = false;
		} catch(e) {}
	}
}


getPageSize = function() {
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

