var activemenu;
var activepage;
var srv = "http://"+document.location.host+"/";
var activeAdminMenu;
var timCount = 0;
var slide;
var timBlogCount = 0;
var blogSlide;
var currentDisplay;

function onload() {
    
	var img9 = new Image(500, 100);
	img9.src = srv+"images/name2.jpg";
	var img10 = new Image(152, 100);
	img10.src = srv+"images/cupola.jpg";
	var img11 = new Image(230, 60);
	img11.src = srv+"images/photogallery2.jpg";
}

function intval( mixed_var, base ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: stensi
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: intval('Kevin van Zonneveld');
    // *     returns 1: 0
    // *     example 2: intval(4.2);
    // *     returns 2: 4
    // *     example 3: intval(42, 8);
    // *     returns 3: 42
    // *     example 4: intval('09');
    // *     returns 4: 9
 
    var tmp;
 
    var type = typeof( mixed_var );
 
    if(type == 'boolean'){
        if (mixed_var == true) {
            return 1;
        } else {
            return 0;
        }
    } else if(type == 'string'){
        tmp = parseInt(mixed_var * 1, 10);
        if(isNaN(tmp) || !isFinite(tmp)){
            return 0;
        } else{
            return tmp.toString(base || 10);
        }
    } else if(type == 'number' && isFinite(mixed_var) ){
        return Math.floor(mixed_var);
    } else{
        return 0;
    }
}

String.prototype.startsWith = function(str) {
	return (this.match("^"+str)==str)
}

String.prototype.endsWith = function(str) {
	return (this.match(str+"$")==str)
}

function min(x,y) {
	if(x < y)
		return x;
	else return y;
}

function max(x,y) {
	if(x > y)
		return x;
	else return y;
}

function prova(img) {
	if(navigator.userAgent.indexOf("msie") != -1) {
		var max_w = document.documentElement.clientWidth/100*90;
		var max_h = document.documentElement.clientHeight/100*96;
	}
	else {
		var max_w = window.innerWidth/100*90;
		var max_h = (window.innerHeight-10)/100*98;
	}
	
	var w = img.width;
	var h = img.height;
	
	var n_h = min(max_h, 1000);  //w:h=x:max_h => x=
	var n_w = w*n_h/h;
	
	document.getElementById('ontop').style.width = ""+n_w+"px"; 
	document.getElementById('ontop').style.height= ""+n_h+"px"; 
	document.getElementById('ontop').style.marginTop= "1%";
}

function loadBlog() {
	Nifty("div#archivio", "fixed-height small tl bl");
	if(document.getElementById('insert_message_blog') != null && document.getElementById('insert_message_blog') != "undefined") {
		var tim = setTimeout('activateSliderBlog()', 2500);
	}
}

function sliderBlog() {
	if(timBlogCount <= -4.5) {
		clearInterval(blogSlide);
		document.getElementById('insert_message_blog').style.display= 'none';
	}
	else {
		timBlogCount += -0.1;
		document.getElementById('insert_message_blog').style.top = ""+timBlogCount+"em";
	}
}

function activateSliderBlog() {
	blogSlide = setInterval('sliderBlog()', 50);
}

function redirect() {
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
        rv = parseFloat( RegExp.$1 );
        if(rv <= 6)
            location.href = srv+"ie6.html";
    }
}

var srcElementId;

function fnGetSource() {
    srcElementId = event.srcElement.id ;
}

function disableDrag() {
    alert("DIS");
    window.event.returnValue = false;
    
}

function setThumbsSize(page) {

	if(document.images) {
		for(i=0; i<document.images.length; i++) {
		    
		    //document.images[i].ondrop= 'disableDrag()';
		    document.images[i].ondragstart='disableDrag()';
		    //document.images[i].ondragenter='disableDrag()';
		    document.images[i].ondrop='disableDrag();'
		    //document.images[i].ondrop='disableDrag();'
		}
	}

	redirect();
    

	document.body.oncontextmenu= function() {
		return false;
	}
	  
	if(navigator.userAgent.toLowerCase().indexOf("msie") != -1)
		setThumbsSizeIE(page);
	else
		setThumbsSizeFF(page);
}

