// get cookie
function getCookie(NameOfCookie){
	if (document.cookie.length > 0) { 
		begin = document.cookie.indexOf(NameOfCookie+"="); 
	if (begin != -1){ 
		begin += NameOfCookie.length+1; 
		end = document.cookie.indexOf(";", begin);
		if (end == -1) end = document.cookie.length;
		return unescape(document.cookie.substring(begin, end)); } 
	}
	return null; 
}

// set cookie
function setCookie(NameOfCookie, value, expirehours){
	var ExpDate = new Date ();
	ExpDate.setTime(ExpDate.getTime() + (expirehours * 3600 * 1000));
	document.cookie = NameOfCookie + "=" + escape(value) + ((expirehours == null) ? ";" : "; expires=" + ExpDate.toGMTString());
}

// preload images
// simplePreload( '01.gif', '02.gif' );
function simplePreload(){
  	 var args = simplePreload.arguments;
  	 document.imageArray = new Array(args.length);
  	 for(var i=0; i<args.length; i++)
  	 {
    	 document.imageArray[i] = new Image;
    	 document.imageArray[i].src = args[i];
  	 }
}
	 
// switch images
// switchImage( 'nomeImg', '01.gif' );
function switchImage(imgName, imgSrc){
	if (document.images){
		if (imgSrc != ''){
		 document.images[imgName].src = imgSrc;
		}
	}
}

// openWindow('urlPage', 'namePopup', 'width', 'height', 'yes/no', 'yes/no');
function openWindow(mypage,myname,w,h,resizable,scrollbars){ 
	w = (Number(w) + 1);
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0; 
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0; 
	settings = 'scrollbars='+scrollbars+',resizable='+resizable+',status=no,height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition;
	win = window.open(mypage,myname,settings);
}

function MM_openBrWindow(theURL,winName,features){
  window.open(theURL,winName,features);
}

// correct date
function areCharsInList(s,list) {
	var i,c;
	for (i=0;i<s.length; i++) {
		c = s.charAt(i);
	if (list.indexOf(c) == -1)
		return false;
	}
return true;
}

function isDate(str){
	if(str.length!=10){
		return false;
	}
	if(str.charAt(2)!='/' || str.charAt(5)!='/'){
		return false;
	}
	if( !areCharsInList(str.substring(0,2)+str.substring(3,5)+str.substring(6,10), '1234567890') ){
		return false;
	}
	if(str.substring(3,5)>12){
		return false;
	}
	if(str.substring(0,2)>31){
		return false;
	}
return true;
}

function stampDate(){
	var months = new Array(12);
	months[0]  = "gennaio";
	months[1]  = "febbraio";
	months[2]  = "marzo";
	months[3]  = "aprile";
	months[4]  = "maggio";
	months[5]  = "giugno";
	months[6]  = "luglio";
	months[7]  = "agosto";
	months[8]  = "settembre";
	months[9]  = "ottobre";
	months[10] = "novembre";
	months[11] = "dicembre";
	
	var days = new Array(6);
	days[0]  = "Domenica";
	days[1]  = "Lunedì";
	days[2]  = "Martedì";
	days[3]  = "Mercoledì";
	days[4]  = "Giovedì";
	days[5]  = "Venerdì";
	days[6]  = "Sabato";
	
	var timestamp = new Date();
	
	var lday      = days[timestamp.getDay()];
	var day       = timestamp.getDate();
	var lmonth    = months[timestamp.getMonth()];
	var year      = timestamp.getYear();
	
	if ( navigator.appName == "Netscape" )
		 year=1900 + year;
	
	document.write(lday+", "+day+" "+lmonth+" "+year);
}

function returnSelection(radioButton) {
	var selection=null;
	for(var i=0; i<radioButton.length; i++) {
		 if(radioButton[i].checked) {
		   selection=radioButton[i].value;
		   return selection;
		 }
	}
	return selection; 
} 
