Event.observe(window, "load", function() {
	if (window.GMapsInitialize) GMapsInitialize();
});

Event.observe(window, "unload", function() {
	if (window.GMapsInitialize) GUnload();
});

function checkLogin() {
	if (document.getElementById('login:email').value == '' || document.getElementById('login:password').value == '') {
		alert('Not all required fields are filled!');
		return false;
	}
	
	return true;
}

function searchBtnPressed(fields, searchtext) {
	for (i = 0; i < fields.length; i++) {
		if (fields[i].checked == true && fields[i].value == "products") 
			return true;
		else if (fields[i].checked == true) {
			window.open('http://www.google.de/search?q=' + searchtext + '+site%3Adaemmisol.at');
			return false;
		}
	}
}
 
function checkNewsleterForm() {
	if (document.getElementById('email').value == '' || document.getElementById('company').value == '' || document.getElementById('zipcode').value == '' || document.getElementById('place').value == '' || document.getElementById('street').value == '' || document.getElementById('title').value == '' || document.getElementById('branche').value == '' || document.getElementById('country').value == '') {
		alert('Not all required fields are filled!');
		return false;
	} else {
		return checkEmail(document.getElementById('email').value);
	}
}

function checkContactSubmit() {
	if (document.getElementById('firstname').value == '' || document.getElementById('lastname').value == '' || document.getElementById('company').value == '' || document.getElementById('contemail').value == '' || document.getElementById('subject').value == '' || document.getElementById('message').value == '') {
		alert('Not all required fields are filled!');
		return false;
	} else {
		return checkEmail(document.getElementById('contemail').value);
	}
}

function openImageChooserWindow(textid) {
	features="height=600,width=400,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes";			
	winId=window.open(window.location.host + window.location.pathname + 'index.php?module=adminarea&class=manageimages&setParent=' + textid, '', features);
}

function setParentWindowTextfield(textid, value) {
	parent.opener.document.getElementById(textid).value = value;
	ww = window.open(window.location, "_self");
	ww.close();
}

function isArray(obj) {
	if (obj.constructor.toString().indexOf('Array') == -1)
		return false;
	else
		return true;
}

function ajaxloading() {
}

function ajaxfinished() {
}

function loadHtmlDataForm(url, transmethod, replaceElement, form) {
	Element.extend(form);
	form.request({
		method: transmethod,
		onSuccess: function(transport) {
			var response = transport.responseText || null;
			
			if (response != null)
				document.getElementById(replaceElement).innerHTML = response;
		},
		onFailure:function() { alert('Failed to communicate with server'); }
	});
}

function loadHtmlData(url, transmethod, replaceElement) {
	new Ajax.Request(url, {
		method: transmethod,
		onSuccess: function(transport) {
			var response = transport.responseText || null;
			
			if (response != null)
				document.getElementById(replaceElement).innerHTML = response;
		}, 
		onFailure:function() { alert('Failed to communicate with server'); }
	});
}

function loadPageContent(url, transmethod) {
	new Ajax.Updater(CONTENT_DIV, url, { 
		method: transmethod,
		onLoading: ajaxloading(),
		onComplete: ajaxfinished()
	});
}