
var activeLink = '';
var locked = false;

function form_check() {
	form.expose();
}


function form_check_anfrage() {
	inq.error = false;
	if ($('vorname').value.length < 2 || $('vorname').value == labels['vorname']) {
		inq.setError('vorname');
	}
	
	if ($('nachname').value.length < 2 || $('nachname').value == labels['nachname']) {
		inq.setError('nachname');
	}
	
	if ($('email').value.search(form.mail) == -1 || $('email').value == labels['email']) {
		inq.setError('email');
	}
		
	if ($('tel').value.search(form.tel) == -1 || $('tel').value == labels['tel']) {
		inq.setError('tel');
	}

if (inq.error == false) {
		$('anfrage_form').submit();
	}
}

inq = {
	error: false,
	
	setError: function(field) {
		this.error = true;
		$(field).style.color = form.color.bad;
		$(field).value = labels[field];
	},
	
	rmError: function(field) {
		$(field).style.color = form.color.cool;
		if ($(field).value == labels[field]) $(field).value = "";
	}
}


function rmErrVorame() {
	inq.rmError('vorname');
}
function rmErrNachname() {
	inq.rmError('nachname');
}

function rmErrTel() {
	inq.rmError('tel');
}

function rmErrEmail() {
	inq.rmError('email');
}

function rmErr() {
	form.removeError();
}

form = {
	
	mail: /^[a-z0-9._%-]+@[a-z0-9.-]+\.[a-z]{2,4}$/i,
	tel: /^[\d\s ().-\/]+$/,
	
	color: {
		cool: "#333333",
		bad: "#999"
	},
	
	labels: {
		mail: "eMail fehlt"
	},
	
	expose: function() {
		if (this.checkMail() == false) {
			this.setError();
			return false;
		} else {
			$('expose_form').submit();
			return true;
		}
	},
	
	setError: function() {
		document.getElementById('email').style.color = this.color.bad;
		$('email').value = this.labels.mail;
	},
	
	removeError: function() {
		document.getElementById('email').style.color = this.color.cool;
		if ($('email').value == this.labels.mail) {
			$('email').value = "";
		}
	},
	
	
	checkMail: function() {
		if ($('email').value.search(this.mail) == -1 || $('email').value == this.labels.mail) {			
			return false;
		} else {
			return true;
		}
	}
}



window.addEvent('domready', function() {
	
	if (typeof doNotStart != "undefined") {
		if (doNotStart) return;
	}
	
	var right = $('jump-right');
	
	if (right) {
		right.setStyle('cursor','pointer');
		right.addEvent('click', function() {
			var next = parseInt(document.changeList.tx_property_pi1_start.value);
			if (isNaN(next)) {
				next = 0;
			}
			next += 4;
			document.changeList.tx_property_pi1_start.value = next;

			document.changeList.submit();
		});
	}
	
	var left = $('jump-left');
	if (left) {
		left.setStyle('cursor', 'pointer');
		left.addEvent('click', function() {
			var prev = parseInt(document.changeList.tx_property_pi1_start.value);
			if (isNaN(prev)) {
				prev = 4;
			}
			prev -= 4;
			document.changeList.tx_property_pi1_start.value = prev;

			document.changeList.submit();
		});
	}
	
	$$('tr').each(function(item, index) {
		var link = item.getProperty("rel");
		if ($type(link) == "string") {
			if (link.indexOf("linkto") !== -1) {

				var link = link.substr(7);
				link = link.substr(0, link.length - 1);
				
				tds = item.getElements('td');
				
				for (var i=0; i<tds.length-1; i++)  {
					tds[i].addEvents({
						mouseover: function() {
							this.addClass("mouseover");
						},
						mouseout: function() {
							this.removeClass("mouseover");
						},
						click: function() {
							var page = this.getParent().getProperty('rel').substr(7);
							page = page.substr(0, page.length - 1);
							var jumpToPage = call_page.delay(150, this, page);
						}
					});	
				}			
			}
		}
	});
	/*
	$$("td.check input").each(function(elem, i) {
		elm.addEvent("change", function() { elem.blur(); });
	});
	*/
});

function call_page(link) {
	if (locked == false) {
		top.location.href = link;
	}
}




function merkliste(uid, parent) {

	if (parent.checked == true) {
		var action = 'add';
	} else {
		var action = 'remove';
	}


	var url = hostName + 'typo3conf/ext/property/merkliste.php';
	var query = 'uid=' + uid + '&action=' + action;



	new Json.Remote(url + '?' + query, {

		onRequest: function() {
			locked = true;
			$$('input').each(function(item, index) {
				item.disabled = true;
			});
			isActive = true;
		},

		onComplete: function(r) {

				//merkliste_obj_count = Json.evaluate(r, true).anzahl;
				merkliste_obj_count = r.anzahl;
				merkliste_update();
				$$('input').each(function(item, index) {
					item.disabled = false;
				});
				locked = false;

		}

	}).send({0:1});
}
