﻿// vars
var adHeight = 0;
var linkWidth = "";
var linkHeight = "";
var linkCount = 0;
var linkHides = new Array();
var show_hide = "no";
var topOfDiv = 0;
var divTops = new Array();

// link vars
if(!maxAdHeight)
var maxAdHeight = 0;
var linkWidth = '';
var linkHeight = '';
var link_heights = new Array();
var linkTop = '';
// animation
var animateSpeed = 8;
var object = null;
var fX= null;
var fY= null;
var cX = null;
var cY = null;
var dX = null;
var dY = null;
var stepX= null;
var stepY = null;
var slope = null;

// more link vars
var linkHeight = '';
var linkTop = '';
var linkDepth = '';
var deepestLink = '';
var maskHeight = 1;
var adMaskHeight = 1;
if(!maxAdMaskHeight)
var maxAdMaskHeight = 1;

window.maxZ = 300;
window.heightsRecorded = '';


// attempt php vars: fail
//<?php
//echo 'var testPc = '.$paper_code.';'; 
//echo 'alert("php working in js_fns.php; testPc: "+testPc);';
//?>


function setTop(objectID,y) {
var object = document.getElementById(objectID);
if(object)
object.style.top = y + "px";
}

function findHeight(objectID) {

	var object = document.getElementById(objectID);
	if(object && object.offsetHeight)
//	if(object.offsetHeight)
	return object.offsetHeight;
	return (null);
}

function findWidth(objectID) {

	var object = document.getElementById(objectID);
	if(object.offsetWidth)
	return object.offsetWidth;
	else	
	return (null);
}

function findTop(objectID){
	var object = document.getElementById(objectID);
	if(object.offsetTop)
	return object.offsetTop;
	return(null);
}

function findLivePageWidth()
{
if(window.innerWidth)
return window.innerWidth;
if(document.body.clientWidth)
return document.body.clientWidth;
return (null);
}

function findLivePageHeight()
{
if(window.innerHeight)
return window.innerHeight;
if(document.body.clientHeight)
return document.body.clientHeight;
return (null);
}

function setMargin(objectID,margin)
{
var object = document.getElementById(objectID);
object.style.left = margin+"px";
}

function setHeight(objectID,height)
{
var object = document.getElementById(objectID);
object.style.height = height+"px";
}

function setWidth(objectID,width)
{
var object = document.getElementById(objectID);
object.style.width = width+"px";
}


function setVisibilityA(objectID,state)
{
var object = document.getElementById(objectID);
if(object)
object.style.visibility = state;
else
return (null);
}


function setVisibility(objectID,state)
{
if (show_hide == "yes")
{
var object = document.getElementById(objectID);
if(object)
{
object.style.visibility = state;
if(state == 'visible')
{
object.style.zIndex = window.maxZ;
window.maxZ++;
}
}
}
}
var show_hide = "no";


function setVisibilityAndPosition(objectID,state,thisX,thisY,thisW,xAdj,yAdj,trigger)
{

var object = document.getElementById(objectID);
if(object)
{
if(trigger == "click" && object.style.visibility.toLowerCase() == 'visible')
object.style.visibility = 'hidden';
else
{
object.style.left = Math.round(thisX+thisW+xAdj) + 'px'; //
object.style.top = Math.round(thisY+yAdj) + 'px';
object.style.visibility = state;
}
}
else
return (null);
}

function setClass(objectID,newClass)
{
var object = document.getElementById(objectID);
if(object)
object.className = newClass;
else
return (null);
}

function setDisplayOnly(objectID,state)
{
var object = document.getElementById(objectID);
if(object)
object.style.display = state;
}

function setDisplay(objectID,state,imageID,width,height,open_panel)
{
if((objectID != window.open_panel_iv) || state == "none")
{
var object = document.getElementById(objectID);
if(object)
object.style.display = state;
if(state == 'inline')
{
window.open_panel_iv = objectID;
if(width && height)
initExpand(imageID, width, height, '');
}
}
else
{
window.open_panel_iv = '';
initExpand(imageID, '12', '9', objectID);
}
}

function setVisibilityExpand(objectID,state,imageID,width,height,open_panel,status)
{
if((objectID != window.open_panel_iv) || state == "hidden" || status == "notYetExpanded")
//if((objectID != window.open_panel_iv) || state == "hidden" || status == "mouseoverExpanded")
{
var object = document.getElementById(objectID);
if(object)
{
object.style.visibility = state;
object.style.zIndex = window.maxZ;
window.maxZ++;
}
if(state == 'visible')
{
if(status != 'notYetExpanded')
window.open_panel_iv = objectID;
if(width && height)
initExpand(imageID, width, height,'','','','','','','visibility',objectID);
}
}
else
{
window.open_panel_iv = '';
initExpand(imageID, '12', '9', objectID, '','','','',1,'visibility',objectID);
}
}

function setBackground(objectID,state)
{
var object = document.getElementById(objectID);
if(object)
object.style.background = state;
}

function initAnimate(objectID,x,y,animateSpeed){
if(!animateSpeed)
var animateSpeed = 8;
window.cX = 0;
var left = 0;
window.cY = 0;
var thisTop = 0;
window.dX = 0;
window.dY = 0;

window.stepX = 0;
window.stepY = 0;
window.slope = 0;
object = document.getElementById(objectID);
fX = x;
fY = y;
	
cX = object.offsetLeft;

window.left = cX;

cY = object.offsetTop;

window.thisTop = cY;

dX = Math.abs(fX-cX);
dY = Math.abs(fY-cY);

if((dX ==0) || (dY == 0)) slope = 0;

else slope = dX/dY;
	if(dX>=dY){
		if(cX<fX) stepX = animateSpeed;
		else if (cX>fX) stepX = -animateSpeed;
		if(cY<fY) stepY = animateSpeed*slope;
		if(cY>fY) stepY = -animateSpeed*slope;
	}
	else if (dX<dY) {
		if(cY<fY) stepY =animateSpeed;
		else if (cY>fY) stepY = -animateSpeed;
		if(cX<fX) stepX = animateSpeed/slope;
		else if (cX>fX) stepX = -animateSpeed/slope;
	}
animateObject()
}

