﻿function GoogleAnalyticsParams(e) {
	_uacct = "UA-604874-2";
	urchinTracker();
}
addEvent(window, "load", GoogleAnalyticsParams);

function hasBlock(cdDocument) {
	var blockDocuments = new Array();
	var block = false;
	blockDocuments.push("25108295804");
	blockDocuments.push("14767112087");
	blockDocuments.push("30335059880");
//	blockDocuments.push("08628779701");
	blockDocuments.push("04574064000157");
	blockDocuments.push("06116778000147");
	blockDocuments.push("07070064000108");
	blockDocuments.push("07043402000112");
	blockDocuments.push("06871635000140");
	blockDocuments.push("07072686000175");
	blockDocuments.push("04956532000158");
	blockDocuments.push("17093139000120");

	for(var i = 0; i < blockDocuments.length; i++) {
		if(blockDocuments[i] == cdDocument) {
			block = true;
			break;
		}
	}
	return block;
}

function getSelectText(objSelect) {
	var currItem;
	for(var i = 0; i < objSelect.childNodes.length; i++) {
		currItem = objSelect.childNodes[i];
		if(currItem.nodeName == "OPTION" && currItem.selected) {
			return currItem.text;
		}
	}
}

// vDate
// USO: vDate(ano, mes, dia)
function vDate(y, m, d) {
	var vDate = false;
	var date = new Date();
	var betweenDays = 0;
	var betweenMonths = 0;
	var betweenYears = 0;
	
    with (D = new Date(y, --m, d)) {
        vDate = (getMonth() == m && getDate() == d) ? true : false;
    }
	if(vDate) {
		betweenDays = Math.floor(Math.abs(Math.round(date - D)) / (24 * 60 * 60 * 1000));
		betweenMonths = Math.floor(betweenDays / 30);
		betweenYears = Math.floor(betweenDays / 365);
	}
	return {
		valid : vDate,
		days : betweenDays,
		months : betweenMonths,
		years : betweenYears
	}
}

// replace
// USO: replace(src, srt1, str2)
function replace(pSource, pOut, pIn) {
	while(pSource.indexOf(pOut) > -1) {
		var pos = pSource.indexOf(pOut);
		pSource = (pSource.substring(0, pos) + pIn + pSource.substring((pos + out.length), pSource.length));
	}
	return pSource;
}

// RemoveSpecial
// USO: RemoveSpecial(object)
function RemoveSpecial(e) {
	var obj = getTarget(e);
	var specialChars = "ÃÂÁÀÄÊÉÈËÎÍÌÏÕÔÓÒÖÛÚÙÜÇ";
	var value = (typeof(obj) == "string") ? obj.toUpperCase() : String(obj.value).toUpperCase();
	var strReturn = "";
	for(var i = 0; i < value.length; i++) {
		pos = String(specialChars).indexOf(value[i]);
		if(pos == -1) {
			strReturn += value.charAt(i);
		}
		else {
			switch(specialChars.charAt(pos))	{
				case "Ã" : case "Â" : case "Á" : case "À" : case "Ä" :
					strReturn += "A";
				break;
				case "Ê" : case "É" : case "È" : case "Ë" :
					strReturn += "E";
				break;
				case "Î" : case "Í" : case "Ì" : case "Ï" :
					strReturn += "I";
				break;
				case "Õ" : case "Ô" : case "Ó" : case "Ò" : case "Ö" :
					strReturn += "O";
				break;
				case "Û" : case "Ú" : case "Ù" : case "Ü" :
					strReturn += "U";
				break;
				case "Ç" :
					strReturn += "C";
				break;
			}
		}
	}
	return strReturn;
}

// delCookie
// USO: delCookie(name)
function delCookie(name) {
	if(getCookie(name)) {
		document.cookie = name + "=" +
		";expires=Fri, 03-Jul-81 02:20:02 GMT+3";
	}
}

// setCookie
// USO: setCookie(name, value)
function setCookie(name, value){
	document.cookie = name + "=" + escape (value);
}

// getCookie
// USO: getCookie('nome')
function getCookie(name){
	var dcookie = document.cookie;
	var cname = name + "=";
	var clen = dcookie.length;
	var cbegin = 0;
	while (cbegin < clen){
		var vbegin = cbegin + cname.length;
		if (dcookie.substring(cbegin, vbegin) == cname){
			var vend = dcookie.indexOf (";", vbegin);
			if (vend == -1) vend = clen;
			return unescape(dcookie.substring(vbegin, vend));
		}
		cbegin = dcookie.indexOf(" ", cbegin) + 1;
		if (cbegin == 0) break;
	}
	return false;
}

