﻿// JScript File
/// <reference path="../JQuery-1.3.2-vsdoc2.js" />

function retrieveUrlAJAX(url, stringIdElm,Params) {

    $(document).ready(function() {
        $.ajax({
            url: url,
            type: "GET",
            data: Params,
            cache: false,                //Do not cache the page  
            success: function(response) {
                
                var headHtml = getScripts(response);
                response = removeFormHtml(response);
                response = removeViewstateHtml(response);

                response = headHtml + response;


                if (stringIdElm != "") {

                    //$("#"+stringIdElm).fadeOut(100)
                    $("#" + stringIdElm).html(response);
                    //$("#"+stringIdElm).fadeIn(1500);
                }
            }

        });
    });
}


function getScripts(sResponseText)
{
    var sResponseHtml =  sResponseText;    
                   
    var nIndexFormOpen = sResponseHtml.indexOf('<head');
    
    sResponseHtml = sResponseHtml.substring(nIndexFormOpen, sResponseHtml.length);
    
    nIndexFormOpen = sResponseHtml.indexOf('>');

    var nIndexFormClose = sResponseHtml.lastIndexOf("</head>");
    
    sResponseHtml = sResponseHtml.substring(nIndexFormOpen+1,nIndexFormClose);
    
    return sResponseHtml;
}

function removeFormHtml(sResponseText)
{
    var sResponseHtml =  sResponseText;    
                   
    var nIndexFormOpen = sResponseHtml.indexOf('<form');
    
    sResponseHtml = sResponseHtml.substring(nIndexFormOpen, sResponseHtml.length);
    
    nIndexFormOpen = sResponseHtml.indexOf('>');

    var nIndexFormClose = sResponseHtml.lastIndexOf("</form>");
    
    sResponseHtml = sResponseHtml.substring(nIndexFormOpen+1,nIndexFormClose);
    
    return sResponseHtml;
}

function removeViewstateHtml(sResponseText)
{
   var sResponseHtml = sResponseText;
   
   var nIndexViewstateOpen = sResponseHtml.toUpperCase().indexOf("<DIV>");
   
   var nIndexViewstateClose = sResponseHtml.toUpperCase().indexOf("</DIV>");    
   
   sResponseHtml = sResponseHtml.substring(nIndexViewstateClose+6, sResponseHtml.length);
   
   return sResponseHtml;
}
 

function trim(s)
{
	return s.replace(/^\s+|\s+$/g,"");
}
