var popupWin;
function openImage (prefix, table, column, id, width, height) {
	if (popupWin) {
		try { popupWin.close (); } catch (exception) {}
	}
	popupWin = window.open (prefix + 'popupimg.php?prefix=' + prefix + '&table=' + table + '&column=' + column + '&id=' + id, '_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=' + width + ',height=' + height);
}
function openReservationWin (id) {
	if (popupWin) {
		try { popupWin.close (); } catch (exception) {}
	}
	popupWin = window.open ('/reservation.php?id=' + id, '_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=642,height=440');
}
function unscrambleLink (id, sUrl, sText, isEmail) {
	var obj = document.getElementById (id);
	if (obj == null) {
		alert ('unscrambleLink: Object not found (' + id + ')');
		return;
	}
	var parent = obj.parentNode;
	if (parent == null) {
		alert ('unscrambleLink: Parent object not found');
		return;
	}
	// to create standard xhtml, use <div><a></a><-- scramble --></div>
	if (parent.nodeName.toLowerCase () == 'div') {
		parent = parent.firstChild;
	}
	if (parent.nodeName.toLowerCase () != 'a') {
		alert ('unscrambleLink: Parent object is not an anchor tag');
		return;
	}
	if (sUrl != null && sUrl.length > 0) {
		eval ('var txt = String.fromCharCode(' + sUrl + ');');
		parent.href = txt;
	}
	if (sText != null && sText.length > 0) {
		var firstChild = parent.firstChild;
		//First node is a text node with input
		if (firstChild && firstChild.nodeType == 3 && firstChild.nodeValue != null && firstChild.nodeValue.replace (' ', '').length > 0) {
			return;
		}
		eval ('var txt = String.fromCharCode (' + sText + ');');
		txt = txt.replace (/&amp;/g, '&');
		parent.innerHTML = txt;
		if (parent.title != null && parent.title.length == 0) {
			parent.title = txt;
		}
	}
}
function checkFormData (id) {
	try {
		if (id != 'newsletterform' && id != 'reservationform' && id != 'memberregistrationform')
			return true;
		
		var hasError = false;
		var fieldName = '';
		
		var pre = '';
		var fields = new Array('email','name','firstname');
		if(id == 'reservationform'){
			pre = 'res_';
		}
		else if(id == 'memberregistrationform'){
			pre = 'member_';
			fields = new Array('city','zip','address','name','firstname');
		}
						
		for(var i=0;i<fields.length;i++){		
			var key = pre+fields[i];
			var obj = AJS.getElement (key);
			if(obj==null)
				continue;
			var value = obj.value.trim ();
				
			if(value.length == 0) {
				hasError = true;
				fieldName = key;
				AJS.getElement (key + '_label').className = 'error';
			}
			else {
				if(fields[i]=='email'){
					if (!(value.match (/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/))) {
						hasError = true;
						fieldname = key;
						AJS.getElement (key + '_label').className = 'error';
						continue;
					}
				}
				AJS.getElement (key + '_label').className = '';
			}
			if (fieldName.length > 0) {
				var l = AJS.getElement (fieldName);
				if(l!=null)
					l.focus ();
			}
		}
		return !hasError;
	} catch (ex) {
		alert(ex);
		//return true;
	}
}

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

function setPressImage (button, prefix, url, id, w, h, wO, hO, caption) {
	a = AJS.getElement ('img-press');
	a.firstChild.src = prefix + url + '&id=' + id;
	a.firstChild.style.width = w + 'px';
	a.firstChild.style.height = h + 'px';
	a.href = 'javascript:openImage(\'' + prefix + '\', \'images\', \'image\', ' + id + ', ' + wO + ', ' + hO + ');';

	// unset all placeholders
	pls = AJS.getElementsByTagAndClassName ('div', 'img-placeholder', a.parentNode);
	for (i = 0; i < pls.length; i++) {
		pls[i].className = 'img-placeholder';
	}
	// mark placeholder
	button.className = 'img-placeholder active';
	AJS.getElement ('img-caption').innerHTML = caption;
}