function janela(pagina, nome, W, H) {
	s = ",width="+W+",height="+H;
	window.open(pagina , nome, "fullscreen=0,toolbar=0,location=0,directories=0,status=1,menubar=0,, top = 10, left = 10,scrollbars=1,resizable=0"+s)
}

//#############################################################
//####             Criar mascara para o campo              ####
//####                 ####-### ou ####-####               ####
//#############################################################
function mascara(src, mask){
	var i = src.value.length;
	var saida = mask.substring(0,1);
	var texto = mask.substring(i)
	if (texto.substring(0,1) != saida){
		src.value += texto.substring(0,1);
	}
}

//#############################################################
//####    Verifica  formatação do campo como aaa@bbb.cc    ####
//####         Retorna true se for um E-Mail valido        ####
//####        Retorna false nao for um E-Mail valido       ####
//#############################################################
function IsValidEmail( Value )
{
	var i, Current, Tmp
	var Array = Value.split( '@' , 3 );

	// Se tiver mais ou menos que 1 Arroba ou nao tiver nada antes ou apos o Arroba
	if( Array.length != 2 || Array[0] == '' || Array[1] == '' )
		return false;

	Tmp = Array[0];
	// Se contiver caracteres especiais antes do Arroba
	for(i=0; i < Tmp.length ;i++)
		{
		Current =  Tmp.charAt(i);
		if( (Current < '0' || Current > '9') && (Current < 'A' || Current > 'Z') && (Current < 'a' || Current > 'z') && Current != '_' && Current != '-' && Current != '.' )
			return false;
		}

	Tmp = Array[1];
	// Se contiver caracteres especiais depois do Arroba
	for(i=0; i < Tmp.length ;i++)
		{
		Current =  Tmp.charAt(i);
		if( (Current < '0' || Current > '9') && (Current < 'A' || Current > 'Z') && (Current < 'a' || Current > 'z') && Current != '.' )
			return false;
		}
	
	Tmp = Tmp.split( '.' , 4 );
	// Se depois do arroba existir menos de 2 ou mais de 3 pontos
	if( Tmp.length != 2 && Tmp.length != 3 )
		return false;

	// Se depois do arroba existir menos de 2 ou mais de 3 pontos
	if( Tmp.length == 2 && (Tmp[0] == '' || Tmp[1] == '') )
		return false;

	// Se depois do arroba existir menos de 2 ou mais de 3 pontos
	if( Tmp.length == 3 && (Tmp[0] == '' || Tmp[1] == '' || Tmp[2] == '') )
		return false;

	return true
	}

//#############################################################
//  Function:       isEmpty(s)																								|
//  Description:    Check whether string s is empty.													|
//  Arguments:      s = document.forms[0].elemment														|
//  Returns:        true/false																								|
//#############################################################

function isEmpty(s){
	return ((s == null) || (s.length == 0))
}

//#############################################################
//  Function:       isWhitespace (s)																									|
//  Description:    Returns true if string s is empty or whitespace characters only.	|
//  Arguments:      s = document.forms[0].elemment																		|
//  Returns:        true/false																												|
//#############################################################

var whitespace = " \t\n\r";

function isWhitespace (s)
{   
		var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

function hidestatus(){
window.status = 'Doremus Alimentos'
return true
}

if (document.layers)
document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT)

document.onmouseover=hidestatus
document.onmouseout=hidestatus

