
  var total=0;
  var pb=1;
  var selectStart=false;
  var blockarray=new Array();
  var debug="";
  var counter=0;
  var ItemID=1;
  var theDescription="";
  var upperleftsponsor="<table cellpadding=0 cellspacing=0 border=1 bgcolor=ffffe1><tr><td>click the \"buy now\" button to claim the selected area or reselect a corner.</td><tr></table>";
  var lowerrightsponsor="<table cellpadding=0 cellspacing=0 border=1 bgcolor=ffffe1><tr><td>Select the lower right-hand corner of the desired block to sponsor.</td><tr></table>";
  var sponsortext="<table cellpadding=0 cellspacing=0 border=1 bgcolor=ffffe1><tr><td>Select the upper left-hand corner of the desired block to sponsor.</td><tr></table>";
  var selectingRegionText="<table cellpadding=0 cellspacing=0 border=1 bgcolor=ffffe1><tr><td>Selecting the region...</td><tr></table>";
<!--

/////////////////////////////////////////////
function getpb() {
  var theprodname="product"+ItemID;
  var hiddenvalue=document.getElementById(theprodname).value;
  pb=hiddenvalue*1;
  
  var thedesc="desc"+ItemID;
  theDescription=document.getElementById(thedesc).value;
}

/////////////////////////////////////////////
function addblock(obj) {
  //alert("addblock: "+obj);
  getpb();
  
  total=total+pb;

  blockarray[blockarray.length]=obj;
  debug=blockarray.length;
  updateTotalText(obj);
  //alert("blockarray after clear: "+blockarray[0]);
  //alert("hi");
  }
  
/////////////////////////////////////////////
function removeblock(obj) {
  total=total-pb;
  updateTotalText(obj);
}

/////////////////////////////////////////////
function buttonClear() {
selectStart=false;
clearAllBlocks();
blockarray.length=0;
updateTotalText();
//sponsortext=upperleftsponsor;
setTrailingMessage(sponsortext);
}

/////////////////////////////////////////////
function submitTheForm() {
  document.form_buy.submit();
}

/////////////////////////////////////////////
function createTheForm() {
  var theform=
  "<form name=\"form_buy\" action=\"../buying/\" method=\"post\">" +
  "<input type=\"hidden\" name=\"theitem\" value=\""+ItemID+"\">" +
  "<input type=\"hidden\" name=\"theDescription\" value=\""+theDescription+"\">" +
  "<input type=\"hidden\" name=\"price\" value=\""+pb+"\">" +
  "<input type=\"hidden\" name=\"upperleft\" value=\""+blockarray[0]+"\">" +
  "<input type=\"hidden\" name=\"totalprice\" value=\""+total+"\">" +
  "<input type=\"hidden\" name=\"lowerright\" value=\""+blockarray[blockarray.length-1]+"\">" +
  "</form>";
  //sponsortext=upperleftsponsor;
  return theform;
}

/////////////////////////////////////////////
function checkfilename(thediv) {
  alert(thediv);
  var ext = document.thediv.pic.value;
  ext = ext.substring(ext.length-3,ext.length);
  ext = ext.toLowerCase();
  if(ext != 'jpg') {
    alert('You selected a .'+ext+
          ' file; please select a .jpg file instead!');
    return false; }
  else
    return true; }

/////////////////////////////////////////////
function ShowUploadFileForm(PurchaseID, theWidth, theHeight) {

  var thediv = PurchaseID + "_uploadfilediv";
  //alert(thediv);
  document.getElementById(thediv).innerHTML = 
  "<form action=\"./\" method=\"post\" enctype=\"multipart/form-data\" >" +
  "<table cellpadding=0 cellspacing=0 border=0>" +
  "<input type=\"hidden\" name=\"purchaseid\" value=\""+PurchaseID+"\" />" +
  "<input type=\"hidden\" name=\"theWidth\" value=\""+theWidth+"\" />" +
  "<input type=\"hidden\" name=\"theHeight\" value=\""+theHeight+"\" />" +
  "<tr>" +
  "<td><label for=\"file\">Filename</label>&nbsp;</td>" +
  "<td><input type=\"file\" name=\"updated_filename\" id=\"file\" size=\"60\" value=\"\" /></td>" +
  "<td><input type=\"submit\" name=\"submitfile\" value=\"Upload\" /></td>" +
  "</tr></table></form>";
  //"<div style=\"position:absolute;left:30px;top:-15px;\">" + "FORM" +
  //"<table cellspacing=0 cellpadding=0>"+
  //"<tr>"+themenu+"</tr>"+
  //"<tr><td>Total</td><td>$" + total + ".00</td></tr>" +
  //"<tr><td>Blocks</td><td>" + debug + "</td></tr>" +
  //"<tr><td>Pixels</td><td>" + totalpixels + "</td></tr>";
  //"</div>";
}

