// POP UP
function popup(theURL, width, height, features) { 
	//"location=no,menubar=no,resiable=no,toolbar=no,scroollbars=yes"
	if(window.screen){
		per_ancho=(width/screen.width)*100;
		per_alto=(height/width)*100;
		win_ancho=(screen.width*per_ancho)/100;
		win_alto=(win_ancho*per_alto)/100;
		x=(screen.width-win_ancho)/2;
		y=(screen.height-win_alto)/2;
	}else{
		x=0;
		y=0;
		win_ancho=w;
		win_alto=y;
	}
	winfeatures=("top="+y+",left="+x+",width="+win_ancho+",height="+win_alto+","+features);
	window.open(theURL, 'popup', winfeatures);
}

function nada() {
   return;
}

//FLASH
function flash(versao, largura, altura, nome, modo, cor)
{
	/*
	versao = 8 .................. <- Versão do player
	largura = 200px ............. <- Largura do SWF
	altura = 200px .............. <- Altura do SWF
	id = nome ................... <- ID do arquivo
	nome = arquivo.swf .......... <- Caminho do SWF, essa opção não pode ser vazia
	modo = transparent/opaque ... <- Flash transparente ou opaco / pode ser vazia
	cor = #ffffff ............... <- Cor de fundo
	*/
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="'+largura+'" height="'+altura+'">\n');
	document.write('<param name="allowScriptAccess" value="sameDomain" />\n');
	document.write('<param name="movie" value="'+nome+'" />\n');
	document.write('<param name="wmode" value="'+modo+'" />\n');
	document.write('<param name="bgcolor" value="'+cor+'" />\n');
	document.write('<embed src="'+nome+'" wmode="'+modo+'" bgcolor="'+cor+'" width="'+largura+'" height="'+altura+'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash"/>\n');
	document.write('</object>\n');
}

// DATA - INÍCIO
function data(){

	mdata      = new Date()
	mhora      = mdata.getHours()
	mminuto    = mdata.getMinutes()
	msegundos  = mdata.getSeconds()
	mdia       = mdata.getDate()
	mdiasemana = mdata.getDay()
	mmes       = mdata.getMonth()
	mano       = mdata.getFullYear()

if(mdiasemana == 0)
	document.write("'Domingo, ");
		else if(mdiasemana == 1)
			document.write("Segunda Feira, ");
		else if(mdiasemana == 2)
			document.write("Ter&ccedil;a Feira, ");
		else if(mdiasemana == 3)
			document.write("Quarta Feira, ");
		else if(mdiasemana == 4)
			document.write("Quinta Feira, ");
		else if(mdiasemana == 5)
			document.write("Sexta Feira, ");
		else if(mdiasemana == 6)
			document.write("S&aacute;bado, ");

			document.write(+mdia+' de ');
if(mmes == 0)
	document.write("Janeiro de ");
		else if(mmes == 1)
			document.write("Fevereiro de ");
		else if(mmes == 2)
			document.write("Mar&ccedil;o de ");
		else if(mmes == 3)
			document.write("Abril de ");
		else if(mmes == 4)
			document.write("Maio de ");
		else if(mmes == 5)
			document.write("Junho de ");
		else if(mmes == 6)
			document.write("Julho de ");
		else if(mmes == 7)
			document.write("Agosto de ");
		else if(mmes == 8)
			document.write("Setembro de ");
		else if(mmes == 9)
			 document.write("Outubro de ");
		else if(mmes == 10)
			 document.write("Novembro de ");
		else if(mmes == 11)
			 document.write("Dezembro de ");
			 document.write(mano);
}
// DATA - FIM

// IS NUMERIC
//onKeyPress="return(IsNumeric(this,event))"
function IsNumeric(fld, e) 
{
	var strCheck = '0123456789';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	key = String.fromCharCode(whichCode);
	if (strCheck.indexOf(key) == -1) return false;
}

//LAYER
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_showHideLayers() { //v6.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3){
		if ((obj=MM_findObj(args[i]))!=null){
			v=args[i+2];
			if (obj.style){
				obj=obj.style;
				v=(v=='show')?'visible':(v=='hide')?'hidden':v;
			}
			if (obj.visibility=='hidden'){
				obj.visibility='visible';
			}
			else{
				obj.visibility='hidden';
			}
			
		}
	}
}

