/*	function checkEmail() {
		if (document.registration_form.email_check.value==document.registration_form.email.value) document.registration_form.email_img.style.display="inline";
		else document.registration_form.email_img.style.display="none";
	}

	function checkPass() {
		if (document.registration_form.password.value==document.registration_form.password2.value) document.registration_form.pass_img.style.display="inline";
		else document.registration_form.pass_img.style.display="none";
	}
*/	
	function checkAge(date_birth){	
		var text_message = "Enter please value in field 'Date of Birth' in formate: dd/mm/yyyy";
		var age;
		
		var res = date_birth.value.match("^(0[1-9]|[1-2][0-9]|3[01])\/(0[1-9]|1[0-2])\/(19[0-9]{2}|2[0-9]{3})$");
		if(!res){			
			//alert(text_message);
			return false;
		}
				
		var birth = new Date(res[3],res[2],res[1]);
		var now_date = new Date();		
			
		if (birth.getFullYear()>=now_date.getFullYear()){
			//alert(text_message);
			return false;
		}else{
			if ((birth.getMonth() == now_date.getMonth()+1 && birth.getDate()>now_date.getDate()) || (birth.getMonth()>now_date.getMonth()+1)){				
				age = now_date.getFullYear() - birth.getFullYear() - 1;				
			}else{				
				age = now_date.getFullYear() - birth.getFullYear();
			}
		}
				
		return age;
				
	}
	
	function AgeTitle(user_title,date_birth){
		var age;
		if(user_title.value){
			age = checkAge(date_birth);
			if (age){
				switch (user_title.value) {
				   case 'Mr':
				   case 'Mrs':
				     if(!(age>20 && age<90))
				     	return false;
				     break;
				   case 'Dr':
				     if(!(age>21 && age<90))
				     	return false;
				     break;
				   case 'Prof':
				     if(!(age>26 && age<90))
				     	return false;
				     break;			   
				}
			}
		}
		
		return true;
	}
	
	function CheckMail(name,host){	
		var user_work_email = name.value+"@"+host.value;
		//var text_message = "E-mail is failed";
		var reg= new RegExp("^[a-z][0-9a-z\._\-\']*@([0-9a-z\._-]+\.)+[a-z]{2,3}$", "i");//^[a-z][0-9a-z\._]*@([0-9a-z_-]+\.)+[a-z]{2,3}$	
       	if (!reg.test(user_work_email)) {
		//alert('user_work_email');
       		//alert(text_message);
       		return false;
       	}
       	
       	return true;		
	}
	
	function CheckPasswordLength(password1,password2){		
		if (password1.value.length<6 || password2.value.length<6){			
			return false;
		}
		
		return true;	
	}
	
	function CheckPasswordCompare(password1,password2){
		if (password1.value != password2.value){			
			return false;
		}
		
		return true;
	}
		
	function CheckText(element){
		var text_message = "Required field is empty";
		if(element.value ==''){
			//alert(text_message);
			return false;
		}		
		
		return true;
	}
	
	function IsChecked(element){
		var text_message = "Required field is empty";
		if(!element.checked){
			//alert(text_message);			
			return false;
		}
		return true;
	}
	
	function CheckDataBirth(element){
		var reg= new RegExp("^(0[1-9]|[1-2][0-9]|3[01])\/(0[1-9]|1[0-2])\/(19[0-9]{2}|2[0-9]{3})$", "i");
		if (!reg.test(element.value)){			
			return false;
		}
		return true;
		
		
	}
	/*
	value of element is writed ajax.js
	*/
	function CheckOrganization(element){
		if(!(element.value == 'exist_org')){
			return false;
		}
		return true;
	}

	//message - string that split on section with help splitter '|'
	function ConfirmEmailWebsite(message){	
		var aMess = message.split('|');
		
		if(aMess.length >1){

			var res = confirm(aMess[0]);

			if(!res){
				res = confirm(aMess[1]);

				if(res){
					if(MainCheck(registration_form)){
						document.registration_form.submit();
					}
				} 
			}		
		}
	}

	function SubmitForm()
    {
        if(MainCheck(registration_form)){
            document.registration_form.submit();
        }
    }
	function MainCheck(form){
		var aCheck = new Array();
		var aMess = new Array();
		
		var aCheckAdd = new Array();
		var aMessAdd = new Array();
		
		var UCheck = new Array();
		var UMess = new Array();
		
		//var campus_flag = form.campus_flag;//'','exist_org','not_exist_org'
		
		with(form){
				aCheck[0] = CheckText(user_title);
				aMess[0] = "Title is required";
		
				aCheck[1] = CheckText(user_first_name);
				aMess[1] = "First name is required";
		
				aCheck[2] = CheckText(user_last_name);
				aMess[2] = "Last name is required";
		
//				aCheck[3] = CheckText(user_organization_name);
//				aMess[3] = "Registered Name of Organization is required";
				
				//aCheck[4] = CheckDataBirth(user_date_birth);
				//aMess[4] = "Date of Birth is wrang";							
					
				//if(campus_flag.value == 'exist_org'){//choosed element of drop down have not value 'Not Listed'
		
				//	aCheck[5] = CheckText(user_campus_pro_nro);
				//	aMess[5] = "Campus name is required";
				//}else if(campus_flag.value == 'not_exist_org'){//Not Listed
				
				/*if(user_campus_pro_nro.value == -1){
					aCheck[6] = CheckText(user_campus);
					aMess[6] = "Campus name is required";
		
					aCheck[7] = CheckText(user_city);
					aMess[7] = "Suburb/City is required";
		
					aCheck[8] = CheckText(user_state);
					aMess[8] = "State is required";
		
					aCheck[9] = CheckText(user_post_code);
					aMess[9] = "Post-code is required";
		
					aCheck[10] = CheckText(user_country);
					aMess[10] = "Country is required";
		
					aCheck[11] = CheckText(org_site);
					aMess[11] = "Organization's Website is required";		
					
				}
				*/
		
				aCheckAdd[0] = CheckText(username);
				aMessAdd[0] = "Username is required";
		
				aCheckAdd[1] = CheckMail(user_work_email1,user_work_email2);
				aMessAdd[1] = "E-mail is failed";
				
				aCheckAdd[2] = CheckPasswordLength(password,password2);
				aMessAdd[2] = "Length password is wrang";
				
				aCheckAdd[3] = CheckPasswordCompare(password,password2);
				aMessAdd[3] = "Compare of passwords is wrang";
										
				aCheckAdd[4] = IsChecked(allow_connect_via_email);
				aMessAdd[4] = "Communicate with you via e-mail is required";
		
				aCheckAdd[5] = IsChecked(ack_terms);
				aMessAdd[5] = "Terms of Service is required";
		}	
		
		UCheck = aCheck.concat(aCheckAdd);
		UMess = aMess.concat(aMessAdd);
		
		var tempCheck = 0;
		var msg = "";
		
		for (var i = 0; i < UCheck.length; i++)
			if(UCheck[i] == false)
			{
				tempCheck = 1;
				msg += "\t"+UMess[i]+"\r\n";
			}
			
		if(tempCheck == 1)
		{			
			alert(msg);
			return false
		}
		
		return true;			
	}
	

