﻿//useful stuff:
String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.toProperCase = function()
{
  return this.toLowerCase().replace(/^(.)|\s(.)/g, 
      function($1) { return $1.toUpperCase(); });
}


//general functions
function findPos(obj) 
{
    var curleft = curtop = 0;
    if (obj.offsetParent) 
    {
        do 
        {
		    curleft += obj.offsetLeft;
		    curtop += obj.offsetTop;
        } 
        while (obj = obj.offsetParent);
    }
    return [curleft,curtop];
}

function getHash() {
  var hash = window.location.hash;
  return hash.substring(1); // remove #
}

function openMenu(target, menu, offset, doubleSize, width)
{
    var targetCoords = findPos(target);
    var heightOffset;
    if(offset==undefined)
        heightOffset=target.style.height.replace('px','');
    else
        heightOffset=offset;
    menu.style.left=targetCoords[0]+'px';
    menu.style.top=(targetCoords[1]+(heightOffset*1))+'px';
    if(width==undefined)
        menu.style.width='170px'; //constrain width
    else
        menu.style.width=width+'px'; //constrain width
        
    if(target.id=="mainLeftLink")
    {
        menu.style.border="solid 1px #A6C3DE";
        menu.style.borderLeft="none";
        menu.style.left=targetCoords[0]+146+'px';
    }
    else
    {
        menu.style.border="solid 1px #195AAB";
        menu.style.borderTop="none";
    }
    if(target.id=="travelButton")
        menu.style.left=parseInt(menu.style.left)-125+"px";
        
    menu.onmouseover=function() { this.style.display='block'; }
    menu.onmouseout=function() { this.style.display='none'; }
    menu.style.display='block';
}

function bookmarksite(title,url){
    if (window.sidebar) // firefox
        window.sidebar.addPanel(title, url, "");
    else if(window.opera && window.print){ // opera
        var elem = document.createElement('a');
        elem.setAttribute('href',url);
        elem.setAttribute('title',title);
        elem.setAttribute('rel','sidebar');
        elem.click();
    } 
    else if(document.all)// ie
        window.external.AddFavorite(url, title);
}


//cookie functions
function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name,"",-1);
}
//end cookie functions

function centerIcons()
{
//    alert('about to center');
    centerEls = document.getElementsByTagName('img');
    for ( i=0;i<centerEls.length;i++ )
        {
            
            if(centerEls[i].className=="icon")
            {
                
                var width=centerEls[i].offsetWidth;
                if(width<16)
                    centerEls[i].style.padding="0px "+(Math.round((16-width)/2))+"px 0px "+(Math.round((16-width)/2))+"px";
                    
                //els[i].style.border='solid 1px green';
            }
        }
}

//this runs on startup
function doPageRender()
{
    
    try
    {
    if(document.getElementById('mmDiv').innerHTML.trim()=="")
        {
            try {document.getElementById('mm').style.display='none'; } catch(e) { }
        }
    }
    catch(e)
    { }
        
    try
    {
    var els = document.getElementsByTagName('input');
    for ( i=0;i<els.length;i++ )
        if ( els[i].getAttribute('type') )
        {
            if ( els[i].getAttribute('type') == 'text')
            {
                if(els[i].className.indexOf('text') == -1)
                    els[i].className += ' text';
            }
            else if( els[i].getAttribute('type') == 'password')
            {
                if(els[i].className.indexOf('password') == -1)
                    els[i].className = 'password';
            }
            else
            {   
                if(els[i].className.indexOf('button') == -1)
                    els[i].className += ' button';
            }
        }
    }
    catch(e)
    { }
        
    //set a titles and set links for no onbeforeunload
    //try
    //{
    els = document.getElementsByTagName('a');
    for ( i=0;i<els.length;i++ )
        {
            if(els[i].title.trim()=="")
                els[i].title=els[i].innerHTML.replace(/(<([^>]+)>)/ig,"").trim();
                
//            if(els[i].className.indexOf("noBUL") > -1)
//            {
//                alert(els[i]);
//                els[i].onclick = function() { window.onbeforeunload=null; };
//                
//            }
        }
    //}
    //catch(e)
    //{ }    
    
    
    var ftafButton = document.getElementById('ftafButton');
    if(ftafButton != undefined)
    {
        if(readCookie("destination") == "2") //pf
        {
            ftafButton.src=appRoot + "gcr/images/buttons/pf/forward.gif";
        }
        else if(readCookie("destination") == "5") //biloxi
        {
            ftafButton.src=appRoot + "gcr/images/buttons/biloxi/forward-biloxi.png";
        }
    }
       
    try { bodyOnLoad(); } catch(e){ }
}



