// função para mudar de usuário.
function changeUser(user_id,username){
	document.frm_verifica.CD_USER.value = user_id;
	document.frm_verifica.USERNAME.value = username;
	document.frm_verifica.submit();
}

function home(){
	document.frm_verifica.action = "/intranet/index.aspx";
	document.frm_verifica.submit();
}

function call_tdFocus(td,color){
	
	if(td.length>1){
		for(i=0;i<td.length;i++){
			var x = new String(td[i].id)
			var number = x.substr(3,x.length)
			
			if(color == 'WhiteSmoke'){
				var x = "day_" + (parseInt(number)+1) + ".style.background = '#eee8aa';"
				document.forms[2].mudaDia.style.visibility = 'hidden';	
			}else{
				var x = "day_" + (parseInt(number)+1) + ".style.background = 'Khaki';"
				number = parseInt(number);
				document.forms[2].mudaDia.style.visibility = 'visible';	
				document.forms[2].mudaDia.value = 'Dia:' + document.forms[2].data[number].value;
			}
			
			execScript(x,"JavaScript")
			td[i].style.background = color;
		}
	}else{
		var x = new String(td.id)
		var number = x.substr(3,x.length)

		if(color == 'WhiteSmoke'){
			var x = "day_" + (parseInt(number)+1) + ".style.background = 'lightsteelblue';"
			document.forms[2].mudaDia.style.visibility = 'hidden';	
		}else{
			var x = "day_" + (parseInt(number)+1) + ".style.background = 'LightSlateGray';"
			number = parseInt(number);
			document.forms[2].mudaDia.style.visibility = 'visible';	
			document.forms[2].mudaDia.value = 'Dia:' + document.forms[2].data[number].value;
		}
			
		execScript(x,"JavaScript")
		td.style.background = color;
	}
	
}
function call_validaInput(field){
	if(field.value == "" && field.value == 0){
		//field.value = "00:00"
		return;
	}else{
		field.value = call_formathoras(field.value.replace(",",":"));
	}
}

function soNumero(){
	if (!(event.keyCode>47 && event.keyCode<58)){
		if(event.keyCode != 44)
			event.keyCode=0;
	}
}

function call_loadfields(){

	if(document.frm_thoras.linedom.length > 1){
		for(i=0;i<document.frm_thoras.linedom.length;i++){
			if(document.frm_thoras.linedom[i].value == ''){
				document.frm_thoras.linedom[i].value = '00:00';
			}
		}
	}else{
		if(document.frm_thoras.linedom.value == ''){
			document.frm_thoras.linedom.value = '00:00';
		}
	}	
	
	if(document.frm_thoras.lineseg.length > 1){
		for(i=0;i<document.frm_thoras.lineseg.length;i++){
			if(document.frm_thoras.lineseg[i].value == ''){
				document.frm_thoras.lineseg[i].value = '00:00';
			}
		}
	}else{
		if(document.frm_thoras.lineseg.value == ''){
			document.frm_thoras.lineseg.value = '00:00';
		}
	}	
	
	if(document.frm_thoras.lineter.length > 1){
		for(i=0;i<document.frm_thoras.lineter.length;i++){
			if(document.frm_thoras.lineter[i].value == ''){
				document.frm_thoras.lineter[i].value = '00:00';
			}
		}
	}else{
		if(document.frm_thoras.lineter.value == ''){
			document.frm_thoras.lineter.value = '00:00';
		}
	}	
	
	if(document.frm_thoras.linequa.length > 1){
		for(i=0;i<document.frm_thoras.linequa.length;i++){
			if(document.frm_thoras.linequa[i].value == ''){
				document.frm_thoras.linequa[i].value = '00:00';
			}
		}
	}else{
		if(document.frm_thoras.linequa.value == ''){
			document.frm_thoras.linequa.value = '00:00';
		}
	}	
	
	if(document.frm_thoras.linequi.length > 1){
		for(i=0;i<document.frm_thoras.linequi.length;i++){
			if(document.frm_thoras.linequi[i].value == ''){
				document.frm_thoras.linequi[i].value = '00:00';
			}
		}
	}else{
		if(document.frm_thoras.linequi.value == ''){
			document.frm_thoras.linequi.value = '00:00';
		}
	}	
	
	if(document.frm_thoras.linesex.length > 1){
		for(i=0;i<document.frm_thoras.linesex.length;i++){
			if(document.frm_thoras.linesex[i].value == ''){
				document.frm_thoras.linesex[i].value = '00:00';
			}
		}
	}else{
		if(document.frm_thoras.linesex.value == ''){
			document.frm_thoras.linesex.value = '00:00';
		}
	}	
	
	if(document.frm_thoras.linesab.length > 1){
		for(i=0;i<document.frm_thoras.linesab.length;i++){
			if(document.frm_thoras.linesab[i].value == ''){
				document.frm_thoras.linesab[i].value = '00:00';
			}
		}
	}else{
		if(document.frm_thoras.linesab.value == ''){
			document.frm_thoras.linesab.value = '00:00';
		}
	}	
}