var debug = true; 

function right(e) { 
	if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2)) 
			return false; 
	else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) { 
		return false; 
	} 
	return true; 
} 

document.onmousedown=right; 
if (document.layers) {
	window.captureEvents(Event.MOUSEDOWN); 
	window.onmousedown=right;
}

function setThumbsSizeIE(page) {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  
  if(page=="gal") {
	document.getElementById('thumb_img').style.display = "";    
	
	var h = document.getElementById('thumb_img').height;
	var w = document.getElementById('thumb_img').width;
	var thumbHeight = min(h, min(600, ((myHeight-10)*3/5)));
	var thumbWidth = min(w, min(600, ((myWidth-10)*3/5)));
	var main_h = (myHeight-10)/100*75;

	if((myWidth-thumbWidth) > (myHeight-thumbHeight)) {
		document.getElementById('thumb_img').width = document.getElementById("thumb_img").width*thumbHeight/document.getElementById("thumb_img").height;
	}
	else
		document.getElementById('thumb_img').height = document.getElementById("thumb_img").height*thumbWidth/document.getElementById("thumb_img").width;
  }
  else if(page=="image") {
    var main_h = (myHeight-10)/100*75;
    var max_h = main_h*6/16;
    var max_w = myWidth/5;
    
    document.getElementById("photo_table").style.display = "";
    for(i=0; i<6; i++) {
	    var img = document.getElementById("img"+i);
        
        var w = img.width;
        var h = img.height;
        
        if(w < h) {
            var n_h = min(max_h, min(h, 600));  //w:h=x:max_h => x=
            var n_w = w*n_h/h;
        }
        else {
            var n_w = min(max_w, min(w,600));  //w:h=x:max_h => x=
            var n_h = h*n_w/w;
        }
        
        document.getElementById('img'+i).style.width = ""+n_w+"px"; 
	    document.getElementById('img'+i).style.height= ""+n_h+"px";
        var k = (i < 4) ? 1 : 2;
        document.getElementById('img'+i).style.marginTop= ""+intval(((main_h/2)-n_h-20)/2)+"px";
    }
    document.getElementById("photo_table").style.marginTop = ""+intval(((main_h)-main_h*0.78)/2)+"px";
    
  }
  else if(page=="single") {
  
    /*currentDisplay = getCookie("currentDisplay");
    alert(currentDisplay);
    if(currentDisplay != "") {
        
        if(currentDisplay == "comments")
            showComments();
        else 
            showDesc();
    }*/
  
    document.getElementById('single').style.display = "";
	if(document.getElementById("photo_thumb") != null) {
		Nifty("div#photo_thumb", "fixed-height small tr br"); 
    }
	if(document.getElementById("box_right") != null) {
		Nifty("div#box_right", "fixed-height small tl bl");
    }
        
	var main_h =myHeight*77/100;
	var max_h = main_h*9/10;
	
	var img = document.getElementById("single");

	var max_w = myWidth*0.5;
	
	var w = img.width;
	var h = img.height;
	
	if(w < h) {
		var n_h = min(600, min(h, max_h));  //w:h=x:max_h => x=
		var n_w = w*n_h/h;
	}
	else {
		var n_w = min(600, min(w,max_w));  //w:h=x:max_h => x=
		var n_h = h*n_w/w;
	}
	var margintop = (main_h-n_h)/2;
	document.getElementById('single').style.width = ""+intval(n_w)+"px"; 
	document.getElementById('single').style.height= ""+intval(n_h)+"px"; 
	document.getElementById('single').style.marginTop= margintop+"px";
    
	if(document.getElementById('insert_message') != null && document.getElementById('insert_message') != "undefined") {
		var tim = setTimeout('activateSlider()', 2500);
    }
	if(document.getElementById('box_right') != null) {
		var box = document.getElementById('box_right');
	}
}
else if(page == "big") {

    document.getElementById('ontop').style.display = "";
	var img = document.getElementById("ontop");

	var max_w = min(myWidth/100*90, myWidth/100*90-300);
	var max_h = (myHeight-10)/100*90;
	
	var w = min(1000, img.width);
	var h = min(1000, img.height);
    		
	if((w < h) ||  (h > max_h)) {
			var n_h = min(max_h, h);  //w:h=x:max_h => x=
			var n_w = w*n_h/h;	
	}
	else {
		var n_w = min(max_w, w);  //w:h=x:max_h => x=
		var n_h = h*n_w/w;
	}
	
	var margintop = (myHeight-n_h)/2;
	document.getElementById('ontop').style.width = ""+intval(n_w)+"px"; 
	document.getElementById('ontop').style.height= ""+intval(n_h)+"px"; 
	document.getElementById('ontop').style.marginTop= ""+margintop+"px";
				
//	prova(document.getElementById("ontop"));

	if(document.getElementById('insert_message') != null && document.getElementById('insert_message') != "undefined") {
		var tim = setTimeout('activateSlider()', 2500);
    }
    
    //Nifty("#photo_thumb");//, "tr br big");
  }
  else if(page == "home") {
    var main_h = (myHeight-10)/100*75;
    var max_h = main_h*6/16;
    var max_w = myWidth/6;

    
    document.getElementById('latest_photos').style.display = "";
    document.getElementById('brick').style.display = "";
    document.getElementById('works').style.display = "";
    for(i=0; i<4; i++) {
    
	    var img = document.getElementById("img"+i);
        
        
        var w = img.width;
        var h = img.height;
        if(w < h) {
            var n_h = min(max_h, min(h, 650));  //w:h=x:max_h => x=
            var n_w = w*n_h/h;
        }
        else {
            var n_w = min(max_w, min(w,700));  //w:h=x:max_h => x=
            var n_h = h*n_w/w;
        }
        document.getElementById('img'+i).style.width = ""+n_w+"px"; 
	    document.getElementById('img'+i).style.height= ""+n_h+"px";
        var k = (i < 4) ? 1 : 2;
        document.getElementById('img'+i).style.marginTop= ""+intval(((main_h/2)-n_h-20)/2)+"px";
        
        
        //document.getElementById('latest_photos').style.display = "";
        
    
    }
    var fav = document.getElementById('fav');
    var fav_w = fav.width;
    var fav_h = fav.height;
    var fmax_h = main_h;
    var fmax_w = (2*myWidth/5)-50;

    if(fav_w < fav_h) {
            var fn_h = min(fmax_h, min(fav_h, 600));  //w:h=x:max_h => x=
            var fn_w = fav_w*fn_h/fav_h;
    }
    else {
        var fn_w = min(fmax_w, min(fav_w,600));  //w:h=x:max_h => x=
        var fn_h = fav_h*fn_w/fav_w;
    }
    
    var wor = document.getElementById('works_thumb');
    var wor_w = wor.width;
    var wor_h = wor.height;
    var wmax_h = main_h;
    var wmax_w = (2*myWidth/5)-50;

    if(wor_w < wor_h) {
            var wn_h = min(wmax_h, min(wor_h, 600));  //w:h=x:max_h => x=
            var wn_w = wor_w*wn_h/wor_h;
    }
    else {
        var wn_w = min(wmax_w, min(wor_w,600));  //w:h=x:max_h => x=
        var wn_h = wor_h*wn_w/wor_w;
    }
    
    document.getElementById('fav').style.width = ""+fn_w+"px";
    document.getElementById('fav').style.height = ""+fn_h+"px";
    document.getElementById('works_thumb').style.width= ""+wn_w+"px";
    document.getElementById('works_thumb').style.height= ""+wn_h+"px";
    
    Nifty("div#latest_post","big br transparent");
    Nifty("div#latest_photos","big br transparent");
    Nifty("div#brick","big br transparent");
    Nifty("div#gallery_link","big br transparent");
    Nifty("div#links","big br transparent");
    Nifty("div#works","big br transparent");
  }
  
  
    
        
}