function showLeadForm(promoID)
{
    disclaimerWindow = window.open(appRoot+"gcr/packages/form.aspx?promoID="+promoID+"", "lead", "width=500,height=500,scrollbars=yes,resizable=yes,status=no,location=no,toolbar=no"); 
}

//forward to a friend stuff
function ftafDisplay()
{
    document.getElementById('ftafDiv').innerHTML="<span id=\"ftafResult\" style=\"display: none; font-weight: bold;\"></span><input id=\"ftafBox\" type=\"text\" value=\"myfriend@example.com\" onfocus=\"if(this.value==\'myfriend@example.com\') { this.value=\'\'; this.style.color=\'black\'; }\" onblur=\"if(this.value==\'\') {this.value=\'myfriend@example.com\'; this.style.color=\'#767676\'; }\" style=\"color: #767676; font-size:8pt;\" /><input id=\"ftafButton\" type=\"button\" value=\"Forward\"onclick=\"ftaf(document.getElementById(\'ftafBox\').value, document.title, window.location, \'some message\');\"/>";
}

function ftaf(emailAddress, title, url)
{
    var description;
    var metas = document.getElementsByTagName('meta');
    for (var x=0,y=metas.length; x<y; x++) {
      if (metas[x].name.toLowerCase() == "description") {
        description = metas[x];
      }
    }
    
    var xmlhttp;
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
      }
    else if (window.ActiveXObject)
      {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    else
      alert("Your browser does not support forwarding to a friend.");
      
    //do it
    xmlhttp.onreadystatechange=function()
    {
        if(xmlhttp.readyState==4)
        {
          document.getElementById('ftafResult').innerHTML=xmlhttp.responseText;
          document.getElementById('ftafResult').style.display='block';
          document.getElementById('ftafBox').value='myfriend@example.com';
          document.getElementById('ftafBox').style.color='#767676';
          setTimeout("document.getElementById('ftafResult').style.display='none';", 5000);
        }
    }
    if(description==undefined)
        xmlhttp.open("GET",appRoot+"gcr/ajax/ftaf.aspx?emailaddress="+emailAddress+"&title="+title+"&url="+url+"&message=",true);
    else
        xmlhttp.open("GET",appRoot+"gcr/ajax/ftaf.aspx?emailaddress="+emailAddress+"&title="+title+"&url="+url+"&message="+description.content,true);
    xmlhttp.send(null);
}

function switchIcons(iconSuffix)
{
    try
    {
    els = document.getElementsByTagName('img');
    if(iconSuffix!="")
        for ( i=0;i<els.length;i++ )
            {
                
                if(els[i].className=="icon")
                {
                    var imgName = els[i].src.toUpperCase();
                    if(imgName.substring(imgName.length-3, imgName.length) == "PNG")
                    {
                        els[i].src=els[i].src.substring(0, els[i].src.length-4) + iconSuffix + ".png";
                    }
                }
            }
        
    }
    catch(e)
    { }
}