function call_sum(){
	var dom,seg,ter,qua,qui,sex,sab;
	dom = seg = ter = qua = qui = sex = sab = 0;
	//Somatória dos DOMINGOS.
	if(document.frm_thoras.linedom.length > 1){
		for(i=0;i<document.frm_thoras.linedom.length;i++){
			dom+= parseFloat(document.frm_thoras.linedom[i].value.replace(":",".")); 
		}
		document.frm_thoras.totdom.value = call_formathoras(new String(dom).replace(".",":"));
	}else{
		document.frm_thoras.totdom.value = document.frm_thoras.linedom.value;
	}	
	//Somatória dos SEGUNDAS.
	if(document.frm_thoras.lineseg.length > 1){
		for(i=0;i<document.frm_thoras.lineseg.length;i++){
			seg+= parseFloat(document.frm_thoras.lineseg[i].value.replace(":",".")); 
		}
		document.frm_thoras.totseg.value = call_formathoras(new String(seg).replace(".",":"));
	}else{
		document.frm_thoras.totseg.value = document.frm_thoras.lineseg.value;
	}	
	//Somatória dos TERÇAS.
	if(document.frm_thoras.lineter.length > 1){
		for(i=0;i<document.frm_thoras.lineter.length;i++){
			ter+= parseFloat(document.frm_thoras.lineter[i].value.replace(":",".")); 
		}
		document.frm_thoras.totter.value = call_formathoras(new String(ter).replace(".",":"));
	}else{
		document.frm_thoras.totter.value = document.frm_thoras.lineter.value;
	}	
	//Somatória dos QUARTAS.
	if(document.frm_thoras.linequa.length > 1){
		for(i=0;i<document.frm_thoras.linequa.length;i++){
			qua+= parseFloat(document.frm_thoras.linequa[i].value.replace(":",".")); 
		}
		document.frm_thoras.totqua.value = call_formathoras(new String(qua).replace(".",":"));
	}else{
		document.frm_thoras.totqua.value = document.frm_thoras.linequa.value;
	}	
	//Somatória dos QUINTAS.
	if(document.frm_thoras.linequi.length > 1){
		for(i=0;i<document.frm_thoras.linequi.length;i++){
			qui+= parseFloat(document.frm_thoras.linequi[i].value.replace(":",".")); 
		}
		document.frm_thoras.totqui.value = call_formathoras(new String(qui).replace(".",":"));	
	}else{
		document.frm_thoras.totqui.value = document.frm_thoras.linequi.value;
	}	
	//Somatória dos SEXTAS.
	if(document.frm_thoras.linesex.length > 1){
		for(i=0;i<document.frm_thoras.linesex.length;i++){
			sex+= parseFloat(document.frm_thoras.linesex[i].value.replace(":",".")); 
		}
		document.frm_thoras.totsex.value = call_formathoras(new String(sex).replace(".",":"));				
	}else{
		document.frm_thoras.totsex.value = document.frm_thoras.linesex.value;
	}	
	//Somatória dos SÁBADOS.
	if(document.frm_thoras.linesab.length > 1){
		for(i=0;i<document.frm_thoras.linesab.length;i++){
			sab+= parseFloat(document.frm_thoras.linesab[i].value.replace(":",".")); 
		}
		document.frm_thoras.totsab.value = call_formathoras(new String(sab).replace(".",":"));				
	}else{
		document.frm_thoras.totsab.value = document.frm_thoras.linesab.value;
	}	
}


function call_formathoras(hora){
	if(hora.length == 1){
		if(hora == 0){
			hora = "00:00"
		}else{
			hora = "0" + hora + ":00"
		}	
	}else if(hora.length == 2){
		if(hora == 00){
			hora = "00:00"
		}else{
			hora = hora + ":00"
		}
	}else if(hora.length == 3){
		if(hora == 00){
			hora = "00:00"
		}else{
			var index;
			index = hora.search("\:")
			hora = "0" + hora.substr(0,1) + ":" + hora.substr(index+1,hora.length) + "0";
			hora = call_completa(hora);
			
		}		
	}else if(hora.length == 4){
		if(hora == 000){
		
			hora = "00:00";
		}else{
			var index;
			index = hora.search("\:")
			if(index != -1){
				if(hora.substr(0,index).length == 1){
				
					hora = "0" + hora.substr(0,1) + ":" + hora.substr(2,hora.length);
				}else{
					hora = hora.substr(0,index) + ":" + hora.substr(index+1,hora.length);
				}
				hora = call_completa(hora);
			}else{
				hora = hora;	
			}
			
		}
	}else if(hora.length == 5){	
		hora = call_completa(hora);
	}
	return hora;
}
function call_completa(hora){
	var index, subs, completa;
	
	index = hora.search("\:")
	subs  = hora.substr(index+1,hora.length);
	
	if(index != -1){
		if(subs < 15){
			completa = hora.substr(0,2).toString() + ":00";
		}else if(subs == 15){
			completa = hora;
		}else if(subs == 30){
			completa = hora;
		}else if(subs == 45){	
			completa = hora;
		}else if(subs > 45){
			completa = parseFloat(hora.substr(0,2)) + 1 + ":00"; 
		}
	}else{
		alert('Hora Invalida');
		completa = hora;
	}
	return completa;
			   
}
function  doDelete(note_id){
	if(confirm('Confirma a exclusão da notícia?') == true){
		location.href = '/intranet/entity/men/note_delete.aspx?note_id=' + note_id;
	}
}

function expanddiv(div){
	div.style.visibility = 'visible';
	div.style.display = '';
}
function closediv(div){
	div.style.visibility = 'hidden';
	div.style.display = 'none';
}

function validaHORA(campo)
{
	var Hora = campo.value.substr(0,2);
	var Minuto = campo.value.substr(3,2);
		
	if (campo.value != null && campo.value != '')
	{
		if (Hora < '00' || Hora > '23')
		{
			alert('Campo Hora inválido!');
			campo.focus();		
			return true;
		}
		if (Minuto < '00' || Minuto > '59')
		{
			alert('Campo Hora inválido!');
			campo.focus();		
			return true;
		}	
	}
	else
	{
		return true;
		//alert('Campo Hora em branco!');
	}
}