function setThumbsSizeFF(page) {
  if(page=="gal") {
	var h = document.getElementById('thumb_img').height;
	var w = document.getElementById('thumb_img').width;
	var thumbHeight = min(h, min(650, ((window.innerHeight-10)-10)*3/5));
	var thumbWidth = min(w, min(700, ((window.innerWidth-10)-10)*3/5));
	if((window.innerWidth-thumbWidth) > (window.innerHeight-thumbHeight)) {
		document.getElementById('thumb_img').width = document.getElementById("thumb_img").width*thumbHeight/document.getElementById("thumb_img").height;
        //document.getElementById('thumb_img').height = thumbHeight;
	}
	else {
		document.getElementById('thumb_img').height = document.getElementById("thumb_img").height*thumbWidth/document.getElementById("thumb_img").width;
    }
	document.getElementById('thumb_img').style.display = "";
    
  }
  else if(page=="image") {
    var main_h = (window.innerHeight-10)/100*75;
    var max_h = main_h*5/16;
    for(i=0; i<6; i++) {
	    var img = document.getElementById("img"+i);

        var max_w = window.innerWidth/5;
        
        var w = img.width;
        var h = img.height;
        
        if(w < h) {
            var n_h = min(max_h, min(h, 600));  //w:h=x:max_h => x=
            var n_w = w*n_h/h;
        }
        else {
            var n_w = min(max_w, min(w,600));  //w:h=x:max_h => x=
            var n_h = h*n_w/w;
        }
        document.getElementById('img'+i).style.width = ""+n_w+"px"; 
	    document.getElementById('img'+i).style.height= ""+n_h+"px";
        var k = (i < 4) ? 1 : 2;
        document.getElementById('img'+i).style.marginTop= ""+intval(((main_h/2)-n_h-20)/2)+"px";
    }
    document.getElementById("photo_table").style.display = "";
  }
  else if(page=="single") {
    
    /*currentDisplay = getCookie("currentDisplay");
    if(currentDisplay != "") {
        if(currentDisplay == "comments") {
            document.getElementById('description').style.display = 'none';
            document.getElementById('comment_link').style.display = 'none';
            document.getElementById('comments').style.display = '';
            document.getElementById('desc_link').style.display = '';
        }
        else {
            
            document.getElementById('comments').style.display = 'none';
            document.getElementById('desc_link').style.display = 'none';
            document.getElementById('description').style.display = '';
            document.getElementById('comment_link').style.display = '';            
        }
    }*/
        
        
	if(document.getElementById("photo_thumb") != null) 
		Nifty("div#photo_thumb", "fixed-height small tr br");
	if(document.getElementById("box_right") != null) 
		Nifty("div#box_right", "fixed-height small tl bl");
		
	if(document.getElementById('box_right') != null) {
		var box = document.getElementById('box_right');
	}
	
    var main_h =window.innerHeight*77/100;
	var max_h = main_h*9/10;
	
	var img = document.getElementById("single");

	var max_w = window.innerWidth*0.5;
	
	var w = img.width;
	var h = img.height;
	
    if(w < h) {
		var n_h = min(max_h, min(h, 600));  //w:h=x:max_h => x=
		var n_w = w*n_h/h;
	}
	else {
		var n_w = min(max_w, min(w,600));  //w:h=x:max_h => x=
		var n_h = h*n_w/w;
	}
	
	var margintop = ((main_h-n_h)/2)-20;
	document.getElementById('single').style.width = ""+n_w+"px"; 
	document.getElementById('single').style.height= ""+n_h+"px"; 
	document.getElementById('single').style.marginTop= ""+margintop+"px";
	if(document.getElementById('insert_message') != null && document.getElementById('insert_message') != "undefined") {
		var tim = setTimeout('activateSlider()', 2500);
    }
    document.getElementById('single').style.display = '';
}
else if(page == "big") {    
	var img = document.getElementById("ontop");

	var max_w = min(window.innerWidth/100*90, window.innerWidth/100*90-300);
	var max_h = (window.innerHeight-10)/100*90;
	
	var w = img.width;
	var h = img.height;
		
	if((w < h) ||  (h > max_h)) {
			var n_h = min(max_h, min(h, 1000));  //w:h=x:max_h => x=
			var n_w = w*n_h/h;	
	}
	else {
		var n_w = min(max_w, min(w,1000));  //w:h=x:max_h => x=
		var n_h = h*n_w/w;
	}
	
	var margintop = (window.innerHeight-n_h)/2;
	document.getElementById('ontop').style.width = ""+n_w+"px"; 
	document.getElementById('ontop').style.height= ""+n_h+"px"; 
	document.getElementById('ontop').style.marginTop= ""+margintop+"px";
    
    document.getElementById('ontop').style.display = '';
				
//	prova(document.getElementById("ontop"));

	if(document.getElementById('insert_message') != null && document.getElementById('insert_message') != "undefined") {
		var tim = setTimeout('activateSlider()', 2500);
    }    
  }
  else if(page == "home") {
    var main_h = (window.innerHeight-10)/100*75;
    var max_h = main_h*5/16;
    for(i=0; i<4; i++) {
	    var img = document.getElementById("img"+i);

        var max_w = window.innerWidth/6;
        
        var w = img.width;
        var h = img.height;
        
        if(w < h) {
            var n_h = min(max_h, min(h, 600));  //w:h=x:max_h => x=
            var n_w = w*n_h/h;
        }
        else {
            var n_w = min(max_w, min(w,600));  //w:h=x:max_h => x=
            var n_h = h*n_w/w;
        }
        document.getElementById('img'+i).style.width = ""+n_w+"px"; 
	    document.getElementById('img'+i).style.height= ""+n_h+"px";
        var k = (i < 4) ? 1 : 2;
        document.getElementById('img'+i).style.marginTop= ""+intval(((main_h/2)-n_h-20)/2)+"px";
    }
    var fav = document.getElementById('fav');
    var fav_w = fav.width;
    var fav_h = fav.height;
    var fmax_h = main_h;
    var fmax_w = 2*window.innerWidth/5-50;
    
    if(fav_w < fav_h) {
            var fn_h = min(fmax_h, min(fav_h, 600));  //w:h=x:max_h => x=
            var fn_w = fav_w*fn_h/fav_h;
    }
    else {
        var fn_w = min(fmax_w, min(fav_w,600));  //w:h=x:max_h => x=
        var fn_h = fav_h*fn_w/fav_w;
    }
    
    var wor = document.getElementById('works_thumb');
    var wor_w = wor.width;
    var wor_h = wor.height;
    var wmax_h = main_h;
    var wmax_w = (2*window.innerWidth/5)-50;

    if(wor_w < wor_h) {
            var wn_h = min(wmax_h, min(wor_h, 600));  //w:h=x:max_h => x=
            var wn_w = wor_w*wn_h/wor_h;
    }
    else {
        var wn_w = min(wmax_w, min(wor_w,600));  //w:h=x:max_h => x=
        var wn_h = wor_h*fn_w/wor_w;
    }
    
    document.getElementById('fav').style.width= ""+fn_w+"px";
    document.getElementById('fav').style.height= ""+fn_h+"px";
    document.getElementById('works_thumb').style.width= ""+wn_w+"px";
    document.getElementById('works_thumb').style.height= ""+wn_h+"px";
    
    document.getElementById('brick').style.display = "";
    document.getElementById('works').style.display = "";
    
    document.getElementById('latest_photos').style.display = "";
    
    Nifty("div#latest_post","big br transparent");
	Nifty("div#latest_photos","big br transparent");
	Nifty("div#brick","big br transparent");
    Nifty("div#gallery_link","big br transparent");
    Nifty("div#links","big br transparent");
    Nifty("div#works","big br transparent");
  }
}

