// JavaScript Document
function search_checkbox(myform){
	var arrBox = new Array();
	for(var i=0;i<myform.elements.length;i++){
			var input = myform.elements[i];
			if(input.type == 'checkbox' && input.name!='delete_img'){
				arrBox.push(input);
				}
			
		}
		return arrBox;
	}
//Retourne TRUE ou FALSE si le tablo de checkbox ne comprend aucun element coché
function are_checked(arrBox){
	if(arrBox.length ==0)return true;
	var checked = false;
	for(var i=0;i<arrBox.length;i++){
		input = arrBox[i];
		if(input.checked == true){
			checked = true;
			break;
			}
		}
	
	return checked;
	}
	
function check_form(myform){
	for(var i=0;i<myform.elements.length;i++){
		var input =myform.elements[i];
		if(input.type == 'text'|| input.type =='textarea' ){
			if(input.value ==''){
				window.alert(alert_FORM_VIDE);
				return false;
				}
			}

	}
	
		
		
	return true;
	
	}
	
function check_form_modif(myform){
	for(var i=0;i<myform.elements.length;i++){
		var input =myform.elements[i];
		if(input.type == 'text'|| input.type =='textarea' ){
			if(input.value =='' && input.name!='subject' && input.name != 'body'){
				window.alert("Some textfields are empty");
				return false;
				}
			}
		if( input.name == 'date'){
				jj = input.value.substring(0,2);
				mm = input.value.substring(3,5);
				aaaa = input.value.substring(6,10);
				
				if(mm<=7){
						if(mm%2==0)maxjour = 30;
						else maxjour = 31;
					}else{
						if(mm%2==0)maxjour = 31;
						else maxjour = 30;
						}
				
				if(jj>31 || jj>maxjour || mm>12 || jj<1 || mm<1|| aaaa<2006){
						window.alert("incorrect date!");
						return false;
					}
			}
	}
	var a = search_checkbox(myform);
	if(!are_checked(a)){
		window.alert("Please, check at least one checkbox");
		return false;
		}
		
		
	return true;
	
	}
	
function emailCheck(emailValue) 
{
            var str = emailValue // email string
            var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|(@\-)/; // not valid
            var reg2 = /^[a-zA-Z0-9\-\._!#\$%&\*\+=\^\{\}~]+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
            var result ;
            if (!reg1.test(str) && reg2.test(str)) 
            { // if syntax is valid
                        result = true;
            } else {
                        result = false;
            }
            return result;
}