//#############################################################
// ================== VALIDAÇÃO DE CPF =======================
// método: OnChange="javascript:VerificaCPF(this.value);"
//#############################################################
function VerificaCPF(pcpf) {
if (pcpf.length != 11){
	sim = false
}else{
	sim = true
}

if (sim){
i = 1;
while(pcpf.charAt(i) == pcpf.charAt(i -1) && i < 10){
i++;
}
if(i == 10){
sim=false
}else{
sim=true
}   
}

if(sim){
for (i=0; i<=(pcpf.length-1) && sim; i++){
val = pcpf.charAt(i)
if((val!="9")&&(val!="0")&&(val!="1")&&(val!="2")&&(val!="3")&&(val!="4")&&( val!="5")&&(val!="6")&&(val!="7")&&(val!="8")){
sim=false
}
}

if(sim){
soma=0
for (i=0;i<=8;i++){
val = eval(pcpf.charAt(i))
soma = soma + (val*(i+1))
}

resto = soma % 11
if (resto>9){
dig = resto -10
}else{
dig = resto
}

if (dig != eval(pcpf.charAt(9))){
sim=false
}else{
soma = 0
for (i=0;i<=7;i++){
val = eval(pcpf.charAt(i+1))
soma = soma + (val*(i+1))
}
soma = soma + (dig * 9)
resto = soma % 11
if (resto>9){
dig = resto -10
}else{
dig = resto
}

if (dig != eval(pcpf.charAt(10))){
sim = false
}else{
sim = true
}
}
}
}

if(!sim){
alert("CPF inválido");
document.form.nr_cpf.value='';
document.form.nr_cpf.focus();
}
}

//#############################################################
// ================== VALIDAÇÃO DE DATAS ======================
// método: OnChange="javascript:VerificaData(this);"
//#############################################################
function VerificaData(field){ 
var checkstr = "0123456789"; 
var DateField = field; 
var Datevalue = ""; 
var DateTemp = ""; 
var seperator = "/"; 
var day; 
var month; 
var year; 
var leap = 0; 
var err = 0; 
var i; 
err = 0; 
DateValue = DateField.value; 
/* Deleta todos os caracteres exceto 0..9 */ 
for (i = 0; i < DateValue.length; i++) { 
if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) { 
DateTemp = DateTemp + DateValue.substr(i,1); 
} 
} 
DateValue = DateTemp; 
/* Sempre modifica a data para 8 digitos*/ 
/* Se o ano for digitado com 2 digitos assume 20xx */ 
if (DateValue.length == 6) { 
DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); } 
if (DateValue.length != 8) { 
err = 1;} 
/* ano é considerado inválido se for = 0000 */ 
year = DateValue.substr(4,4); 
if (year == 0) { 
err = 1; 
} 
/* Validação do Mês */ 
month = DateValue.substr(2,2); 
if ((month < 1) || (month > 12)) { 
err = 1; 
} 
/* Validação do Dia */ 
day = DateValue.substr(0,2); 
if (day < 1) { 
err = 1; 
} 
/* Validação do ano bissexto referente ao mês de fevereiro */ 
if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) { 
leap = 1; 
} 
if ((month == 2) && (leap == 1) && (day > 29)) { 
err = 1; 
} 
if ((month == 2) && (leap != 1) && (day > 28)) { 
err = 1; 
} 
/* Validação dos outros meses */ 
if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) { 
err = 1; 
} 
if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) { 
err = 1; 
} 
/* Se não houver erro escreve a data completa no campo input com os separadores (ex. 07/01/2004) */ 
if (err == 0) { 
DateField.value = day + seperator + month + seperator + year; 
} 
/* Escreve mensagem de erro se err != 0 */ 
else { 
alert("Data Inválida!"); 
DateField.select();
DateField.value = ''; 
DateField.focus(); 
return false; 
} 
return (true); 
} 

//#############################################################
// ===== IMPRESSÃO DE CONTEÚDO DE DETERMINADA DIV =============
// método: href="javascript:imprimir_div('NOME DA DIV')" 
//#############################################################
function imprimir_div(nome){
  var ficha = document.getElementById(nome);
  var ventimp = window.open(' ', 'popimpr');
  ventimp.document.write( ficha.innerHTML );
  ventimp.document.close();
  ventimp.print( );
  ventimp.close();
}