// scriptLoader
// USO: scriptLoader(jsPath)
function scriptLoader(url) {
	try {
		var objScript = document.createElement("script");
		objScript.type = "text/javascript";
		objScript.src = url;
		var objHead = document.getElementsByTagName("head");
		objHead[0].appendChild(objScript);
	}
	catch(e) {
		document.write("<script type=\"text\/javascript\" src=\"" + url + "\"><\/script>");	
	}
}

// trim
// USO: trim(obj.value)
function trim(str){
	return str.replace(/^\s*(\w+)*\s*$/,"$1");
}

// email
// USO: campo.value.isEmail
String.prototype.isEmail = function(){
	var er = /^[a-z0-9._-]+@([a-z0-9]+[a-z0-9_-]*)+(\.[a-z0-9]+)+$/;
	var value = this.toLowerCase();
	return er.test(value);
}

// CNPJ
// USO: campo.value.isCNPJ
String.prototype.isCNPJ = function(){
	var d = this.split("");
	var m1 = [d[0]*5,d[1]*4,d[2]*3,d[3]*2,d[4]*9,d[5]*8,d[6]*7,d[7]*6,d[8]*5,d[9]*4,d[10]*3,d[11]*2];
	var s1 = 0;
	for(i in m1){ s1 += m1[i]; }
	var d1 = (s1%11<2)?0:11-(s1%11);
	var m2 = [d[0]*6,d[1]*5,d[2]*4,d[3]*3,d[4]*2,d[5]*9,d[6]*8,d[7]*7,d[8]*6,d[9]*5,d[10]*4,d[11]*3,d1*2];
	var s2 = 0;
	for(i in m2){ s2 += m2[i]; }
	var d2 = (s2%11<2)?0:11-(s2%11);
	return (d1 == d[12] && d2 == d[13])?true:false;
} 

// CPF 
// USO: campo.value.isCPF
String.prototype.isCPF = function(){
	if(this.split(this.charAt(0)).join("")=="") return false;
	var d = this.split("");
	var m1 = [d[0]*10,d[1]*9,d[2]*8,d[3]*7,d[4]*6,d[5]*5,d[6]*4,d[7]*3,d[8]*2];
	var s1 = 0;
	for(i in m1){ s1 += m1[i]; }
	var d1 = (s1%11<2)?0:11-(s1%11);
	var m2 = [d[0]*11,d[1]*10,d[2]*9,d[3]*8,d[4]*7,d[5]*6,d[6]*5,d[7]*4,d[8]*3,d1*2];
	var s2 = 0;
	for(i in m2){ s2 += m2[i]; }
	var d2 = (s2%11<2)?0:11-(s2%11);
	return (d1 == d[9] && d2 == d[10])?true:false;
}

// numeros e barra
// USO: onkeypress="return setDate(event)"
function setdate(e) {
	var obj = getTarget(e);
	var key = '';
	var strCheck = "0123456789";
	var whichCode = (window.Event) ? e.which : e.keyCode;
	var ins = false;

	if(whichCode == "\t" || whichCode == "\n" || whichCode == "\b" || whichCode == 8) return true; // Tab, Enter e backspace
	key = String.fromCharCode(whichCode);  // Pega o codigo da tecla precionada

	if(strCheck.indexOf(key) != -1){ // tecla valida
		if(!obj.format) {
			if((obj.value.length == 1) || (obj.value.length == 4)) {
				ins = true;
			}
		}
		else {
			if(obj.value.length == 1) {
				ins = true;
			}
		}
		if(ins) {
			obj.value += key + "/";
			return abort(e);
		}
	}
	else {
		return abort(e);
	}
}

function abort(e) {
	var w3DOM = window.addEventListener;
	if(w3DOM){
		e.preventDefault();
	}
	else{
		return false;
	}
}

// numeros
// USO: onkeypress="return setNumeric(event)"
function setNumeric(e) {
	var key = '';
	var strCheck = "0123456789";
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == "\t" || whichCode == "\n" || whichCode == "\b" || whichCode == 8) return true; // Tab, Enter e backspace
	key = String.fromCharCode(whichCode);  // Pega o codigo da tecla precionada
	if (strCheck.indexOf(key) == -1){ // tecla não valida
		return abort(e);
	}
}