//popunder code
function drawPopunder(popunderDiv, width, height, show) //deprecated
{
    var grayDiv;
    var _docHeight = (document.height || document.body.offsetHeight);
    var _docWidth = (document.width || document.body.offsetWidth);
    
    if(!document.getElementById('grayDiv'))
    {
        grayDiv = document.createElement('div');
        grayDiv.id = "grayDiv";
        grayDiv.style.backgroundColor="black";
        grayDiv.style.zIndex = "20";
        grayDiv.style.position="absolute";
        grayDiv.style.left="0px";
        grayDiv.style.top="0px";
        grayDiv.style.width = "100%";
        grayDiv.style.height= _docHeight + "px";
        grayDiv.style.opacity="0.8";                      
        grayDiv.style.MozOpacity="0.8";                   
        grayDiv.style.filter='alpha(opacity=80)'; 
        document.getElementById('mainDiv').appendChild(grayDiv);
    }
    else
        grayDiv = document.getElementById('grayDiv');
    
    
    var innerHeight;
    if (self.innerHeight) // all except Explorer
	    innerHeight = self.innerHeight;
	else if (document.documentElement && document.documentElement.clientHeight)
	    innerHeight = document.documentElement.clientHeight;
	else if (document.body) // other Explorers
	    innerHeight = document.body.clientHeight;
	
	popunderDiv.style.zIndex="21";
    popunderDiv.style.position="absolute";
    popunderDiv.style.width=width + "px";
    popunderDiv.style.height = height + "px";
    popunderDiv.style.left = (_docWidth - width)/2 + "px";
    popunderDiv.style.top = (innerHeight - height) / 2 + "px";
    
    if(show)
    {
        grayDiv.style.display='block';
        popunderDiv.style.display='block';
    }
    else
    {
        grayDiv.style.display='none';
        popunderDiv.style.display='none';
    }
}

function isIE()
{ return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent); }

//function getSize() {
//  var myWidth = 0, myHeight = 0;
//  if( typeof( window.innerWidth ) == 'number' ) {
//    //Non-IE
//    myWidth = window.innerWidth;
//    myHeight = window.innerHeight;
//  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
//    //IE 6+ in 'standards compliant mode'
//    myWidth = document.documentElement.clientWidth;
//    myHeight = document.documentElement.clientHeight;
//  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
//    //IE 4 compatible
//    myWidth = document.body.clientWidth;
//    myHeight = document.body.clientHeight;
//  }
//  
//  return [myWidth,myHeight];
//}

function getWindowSize() {
    var _docHeight = (document.height !== undefined) ? document.height : document.body.offsetHeight;
    var _docWidth = (document.width !== undefined) ? document.width : document.body.offsetWidth;
    
    return [_docWidth,_docHeight];
}

