var fprocessed = false;
var nprocessed = false;
function checkSendContactForm(){
	formdata = $('frm').serialize();
	if (fprocessed == false) {
		fprocessed = true;
		new Ajax.Request('/includes/process_contactform.php', { onSuccess: returnCheckSendContactForm, method: "post", parameters: formdata });
	}
}

function returnCheckSendContactForm(data) {
	fprocessed = false;
	obj = data.responseJSON;
	if (!Object.isUndefined(obj.error)) {
		showPopup("Fout",obj.error,"error");
	}
	else if (!Object.isUndefined(obj.mssg)) {
		showPopup("Bedankt!",obj.mssg,"mssg");
		$('frm').reset();
	}
	
}

function checkSendNB(){
	formdata = $('txtnb').serialize();
	if (nprocessed == false) {
		nprocessed = true;
		new Ajax.Request('/includes/process_newsletter.php', { onSuccess: returnCheckSendNB, method: "post", parameters: formdata });
	}
}

function returnCheckSendNB(data) {
	nprocessed = false;
	obj = data.responseJSON;
	if (!Object.isUndefined(obj.error)) {
		showPopup("Fout",obj.error,"error");
	}
	else if (!Object.isUndefined(obj.mssg)) {
		showPopup("Bedankt!",obj.mssg,"mssg");
		$('txtnb').value = "";
	}
	
}

function showMessage(c_title, c_content) {
	 Shadowbox.open({
        content:    c_content,
        player:     "html",
        title:      c_title,
        height:     "auto",
        width:      "auto"
    });
}

function changeBg(picid) {
	/* url = 'url(/img/main/toppic'+picid+'.jpg)';
	$('top').setStyle({background: url+' right no-repeat'}); */
}

function doOffert() {
	new Ajax.Request('/includes/process_offerte.php', { onSuccess: returnDoOffert, method: "post" });
}

function returnDoOffert(data) {
	obj = data.responseJSON;
	window.location = obj.uri;
}

function showPopup(title,content,type) {
	if (title != "") { $('popbox_title').update(title); }
	if (content != "") { $('popbox_content').update(content); }
	
	if (type == "error") { 
		$('popbox').setStyle({border: '16px solid #b50000'})
		$('popbox_title').setStyle({color: '#b50000'});
	}
	else if (type == "mssg") { 
		$('popbox').setStyle({border: '16px solid #0099FF'})
		$('popbox_title').setStyle({color: '#0099FF'});
	}
	
	//h = $('popbox').getDimensions().height + 100;
	//$('popbox').setStyle({height: h+"px"});
	
	$('popbox').show();
	$('black_overlay').show();
}

function hidePopup() {
	$('popbox').hide();
	$('black_overlay').hide();
}
