/***************************************
	name :		AuthenticationCheck
	process :	checks obligatory fields of the form
	in param :	the form
	out param :	true or false
****************************************/
function AuthenticationCheck(ZeForm)
{
	var b_Go = false;
	
	if(ZeForm.out_email.value.length < 6)
	{
		alert(txt_TooShortEmail);
		return false ;
	}
	else if(ZeForm.out_password.value.length < 3)
	{
		alert(txt_TooShortPassword);
		return false ;
	}

	return true ;
}


/***************************************
	name :		CheckOrder
	process :	
	in param :	the form
	out param :	true or false
****************************************/
function CheckOrder(ZeForm)
{
	var b_PackageChosen = false;
	for(var i = 0 ; i < ZeForm.out_audit_package.length ; i++)
	{
		if(ZeForm.out_audit_package[i].checked)
			b_PackageChosen = true;
	}
	
	
	if( ! b_PackageChosen)
	{
		alert('Vous devez selectionner un package !') ;
		return false ;
	}
	
	return true ;
}

/***************************************
	name :		email_check
	process :	checks an e-mail address
	in param :	e-mail
	out param :	true	e-mail ok (!)
				false	e-mail not ok (!!!)
****************************************/
function Email_check(email) {
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return filter.test(s_Email) ;
}

/***************************************
	name :		PasswordRequestCheck
	process :	checks obligatory fields of the form
	in param :	the form
	out param :	true or false
****************************************/
function PasswordRequestCheck(form)
{
	var b_Go = false;
	
	if( ! Email_check(form.out_email.value))
	{
		alert(txt_InvalidEmail);
		return false ;
	}
	
	return true ;
}


/***************************************
	name :		SubscriptionCheck
	process :	checks obligatory fields of the form
	in param :	the form
	out param :	true or false
****************************************/
function SubscriptionCheck(SubscrForm)
{
	var b_Go = false;
	
	if(SubscrForm.out_password.value.length < 4)
	{
		alert(txt_TooShortPassword);
		return false ;
	}
	else if(SubscrForm.out_password.value != SubscrForm.out_password_confirm.value)
	{
		alert(txt_PasswordConfirmation);
		return false ;
	}
	else if( ! Email_check(SubscrForm.out_email.value))
	{
		alert(txt_InvalidEmail);
		return false ;
	}
	else if( ! CheckOrder(SubscrForm))
	{
		return false ;
	}
	else if( ! SubscrForm.out_conditions.checked)
	{
		alert(txt_AcceptationError) ;
		return false ;
	}
	
	return true ;
}


/***************************************
	name :		SubmitPromoCode
	process :	
	in param :	the form
	out param :	true or false
****************************************/
function SubmitPromoCode(ZeForm)
{
	ZeForm.action = 'index.php?module=order&action=ApplyPromoCode';
	
	if(ZeForm.out_promo_code.value == '')
	{
		alert('Vous devez renseigner un code avantage') ;
		return false ;
	}
	
	ZeForm.submit() ;
}



/***************************************
	name :	ComOpCheck
	process :	checks obligatory fields of the form
	in param :	the form
	out param :	true or false
****************************************/
function ComOpCheck(ComOpForm)
{
	var b_Go = false;
	
	if( ComOpForm.out_name.value.length < 3 )
	{
		alert(txt_WrongOperationName) ;
		return false ;
	}
	
	if( ! ComOpForm.out_operation_type[0].checked &&  ! ComOpForm.out_operation_type[1].checked)
	{
		alert(txt_ChooseComOpType) ;
		return false ;
	}
	
	var a_PackDiscount = $$('.pack_discount');
	
	for(var i = 0 ; i < a_PackDiscount.length ; i++)
	{
		if($F(a_PackDiscount[i]) > 50 || $F(a_PackDiscount[i]) < 0)
		{
			alert(txt_PackDiscountRange) ;
			return false ;
		}
	}
	
	if(ComOpForm.out_operation_type[0].checked)
	{
		if(ComOpForm.out_a_active_on_subscription.checked == false && ComOpForm.out_a_active_on_order.checked == false)
		{
			alert(txt_ChooseComOpActivationMode) ;
			return false ;
		}
	}
	else if(ComOpForm.out_operation_type[1].checked)
	{
		if(ComOpForm.out_promo_code.value.length < 4)
		{
			alert(txt_TooShortPromoCode) ;
			return false ;
		}
	
		if(ComOpForm.out_pc_active_on_subscription.checked == false && ComOpForm.out_pc_active_on_order.checked == false)
		{
			alert(txt_ChooseComOpActivationMode) ;
			return false ;
		}
	}
	
	return true ;
}