﻿/**********************************************************/

//This method will do AJAX call to a webmethod.

//How to set parameters 

//Parameters:

//PsTargetURL: This parameter specifies the URL of webpage / webservice to be called.

//PsTargetMethodName: This parameter specifies the method name to be executed on webservice / webpage.

//PobjData: This is a JSON object. This object contains data to be passed as parameter to server function. 

//If Server method has no parameters then just send null to this function

//PonSuccess: Method name to execute on successful execution of AJAX request.

//PonFailed: Method name to execute if execution of AJAX request failed.

//type: specified as “POST” to do POST requests. Setting POST allows us to send large amount of data (big JSON objects).

//data: Data specifies the JSON data to be sent to server. We are using JSON objet. This data object needs to serialize before sending it to the server.

//contentType: we are using is application/json with utf-8 character set.

//dataType: is set to JSON as we are sending JSON object.

// In this method, If there is no data to be sent to the server, then specify “{}” in data parameter. It will act as no parameters.

// While sending data as parameters to the server method care must be taken that:

// The parameter names given to server method must match to the parameter names given in JSON object.

//Example:

//Var JSONObj = {

// A: 10, b: 100

//}

//Then on server, method must be defined as:

//[webMethod]

//Public static MethodName(int A, int b)

//{

//}

function DoAjaxCall(PsTargetURL, PsTargetMethodName, PObjData, PonSuccess, PonFailed)
/**********************************************************/
{
    var DATA;

    if ((PObjData != null) && (PObjData != "")) 
    {
        DATA = JSON.stringify(PObjData);
    }
    else 
    {
        DATA = "{}";
    }


    $.ajax({
        type: "POST",                                   //Request type POST 
        url: PsTargetURL + "/" + PsTargetMethodName,    //Request URL: Page/methodname. 
        data: DATA,                                     //Parameters to send. Convert them to JSON before sending. 

                                                        //Note: Parameter names in object must bo same to that of parameters to method on server. 
        contentType:"application/json; charset=utf-8",  //Content type encoding. 
        dataType: "json",                               //Datatype 
        success: PonSuccess,                            //Method to be called on success. 
        error: PonFailed                                //Method to be called if failed. 
    });
}


/**********************************************************/

/**********************************************************/
//change the opacity for different browsers 
function changeOpac(opacity, id)
/**********************************************************/
{
    // 
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";    
}
/**********************************************************/ 
