
var VersionInfo;
var gSiteID;



//-------------------------
// Function: GetBrowserInfo
// Purpose: Identify the browser and OS.  WebIQ needs IE4+ and Win32
//-------------------------
function GetBrowserInfo()
{
    //extract info from the browser about compatibility
    var AgentValue=navigator.userAgent

	var CharPos="", lVersion="", bIsIE4=false, bIsIE5=false, bIsIE6=false, OtherBrowser="";
	CharPos=AgentValue.indexOf("MSIE");
	if (CharPos!=-1)
	{
		OtherBrowser=AgentValue.indexOf("Opera");
		if (OtherBrowser == -1)
		{
    	this.ie=true;
		lVersion=AgentValue.charAt(CharPos+5);
		bIsIE4=false;
		(lVersion=="5")?bIsIE5=true:bIsIE5=false;
		(lVersion=="6")?bIsIE6=true:bIsIE6=false;		
		}
		else
		{
			bIsIE4=false;
			bIsIE5=false;	
			bIsIE6=false;
				
		}
	
	} 
	else 
	{
		bIsIE4=false;
		bIsIE5=false;	
		bIsIE6=false;
	}
	CharPos=AgentValue.indexOf("AOL 7");
	if (CharPos!=-1)
	  {
	    this.AOL7=true;
	  }
	else
	  {
	    this.AOL7=false;
	  }
	(bIsIE4||bIsIE5||bIsIE6)?this.ie4compat=true:this.ie4compat=false;
	(AgentValue.indexOf("Windows 95")>0||AgentValue.indexOf("Win95")!=-1||AgentValue.indexOf("Win98")!=-1||AgentValue.indexOf("Windows 98")!=-1||AgentValue.indexOf("Windows NT")!=-1)?this.win32=true:this.win32=false;
}


function DisplayIFrameQuestion(LDI)
{
	var sFeatures = "scrollbars=1,resizable=1,height=475,width=550,top=100,left=100";
	var sExpireDate = PickExpireDate();	

	
		//Check to see if cookies are turned on
	document.cookie = "CookiesONOFF=ON" + ";expires=" + sExpireDate + "; path=/"; 
	sCookiesONOFF = GetCookie("CookiesONOFF");
	if (sCookiesONOFF == "ON")
	{
    	// Use sCookieValue if you don't want to prompt users on their next visit
		sCookieValue = GetCookie("webiq_invitation");
	}
	else
	{
		sCookieValue = "reject";
	}
  
	if ((sCookieValue != "reject") && (sCookieValue != "accept"))
	{

    // write cookie so we don't prompt the user again
//    var dExpirationDate = new Date(2003, 6, 15);
//    SetCookie("webiq_invitation", "accept", dExpirationDate);

    // pop invitation/survey window
    showWebIQIFrame('/data/question.html?ldi=' + LDI, '550', '440');
   // sData = window.open("./webiq/question.html?ldi=" + LDI, "Feedback", sFeatures);
    
  }
    
}



//-------------------------
// Function: GetCookie
// Purpose: Retrieve the value of the cookie with the specified name.
//-------------------------
function GetCookie(sName)
{
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) 
      return unescape(aCrumb[1]);
  }

  // a cookie with the requested name does not exist
  return null;
}


//-------------------------
// Function: PickExpireDate
// Purpose: Set the cookie expire date so that it will still
//          be here when they return.
//-------------------------
function PickExpireDate()
{
    RightNow = new Date();
    var TheMonth = RightNow.getMonth()
    var TheYear  = RightNow.getYear()
    //set expire date to way into the future
    TheMonth = TheMonth + 3;
    
    if (TheMonth > 12)
    {
      TheMonth = TheMonth - 12;
      TheYear  = TheYear + 1;
      RightNow.setYear(TheYear);
      RightNow.setMonth(TheMonth);
    }
    else
    {
      RightNow.setMonth(TheMonth);
    }
    
    RightNow = RightNow.toGMTString();

    return RightNow;
}



