// JavaScript Document
function init() {
	tinyMCE.init({
				// General options
				mode : "textareas",
				language : "it",
				theme : "advanced",
				
				plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
		
				// Theme options
				
				theme_advanced_buttons1 : "bold,italic,underline,separator,undo,redo,separator,pastetext,pasteword,separator,cleanup,removeformat,separator,fullscreen,print,help",
				theme_advanced_buttons2 : "",
				theme_advanced_buttons3 : "",
				theme_advanced_buttons4 : "",
				theme_advanced_toolbar_location : "top",
				theme_advanced_toolbar_align : "left",
				theme_advanced_statusbar_location : "bottom",
				theme_advanced_resizing : true,
				theme_advanced_blockformats :"h2",
				// Example content CSS (should be your site CSS)
				content_css : "EditorStyle.css",
		
				// Drop lists for link/image/media/template dialogs
				template_external_list_url : "lists/template_list.js",
				external_link_list_url : "lists/link_list.js",
				external_image_list_url : "lists/image_list.js",
				media_external_list_url : "lists/media_list.js",
		
				// Replace values for the template plugin
				template_replace_values : {
					username : "Some User",
					staffid : "991234"
				}
			});
}

function visEl(op,id,perc){
	
	
	
    $('#boxDati').slideUp("fast");
    $.ajax({
          type: "POST",
        url: perc+".php",
           data: ({
            'op': op,
            'ID': id
        }),
        success: function(msg){
			if (tinyMCE.getInstanceById('Descr')){
				tinyMCE.execCommand("mceRemoveControl", false, 'Descr');
				
			 }else{
			 	init()
			 }
             document.getElementById("boxDati").innerHTML=msg;
             $('#boxDati').slideDown("slow");
			 tinyMCE.execCommand("mceAddControl", false, 'Descr');
        },
        error : function(XMLHttpRequest, textStatus, errorThrown){
            alert(textStatus)
        }
    });
} 

