/***************************************************************************************************
* SITE: checkMailForm.js
****************************************************************************************************
* Mailing List form checking
****************************************************************************************************
* Contents:
*
* E_MAIL FUNCTIONS:
*
* MEMBER FUNCTIONS:
* - checkEmail(email)				: check if the email is valid
* - updateMemberProfile()			: sets the profile document of a member
*
* GENERAL FUNCTIONS:
* - getRuleMembers()					: 
* - function numberOk(str)			:
* - function charOk(str,badChar)	:
* - function validForm()			:
*
*
****************************************************************************************************
* Written by: Vladi Vexlers
* Company   : Scepia Ltd.
***************************************************************************************************/
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function validateEmail(s_email) {
	var re;
	re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	return re.test(s_email)
} 

function numberOk(str){
	var numOk="0123456789"
	for(i=0; i<str.length; i++){
		if(numOk.indexOf(str.substring(i,i+1))==-1){
			return false;
		}
	}
	return true;
}

function charOk(str,badChar){
	var charPlace;
	for(i=0;i<badChar.length; i++){
		charPlace=badChar.charAt(i);
		if(str.indexOf(charPlace,0)!=-1){
			return false;
		}
	}
	return true;
}


function checkUniForm(f_form){
	var s_required, s_type, s_alt, s_name,  s_type, s_value, type, s_fields, s_fieldsVal, s_field,s_fieldsSpl,i_fieldsSpl;
	var s_NoMessage = siteDic.FILL;
	var s_BadMessage = siteDic.BAD;
	for (var i_count=0; i_count<f_form.length ; i_count++){
		s_name		= f_form(i_count).name;
		s_value		= f_form(i_count).value;
		s_type		= f_form(i_count).s_type;
		s_required	= f_form(i_count).s_required;
		s_alt		= f_form(i_count).s_alt;
		type		= f_form(i_count).type;
		if (s_value==""){
			if (s_required=="true"){
				if (s_type=="select_multi"){
					s_fields	= f_form(i_count).s_fields;
					s_fieldsSpl	= s_fields.split(";");
					s_fieldsVal = "";
					for(i_fieldsSpl=0 ; i_fieldsSpl<s_fieldsSpl.length ; i_fieldsSpl++){
						if (i_fieldsSpl!=0)
							s_fieldsVal+="-";
						s_field		 = s_fieldsSpl[i_fieldsSpl];
						s_fieldsVal += document.all[s_field].value;
					}
					document.all[s_name].value = s_fieldsVal
				}else{
					alert(s_NoMessage + s_alt)
					document.all[s_name].focus();
					return false
				}
			}
		}	
		else{
			switch(s_type){
				case "email"	:
					if (!validateEmail(s_value)){
						alert(s_BadMessage + s_alt)
						document.all[s_name].focus();
						return false
					}
					break;
				case "number"	:
					if (!numberOk(s_value)){
						alert(s_BadMessage + s_alt)
						document.all[s_name].focus();
						return false
					}
					break;
				default			:
					break;
			}
		}
	}
	
	f_form.submit();
}