function showHideLink(objectID,show_hide,size){

object = document.getElementById(objectID);
cX = object.offsetLeft;
cY = object.offsetTop;

if(show_hide == 'show')
{
if(size == 'min')
fX = -617;
else if(size == 'small')
fX = -487;
else if(size == 'medium')
fX = -325;
else if(size == 'above_ad')
fX = -247;
else if(size == 'vertical')
fX = -175;
else
fX = -125;
}
else if(size == 'above_ad')
fX = -605;
else
fX = -770;
fY = cY;
	
dX = Math.abs(fX-cX);
dY = Math.abs(fY-cY);
if((dX ==0) || (dY == 0)) slope = 0;

else slope = dX/dY;

	if(dX>=dY){
		if(cX<=fX) stepX = animateSpeed;
		else if (cX>fX) stepX = -animateSpeed;
		if(cY<=fY) stepY = animateSpeed*slope;
		if(cY>fY) stepY = -animateSpeed*slope;
	}
	else if (dX<dY) {
		if(cY<=fY) stepY =animateSpeed;
		else if (cY>fY) stepY = -animateSpeed;
		if(cX<=fX) stepX = animateSpeed/slope;
		else if (cX>fX) stepX = -animateSpeed/slope;
	}
animateObject()
}

function animateObject() {
	if((dX > 0) || (dY > 0)) {
		object.style.left = Math.round(cX) + 'px';
		object.style.top = Math.round(cY) + 'px';
	cX = cX + stepX;
	cY = cY + stepY;
	dX = dX - Math.abs(stepX);
	dY = dY - Math.abs(stepY);

	setTimeout('animateObject()',0);
	}
	else
	{
		object.style.left = fX + 'px';
		object.style.top = fY + 'px';
	}
return;
}

function openWindow(contentURL, windowName, windowWidth, windowHeight){
	widthHeight = 'height=' + windowHeight +
	 'width=' + windowWidth;
	newWindow = window.open(contentURL, windowName, widthHeight);
	newWindow.focus()
}

function closeWindow(){
if(newWindow != null) {
newWindow.close();
newWindow = null;
}
}

function initExpand(objectID, target_width, target_height, closeWhenDone, destUrl, shiftLeft, position, animateSpeed, hideWhenDone, styleToChange, divID){

object = document.getElementById(objectID);

if(typeof divID != 'undefined')
objectDiv = document.getElementById(divID);

fX = target_width;
fY = target_height;

fZ = closeWhenDone;
if(typeof hideWhenDone != 'undefined')
gZ = hideWhenDone;
else
gZ = '';

// test:ok
//alert("gZ: "+gZ);

if(typeof styleToChange != 'undefined')
jZ = styleToChange;
else
jZ = '';

hZ = shiftLeft;
iZ = position;

cX = object.offsetWidth;
cY1 = object.offsetHeight;

dXr = fX-cX;
dYr = fY-cY1;


if(!animateSpeed)
animateSpeed = 8;

dYorig = dYr;
stepX = dXr/animateSpeed;
stepY = dYr/animateSpeed;

dX = Math.abs(dXr);
dY = Math.abs(dYr);

var appName = navigator.appName;
var browserVer = navigator.appVersion;

// test
//alert("browserVer: "+browserVer);

var isEight = browserVer.indexOf('MSIE 8.0');
//var isSeven = browserVer.indexOf('MSIE 7.0');
//var isSix = browserVer.indexOf('MSIE 6.0');
//var isFirefox = browserVer.indexOf('Firefox');

if(jZ == 'visibility')
{
if(appName == 'Netscape' || isEight > 0)
{
currentX = objectDiv.offsetLeft;

// test:fail
//alert("currentX: "+currentX);

}
else
currentX = objectDiv.offsetLeft - objectDiv.offsetParent.offsetLeft;
currentY = objectDiv.offsetTop;
}
else
{
currentX = object.offsetLeft;
currentY = object.offsetTop;
}
finalY = currentY - dYr;
finalX = currentX - dXr/2;

// test:ok
//alert("gZ: "+gZ);

expandObject(hZ,iZ)
}

function expandObject(hZ,iZ) {

	if((dX > 0) && (dY > 0)) {
		object.style.width = Math.round(cX) + 'px';
		object.style.height = Math.round(cY1) + 'px';

if(jZ == 'visibility')
{

// test
objectDiv.style.top = Math.round(currentY) + 'px';
objectDiv.style.left = Math.round(currentX) + 'px';

}


		if(hZ == "Yes")
		{
		object.style.left = currentX + 'px';
		}

		if(iZ == "bottom")
		{
		object.style.top = currentY + 'px';
		}

	cX = cX + stepX;
	cY1 = cY1 + stepY;
	if(jZ == 'visibility')
	//if(gZ)
	currentX = currentX - stepX/2;
	else
	currentX = currentX - stepX;
	currentY = currentY - stepY;
	dX = dX - Math.abs(stepX);
	dY = dY - Math.abs(stepY);

	setTimeout('expandObject(hZ,iZ)',0);
	}
	else {

		object.style.width = fX + 'px';
		object.style.height = fY + 'px';

if(jZ == 'visibility')
//if(gZ)
{
objectDiv.style.top = Math.round(finalY) + 'px';
objectDiv.style.left = Math.round(finalX) + 'px';
}

	if(fZ)
	{
	object = document.getElementById(fZ);
	if(object)
	{
//	if(jZ == 'visibility')
	if(gZ)
	object.style.visibility = 'hidden';
	else
	object.style.display = 'none';
	}
	}
	if(jZ != 'visibility')
	adjustFooter(dYorig);
	}
return;
}

function swapText(objectID, text)
{
object = document.getElementById(objectID);
if(object)
object.innerHTML=text;
}

function getDocHeight()
{
var docHeight;
// IE
if (typeof document.height != 'undefined' && (document.height > 0) && navigator.appName != 'Netscape') {
docHeight = document.height;
}
// Safari: footer too low; 50 to keep site border set sites out of here 
else if (document.body && typeof document.body.scrollHeight != 'undefined' && document.body.scrollHeight > 50  ) {
docHeight = document.body.scrollHeight;
}
// Firefox
else if (document.compatMode && document.compatMode != 'BackCompat') {
docHeight = document.documentElement.scrollHeight;
}
return docHeight;
}

function adjustFooter(dYorig,type)
{
if(dYorig > 0)
var changeHeight = dYorig + 25;
else
var changeHeight = dYorig - 25;
object = document.getElementById("footer");
if(object)
{
if(window.heightsRecorded != 'Yes' || type != 'onDeck')
window.footerHeight = object.offsetTop;
var footerHeight = window.footerHeight + changeHeight;
if(footerHeight > window.adHeight)
object.style.top = footerHeight+"px";
else
object.style.top = window.adHeight+"px";
}

// page bottom links
object = document.getElementById("page_bottom_links");
if(object)
{
if(window.heightsRecorded != 'Yes' || type != 'onDeck')
window.pblHeight = object.offsetTop;
var pblHeight = window.pblHeight + changeHeight;
if(pblHeight > window.adHeight)
object.style.top = pblHeight+"px";
else
object.style.top = window.adHeight+"px";
}

// whole site
object = document.getElementById("whole_site");
if(object)
{
if(window.heightsRecorded != 'Yes' || type != 'onDeck')
window.pageHeight = object.offsetHeight;
var pageHeight = window.pageHeight + changeHeight;
object.style.height = pageHeight+"px";
}

// page
object = document.getElementById("site_border_left");
if(object)
{
object.style.height = pageHeight+"px";
}
object = document.getElementById("site_border_right");
if(object)
{
object.style.height = pageHeight+"px";
}

var siteBottomHeight = pageHeight + Number(window.topMargin); 

object = document.getElementById("site_border_bottom");
if(object)
{
object.style.top = siteBottomHeight+"px";
}

// record that heights recorded on first execution
if(window.heightsRecorded != 'Yes')
window.heightsRecorded = 'Yes';

}

