﻿        var xmlhttp = null;
        var div;        
        var lastx;
        var lasty;
        
        function BannerClick(param,link)
        {
            if (xmlhttp == null)
            {
                xmlhttp = GetXmlHttp();
            }
            xmlhttp.open("POST", "BannerClickAJAX.aspx", true);
            xmlhttp.setRequestHeader("If-Modified-Since", new Date(0));
            xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            //xmlhttp.onreadystatechange = GetResults;
            xmlhttp.send("BannerID="+param);
            if(link!="")
            {
                window.open("http://"+link);        
            }
        }
        function HideDiv()
        {
        
            //div = document.getElementById(div);
            div = document.getElementById("PopUp");
            if(div!=null)
                div.style.visibility = "hidden";
            
        }
        function GetDiv()
        {
            div = document.getElementById("PopUp");
            if(div==null)
            {
                div = document.createElement("div");
                div.id = "PopUp";
                div.style.position = "absolute";
                div.style.width = "250px";
                div.style.backgroundColor = "White";
                div.style.top = "200px";
                div.style.left = "200px";
                div.style.zIndex = "1";
                div.style.visibility = "hidden";
                div.style.borderColor = "Orange";
                div.style.borderWidth = "2";
                div.style.borderStyle = "solid";
                div.style.textAlign = "right";
                document.body.appendChild(div);
         //       <div id="PopUp" style="position:absolute; width:250px; background-color:White; top:200px; left:200px; z-index:1; visibility:hidden;  border-color:Orange; border-style:solid; border-width:2px; text-align:right;">
            }
            return div;
        }
        function PopUp(method,url,Params)
        {
       lastx = event.x;
       lasty = event.y;
        
        
        
       if (xmlhttp == null)
            {
                xmlhttp = GetXmlHttp();
            }
                      
            switch (method)
            {
                case "GET":
                    xmlhttp.open("GET", url, true);
                    xmlhttp.setRequestHeader("If-Modified-Since", new Date(0));
                    xmlhttp.onreadystatechange = GetResults;
                    xmlhttp.send(null);
                    break;
                case "POST":
                    xmlhttp.open("POST", url, true);
                    xmlhttp.setRequestHeader("If-Modified-Since", new Date(0));
                    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                    xmlhttp.onreadystatechange = GetResults;
                    xmlhttp.send("sTitle="+Params);
                    break;
            }
        }
        
        function GetResults()
        {
        
            if (xmlhttp.readyState == 4)
                if (xmlhttp.status == 200)
                {
                    
                    div = GetDiv();
                    div.style.top = lasty;
                    div.style.left = lastx;
                    div.style.visibility = "visible";
                    div.innerHTML = xmlhttp.responseText;
                }
                else
                {
                    //div.innerHTML = "There was a problem with the response.";
                }
        }
    
 
    function GetXmlHttp()
    {
        var xmlhttp = false;

          var arr = ['MSXML2.XMLHTTP.3.0', 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP' ];
    
        for (var i = 0; i < arr.length; i++) 
        {
            try 
            {
                xmlHttp = new ActiveXObject(arr[i]);
                return xmlHttp;
            }
            catch (ex) 
            {
                xmlhttp = false;
            }
        }
        
        // For FireFox browser:
        if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
        {
            try 
            {
                xmlhttp = new XMLHttpRequest();
            }
            catch (ex) 
            {
                xmlhttp = false;
            }
        }
        
        // For some other browser try the following:
        if (!xmlhttp && window.createRequest) 
        {
            try 
            {
                xmlhttp = window.createRequest();
            } 
            catch (ex) 
            {
                xmlhttp = false;
            }
        }
        
        return xmlhttp;
    }

