﻿/// <reference path="../jquery-vsdoc.js" />
/// <reference path="../jquery.js" />
function CheckLogin() {
    var username = $.trim($("#username").val());
    var pwd = $.trim($("#password").val());
	
    if (username.length < 1 || pwd.length < 1) {
        window.location.href = getRootPath() + "agent-area.aspx";
        return;
    }
    $.ajax({
        "url": getRootPath() + "AjaxHandler/AgentHandler.ashx?action=login&username="
		+ username + "&pwd=" 
		+ pwd+"&timeflag="+new Date().getTime(),
        "type": "GET",        
        "dataType": "xml",
        "success": function ($xml) {
		//alert("timeflag:"+$xml.$xml+"||Password:"+pwd);
            window.location.href = getRootPath() + "agent-area.aspx";
        }
    });
}
function getCookie(c_name)
{
if (document.cookie.length>0)
{ 
c_start=document.cookie.indexOf(c_name + "=")
if (c_start!=-1)
{ 
c_start=c_start + c_name.length+1 
c_end=document.cookie.indexOf(";",c_start)
if (c_end==-1) c_end=document.cookie.length
return unescape(document.cookie.substring(c_start,c_end))
} 
}
return ""
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : "; expires="+exdate.toGMTString())
}
function defaultLogin(e) {
    var msie = (document.all) ? true : false;
         var keycode;
         var e=e||event;
          keycode=e.keyCode||e.which;
          if (keycode == 13)
         {
            CheckLogin();
         }
}
function nav(url) {
    window.location = url;
}
function backtolist() {
	var currentCountry = getCookie("country");
    var currentRegion = getCookie("regionid");
    var currentminprice = getCookie("minprice");
    var currentmaxprice = getCookie("maxprice");
    var currentBed = getCookie("beds");
    window.location = getRootPath()+"properties-for-sale.aspx?countryid="+currentCountry
	+"&regionid="+currentRegion+"&minprice="+currentminprice+"&maxprice="+currentmaxprice+"&beds="+currentBed;
}
function LogOut() {
    $.ajax({
        "url": getRootPath() + "AjaxHandler/AgentHandler.ashx?action=logout",
        "type": "GET",
        "dataType": "xml",
		"timeflag": new Date().getTime(),
        "success": function ($xml) {
            window.location.href = getRootPath() + "default.aspx";
        }
    });
}

function GetCurrentUser() {
    $.ajax({
        "url": getRootPath() + "AjaxHandler/AgentHandler.ashx?action=getuser",
        "type": "GET",
        "dataType": "xml",
        "success": function ($xml) {
            if ($($xml).find("flag").text() == "1") {
                window.location.href = getRootPath() + "default.aspx";
            }
            else {
                $("#currentUser").text($($xml).find("name").text());
            }
        }
    });
}
function getRootPath() {
    var strFullPath = window.document.location.href;
    var strPath = window.document.location.pathname;
    var pos = strFullPath.indexOf(strPath);
    var prePath = strFullPath.substring(0, pos);
    //return (prePath + "/");
	 return ("/");
}
