/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid e-mail adress")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid e-mail adress")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid e-mail adress")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid e-mail adress")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid e-mail adress")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid e-mail adress")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid e-mail adress")
		    return false
		 }

 		 return true					
}

function ValidateSubscribeForm(theform){
	var nameID=theform.subscribe_naam;
	var emailID=theform.subscribe_email;
	
	if ((nameID.value==null) || (nameID.value=="Naam")){
        nameID.style.borderColor="#ff0000";
		nameID.focus()
		return false;
	} else {
        nameID.style.borderColor="#cccccc";
	}
	if ((emailID.value==null)||(emailID.value=="E-mail")){
        emailID.style.borderColor="#ff0000";
		emailID.focus()
		return false;
	} else {
        emailID.style.borderColor="#cccccc";
	}
	if (echeck(emailID.value)==false){
		emailID.focus()
		return false
	}
}
function validate_email(theform){
	var emailID=theform.gbk_user_email;
	
	if ((emailID.value==null)||(emailID.value=="")){
        emailID.style.borderColor="#ff0000";
		emailID.focus()
		return false;
	}
	if (echeck(emailID.value)==false){
		emailID.focus()
		return false
	}
}
function validate_search(theform){
	var search_input=theform.gbk_search;
	
	if ((search_input.value==null)||(search_input.value=="") || (search_input.value=="Zoek...")){
		search_input.focus();
		search_input.style.borderColor="#ff0000";
		return false;
	}
	return true
}

function validate_artist_search(theform){
	var search_input=theform.artist_search;
	
	if ((search_input.value==null)||(search_input.value=="") || (search_input.value=="Zoek...")){
		search_input.focus();
		search_input.style.borderColor="#ff0000";
		return false;
	}
	return true
}


function validate_login(theform){
	var user_name_ID=theform.gbk_username;
	var pass_ID=theform.gbk_password;
	
	if ((user_name_ID.value==null) || (user_name_ID.value=="Gebruikersnaam")){
    	user_name_ID.style.borderColor="#ff0000";
		user_name_ID.focus()
		return false;
	}
	if ((pass_ID.value==null)||(pass_ID.value=="*****")){
    	pass_ID.style.borderColor="#ff0000";
		pass_ID.focus()
		return false;
	}
}
function validate_add_comment(theform){
	var user_comment=theform.comment_add;
	
	if ((user_comment.value==null) || (user_comment.value=="")){
    	user_comment.style.borderColor="#ff0000";
		user_comment.focus();
		return false;
	}
}
function validate_poll(form) {
    var option_buttons = validate_radio_button(form.poll_radios);
    if (option_buttons == null) {
        alert('Kies een antwoord');
        return false;
    }
}
function validate_add_prikbord(theform){
	var msg_title=theform.msg_title;
	var comment_add=theform.comment_add;
	var emailID=theform.msg_email;
	var msg_type=theform.msg_type;
	var spam_check=theform.spam_check;
	
    if ((msg_title.value==null) || (msg_title.value=="")){
    	msg_title.style.borderColor="#ff0000";
		msg_title.focus();
		return false;
	} else {
    	msg_title.style.borderColor="#cccccc";
	}
    if ((comment_add.value==null) || (comment_add.value=="")){
    	comment_add.style.borderColor="#ff0000";
		comment_add.focus();
		return false;
	} else {
    	comment_add.style.borderColor="#cccccc";
	}
	if ((emailID.value==null)||(emailID.value=="")){
    	emailID.style.borderColor="#ff0000";
		emailID.focus()
		return false;
	} else {
    	emailID.style.borderColor="#cccccc";
	}
	if (echeck(emailID.value)==false){
		emailID.focus()
		return false
	}
    var option_buttons = validate_radio_button(msg_type);
    if (option_buttons == null) {
        alert('Kies het type bericht');
        return false;
    }
    if ((spam_check.value==null) || (spam_check.value=="")){
    	spam_check.style.borderColor="#ff0000";
		spam_check.focus();
		return false;
	} else {
    	spam_check.style.borderColor="#cccccc";
	}
}
function validate_add_subject(theform){
	var msg_title=theform.msg_title;
	var msg_text=theform.comment_add;
	var msg_type=theform.msg_type;
	
	if ((msg_title.value==null) || (msg_title.value=="")){
    	msg_title.style.borderColor="#ff0000";
		msg_title.focus()
		return false;
	}
	if ((msg_text.value==null)||(msg_text.value=="")){
    	msg_text.style.borderColor="#ff0000";
		msg_text.focus()
		return false;
	}
    var option_buttons = validate_radio_button(msg_type);
    if (option_buttons == null) {
        alert('Kies het type bericht');
        return false;
    }
}
function validate_add_reply(theform){
	var user_reply=theform.reply_add;
	if ((user_reply.value==null) || (user_reply.value=="")){
    	user_reply.style.borderColor="#ff0000";
		user_reply.focus();
		return false;
	}
}