function slider() {
	if(timCount <= -3) {
		clearInterval(slide);
		document.getElementById('insert_message').style.display= 'none';
	}
	else {
		//alert("SLIDE");
		timCount -= 0.1;
		document.getElementById('insert_message').style.top = ""+timCount+"%";
	}
}

function activateSlider() {
	//alert("ACT");
	slide = setInterval('slider()', 50);
}

function showComments() {
  document.getElementById('description').style.display = 'none';
  document.getElementById('comment_link').style.display = 'none';
  document.getElementById('comments').style.display = '';
  document.getElementById('desc_link').style.display = '';
  
  setCookie("currentDisplay", "comments");
}

function showDesc() {
  document.getElementById('comments').style.display = 'none';
  document.getElementById('desc_link').style.display = 'none';
  document.getElementById('description').style.display = '';
  document.getElementById('comment_link').style.display = '';
  
  setCookie("currentDisplay", "description");
}

function setCookie(cookieName, cookieVal) {
    document.cookie = "";
    document.cookie = cookieName+"="+cookieVal+";";
}

function getCookie(cookieName) {
    if(document.cookie.length > 0) {
        var x = document.cookie.indexOf(cookieName+"=")+cookieName.length+1;
        if(x != -1) {
            var y = document.cookie.indexOf(";", x);
            var value = document.cookie.substring(x,y);
            return value;
        }
    }
    else
        return "";
}

