
﻿function CheckEnable()
{if(document.getElementById("condUse").checked==true)
{$('#login_btn').html("<a onclick=\"submit_signin_form();return false;\" rel=\"nofollow\"><div>Tạo tài khoản</div></a>");}
else
{$('#login_btn').html("<span rel=\"nofollow\"><div style=\"background-color:#AAAAAA;\">Tạo tài khoản</div></span>");}}
function Processing()
{$('#login_btn').html("<span rel=\"nofollow\"><div style=\"background-color:#AAAAAA;\">Đang xử lý..</div></span>");}
function send_email_forgot_password()
{if(document.getElementById("forgot_password_email_field").value=="")
{alert("Bạn phải nhập Email!");document.getElementById("forgot_password_email_field").focus();return false;}
var act="act=sendemailforgotpass";var email="&email="+document.getElementById("forgot_password_email_field").value;var url=pathClientAjax+"handler/BlogHandler.aspx?"+act+email+"&d="+(new Date()).getTime();$.get(pathClientAjax+"handler/BlogHandler.aspx",act+email+"&d="+(new Date()).getTime(),function(data){if(data!=""){alert("Gửi thành công, bạn kiểm tra lại Email để biết thông tin!");document.getElementById('login_box').style.display='none';}});}
function showformfogotpass()
{var act="act=showformfogotpass";var url=pathClientAjax+"handler/LogHandler.aspx?"+act+"&d="+(new Date()).getTime();$.get(pathClientAjax+"handler/LogHandler.aspx",act+"&d="+(new Date()).getTime(),function(data){if(data!=""){$('#login_box_popup_header').html("Bạn quên mật khẩu?");$('#contentlogin').html(data);$('#login_box').show();document.getElementById("forgot_password_email_field").focus();}
else
{$('#login_box').hide();}});}
function submit_signin_form()
{if(document.getElementById("name_field").value=="")
{alert("Bạn phải nhập Họ Tên!");document.getElementById("name_field").focus();return false;}
if(document.getElementById("email_field").value=="")
{alert("Bạn phải nhập Tên đăng nhập!");document.getElementById("email_field").focus();return false;}
if(document.getElementById("password_field").value=="")
{alert("Bạn phải nhập Mật khẩu!");document.getElementById("password_field").focus();return false;}
if(document.getElementById("password_verify_field").value=="")
{alert("Bạn phải nhập lại Mật khẩu!");document.getElementById("password_verify_field").focus();return false;}
if(document.getElementById("password_verify_field").value!=document.getElementById("password_field").value)
{alert("Mật khẩu nhập lại chưa đúng!");document.getElementById("password_verify_field").focus();return false;}
if(document.getElementById("email").value=="")
{alert("Bạn phải nhập Email!");document.getElementById("email").focus();return false;}
Processing();var act="act=submitSignin";var name="&name="+encodeURI(document.getElementById("name_field").value);var username="&username="+encodeURI(document.getElementById("email_field").value);var pass="&pass="+document.getElementById("password_field").value;var loca="&loca="+encodeURI(document.getElementById("location_field").value);var phone="&phone="+document.getElementById("phone").value;var mobilephone="&mobilephone="+document.getElementById("mobilephone").value;var email="&email="+document.getElementById("email").value;var newsletter="&newsletter=0";if(document.getElementById("contact_me_field").checked==true)
newsletter="&newsletter=1";var memforum="&memforum=0";if(document.getElementById("memberforum").checked==true)
memforum="&memforum=1";var al=act+name+username+pass+loca+phone+mobilephone+email+newsletter+memforum;var url=pathClientAjax+"handler/LogHandler.aspx?"+al+"&d="+(new Date()).getTime();$.get(pathClientAjax+"handler/LogHandler.aspx",al+"&d="+(new Date()).getTime(),function(data){if(data=="email")
{alert("Địa chỉ email của bạn đã tồn tại trong hệ thống rồi!");document.getElementById("email").focus();$('#login_btn').html("<a onclick=\"submit_signin_form();return false;\" rel=\"nofollow\"><div>Tạo tài khoản</div></a>");}
else if(data=="username")
{alert("Tên đăng nhập của bạn đã tồn tại trong hệ thống rồi!");document.getElementById("email_field").focus();$('#login_btn').html("<a onclick=\"submit_signin_form();return false;\" rel=\"nofollow\"><div>Tạo tài khoản</div></a>");}
else if(data=="username1")
{alert("Tên đăng nhập của bạn không được gõ Tiếng Việt và không chứa khoản trắng!");document.getElementById("email_field").focus();$('#login_btn').html("<a onclick=\"submit_signin_form();return false;\" rel=\"nofollow\"><div>Tạo tài khoản</div></a>");}
else if(data=="pass")
{alert("Mật khẩu của bạn không được gõ Tiếng Việt và không chứa khoản trắng!");document.getElementById("password_field").focus();$('#login_btn').html("<a onclick=\"submit_signin_form();return false;\" rel=\"nofollow\"><div>Tạo tài khoản</div></a>");}
else
{$('#login_box_popup_header').html("Tạo tài khoản thành công!");$('#contentlogin').html(data);$('#login_box').show();}});}
function submit_login_form()
{if(document.getElementById("txtnamelogin").value=="")
{alert("Bạn phải nhập Tên đăng nhập!");document.getElementById("txtnamelogin").focus();return false;}
if(document.getElementById("txtPassword").value=="")
{alert("Bạn phải nhập Mật khẩu!");document.getElementById("txtPassword").focus();return false;}
Processing();var act="act=submitLogin";var username="&username="+document.getElementById("txtnamelogin").value;var pass="&pass="+document.getElementById("txtPassword").value;var registpass="&registpass=0";if(document.getElementById("chkRemember").checked==true)
registpass="&registpass=1";var lnk="&lnk="+document.getElementById("hdredirlnk").value;var url=pathClientAjax+"handler/LogHandler.aspx?"+act+username+pass+registpass+lnk+"&d="+(new Date()).getTime();$.get(pathClientAjax+"handler/LogHandler.aspx",act+username+pass+registpass+"&d="+(new Date()).getTime(),function(data){if(data!=""){$('#mjLogin').html(data.split("<==>")[0]);$('#login_box').hide();if(data.split("<==>")[1]!="")
window.location=data.split("<==>")[1];}
else
{alert("Tên đăng nhập hoặc Mật khẩu của bạn chưa đúng!");$('#login_btn').html("<a onclick=\"submit_login_form();return false;\" rel=\"nofollow\"><div>Đăng nhập</div></a>");}});}
function ShowFormSignin()
{var act="act=showformsignin";var url=pathClientAjax+"handler/LogHandler.aspx?"+act+"&d="+(new Date()).getTime();$.get(pathClientAjax+"handler/LogHandler.aspx",act+"&d="+(new Date()).getTime(),function(data){if(data!=""){$('#login_box_popup_header').html("Tạo tài khoản");$('#contentlogin').html(data);$('#login_box').show();}
else
{$('#login_box').hide();}});}
function showformLogin()
{var act="act=showformlogin";var url=pathClientAjax+"handler/LogHandler.aspx?"+act+"&d="+(new Date()).getTime();$.get(pathClientAjax+"handler/LogHandler.aspx",act+"&d="+(new Date()).getTime(),function(data){if(data!=""){$('#login_box_popup_header').html("Đăng nhập");$('#contentlogin').html(data);$('#login_box').show();}
else
{$('#login_box').hide();}});}
function RequestLogin(redlink)
{guestId=getCookieForLogin('gGstId');guestEmail=getCookieForLogin('GuestEmail');guestAccount=getCookieForLogin('UserName');guestName=getCookieForLogin('GuestName');guestAgentName=getCookieForLogin('GAgentNameContact');if(guestId!=null)
gId=guestId.split('=')[1];else
gId=null;if(guestEmail!=null)
gEmail=guestEmail.split('=')[1];else if(guestAccount!=null)
gEmail=guestAccount.split('=')[1];else
gEmail=null;if(guestName!=null)gName=guestName.split('=')[1];else if(guestAgentName!=null)gName=guestAgentName.split('=')[1];else gName='';if(gId!=null&&gEmail!=null)
{window.location=pathClientAjax+redlink;}
else
{var act="act=showformlogin"+"&lnk="+redlink;var url=pathClientAjax+"handler/LogHandler.aspx?"+act+"&d="+(new Date()).getTime();$.get(pathClientAjax+"handler/LogHandler.aspx",act+"&d="+(new Date()).getTime(),function(data){if(data!=""){$('#login_box_popup_header').html("Đăng nhập");$('#contentlogin').html(data);$('#login_box').show();}
else
{$('#login_box').hide();}});}}
function CheckLogin_PopupForm()
{var act="act=CheckLogin_PopupForm";$.get(pathClientAjax+"handler/LogHandler.aspx",act+"&d="+(new Date()).getTime(),function(data){if(data!=""){$('#login_box_popup_header').html("Đăng nhập");$('#contentlogin').html(data);$('#login_box').show();}
else
{$('#login_box').hide();}});}
function do_logout()
{var act="act=submitLogout";var url=pathClientAjax+"handler/LogHandler.aspx?"+act+"&d="+(new Date()).getTime();$.get(pathClientAjax+"handler/LogHandler.aspx",act+"&d="+(new Date()).getTime(),function(data){if(data!=""){CheckLogin();if(window.location.href.indexOf("changeinfo")!=-1||window.location.href.indexOf("ViewGuestInfo")!=-1||window.location.href.indexOf("MyAlert")!=-1||window.location.href.indexOf("PropertyAsd")!=-1||window.location.href.indexOf("ListAdsGuest")!=-1)
window.location=pathClient;}
else
{alert("Logout không thành công!");}});}
function getCookieForLogin(name)
{var dc=document.cookie;var prefix=name+"=";var begin=dc.indexOf("; "+prefix);if(begin==-1)
{begin=dc.indexOf(prefix);if(begin!=0)return null;}
else
{begin+=2;}
var end=document.cookie.indexOf(";",begin);if(end==-1)
{end=dc.length;}
return unescape(dc.substring(begin+prefix.length,end));}
function convertTounicode(s)
{if(s==null||s=="")return"";var atemp=new Array();var name="";atemp=s.split(',');for(i=0;i<atemp.length;i++)
name+=String.fromCharCode(atemp[i]);return name;}
function CheckLogin(){var act="act=checklogin";var url=pathClientAjax+"handler/LogHandler.aspx?"+act+"&d="+(new Date()).getTime();$.get(pathClientAjax+"handler/LogHandler.aspx",act+"&d="+(new Date()).getTime(),function(data){if(data!=""){$('#mjLogin').html(data.split("<==>")[0]);}
else
{$('#mjLogin').hide();}});}
function CheckLoginNew()
{tem=getCookieForLogin('GuestName');if(tem!=null)
temp=convertTounicode(tem.replace('GuestName','').replace('=',''));else temp=convertTounicode(tem);if(temp=="")
$('#mjLogin').html("<a href=\"javascript:showformLogin()\">Đăng nhập</a>&nbsp;<span >|</span>&nbsp;<a  href=\"javascript:ShowFormSignin()\">Đăng ký (miễn phí)</a>&nbsp;<span >|</span>&nbsp;");else
$('#mjLogin').html("<span style=\"margin:0px; text-align:center\"><strong><span style=\"font-size:11px\">Chào "+temp+"</span></strong></span>&nbsp;<span >|</span>&nbsp;<a  href=\"javascript:do_logout()\">Thoát</a>&nbsp;<span >|</span>&nbsp;");}
function KeyPressLogin(e,type)
{var unicode=e.charCode?e.charCode:e.keyCode;if(unicode==13)
{switch(type){case"loginhead":submit_login_form();break;case"fogotpass":send_email_forgot_password();break;}}}
function clickTienIch(div_id,dis)
{var id=$('#'+div_id);if(id!=null){id.css('display',dis);}}
function HrefOnSubmit(t)
{temp=getCookieForLogin('GAgentID');if(temp!=null)
gId=temp.split('=')[1];else
gId='';if(t=='0'||t=='5')
window.location=pathClient+"/ListAdsGuest.aspx?id="+gId+"&t="+t;else
window.location=pathClient+"/changepass.aspx?id="+gId;}
function login_box_close()
{document.getElementById('login_box').style.display='none';return false;}