//AJAX call with prototype

function ajax_loadContent(where, url){
	new Ajax.Request(url,
		{
			method:'get',
			onSuccess: function(req){
				document.getElementById(where).innerHTML = req.responseText;
			},
			onFailure: function(){
				document.getElementById(where).innerHTML = "<p style='text-align:center;'>Error while loading ajax response</p>";
			}
		}
	);
}
function ajax_addContent(where, url){
	new Ajax.Request(url,
		{
			method:'get',
			onSuccess: function(req){
				document.getElementById(where).innerHTML = req.responseText
			}
		}
	);
}

//validate form

function validateForm(formname) { 
	var valid=new Validation(formname,{onSubmit:false,useTitles:true});
	return valid.validate();
}

//SCROLL DIV

var scrollinterval;
var scrollspeed=50;
var scrollheight=15;
new Event.observe(window, "load", loadScroll);
new Event.observe(window, "load", loadScroll2);

function loadScroll(){
	if($("scrollable").scrollHeight==$("scrollable").offsetHeight){
		$("scrollnav").style.display="none";
	}else{
		Event.observe($("scrollup"), "mouseover", scrollstartup);
		Event.observe($("scrollup"), "mouseout", scrollend);
		Event.observe($("scrolldown"), "mouseover", scrollstartdown);
		Event.observe($("scrolldown"), "mouseout", scrollend);
		Event.observe($("scrollable"), "mousewheel", scrollmouse);
		Event.observe($("scrollable"), "DOMMouseScroll", scrollmouse);
	}
}
function scrollstartup(){
	scrollinterval=setInterval(scrollup, scrollspeed);
}
function scrollstartdown(){
	scrollinterval=setInterval(scrolldown, scrollspeed);
}
function scrollend(){
	clearInterval(scrollinterval);
}
function scrollup(){
	$("scrollable").scrollTop=$("scrollable").scrollTop-scrollheight;
}
function scrolldown(){
	$("scrollable").scrollTop=$("scrollable").scrollTop+scrollheight;
}
function scrollmouse(e) {
	$("scrollable").scrollTop=$("scrollable").scrollTop-(Event.wheel(e)*scrollheight);
}

function loadScroll2(){
	Event.observe($("scrollup2"), "mouseover", scrollstartup2);
	Event.observe($("scrollup2"), "mouseout", scrollend2);
	Event.observe($("scrolldown2"), "mouseover", scrollstartdown2);
	Event.observe($("scrolldown2"), "mouseout", scrollend2);
	Event.observe($("scrollable2"), "mousewheel", scrollmouse2);
	Event.observe($("scrollable2"), "DOMMouseScroll", scrollmouse2);
}
function scrollstartup2(){
	scrollinterval2=setInterval(scrollup2, scrollspeed);
}
function scrollstartdown2(){
	scrollinterval2=setInterval(scrolldown2, scrollspeed);
}
function scrollend2(){
	clearInterval(scrollinterval2);
}
function scrollup2(){
	$("scrollable2").scrollTop=$("scrollable2").scrollTop-scrollheight;
}
function scrolldown2(){
	$("scrollable2").scrollTop=$("scrollable2").scrollTop+scrollheight;
}
function scrollmouse2(e) {
	$("scrollable2").scrollTop=$("scrollable2").scrollTop-(Event.wheel(e)*scrollheight);
}

Object.extend(Event, {
	wheel:function (event){
		var delta = 0;
		if (!event) event = window.event;
		if (event.wheelDelta) {
			delta = event.wheelDelta/120; 
			if (window.opera) delta = -delta;
		} else if (event.detail) { delta = -event.detail/3;	}
		return Math.round(delta);
	}
});