function getInnerSize() {
    var _innerHeight;
    var _innerWidth;
    
    if (self.innerHeight) // all except Explorer
    {
	    _innerHeight = self.innerHeight;
	    _innerWidth = self.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{
	    _innerHeight = document.documentElement.clientHeight;
	    _innerWidth = document.documentElement.clientWidth;
	}
	else if (document.body) // other Explorers
	{
	    _innerHeight = document.body.clientHeight;
	    _innerHeight - document.body.clientWidth;
	}
	    
	return [_innerWidth,_innerHeight];
}

function GCRDrawPopunder(popunderDiv, width, height, show)
{
    var grayDiv;
    //var _docHeight = (document.height || document.body.offsetHeight);
    //var _docWidth = (document.width || document.body.offsetWidth);
    
    var _docHeight = (document.height !== undefined) ? document.height : document.body.offsetHeight;
    var _docWidth = (document.width !== undefined) ? document.width : document.body.offsetWidth;

    
    if(!document.getElementById('grayDiv'))
    {
        grayDiv = document.createElement('div');
        grayDiv.id = "grayDiv";
        grayDiv.style.backgroundColor="black";
        grayDiv.style.zIndex = "20";
        grayDiv.style.position="absolute";
        grayDiv.style.left="0px";
        grayDiv.style.top="0px";
        if(isIE())
        {
            grayDiv.style.width = _docWidth + 'px';
        }
        else
        {
            grayDiv.style.width="100%";
        }
        
        grayDiv.style.height= _docHeight + 'px';
        
        grayDiv.style.opacity="0.5";                      
        grayDiv.style.MozOpacity="0.5";                   
        grayDiv.style.filter='alpha(opacity=50)'; 
        document.getElementById('mainDiv').appendChild(grayDiv);
    }
    else
        grayDiv = document.getElementById('grayDiv');
    
    
    var innerHeight;
    if (self.innerHeight) // all except Explorer
	    innerHeight = self.innerHeight;
	else if (document.documentElement && document.documentElement.clientHeight)
	    innerHeight = document.documentElement.clientHeight;
	else if (document.body) // other Explorers
	    innerHeight = document.body.clientHeight;
	
	popunderDiv.style.zIndex="21";
    popunderDiv.style.position="absolute";
    popunderDiv.style.width=width;
    popunderDiv.style.height = height + "px";
    
    if(width.indexOf("px") >= 0)
        popunderDiv.style.left = (_docWidth - parseInt(width))/2 + "px";
    else
        popunderDiv.style.left = "0px";
        
    popunderDiv.style.top = (innerHeight - height) / 2 + "px";
    
    if(show)
    {
        grayDiv.style.display='block';
        popunderDiv.style.display='block';
    }
    else
    {
        grayDiv.style.display='none';
        popunderDiv.style.display='none';
    }
}

var surveyOpacity = 0;

function displaySurvey(surveyID, IgnoreIESix)
{
    if(IgnoreIESix || navigator.userAgent.indexOf("MSIE 6.0") == -1)
    {
        var survey = document.getElementById(surveyID);
        var _docWidth=getWindowSize()[0];
        var _docHeight=getWindowSize()[1];
        
        var _innerWidth = getInnerSize()[0];
        var _innerHeight = getInnerSize()[1];
        
        
        
        setOpacity(survey,0);
        
        survey.style.display="block";
        
        survey.style.top = (_innerHeight-parseInt(survey.style.height)) / 2 + "px";
        survey.style.left=(_docWidth-parseInt(survey.style.width)) / 2 + "px";
        
        
        //alert(surveyID + "--" + survey);
        
        surveyHandle = setInterval("surveyOpacity += 10; if(surveyOpacity <= 100) { setOpacity(document.getElementById('"+ survey.id +"'),surveyOpacity/100); } else { clearInterval(surveyHandle); surveyOpacity=0; }",40);
    }
}
//end popunder code

function setOpacity(element, decimalOpacity)
{ 
    element.style.opacity=decimalOpacity;
    element.style.filter = 'alpha(opacity = '  + (decimalOpacity*100) + ')';
}

function isChildOf(ChildObject,ContainerObject) 
{ 
    var retval=false; 
    var curobj; 
    if(typeof(ContainerObject)=="string")
    {
        ContainerObject=document.getElementById(ContainerObject);
    }
    if(typeof(ChildObject)=="string")
    {
        ChildObject=document.getElementById(ChildObject);
    }
    curobj=ChildObject.parentNode; 
    while(curobj!=undefined) 
    { 
        if(curobj==document.body) 
        { break;} 
        if(curobj.id==ContainerObject.id)
        {
            retval =true;
            break;
        }
        curobj=curobj.parentNode;//move up the hierarchy 
    } 
    return retval; 
} 

function popunderImpression(id)
{
    var xmlhttp;
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
      }
    else if (window.ActiveXObject)
      {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      
    //do it
    xmlhttp.onreadystatechange=function()
    {
        if(xmlhttp.readyState==4)
        {
            //alert(xmlhttp.responseText);
        }
    }
    
    xmlhttp.open("GET",appRoot+"gcr/ads/ajax/popunderImpression.aspx?id="+id,true);
    xmlhttp.send(null);
}

function sessionCallback(sessionID, url, title)
{
    var xmlhttp;
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
      }
    else if (window.ActiveXObject)
      {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      
    //do it
    xmlhttp.onreadystatechange=function()
    {
        if(xmlhttp.readyState==4)
        {
            if(xmlhttp.status==200)
            {
                debug("Received response: " + xmlhttp.responseText);
                
                if(xmlhttp.responseText.length > 11)
                    if(xmlhttp.responseText.substr(0,11) == "invitation:")
                    {
                        var invitationText = xmlhttp.responseText.replace("invitation:","");
                        debug("Found invitation: " + invitationText);
                        
                        //dynamicPopunder(invitationText, "javascript:void(0);", "Chat", function() { setInvitationStatus(currentSessionID,"1"); this.parentNode.parentNode.style.display='none'; launchChat(currentSessionID); return false; }, "No Thanks", function() { setInvitationStatus(currentSessionID,"0"); this.parentNode.parentNode.style.display='none'; return false; }, document.getElementById('bottomAnchorDiv'), "100px", "400px")
                        chatInvitation(invitationText,document.getElementById('bottomAnchorDiv'));
                    }
            }
            else
            {
                debug("Session callback received a response code other than 200.  :(");
            }
        }
    }
    
    var url = appRoot+"gcr/ajax/maintainSession.aspx?sessionID="+sessionID+"&url=" + url + "&title=" + title + "&rand="+ Math.floor(Math.random()*1000000);
    debug("Calling url: " + url);
    
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
}

function sessionEndCallback(sessionID)
{
    debug('ending session:' + sessionID);
    
    var xmlhttp;
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
      }
    else if (window.ActiveXObject)
      {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      
    //do it
    xmlhttp.onreadystatechange=function()
    {
        if(xmlhttp.readyState==4)
        {
            //debug("Received response: " + xmlhttp.responseText);
        }
    }
    
    var url = appRoot + "gcr/ajax/chat/endSession.aspx?sessionID=" + sessionID + "&rand="+ Math.floor(Math.random()*1000000);
    debug("Calling url: " + url);
    
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
}

function debug(text)
{
    try 
    {
        var debugList = document.getElementById('debugList');
        
        var li = document.createElement('li');
        li.innerHTML = text;
        debugList.appendChild(li);
    }
    catch(e) { }
}

function getChatLink()
{
    try {
        var link = document.getElementById('chatLaunchLink');
        var span = document.getElementById('chatInnerSpan');
        
        var xmlhttp;
        if (window.XMLHttpRequest)
          {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
          }
        else if (window.ActiveXObject)
          {// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
          
        //do it
        xmlhttp.onreadystatechange=function()
        {
            if(xmlhttp.readyState==4)
            {
                try {
                    if(xmlhttp.responseText == "0") //no agents
                    {
                        link.style.display='none';
                    }
                    else
                    {
                        span.innerHTML = "Live Chat Now";
                        link.title = "Live Chat Now";
                        link.href="javascript:void(0);";
                        link.onclick=function() 
                        {
                            launchChat(currentSessionID);
                            return false;
                        };
                        
                        link.style.display='block';
                    }
                } catch(e) { }
            }
        }
        
        var url = appRoot + "gcr/ajax/chat/chatAvailable.aspx?rand="+ Math.floor(Math.random()*1000000);
        debug("Calling url: " + url);
        
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    } catch(e) { }
}

function dynamicPopunder(text, actionURL, actionText, actionOnclick, declineText, declineOnclick, parent, height, width)
{
    if(document.getElementById('dynamicPopunder') != undefined)
        return;
        //document.getElementById('dynamicPopunder').parentNode.removeChild(document.getElementById('dynamicPopunder'));

    if(surveyHandle != undefined) {
        try { clearTimeout(surveyHandle); } catch(e) { }
    }

    var popunder = document.createElement('div');
    popunder.className = "dynamicPopunder";
    popunder.id = "dynamicPopunder";
    
    popunder.style.height=height;
    popunder.style.width=width;
    
    var messageDiv = document.createElement('div');
    messageDiv.innerHTML = text.replace("*title*",document.title);
    messageDiv.style.padding="5px";
    messageDiv.style.textAlign="center";
    messageDiv.style.paddingBottom="20px";
    popunder.appendChild(messageDiv);
    
    var actionDiv = document.createElement('div');
    actionDiv.style.textAlign="center";
    actionDiv.style.borderTop="solid 1px gray";
    actionDiv.style.paddingTop="10px";
    
    var actionLink = document.createElement('a');
    actionLink.innerHTML = actionText;
    actionLink.href=actionURL;
    actionLink.style.marginRight="20px";
    actionLink.onclick=actionOnclick;
    actionDiv.appendChild(actionLink);
    
    var declineLink = document.createElement('a');
    declineLink.innerHTML = declineText;
    declineLink.href = "javascript:void(0);";
    declineLink.onclick = declineOnclick;
    actionDiv.appendChild(declineLink);
    
    popunder.appendChild(actionDiv);
    
    parent.appendChild(popunder);
    
    displaySurvey(popunder.id);
}

function chatInvitation(text, parent)
{
    if(document.getElementById('dynamicPopunder') != undefined)
        return;
        //document.getElementById('dynamicPopunder').parentNode.removeChild(document.getElementById('dynamicPopunder'));

    if(surveyHandle != undefined) {
        try { clearTimeout(surveyHandle); } catch(e) { }
    }

    var popunder = document.createElement('div');
    popunder.className = "dynamicPopunder";
    popunder.id = "dynamicPopunder";
    
    popunder.style.height="150px";
    popunder.style.width="400px";
    
    var messageDiv = document.createElement('div');
    messageDiv.innerHTML = text.replace("*title*",document.title);
    messageDiv.style.padding="5px";
    messageDiv.style.textAlign="center";
    messageDiv.style.paddingBottom="20px";
    popunder.appendChild(messageDiv);
    
    var actionDiv = document.createElement('div');
    actionDiv.style.textAlign="center";
    actionDiv.style.borderTop="solid 1px gray";
    actionDiv.style.paddingTop="10px";
    
    var actionLink = document.createElement('a');
    actionLink.innerHTML = "Chat";
    actionLink.href="javascript:void(0);";
    actionLink.style.marginRight="20px";
    actionLink.onclick=function() { setInvitationStatus(currentSessionID,"1"); this.parentNode.parentNode.style.display='none'; launchChat(currentSessionID); return false; };
    actionDiv.appendChild(actionLink);
    
    var messageLink = document.createElement('a');
    messageLink.innerHTML = "Send Message";
    messageLink.href=appRoot+"gcr/clickToCall.aspx?invitation=true";
    messageLink.style.marginRight="20px";
    actionDiv.appendChild(messageLink);
    
    var declineLink = document.createElement('a');
    declineLink.innerHTML = "No Thanks";
    declineLink.href = "javascript:void(0);";
    declineLink.onclick = function() { setInvitationStatus(currentSessionID,"0"); this.parentNode.parentNode.style.display='none'; return false; };
    actionDiv.appendChild(declineLink);
    
    popunder.appendChild(actionDiv);
    
    parent.appendChild(popunder);
    
    displaySurvey(popunder.id, true);
}

function doAjax(targetURL, targetFunction)
{
    var xmlhttp;
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
      }
    else if (window.ActiveXObject)
      {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      
    //do it
    xmlhttp.onreadystatechange=function()
    {
        if(xmlhttp.readyState==4)
        {
            targetFunction();
        }
    }
    
    var url = targetURL;
    if(url.indexOf("?") == -1)
        url += "?rand="+ Math.floor(Math.random()*1000000);
    else
        url += "&rand="+ Math.floor(Math.random()*1000000);
        
        
    debug("Calling url: " + url);
    
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
}