<!--//
function SwapImg(org, over){
	var tmp = over.split(".");
	eval("document." + org + ".src = 'imagens/layout/" + tmp[0] + "_over." + tmp[1] + "'");
}
function desSwap(org, over){
	eval("document." + org + ".src = 'imagens/layout/" + over + "'");
}

function AbrePopUp(sPagina,sNome,sParametros){
	window.open(sPagina,sNome,sParametros);
}

function Confirma(sMsg){
	var tmp = confirm(sMsg);
	if (!tmp) return false;
}

function AbrePopUpGaleria(varPathFotos,raiz){
	window.open(raiz + 'g_popupimg.php?img=' + varPathFotos + '&','Visualizador','toolbar=0, location=0, directories=0, status=1, menubar=0, scrollbars=0, resizable=1, width=10, height=10, top=10, left=10');
}

function AbrePopUpFoto(caminho, download, raiz){
	window.open(raiz + 'popupimg.php?caminho=' + caminho + '&download=' + download + '&','Visualizador','toolbar=0, location=0, directories=0, status=1, menubar=0, scrollbars=0, resizable=1, width=10, height=10, top=10, left=10');
}

function Obrigatorios(sForm){
	var obrigatorios = eval("sForm._obrigatorios.value");
	if (obrigatorios != ""){
		obrigatorios = obrigatorios.split(",");
		for (var i = 0; i < obrigatorios.length; i++){
			if (eval("sForm." + obrigatorios[i] + ".value") == ""){
				alert("Campo obrigatório não preenchido!");
				eval("sForm." + obrigatorios[i] + ".focus();");
				return false;
				break;
			}
		}
	}
}

function ValidaEmail(Wparam){
	if (Wparam.value != ""){
		if (Wparam.value.indexOf('@', 0) == -1 || Wparam.value.indexOf('.', 0) == -1) { 
			alert("E-mail invalido!");
			Wparam.focus()
			return false;
		}
	}
}

function PulaCampo(campo,qt,proximo){
	if (campo.value.length == qt) document.getElementById(proximo).focus();	
}



function check_date(field,atual){
	if (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; 
		var dataatual = atual.split("-");
		
		err = 0; 
		DateValue = DateField; 
		/* 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; 
		} 
		
		if (year == dataatual[0]){
			if (month > dataatual[1]) {
				err = 1;
			} else if (month == dataatual[1]) {
				if (day >= dataatual[2]){
					err = 1;
				}
			}
		}else if (year > dataatual[0]){
			err = 1;
		}
		
		/* Se não houver erro escreve a data completa no campo input com os separadores (ex. 07/01/2004) */ 
		if (err != 0) {  
			alert("Data Inválida!!!"); 
			//DateField.select(); 
			//DateField.focus(); 
			return false; 
		} 
		return (true); 
	}else{
			alert("Informe a data");
			return false
	}
} 


function check_cpf(numcpf){
	x = 0;
	soma = 0;
	dig1 = 0;
	dig2 = 0;
	texto = "";
	numcpf1="";
	len = numcpf.length; x = len -1;
	// var numcpf = "12345678909";
	for (var i=0; i <= len - 3; i++) {
		y = numcpf.substring(i,i+1);
		soma = soma + ( y * x);
		x = x - 1;
		texto = texto + y;
	}
	dig1 = 11 - (soma % 11);
	if (dig1 == 10) dig1=0 ;
	if (dig1 == 11) dig1=0 ;
	numcpf1 = numcpf.substring(0,len - 2) + dig1 ;
	x = 11; soma=0;
	for (var i=0; i <= len - 2; i++) {
		soma = soma + (numcpf1.substring(i,i+1) * x);
		x = x - 1;
	}
	dig2= 11 - (soma % 11);
	if (dig2 == 10) dig2=0;
	if (dig2 == 11) dig2=0;
	//alert ("Digito Verificador : " + dig1 + "" + dig2);
	if ((dig1 + "" + dig2) == numcpf.substring(len,len-2)) {
		return true;
	}
	alert ("Numero do CPF invalido !!!");
	return false;
}