//Formata data na digitação
//onKeyPress="return(maskDT(this,event))"
function maskDT(field, e) {
	if(field.value.length == 2){
		field.value = field.value + "/";
	}
	if(field.value.length == 5 ){
		field.value = field.value + "/";
	}
	
	return IsNumeric(field, e);
}

//onKeyPress="return(maskCEP(this,event))"
function maskCEP(field, e){
    
	if(field.value.length == 5){
		field.value = field.value + '-';
	}
	
	var strCheck = '0123456789-';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	key = String.fromCharCode(whichCode);
	if (field.indexOf(key) == -1)  return false;

	return true;
}

//onKeyPress="return(maskTEL(this,event))"
function maskTEL(field, e){
    
	if(field.value.length == 2){
		field.value = field.value + ' ';
	}
	else if(field.value.length == 7){
		field.value = field.value + '-';
	}
	
	return field;//IsNumeric(field, e);
}

//onKeyPress="return(maskCPF(this,event))"
function maskCPF(field, e){
	if (field.value.length == 3) {
        field.value = field.value+'.';
    }
    if (field.value.length == 7) {
        field.value = field.value+'.';
    }
    if (field.value.length == 11) {
        field.value = field.value+ '-';
    }
    
	return IsNumeric(field, e);
}

function maskCNPJ(field, e){
	if (field.value.length == 2) {
        field.value = field.value+'.';
    }
    if (field.value.length == 6) {
        field.value = field.value+'.';
    }
    if (field.value.length == 10) {
        field.value = field.value+ '/';
    }
    if (field.value.length == 15) {
        field.value = field.value+ '-';
    }
    
	return IsNumeric(field, e);
}

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;
	
	/* Delete all chars except 0..9 */
	for (i = 0; i < DateValue.length; i++)
	{
    	if (checkstr.indexOf(DateValue.substr(i,1)) >= 0){   
			DateTemp = DateTemp + DateValue.substr(i,1);
		}
		else{ //Converte data d/m/yyyy para dd/mm/yyyy
			if (DateTemp.length==1) DateTemp='0'+DateTemp;
			else if (DateTemp.length==3) DateTemp=DateTemp.substr(0,2)+'0'+DateTemp.substr(2,1);
		}
	}

	DateValue = DateTemp;

	/* Always change date to 8 digits - string*/
	/* if year is entered as 2-digit / always assume 20xx */
	if (DateValue.length == 6){
		DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2);
	}
	if (DateValue.length != 8){
		err = 19;
	}
		
	/* year is wrong if year = 0000 */
	year = DateValue.substr(4,4);
	if ((year == 0) || (year < 1900)){
		err = 20;
	}
	
	/* Validation of month*/
	month = DateValue.substr(2,2);
	if ((month < 1) || (month > 12)){
		err = 21;
	}
	
	/* Validation of day*/
	day = DateValue.substr(0,2);
	if (day < 1){
		err = 22;
	}
	
	/* Validation leap-year / february / day */
	if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
		leap = 1;
	}
	if ((month == 2) && (leap == 1) && (day > 29)) {
		err = 23;
	}
	if ((month == 2) && (leap != 1) && (day > 28)) {
		err = 24;
	}
		
	/* Validation of other months */
	if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
		err = 25;
	}
	if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
		err = 26;
	}
	
	/* if 00 ist entered, no error, deleting the entry */
	if ((day == 0) && (month == 0) && (year == 00)){
		err = 0; day = ""; month = ""; year = ""; seperator = "";
	}
	
	/* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
	
	if 	(DateValue=='' || DateValue=='00000000'){
		err = 27;
	}

	if (err == 0) {
		DateField.value = day + seperator + month + seperator + year;
	}
	/* Error-message if err != 0 */
	else{
		alert("A data está incorreta, favor verificar novamente.");
		DateField.select();
		DateField.focus();
		return false;
	}
	return true;	
}

