/*
* Copyright © www.xardeau.com
*/
var image_url = '';
var imageFrame;

/**  VALIDATE FORM FUNCTIONS **/

var validationErrorColor = '#B90034';
var orgBorderStyle = '';
var selectedDelivery = false;

function validateContactForm(formName){
	var theForm = document.forms[formName];
	var validationMsg = '';
	var textIsEmpty_nl = 'De volgende velden zijn niet correct gevuld:\n';
	
	
	if(isEmpty(getElement('contact_name'))){	
		validationMsg += 'Naam' + '\n';
	};
	if(isEmpty(getElement('contact_phone'))){	
		validationMsg += 'Land' + '\n';
	};
	if(isEmpty(getElement('contact_email_contact'))){	
		validationMsg += 'E-mail' + '\n';
		setInvalid(getElement('contact_email_contact'), true);
	}else if(isInValidEmail(getElement('contact_email_contact'))){
		validationMsg += 'E-mailadres is ongeldig' + '\n';
		var emailText = getElement('contact_email_contact').value;
		setInvalid(getElement('contact_email_contact'), true);
		getElement('contact_email_contact').value = emailText;
	}
	if(isEmpty(getElement('contact_text'))){	
		validationMsg += 'Reden voor contact' + '\n';
	};	
	if(validationMsg.length > 0){
        showDivMessage('base_message', 'De aangegeven verplichte velden zijn niet correct gevuld.', 'message nok');
		//alert(validationMsg);
	}else{
		document.forms[formName].submit();
	}
}

function isEmpty(element){
	var isEmpty = false;
	if(element && element.value.replace(/^\s+|\s+$/, "") == ''){
		isEmpty =  true;
		setInvalid(element, true);
	}else{
		setInvalid(element, false);
	}
	return isEmpty;
}

function setInvalid(element, isInvalid){
	if(isInvalid){
		element.value = '';
		element.style.borderColor  = validationErrorColor;
	}else{
		element.style.borderColor = '';
	}
}

function isInValidEmail(element){
	var isInvalid = true;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(element.value)){
		element.style.borderColor  = validationErrorColor;
	}else{
		isInvalid = false;
	}
	return isInvalid;
}

function getElement(id){
	var element = document.getElementById(id);
	return element;
}

function showDivMessage(id, message, className ){
	var theElement = showDiv(id);
	theElement.className = className;
	theElement.innerHTML = message;
}

function showDiv(id){
	var	theElement = getElement(id);
	changeOpacity(100,id);
	theElement.style.display = 'block';
	return theElement;
}

function hideDiv(id, fadeOut){
	var	theElement = getElement(id);
	if(fadeOut){
		setTimeout("fade('"+id+"', 100, 0, 1000)", 4000);
		setTimeout("hideDiv('"+id+"', false)", 5000);
	}else{
		theElement.style.display = 'none';
	}
}

function fade(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpacity(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpacity(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpacity(opacity,id) {
    var object = getElement(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 