
	// --------- Areabox Default, Radio, Textfield ---------

	var enableSubmit = false;
	var tmp_plz_id;
	var tmp_plz;

    function submitButton() {
        if (enableSubmit) {
        	// setSessionValue('plz_id',tmp_plz_id);
        	// setSessionValue('orderform_plz',tmp_plz);
        	setSessionValue('plz_id',tmp_plz_id, 'orderform_plz',tmp_plz);

            return hs.close($('areabox'));
        }
    }



    function liveCheckPLZ(val) {
		if (val.length < 5) {
			PLZincorrect();
		} else {
			tmp_plz = val;
			sendPLZCheck();
		}
    }

    function sendPLZCheck() {
		if (work == 0) {
			work = 1;
			stamp = new Date() * getRandom();

			var urlQuery = domain+'ajax_check_plz.php?plz=' + tmp_plz +'&orderform=1' + '&sid=' + sid + '&' + stamp;

			xmlHttp.open("GET", urlQuery, true);
			xmlHttp.onreadystatechange = liveCheckPLZAction;
			xmlHttp.send(null);
		}
		else { setTimeout("sendPLZCheck()", 100); }
	}


    function liveCheckPLZAction() {
		if (xmlHttp.readyState == 4) {
			work = 0;

			if (xmlHttp.status == 200) {
				var response = xmlHttp.responseText;

				if (response == 0) {
					PLZincorrect();
				}

				if (response == 1) {
					PLZok();
				}
			}
		}
    }


    function PLZok() {
		alert('ALLES OK');
	}

	function PLZincorrect() {
		alert('FALSCH');
	}


    // --------- Areabox Textfield ---------

    var plz_color_default = "#999999";
    var plz_color_error = "darkred";
    var plz_color_checking = "silver";
    var plz_color_ok = "darkgreen";


    String.prototype.trim = function () { return this.replace(/^s+/g, '').replace(/s+$/g, ''); }

    function do_request() {
		if (work == 0) {
			work = 1;
			stamp = new Date() * getRandom();

			var urlQuery = domain+'ajax_check_plz.php?plz=' + tmp_plz + '&sid=' + sid + '&' + stamp;

			xmlHttp.open("GET", urlQuery, true);
			xmlHttp.onreadystatechange = updatePLZinfo;
			xmlHttp.send(null);
		}
		else { setTimeout("do_request()", 100); }
	}



	function updatePLZinfo() {

		if (xmlHttp.readyState == 4) {
			work = 0;

			if (xmlHttp.status == 200) {
				var response = xmlHttp.responseText;

				if (response == 0) {
					if ($('areabox-info') != null) {
						$('areabox-info').innerHTML = "PLZ liegt <strong>nicht</strong> im Liefergebiet";
						$('areabox-info').style.color = plz_color_error;
						$('areabox-closeit').className='highslide-button_inact';
						enableSubmit = false;
						$('plz_input').onkeydown = function() { }
					}
				}
				if (response == 1) {
					if ($('areabox-info') != null) {
						$('areabox-info').innerHTML = "PLZ liegt im Liefergebiet";
						$('areabox-info').style.color = plz_color_ok;
						$('areabox-closeit').className='highslide-button_colored';
						enableSubmit = true;
						$('plz_input').onkeydown = function(e) { if(e.keyCode == 13) { submitButton(); } }
					}
				}
			}
		}
	}


	function enableAreaboxTextfieldButton() {
		$('areabox-info').style.color = plz_color_default;
		$('areabox-info').innerHTML = "Bitte f&uuml;nfstellige PLZ eingeben.";

		$('areabox-closeit').className='highslide-button_inact';

		if(tmp_plz.length == 5)
		{
			if (!tmp_plz.match(/[0-9]{5}/)) {
				$('areabox-info').innerHTML = "Bitte nur Zahlen eingeben!";
				$('areabox-info').style.color = plz_color_error;
			} else {
				$('areabox-info').style.color = plz_color_checking;
				$('areabox-info').innerHTML = "&Uuml;berpr&uuml;fe ...";
				do_request();
			}
		}
	}


	function enableAreaboxGermanyButton() {
		$('areabox-info').style.color = plz_color_default;
		$('areabox-info').innerHTML = "Bitte f&uuml;nfstellige PLZ eingeben.";

		$('areabox-closeit').className='highslide-button_inact';

		if(tmp_plz.length == 5)
		{
			if (!tmp_plz.match(/[0-9]{5}/)) {
				$('areabox-info').innerHTML = "Bitte nur Zahlen eingeben!";
				$('areabox-info').style.color = plz_color_error;
			} else {
				//$('areabox-info').style.color = plz_color_checking;
				//$('areabox-info').innerHTML = "&Uuml;berpr&uuml;fe ...";
				//do_request();
				$('areabox-info').innerHTML = "";
				$('areabox-info').style.color = plz_color_ok;
				$('areabox-closeit').className='highslide-button_colored';
				enableSubmit = true;
				$('plz_input').onkeydown = function(e) { if(e.keyCode == 13) { submitButton(); } }
			}
		}
	}




    // --------- Closedbox ---------

	function submitClosedbox(value) {
		if (value != "") {
			setSessionValue('orderform_lieferzeitpunkt', value);
			return true;
		} else {
			return false;
   		}
    }

	function enableClosedboxButton(value) {
    	if (value != "") {
    		$('closedbox-closeit').className = "highslide-button_colored";
    		$('closedbox-closeit').style.cursor = "pointer";
    		$('closedbox-closeit').onclick = function() {
    			submitClosedbox(value);
    			document.closebox.submit();
    		}
    	} else {
    		$('closedbox-closeit').className = "highslide-button_inact";
    		$('closedbox-closeit').style.cursor = "default";
   			$('closedbox-closeit').onclick = "";
   			return false;
   		}
    }