function findPosition( oElement ) {
	if( typeof( oElement.offsetParent ) != 'undefined' ) {
		for( var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent ) {
			posX += oElement.offsetLeft;
			posY += oElement.offsetTop;
		}
		return { x:posX, y:posY };
	} else {
		return { x:oElement.x, y:oElement.y };
	}
}

function applyPosition(ids){
	var mId = ids.split(",");
	
	for (i = 0; i < mId.length; i++){
		var menu = null;
		var imag = null;

		try{
			menu = document.getElementById("menu" + mId[i]);
			imag = document.getElementById("img" + mId[i]);
			
			menu.style.left = findPosition(imag).x + "px";
			menu.style.top = (findPosition(imag).y + imag.offsetHeight) + "px";
		} catch (e){}
	}
}

function showSubMenu(id){
	try {
		applyPosition(id);
		document.getElementById("menu"+id).style.display='';
	} catch(e) { }
}
function hiddeSubMenu(id){
	try {
		document.getElementById("menu"+id).style.display='none';
	} catch(e) { }
}

function abrirLinkSebrae(){

	if(document.forms[0].lnk_estadual.value != '')

		open(document.forms[0].lnk_estadual.value,'','');

	else

		alert("Escolha um estado!");

}

function SomenteNumero(e){
    var tecla=(window.event)?event.keyCode:e.which;
    if((tecla > 47 && tecla < 58)){
		return true;
	}else{
    	if (tecla != 8){
			return false;
		}else{
			return true;
		}
    }
}

function SomenteNumeroFloat(e){
    var tecla=(window.event)?event.keyCode:e.which;
    if((tecla > 47 && tecla < 58)){
		return true;
	}else{
    	if (tecla != 8 && tecla != 44){
			return false;
		}else{
			return true;
		}
    }
}

function CheckDate(pObj) {
  if (pObj.value != ""){
	  var expReg = /^((0[1-9]|[12]\d)\/(0[1-9]|1[0-2])|30\/(0[13-9]|1[0-2])|31\/(0[13578]|1[02]))\/(19|20)?\d{2}$/;
	  var aRet = true;
	  if ((pObj) && (pObj.value.match(expReg)) && (pObj.value != '')) {
		var dia = pObj.value.substring(0,2);
		var mes = pObj.value.substring(3,5);
		var ano = pObj.value.substring(6,10);
		if ((mes == 4 || mes == 6 || mes == 9 || mes == 11 ) && dia > 30)
		  aRet = false;
		else
		  if ((ano % 4) != 0 && mes == 2 && dia > 28)
			aRet = false;
		  else
			if ((ano%4) == 0 && mes == 2 && dia > 29)
			  aRet = false;
	  }  else
		aRet = false;
		
	  if (!aRet){
		alert("Data inválida!");
		pObj.focus();
	  }
  }
}

function MaskField(o,f) {
    v_obj = o;
    v_fun = f;
    setTimeout("ExecMask()",1);
}

function ExecMask() {
    v_obj.value = v_fun(v_obj.value);
}

function Data(v){
    v=v.replace(/\D/g,"");                    
    v=v.replace(/(\d{2})(\d)/,"$1/$2");      
    v=v.replace(/(\d{2})(\d)/,"$1/$2");      
                                            
    v=v.replace(/(\d{2})(\d{2})$/,"$1$2");
    return v;
}

function Mascara_Hora(Hora){ 
	var hora01 = ''; 
	hora01 = hora01 + Hora.value; 
	if (hora01.length == 2){ 
		hora01 = hora01 + ':'; 
		Hora.value = hora01; 
	} 
	if (hora01.length == 5){ 
		hrs = (Hora.value.substring(0,2)) * 1; 
		min = (Hora.value.substring(3,5)) * 1; 
		
		if (hrs < 00 || hrs > 23 || isNaN(hrs)){
			alert("Hora Inválida");
			Hora.focus();
		}else if (min < 00 || min > 59 || isNaN(min)){
			alert("Hora Inválida");
			Hora.focus();
		}
		
	} 
} 
//-->