function repositionFooterOpEd(paperCode)
{
docHeight = getDocHeight();

// test
//alert("docHeight at 604: "+docHeight);  // 5, wrong


if(!window.adHeight)
	var adHeight = 0;

// test: error, error,ok
//alert("OK to js 607");

var mainHeight = findHeight("main_content");
object = document.getElementById("page_bottom_links");
if(window.storyDisplay == "on_deck")
{
docHeight = getDocHeight();
if (typeof window.orientation != 'undefined' && window.orientation == 'vertical')
mainHeight = docHeight - window.menuHeight - window.topMargin;
else
mainHeight = docHeight - window.bannerHeight - window.menuHeight - window.topMargin;
}
else
{
if(window.adHeight > mainHeight)
mainHeight = window.adHeight;
}

if(window.linksTopMargin)
mainHeight += window.linksTopMargin;

if(object && mainHeight)
object.style.top = mainHeight+"px";
if(object) object.style.display = 'inline';

// doc height
docHeight = getDocHeight();

// get footer object
object = document.getElementById("footer");

if(!window.footerAdj)
window.footerAdj = 0;

if(!window.safariAdj)
window.safariAdj = 0;

// calculate
if(window.scrollMain == 'Yes' && window.menuOrientation == 'vertical')
var footerHeight = docHeight - window.footerAdj;
else
if(window.menuOrientation == 'vertical_image' || window.menuOrientation == 'vertical')
var footerHeight = docHeight - window.bannerHeight - window.topMargin - window.footerAdj;
//var footerHeight = docHeight - window.bannerHeight - window.topMargin - window.menuHeight - window.footerAdj;
else if (typeof window.orientation != 'undefined' && window.orientation == 'vertical')
var footerHeight = docHeight - window.menuHeight - window.topMargin - window.footerAdj;
else
var footerHeight = docHeight - window.bannerHeight - window.menuHeight - window.topMargin - window.footerAdj;

// safari
if (navigator.appName == 'Netscape')
footerHeight = footerHeight - window.safariAdj;

if(!window.siteWidth)
window.siteWidth = 783;

// set new height
if(object) object.style.top = footerHeight+"px";
if(window.menuOrientation != 'vertical_image' && window.menuOrientation != 'vertical')
if(object) object.style.width = window.siteWidth+"px";
//if(object) object.style.width = 783+"px";
if(object) object.style.display = 'inline';

// doc height
docHeight = getDocHeight();

// last link mask
if(window.lastMask)
{
object = document.getElementById(window.lastMask);
if(object)
{
if(window.storyDisplay == 'on_deck' || window.storeLink == 'Yes')
var linkMaskHeight = docHeight  -  window.bannerHeight - window.menuHeight - window.topMargin - window.adHeight;
else
var linkMaskHeight = docHeight - window.adHeight -  window.bannerHeight - window.menuHeight - window.topMargin ;  
object.style.height = linkMaskHeight+"px";
}
}

// test
//alert("docHeight: "+docHeight);  // 5,wrong; 349 with border off
//alert("window.topMargin: "+window.topMargin);  // 15  border + padding; 5, tech. correct, with border off

// page
var wholeSiteHeight = docHeight - window.topMargin;
object = document.getElementById("whole_site");
if(object)
{
var browserVer = navigator.appVersion;

var isSeven = browserVer.indexOf('MSIE 7.0');
var isSix = browserVer.indexOf('MSIE 6.0');
var isFirefox = browserVer.indexOf('Firefox');

// test:correct
//alert("isSeven: "+isSeven);

if(isSeven > 0 || isSix > 0)
var isSevenOrSix = 1;

// test: -10, wrong
//alert("wholeSiteHeight: "+wholeSiteHeight);


if(top == self || isSevenOrSix != 1  || navigator.appName.indexOf('Netscape') > -1) 
{
object.style.height = wholeSiteHeight+"px";
}

object.style.visibility = "visible";
}

// ad mask too
object = document.getElementById("mask");
if(object)
{
if(window.menuOrientation == 'vertical_image' || window.menuOrientation == 'vertical')
var maskHeight = docHeight + 250;
else
var maskHeight = docHeight - window.bannerHeight;
object.style.height = maskHeight+"px";
}

// main content, try if not vertical
object = document.getElementById("main_content");
if(object && window.menuOrientation != 'vertical_image' &&  window.menuOrientation != 'vertical')
{
var contentHeight = docHeight - window.bannerHeight;
object.style.height = contentHeight+"px";
}


// top
object = document.getElementById("site_border_top");
if(object)
object.style.visibility = "visible";

// sides
var sideHeight = docHeight - 0*Number(window.siteBorderSize) + 2*Number(window.siteBorderPadding) - 1*(window.topMargin); 
object = document.getElementById("site_border_left");
if(object)
{
object.style.height = sideHeight+"px";
object.style.visibility = "visible";
}
object = document.getElementById("site_border_right");
if(object)
{
object.style.height = sideHeight+"px";
object.style.visibility = "visible";
}

// bottom
var siteBottomHeight = docHeight + 0*Number(window.siteBorderSize) + 1*Number(window.siteBorderPadding) - window.topMargin; 
object = document.getElementById("site_border_bottom");
if(object)
{
object.style.top = siteBottomHeight+"px";
object.style.visibility = "visible";
}

// end test
//}

}

function setTextOfTextfield(objName,newText)
{ 
var object = document.getElementById(objName);
if (object)
object.value = newText;
}

