var strIncorrectFields;
var strFirstIncorectFiled;

function submitProductInfoForm(productInfoForm){
	if (checkForm(productInfoForm)){
		//alert("mail opgestuurd");
		productInfoForm.submit();
	}
	else{
		alert("De volgende velden zijn incorrect: \n\n" + strIncorrectFields);
		if (strFirstIncorectFiled == "serie1ChkBoxes" || strFirstIncorectFiled == "serie2ChkBoxes" || strFirstIncorectFiled == "serie3ChkBoxes"){
		
		}else{
			productInfoForm[strFirstIncorectFiled].focus();
		}
		//alert(FORM_NOT_COMPLETE);
		return false;
	}
}


// This function performs the form check and puts focus on errornous fields
function checkForm(form){
	var bIsFormCorrectlyField = true;
		strIncorrectFields = "";
		strFirstIncorectFiled = "";
	
	if (!checkStrField(form.naambedrijf.value)){
		bIsFormCorrectlyField = false;
		(strFirstIncorectFiled == "") ? strFirstIncorectFiled = "naambedrijf" : strFirstIncorectFiled = strFirstIncorectFiled;
		strIncorrectFields += "naam bedrijf\n";
				
		//form.naambedrijf.focus();
		//return false;
	}
	
	if (!checkStrField(form.naamcontactpersoon.value)){
		bIsFormCorrectlyField = false;
		(strFirstIncorectFiled == "") ? strFirstIncorectFiled = "naamcontactpersoon" : strFirstIncorectFiled = strFirstIncorectFiled;
		strIncorrectFields += "naam contactpersoon\n";
	}
	
	if (!checkStrField(form.straathuisnr1.value)){
		bIsFormCorrectlyField = false;
		(strFirstIncorectFiled == "") ? strFirstIncorectFiled = "straathuisnr1" : strFirstIncorectFiled = strFirstIncorectFiled;
		strIncorrectFields += "adres\n";
	}
		
	
	
	if (!checkStrField(form.postcodeletters.value)){
		bIsFormCorrectlyField = false;
		(strFirstIncorectFiled == "") ? strFirstIncorectFiled = "postcodeletters" : strFirstIncorectFiled = strFirstIncorectFiled;
		strIncorrectFields += "postcode\n";
	}
	
	if (!checkStrField(form.woonplaats.value)){
		bIsFormCorrectlyField = false;
		(strFirstIncorectFiled == "") ? strFirstIncorectFiled = "woonplaats" : strFirstIncorectFiled = strFirstIncorectFiled;
		strIncorrectFields += "woonplaats\n";
	}
	
	if (!checkStrField(form.telefoonnummer.value)){
		bIsFormCorrectlyField = false;
		(strFirstIncorectFiled == "") ? strFirstIncorectFiled = "telefoonnummer" : strFirstIncorectFiled = strFirstIncorectFiled;
		strIncorrectFields += "telefoonnummer\n";
	}			
	
	if (!checkEmail(form.emailadres.value)){
		bIsFormCorrectlyField = false;
		(strFirstIncorectFiled == "") ? strFirstIncorectFiled = "emailadres" : strFirstIncorectFiled = strFirstIncorectFiled;
		strIncorrectFields += "emailadres\n";
	}
	
	/*
	if (!checkCheckboxArray(form, form.serie1ChkBoxes.value)){
		bIsFormCorrectlyField = false;
		(strFirstIncorectFiled == "") ? strFirstIncorectFiled = "serie1ChkBoxes" : strFirstIncorectFiled = strFirstIncorectFiled;
		strIncorrectFields += "autoreparatie producten\n";
	}
	
	if (!checkCheckboxArray(form, form.serie2ChkBoxes.value)){
		bIsFormCorrectlyField = false;
		(strFirstIncorectFiled == "") ? strFirstIncorectFiled = "serie2ChkBoxes" : strFirstIncorectFiled = strFirstIncorectFiled;
		strIncorrectFields += "algemeen\n";
	}
	
	if (!checkCheckboxArray(form, form.serie3ChkBoxes.value)){
		bIsFormCorrectlyField = false;
		(strFirstIncorectFiled == "") ? strFirstIncorectFiled = "serie3ChkBoxes" : strFirstIncorectFiled = strFirstIncorectFiled;
		strIncorrectFields += "producten voor carrosserie\n";
	}
	
	
	if (!checkStrField(form.opmerkingen.value)){
		bIsFormCorrectlyField = false;
		(strFirstIncorectFiled == "") ? strFirstIncorectFiled = "opmerkingen" : strFirstIncorectFiled = strFirstIncorectFiled;
		strIncorrectFields += "Aanvullende opmerkingen\n";
	}	
	*/
	
	
	return bIsFormCorrectlyField;
}

// Function that checks the text field
function checkStrField(fldValue){
	return (fldValue.length > 0)
}

function checkNumField(fldValue){
        if (fldValue == ""){
           return false
        }else{
           return (!isNaN(fldValue));
        }
}

function checkSelectBox(selIndex){
        return (selIndex != 0)
}

function checkRadioButton(frmName, fldName){
    for(i=0;i<frmName[fldName].length;i++){
        if(frmName[fldName][i].checked) return true;
    }
    return false;
}

// Function that checks the email
// minimal e-mail is a@b.c
function checkEmail(email){
	var reEmail = /^.+\@.+\..+$/

	return reEmail.test(email)
}

function checkCheckBoxes(checkBoxesName){
	var oneChecked = false;
	
	for (var i=0;i<checkBoxesName.length;i++){
		oneChecked = oneChecked || checkBoxesName[i].checked;
	}
	
	return oneChecked;
}



function checkCheckboxArray(frmName, fldName){
    for(i=0;i<frmName[fldName].length;i++){
        if(frmName[fldName][i].checked) return true;
    }
    return false;
}

