// JavaScript Document

function setUR(ur){

	location.href="index.php?op=110&pr=adm&chur="+ur+"&page=1";

}

function setUR2(ur){

	location.href="index.php?op=110&pr=ver&chur="+ur+"&page=1";

}

function cargaPagina(div,page){

	ajax_loadContent(div,page);


}

function esEmail(texto) { 

	var textoStr = texto.toString() // transformo a string todo el campo

	var tiene = 0

	for(var i = 0;i < texto.length;i++){ // recorro letra por letra

		var oneChar = textoStr.charAt(i) 

		if (oneChar == "@"){ // busco una arroba en cada letra

			tiene = 1 

		}

	}

	if (tiene == 1){ // controlo si existe o no una arroba

		return true 

	}else{ 

		alert("El Email no es valido") 

		return false 

	} 

}

function valida() {

	if(document.datos.numUO.value.length == 0) {

		alert("Es necesario asignar un Número a la Unidad Organizacional");

		return false;

	}

	if(document.datos.nombre.value.length == 0) {

		alert("Es necesario ingresar el Nombre de la Unidad Organizacional");	

		return false;

	}

	if(document.datos.pass1.value.length == 0 || document.datos.pass2.value.length == 0) {

		alert("Es necesario ingresar y confirmar la contraseña");	

		return false;

	}

	if(document.datos.pass1.value.length!=0 && document.datos.pass2.value.length!=0) {

		var p1=document.datos.pass1.value.length;

		var p2=document.datos.pass2.value.length;

		var pass1=document.datos.pass1.value;

		var pass2=document.datos.pass2.value;

		

		if(p1==p2) {

			

			for(i=0;i<p1;i++) {

				var c1=pass1.charAt(i);

				var c2=pass2.charAt(i);

				

				if(c1!=c2){

					alert('Contraseña incorrecta. Confirme nuevamente.');

					return false;

				}

			}

		}

		else{ 

			alert("Contraseña incorrecta. Confirme nuevamente.");

			return false;

		}

	}

	if(document.datos.ur.value == 0) {

		alert("Es necesario seleccionar una Unidad Regional");	

		return false;

	}

	if(document.datos.responsable.value.length == 0) {

		alert("Es necesario ingresar un Responsable");	

		return false;

	}

	if(!esEmail(document.datos.correo.value)) {

		return false;

	}

	return true;

}

function abre(url){

	w=600;

	h=400;

	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;

	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;

	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+'status=no';

	miPopup = window.open(url,"miwin",settings);

    miPopup.focus();

}

function ff(fecha){

	var nfecha=fecha.split("-");	

	var anio=parseFloat(nfecha[0])+4;

	var mynfecha=anio+"-"+nfecha[1]+"-"+nfecha[2];

	document.getElementById('f_fin').innerHTML=mynfecha;

}

function mostrar(id,op){

	if(op==1){

		document.getElementById(id).style.display="block";	

	}else{

		document.getElementById(id).style.display="none";	

	}

}

function crea_ciclo(){

	f1=document.getElementById('f_ini').value;

	f1=f1.split('-');

	f1=f1[0];

	f2=document.getElementById('f_fin').value;	

	f2=f2.split('-');

	f2=f2[0];

	var datos="";

	for(i=f1; i<=f2; i++){

		datos+="<h4>"+i+"</h4><select name='select"+i+"'>";

		for(j=1;j<=4;j++){

			datos+="<option value='"+j+"'>"+j+"</option>";

		}

		datos+="</select>"

	}

	document.getElementById("crea_ciclo").innerHTML=datos;

}



function modal(t){

	if(t=="in"){

		document.getElementById('blackboard').style.display="block";

		document.getElementById('msgbox').style.display="block";

	}

	if(t=="out"){

		document.getElementById('blackboard').style.display="none";

		document.getElementById('msgbox').style.display="none";

		document.getElementById('msgContent').innerHTML="";

	}

}
function hide(obj){
	obj.style.display='none';	
}
function show(obj){
	obj.style.display='block';	
}
function validar()
		   {
		      if(document.form1.pregunta.value.length == 0  ){
			    alert('Es necesario definir una pregunta para la encuesta');
				return false;				
			  }
			  var ch=6;
			  if(document.form1.opcion1.value==""){
			  	ch--;
			  }
			  if(document.form1.opcion2.value==""){
			  	ch--;
			  }
			  if(document.form1.opcion3.value==""){
			  	ch--;
			  }
			  if(document.form1.opcion4.value==""){
			  	ch--;
			  }
			  if(document.form1.opcion5.value==""){
			  	ch--;
			  }
			  if(document.form1.opcion6.value==""){
			  	ch--;
			  }
			  if(ch<2){
			   alert('Es necesario definir como minimo dos opciones para la encuesta');
				return false;
			  }
			}
function showBitacora(id){
	modal('in');
	page='includes/bitacoraDesc.php?id='+id;
	ajax_loadContent('msgContent',page);
}
function editBitacora(){
	hide($('edtBt'));
	show($('gdBt'));
	$('descBitacora').removeAttribute("readonly");
	$('descBitacora').style.backgroundColor="#ffffff";
}
function guardarBitacora(id){
	descripcion=$('descBitacora').value;
	page='includes/bitacoraEdit.php?id='+id+'&descripcion='+descripcion+'&type=1';
	ajax_loadContent('result',page);
	$('descBitacora').setAttribute("readonly","readonly");
	$('descBitacora').style.backgroundColor="#efefef";
	hide($('gdBt'));
	show($('edtBt'));
}
function marcarBitacora(id){
	page='includes/bitacoraEdit.php?id='+id+'&type=2';
	ajax_loadContent('status',page);
	hide($('gdBt'));
	hide($('edtBt'));
}
function carga_msgbox(page){
		modal('in');
		ajax_loadContent('msgContent',page);
		
}
