// Funzioni JavaScript per MyVision
// $Id: myvision.js,v 1.1 2008-01-05 22:38:24 cvsuser Exp $

function mvform_mandatory(form) {
	if(document.mvform.mvFormCondtionAccept!=undefined) 
		if(!document.mvform.mvFormCondtionAccept.checked) { alert('Per continuare devi approvere i termini e le condizioni.'); return false;}
	for(var i=0;i<form.elements.length;i++) {
		if(form.elements[i].name.substr(0,1)=='_' && form.elements[i].value=="") {
			alert("Il campo "+form.elements[i].name.substr(1)+" è obbligatorio.");
			return false;
		}
	}
	return true;
}

function webmail_login (domain) {
	var new_login=document.webmail_form.imapuser.value;
	if(new_login.replace(/@/g,"")==document.webmail_form.imapuser.value) {new_login=document.webmail_form.imapuser.value+'@'+domain;document.webmail_form.imapuser.value=new_login;}
	// reload to hidden the password
	self.location = self.location;
	return true;
}

function ConfirmMessage (message,url) {
	var ret; url=unescape(url);
	message=unescape (message).replace(/\+/g," ");
	message=message.replace(/<br>/g, "\n");
	message=message.replace(/<BR>/g, "\n");
	if(confirm(message)) {this.location=url; return true;} else return false; 
}

function ImagePopUp(link, width, height) {
  var aspect; var scroll="no"; 
  if(width>750) { scroll="yes"; width=750; }
  if(height>550) { scroll="yes"; height=550; }
  aspect = "toolbar=no,status=no,location=no,scrollbars=" + scroll + ",resizable=yes,width=" + width + ",height=" + height;
  window.open (link, "_img_popup", aspect);
}

function OpenPopUp(link,x,y) {
	var l=(screen.width-x)/2; var t=(screen.height-y)/2;
	window.open(link,"_mv_popup","toolbar=no,status=no,location=no,scrollbars=no,resizable=no,width="+x+",height="+y+",top="+t+",left="+l);
}

function OpenPopUpScroll(link,x,y) {
	var l=(screen.width-x)/2; var t=(screen.height-y)/2;
	var newwin=window.open(link,"_mv_popup","toolbar=no,status=no,location=no,scrollbars=yes,resizable=no,width="+x+",height="+y+",top="+t+",left="+l);
	if(window.focus) { newwin.focus(); }
}

function DeleteOpen (link) {
	window.open(link, "_del_confirm","toolbar=no,location=no,scrollbars=yes,resizable=yes,width=400,height=150");
}

function ImageOpen(link) {
	var newwin=window.open(link,"_img_upload","toolbar=no,status=yes,location=no,scrollbars=yes,resizable=yes,width=850,height=550");
	if(window.focus) { newwin.focus(); }
}

function UploadOpen(link) {
  window.open(link, "_file_upload","toolbar=no,status=yes,location=no,scrollbars=yes,resizable=yes,width=500,height=380");
}

function HelpOpen()
{
  window.open ("mv_help.php", "_file_upload","toolbar=no,status=no,location=no,scrollbars=yes,resizable=yes,width=450, height=500");
}

function HTMLEdit (form, field, html)
{
  if (navigator.appName != "Microsoft Internet Explorer") {
    alert ("Questa opzione puo' esserere usata solo con il browser Microsoft Internet Explorer!\n(Browser in uso: " + navigator.appName + ")");
    return;
  }

  window.open ("editor/edit.php?form=" + form + "&field=" + field, "_html_editor","toolbar=no,status=no,location=no,scrollbars=yes,resizable=yes,width=650,height=500");
}

function SetHTML (form, field, html)
{
  window.document.forms[form].elements[field].value = html;
}

function EcommValidate(frm) {
	var i,f;
	for(var i=0; i<frm.elements.length;i++) {
		if(frm.elements[i].name.substr(0,1)=='_') f=frm.elements[i].name.substr(5); else f=frm.elements[i].name.substr(4);
		if(frm.elements[i].name.substr(0,1)=='_') {
			if(frm.elements[i].value.length==0) {
				alert('Il campo obbligatorio '+f+' ï¿½ vuoto');
				frm.elements[i].focus();
				return false;
			}
			else {
				if(f=='email') {
					if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(frm.elements[i].value)) return true;
					alert('Il campo non ï¿½ un indirizzo email valido');
					frm.elements[i].focus();
					return false;
				}
			}
		}
	}
	return true;
}

function MyCalendarCheck(base) {
	var week=['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];
	var months=[31,28,31,30,31,30,31,31,30,31,30,31];

	var oy=document.getElementById(base+'y');
	var om=document.getElementById(base+'m');
	var od=document.getElementById(base+'d');

	if (oy.value/4==parseInt(oy.value/4)) months[1]=29;
	if(od.selectedIndex>months[om.selectedIndex-1]) document.getElementById(base+'w').value="ERR";
	else {
		var date=new Date();
		date.setFullYear(oy.value,om.selectedIndex-1,od.selectedIndex);
		document.getElementById(base+'w').value=week[date.getDay()];
	}
}

// MyAjax
var MyLoopTimer=0; var MyLoopFuncs=new Array();

function MyLoopAddHandler(func,timeout) { var item=Array(func,timeout,0); MyLoopFuncs.push(item); }

function MyLoopStart(timer) { MyLoopTimer=timer; MyLoopHandler(); }

function MyLoopHandler() { 
	for(i=0;i<MyLoopFuncs.length;i++) { MyLoopFuncs[i][2]++; if(MyLoopFuncs[i][2]>=MyLoopFuncs[i][1]) { MyLoopFuncs[i][2]=0; if(!MyLoopFuncs[i][0]()) MyLoopFuncs.splice(i,1); i--; } }
	if(MyLoopTimer>0) setTimeout("MyLoopHandler()",MyLoopTimer);
}

function BannerRot(contid,linkid,images1,links1) {
	var images=new Array(); var links=Array();  var currIndex=0;
	var imgcont=document.getElementById(contid); var linkcont=document.getElementById(linkid);
	for(var i=0;i<images1.length;i++) { images[i]=new Image(); images[i].src=images1[i]; links[i]=links1[i]; }

	this.rotate = function() {

		if(!images.length) return;
		currIndex++;
		if(currIndex==images.length) currIndex=0; 
		imgcont.src=images[currIndex].src; linkcont.href=links[currIndex]; //alert('a'+currIndex);
		return true;
	};

};


function MyLoopBannerRot() {
	}
function DOMShowHide (objId) {
	oggetto=document.getElementById(objId);
	stato=oggetto.style.display;
	if (stato=="none") {
		oggetto.style.display="inline";
	}
	else {
		oggetto.style.display="none";
	}
}
