/* scroollbox http://javascript.internet.com
Created by: Mr J | http://www.huntingground.net/ */

scrollStep=5;

timerLeft="";
timerRight="";

function toLeft(id){
  document.getElementById(id).scrollLeft=0;
}

function scrollDivRight(id){
  clearTimeout(timerRight) ;
  document.getElementById(id).scrollLeft+=scrollStep;
  timerRight=setTimeout("scrollDivRight('"+id+"')",10);
}

function scrollDivLeft(id){
  clearTimeout(timerLeft);
  document.getElementById(id).scrollLeft-=scrollStep;
  timerLeft=setTimeout("scrollDivLeft('"+id+"')",10);
}

function toRight(id){
  document.getElementById(id).scrollLeft=document.getElementById(id).scrollWidth;
}

function stopScroll(){
  clearTimeout(timerRight);
  clearTimeout(timerLeft);
}

/* misc functions */
function showMboxInfo() {
	$('mbimg').style.display='none';
	$('mbnext').style.display='none';
	$('mbinfo').style.display='block';
	$('mbback').style.display='block';
}
function showMboxImage() {
	$('mbinfo').style.display='none';
	$('mbback').style.display='none';
	$('mbimg').style.display='block';
	$('mbnext').style.display='block';
}

function showJob(elem, job) {
	$$('.joboffers').each(function(item) {
		item.style.color = '';
	});
	elem.style.color = '#F00';
	cm_ajaxOverlayBoxLoader2('ajax.php5?showJoboffer='+job, '0 0 mbox');
}


function focusSearchField(elem) {
	var e = $(elem);
	var e_id = $(elem+'_id');
	if (e.value == 'PLZ oder Ort') {
		e.value='';
		e_id.value='';
	}
}

function blurSearchField(elem) {
	var e = $(elem);
	var e_id = $(elem+'_id');
	if (e.value == '') { 
		e.value='PLZ oder Ort';
		e_id.value='';
	}
}


function gotoMarket(url) {
	var pos = url.indexOf('markt=');
	if (pos>0) 
		url = url.substr(0,pos-1);
	if ($('searchtext').value=='PLZ oder Ort') {
		alert('Bitte geben Sie PLZ oder Ort ihres Marktes ein.');
	}
	else {
		var e = $('searchtext_id').value;
		if (e!="") {
			Cookie.write('marktauswahl', e);
			var con = url.indexOf('?')>0 ? "&" : "?";
			window.location = url + con + "markt=" + e;
		}
		else {
			var txt = $('searchtext').value;
			window.location ="./Marktsuche.htm?adresse=" + txt;
		}
	}
}

function fillFromPopup(name, src, tgt) { 
	// src/tgt taken from .value(=0) OR .innerHTML(=1)
	var el = document.forms['selector'].elements[name+'_selector']; 
	var value = "";
	if (src)
		value = el.options[el.selectedIndex].innerHTML;
	else
		value = el.options[el.selectedIndex].value;
		
	value = value.replace(/<br\/>/g, "\n");	
	value = value.replace(/<br>/g, "\n");	
	
	if (tgt)
		$('fld_'+name).innerHTML = value;
	else (el.tagName=="input")
		$('fld_'+name).value = value;	
	
	cm_ajaxOverlayBoxClose();
}

function fillClientFromPopup() { 
	// src/tgt taken from .value(=0) OR .innerHTML(=1)
	var el = document.forms['selector'].elements['city_selector']; 
	var value = el.options[el.selectedIndex].innerHTML;
	var p = value.search(' ');
	var id = value.substr(0, p);
	var city = value.substr(p);	
	
	$('fld_client_id').value = id;	
	$('fld_city').value = city;	
	
	cm_ajaxOverlayBoxClose();
}


//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// date selector
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
var calendar='';
function showCalendar(target, mydate, today) {
	calendar = target;
	var tmp = target.split('.');
    cm_ajaxSimpleLoader('ajax.php5?calendar='+target+(mydate ? '&date='+mydate : '')+(today ? '&today='+today : ''), 'calendar_'+tmp[1]);
}
function hideCalendar(target, mydate) {
	var tmp = calendar.split('.');
	document.getElementById('calendar_'+tmp[1]).innerHTML='';
	calendar = '';
}
function pickDate(mydate, target, type) {
   	var tmp = mydate.split('-');
   	var newdate = tmp[2]+'.'+tmp[1]+'.'+tmp[0];
   	var tmp = target.split('.');
	document.forms[tmp[0]].elements[tmp[1]].value = newdate;
  	hideCalendar();
}