function Set_Cookie( name, value, expires, path, domain, secure )
{

// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}


function ajaxFunction(myForm,myField,productid,minQtyType)
{
var xmlHttp;
try
  {
    // Firefox, Opera 8.0+, Safari
     xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
   // Internet Explorer
    try
    {    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    }
  catch (e)
    {    try
      {      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      }
    catch (e)
      {      alert("Your browser does not support AJAX!");      return false;      }    }  } 
      
   xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
	  	if(myField == 'new_product_qty0')
  	 	{
		if(minQtyType == 'select')
		{
		for (var i = 0; i < 51; i++)
		document.qo_form.new_product_qty0.options[i]=new Option(i*(xmlHttp.responseText), i*(xmlHttp.responseText));
      	}
      	document.qo_form.new_product_qty0.value=xmlHttp.responseText;
		Set_Cookie('qoQty0',xmlHttp.responseText, '', '/');
		Set_Cookie('qoMinQty0',xmlHttp.responseText, '', '/');
		}
		else if(myField == 'new_product_qty1')
    	{
		if(minQtyType == 'select')
		{
		for (var i = 0; i < 51; i++)
		document.qo_form.new_product_qty1.options[i]=new Option(i*(xmlHttp.responseText), i*(xmlHttp.responseText));
		}
      	document.qo_form.new_product_qty1.value=xmlHttp.responseText;
		Set_Cookie('qoQty1',xmlHttp.responseText, '', '/');
		Set_Cookie('qoMinQty1',xmlHttp.responseText, '', '/');
		}
		else if(myField == 'new_product_qty2')
      	{
		if(minQtyType == 'select')
		{
		for (var i = 0; i < 51; i++)
		document.qo_form.new_product_qty2.options[i]=new Option(i*(xmlHttp.responseText), i*(xmlHttp.responseText));
		}
      	document.qo_form.new_product_qty2.value=xmlHttp.responseText;
		Set_Cookie('qoQty2',xmlHttp.responseText, '', '/');
		Set_Cookie('qoMinQty2',xmlHttp.responseText, '', '/');
		}
		else if(myField == 'new_product_qty3')
      	{
		if(minQtyType == 'select')
		{
		for (var i = 0; i < 51; i++)
		document.qo_form.new_product_qty3.options[i]=new Option(i*(xmlHttp.responseText), i*(xmlHttp.responseText));
		}
      	document.qo_form.new_product_qty3.value=xmlHttp.responseText;
		Set_Cookie('qoQty3',xmlHttp.responseText, '', '/');
		Set_Cookie('qoMinQty3',xmlHttp.responseText, '', '/');
		}
		else if(myField == 'new_product_qty4')
      	{
		if(minQtyType == 'select')
		{
		for (var i = 0; i < 51; i++)
		document.qo_form.new_product_qty4.options[i]=new Option(i*(xmlHttp.responseText), i*(xmlHttp.responseText));
		}
      	document.qo_form.new_product_qty4.value=xmlHttp.responseText;
		Set_Cookie('qoQty4',xmlHttp.responseText, '', '/');
		Set_Cookie('qoMinQty4',xmlHttp.responseText, '', '/');
		}
		else if(myField == 'new_product_qty5')
      	{
		if(minQtyType == 'select')
		{
		for (var i = 0; i < 51; i++)
		document.qo_form.new_product_qty5.options[i]=new Option(i*(xmlHttp.responseText), i*(xmlHttp.responseText));
		}
      	document.qo_form.new_product_qty5.value=xmlHttp.responseText;
		Set_Cookie('qoQty5',xmlHttp.responseText, '', '/');
		Set_Cookie('qoMinQty5',xmlHttp.responseText, '', '/');
		}
		else if(myField == 'new_product_qty6')
      	{
		if(minQtyType == 'select')
		{
		for (var i = 0; i < 51; i++)
		document.qo_form.new_product_qty6.options[i]=new Option(i*(xmlHttp.responseText), i*(xmlHttp.responseText));
		}
      	document.qo_form.new_product_qty6.value=xmlHttp.responseText;
		Set_Cookie('qoQty6',xmlHttp.responseText, '', '/');
		Set_Cookie('qoMinQty6',xmlHttp.responseText, '', '/');
		}
		else if(myField == 'new_product_qty7')
      	{
		if(minQtyType == 'select')
		{
 		for (var i = 0; i < 51; i++)
		document.qo_form.new_product_qty7.options[i]=new Option(i*(xmlHttp.responseText), i*(xmlHttp.responseText));
		}
	   	document.qo_form.new_product_qty7.value=xmlHttp.responseText;
		Set_Cookie('qoQty7',xmlHttp.responseText, '', '/');
		Set_Cookie('qoMinQty7',xmlHttp.responseText, '', '/');
		}
		else if(myField == 'new_product_qty8')
      	{
		if(minQtyType == 'select')
		{
		for (var i = 0; i < 51; i++)
		document.qo_form.new_product_qty8.options[i]=new Option(i*(xmlHttp.responseText), i*(xmlHttp.responseText));
		}
      	document.qo_form.new_product_qty8.value=xmlHttp.responseText;
		Set_Cookie('qoQty8',xmlHttp.responseText, '', '/');
		Set_Cookie('qoMinQty8',xmlHttp.responseText, '', '/');
		}
		else if(myField == 'new_product_qty9')
      	{
		if(minQtyType == 'select')
		{
		for (var i = 0; i < 51; i++)
		document.qo_form.new_product_qty9.options[i]=new Option(i*(xmlHttp.responseText), i*(xmlHttp.responseText));
		}
      	document.qo_form.new_product_qty9.value=xmlHttp.responseText;
		Set_Cookie('qoQty9',xmlHttp.responseText, '', '/');
		Set_Cookie('qoMinQty9',xmlHttp.responseText, '', '/');
		}
      }
    }
  xmlHttp.open("GET","../subscribe/cart_get_min_qty.php?productid="+productid,true); 
  xmlHttp.send(null);     
}

function ajaxFunction1(myDiv,productid,thisX,thisY,thisW) //
{

// only show xmlHttp if this current id - when mousing quickly over multiple items, only show last
currentProductId = productid;

// old, default offset width
if(typeof thisW == 'undefined' || !thisW)
var thisW = 38;

// try visibility first, so not delayed and countermanding hide from exit during scanning of page
document.getElementById(myDiv).innerHTML='<img src="../images/timer.gif">';
document.getElementById(myDiv).style.left = Math.round(thisX+thisW) + 'px'; //
document.getElementById(myDiv).style.top = Math.round(thisY) + 'px';
document.getElementById(myDiv).style.visibility = 'visible';

var xmlHttp;
try
  {
    // Firefox, Opera 8.0+, Safari
     xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
   // Internet Explorer
    try
    {    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    }
  catch (e)
    {    try
      {      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      }
    catch (e)
      {      alert("Your browser does not support AJAX!");      return false;      }    }  } 
      
   xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4 && currentProductId == productid)
      {
	  document.getElementById(myDiv).innerHTML=xmlHttp.responseText;
      }
    }
  xmlHttp.open("GET","../subscribe/product_details.php?productid="+productid,true); 
  xmlHttp.send(null);     
}

