//////// 
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


//////// abrir pop up centralizado
function NewWindow(mypage, myname, w, h, scroll) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',noresizable'
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

//////// abrir pop up Metodologia
function Metodologia() {
var w = 800
var h = 500
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=no,noresizable'
win = window.open('http://www.cbtanet.com.br/apresentacao_metodologia.asp', 'Metodologia', winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

//////// abrir pop up PMBoK
function PMBoK() {
var w = 900 //Tamanho mínimo deve ser 900 para caber as imagens
var h = 600 //Tamanho mínimo deve ser 600 para caber as imagens
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=no,resizable'
win = window.open('http://www.cbtanet.com.br/pmbok/principal.htm', 'PMBoK', winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}


//////// validação para formulários

function Validar_Email(email)
{
	if(email.length < 6) {
		return false;
	}
	var x = 0;
	for (var c=0;c<email.length;c++) {
		if (email.substring(c,c+1) == '@') {
			x = c;
		}
	}
	var y = 0;
	if (x > 0) {
		for (c=x;c<email.length;c++) {
			if (email.substring(c,c+1)=='.') {
				y = c;
				var valida = 1;
			}
		}
		if (y > 0) {
			var dominio = '';
			for (c=x;c<y;c++) {
				dominio = dominio + email.substring(1,c);
			}
		}
	}
	else {
		return false;
	}					
	if (y <= x+2){
		return false;
	}				
	if (valida == 1){
		return true;
	}
}

function Validar_CNPJ()
{
	cnpj = Limpa(document.form.cnpj.value);
	if(cnpj == 0) {
		return (false);
	}
	else {
		g = cnpj.length-2;
		if(Testar_Cnpj(cnpj,g) == 1) {
			g = cnpj.length-1;
			if(Testar_Cnpj(cnpj,g) == 1) {	
				return (true);
			}
			else {
				return (false);
			}
		}
		else {
			return (false);
		}
	}
}



function Mascarar_Telefone(objeto,tammax,teclapres)
{
	var tecla = teclapres.keyCode;
	vr = objeto.value;
	vr = vr.replace( "(", "" );
	vr = vr.replace( ")", "" );
	vr = vr.replace( " ", "" );
	vr = vr.replace( "-", "" );
	tam = vr.length;
	if (tam < tammax && tecla != 8) {
		tam = vr.length + 1 ;
	}
	if (tecla == 8 ) {
		tam = tam - 1 ;
	}
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) {
		if ( tam <= 4 ) { 
	 		objeto.value = vr ;
		}
	 	if ( (tam > 4) && (tam <= 8) ) {
	 		objeto.value = vr.substr(0,tam-4) + '-' + vr.substr( tam - 4, tam ) ;
		}
	 	if ( (tam >= 9) && (tam <= 10) ) {
			objeto.value = '(' + vr.substr(0,2) + ') ' + vr.substr(2,tam-6) + '-' + vr.substr(tam-4,tam) ;			
		}
	}		
}

function Mascarar_CNPJ(keypress, objeto)
{
	campo = eval (objeto);
	caracteres = '1234567890';
	if ((caracteres.search(String.fromCharCode (keypress)) == -1) || (keypress == 36) || (keypress == 41) || (keypress == 46) || (keypress == 94) || (keypress == 124)) {
		event.returnValue = false;
	}
	else {
		if (campo.value.length == 2 ) { 
			campo.value = campo.value;
			campo.value = campo.value + '.';
		}
		if (campo.value.length == 6 ) { 
			campo.value = campo.value;
			campo.value = campo.value + '.';
		}
		if (campo.value.length == 10 ) { 
			campo.value = campo.value;
			campo.value = campo.value + '/';
		}
		if (campo.value.length == 15 ) { 
			campo.value = campo.value;
			campo.value = campo.value + '-';
		}
	}
}

function Mascarar_Data(keypress, objeto)
{
	campo = eval (objeto);
	caracteres = '1234567890';
	if ((caracteres.search(String.fromCharCode (keypress)) == -1) || (keypress == 36) || (keypress == 41) || (keypress == 46) || (keypress == 94) || (keypress == 124)) {
		event.returnValue = false;
	}
	else {
		if (campo.value.length == 2 ) { 
	 		campo.value = campo.value;
	 		campo.value = campo.value + '/';
		}
		if (campo.value.length == 5 ) { 
	 		campo.value = campo.value;
	 		campo.value = campo.value + '/';
		}
	}
}


//////// botao direito do mouse
function ObjParaCopiaIE5(id)
{
	this.id = id;
	this.Iniciar = function() {
		document.oncontextmenu = this.Botao;
	}
	this.Botao = function() {
		if(document.all) {
			window.event.cancelBubble = true;
			window.event.returnValue = false;
		}
		return false;
	}
	this.Iniciar();
}

//var pcc5 = new ObjParaCopiaIE5("pcc5");



//////// Elimina marca no Flash

// When the page loads: 
window.onload = function(){ 
if (document.getElementsByTagName) { 
// Get all the tags of type object in the page. 
var objs = document.getElementsByTagName("object"); 
for (i=0; i<objs.length; i++) { 
// Get the HTML content of each object tag 
// and replace it with itself. 
objs[i].outerHTML = objs[i].outerHTML; 
} 
} 
} 
// When the page unloads: 
window.onunload = function() { 
if (document.getElementsByTagName) { 
//Get all the tags of type object in the page. 
var objs = document.getElementsByTagName("object"); 
for (i=0; i<objs.length; i++) { 
// Clear out the HTML content of each object tag 
// to prevent an IE memory leak issue. 
objs[i].outerHTML = ""; 
} 
} 
} 