function setCurrency(e) {
	var strValue = "";
	var strLength = 0;
	var obj = getTarget(e);
	var key = '';
	var strCheck = "0123456789";
	var floatPoint = 2;
	var decimalSep = ',';
	var thousandsSep = '.';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if(trim(obj.value) == "" && obj.stringValue) {
		var objStr = document.getElementById(obj.stringValue);
		objStr.innerHTML = "";
	}
	if (whichCode == "\t" || whichCode == "\n" || whichCode == "\b" || whichCode == 8) return true; // Tab, Enter e backspace
	key = String.fromCharCode(whichCode);  // Pega o codigo da tecla precionada
	if (strCheck.indexOf(key) != -1){ // tecla valida
		var obj, strValue, strLength = (
					   strValue = (
							obj.value.replace(/^0+/g, "") + key
							).replace(/\D/g, "")
					   ).length, floatPoint;
		if(obj.maxLength + 1 && strLength >= obj.maxLength) {
			return abort(e);
		}
		strLength <= (floatPoint) && (strValue = new Array(floatPoint - strLength + 2).join("0") + strValue);
		for(var i = (strLength = (strValue = strValue.split("")).length) - floatPoint; (i -= 3) > 0; strValue[i - 1] += thousandsSep);
		floatPoint && floatPoint < strLength && (strValue[strLength - ++floatPoint] += decimalSep);
		obj.value = strValue.join("");
		if(obj.stringValue) {
			var objStr = document.getElementById(obj.stringValue);
			objStr.innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + obj.value.strValue();
		}
	}
	return abort(e);
}

String.prototype.strValue = function(){
	var c = 1;
	var ex = [
		["zero", "um", "dois", "três", "quatro", "cinco", "seis", "sete", "oito", "nove", "dez", "onze", "doze", "treze", "quatorze", "quinze", "dezesseis", "dezessete", "dezoito", "dezenove"],
		["dez", "vinte", "trinta", "quarenta", "cinqüenta", "sessenta", "setenta", "oitenta", "noventa"],
		["cem", "cento", "duzentos", "trezentos", "quatrocentos", "quinhentos", "seiscentos", "setecentos", "oitocentos", "novecentos"],
		["mil", "milhão", "bilhão", "trilhão", "quadrilhão", "quintilhão", "sextilhão", "setilhão", "octilhão", "nonilhão", "decilhão", "undecilhão", "dodecilhão", "tredecilhão", "quatrodecilhão", "quindecilhão", "sedecilhão", "septendecilhão", "octencilhão", "nonencilhão"]
	];
	var a, n, v, i, n = this.replace(c ? /[^,\d]/g : /\D/g, "").split(","), e = " e ", $ = "real", d = "centavo";
	for(var f = n.length - 1, l, j = -1, r = [], s = [], t = ""; ++j <= f; s = []){
		j && (n[j] = (("." + n[j]) * 1).toFixed(2).slice(2));
		if(!(a = (v = n[j]).slice((l = v.length) % 3).match(/\d{3}/g), v = l % 3 ? [v.slice(0, l % 3)] : [], v = a ? v.concat(a) : v).length) continue;
		for(a = -1, l = v.length; ++a < l; t = ""){
			if(!(i = v[a] * 1)) continue;
			i % 100 < 20 && (t += ex[0][i % 100]) ||
			i % 100 + 1 && (t += ex[1][(i % 100 / 10 >> 0) - 1] + (i % 10 ? e + ex[0][i % 10] : ""));
			s.push((i < 100 ? t : !(i % 100) ? ex[2][i == 100 ? 0 : i / 100 >> 0] : (ex[2][i / 100 >> 0] + e + t)) +
			((t = l - a - 2) > -1 ? " " + (i > 1 && t > 0 ? ex[3][t].replace("ão", "ões") : ex[3][t]) : ""));
		}
		a = (s.length > 1 ? (a = s.pop(), s.join(" ") + " e " + a) : s.join("") || ((!j && (n[j + 1] * 1 > 0) || r.length) ? "" : ex[0][0]));
		a && r.push(a + (c ? (" " + (v.join("") * 1 > 1 ? j ? d + "s" : $.replace("l", "is") : j ? d : $)) : ""));
	}
	return r.join(e);
}

function getSelected(e) {
	var userSelection;
	if (window.getSelection) {
		userSelection = window.getSelection();
	}
	else if (document.selection) { // should come last; Opera!
		userSelection = document.selection.createRange();
	}

	var selectedText = userSelection;
	if(userSelection.text) {
		selectedText = userSelection.text;
	}
	return selectedText;
}