function visOrd(ID){
	
		$.ajax({
		   type: "POST",
		   url: "dettOrd.php",
		   data: ({
					'ID': ID,
					'sez': 0
				}),
		   success: function(msg){
			   	if ($('#dettOrd').css('display')=='none') {
					$('#dettOrd').html(msg)
					$('#dettOrd').toggle('slow')
				}else{
					$('#dettOrd').animate({opacity: 0}, 500,function(){
						$('#dettOrd').html(msg)
						$('#dettOrd').css('opacity', 100); 
						
					})
				}
	
		   }
		 });
	
	
}
function openSelectImg(puls,perc){
	if (!perc) perc=''
	$("#selectImageGall").html('<iframe src="../'+perc+'immagini/index.php"></iframe>')
	$('#selectImageGall').slideDown("slow")
	
	$(puls).attr('id','riceviPerc')
	$('#copriBody').fadeIn('slow')
	$('#copriBody').click(function (){
		$(this).fadeOut('slow')
		$('#selectImageGall').slideUp("slow")
	})
}
function genFat(ID){
		$.ajax({
		   type: "POST",
		   url: "dettOrd.php",
		   data: ({
					'ID': ID,
					'sez': 1
				}),
		   success: function(msg){
			   $('#genCor').html(msg);	
		   }
		 });
}
function modFat(ID){
	if (confirm("Si è certi di voler modificare questo elemento?")){
		$.ajax({
		   type: "POST",
		   url: "dettOrd.php",
		   data: ({
					'ID': ID,
					'Val': $('#numfat_inp').val(),
					'datafat': $('#datafat').val(),
					'spedito': $('#spedito').val(),
					'sez': 2
				}),
		   success: function(msg){
			   alert(msg);	
		   }
		 });
	}
}
function cancFat(ID){
	if (confirm("Si è certi di voler eliminare questo elemento?")){
		$.ajax({
		   type: "POST",
		   url: "dettOrd.php",
		   data: ({
					'ID': ID,
					'sez': 3
				}),
		   success: function(msg){
			   $('#genCor').html(msg);	
		   }
		 });
	}
}
function hideOrd(){
	$('#dettOrd').toggle('slow');
}
function cancEL(sezione,ID_stage,ID){
	if (confirm("Si è certi di voler eliminare questo elemento?")){
		location.href="edit.php?tipDati="+sezione+"&id_stage="+ID_stage+"&id="+ID;
	}
}
function cancStud(sezione,ID_stage,ID){
	if (confirm("Si è certi di voler eliminare questo elemento?")){
		document.getElementById("note"+ID_stage).style.visibility="visible"
	}
}
function riprEL(sezione,ID_stage,ID){
	if (confirm("Si è certi di voler ripristinare questo elemento?")){
		location.href="edit.php?tipDati="+sezione+"&id_stage="+ID_stage+"&id="+ID;
	}
}
function hideEl(elemento){
	if (confirm("Uscendo l'operazione non verrà eseguita. Continuare?")){
		document.getElementById(elemento).style.visibility="hidden"
	}
}
function showInfo(elemento){
		document.getElementById(elemento).style.visibility="visible"
}
function hideInfo(elemento){
		document.getElementById(elemento).style.visibility="hidden"
}
function sorta(valore){
	
	document.getElementById("sorta").value=valore;
	document.ricerca.submit();
}
function vaiPag(valore){
	$('#ricerca input[name="pag"]').val(valore);
	$('#ricerca').submit();
}
function iniziaRicerca(){
	document.getElementById("pag").value=0;
	document.ricerca.submit();
}
function cekka(nome){
	if (document.getElementById(nome).style.visibility=="hidden"){
		document.getElementById(nome).style.visibility="visible"
		document.getElementById(nome+"_inpt").value=1;
	}else{
		document.getElementById(nome).style.visibility="hidden"
		document.getElementById(nome+"_inpt").value=0;
	}
}
function salvaDati(nomeform){
	if (confirm("Stanno per essere salvate le modifiche effettuate, continuare?")){
		if (nomeform=="scheda_stud"){
			if (ceckDati(nomeform)){
				document.forms[nomeform].submit();
			}else{
				alert("compilare tutti i campi contrassegnati con *");
			}
		}else{
			document.forms[nomeform].submit();
		}
	}
}
function calcolaPerc(inputRef){
	minimo=prompt('Voto Ottenuto','')
	massimo=prompt('Voto Massimo Ottenibile','')
	document.getElementById(inputRef+"Input").value=Math.round((100*minimo)/massimo)
	allunga(inputRef)
}
function ceckDati(nomeform){
	var Ceckform=document.forms[nomeform]
	switch(nomeform){
	case "scheda_stud":
	
		if (Ceckform.eta_gg.value!="" && Ceckform.eta_mm.value!="" && Ceckform.eta_aa.value!="" && Ceckform.nome.value!="" && Ceckform.cognome.value!="" && Ceckform.anno.value!="" && Ceckform.annoIscr.value!="" && Ceckform.comune.value!="nth"){
			return true;
		}else{
			return false;		
		}
		
	break;
	}
	return false;
}
function ceckDati_CancStud(nomeform){
	if (document.forms[nomeform].note.value !=""){
		document.forms[nomeform].submit();
	}else{
		alert("Per cancellare inserire una motivazione")
	}
}

function allunga(quale){
	
	document.getElementById(quale+"Riemp").style.width=document.getElementById(quale+"Input").value+"%"
}
function aggiungiAnno(){
	valore=parseInt(document.scheda_stud.anno.value)+1
	if (valore<=5) {
		if (SelezionaOptionDaValore(document.scheda_stud.anno,valore)){
			salvaDati('scheda_stud')
		}
	}
}
function SelezionaOptionDaValore(cc,valore){
	oo = cc.options
	
  	for(i=0;i<oo.length;i++){
		//alert(oo[i].value)
    	if(oo[i].value==valore){
      		oo[i].selected=true
			return true;
		}
	}
	return false;
}
function accediSegr(){
	
	$.ajax({
		   type: "POST",
		   url: "accedicome.php",
		   data: ({
					'IDsgr': escape(document.accedicome.gestSegr.value)
				}),
		   success: function(msg){
			   
				if (msg==""){
					/*window.location.href = "http://techpro2.com/area_riservata/segreterie.php";*/
					window.location.href = "http://localhost/techpro2/area_riservata/segreterie.php";
				}else{
					alert( msg );
				}
			 
		   }
		 });
}
