//valore del mese e dell'anno, e l'oggetto dei giorni

//questa inoltre mi aggiorna un campo hidden dove c'è il parametro,cosi da nn dover ogni volta impazzire!
/**formato gg/mm/aaaa 
*/
function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}


function checkArray(){
var j;
var k=0;

for (j=0;j<3;j++){
	if (array[j]!='images/spacer.gif \" height=\"100'){
		nuovo[k]=array[j];
		k++;
		}
	}
	if(nuovo[0]==undefined)
		return false;
	else {
		//array[]=nuovo;
		return true;
	}
}
function ruota(){
	//alert(i);
	var ogg=findObj('immagine');
	if(checkArray()){ //se c'è almeno un'immagine
		if(nuovo[i-1]==undefined) 
			i=1;
		ogg.src=nuovo[i-1];
		i++;
		if(i==4)i=1;
		}
	else {
			window.clearInterval();
			return false;
		}
	}

var ref
function openwin(url,x,y)
 {
 ref=window.open(url,'url','width='+x+',height='+y+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=yes,screenX=0,screenY=0,top=0,left=0');
 ref.focus();
 }


function aggiornaText(label,value){
label.value=value;
}


function aggiornaData(giorniSel,mese,anno){
	giorno=giorniSel.value;
	var data=new Date(anno,mese-1,giorno);
	//getMonth
	//giorni del mese.
	var data1=new Date(anno,mese,0);
	//parte da zero..
	var giorniCorrenti=giorniSel.length; //quanti giorni ho adesso
	var giorni=data1.getDate();//giorno del mese selezionato..
	while(giorni<giorniCorrenti){ //devo togliere giorni..
		giorniSel.options[giorniCorrenti-1]=null;//lo tolgo
		giorniCorrenti--;//adesso ho meno giorni.
	}
	while(giorni>giorniCorrenti){ //devo aggiungere giorni..
		giorniSel.options[giorniCorrenti]=new Option(giorniCorrenti+1);//lo tolgo
		giorniSel.options[giorniCorrenti].value=giorniCorrenti+1;
		giorniCorrenti++;//adesso ho meno giorni..
	}
	if(giorno >giorni){
		giorniSel.options[giorni-1].selected=true;
	}
}

//ritorna l'oggetto che vogliamo vedere dall'id (per vari browser
function getObj(name)
{
	var obj;
  if (document.getElementById)
  {
    	obj = document.getElementById(name);
  }
  else if (document.all)
  {
    obj = document.all[name];
  }
  else if (document.layers)
  {
   	obj = document.layers[name];
  }
	return obj;
}

function prendiColore(nome_oggetto,link){
oggetto=getObj(nome_oggetto);
var cp2=new ColorPicker('window');
cp2.select(oggetto,link);
}


function cambia_hidden(name){
	obj=this.getObj(name);
	obj.style.visibility=(obj.style.visibility=='visible')?'hidden':'visible';

}

function check(field)
{
for (i = 0; i < field.length; i++)
{
field[i].checked = true;
}
}

function decheck(field)
{
for (i = 0; i < field.length; i++)
{
field[i].checked = false;
}
}

/**
 * Checks/unchecks all tables
 *
 * @param   string   the form name
 * @param   boolean  whether to check or to uncheck the element
 *
 * @return  boolean  always true
 */
function setAllRadio(the_form,the_element,value_check)
{
	if(typeof(the_form)!='object'){
		var obj=getObj(the_form);//adesso ho l'oggetto form
	}else{
		obj=the_form;
	}
	while(obj!=null && obj.tagName!='FORM'){//salgo in qualsiasi caso
		obj=obj.parentNode;
		}
	if(obj==null)return;
	for(var i=0;i<obj.elements.length;i++){//tutti gli input del form
		oggetto=obj.elements[i];
		if(oggetto.tagName=='INPUT'){
			if(oggetto.name.indexOf(the_element+'[')==0 && oggetto.disabled==false){//quelli disabilitati li lascio stare
				if(oggetto.value==value_check)oggetto.checked=true;
				}
			}		
	}
	return;
} // end of the 'setCheckboxes()' function

function showObject(obj, level) {
	var l = '';
	var tmp = '';
	for(var a = 0; a < level; a++)
		l += '[_]';
	for(var a in obj) {
		var type = typeof(obj[a]);
		if(type == 'object')
			tmp += showObject(obj[a], (level + 1));
		else
			tmp += l + ' [' + typeof(a) + '] ' + a + ' = value: ' +
			obj[a] + ' < ' + type + '\n';
	}
	return tmp;
}

function initEditor_old(testo,width,height) {
var editor=null;
obj=getObj(testo);
if(obj==null){
	return;
	}
  editor = new HTMLArea(testo);
  //editor.registerPlugin(ContextMenu);
   editor.registerPlugin(TableOperations);
config=editor.config;
config.toolbar = [
[ "fontname", "space",
  "fontsize", "space",
  "copy", "cut", "paste", "space"
 ],

["justifyleft", "justifycenter", "justifyright", "justifyfull", "separator",
 "insertorderedlist", "insertunorderedlist", "outdent", "indent", "separator",
  "bold", "italic", "underline"],

[ "forecolor", "hilitecolor", "textindicator", "separator",
  "inserthorizontalrule", "createlink", "insertimage",  "htmlmode", "separator", "undo", "redo" ,
]
];
config.width = height+'px';
config.height = height+'px';
config.pageStyle =
  'body { background-color:#FFFFFF; color: black; width:100%;}';

  // comment the following two lines to see how customization works
  editor.generate();
  return false;
  }

function controllaMail(mail){
	n=mail.lastIndexOf("@");
IF(N>0 && (mail.lastIndexOf(".")>n) && mail.length>7)
	return true;
return false;
}

function checkForm(){	
	obj=getObj('email');
	if(!getObj('tratt_dati').checked){
		alert('Autorizzare il trattamento dei dati personali per inviare la richiesta');
		getObj('tratt_dati').style.backgroundColor='blue';
		return false;
	}
	if((getObj('nome')).value==''){
		alert('Nome non inserito');
		getObj('nome').style.borderColor='blue';
		return false;
	}
	if((getObj('cognome')).value==''){
		alert('Cognome non inserito');
		getObj('cognome').style.borderColor='blue';
		return false;
	}
	if(!controllaMail(obj.value)){
		alert('Mail non valida');
		getObj('email').style.borderColor='blue';
		return false;
		}
		return true;
}

function aggiungiSottomenu(id){
	parent=getObj('id_parent_new');
	bottone=getObj('id_text_new');
	parent.value=id;
	bottone.focus();
	bottone.style.border='1px solid red';
	alert('Scrivere il nome del sottomenu e premere invio o \'ok\'');
}


function login_md5(){
var md5=getObj('login_password');
var md51=md5.value;
md51=hex_md5(md51);
var md5_str=getObj('md5_password');
md5_str.value=md51;
(getObj('login_type')).value=1;
md5.value='';
submit();
return false;
}

function initEditor(name,width,height) {
//	if(getObj(name)==null)return;
	var oFCKeditor = new FCKeditor(name) ;
	this.nome_combo=new Array();
	this.arrComboItems=new Array();
	if(this.select){
		//nome_combo='personalizza';
/*		nome_combo=new Array('personalizza','pippo');
		etichette_combo=new Array('Utenti','Tag');*/
		valori_combo=new Array();
		nome_combo.push('personalizza');
		for(x in this.select){
			valori_combo.push(new Array(this.select[x],x));
			//	alert(x);		//Nome
			//	alert(this.select[x]);	//Tag

			}
		this.arrComboItems.push(valori_combo);
	}

	if(this.tag){
		valori_combo=new Array();
		nome_combo.push('tag');
		for(x in this.tag){
			valori_combo.push(new Array(this.tag[x],x));
		}
		this.arrComboItems.push(valori_combo);
	}

	
	//this.arrComboItems=new Array(valori_combo,new Array(new Array('prova1','pipo1'),new Array('prova2','ciccio')));
	this.baseurl=document.URL.substring(0,document.URL.lastIndexOf("/")+1);
        oFCKeditor.BasePath = "/FCKeditor/" ;
	oFCKeditor.Config['FontNames']= 'Trebuchet MS;Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana' ;
	oFCKeditor.Config['FontSizes']= '1/xx-small(1);2/x-small(2);3/small(3);4/medium(4);5/large(5);6/x-large(6);7/xx-large(7)' ;
	oFCKeditor.Config[ "DefaultLanguage" ] = "it-IT";
	oFCKeditor.Height =height;
	oFCKeditor.Width =width;
	oFCKeditor.Config['CustomConfigurationsPath'] = 'myconfig.js';
	oFCKeditor.ToolbarSet = 'wf' ;
	oFCKeditor.Config['SkinPath']='skins/office2003/'
	oFCKeditor.ReplaceTextarea() ;
}

function ReplaceAllTextareas(width,height) {
// replace all of the textareas
 var allTextAreas = document.getElementsByTagName("textarea");

  for (var i=0; i < allTextAreas.length; i++) {
 initEditor(allTextAreas[i].name,width,height);
 }
 }
