/*function sendRequest(toPost, Link, callBack, type){
	$.post( URL+Link , toPost ,function(data){
		setTimeout(callBack, 10);	
	},type); 
 } */
 

function true_field(text_id)
{
	$('#'+text_id+'_error_text').removeClass('error');
	$('#'+text_id+'_error_text').addClass('discreption');	
	$('#'+text_id+'_error_text').text('');
	
}
function phone_validation(text_id)
{			
	if ($('#'+text_id).attr('value').length<8&&$('#'+text_id).attr('value')!='')
	{
	
		$('#'+text_id+'_error_text').removeClass('discreption');
		$('#'+text_id+'_error_text').addClass('error');
		$('#'+text_id+'_error_text').text('Must be > 7 numbers.');		
		return false;			
	}
	else if($('#'+text_id).attr('value')!='')
	{
		var plus=$('#'+text_id).attr('value').slice(0,2);
		if (plus=="++")
		{
			var no=$('#'+text_id).attr('value').slice(2,$('#'+text_id).attr('value').length);
			if (isNaN(no))
			{							
			
				$('#'+text_id+'_error_text').removeClass('discreption');
				$('#'+text_id+'_error_text').addClass('error');
				$('#'+text_id+'_error_text').text('Must be numbers only.');
				return false;							
			}
			else if (no.length<8)
			{						
				$('#'+text_id+'_error_text').removeClass('discreption');
				$('#'+text_id+'_error_text').addClass('error');
				$('#'+text_id+'_error_text').text('Must be > 7 numbers.');		
				return false;	
			}
		}
		else if (isNaN($('#'+text_id).attr('value')))
		{
			$('#'+text_id+'_error_text').css('display','block');
			$('#'+text_id+'_error_text').text('Must be numbers only.');	
			return false;							
		}
	}
	true_field(text_id);
	
	return true;		
}