function getTarget(e) {
	var obj = e;
	var w3DOM = window.addEventListener;
	if(w3DOM){
		if(e.currentTarget) {
			obj = e.currentTarget;
		}
	}
	else {
		if(e.srcElement) {
			obj = e.srcElement;
		}
	}
	return obj;
}

// addEvent
// USO: addEvent(objeto, tpEvento, funcao)
function addEvent(obj, evType, fn){
	if(obj) {
		var w3DOM = obj.addEventListener;
		var ieDOM = obj.attachEvent;
		if (w3DOM)  obj.addEventListener(evType, fn, true);
		if (ieDOM)  obj.attachEvent("on"+evType, fn);
	}
}

// removeEvent
// USO: removeEvent(objeto, tpEvento, funcao)
function removeEvent(obj, type, fn) {
	if(obj.detachEvent) {
		obj.detachEvent( 'on'+type, obj[type+fn]);
		obj[type+fn] = null;
	}
	else {
		obj.removeEventListener( type, fn, false);
	}
}

// getParent
// USO: getParent(el, pTagName)
function getParent(el, pTagName) {
	if (el == null) {
		return null;
	}
	else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase()) {
		return el;
	}
	else {
		return getParent(el.parentNode, pTagName);
	}
}

// getStyle
// USO: getStyle(el, styleProp)
function getStyle(el,styleProp) {
	if(String(typeof(el)) != "object") {
		var x = document.getElementById(el);
	}
	else {
		var x = el;	
	}
	if (x.currentStyle) {
		var y = x.currentStyle[styleProp];
		if(styleProp == "height") {
			y = x.scrollHeight + "px";
		}
	}
	else if (window.getComputedStyle) {
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	}
	return y;
}

function getElementsByClass(searchClass, node, tag) {
	var classElements = new Array();
	if(node == null) {
		node = document;
	}
	else if(typeof(node) == "string") {
		node = document.getElementById(node);
	}
	if(tag == null) {
		tag = '*';
	}
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for(i = 0; i < elsLen; i++) {
		if(pattern.test(els[i].className)) {
			classElements.push(els[i]);
		}
	}
	return classElements;
}

function px2int(pValue) {
	if(String(pValue).indexOf("px") != -1) {
		var intReturn = pValue.substring(0, (pValue.length - 2));
		intReturn = parseInt(intReturn);
		return intReturn;
	}
	else {
		return;
	}
}

function getSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == "number" ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return {"width": myWidth, "height": myHeight};
}

function showLoading() {
	var xmlHttpRequestLoaderBar = document.getElementById("xmlHttpRequestLoaderBar");
	var Width = px2int(getStyle(xmlHttpRequestLoaderBar, "width"));
	var Height = px2int(getStyle(xmlHttpRequestLoaderBar, "height"));
	var windowSize = getSize();
	var xMidle = (windowSize.width / 2) - (Width / 2);
	var yMidle = (windowSize.height / 2) - (Height / 2);
	xmlHttpRequestLoaderBar.style.left = xMidle + "px";
	xmlHttpRequestLoaderBar.style.top = yMidle + "px";
	xmlHttpRequestLoaderBar.style.display = "block";

	xmlHttpRequestLoaderBar.innerHTML = "Conectando...";
	window.setTimeout(
		function() {
			xmlHttpRequestLoaderBar.innerHTML = "Aguarde, verificando...";
		}, 3000
	);
	window.setTimeout(
		function() {
			xmlHttpRequestLoaderBar.innerHTML = "Sua conexão esta lenta...";
		}, 6000
	);
}

function hideLoading() {
	var xmlHttpRequestLoaderBar = document.getElementById("xmlHttpRequestLoaderBar");
	xmlHttpRequestLoaderBar.style.display = "none";
}

function hasClass(obj, cName) {
	return new RegExp('\\b'+cName+'\\b').test(obj.className);
}

function addClass(obj, cName) {
	if (!hasClass(obj,cName)) {
		obj.className += obj.className ? ' ' + cName : cName;
	}
}

function removeClass(obj, cName) {
	if (!hasClass(obj,cName)) {
		return false;
	}
	var rep = obj.className.match(' '+cName) ? ' ' + cName:cName;
	obj.className = obj.className.replace(rep,'');
}



scriptLoader("_javascript/xmlHttpRequest.js");
//scriptLoader("_javascript/dom-drag.js");
