/*----REZA----*/

jQuery(document).ready(function(){
	$("#hostLink .signIn").click(function(){
		$('#headerWrapper form.siteform').slideToggle('slow');
	});
	
	$('#top_pwd').show();
	$('#top_pwd_pwd').hide();
	
	$('#top_pwd').focus(function() {
		$('#top_pwd').hide();
		$('#top_pwd_pwd').show();
		$('#top_pwd_pwd').focus();
	});
	$('#top_pwd_pwd').blur(function() {
		if($('#top_pwd_pwd').val() == '') {
			$('#top_pwd').show();
			$('#top_pwd_pwd').hide();
		}
	});
});

function JU_checkAll_profile(){
	if(document.josForm_profile.password.value != document.josForm_profile.password2.value){
		alert('Please retype the same password.');
		return false;	
	}
	
	if(document.josForm_profile.email.value==''){
		alert('Email address can not be empty.');
		return false;	
	}
	
	if(document.josForm_profile.email.value!=''){
		if(!checkEmail(document.josForm_profile.email.value)){
			alert('Please type a valid email address.');
			return false;	
		}
	}
	
	if(document.josForm_profile.username.value==''){
		alert('Please complete User Name.');
		return false;	
	}
	
    var data = 'register=1&username=' + document.josForm_profile.username.value+'&email=' + document.josForm_profile.email.value+'&user_reg_id=' + document.josForm_profile.user_reg_id.value;
	$.ajax({
		url: TemplatePath+'/ajax.php',	
		type: "POST",		
		data: data,		
		cache: false,
		success: function (html) {				
			if(html==1){
				alert('This username already exists.');
				return;
			}
			else if(html==2){
				alert('This email address already exists.');
				return;
			}
			else{
				document.josForm_profile.submit();		
			}
		}		
	});
	
}
	
function checkEmail(email){
	var str=email;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filter.test(str))
		return true;
	else
		return false;
}

function showForget(){
	$('#topSignIn').hide();
	$('#topForgetPwd').show();	
}

function forget_pass() {
	$('#error_popup').css('display', 'none');
	/*document.getElementById('success_popup').style.display = 'none';*/
	//var recipient = trim(document.getElementById('top_email').value);
	var url = window.location.href;
	
	if($('#top_email').val()==''){
		$('#top_email').css('color','red');
		return;
	}
	else{
		$('#top_email').css('color','#000');	
	}
	
	var data = 'forget_pwd=1&top_email=' + $('#top_email').val();
	//alert('alert');	
	//start the ajax
		$.ajax({
		//this is the php file that processes the data and send mail
		url: TemplatePath+'/ajax.php',
		
		//POST method is used
		type: "POST",
		//pass the data
		data: data,
		//Do not cache the page
		cache: false,
		//success
		success: function (html) {

		if(html==1){
				window.location.reload( false );
				return;
			}
			else{
				$('#top_email').css('color','red');
				//document.getElementById('error').style.display='block';
				return;
			}
		}
	});
	//send_ajax_mail(name, email, mess);
	return false
}

function ajax_login(){
	if($('#top_login').val() == 'User Name'){
		$('#top_login').css('color','red');
		return;
	}
	else
		$('#top_login').css('color','black');
		
	if($('#top_pwd_pwd').val() == 'Password'){
		$('#top_pwd_pwd').css('color','red');
		return;
	}
	else
		$('#top_pwd_pwd').css('color','black');

	var data = 'signIn=1&login=' + $('#top_login').val()+'&pwd=' + $('#top_pwd_pwd').val();
		$.ajax({
			url: TemplatePath+'/ajax.php',	
			type: "POST",		
			data: data,		
			cache: false,
			success: function (html) {				
				if(html==1){
					window.location.reload( false );
					return;
				}
				else{
					$('#top_pwd_pwd, #top_login').css('color','red');
					return;
				}
				//else	
				//your code here
			}		
		});
		return false;
}