function loadAdmin() {
	Nifty("ul#nav a","small transparent top");
	Nifty("div#adminaction", "small bottom tr fixed-height");
}

function showThumbForDelete(path) {
	var x = new Image();
	x.src = path;
	document.getElementById('preview_thumb').src = path;
	document.getElementById("preview_thumb").width = x.width/2;
	document.getElementById("preview_thumb").height= x.height/2;
	document.getElementById('preview_admin_delete').style.display = "";
	
}

function rolloverMenuCat(catId, catName, thumbFilename, width, height) {
    var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    
    document.getElementById("thumb_img").style.display = "none";
    var main_h = (myHeight-10)*0.75;
	var thumbImg = document.getElementById('thumb_img');
	var path = location.href;
	var newSrc = path+"thumbs/"+catName+".jpg";
    thumbImg.src = newSrc;
	var imgLink = document.getElementById('imgLink_'+catId);
	if(!imgLink.src.endsWith("_o.png"))
		imgLink.src = imgLink.src.replace(/.png/, "_o.png");
        
    
        
    document.getElementById("thumb_img").style.display = "";
    //document.getElementById("thumb_img").style.top = ""+intval(((main_h)-document.getElementById('thumb_img').height)/2)+"px";
    //alert(""+intval((document.getElementById("thumb_img").height))+"px");
}