function validarCPF(field){ 
    CPF= field.value.replace(".","");
    CPF= CPF.replace(".","");
    CPF= CPF.replace("-","");
    CPF= CPF.replace("-","");
    //CPF=field.value;
    Ok=true; 
    if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
    CPF == "22222222222" ||	CPF == "33333333333" || CPF == "44444444444" ||
    CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
    CPF == "88888888888" || CPF == "99999999999")
        Ok=false;
    
    soma = 0;
    for (i=0; i < 9; i ++)
        soma += parseInt(CPF.charAt(i)) * (10 - i);
        
    resto = 11 - (soma % 11);
    if (resto == 10 || resto == 11)
        resto = 0;
        
    if (resto != parseInt(CPF.charAt(9)))
        Ok=false;
        
    soma = 0;
    for (i = 0; i < 10; i ++)
        soma += parseInt(CPF.charAt(i)) * (11 - i);
        
    resto = 11 - (soma % 11);
    if (resto == 10 || resto == 11)
        resto = 0;
        
    if (resto != parseInt(CPF.charAt(10)))
        Ok=false;

    return(Ok);
}

//Função que oculta ou mostra os campos do formulário
function show(){
	if (dadosShow.style.display == ""){
		dadosShow.style.display = "none";
		dadosHide.style.display = "";
	}
	else {
		dadosShow.style.display = "";
		dadosHide.style.display = "none";
	}
}


//Função para mantar o POPUP alinhado ao centro.
var x_distance = "";
var y_distance = 0;
var y_offset = 0;
function centralizaPopup() {
    y_offset = document.body.scrollTop;
    popupDetalhes.style.top = y_offset
    popupDetalhes.style.left = x_distance;
    
    popupDetalhesBack.style.top = y_offset;
    popupDetalhesBack.style.left = x_distance;
}

//Função para fechar o POPUP.
function fecharPopup(){
    if (parent.popupDetalhes.style.display == "none"){
	    parent.popupDetalhes.style.display = "block";
	    parent.popupDetalhesBack.style.display = "block";
    }else{
	    parent.popupDetalhes.style.display = "none";
	    parent.popupDetalhesBack.style.display = "none";
	    parent.document.getElementById('ifrmDetalhes').src ="#";
    }
}

//Função que muda a imagem clicada para a imagem Grande nos detalhes
function ExibirGrande(obj){
    //alert(obj.src);
    document.getElementById("ctl00_ct_imgFoto").src=obj.src;
}

//Função que redireciona para a página que lista as categorias
function Buscar(){

}

function GravarTipo(obj){
	document.getElementById("ctl00_ct_tipo").value=obj.value;
}

function MarcarOpcao(obj){
    document.getElementById("ctl00_ct_optParcela").value=obj.value;
}



function ValidarBusca()
{
    if (document.getElementById("ctl00$txtBusca").value.length>0){
	if ((document.getElementById("ctl00$txtBusca").value.length>0) &&
            (document.getElementById("ctl00$txtBusca").value.length<3)){
	        alert('Preencha no mínimo 3 (três) caractéres para realizar a busca !!!');
	        document.getElementById("ctl00$txtBusca").focus();
	        //return false;
        }
        else{
		var txtBusca=document.getElementById("ctl00$txtBusca").value;
		window.location="../busca/busca.aspx?texto="+ txtBusca;
		return false;
        }
    }
}

function checkCartao(){
    document.getElementById("ctl00_ct_rbCartao").checked=true;
}

//MENU
var anterior,subAnterior;

function menuShow(div){
	document.getElementById(div).style.display = ("none" == document.getElementById(div).style.display)  ? "block" : "none";
	
	if((anterior) && (anterior !=div)){
		document.getElementById(anterior).style.display = 'none';
	}
	if((subAnterior) && (subAnterior !=div)){
		document.getElementById(subAnterior).style.display = 'none';
	}
	 anterior = div;
}

//MENU SUB
function menuSubShow(div){
	document.getElementById(div).style.display = ("none" == document.getElementById(div).style.display)  ? "block" : "none";
	
	if((subAnterior) && (subAnterior !=div)){
		document.getElementById(subAnterior).style.display = 'none';
	}
	 subAnterior = div;
}

//onKeyDown="return goDown(ValidaForm)"
function goDown(fnc)
{
	var whichCode = (window.Event) ? event.which : event.keyCode;
	if (whichCode == 13){
		return fnc();
	}
}

//onKeyDown="return noDown()"
function noDown()
{
	var whichCode = (window.Event) ? event.which : event.keyCode;
	if (whichCode == 13){
		return false;
	}
}
