﻿var PageController = function(){
    this.PostDefaultUrl = '/Service.ashx';
    this.GetDefaultUrl = '/GetService.ashx';
}

PageController.prototype = {
    GetRoads:function(returnFun){ 
        var pars = 'Type=GetRoads' ;
        this.PostExec(pars,returnFun);
    },
    GetGoadsSimple:function(returnFun){
        var pars = 'Type=GetGoadsSimple' ;
        var myAjax = new Ajax.Request(
        this.GetDefaultUrl,
        {
            method: "get",
            parameters: pars,
            asynchronous:true,
            onComplete: returnFun
        });
    },
     
    GetEventTypes:function(returnFun){
        var pars = 'Type=GetEventTypes' ;
        var myAjax = new Ajax.Request(
        this.GetDefaultUrl,
        {
            method: "get",
            parameters: pars,
            asynchronous:true,
            onComplete: returnFun
        });
    },
   
    GetEventClasses:function(typeID,returnFun){
        var pars = 'Type=GetEventClasses&EventTypeID='  + typeID;
        this.GetExec(pars,returnFun);
    },
    GetInsertDefaultMsg:function(returnFun){
        var pars = 'Type=GetInsertDefaultMsg' ;5
        var myAjax = new Ajax.Request(
        this.GetDefaultUrl,
        {
            method: "post",
            parameters: pars,
            asynchronous:true,
            onComplete: returnFun
        });
    },
    GetEventStatus:function(returnFun){
        var pars = 'Type=GetEventStatus' ;
        var myAjax = new Ajax.Request(
        this.GetDefaultUrl,
        {
            method: "get",
            parameters: pars,
            asynchronous:true,
            onComplete: returnFun
        });
    },
     
    GetEventsByUser: function(returnFun){
        var pars = 'Type=GetEventsByUser' ;
        this.PostExec(pars,returnFun);
    },
    GetEventModelByID: function(eventId, returnFun){// alert(eventId);
        var pars = 'Type=GetEventModelByID&EventID=' +eventId;
        this.PostExec(pars,returnFun);
    },
    GetRoadsByUser: function(returnFun){//获取道路信息
        var pars = 'Type=GetRoadsByUser' ;
        this.PostExec(pars,returnFun);
    },
    GetStakesByRoad: function(roadId, returnFun){//获取桩号信息
        var pars = 'Type=GetStakesByUser&RoadID='+roadId ;
        this.PostExec(pars,returnFun);
    },
    InsertEvent:function(strArr,returnFun){
        var pars = 'Type=InsertEvent' ;
        for(var i = 0 ; i < strArr.length; i++){
            pars += "&" + strArr[i];
        }
        this.PostExec(pars,returnFun);
    },
    GetInsertDefaultMsg:function(returnFun){
        var pars = 'Type=GetInsertDefaultMsg' ;
        this.PostExec(pars,returnFun);
    },
    CheckEvent:function(strArr,returnFun){
        var pars = 'Type=CheckEvent' ;
        for(var i = 0 ; i < strArr.length; i++){
            pars += "&" + strArr[i];
        }
        this.PostExec(pars,returnFun);
    },
    UpdateEvent: function(strArr,returnFun){
        var pars = 'Type=UpdateEvent' ;
        for(var i = 0 ; i < strArr.length; i++){
            pars += "&" + strArr[i];
        }
        this.PostExec(pars,returnFun);
    },
    DeleteEvent: function(eventID,returnFun){
        var pars ='Type=DeleteEvent&EventID='+eventID ;
        this.PostExec(pars,returnFun);
    },
    Login:function(loginName,passWord,returnFun){
        var pars = 'Type=Login&LoginName='+loginName+"&PassWord="+passWord;
        this.PostExec(pars,returnFun);
    },
    Logout:function(returnFun){
        var pars = 'Type=Logout';
        this.PostExec(pars,returnFun);
    },
    SetShowSetting:function(roadsStr,returnFun){
        var pars = 'Type=SetShowSetting&RoadList=' + roadsStr;
        this.PostExec(pars,returnFun);
    },
    GetShowSetting:function(returnFun){
        var pars = 'Type=GetShowSetting';
        this.PostExec(pars,returnFun);
    },
    GetEventCount:function(returnFun){
        var pars = 'Type=GetEventCount';
        this.PostExec(pars,returnFun);
    },
    GetEventsByPage:function(pageNo,returnFun){
        var pars = 'Type=GetEventsByPage&PageNo='+pageNo;
        this.PostExec(pars,returnFun);
    },
    CheckIsLogin:function(returnFun){
        var pars = 'Type=CheckIsLogin';
        this.PostExec(pars,returnFun);
    },

    PostExec: function(pars,returnFun){
        this.Exec('post',pars,returnFun);
    },
    GetExec: function(pars,returnFun){
        this.Exec('get',pars,returnFun);
    },
    Exec:function(type,pars,returnFun){ 
        
        var url = (type =='post')?  this.PostDefaultUrl : this.GetDefaultUrl ;
        
        if(pars=="Type=GetRoads")
            alert("Exec GetRoads : " + url);
            
        var myAjax = new Ajax.Request(
        url,
        {
            method: type,
            parameters: pars,
            onComplete: returnFun
        });
    }
};