/////////////////////////////////////////////
function updateTotalText(obj) {
  var totalpixels=debug*100;
  var tempUpdateText="the_total_"+ItemID;

  var themenu="<td><img onclick=\"javascript:submitTheForm();\" src=\"../images/buynow.jpg\" border=\"0\">&nbsp;</td>"+"<td><img onclick=\"javascript:buttonClear();\" src=\"../images/clearselection.jpg\" border=\"0\">&nbsp;</td>";
  document.getElementById(tempUpdateText).innerHTML = 
  "<div style=\"position:absolute;left:30px;top:-15px;\">" + createTheForm() +
  "<table cellspacing=0 cellpadding=0>"+
  "<tr>"+themenu+"</tr>"+
  "<tr><td>Total</td><td>$" + total + ".00</td></tr>" +
  "<tr><td>Blocks</td><td>" + debug + "</td></tr>" +
  "<tr><td>Pixels</td><td>" + totalpixels + "</td></tr>";
  "</div>";
}

/////////////////////////////////////////////
function setMessage(obj) {
  document.getElementById('message').innerHTML = obj;
}

/////////////////////////////////////////////
function setTrailingMessage(lowerrightsponsor) {
  document.getElementById('trailimageid').innerHTML = lowerrightsponsor;
}

/////////////////////////////////////////////
function isItTheStart() {

  if (selectStart==true) {
    selectStart=false;
	//sponsortext=upperleftsponsor;
	setTrailingMessage(upperleftsponsor);
	//alert("is was true");
  }
  else
  {
    selectStart=true;
	//sponsortext=lowerrightsponsor;
	setTrailingMessage(lowerrightsponsor);
	//alert("it was false");
  }
  return selectStart;
}

/////////////////////////////////////////////
function clearblock(obj) {
  //alert("clearblock:"+obj);
  if (document.getElementById(obj))
  {
      //alert("clearblock IF:"+obj);
	  target=document.getElementById(obj);
	  var str=target.src;
      target.src='../images/unselected.png';
  }
  else
  {
    //alert("clearblock ELSE:"+obj);
	document.images[obj].src='../images/unselected.png';
  }
  return 0;
}

/////////////////////////////////////////////
function clearAllBlocks(obj) {
	//alert("Array Size Before Clear:"+blockarray.length);
	for(i=0;i<blockarray.length;i++) {
	  //alert("clearAllBlocks:"+blockarray[i]);
      clearblock(blockarray[i]);
    }
	//alert("After");
	blockarray.length=0;
	total=0;
	debug=blockarray.length;
	//alert("Array Size After Clear:"+blockarray.length);
	return 0;
}

function isItTheSameItem(obj)
{
	var theItemText1a=blockarray[0].split(".");
	var theItemText1=theItemText1a[1];
	
	var theEndID=obj.split(".");
	var theItemText2=theEndID[1];
	
	var forReturn=0;
	if (theItemText1==theItemText2)
	{
		//alert("same Item");
		forReturn=1;
	}
	//alert(forReturn);
	return forReturn;
}

function createBlock(obj) {
    //alert(obj.name);
	//blockarray.length=1;
	//alert(obj);
	//setTrailingMessage(selectingRegionText);
	var startcoord=blockarray[0].split("_");
	var tempstart=startcoord[1].split(".");
	startcoord[1]=tempstart[0];
	//alert("start: "+startcoord[0]+", "+startcoord[1]);
	var endcoord=obj.split("_");
	var tempend=endcoord[1].split(".");
	endcoord[1]=tempend[0];
	
	//alert("end: "+endcoord[0]+", "+endcoord[1]);
	
	if (isItTheSameItem(obj))
	{
	//alert(startcoord[0]+" "+endcoord[0]);
	//alert(startcoord[1]+" "+endcoord[1]);
	if ((endcoord[0]*1) < (startcoord[0]*1))
	{
		var temp=startcoord[0];
		startcoord[0]=endcoord[0];
		endcoord[0]=temp;
	}
	if ((endcoord[1]*1) < (startcoord[1]*1))
	{
		var temp=startcoord[1];
		startcoord[1]=endcoord[1];
		endcoord[1]=temp;
	}
	clearAllBlocks();
	xcount=endcoord[0]-startcoord[0];
	ycount=endcoord[1]-startcoord[1];
	//alert (xcount+" "+ycount);
	var temp="start="+startcoord+" end="+endcoord+" blockarray len:"+blockarray.length;
	//setMessage(temp);
	//alert(temp);
	counter=0;
    for (var x2 = 0; x2 <= xcount; x2++)
    {
    for (var y2 = 0; y2 <= ycount; y2++)
    {
	counter++;
	var xval=(startcoord[0]*1)+x2;
	var yval=(startcoord[1]*1)+y2;
	
	var thename=xval+"_"+yval+"."+ItemID;
	
	//alert("thename:"+thename);
	if (thename!=blockarray[0]) {
	if (document.getElementById("d"+thename)) {
	if (document.getElementById(thename)) {
		target=document.getElementById(thename);
		var str=target.src;
		addblock(thename);
		target.src='../images/selected.gif';
	}
	else if (document.images[thename])
	{
		//alert("mozilla "+thename);
		// This is for MOZILLA
		target=document.images[thename];
		var str=target.src;
		addblock(thename);
		document.images[thename].src='../images/selected.gif';
	}
	}
	else
	{
		//setMessage("Invalid Block.  The selected region must me a square or rectangle.");
		x2=xcount;
		y2=ycount;
		selectStart=false;
		clearAllBlocks();

		updateTotalText();
		//selectSquareByName(blockarray[0]);
		var temptext="Invalid region, please select an area that is a square or a rectangle that does not overlap an unselectable region.";
		setTrailingMessage(temptext);
		alert(temptext);
		setTrailingMessage(sponsortext);
	}
	}
  }
  }
  	updateTotalText(obj);
  }
  else
  {
  		clearAllBlocks();
		alert("Invalid region, please select a region on the same image.");
		setTrailingMessage(sponsortext);
  }
  //alert("done");
}