////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 
// IsNumeric(num)
// IsDate(data) -- valida datas no formato (dd/mm/aaaa)
// Mid(string,start,length)
// Left(string,length)
// Right(string,length)
// UCase(string)
// LCase(string)
// LTrim(string)
// RTrim(string)
// Trim(string)
//
// fCvData(pData,De,Para)
//		Esta função converte formato de uma data 
//		(De / Para) cfe numeração abaixo:
//		1 - (DD/MM/AAAA)
//		2 - (MM/DD/AAAA)
//		3 - (AAAAMMDD)
//									by SuperPro
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function isNumeric(pNum){
// http://www.superpro.com.br
	if (pNum==''){
		return false;
	}
	for (var i = 0; i < pNum.length; i++){
		var ch = pNum.substring(i, i + 1);
		if (ch < '0' || '9' < ch){
			return false;
		}
	}
	return true;
}




function IsDate(pData){
// http://www.superpro.com.br

	var var_data = pData.value;



	//Andreza - 29/05/2006 - Não mostrar a mensagem quando a data não for digitada, 
	//somente se o campo não for preenchido corretamemte

	//if(var_data.length<10 || var_data.length>10)  - verificação antiga
	
	if(var_data.length>0) {
		if (var_data.length!=10) {
			alert('Data inválida\nInforme a data no formato (dd/mm/aaaa)');
			return false;
		}
	}



	var ano = '' + var_data.substring(6,10);
	var mes = '' + var_data.substring(3,5);
	var dia = '' + var_data.substring(0,2);
				
	if(dia>'31'){
		alert('Data inválida');
		pData.value = '';
		pData.focus();
		return false;
	}
				
	if(mes>'12'){
		alert('Data inválida');
		pData.value = '';
		pData.focus();
		return false;
	}

	if(mes=='02'){
		if(ano%4!=0 && dia>'28'){
			alert('Data Inválida');
			pData.value = '';
			pData.focus();
			return false;
		}
		else{
			if(dia>'29'){
				alert('Data Inválida');
				pData.value = '';
				pData.focus();				
				return false;
			}
		}
	}
	
	if(mes<='07'){
		if(mes%2==0 && dia>'30'){
			alert('Data inválida');
			pData.value = '';
			pData.focus();
			return false;
		}
	}
	else{
		if(mes>'09'){
			if(mes%2!=0 && dia>'30'){
				alert('Data inválida');
				pData.value = '';
				pData.focus();
				return false;
			}
		}
	}
				
	return true
}

function Mid(campo,x,y){
// http://www.superpro.com.br
	var res;
	if(x>0)
		x = x-1;
	if(x+y > campo.length)
		y = campo.length
	else
		y = x + y;
	res = campo.substring(x,y);
	return res;
}
	
function Left(campo,x){
// http://www.superpro.com.br
	var res;
	if(x > campo.length)
		x = campo.length;
	res = campo.substring(0,x);
	return res;
}
	
function Right(campo,x){
// http://www.superpro.com.br
	var res;
	if(x > campo.length){
		res = campo;
		return res;
	}
	res = campo.substring(campo.length-x,campo.length);
	return res;
}




//Andreza - 18/01/2007
//Funções Ucase e Lcase não funcionavam na maneira que estava
function UCase(campo){
	
	campo.value = campo.value.toUpperCase( );

}

function LCase(campo){

	 campo.value = campo.value.toLowerCase();
}




function RTrim(campo){
// http://www.superpro.com.br
	y=true;
	while(y==true){
		x = campo.length;
		if(Right(campo,1)==' '){
			campo = Left(campo,x-1);
			y=true;
		}
		else{
			y=false
		}
	}
	return campo;
}

function LTrim(campo){
// http://www.superpro.com.br
	y=true;
	while(y==true){
		x = campo.length-1;
		if(Left(campo,1)==' '){
			campo = Right(campo,x);
			y=true;
		}
		else{
			y=false;
		}
	}
	return campo;
}
	
function Trim(campo){
// http://www.superpro.com.br
	return RTrim(LTrim(campo));
}



//#############################################################
// =========== Conta a quantidade de caracteres =============== 
// ============= em um <textarea></textarea> ==================
// 
//#############################################################


	function contador_texto(campo, contador, maximo) {
		/* 
		alert(campo.value);
		alert(contador.value);
		alert(maximo);
		*/
		if (campo.value.length > maximo) // if too long...trim it!
			campo.value = campo.value.substring(0, maximo);
		// otherwise, update 'characters left' counter
		else
			contador.value = maximo - campo.value.length;
	}
	
	
	
