document.onmousemove =
	function (e) {
		if (document.all) {
			mouse_x = event.clientX;
			mouse_y = event.clientY;
			if ((event.srcElement) && (event.srcElement.tagName) && (event.srcElement.tagName.toLowerCase() == 'select')) mouse_y += 30;
		} else if (document.getElementById){
			mouse_x = e.clientX;
			mouse_y = e.clientY;
		} else if (document.layers) {
			mouse_x = e.x;
			mouse_y = e.y;
		} // end if
		if (window.pageXOffset) {
			mouse_x += window.pageXOffset;
			mouse_y += window.pageYOffset;
		} else {
			var html = document.getElementsByTagName('html')[0];
			mouse_x += html.scrollLeft;
			mouse_y += html.scrollTop;
		} // end if
		moveIt();
	} // end event

input_y = false;

function startDrag() {
	input_y = true;
	old_mouse_position = mouse_y; 
	input = document.getElementById('scroll_lister');
	old_input_position = input.offsetTop;
	top_mouse_border = old_mouse_position - input.offsetTop+9;
	bottom_mouse_border = top_mouse_border + input.parentNode.offsetHeight - input.offsetHeight-18;
	table = document.getElementById('scroller_wrapper');
	k = (table.offsetHeight - input.parentNode.offsetHeight)/ (input.parentNode.offsetHeight - input.offsetHeight);
}
function PopupStartDrag() {
	input_y = true;
	old_mouse_position = mouse_y; 
	input = document.getElementById('popup_scroll_lister');
	old_input_position = input.offsetTop;
	top_mouse_border = old_mouse_position - input.offsetTop+9;
	bottom_mouse_border = top_mouse_border + input.parentNode.offsetHeight - input.offsetHeight-18;
	table = document.getElementById('popup_scroller');
	k = (table.offsetHeight - input.parentNode.offsetHeight)/ (input.parentNode.offsetHeight - input.offsetHeight);
}
function moveIt() {
	if (input_y) {		
		current_mouse_position = mouse_y;
		if (current_mouse_position <= top_mouse_border ) {
			input.style.top = 9+"px";
			table.style.top = 0+"px";
		} else {
			if (current_mouse_position <= bottom_mouse_border) {
				dX = current_mouse_position - old_mouse_position;
				input.style.top = old_input_position + dX + "px";
				table.style.top = - (input.offsetTop) * k + "px";
			} else {
				input.style.top = input.parentNode.offsetHeight - input.offsetHeight + "px";
				table.style.top = - (input.parentNode.offsetHeight - input.offsetHeight)* k + "px";
			}
		}
	}
}
document.onmouseup = 
function () {
	input_y = false;
	if (scroll_interval) {
		clearInterval(scroll_interval);
		scroll_interval = null;
	}
}

function EnterForm(){
	var enter_block = document.getElementById("enter");
	var form_block = document.getElementById("form");
	enter_block.style.display = "none";
	form_block.style.display = "block";
	return false;
}
var scroll_interval = null;

function StartScrollTextarea(id, delta) {
	var textarea = document.getElementById(id);
	if (textarea) scroll_interval = setInterval(function () { textarea.scrollTop += delta; }, 100);
	return false;
}

function ScrollTextBlock(delta) {
	var textblock = document.getElementById("scroller_wrapper");
	var lister  = document.getElementById("scroll_lister");
	if (textblock) {
		var position = 0;
		deltax = delta;
		if (isNaN(textblock.style.top)){
			deltax = parseInt(textblock.style.top)+delta;
			position = parseInt(textblock.style.top);
		}
		border_top=textblock.parentNode.offsetHeight-textblock.offsetHeight;
		if (position<=border_top && delta<0) {
			textblock.style.top = border_top + "px";
		} else {
			if (position>=0 && delta>0) {
				textblock.style.top = 0 + "px";
			} else {
				text_delta = textblock.offsetHeight-textblock.parentNode.offsetHeight;
				lister_delta = lister.offsetHeight-lister.parentNode.offsetHeight+18;
				lister_deltax = deltax / text_delta * lister_delta + 16;
				lister.style.top = lister_deltax + "px";
				textblock.style.top = deltax + "px";
			}
		}
	}
}

function StartScrollTextblock(delta) {
	ScrollStop();
	var textblock = document.getElementById("scroller_wrapper");
	if (textblock) scroll_interval = setInterval("ScrollTextBlock("+delta+");", 20);
}
function ScrollStop() {
     input_y = false;
     if (scroll_interval) {
          clearInterval(scroll_interval);
          scroll_interval = null;
     }
}
function ScrollPopupBlock(delta) {
	var textblock = document.getElementById("popup_scroller");
	var lister  = document.getElementById("popup_scroll_lister");
	if (textblock) {
		var position = 0;
		deltax = delta;
		if (isNaN(textblock.style.top)){
			deltax = parseInt(textblock.style.top)+delta;
			position = parseInt(textblock.style.top);
		}
		border_top=textblock.parentNode.offsetHeight-textblock.offsetHeight;
		if (position<=border_top && delta<0) {
			textblock.style.top = border_top + "px";
		} else {
			if (position>=0 && delta>0) {
				textblock.style.top = 0 + "px";
			} else {
				text_delta = textblock.offsetHeight-textblock.parentNode.offsetHeight;
				lister_delta = lister.offsetHeight-lister.parentNode.offsetHeight+18;
				lister_deltax = deltax / text_delta * lister_delta + 16;
				lister.style.top = lister_deltax + "px";
				textblock.style.top = deltax + "px";
			}
		}
	}
}

function StartScrollPopupblock(delta) {
	var textblock = document.getElementById("popup_scroller");
	if (textblock) scroll_interval = setInterval("ScrollPopupBlock("+delta+");", 20);
}
function SoundClick(link, link_class) {
	link.parentNode.className="Sound "+link_class;
	if (soundManager)
	{
		if (link_class == 'on')
		{
			document.cookie = "PageSoundOff=0; path=/;";
			soundManager.play('pagesound');
		}
		else
		{
			document.cookie = "PageSoundOff=1; path=/;";
			soundManager.stop('pagesound');
		}
	}
}

function AddJobForm(button, id) {
	var form = document.getElementById('form'+ id);
	if (form) { form.style.display= "block"; }
	document.getElementById('ShowForm' + id).value = 1;
	if (id==3) 
	{
		var addform = document.getElementById('add_job_form');
		if (addform) {
			addform.style.display="none";
		}
	}
	button.onclick =
					function () {
						return AddJobForm(this, 3);
					}
	ScrollerResize();
	return false;
}

function ClearInput(input, text) {
	if (input.value==text) input.value ="";
	
}
function ReturnValue(input, text) {
	if (input.value=="") input.value =text;
}
function ShowImage(image) {
	var img = document.getElementById(image);
	if (img) img.style.display="block";
	return false;
}
function HideImage(image) {
	var img = document.getElementById(image);
	if (img) img.style.display="none";
	return false;
}