function selectSquareByName(theName) {
  //alert("selectSquareByName");
  //var temptext="Selecting region...";
  //setTrailingMessage(temptext);
  if (isItTheStart()) {
    // Start Block
	//var temp1="thename:"+thename;
    //alert("temp1");
	//if (blockarray != null) {
		//alert("Before Clear");
		clearAllBlocks(theName);
		//alert("After Clear");
	    //setMessage("Cleared all blocks");
	//}
	if (document.getElementById(theName)) {
		//alert("name stuff good");
		target=document.getElementById(theName);
		var str=target.src;
		if (str.indexOf("../images/selected.gif") > -1) {
			removeblock(theName);
			target.src='../images/unselected.png';
		}
		else
		{
			addblock(theName);
			target.src='../images/selected.gif';
		}
	}
	else
	{
		// This is for MOZILLA
		//alert("mozilla");
		//alert(theName);
		target=document.images[theName];
		var str=target.src;
		if (str.indexOf("../images/selected.gif") > -1) {
			removeblock(theName);
			document.images[theName].src='../images/unselected.png';
		}
		else
		{
			//alert("before selected");
			addblock(theName);
			document.images[theName].src='../images/selected.gif';
			//alert("after selected");
		}
	}
	// End Start Block
  }
  else
  {
    //alert("Creating Block");
	//setMessage("Block Creation Started");
	createBlock(theName);
  }
}

/////////////////////////////////////////////
function selectit(obj) {
	var tempUpdateText2="the_total_"+ItemID;
	//alert(tempUpdateText2);
	document.getElementById(tempUpdateText2).innerHTML = " ";
    //alert(ItemID);
	var theObjName=obj.name.split(".");
	ItemID=theObjName[1];
	//alert(theObjName[0]);
	//alert(theObjName[1]);
	//selectSquareByName(theObjName[0]);
	//alert(ItemID);
	selectSquareByName(obj.name);
}

function mousedown(obj) {
//alert("hi");
}
function mouseup(obj) {

}
function mover() {
window.status='Click here to purchase';
document.body.style.cursor = "crosshair";
}
function mout() {
window.status='';
document.body.style.cursor = "default";
}

function CheckRegForm(f) {

//if (
  //chk_text_email(f.email, 'Please enter a valid email address.') &&
  //chk_text_email(f.reemail, "Please confirm your email address.") &&
  //chk_text(f.password, 'You need a password.', false) &&
  //chk_text(f.repassword, 'Please confirm your password.', false)
//  ) {
           	if (f.email.value != f.reemail.value) {
                alert('Your email and confirmation email do not match. Please check them and try again.');
           	} else if (f.passwd.value.length<6) {
                alert('Your password should be at least 6 characters long.');
			} else {
				if (f.passwd.value != f.repasswd.value) {
                    alert('Your password and confirmation password do not match. Please check them and try again.');
				} else {
					var retstring;
					//retstring = RemoveTrailingSpaces(document.register.email.value);
					//document.register.email.value = retstring;

					return true;
				}
			}
	//}
    return false;
}

var trailimage=["myimage.gif", 100, 99] 
var distancefrommouse=[25,-35] 
var displayduration=0 


function gettrailobj(){
if (document.getElementById)
return document.getElementById("trailimageid").style
else if (document.all)
return document.all.trailimagid.style
}

function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function hidetrail(){
gettrailobj().visibility="hidden";
document.onmousemove="";
}

function followmouse(e){
  var xcoord=distancefrommouse[0];
  var ycoord=distancefrommouse[1];
  if (typeof e != "undefined"){
    xcoord+=e.pageX;
    ycoord+=e.pageY;
  }
  else if (typeof window.event !="undefined"){
    xcoord+=truebody().scrollLeft+event.clientX;
    ycoord+=truebody().scrollTop+event.clientY;
  }
  var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15;
  var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight);
  if (xcoord+trailimage[1]+3>docwidth || ycoord+trailimage[2]> docheight)
    gettrailobj().display="none";
  else 
    gettrailobj().display="";
  gettrailobj().left=xcoord+"px";
  gettrailobj().top=ycoord+"px";
}

function showbb(thediv) {
  var divcontrol=document.getElementById(thediv);
  divcontrol.style.visibility = "visible";
}

function hidebb(thediv) {
  var divcontrol=document.getElementById(thediv);
  divcontrol.style.visibility = "hidden";
}

