var width = 800;
var height = 600;





function get_popup_screen_coords()
{
	// get the x,y position of current window in screen coords
	var screenX = 0;
	var screenY = 0;

	if ( window.screen.availLeft != null )
	{
		screenX = parseInt( window.screen.availLeft );
		screenY = parseInt( window.screen.availTop );
	}
	else
	{
		screenX = 0;
		screenY = 0;
	}

	return new Array( screenX, screenY );
}

function popunder(url, popup_type, image_url)
{
		if (get_cookie('popunder')=='')
		{
			
			if (popup_type == "static")
			{
				popunder_banner(image_url, url, width, height);
			}
			else
			{
				var screen_coords = get_popup_screen_coords();
				var x = screen_coords[ 0 ] + ( ( screen.width - width ) / 2 );
				var y = screen_coords[ 1 ] + ( ( screen.height - height ) / 2 );
			
				var params = "left=" + x + ",top=" + y + ",width=" + width + ",height=" + height;
	
				params += ",status=1,toolbar=1,scrollbars=1,directories=1,resizable=1";
			
				new_window = window.open( url, "popunderwindow", params );
				if (navigator.userAgent.indexOf('Chrome/') <= 0) {
					new_window.blur();
				}
				else
				{
					window.blur();
				}
				window.focus();
			}
			var date = new Date();
			date.setTime(date.getTime()+(1*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
			document.cookie = "popunder=yes" + expires;
		}
	
	
}

function init_popunder(url, width, height, scrollbar, image_url) {
	for (i in document.links) {
		document.links[i].orig_onclick = (document.links[i].onclick) ? document.links[i].onclick : function(){};
		document.links[i].onclick = function(){popunder(url, width, height, scrollbar, image_url); this.orig_onclick();}
	}
}

function get_cookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) { // if cookie exists
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1)
         end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}

function addOnLoad(newFunction){
	var oldOnLoad = window.onload;
	
	if(typeof oldOnLoad == "function"){
		window.onload = function(){
			if(oldOnLoad){
				oldOnLoad();
			}
			newFunction();
		}
	}
	else{
		window.onload = newFunction;
	}
}


function popunder_banner(image_url, redirect_url, width, height)
{
	var screen_coords = get_popup_screen_coords();
	var x = screen_coords[ 0 ] + ( ( screen.width - width ) / 2 );
	var y = screen_coords[ 1 ] + ( ( screen.height - height ) / 2 );

	var params = "left=" + x + ",top=" + y + ",width=" + (width+30) + ",height=" + (height+30);
	params += ",status=0,toolbar=0,scrollbars=0,directories=0,menubar=0,resizable=0,titlebar=0";
	new_window = window.open( "", "", params );
	new_window.document.write("<a href='" + redirect_url + "' target='_blank'><img width='"+width+"' height='"+height+"'  src='"+image_url+"' /></a>");
	if (navigator.userAgent.indexOf('Chrome/') <= 0) {
		new_window.blur();
	}
	else
	{
		window.blur();
	}
	window.focus();
}