function ajaxFunction2(myDiv,pageid)
{

var xmlHttp;
try
  {
    // Firefox, Opera 8.0+, Safari
     xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
   // Internet Explorer
    try
    {    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    }
  catch (e)
    {    try
      {      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      }
    catch (e)
      {      alert("Your browser does not support AJAX!");      return false;      }    }  } 
      
   xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
	  document.getElementById(myDiv).innerHTML=xmlHttp.responseText;
      }
    }
  xmlHttp.open("GET","../content/story_details.php?pageid="+pageid,true); 
  xmlHttp.send(null);     
}

// customer list
function ajaxFunction3(selectName,selectDiv,categoryId,flagId,onChange)
{

var xmlHttp;
try
  {
    // Firefox, Opera 8.0+, Safari
     xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
   // Internet Explorer
    try
    {    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    }
  catch (e)
    {    try
      {      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      }
    catch (e)
      {      alert("Your browser does not support AJAX!");      return false;      }    }  } 
      
   xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
	  document.getElementById(selectDiv).innerHTML=xmlHttp.responseText;
      }
    }

  xmlHttp.open("GET","../subscribe/customer_list.php?categoryid="+categoryId+"&flagid="+flagId+"&select_name="+selectName+"&onchange="+onChange,true); 

xmlHttp.send(null);     

}

function ajaxFunction4(myDiv,parentid,position,sectionid,text_only,thisX,thisY,thisW) //
{

// only show xmlHttp if this current id - when mousing quickly over multiple items, only show last
currentParentId = parentid;

// try visibility first, so not delayed and countermanding hide from exit during scanning of page
document.getElementById(myDiv).innerHTML='<img src="../images/timer.gif">';
document.getElementById(myDiv).style.left = Math.round(thisX+thisW-1) + 'px'; //
document.getElementById(myDiv).style.top = Math.round(thisY) + 'px';
document.getElementById(myDiv).style.visibility = 'visible';

var xmlHttp;
try
  {
    // Firefox, Opera 8.0+, Safari
     xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
   // Internet Explorer
    try
    {    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    }
  catch (e)
    {    try
      {      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      }
    catch (e)
      {      alert("Your browser does not support AJAX!");      return false;      }    }  } 
      
   xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4 && currentParentId == parentid)
      {
	  document.getElementById(myDiv).innerHTML=xmlHttp.responseText;
      }
    }
  xmlHttp.open("GET","../content/child_pages.php?parentid="+parentid+"&position="+position+"&text_only="+text_only+"&sectionid="+sectionid,true); 
  xmlHttp.send(null);     
}

// customer record update
function ajaxFunction5(customerId,field,data)
{

var xmlHttp;
try
  {
    // Firefox, Opera 8.0+, Safari
     xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
   // Internet Explorer
    try
    {    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    }
  catch (e)
    {    try
      {      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      }
    catch (e)
      {      alert("Your browser does not support AJAX!");      return false;      }    }  } 
      
   xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
//	  document.getElementById(selectDiv).innerHTML=xmlHttp.responseText;
      }
    }

  xmlHttp.open("GET","../subscribe/customer_field_update.php?customerid="+customerId+"&field="+field+"&data="+data,true); 

xmlHttp.send(null);     

}

function ajaxFunction6(myDiv,start,parentDb,fieldName,formName,method) //
{

// visibility first, works above
document.getElementById(myDiv).style.visibility = 'visible';

//if(status == 'startOver' && start.length > 4)
//return true;

// ok
//alert("myDiv: "+myDiv);
//alert("start: "+start);
//alert("parentDb: "+parentDb);
//alert("fieldName: "+fieldName);

var xmlHttp;
try
  {
    // Firefox, Opera 8.0+, Safari
     xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
   // Internet Explorer
    try
    {    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    }
  catch (e)
    {    try
      {      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      }
    catch (e)
      {      alert("Your browser does not support AJAX!");      return false;      }    }  } 
      
   xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4 && (xmlHttp.responseText))
      {

// test:fail,ok
//alert(xmlHttp.responseText);

		
	  document.getElementById(myDiv).innerHTML=xmlHttp.responseText;
      }
    }

// test:ok
//alert("OK to just before get statement");

  xmlHttp.open("GET","../email/find_records.php?start="+start+"&parent_db="+parentDb+"&field_name="+fieldName+"&div_name="+myDiv+"&form_name="+formName+"&method="+method,true); 

// test:ok
//alert("OK to just after get statement");


  xmlHttp.send(null);     
}


function ajaxFunction7(myDiv,linkType,link,linkId) //
{
// try visibility first, so not delayed and countermanding hide from exit during scanning of page
document.getElementById(myDiv).innerHTML='<img src="../images/timer.gif">';
document.getElementById(myDiv).style.visibility = 'visible';

var xmlHttp;
try
  {
    // Firefox, Opera 8.0+, Safari
     xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
   // Internet Explorer
    try
    {    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    }
  catch (e)
    {    try
      {      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      }
    catch (e)
      {      alert("Your browser does not support AJAX!");      return false;      }    }  } 
      
   xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
	  document.getElementById(myDiv).innerHTML=xmlHttp.responseText;
      }
    }
  xmlHttp.open("GET","../content/link_types.php?link_type="+linkType+"&link="+link+"&linkid="+linkId,true); 
  xmlHttp.send(null);     
}

function ajaxFunction8(myDiv,field,data,taskId,view,return_url,showDone,thisPage) //
{
// try visibility first, so not delayed and countermanding hide from exit during scanning of page
document.getElementById(myDiv).innerHTML='<img src="../images/timer.gif">';
document.getElementById(myDiv).style.visibility = 'visible';

var xmlHttp;
try
  {
    // Firefox, Opera 8.0+, Safari
     xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
   // Internet Explorer
    try
    {    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    }
  catch (e)
    {    try
      {      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      }
    catch (e)
      {      alert("Your browser does not support AJAX!");      return false;      }    }  } 
      
   xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
	  document.getElementById(myDiv).innerHTML=xmlHttp.responseText;
      }
    }
if(field)
xmlHttp.open("GET","../notes/task_update.php?field="+field+"&data="+data+"&taskidA="+taskId+"&view="+view+"&return="+return_url+"&show_done="+showDone+"&this_page="+thisPage,true); 
else if(!taskId)
xmlHttp.open("GET","../notes/task_update.php?view="+view+"&return="+return_url+"&show_done="+showDone+"&this_page="+thisPage,true); 
else
xmlHttp.open("GET","../notes/task_update.php?taskid="+taskId+"&view="+view+"&return="+return_url+"&show_done="+showDone+"&this_page="+thisPage,true); 
xmlHttp.send(null);     
}

function ajaxFunction9(myDiv,field,data,noteId,view,return_url,showDate,thisPage,search) //
{
// try visibility first, so not delayed and countermanding hide from exit during scanning of page
document.getElementById(myDiv).innerHTML='<img src="../images/timer.gif">';
document.getElementById(myDiv).style.visibility = 'visible';

var xmlHttp;
try
  {
    // Firefox, Opera 8.0+, Safari
     xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
   // Internet Explorer
    try
    {    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    }
  catch (e)
    {    try
      {      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      }
    catch (e)
      {      alert("Your browser does not support AJAX!");      return false;      }    }  } 
      

   xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)  
      {
	  document.getElementById(myDiv).innerHTML=xmlHttp.responseText;
      }
    }

