﻿Request = {
 QueryString : function(item){
  var svalue = location.search.match(new RegExp("[\?\&]" + item + "=([^\&]*)(\&?)","i"));
  return svalue ? svalue[1] : svalue;
 }
}

function changeOrder(link,oid)
{
    window.location.href=link+"&o="+oid;
}
function changeKey(link)
{
    var k = encodeURI(document.getElementById("key").value);
    window.location.href=link+"&k="+k;
}

function getcookie(name) {
	var cookie_start = document.cookie.indexOf(name);
	var cookie_end = document.cookie.indexOf(";", cookie_start);
	return cookie_start == -1 ? '' : unescape(document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length)));
}

function initBar()
{
//    setSelect($('type'), 't');
    setSelect($('district'), 'd');
    setSelect($('piecesection'), 'p');
    setValue($('key'), 'k');
}

function setSelect(dobj, qs)
{
    try{
    for(var i=0;i<dobj.options.length;i++)
    {
        if(Request.QueryString(qs) == dobj.options[i].value)
        {
            dobj.options[i].selected = true;
            return;
        }    
    }
    }catch(e){}
}
function setValue(dobj, qs)
{
    try{
        if(Request.QueryString(qs)!=null)
        dobj.value = decodeURI(Request.QueryString(qs));  
    }
    catch(e){}
}

function GetDistricts(obj, cityId)
{   
    var objs = $(obj);
    var strpost = "{'cityId':'"+cityId+"'}";
    var ajaxdistrict = new Ajax(null,"","/WebService/WsPieceSelect.asmx/GetDistrictsByCityId",2,strpost,function(rexm){GetDistrictsSuccessCallBack(objs, rexm)});
    ajaxdistrict.post();
}

function GetDistrictsSuccessCallBack(obj, rexm){
    var data = eval("(" + rexm + ")");
    var cur=false;
    var arealist = "";
    try{
        if(Request.QueryString('d')=='-1')
            cur = true;
    }catch(e){}
            
    arealist = "<a href=\"\" "+(cur==true?"class='cur'":"")+" onclick=\"SetArea(-1);return false;\">不限</a>&nbsp;";
    obj.options[0] = new Option("--区县--", -1);
    for(var i=0;i<data.length;i++){
        obj.options[i+1] = new Option(data[i].Key, data[i].Value);
        cur=false;
        if(Request.QueryString('d')!=null)
        {
            try{
            if(Request.QueryString('d')==data[i].Value)
                cur = true;
            }catch(e){}
        }
        arealist += "<a href=\"\" "+(cur==true?"class='cur'":"")+" onclick=\"SetArea("+data[i].Value+");return false;\">"+data[i].Key.replace("区", "")+"</a>&nbsp;";
    }
    setSelect($('district'), 'd');
    $('area').innerHTML = arealist;
    var initd = -1;
    if(Request.QueryString('d')!=null)
        initd =Request.QueryString('d');
    GetPieceSections('piecesetion', initd);
    
}

function GetPieceSections(obj, districtId)
{   
    var objs = $(obj);
    var strpost = "{'districtId':'"+districtId+"'}";
    var ajaxpiece = new Ajax(null,"","/WebService/WsPieceSelect.asmx/GetSectionByDistrictId",2,strpost,function(rexm){GetPieceSectionsSuccessCallBack(objs, rexm)});
    ajaxpiece.post();
}

function GetPieceSectionsSuccessCallBack(obj, rexm){
    var data = eval("(" + rexm + ")");
    obj.options.length=0;
    obj.options[0] = new Option("--片区--", -1);
    for(var i=0;i<data.length;i++){
    obj.options[i+1] = new Option(data[i].Key, data[i].Value);
    }
    setSelect($('piecesetion'), 'p');
}

function GetHouseList(obj, loginName)
{   
    var objs = $(obj);
    var strpost = "{'loginName':'"+loginName+"'}";
    var ajaxh = new Ajax(objs,"<div style='padding-left:235px;padding-top:50px;'><img src='/Images/loading.gif' align='center' /></div>","Search.aspx/GetHouseList",2,strpost,function(rexm){GetHouseListSuccessCallBack(objs, rexm)});
    ajaxh.post();
}

function GetHouseListSuccessCallBack(obj, rexm){
    var data = eval("(" + rexm + ")");
    obj.innerHTML = data;
}

function GetClubs(obj, loginName)
{   
	var objs = $(obj);
    var strpost = "{'loginName':'"+loginName+"'}";
	var filePath = "Search.aspx/GetClubs";
	objs.innerHTML = "<div style='padding:10px;'><img src='/Images/loading.gif' align='center' /></div>";
	new Ajax.Request(filePath , {
		method:'post',
		contentType:'application/json',
		asynchronous:true,
		postBody:strpost,
		onSuccess: function(transport) {
			j = transport.responseJSON;
			GetClubsSuccessCallBack(objs, j);
		},
		onFailure: function() {
			objs.innerHTML = "<img src='/App_Themes/Default/cximg/loading.gif' /> 载入失败";
		}
	});

}

function GetClubsSuccessCallBack(obj, rexm){
    var data = rexm.toString();
    obj.innerHTML = data;
}

function GetServiceClubs(obj, loginName)
{   

    var objs = $(obj);
    var strpost = "{'loginName':'"+loginName+"'}";
	var filePath = "Search.aspx/GetServiceClubs";
	objs.innerHTML = "<div style='padding:10px;'><img src='/Images/loading.gif' align='center' /></div>";
	new Ajax.Request(filePath , {
		method:'post',
		contentType:'application/json',
		asynchronous:true,
		postBody:strpost,
		onSuccess: function(transport) {
			j = transport.responseJSON;
			GetServiceClubsSuccessCallBack(objs, j);
		},
		onFailure: function() {
			objs.innerHTML = "<img src='/App_Themes/Default/cximg/loading.gif' /> 载入失败";
		}
	});
	
}

function GetServiceClubsSuccessCallBack(obj, rexm){
    var data = rexm.toString();
    obj.innerHTML = data;
}

function GetStoreHouse(obj, loginName)
{   

    var objs = $(obj);
    var strpost = "{'loginName':'"+loginName+"'}";
	var filePath = "Search.aspx/GetStoreHouse";
	objs.innerHTML = "<div style='padding:10px;'><img src='/Images/loading.gif' align='center' /></div>";
	new Ajax.Request(filePath , {
		method:'post',
		contentType:'application/json',
		asynchronous:true,
		postBody:strpost,
		onSuccess: function(transport) {
			j = transport.responseJSON;
			GetStoreHouseSuccessCallBack(objs, j);
		},
		onFailure: function() {
			objs.innerHTML = "<img src='/App_Themes/Default/cximg/loading.gif' /> 载入失败";
		}
	});
}

function GetStoreHouseSuccessCallBack(obj, rexm){
    var data = rexm.toString();
    obj.innerHTML = data;
}

