// JavaScript Document

function checkForm(form_name,field_list){
	var ff = document[form_name];
	var errors = false;                             
	var fields = field_list.split(","); 
	var error_message = new Array();                                   
	for(var i = 0; i < fields.length; i++){                     
		switch(ff[fields[i]].type){
			case "text":
			case "textarea":
			case "select-one":
				if(ff[fields[i]].name == "email" || ff[fields[i]].name == "contact_email"){
					mailreg = ff[fields[i]].value;
					mailreg = mailreg.indexOf('@');
					if (mailreg == -1){
					   error_message.push('This email address is not valid.');
					   errors = true;
					}//endif
				} else {
					if(ff[fields[i]].value == ""){
						error_message.push("The field "+ff[fields[i]].name+" is compulsory.");
						errors = true;
					}//endif
				}//endif
				break;
			case "checkbox":
				if(ff[fields[i]].checked == false){
					error_message.push("The field "+ff[fields[i]].name+" is compulsory.");
					errors = true;
				}//endif
				break;              
		}//endswitch                         
	}//endfor                 
	if(!errors){
		ff.submit();
	} else {
		var testo_errore = 'The form has returned the following errors:\n';
		for(var i = 0; i < error_message.length; i++){
			testo_errore += '> '+error_message[i]+'\n';
		}
		alert(testo_errore);
	}
}

function checkWords(textareaName){
	var words = document.getElementById(textareaName).value.split(" ");
	return words.length;
}

function countWords(textareaName,maxWords){
	var words = checkWords(textareaName);
	words = maxWords - words;
	var label = textareaName+'_words';
	var t = document.getElementById(label);
	if(maxWords == 700){
		t.innerHTML = '(max. '+words+' words - must be accomanied by JPEGs and MPEGs containing advertising and support material used):';
	} else {
		t.innerHTML = '(max. '+words+' words):';	
	}//end if
}

function checkCard(fieldID){
	var card = document.getElementById(fieldID).value;
	if(card == "laser"){
		document.getElementById('lasercard_opt').style.display = 'inline';
	} else {
		document.getElementById('lasercard_opt').style.display = 'none';
	}
}