if(field)
{
// switching to POST for large data strings
var url = "../notes/note_update.php";
var params = "field="+field+"&data="+data+"&noteidA="+noteId+"&view="+view+"&return="+return_url+"&show_date="+showDate+"&this_page="+thisPage;
xmlHttp.open("POST", url, true);

// Send the proper header information along with the request
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(params);
}
else if(!noteId && !search)
xmlHttp.open("GET","../notes/note_update.php?view="+view+"&return="+return_url+"&show_date="+showDate+"&this_page="+thisPage,true); 
else if(!noteId)
xmlHttp.open("GET","../notes/note_update.php?view="+view+"&return="+return_url+"&show_date="+showDate+"&this_page="+thisPage+"&search="+search,true); 
else
xmlHttp.open("GET","../notes/note_update.php?noteid="+noteId+"&view="+view+"&return="+return_url+"&show_date="+showDate+"&this_page="+thisPage,true); 

// don't send get methos unless using one of last three above
if(!field)
xmlHttp.send(null);     

}

function ajaxFunction10(myDiv,productId,qty) //
{
// try visibility first, so not delayed and countermanding hide from exit during scanning of page
document.getElementById(myDiv).innerHTML='<img src="../images/timer.gif">';
document.getElementById(myDiv).style.visibility = 'visible';

var xmlHttp;
try
  {
    // Firefox, Opera 8.0+, Safari
     xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
   // Internet Explorer
    try
    {    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    }
  catch (e)
    {    try
      {      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      }
    catch (e)
      {      alert("Your browser does not support AJAX!");      return false;      }    }  } 
      
   xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
	  document.getElementById(myDiv).innerHTML=xmlHttp.responseText;
      }
    }

xmlHttp.open("GET","../subscribe/cart_item_update.php?productid="+productId+"&qty="+qty,true); 
xmlHttp.send(null);     
}

// updates one field in a database; secure doesn't work
function ajaxFunction11(myDiv,field,data,parentDb,parentId,idField,securePath,paperCode,encrypt) //
{
// try visibility first, so not delayed and countermanding hide from exit during scanning of page
document.getElementById(myDiv).innerHTML='<img src="../images/timer.gif">';
//document.getElementById(myDiv).style.visibility = 'visible';

if(!encrypt)
var encrypt = '';

// test:ok
//alert("securePath: " + securePath);

var xmlHttp;
try
  {
    // Firefox, Opera 8.0+, Safari
     xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
   // Internet Explorer
    try
    {    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    }
  catch (e)
    {    try
      {      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      }
    catch (e)
      {      alert("Your browser does not support AJAX!");      return false;      }    }  } 
      

   xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)  
      {
	  document.getElementById(myDiv).innerHTML=xmlHttp.responseText;
      }
    }

// test:OK, card_type
//alert("field: " + field);


if(field)
{

//securePath = decodeURIComponent(securePath);
// switching to POST for large data strings
var url = securePath + "/admin/field_update.php";
var params = "field="+field+"&data="+data+"&parent_db="+parentDb+"&parentid="+parentId+"&id_field="+idField+"&secure_path="+encodeURIComponent(securePath)+"&paper_code="+paperCode+"&encrypt="+encrypt;

// test:ok
//alert("url: " + url);
//alert("params: " + params);

xmlHttp.open("POST", url, true);

// test:fail
//alert('ok to js1423');

// Send the proper header information along with the request
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(params);
}

/*
else if(!noteId && !search)
xmlHttp.open("GET","../notes/note_update.php?view="+view+"&return="+return_url+"&show_date="+showDate+"&this_page="+thisPage,true); 
else if(!noteId)
xmlHttp.open("GET","../notes/note_update.php?view="+view+"&return="+return_url+"&show_date="+showDate+"&this_page="+thisPage+"&search="+search,true); 
else
xmlHttp.open("GET","../notes/note_update.php?noteid="+noteId+"&view="+view+"&return="+return_url+"&show_date="+showDate+"&this_page="+thisPage,true); 
// don't send get method unless using one of last three above
if(!field)
xmlHttp.send(null);     
*/

}

