<html>
<head>
<script language='javascript'>

//Get coordinates of input object
function find_position()
{
    var posx = posy = 0;
    if (typeof window.screenLeft != 'undefined' && typeof window.screenTop != 'undefined')
    {  posx = window.screenLeft;  posy =window.screenTop; }
    else if (typeof window.screenX != 'undefined' && typeof window.screenY != 'undefined')
    {  posx = window.screenX;  posy = window.screenY; }
    else
    {  posx = posy = 0; }
       //if window is maximized, make sure there arnt negatives
    if (posx > -10 && posx < 0) posx = 0;
    if (posy > -10 && posy < 0) posy = 0;

    return posx + "x" + posy;
}

//Get viewport of popup
function get_viewport()
{
	var viewportwidth = 0;
	var viewportheight = 0;
 
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	if (typeof window.innerWidth != 'undefined')
	{
		viewportwidth = window.innerWidth;
		viewportheight = window.innerHeight;
	}
	else 
	{
		if (document.body == null)
			document.write('<body>');

		if	(document.body != null && typeof document.body.clientWidth != 'undefined' && document.body.clientWidth != 0)
		{
			viewportheight = document.body.clientHeight;
			viewportwidth = document.body.clientWidth;
		}
			// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
		else if (document.documentElement != null && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
		{
			viewportwidth = document.documentElement.clientWidth;
			viewportheight = document.documentElement.clientHeight;
		}
			// older versions of IE
		else if (document.getElementsByTagName('body') != null && document.getElementsByTagName('body')[0] != null && typeof document.getElementsByTagName('body')[0].clientWidth != 'undefined' && document.getElementsByTagName('body')[0].clientWidth != 0)
		{
			viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
			viewportheight = document.getElementsByTagName('body')[0].clientHeight;
		}
	}
	return viewportwidth + "x" + viewportheight;
}

function setCookie( name, value, expiredays, path)
{    var exdate=new Date();
     exdate.setDate(exdate.getDate()+expiredays);
     document.cookie=name+ "=" +escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toUTCString()) + (( path ) ? ";path=" + path : "" );
        //** setCookie('testCookie', 'xxx', 1, '/');
}


function isInIframe( breakout )
{
   var isInIFrame = (window.top === window.self) ? "N" : "Y";
     // var isInIFrame = (window.location != window.parent.location) ? "Y" : "N";

   if (isInIFrame == "Y" && breakout && window.top.location!= window.self.location) 
      window.top.location = window.self.location.href
   return isInIFrame;
}


function getParam(theName)
{  var url = window.location.toString();
      //get the parameters
   url.match(/\?(.+)$/);
   var params = RegExp.$1;
   var size = params.split("&").length;
   var theValue;
   for (var i = 0; i < size; i++)
   {  var piece  = params.split("&")[i];
      var name = piece.split("=")[0];
      var value = piece.split("=")[1];
      if (theName == name && value != null)
          theValue = value.replace(/\+/g, " ");
   }
   //**Decode
   return theValue;
}

   //**Redirect - accomodates IE bug causing a blank referer
function redir(url) 
{  
   if (navigator.appName == 'Microsoft Internet Explorer')
   {   var referLink = document.createElement('a');
       referLink.href = url;
       document.body.appendChild(referLink);
       try { referLink.click();}
       catch (ex) { document.location.href = url; }
   }
   else
   {
      document.location.href = url;
   }
}

function go()
{   var query = window.location.search.substring(1);
    domain = window.location.host;
    domainArray = domain.split('.');
    if (domain == "myeport.org" || domain == "www.myeport.org" || domain == "audsplace.com" || domain == "www.audsplace.com" || domain == "audsbackup.com" || domain == "www.audsbackup.com" || domain == "searchtest.net" || domain == "www.searchtest.net")  //Aud's local area test
        newDomain = "audsbackup.com";
    else 
       newDomain = "click.mygeek.com";
    ref=document.referrer;
    if (ref == "")
       ref="NONE";
    else
       ref = escape(ref);  

    pos = find_position();
    viewport = get_viewport();
    breakOut = getParam("breakout");
    if (breakOut != null && (breakOut == "Y" || breakOut == "y"))
       breakout = true;
    else 
       breakout = false;
    isIframe = isInIframe( breakout );

      //**Set cookie to test for cookies later
    setCookie('AAXAA', newDomain, 1, '/');
    cookieEnabled=(document.cookie.indexOf("AAXAA")!=-1 || document.cookie.indexOf("mgUser")!=-1)? "Y" : "N";

    newURL = "http://" + newDomain + "/presults.jsp?" + query + "&REFERER=" + ref + "&POS=" + pos + "&VIEWPORT=" + viewport + "&IFRAME=" + isIframe + "&COOKIES=" + cookieEnabled;
    //alert(newURL);
    redir(newURL);
}

</script>
</head>
<body onload="go();">

</body>
</html>