function rolloutMenuCat(catId) {
	var imgLink = document.getElementById('imgLink_'+catId);
	if(imgLink.src.endsWith("_o.png"))
		imgLink.src = imgLink.src.replace(/_o.png/, ".png");
}

function showNewCommentBox() {
	document.getElementById('new_comment_box').style.left = "33%";
	document.getElementById('new_comment_box').style.top = "33%";
	//Nifty("div#new_comment_box", "transparent small fixed-height");
	document.getElementById('new_comment_box').style.display = '' ;
}

function validate_email(field,alerttxt) {
	//with (field) {
		apos=field.indexOf("@");
		dotpos=field.lastIndexOf(".");
		if (apos<1||dotpos-apos<2) {
			alert(alerttxt);
			return false;
		}
		else {
			return true;
		}
	//}
}

function validate_required(field,alerttxt) {
	with (field) {
		if (value==null || value=="") {
			alert(alerttxt);
			return false;
		}
		else {
			return true;
		}
	}
}

function validate_form()
{
	var name = document.comment_form.elements.author.value;
	var msg = document.comment_form.msg.value;
	var email = document.comment_form.email.value;
	if(name == "" || name == null) {
		alert("Inserisci il nome!");
		document.comment_form.author.focus();
		return false;
	}
	else if (email != "" && !emailcheck(email)) {
		document.comment_form.email.focus();
		return false;
	}	
	else if(msg == "" || msg == null || msg == "Inserisci qui il tuo commento") {
		alert("Inserisci il messaggio!");
		document.comment_form.msg.focus();
		return false;
	}
	else {
		document.comment_form.submit();
	}
}