function stripslashes (str) {
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Ates Goral (http://magnetiq.com)
    // +      fixed by: Mick@el
    // +   improved by: marrtins    // +   bugfixed by: Onno Marsman
    // +   improved by: rezna
    // +   input by: Rick Waldron
    // +   reimplemented by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: stripslashes('Kevin\'s code');    // *     returns 1: "Kevin's code"
    // *     example 2: stripslashes('Kevin\\\'s code');
    // *     returns 2: "Kevin\'s code"
    return (str+'').replace(/\\(.?)/g, function (s, n1) {
        switch (n1) {            case '\\':
                return '\\';
            case '0':
                return '\0';
            case '':                return '';
            default:
                return n1;
        }
});}

function concatObject(obj) {
  str='';
  for(prop in obj)
  {
    str+=prop + " value :"+ obj[prop]+"\n";
  }
  return(str);
}

function addfav(url,label)
   {
   if (document.all)
      {
      window.external.AddFavorite
      (url,label)
      }
   }

function disableEnterKey(e,nextField)
{
     var key;

     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox

     if(key == 13)
{
//document.getElementById(nextField).focus(); // doesn't work in FF or Safari
         return false;
}
     else
          return true;
}

function toggleShowHideJS(element) {
	//function to show or hide elements
	//element variable can be string or object
	if (document.getElementById(element)) {
		element = document.getElementById(element);
	}

		if (element.style.visibility == "hidden") {
			showHideElement(element, 'show');
		} else {
			showHideElement(element, 'hide');
		}
}

dragDrop = {
	keyHTML: '<a href="#" class="keyLink" ></a>',
	keySpeed: 10, // pixels per keypress event
	initialMouseX: undefined,
	initialMouseY: undefined,
	previousMouseX: undefined,
	previousMouseY: undefined,
	startX: undefined,
	startY: undefined,
	dXKeys: undefined,
	dYKeys: undefined,
	draggedObject: undefined,
	initElement: function (element) {

// test:ok, still sring
//alert(element);

	var element_string = element;
		if (typeof element == 'string')
			element = document.getElementById(element);
		element.onmousedown = dragDrop.startDragMouse;
		element.innerHTML += dragDrop.keyHTML;
		var links = element.getElementsByTagName('a');
		var lastLink = links[links.length-1];
		lastLink.relatedElement = element;
		lastLink.onclick = dragDrop.startDragKeys;
	},
	startDragMouse: function (e) {
		dragDrop.startDrag(this);
		var evt = e || window.event;
		dragDrop.initialMouseX = evt.clientX;
		dragDrop.initialMouseY = evt.clientY;

		dragDrop.previousMouseX = 0;
		dragDrop.previousMouseY = 0;

		addEventSimple(document,'mousemove',dragDrop.dragMouse);
		addEventSimple(document,'mouseup',dragDrop.releaseElement);
		return false;
	},
	startDragKeys: function () {
		dragDrop.startDrag(this.relatedElement);
		dragDrop.dXKeys = dragDrop.dYKeys = 0;
		addEventSimple(document,'keydown',dragDrop.dragKeys);
		addEventSimple(document,'keypress',dragDrop.switchKeyEvents);
		this.blur();
		return false;
	},
	startDrag: function (obj) {
		if (dragDrop.draggedObject)
//			dragDrop.releaseElement(element_string);
			dragDrop.releaseElement();
		dragDrop.startX = obj.offsetLeft;
		dragDrop.startY = obj.offsetTop;
		dragDrop.draggedObject = obj;
		obj.className += ' dragged';
	},
	dragMouse: function (e) {
		var evt = e || window.event;
		var dX = evt.clientX - dragDrop.initialMouseX;
		var dY = evt.clientY - dragDrop.initialMouseY;
		
		dragDrop.setPosition(dX,dY);

		var fX = dX - dragDrop.previousMouseX;
		var fY = dY - dragDrop.previousMouseY;

		// record	
		dragDrop.previousMouseX = dX;
		dragDrop.previousMouseY = dY;
		
			// id
			var divId = dragDrop.draggedObject.id;

			// this works
			if(divId.indexOf('tl_') > -1)
			{
			document.edit_form['width_' + divId.substr(3)].value=Math.round(Number(document.edit_form['width_' + divId.substr(3)].value) - fX);
			document.edit_form['height_' + divId.substr(3)].value=Math.round(Number(document.edit_form['height_' + divId.substr(3)].value) - fY);

			document.getElementById(['tr_' + divId.substr(3)]).style.top=dragDrop.draggedObject.offsetTop;
			document.getElementById(['bl_' + divId.substr(3)]).style.left=dragDrop.draggedObject.offsetLeft;
	
			document.getElementById(['dr_' + divId.substr(3)]).style.top=document.getElementById(['dr_' + divId.substr(3)]).offsetTop + Math.round(fY/2);
			document.getElementById(['dr_' + divId.substr(3)]).style.left=document.getElementById(['dr_' + divId.substr(3)]).offsetLeft + Math.round(fX/2);
	
			document.getElementById([divId.substr(3)]).style.left=dragDrop.draggedObject.offsetLeft+4;
			document.getElementById([divId.substr(3)]).style.width=Math.round(Number(document.edit_form['width_' + divId.substr(3)].value));
			document.getElementById([divId.substr(3)]).style.top=dragDrop.draggedObject.offsetTop+4;
			document.getElementById([divId.substr(3)]).style.height=Math.round(Number(document.edit_form['height_' + divId.substr(3)].value));

			document.edit_form['x_' + divId.substr(3)].value=dragDrop.draggedObject.offsetLeft+4;
			document.edit_form['y_' + divId.substr(3)].value=dragDrop.draggedObject.offsetTop+4;
			}
			else if(divId.indexOf('tr_') > -1)
			{
			document.edit_form['width_' + divId.substr(3)].value=Math.round(Number(document.edit_form['width_' + divId.substr(3)].value) + fX);
			document.edit_form['height_' + divId.substr(3)].value=Math.round(Number(document.edit_form['height_' + divId.substr(3)].value) - fY);
			document.getElementById(['tl_' + divId.substr(3)]).style.top=dragDrop.draggedObject.offsetTop;
			document.getElementById(['br_' + divId.substr(3)]).style.left=dragDrop.draggedObject.offsetLeft;

			document.getElementById(['dr_' + divId.substr(3)]).style.top=document.getElementById(['dr_' + divId.substr(3)]).offsetTop + Math.round(fY/2);
			document.getElementById(['dr_' + divId.substr(3)]).style.left=document.getElementById(['dr_' + divId.substr(3)]).offsetLeft + Math.round(fX/2);

			document.getElementById([divId.substr(3)]).style.width=Math.round(Number(document.edit_form['width_' + divId.substr(3)].value));
			document.getElementById([divId.substr(3)]).style.top=dragDrop.draggedObject.offsetTop+4;
			document.getElementById([divId.substr(3)]).style.height=Math.round(Number(document.edit_form['height_' + divId.substr(3)].value));
			document.edit_form['y_' + divId.substr(3)].value=dragDrop.draggedObject.offsetTop+4;
			}
			else if(divId.indexOf('br_') > -1)
			{
			document.edit_form['width_' + divId.substr(3)].value=Math.round(Number(document.edit_form['width_' + divId.substr(3)].value) + fX);
			document.edit_form['height_' + divId.substr(3)].value=Math.round(Number(document.edit_form['height_' + divId.substr(3)].value) + fY );
			document.getElementById(['tr_' + divId.substr(3)]).style.left=dragDrop.draggedObject.offsetLeft;
			document.getElementById(['bl_' + divId.substr(3)]).style.top=dragDrop.draggedObject.offsetTop;

			document.getElementById(['dr_' + divId.substr(3)]).style.top=document.getElementById(['dr_' + divId.substr(3)]).offsetTop + Math.round(fY/2);
			document.getElementById(['dr_' + divId.substr(3)]).style.left=document.getElementById(['dr_' + divId.substr(3)]).offsetLeft + Math.round(fX/2);

			document.getElementById([divId.substr(3)]).style.width=Math.round(Number(document.edit_form['width_' + divId.substr(3)].value));
			document.getElementById([divId.substr(3)]).style.height=Math.round(Number(document.edit_form['height_' + divId.substr(3)].value));
			}
			else if(divId.indexOf('bl_') > -1)
			{
			document.edit_form['width_' + divId.substr(3)].value=Math.round(Number(document.edit_form['width_' + divId.substr(3)].value) - fX);
			document.edit_form['height_' + divId.substr(3)].value=Math.round(Number(document.edit_form['height_' + divId.substr(3)].value) + fY);
			document.getElementById(['tl_' + divId.substr(3)]).style.left=dragDrop.draggedObject.offsetLeft;
			document.getElementById(['br_' + divId.substr(3)]).style.top=dragDrop.draggedObject.offsetTop;

			document.getElementById(['dr_' + divId.substr(3)]).style.top=document.getElementById(['dr_' + divId.substr(3)]).offsetTop + Math.round(fY/2);
			document.getElementById(['dr_' + divId.substr(3)]).style.left=document.getElementById(['dr_' + divId.substr(3)]).offsetLeft + Math.round(fX/2);

			document.getElementById([divId.substr(3)]).style.left=dragDrop.draggedObject.offsetLeft+4;
			document.getElementById([divId.substr(3)]).style.width=Math.round(Number(document.edit_form['width_' + divId.substr(3)].value));
			document.getElementById([divId.substr(3)]).style.height=Math.round(Number(document.edit_form['height_' + divId.substr(3)].value));
			document.edit_form['x_' + divId.substr(3)].value=dragDrop.draggedObject.offsetLeft+4;
			}

			if(divId.indexOf('dr_') > -1)
			{
			var mainDiv = document.getElementById([divId.substr(3)]);
			var mainWidth = mainDiv.offsetWidth;
			var mainHeight = mainDiv.offsetHeight;
			var newLeft = dragDrop.draggedObject.offsetLeft - Math.round(.5*mainWidth) +20;
			var newTop = dragDrop.draggedObject.offsetTop - Math.round(.5*mainHeight) +20;

			mainDiv.style.left=newLeft;
			mainDiv.style.top=newTop;

			document.getElementById(['tl_' + divId.substr(3)]).style.top=newTop-4;
			document.getElementById(['tl_' + divId.substr(3)]).style.left=newLeft-4;

			document.getElementById(['tr_' + divId.substr(3)]).style.top=newTop-4;
			document.getElementById(['tr_' + divId.substr(3)]).style.left=newLeft+mainWidth-4;

			document.getElementById(['br_' + divId.substr(3)]).style.top=newTop+mainHeight-4;
			document.getElementById(['br_' + divId.substr(3)]).style.left=newLeft+mainWidth-4;

			document.getElementById(['bl_' + divId.substr(3)]).style.top=newTop+mainHeight-4;
			document.getElementById(['bl_' + divId.substr(3)]).style.left=newLeft-4;

			document.edit_form['x_' + divId.substr(3)].value=newLeft;
			document.edit_form['y_' + divId.substr(3)].value=newTop;
	
			}

		return false;
	},
	dragKeys: function(e) {
		var evt = e || window.event;
		var key = evt.keyCode;
		switch (key) {
			case 37:	// left
			case 63234:
				dragDrop.dXKeys -= dragDrop.keySpeed;
				break;
			case 38:	// up
			case 63232:
				dragDrop.dYKeys -= dragDrop.keySpeed;
				break;
			case 39:	// right
			case 63235:
				dragDrop.dXKeys += dragDrop.keySpeed;
				break;
			case 40:	// down
			case 63233:
				dragDrop.dYKeys += dragDrop.keySpeed;
				break;
			case 13: 	// enter
			case 27: 	// escape
				dragDrop.releaseElement();
//				dragDrop.releaseElement();
				return false;
			default:
				return true;
		}
		dragDrop.setPosition(dragDrop.dXKeys,dragDrop.dYKeys);
		if (evt.preventDefault)
			evt.preventDefault();
		return false;
	},
	setPosition: function (dx,dy) {
		dragDrop.draggedObject.style.left = dragDrop.startX + dx + 'px';
		dragDrop.draggedObject.style.top = dragDrop.startY + dy + 'px';
	},
	switchKeyEvents: function () {
		// for Opera and Safari 1.3
		removeEventSimple(document,'keydown',dragDrop.dragKeys);
		removeEventSimple(document,'keypress',dragDrop.switchKeyEvents);
		addEventSimple(document,'keypress',dragDrop.dragKeys);
	},
	releaseElement: function(element) {
		removeEventSimple(document,'mousemove',dragDrop.dragMouse);
		removeEventSimple(document,'mouseup',dragDrop.releaseElement);
		removeEventSimple(document,'keypress',dragDrop.dragKeys);
		removeEventSimple(document,'keypress',dragDrop.switchKeyEvents);
		removeEventSimple(document,'keydown',dragDrop.dragKeys);
		dragDrop.draggedObject.className = dragDrop.draggedObject.className.replace(/dragged/,'');

		// original end
		dragDrop.draggedObject = null;

	}
}

function addEventSimple(obj,evt,fn) {
	if (obj.addEventListener)
		obj.addEventListener(evt,fn,false);
	else if (obj.attachEvent)
		obj.attachEvent('on'+evt,fn);
}

function removeEventSimple(obj,evt,fn) {
	if (obj.removeEventListener)
		obj.removeEventListener(evt,fn,false);
	else if (obj.detachEvent)
		obj.detachEvent('on'+evt,fn);
}


function pressedKey(e){
var evtobj=window.event? event : e //distinguish between IE's explicit event object (window.event) and Firefox's implicit.
var unicode=evtobj.charCode? evtobj.charCode : evtobj.keyCode
var actualkey=String.fromCharCode(unicode)
return actualkey;

//if (actualkey=="a")
//document.body.style.fontSize="120%"
//if (actualkey=="z")
//document.body.style.fontSize="100%"
}

function setStartTimeNow(e,field,divName,note,noteId,view,returnURL,showDate,thisPage)
{

// test:ok, note
//alert("field: "+field);

var key;
if(window.event)
key = window.event.keyCode;     //IE
else
key = e.which;     //firefox

// test:ok
//alert("key: "+key);


// F2
if(key == 113)
{
var d = new Date();
var currYear = d.getFullYear();
var currMonth = d.getMonth() + 1;
var currDate = d.getDate();
var currHour = d.getHours();
var currMin = d.getMinutes();
var currSec = d.getSeconds();
time = currYear + "-" +
(currMonth < 10 ? "0" : "") + currMonth + "-" +
(currDate < 10 ? "0" : "") + currDate + " " +
(currHour < 10 ? "0" : "") + currHour + ":" +
(currMin < 10 ? "0" : "") + currMin + ":" +
(currSec < 10 ? "0" : "") + currSec;

// add to field
theInput = document.getElementById(field);

// test:fail, value or innerHTML
//alert("theInput.innerHTML: "+theInput.innerHTML);

if(theInput.value.substr((theInput.innerHTML.length-1),1) != " ")
theInput.value += " ";

theInput.value += time;

// test:fail
//alert("theInput.value: "+theInput.value);

// needs this or crashes Safari
var browserVer = navigator.appVersion;
var isSafari = browserVer.indexOf('Safari');
if(isSafari > 0)
alert("Saving note now with timestamp");

// update field - necessary because browser does not consider insertion of timestamp a change - won't save until something else changed, but also convenient as a force-save(F2)
ajaxFunction9(divName,note,encodeURIComponent(theInput.value),noteId,view,returnURL,showDate,thisPage);
}
}

// work around for IE7 warning
function CloseWindow()
{
window.open('','_self','');
window.close();
}


