var xmlhttp;

function ofekTest()
{
        alert('ofekTest');
}

function notifyAnalyticsPageLoadEvent()
{
        _gaq.push(['_trackEvent', 'stage', 'page loaded', '']);
}

function ajaxGet(strPageAddress, strHandlerFunctionName)
{
        if (window.XMLHttpRequest)
        {
                // code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp=new XMLHttpRequest();
        }
        else
        {
                // code for IE6, IE5
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }

        //Handler function
       xmlhttp.onreadystatechange=strHandlerFunctionName;

       
       //Add random number so there will be a unique request
       if(strPageAddress.indexOf('?') == -1)
        {
                strPageAddress = strPageAddress + '?r='+ Math.floor(Math.random() * 100000)
        }
        else
        {
                strPageAddress = strPageAddress + '&r=' + Math.floor(Math.random() * 100000)
        }

        xmlhttp.open("GET", strPageAddress, true);
        xmlhttp.send();
}


function ajaxPost(strPageAddress, strHandlerFunctionName, strParams)
{
        if (window.XMLHttpRequest)
        {
                // code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp=new XMLHttpRequest();
        }
        else
        {
                // code for IE6, IE5
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }

        //Handler function
        xmlhttp.onreadystatechange=strHandlerFunctionName;

       //Add random number so there will be a unique request
       if(strPageAddress.indexOf('?') == -1)
        {
                strPageAddress = strPageAddress + '?r='+ Math.floor(Math.random() * 100000)
        }
        else
        {
                strPageAddress = strPageAddress + '&r=' + Math.floor(Math.random() * 100000)
        }

        strParams = encodeURI(strParams);
        //alert(strParams);
        xmlhttp.open("POST", strPageAddress, true);
        xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        xmlhttp.send(strParams);
}








/*
//----------------------------------AJAX CODE BASIC----------------------------
var xmlHttp;

//Create XmlHttp object that will get a response from a server
//Gets the URL to handle and the response handler function
function getServerResponse(strAspxPageUrl, responseHandlerFunction)
{
        //alert('getServerResponse');
        //alert(xmlHttp);
        //alert(responseHandlerFunction);
    
        //ADD A RANDOM NUMBER TO AVOID CACHING PROBLEM (when the page gets last answer instead of going to the server)
        if(strAspxPageUrl.indexOf('?') == -1)
        {
                strAspxPageUrl = strAspxPageUrl + '?r='+ Math.floor(Math.random() * 100000)
        }
        else
        {
                strAspxPageUrl = strAspxPageUrl + '&r=' + Math.floor(Math.random() * 100000)
        }

        //alert(strAspxPageUrl);
   
        //Create XmlHttp object
        GetXmlHttpObject(responseHandlerFunction);
        xmlHttp.open("GET", strAspxPageUrl , true);
        //xmlHttp.open("POST", strAspxPageUrl , true); //ANOTHER SOLUTION FOR THE CACHING PROBLEM

        xmlHttp.send();
}

//Create XmlHttp object
function GetXmlHttpObject(responseHandlerFunction)
{
        try
        {
                // Gecko-based browsers, Safari, and Opera, IE7.
                xmlHttp = new XMLHttpRequest();
                xmlHttp.onreadystatechange=responseHandlerFunction;
                alert(responseHandlerFunction);
                          
                //OLD CODE
                //xmlHttp.onload=responseHandlerFunction;
                //xmlHttp.onerror=responseHandlerFunction;
        }
        catch(e)
        {
                try
                {
                        // For Internet Explorer 6 and lower.
                        var strName="Msxml2.XMLHTTP";
                        if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
                        {
                                strName="Microsoft.XMLHTTP";
                        }
                        xmlHttp = new ActiveXObject(strName);
                        xmlHttp.onreadystatechange=responseHandlerFunction;
                }
                catch (e)
                {
                        // Browser supports Javascript but not XMLHttpRequest.
                        alert('ERROR');
                        xmlHttp = false;
                }
        }
}
//----------------------------------END AJAX CODE BASIC----------------------------
//------------------------------------- CODE BASIC---------------------------------




//----------------------------------AJAX CODE WITH POST----------------------------
//Call: 
//AjaxPost('ajax.aspx', 'action=updateOrder&age=35', imgBtnOrder_handler);
function AjaxPost(url, parameters, handler_function) 
{
        
        // create the AJAX object
        var xmlHttp = undefined;
        if (window.ActiveXObject)
        {
                try
                {
                        xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
                }
                catch (othermicrosoft)
                {
                        try
                        {
                                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                        }
                        catch (failed) {}
                }
        }

        if (xmlHttp == undefined && window.XMLHttpRequest)
        {
                // If IE7, Mozilla, Safari, etc: Use native object
                xmlHttp = new XMLHttpRequest();
        }

        if (xmlHttp != undefined)
        {
                // open the connections
                xmlHttp.open("POST", url, true);
        
                // callback handler
                xmlHttp.onreadystatechange = function()
                {
                        // test if the response was totally sent
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
                        {
                                if (xmlHttp.status==200)
                                {
                                        //RESPONSE
                                        //alert(xmlHttp.responseText);
                                        handler_function(xmlHttp.responseText);
                                }
                        }
                }

                // create the parameter string
                // iterate the parameters array
                var parameterString;
                parameterString = encodeURI(parameters);
        
                
        //for (var i = 0; i < n; i++)
        //{
        //parameterString += (i > 0 ? "&" : "")
            //+ parameters[i][0] + "="
            //+ encodeURI(parameters[i][1]);
        //}
        

                // set the necessary request headers
                xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                xmlHttp.setRequestHeader("Content-length", parameterString.length);
                xmlHttp.setRequestHeader("Connection", "close");

                // send request
                xmlHttp.send(parameterString);
        }
}
//----------------------------------END AJAX CODE WITH POST----------------------------
*/




