//

//function $(id){return document.getElementById(id);}


function note(){
		//comment Note for all
	var tags = document.getElementsByTagName('*');
		for (var v=0; v<tags.length; v++){
			
		if(tags[v].type == 'text' || tags[v].type == 'password'){
			
			
			tags[v].onfocus = function(){
				var input_note = this.id+'_Note';
				if (this.value == this.defaultValue) this.value = "";
				$(input_note).className = $(input_note).className.replace(/ sub_menu_hidden/g,' sub_menu_visible');
			}
			tags[v].onblur = function(){
				var input_note = this.id+'_Note';
				if (!this.value) this.value = this.defaultValue;
				$(input_note).className = $(input_note).className.replace(/ sub_menu_visible/g,' sub_menu_hidden');
			}
		}
	}
}






	

function reg_test(type){
	//reg test
	var invalid = 0;
	var regForm = $('regForm');
	
	if(regForm){
		
	var tags = regForm.getElementsByTagName('input');
	for (var v=0;  v<tags.length; v++){
	if(tags[v].type == 'text' || tags[v].type == 'password'){
			
			//start of type
			if(!type){
			if (reg_validate(tags[v])){ $(tags[v].id+'_Head').className = 'valid';  }else{ invalid++; $(tags[v].id+'_Head').className = 'invalid';}
			}else{
				
			tags[v].onfocus = function(){
				//note
				var input_note = this.id+'_Note';
				var input_head = this.id+'_Head';
				if (this.value == this.defaultValue) this.value = "";
				$(input_note).className = $(input_note).className.replace(/ sub_menu_hidden/g,' sub_menu_visible');
				$(input_head).className = 'empty';
				//note				
			}
			
			tags[v].onblur = function(){
				//note
				var input_note = this.id+'_Note';
				var input_head = this.id+'_Head';
				if (!this.value) this.value = this.defaultValue;
				$(input_note).className = $(input_note).className.replace(/ sub_menu_visible/g,' sub_menu_hidden');
				$(input_head).className = 'default';
				//note
				
				if(reg_validate(this)){ $(input_head).className = 'valid';  }else{ $(input_head).className = 'invalid';}	
			}
				}
				//end of type
			}
		}
		
		if(!type) if(!invalid){ return true; }
	}
return false;
}
	

function reg_validate(obj){

switch(obj.id) {
	
	case 'secondName':
	//Ôàìèëèÿ
	if(obj.value.match(/^[a-zà-ÿ¸¨ \-]{1,64}$/i))return true;
	break;
	
	case 'firstName':
	//Èìÿ
	if(obj.value.match(/^[a-zà-ÿ¸¨ \-]{1,64}$/i))return true;
	break;
	
	case 'login':
	//Login + doRequest
	if(obj.value.match(/^[a-z]+[a-z0-9\-\_]{4,30}$/i)){
	doRequest('auth/regValidate', 'id', obj.id, obj.value, 'login_Head');	
	
	
	
	if($(obj.id+'_Head').className == 'valid') 
	return true;
	}else{
	$(obj.id+'_Head').innerHTML = 'Ââåäèòå ëîãèí.';
	return false;
	}
	
	break;
	
	case 'password':
	//Password
	if(obj.value.match(/^[a-z0-9\~\`\!\@\#\$\%\^\&\*\(\)]{5,30}$/i))return true;
	break;
	
	case 'passwordConfirm':
	//passwordConfirm
	if(obj.value.match(/^[a-z0-9\~\`\!\@\#\$\%\^\&\*\(\)]{5,30}$/i) && obj.value == $('password').value)return true;
	break;
	
	
	case 'mail':
	//Mail + doRequest
	if(obj.value.match(/^[-a-z0-9\.\_]+@[-a-z0-9\.]+\.[a-z]{2,4}$/i)){
	doRequest('auth/regValidate', 'id', obj.id, obj.value, 'mail_Head');	
	
	if($(obj.id+'_Head').className == 'valid') 
	return true;
	}else{
	$(obj.id+'_Head').innerHTML = 'Ââåäèòå E-mail.';
	return false;
	}
	
	break;
	
	case 'phone':
	//Mobile
	if(obj.value.match(/^[0-9]{10}$/i))return true;
	break;
	

}

return false;
}
















	
	

onload = function() { 
	
	//Çàïóñê 
	reg_test(1);
	var regForm = $('regForm');if(regForm){
	regForm.onsubmit = function(){ if(reg_test(0)) return true;
	return false;}}
	//Çàïóñê 
	
}
	
	
	
	
	
	
	
	
	
	





	