function validate_vriend(theform){

    var option_buttons = validate_radio_button(theform.vriend_type);
    if (option_buttons == null) {
        alert('Kies wat voor vriend u wilt worden');
        return false;
    }
	
	/* RADIO BUTTONS */
    var option_buttons = validate_radio_button(theform.sex_type);
    if (option_buttons == null) {
        alert('Voer uw geslacht in');
        return false;
    }
	if(!default_check(theform.user_naam_first)) { return false; }
	if(!default_check(theform.user_naam)) { return false; }
	if(!default_check(theform.user_adres)) { return false; }
	if(!default_check(theform.user_adres_no)) { return false; }
	if(!default_check(theform.user_pc)) { return false;	}
	if(!default_check(theform.user_plaats)) { return false;	}
	
	if(!default_check(theform.user_email)) {
	   return false;
	}
	if (echeck(theform.user_email.value)==false){
		theform.user_email.focus()
		return false
	}
	if(!default_check(theform.spam_check)) {
	   return false;
	}
}

function validate_lid(theform) {
    /* ---- PERSOONLIJKE GEGEVENS --- */

	/* RADIO BUTTONS */
    var option_buttons = validate_radio_button(theform.sex_type);
    if (option_buttons == null) {
        alert('Voer uw geslacht in');
        return false;
    }
	if(!default_check(theform.user_naam_first)) { return false; }
	if(!default_check(theform.user_naam)) { return false; }
	if(!default_check(theform.user_dob)) { return false; }
	
	if(!default_check(theform.user_adres)) { return false; }
	if(!default_check(theform.user_adres_no)) { return false; }
	if(!default_check(theform.user_pc)) { return false; }
	if(!default_check(theform.user_plaats)) { return false; }

	var user_email=theform.user_email;
	if(!default_check(user_email)) { return false; }
	/* EMAIL */
	if (echeck(user_email.value)==false){
		user_email.focus()
		return false
	}	
    /* ---- OPLEIDING --- */
	if(!default_check(theform.edu_institute_1)) { return false; }
	if(!default_check(theform.edu_period_1)) { return false; }
	var edu_diploma_1=theform.edu_diploma_1;
	/* RADIO BUTTONS */
    var option_buttons_2 = validate_radio_button(edu_diploma_1);
    if (option_buttons_2 == null) {
        alert('Diploma behaald ja of nee?');
        return false;
    } else if(option_buttons_2=='ja') {
		if(!default_check(theform.edu_date_1)) { return false; }
	}

    /* ---- WERK --- */
	if(!default_check(theform.werk_terreinen)) { return false; }
	if(!default_check(theform.werk_karakter)) { return false; }
	if(!default_check(theform.werk_sinds)) { return false; }
	
    /* ---- LIDMAATSCHAP --- */
	if(!default_check(theform.motivatie_lid)) { return false; }
	if(!default_check(theform.lid_bijdrage)) { return false; }
	if(!default_check(theform.hoe_in_contact_met_gbk)) { return false; }
	if(!default_check(theform.ondertekening_place)) { return false; }
	// spam check
	if(!default_check(theform.spam_check)) { return false; }
}

function default_check(input) {
	if ((input.value==null)||(input.value=="")){
    	input.style.borderColor="#ff0000";
		input.focus()
		return false;
	} else {
        input.style.borderColor="#CCCCCC";
        return true;
	}
}

// Radio Button Validation
// copyright Stephen Chapman, 15th Nov 2004,14th Sep 2005
// you may copy this function but please keep the copyright notice with it
function validate_radio_button(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {
            cnt = i; i = -1;
        }
    }
    if (cnt > -1) { 
        return btn[cnt].value;
    } else {
        return null;
    }
}

