﻿/// <reference path="jquery-vsdoc.js" />



/// Functions that calls a method on a page.
/// could also be used to call a JSON web service
function PageMethod(fn, paramArray, successFn, errorFn)  
{ 
    var divResult = $("#divPollAnswersContainer");
  divReslut.html("loading ...");
  var pagePath = window.location.pathname;            
  ServiceMethod(pagePath,fn,paramArray,successFn,errorFn);
}  
 
 
/// Functions that calls a method on a page.
/// could also be used to call a JSON web service
function ServiceMethod(serviceUrl,fn, paramArray, successFn, errorFn)  
 { 
 
 var pagePath = serviceUrl;            
   //var pagePath = "NoteService.asmx";//window.location.pathname;  
   //Create list of parameters in the form:  
 //{"paramName1":"paramValue1","paramName2":"paramValue2"}  
   var paramList = '';  
   if (paramArray.length > 0)  
   {  
     for (var i=0; i<paramArray.length; i+=2)  
     {  
       if (paramList.length > 0) paramList += ',';  
       paramList += '"' + paramArray[i] + '":"' + paramArray[i+1] + '"';  
     }  
   }  
   paramList = '{' + paramList + '}';  
   //Call the page method  
   $.ajax({  
       type: "POST",  
       url: pagePath + "/" + fn,  
       contentType: "application/json; charset=utf-8",  
       data: paramList,  
       dataType: "json",  
       success: successFn,  
       error: errorFn  
   })  
 ;}  
        
function AjaxFailed (result)  
{   
$("#divLoading").dialog('close');
    alert("Failed while performing request." +result);  
}  

