/*
 * ======================================
 * 06-2008 Thomas Schlicker | 08 MEDIA de
 * ======================================
 * Datei: js/cardportal.js
 * Autor: Thomas Schlicker
 * ======================================
 */

var quick_cnt = 0;

function advertMax(advert_width) {

	advert_width_img = advert_width;
	advert_width = parseInt(advert_width) + 16;
	document.getElementById("advert").style.width = advert_width + "px";
	document.getElementById("advert-img").style.width = advert_width_img + "px";
	document.getElementById("advert-action").innerHTML = "<a onclick='advertMin("+advert_width+")'>| Minimieren</a>&nbsp;&nbsp;";
}

function advertMin(advert_width) {

	document.getElementById("advert").style.width = "298px";
	document.getElementById("advert-img").style.width = "282px";
	document.getElementById("advert-action").innerHTML = "<a onclick='advertMax("+advert_width+")'>| Maximieren</a>&nbsp;&nbsp;"; 
}

function closeAdvert() {

	document.getElementById("advert").style.display = "none";
}

function calender(y) {
  
	if(y == "end") {
	
		document.getElementById("div-calender-start").style.display = "none";
		document.getElementById("div-calender-end").style.display = "block";
	}
	else {
	
		document.getElementById("div-calender-end").style.display = "none";
		document.getElementById("div-calender-start").style.display = "block";
	}
}
function hideCalender(y) {

	document.getElementById("div-calender-"+y).style.display = "none";
}
function addDate(year,month,i,who) {

	if(i.length == 1)
		i = "0" + i;
		
	if(month.length == 1)
		month = "0" + month;
		
	if(who == 'start') {
    
		document.getElementById('dateStart').value = "";
		document.getElementById('dateStart').value = i+"."+month+"."+year;
		e = document.getElementById("dateStart");
	}
	if(who == 'end') {
    
		document.getElementById('dateEnd').value = "";
		document.getElementById('dateEnd').value = i+"."+month+"."+year;
		e = document.getElementById("dateEnd");
	}
	document.getElementById("div-calender-"+who).style.display = "none";
	document.getElementById("date-error-msg").innerHTML = "";
	document.getElementById("dateStart").style.borderColor = "#AAAAAA";
	document.getElementById("dateEnd").style.borderColor = "#AAAAAA";
	document.getElementById("searchbutton").style.display = "";
	
	PruefeDatum(e);
}

function getRoute() {

	var saddr;
	var daddr;
	
	if(document.getElementById('sStreet').value && document.getElementById('sCity').value) {
    	saddr = document.getElementById('sStreet').value + ", " + document.getElementById('sCity').value;	
	}
	if(document.getElementById('dC1').value && document.getElementById('dC2').value) {
    	daddr = document.getElementById('dC2').value + ", " + document.getElementById('dC1').value;		
	}
	if(saddr && daddr) {
		g = window.open("http://maps.google.de/maps?f=d&hl=de&geocode=&saddr="+saddr+"&daddr="+daddr,"google","scrollbars=yes, toolbar=0, directories=0, status=0, menubar=0, resizable=1");
		g.focus();
	}
}

function cpPrint(cpOrt,cpRadius,cpSource,cpBranche) {

	ms = window.open("cpPrint.php?cpOrt="+cpOrt+"&cpRadius="+cpRadius+"&cpSource="+cpSource+"&cpBranchenString="+cpBranche+"&cpSearch=1","cpPrint","width=840px, height=800px, scrollbars=yes, toolbar=0, directories=0, status=0, menubar=0, resizable=1");
	ms.focus();
}

function showHelp() {

	ms = window.open("lib/help.html","cpPrint","width=800px, height=500px, scrollbars=yes, toolbar=0, directories=0, status=0, menubar=0, resizable=1");
	ms.focus();
}

function showHelpLeo() {

	ms = window.open("lib/helpLeo.html","cpPrint","width=800px, height=500px, scrollbars=yes, toolbar=0, directories=0, status=0, menubar=0, resizable=1");
	ms.focus();
}

function popUpPromo(code) {

	ms = window.open("lib/popUpPromo.php?code="+code,"cpPromo","scrollbars=yes, toolbar=0, directories=0, status=0, menubar=0, resizable=1");
	ms.focus();
}

function closePromo() {

	document.getElementById("cp-lightbox").style.display = "none";
}

function randomSearch() {

	document.getElementById("branche").value = "random";
	document.getElementById("branche").selected = true; 
	document.search.submit();
}

function extraSearch() {

	document.getElementById('branche').value = "extra";
	document.getElementById('branche').selected = true; 
	document.search.submit();
}

function getCookie(name) {
	
	var search = name + "="
	var returnvalue = "";
	if (document.cookie.length > 0) {

		offset = document.cookie.indexOf(search)
		if (offset != -1) { // if cookie exists
			offset += search.length
			// set index of beginning of value
			end = document.cookie.indexOf(";", offset);
			// set index of end of cookie value
			if (end == -1)
				end = document.cookie.length;
			returnvalue = unescape(document.cookie.substring(offset, end))
		}
	}
	return returnvalue;
}

function closeLightbox() {

	document.getElementById("cp-lightbox").style.display = "none";
}

function chooseOrt(v) {

	document.getElementById("ort").value = v;
	document.getElementById("ort-hidden").style.display = "none";
}

function closeOrt() {

	document.getElementById("ort-hidden").style.display = "none";
}

function activeAh(sender_id, cnt) {

  	quick_cnt = cnt;
  	document.getElementById('ah-'+sender_id+'-'+cnt).style.backgroundColor = '#335EA8';
  	document.getElementById('ah-'+sender_id+'-'+cnt).style.color = '#FFFFFF';
}

function inactiveAh(sender_id, cnt) {

  	document.getElementById('ah-'+sender_id+'-'+cnt).style.backgroundColor = '#FFFFFF';
  	document.getElementById('ah-'+sender_id+'-'+cnt).style.color = '#000000';
}

function autohelp(sender,e,value) {

  	var old_quick_cnt = 0;
  	var sender_id = sender.id;
  	
	if(e.keyCode == 13) {
		document.getElementById(sender_id+'-hidden').style.display = 'none';
		return false;
	}
  	if (e.keyCode == 38 || e.keyCode == 40) {
    	if (!quick_cnt) {
      		quick_cnt = 1;
    	}
    	else {
      		old_quick_cnt = quick_cnt;
      		if (e.keyCode == 38 && quick_cnt > 1) {
        		quick_cnt--;
      		}
      		if (e.keyCode == 40) {
        		new_quick_cnt = quick_cnt+1;
        		if (document.getElementById('ah-'+sender_id+'-'+new_quick_cnt)) {
          			quick_cnt++;
        		}
      		}
    	}
    	if (quick_cnt != old_quick_cnt) {
      		if (document.getElementById('ah-'+sender_id+'-'+old_quick_cnt)) {
        		inactiveAh(sender_id, old_quick_cnt);
      		}
      		if (document.getElementById('ah-'+sender_id+'-'+quick_cnt)) {
        		activeAh(sender_id, quick_cnt);
        		document.getElementById(sender_id).value = document.getElementById('ah-'+sender_id+'-'+quick_cnt).innerHTML;
      		}
    	}
    	return false;
  	}
  	quick_cnt = 0;
  	ajaxOrt(sender_id,value);
}