//-------------------------
// Function: WebIQCookieCheck
// Purpose: If user has not yet loaded WebIQ, then do so now if they qualify
//-------------------------
function WebIQCookieCheck(Frequency, LDI)
{
    //only ask a portion of the users
    var Lottery;
    var gSiteID;
    
    //see if launch page loaded during this session already
    var sSameSessionAsked = GetCookie("webiqLoaded");
    var sSamePageLottery = GetCookie(LDI + "Lottery");
    //if webiq not already loaded then launch it now
    if (sSameSessionAsked != "yes"  && sSamePageLottery != "yes")
    {
      Lottery = Math.floor(Math.random() * Frequency);
      if (Lottery == 0)
      {

		VersionInfo = new GetBrowserInfo();
        if (VersionInfo.ie4compat && VersionInfo.win32)
      	{
    	    DisplayIFrameQuestion(LDI);
    	  
      	}

      	document.cookie = "webiqLoaded=yes; path=/";            
      }

    }

    document.cookie = LDI + "Lottery=yes; path=/";

}

function winopen(url,a,b){
newwin=window.open(url,a,b)
}




// Need to add a sniffer for IE 5 and set it to use DOM as well.
function isIE() {
if (navigator.appName == "Microsoft Internet Explorer")
return true;
else return false;
}
// this will replace all the make window code
function retrieveIFrame(){    
Iframe=eval('document.getElementById("WebIQIFrame")');   

return Iframe;
}
function retrieveParentIFrame(){    
Iframe=eval('parent.document.getElementById("WebIQIFrame")');     

return Iframe;
}

function showWebIQIFrame2(theSrc, theWidth, theHeight){
retrieveIFrame().style.visibility="visible";        
retrieveIFrame().src = theSrc;   
retrieveIFrame().style.left=(document.body.clientWidth/2) -(theWidth/2);
retrieveIFrame().style.top=document.body.scrollTop+80; 
//retrieveIFrame().style.left=0;          
//retrieveIFrame().style.top=0; 

if (!isIE()) {
theWidth = (theWidth/1)-5;
theHeight = (theHeight/1)-5;
}
retrieveIFrame().style.width = theWidth; 
retrieveIFrame().style.height = theHeight;    
}
function closeWebIQIFrame(){
retrieveIFrame().style.visibility="hidden";
}
var oIFrame; // our IFrame object
function showWebIQIFrame(theSrc, theWidth, theHeight) {
if (!retrieveIFrame()) {return true};
var DocIFrame;
oIFrame=retrieveIFrame();
oIFrame.style.border='2px solid';
if (!isIE()) {	oIFrame.style.border='solid black 2px';	}
if (oIFrame.contentDocument) {
// For NS6
DocIFrame = oIFrame.contentDocument; 
} else if (oIFrame.contentWindow) {
// For IE5.5 and IE6
DocIFrame = oIFrame.contentWindow.document;
} else if (oIFrame.document) {
// For IE5
DocIFrame = oIFrame.document;
} else {
return true;
}  
showWebIQIFrame2(theSrc, theWidth, theHeight);
}
// end




function closeWindowOrIframe () {
if (parent.retrieveIFrame() && parent.closeWebIQIFrame() ) {
parent.closeWebIQIFrame();
retrieveIFrame().src = "";
} else {
window.close();
}
}

function WebIQIFrameCheck()
{
	var sSameSessionTaken = GetCookie("webiq_invitation");
	var sSameSessionAsked = GetCookie("webiqLoaded");
	if ((sSameSessionTaken != "reject") && (sSameSessionTaken != "accept") && (sSameSessionAsked !="yes"))
	{
		document.write('<iframe id=\"WebIQIFrame\" style=\"position:absolute;width:0;height:0;visibility:hidden;z-index:1000;\" src=\""></iframe>')
	}
	return;
	
}