function check_empty_text(text_id)
{
	if($('#'+text_id).attr('value')=='')
	{		
		$('#'+text_id+'_error_text').removeClass('discreption');
		$('#'+text_id+'_error_text').addClass('error');
		$('#'+text_id+'_error_text').text('This field is mandatory');
		return true;
	}		
	else return false;
}
function email_format_validation(text_id)
{
	if($('#'+text_id).attr('value')=='')
	{		
		$('#'+text_id+'_error_text').removeClass('discreption');
		$('#'+text_id+'_error_text').addClass('error');
		$('#'+text_id+'_error_text').text('This field is mandatory');	
		return false;
	}		
	else if (($('#'+text_id).attr('value').search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)) == -1)
	{		
		$('#'+text_id+'_error_text').removeClass('discreption');
		$('#'+text_id+'_error_text').addClass('error');
		$('#'+text_id+'_error_text').text('Wrong Email formate');
		return false;
	}
	else
	{		
		true_field(text_id);
		return true;
	}
	
}
function email_validation(text_id)
{
	if($('#'+text_id).attr('value')=='')
	{		
		$('#'+text_id+'_error_text').removeClass('discreption');
		$('#'+text_id+'_error_text').addClass('error');
		$('#'+text_id+'_error_text').text('This field is mandatory');
	
		return false;
	}		
	else if (($('#'+text_id).attr('value').search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)) == -1)
	{		
		$('#'+text_id+'_error_text').removeClass('discreption');
		$('#'+text_id+'_error_text').addClass('error');
		$('#'+text_id+'_error_text').text('Wrong Email formate');
		return false;
	}
	else
	{		
		/*$.getJSON(URL+'/accounts.php/Register/CheckMailDublication','user_email='+$('#'+text_id).attr('value'),
			function(pram){
			var valid=false;
				if(pram.message=='Invalid Email')
				{
					$('#'+text_id+'_error_text').css('display','block');
					$('#'+text_id+'_error_text').text('Dublicate Email');										
				}			
				else					
				{
					true_field(text_id);
				}
			}		
		);	*/		
	}
	true_field(text_id);
	return true;
}
function password_validation(text_id)
{
	if (check_empty_text(text_id)){return false;}
	else if($('#'+text_id).attr('value').length<6)
	{		
		$('#'+text_id+'_error_text').removeClass('discreption');
		$('#'+text_id+'_error_text').addClass('error');
		$('#'+text_id+'_error_text').text('At lest 6 characters.');
		return false;
	}
	else
	{
		true_field(text_id)
		return true;
	}	
}
function re_password_validation(text_id,true_text_id)
{
	if (check_empty_text(text_id)){return false;}	
	else if($('#'+text_id).attr('value')!=$('#'+true_text_id).attr('value'))
	{
		$('#'+text_id+'_error_text').removeClass('discreption');
		$('#'+text_id+'_error_text').addClass('error');
		$('#'+text_id+'_error_text').text('Password does not match.');
		return false;
	}
	else
	{
		true_field(text_id);
		return true;		
	}	
}
function user_name_validation(text_id)
{
	var user_name=$('#'+text_id).attr('value');
	if (check_empty_text(text_id)){return false;}	
	else if(user_name.length<4)
	{		
		$('#'+text_id+'_error_text').removeClass('discreption');
		$('#'+text_id+'_error_text').addClass('error');
		$('#'+text_id+'_error_text').text('At lest 4 characters.');
		return false;
	}
	else
	{
		for(i=0;i<user_name.length;i++)
		{
			if(!((user_name.charAt(i)>='A'&& user_name.charAt(i)<='z' )||( user_name.charAt(i)>='0' && user_name.charAt(i)<='9')||( user_name.charAt(i)==' ')))
			{				
				$('#'+text_id+'_error_text').removeClass('discreption');
				$('#'+text_id+'_error_text').addClass('error');
				$('#'+text_id+'_error_text').text('Only characters and numbers');
				return false;
			}
		}			
	}	
	true_field(text_id)
	return true;
}
function year_validation(text_id)
{
	var dteNow = new Date();
	var intYear = dteNow.getFullYear();
	if (isNaN($('#'+text_id).attr('value'))&&$('#'+text_id).attr('value')!='')
	{		
		$('#'+text_id+'_error_text').removeClass('discreption');
		$('#'+text_id+'_error_text').addClass('error');
		$('#'+text_id+'_error_text').text('Year 4 integers bettween '+(intYear-100)+' and '+intYear+'.');
		return false;
	}
	else if($('#'+text_id).attr('value').length<4 &&$('#'+text_id).attr('value')!='')
	{		
		$('#'+text_id+'_error_text').removeClass('discreption');
		$('#'+text_id+'_error_text').addClass('error');
		$('#'+text_id+'_error_text').text('Year 4 integers.');
		return false;
	}
	else if(($('#'+text_id).attr('value')<'1900'||$('#'+text_id).attr('value')>intYear)&&$('#'+text_id).attr('value')!='')
	{		
		$('#'+text_id+'_error_text').removeClass('discreption');
		$('#'+text_id+'_error_text').addClass('error');
		$('#'+text_id+'_error_text').text('Year bettween '+(intYear-100)+' and '+intYear+'.');
		return false;
	}
	else if(($('#'+'birthday_month').selectedIndex==0||$('#'+'birthday_day').selectedIndex==0)&&$('#'+text_id).attr('value')!='')
	{		
		$('#'+text_id+'_error_text').removeClass('discreption');
		$('#'+text_id+'_error_text').addClass('error');
		$('#'+text_id+'_error_text').text('Day and month must selected.');		
		return false;
	}
	else
	{
		true_field(text_id)
		return true;		
	}	
}
function birthday_validation()
{
	if($('#'+'birthday_month').selectedIndex!=0&&$('#'+'birthday_day').selectedIndex!=0&&$('#'+'birthday_year').attr('value')!='')
	{
		return year_validation('birthday_year');
	}
}



function email_validation_settings(text_id)
{
	var valid2;	
	if($('#'+text_id).attr('value')=='')
	{		
		$('#'+text_id+'_error_text').removeClass('discreption');
		$('#'+text_id+'_error_text').addClass('error');
		$('#'+text_id+'_error_text').text('This field is mandatory');
	
		return false;
	}		
	else if (($('#'+text_id).attr('value').search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)) == -1)
	{		
		$('#'+text_id+'_error_text').removeClass('discreption');
		$('#'+text_id+'_error_text').addClass('error');
		$('#'+text_id+'_error_text').text('Wrong Email formate');
		return false;
	}
	else
	{	
		$.getJSON(URL+'/accounts.php/Register/CheckMailDublicationSettings/user_email/'+$('#'+text_id).attr('value')+'/user_id/'+myID,function(pram){
				if(pram.message=='Invalid Email')
				{
					$('#'+text_id+'_error_text').css('display','block');
					$('#'+text_id+'_error_text').text('Dublicate Email');
				}			
				else					
				{
					true_field(text_id);
			var dataOfSettings={'userID':myID
 			,'settingUserEmail':$('#settingUserEmail').val()
 			,'settingUsername':$('#settingUsername').val()
 			,'settingQuestion':$('#settingQuestion').val()
 			,'settingAnswer':$('#settingAnswer').val()};
					sendRequest(dataOfSettings, '/settings.php/update/updateAccount', '$("#updateSettingsMess").text(data.message).fadeIn();','json');
					
				}
			}		
		);
		
	}
	
}
