
var ns4=document.layers
var ie4=document.all
var ns6=document.getElementById&&!document.all

//drag drop function for NS 4////
/////////////////////////////////

var dragswitch=0
var nsx
var nsy
var nstemp

function drag_dropns(name){
if (!ns4)
return
temp=eval(name)
temp.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP)
temp.onmousedown=gons
temp.onmousemove=dragns
temp.onmouseup=stopns
}

function gons(e){
temp.captureEvents(Event.MOUSEMOVE)
nsx=e.x
nsy=e.y
}

function dragns(e){
if (dragswitch==1){
temp.moveBy(e.x-nsx,e.y-nsy)
return false
}
}

function stopns(){
temp.releaseEvents(Event.MOUSEMOVE)
}

//drag drop function for ie4+ and NS6////
/////////////////////////////////

function drag_drop(e){
if (ie4&&dragapproved){
crossobj.style.left=tempx+event.clientX-offsetx
crossobj.style.top=tempy+event.clientY-offsety
return false
}
else if (ns6&&dragapproved){
crossobj.style.left=tempx+e.clientX-offsetx+"px"
crossobj.style.top=tempy+e.clientY-offsety+"px"
return false
}
}

function initializedrag(e){
crossobj=ns6? document.getElementById("showimage") : document.all.showimage
var firedobj=ns6? e.target : event.srcElement
var topelement=ns6? "html" : document.compatMode && document.compatMode!="BackCompat"? "documentElement" : "body"
while (firedobj.tagName!=topelement.toUpperCase() && firedobj.id!="dragbar"){
firedobj=ns6? firedobj.parentNode : firedobj.parentElement
}
if (firedobj.id=="dragbar"){
offsetx=ie4? event.clientX : e.clientX
offsety=ie4? event.clientY : e.clientY

tempx=parseInt(crossobj.style.left)
tempy=parseInt(crossobj.style.top)

dragapproved=true
document.onmousemove=drag_drop
}
}
document.onmouseup=new Function("dragapproved=false")

////drag drop functions end here//////

function hidebox(){
crossobj=ns6? document.getElementById("showimage") : document.all.showimage
if (ie4||ns6)
crossobj.style.visibility="hidden"
else if (ns4)
document.showimage.visibility="hide"
}

// POPUP HTML
function writeJS()
{
	var str='';
	str+='<div id="showimage" style="position:absolute; width:200px; left:655px; top:133px; z-index: 200;">';
	str+='	<table style="position:relative; width:217px; height:319px; left:0px; top:0px;" width="217px" height="319px" border="0" cellspacing="0" cellpadding="0" >';
	str+='		<tr>';
	str+='			<td>';
	str+='				<table border="0" cellspacing="0" cellpadding="0">';
	str+='		      		<tr style="position: relative; top:2px; left: 0px;">';
	str+='						<td background="http:\/\/maxtool.com\/catalog\/images\/catalog_t.gif" id="dragbar" style="background-repeat: no-repeat;filter:alpha(opacity=95);-moz-opacity:.95;opacity:.95;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="http:\/\/maxtool.com\/catalog\/images\/catalog_t.gif", sizingMethod="scale";" onMouseDown="initializedrag(event)";>';
	str+='							<ilayer onSelectStart="return false">';
	str+='								<layer onMouseover="dragswitch=1;if (ns4) drag_dropns(showimage)" onMouseout="dragswitch=0" style="background-color: transparent;"><img src="http:\/\/maxtool.com\/catalog\/images\/spacer.gif" alt="" width="175" height="0" border="0"><\/layer>';
	str+='							<\/ilayer>';
	str+='						<\/td>';
	str+='						<td align="right" valign="top" style="cursor:hand;" onClick="hidebox();return false">';
	str+='							<a style="position:relative; left:0px; top:0px;background-color: transparent;" href="#" ><img src="http:\/\/maxtool.com\/catalog\/images\/catalog_c.gif" alt="" name="close1" border="0" onMouseOver="document.close1.src=\'http:\/\/maxtool.com\/catalog\/images\/catalog_co.gif\'" onMouseOut="document.close1.src=\'http:\/\/maxtool.com\/catalog\/images\/catalog_c.gif\'" onMouseDown="document.close1.src=\'http:\/\/maxtool.com\/catalog\/images\/catalog_cd.gif\'" style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src="http:\/\/maxtool.com\/catalog\/images\/catalog_t.gif", sizingMethod="scale");"><\/a>';
	str+='						<\/td>';
	str+='					<\/tr>';
	str+='					<tr>';
	str+='						<td id="png" width="100%" height="319px" colspan="2" background="http:\/\/maxtool.com\/catalog\/images\/catalog_b.gif" style="background-color:transparent; position:relative; left:0px; top:0px; background-repeat: no-repeat;">';
	str+='<!-- AD START -->';
	str+='							<a style="position:relative; left:0px; top:0px; background-color:transparent; filter:alpha(opacity=95);-moz-opacity:.95; opacity:.95;" href="http:\/\/www.maxtool.com\/comp_cat.htm" ><img src="http:\/\/maxtool.com\/catalog\/images\/spacer.gif" alt="" width="217" height="319" border="0"><\/a>';
	str+='<!-- AD END -->';
	str+='						<\/td>';
	str+='					<\/tr>';
	str+='				<\/table>';
	str+='			<\/td>';
	str+='		<\/tr>';
	str+='	<\/table>';
	str+='<\/div>';
	document.write(str);
}

var expDays = 1; // number of days the cookie should last

function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
    return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return null;
}

function SetCookie (name, value) {
  var argv = SetCookie.arguments;
  var argc = SetCookie.arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain =(argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;
  document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");
}

function DeleteCookie (name) {
  var exp1 = new Date();
  exp1.setTime (exp1.getTime() - 1);
  var cval = GetCookie (name);
  document.cookie = name + "=" + cval + "; expires=" + exp1.toGMTString();
}

var exp1 = new Date();
exp1.setTime(exp1.getTime() + (expDays*24*60*60*1000));

function amt(){
  var count = GetCookie('count')
  if(count == null) {
    SetCookie('count','1',exp1, '/', 'maxtool.com')
    return 1
  } else {
    // var newcount = parseInt(count) + 1;
    // DeleteCookie('count')
    // SetCookie('count',newcount,exp1, '/', 'maxtool.com')
    return count
  }
}

function getCookieVal(offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
  endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function checkCount() {
  var count = GetCookie('count');
  if (count == null) {
    count=1;
    SetCookie('count', count, exp1, '/', 'maxtool.com');
	writeJS();
    //window.open(page, "", windowprops);
  } else {
    // count++;
    // SetCookie('count', count, exp1, '/', 'maxtool.com');
  }
}

checkCount();
