function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function abrirs(URL, width, height) {
	window.open(URL,'Galeria', 'width='+width+', height='+height+', scrollbars=yes, status=yes, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');
}
function MM_findObj(n, d) { //v4.0
	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 && document.getElementById) x=document.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
	var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
	for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
		if (val) { nm=val.id; if ((val=val.value)!="") {
			if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
				if (p<1 || p==(val.length-1)) errors+='- '+nm+' deve conter um endereço de e-mail.\n';
			} else if (test!='R') {
				if (isNaN(val)) errors+='- '+nm+' deve conter caracteres numéricos.\n';
				if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
					min=test.substring(8,p); max=test.substring(p+1);
					if (val<min || max<val) errors+='- '+nm+' deve conter números entre '+min+' e '+max+'.\n';
		} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' deve conter dados.\n'; }
	} if (errors) alert('Verifique:\n'+errors);
	document.MM_returnValue = (errors == '');
}

function MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}

function validacpf(){ 
  
var i; 
  
s = document.cadastro.clicpf.value; 
  
var c = s.substr(0,9); 
  
var dv = s.substr(9,2); 
  
var d1 = 0; 
  
for (i = 0; i < 9; i++) 
  
{ 
  
d1 += c.charAt(i)*(10-i); 
  
} 
  
if (d1 == 0){ 
  
alert("CPF Invalido") 
document.cadastro.clicpf.focus();  
  
return false; 
  
} 
  
d1 = 11 - (d1 % 11); 
  
if (d1 > 9) d1 = 0; 
  
if (dv.charAt(0) != d1) 
  
{ 
  
alert("CPF Invalido") 
document.cadastro.clicpf.focus();  
  
return false; 
  
} 
  
  
d1 *= 2; 
  
for (i = 0; i < 9; i++) 
  
{ 
  
d1 += c.charAt(i)*(11-i); 
  
} 
  
d1 = 11 - (d1 % 11); 
  
if (d1 > 9) d1 = 0; 
  
if (dv.charAt(1) != d1) 
  
{ 
  
alert("CPF Invalido") 
document.cadastro.clicpf.focus();  
return false; 
  
} 
  
return true; 
  
} 

function moeda(cur,len)
{
   n='__0123456789';
   d=cur.value;
   l=d.length;
   r='';
   if (l > 0)
   {
	z=d.substr(0,l-1);
	s='';
	a=2;
	for (i=0; i < l; i++)
	{
		c=d.charAt(i);
		if (n.indexOf(c) > a)
		{
			a=1;
			s+=c;
		};
	};
	l=s.length;
	t=len-1;
	if (l > t)
	{
		l=t;
		s=s.substr(0,t);
	};
	if (l > 2)
	{
		r=s.substr(0,l-2)+','+s.substr(l-2,2);
	}
	else
	{
		if (l == 2)
		{
			r='0,'+s;
		}
		else
		{
			if (l == 1)
			{
				r='0,0'+s;
			};
		};
	};
	if (r == '')
	{
		r='0,00';
	}
	else
	{
		l=r.length;
		if (l > 6)
		{
			j=l%3;
			w=r.substr(0,j);
			wa=r.substr(j,l-j-6);
			wb=r.substr(l-6,6);
			if (j > 0)
			{
				w+='.';
			};
			k=(l-j)/3-2;
			for (i=0; i < k; i++)
			{
				w+=wa.substr(i*3,3)+'.';
			};
			r=w+wb;
		};
	};
   };
   if (r.length <= len)
   {
	cur.value=r;
   }
   else
   {
	cur.value=z;
   };
   return 'ok';
};
