
/*Fix Page Position*/
function chkPP(){
	var x = screen.width;
//alert(x);
	if (x=="800"){
		document.getElementById('global').style.marginTop='-122px';
	}
}
/*End Fix Page Position*/

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }

  return [ scrOfX, scrOfY ];

}


function popLayerAlert(parameter){

	alturaLayer = document.getElementById('popLayer').offsetHeight;
//	alert(alturaLayer);
	
	posicao = getInnerSize()[1]/2+getScrollXY()[1]-200;	

	document.getElementById('alertArea').style.display='block';
	document.getElementById('popLayer').style.marginTop=posicao+'px';

	obj2 = document.getElementById('bgGeralAlpha');
	obj3 = document.getElementById('bgGeralAlphaSob');

	obj2.style.height = altura+"px";
	obj3.style.height = altura+"px";
	return false;
}

function closePopLayer(parameter){
	document.getElementById('alertArea').style.display='none';
	setTimeout(function(){document.getElementById('alertmsg').innerHTML='';},100);
}


function getInnerSize(){
	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 [myWidth,myHeight];
}


function popLayerAlert2(parameter){

	alturaLayer = document.getElementById('popLayer2').offsetHeight;
//	alert(alturaLayer);
	
	posicao = getInnerSize()[1]/2+getScrollXY()[1]-100;	

	document.getElementById('alertArea2').style.display='block';
	document.getElementById('popLayer2').style.marginTop=posicao+'px';

	obj2 = document.getElementById('bgGeralAlpha');
	obj3 = document.getElementById('bgGeralAlphaSob');

	obj2.style.height = altura+"px";
	obj3.style.height = altura+"px";

}

function closePopLayer2(parameter){
	document.getElementById('alertArea2').style.display='none';
	setTimeout(function(){document.getElementById('msgErro').innerHTML='';},100);
}


function popLayerAlert3(parameter){

	alturaLayer = document.getElementById('popLayer3').offsetHeight;
//	alert(alturaLayer);
	
	posicao = getInnerSize()[1]/2+getScrollXY()[1]-100;	

	document.getElementById('alertArea3').style.display='block';
	document.getElementById('popLayer3').style.marginTop=posicao+'px';

	obj2 = document.getElementById('bgGeralAlpha3');
	obj3 = document.getElementById('bgGeralAlphaSob3');

	obj2.style.height = altura+"px";
	obj3.style.height = altura+"px";
	return false;
}

function closePopLayer3(parameter){
	document.getElementById('alertArea3').style.display='none';
	setTimeout(function(){document.getElementById('alertmsg3').innerHTML='';},100);
}

function isNum( caractere ){
 	var strValidos = "0123456789"
	if ( strValidos.indexOf( caractere ) == -1 )
	return false;
	return true;
} 

function validaTecla(campo, event){
	var BACKSPACE= 8;
	var key;
	var tecla;
	CheckTAB=false;
	if(navigator.appName.indexOf("Netscape")!= -1)
	tecla= event.which;
	else
	tecla= event.keyCode;
	key = String.fromCharCode( tecla);
//	alert( 'key: ' + tecla + ' -> campo: ' + campo.value);
	if ( tecla == 13 )
	return false;
	if ( tecla == 0 && !window.event )
	return true;
	if ( tecla == BACKSPACE )
	return true;
	return ( isNum(key));
}

function isEmail(email){
	var res1=!(/(\.\.)+|(__)+|(--)+/.test(email));
	var res2=(/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/.test(email));
	return (res1 && res2)
}

String.prototype.trim = function(param){
	var s;
	s=this;
	if (!s || s=="") return "";  	
	if(param=='left' || param==undefined) while((s.charAt(0)==" ") || (s.charCodeAt(0)==9) || (s.charAt(0)=='\n') || (s.charAt(0,1)=='\r')){s=s.substr(1,s.length-1);}
	if(param=='right' || param==undefined) while((s.charAt(s.length-1)==" ") || (s.charCodeAt(s.length-1)==9) || (s.charAt(s.length-1)=='\n') || (s.charAt(s.length-1)=='\r')){s=s.substr(0,s.length-1);}
	if(param=='br') s = s.split(String.fromCharCode(13)).join("");
	return s;
}

function isDate(dateStr,format){
	for (var i=0,fo,ds,d="",m="",y="";i<format.length;ds=dateStr.charAt(i),fs=format.charAt(i),((fs=="D")?d+=ds:(fs=="M")?m+=ds:(fs=="Y")?y+=ds:void(0)),i++);
	return ((!isNaN(d) && !isNaN(m) && !isNaN(y)) ? 
	((d<1||d>31) || (m<1||m>12) || ((m==4||m==6||m==9||m==11)&&d==31) || (y.toString().length<4)) ? false :
	((m == 2) ? ((d>29 || (d==29 && !((y%4)==0&&((y%100)!=0||(y%400)==0)))) ? false : true ) : true ) : false );
}

function isCPFCNPJ(str){
	str=str.replace(/[^0-9]/gi,"");
	if (str.length == 14 || str.length == 11){
		var val = str.substring(0,str.length-2);
		val+=dig(val);val+=dig(val);
		return (str==val);
	}else
		return false;
	function dig(str){
		for (var i=0,k,s=0,l=str.length;i<l;k=(l>=12)?(2+i%8):(i+2),s+=parseInt(str.charAt(l-i-1))*k,i++);
		return (((10*s)%11)%10).toString();
	}
}

function MudaCampo(f){
	if(f.value.length==f.maxLength){
  	for(var i=0;i<f.form.length;i++){
    	if(f.form[i]==f&&f.form[i+1]){f.form[i+1].focus();break}
		}
	}
}

function popLayerAlert3(parameter){

	alturaLayer = document.getElementById('popLayer3').offsetHeight;
//	alert(alturaLayer);
	
	posicao = getInnerSize()[1]/2+getScrollXY()[1]-100;	

	document.getElementById('alertArea3').style.display='block';
	document.getElementById('popLayer3').style.marginTop=posicao+'px';

	obj2 = document.getElementById('bgGeralAlpha3');
	obj3 = document.getElementById('bgGeralAlphaSob3');

	obj2.style.height = altura+"px";
	obj3.style.height = altura+"px";
	return false;
}

function closePopLayer3(parameter){
	document.getElementById('alertArea3').style.display='none';
	setTimeout(function(){document.getElementById('alertmsg3').innerHTML='';},100);
}