document.write('<script type="text/javascript" src="/js/jquery.form.js"></script>');
document.write('<script type="text/javascript" src="/js/menu.js"></script>');
document.write('<script type="text/javascript" src="/js/form.js"></script>');
  
var isIE = document.all;
function element(id) { return document.getElementById(id); }

window.document.oncontextmenu = function(e)
{ 
  ob = isIE ? event.srcElement : e.target;
  if(ob.tagName == "IMG") return false; 
  return;
} 

function do_free_code(what,typepad)
{
  url = what+"/";
  alt = what;
  if(what == "all")
  {
    url = "";
    alt = "DAILY";
  }

  syndcode = $("#code").val();
  syndcode = syndcode.replace(/%TOPICURL%/g,url);
  syndcode = syndcode.replace(/%TOPICIMG%/g,what);
  syndcode = syndcode.replace(/%TOPICALT%/g,alt.toUpperCase());
  if(typepad) $("#contentcode").val(syndcode);
  else
  {
    $("#codewindow").val(syndcode);
    $("#sample").html(syndcode);
  }
}

function check_code()
{
  if($("contentcode").val() == "Please go back and enable javascript!")
  {
    alert("Please choose a topic!");
    return false;
  }
  else
  return true;
}

function buy(id, radio)
{
  var type = "";
  if (radio) {
  	var group = document.getElementsByName('typeselect');
  	for (var i = 0; i < group.length; i++)
	  if (group[i].checked)
	    type = group[i].value;
  } else type = $('#typeselect').val();
  if(type == "Select cartoon usage..." || type == "")
  {
    alert("Please choose a presentation type.");
    return;
  }
  location.href = "/store/add/"+id+"/"+type+"/";
}

var _resize_ = false;
function popup(url,w,h)
{
	popup_width = w;
	popup_height = h;

  // prep for ie6
  if(typeof document.body.style.maxHeight === 'undefined')
  {
	  $('body','html').css({height:'100%',width:'100%'});
  }

  // overlay screen
  $('body').append('<div id="overlay"></div><div id="popup"></div>');

  // clear any old content
  $('#popup_content').remove();

  // add iframe position and load url
  $('#popup').css({marginLeft:'-'+parseInt((popup_width/2),10)+'px',top:parseInt((popup_height/2),10)+'px',width:popup_width+'px'});
  $('#popup').append('<iframe scrolling="no" allowtransparency="true" onload="popup_size()" frameborder="0" hspace="0" src="'+url+'" id="popup_content" style="height:100%;width:'+popup_width+'px;"></iframe>');

  $('#popup').css({display:'block'});

  // trap escape key
  document.onkeydown = function(e)
  {
    code = e ? e.which : event.keyCode;
    if(code == 27) popup_close(false);
  }
  _resize_ = setInterval(popup_size,250);
  return false;
}

// close popup window
function popup_close(update)
{
  $('#popup,#overlay').trigger('unload').unbind().remove();
  $('#popup_load').remove();

  //if IE 6
  if(typeof document.body.style.maxHeight == 'undefined')
  {
    $('body','html').css({height:'auto',width:'auto'});
	}
	document.onkeydown = "";
	clearInterval(_resize_);
}

// maintain full size
function popup_size()
{
  if(!$('#popup_content')[0].contentWindow.document.body) return;
  height = $('#popup_content')[0].contentWindow.document.body.offsetHeight;
  $('#popup_content').css('height',height+'px');
}

// rollover enlargement functions
function getIEVersion()
// Returns the version of Windows Internet Explorer or a -1 (indicating the use of another browser).
{
   var rv = -1; // Return value assumes failure.
   if (navigator.appName == 'Microsoft Internet Explorer')
   {
      var ua = navigator.userAgent;
      var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
      if (re.exec(ua) != null)
         rv = parseFloat( RegExp.$1 );
   }
   return rv;
}
function enlargerVisible(vis, row) {
	if (vis) {
		for (var i = 1; i <= 10; i++) {
			if (document.getElementById("enlarger" + i)) {
				if (i != row)
					enlargerVisible(false, i);
			} else {
				break;
			}
		}
	}
	document.getElementById("enlarger" + row).style.visibility = (vis ? "visible" : "hidden");//(ipaddr == "71.227.175.219" ? "visible" : "hidden")
}
function setEnlargerImg(search, img, row, col, id, views, rating) {
	var isie7 = (getIEVersion() >= 7 && getIEVersion() < 8);
	document.getElementById("enlarger" + row).style.left = (col == 0 ? (search == 1 ? (isie7 ? "145px" : "161px") : "146px") : (col == 1 ? (search == 1 ? (isie7 ? "325px" : "341px") : "323px") : (col == 2 ? (search == 1 ? (isie7 ? "505px" : "521px") : (search == 0 ? "500px" : "-34px")) : (search == 1 ? (isie7 ? "152px" : "173px") : "144px"))));
	document.getElementById("enlargeimg" + row).src = img;
	document.getElementById("number" + row).innerHTML = "Cartoon " + id;
	document.getElementById("views" + row).innerHTML = "Views: " + views;
	document.getElementById("rating" + row).innerHTML = "Rating: " + rating + "/5";
}
function imageLoaded(row) {
	enlargerVisible(true, row);
}