//###### galeria de fotos
var offsetfrommouse=[15,15]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.
var currentimageheight = 270;	// maximum image size.

if (document.getElementById || document.all){
	document.write('<div id="trailimageid">');
	document.write('</div>');
}

function gettrailobj(){
if (document.getElementById)
return document.getElementById("trailimageid").style
else if (document.all)
return document.all.trailimagid.style
}

function gettrailobjnostyle(){
if (document.getElementById)
return document.getElementById("trailimageid")
else if (document.all)
return document.all.trailimagid
}


function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}


function visualizar_foto(no_imagem,no_foto,ds_foto,showthumb, no_class, width, height){

	if (height > 0){
		currentimageheight = height;
	}

	document.onmousemove=followmouse;


	newHTML = '<div style="width:400px; position:absolute; padding: 5px; background-color: #FFF; border: 1px solid #6F7DC2;">';
	newHTML = newHTML + '<h1 class=' + no_class + '>' + no_foto + '</h1>';
	newHTML = newHTML + '<div class="galeria" style="font-size:11px">' + ds_foto + '</div>';

	if (showthumb > 0){
	
		if (width > 0) {	
		
			newHTML = newHTML + '<div align="center" style="padding: 8px 2px 2px 2px;" style="background-image:url(../img/carregando.gif)"><img src="' + no_imagem + '" width="' + width + '" height="' + height + '" border="0"></div>';
		
		} else {

			newHTML = newHTML + '<div align="center" style="padding: 8px 2px 2px 2px;" style="background-image:url(../img/carregando.gif)"><img src="' + no_imagem + '" height="' + height + '" border="0"></div>';
	
		}

	}

	newHTML = newHTML + '</div>';

	gettrailobjnostyle().innerHTML = newHTML;

	gettrailobj().visibility="visible";

}

function visualizar_foto2(no_imagem,no_foto,ds_foto,showthumb, no_class, width, height){

	if (height > 0){
		currentimageheight = height;
	}

	document.onmousemove=followmouse;


	newHTML = '<div style="width:800px; position:absolute; padding: 5px; background-color: #FFF; border: 1px solid #6F7DC2;">';
	newHTML = newHTML + '<h1 class=' + no_class + '>' + no_foto + '</h1>';
	newHTML = newHTML + '<div class="galeria" style="font-size:11px">' + ds_foto + '</div>';

	if (showthumb > 0){
	
		if (width > 0) {	
		
			newHTML = newHTML + '<div align="center" style="padding: 8px 2px 2px 2px;" style="background-image:url(../img/carregando.gif)"><img src="' + no_imagem + '" width="' + width + '" height="' + height + '" border="0"></div>';
		
		} else {

			newHTML = newHTML + '<div align="center" style="padding: 8px 2px 2px 2px;" style="background-image:url(../img/carregando.gif)"><img src="' + no_imagem + '" height="' + height + '" border="0"></div>';
	
		}

	}

	newHTML = newHTML + '</div>';

	gettrailobjnostyle().innerHTML = newHTML;

	gettrailobj().visibility="visible";

}



function hide_visualizar_foto(){
	gettrailobj().visibility="hidden"
	document.onmousemove=""
	gettrailobj().left="-500px"

}

function followmouse(e){

	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	//if (document.all){
	//	gettrailobjnostyle().innerHTML = 'A = ' + truebody().scrollHeight + '<br>B = ' + truebody().clientHeight;
	//} else {
	//	gettrailobjnostyle().innerHTML = 'C = ' + document.body.offsetHeight + '<br>D = ' + window.innerHeight;
	//}

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < 380){
			xcoord = e.pageX - xcoord - 400; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < (currentimageheight + 110)){
			ycoord += e.pageY - Math.max(0,(110 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < 445){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - 80; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (currentimageheight + 110)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(110 + currentimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)
		if(ycoord < 0) { ycoord = ycoord*-1; }
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"

}