function expandBlogComment(id) {
	document.getElementById('comment'+id).style.display= '';
}

function collapseBlogComment(id) {
	document.getElementById('comment'+id).style.display= 'none';
}

function validate_comment()
{
	var name = document.post_comment.elements.author.value;
	var msg = document.post_comment.comment.value;
	var email = document.post_comment.email.value;
	if(name == "" || name == null) {
		alert("Inserisci il nome!");
		document.post_comment.author.focus();
		return false;
	}
	else if(email != "" && !emailcheck(email) ) {
		document.comment_form.email.focus();
		return false;
	}
	else if(msg == "" || msg == null || msg == "Inserisci qui il tuo commento") {
		alert("Inserisci il messaggio!");
		document.post_comment.comment.focus();
		return false;
	}
	else {
		document.post_comment.submit();
	}
}

function selectAll(area) {
	area.select();
}

function viewRequestPhoto() {
	document.getElementById('request_div').style.display= '';
}

function closeRequestPhoto() {
	document.getElementById('request_div').style.display= 'none';
}

function emailcheck(str) {

	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);

	if (str.indexOf(at)==-1){
		alert("Indirizzo email non valido!");
		return false;
	}

	else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		alert("Indirizzo email non valido!");
		return false;
	}

	else if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Indirizzo email non valido!");
		return false;
	}

	else if (str.indexOf(at,(lat+1))!=-1){
		alert("Indirizzo email non valido!");
		return false;
	}

	else if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Indirizzo email non valido!");
		return false;
	}

	else if (str.indexOf(dot,(lat+2))==-1){
		alert("Indirizzo email non valido!");
		return false;
	}

	else if (str.indexOf(" ")!=-1){
		alert("Indirizzo email non valido!");
		return false;
	}
	else
		return true;
}

function validateRequestForm() {
	var email = document.send_request.email.value;
	if(!emailcheck(email)) {
		document.send_request.email.focus();
		return false;
	}
	else
		document.send_request.submit();
}

function validateEmailForm() {
	var email = document.contact_form.email.value;
	var msg = document.contact_form.msg.value;
	if(!emailcheck(email)) {
		document.contact_form.email.focus();
		return false;
	}
	else if(msg == "") {
		document.contact_form.name.focus();
		return false;
	}
	else
		document.contact_form.submit();
}

var timContactCount = 0;
var contactSlide;

function loadContact() {
	if(document.getElementById('email_msg') != null && document.getElementById('email_msg') != "undefined") {
		var tim = setTimeout("activateSliderContact()", 2500);
	}		
}

function sliderContact() {
	if(timContactCount <= -4.5) {
		clearInterval(contactSlide);
		document.getElementById('email_msg').style.display= 'none';
	}
	else {
		timContactCount += -0.1;
		document.getElementById('email_msg').style.top = ""+timContactCount+"em";
	}
}

function activateSliderContact() {
	contactSlide = setInterval('sliderContact()', 50);
}

function confirmDelete() {
    var c = confirm("Sei sicuro di volerlo fare ? E se poi te ne penti ?");
    return c;
}

function validateEditPhotoForm() {
	var cat = document.edit_photo_form.category.selectedIndex;
	var title = document.edit_photo_form.title.value;
	var desc = document.edit_photo_form.description.value;
	if(cat == -1) {
		alert("Devi selezionare una categoria");
		return false;
	}
	else if(title == "") {
		alert("Non hai inserito il titolo!");
		document.edit_photo_form.title.focus();
		return false;
	}
	else if(desc == "") {
		alert("Non hai inserito la descrizione!");
		document.edit_photo_form.description.focus();
		return false;
	}
	else {
		var c = confirm("Vuoi proseguire?");
		return c;
	}
}