<!--

/*
 *
 *  functions for formatting dropdown autocomplete choices
 *  and passing id from array to hidden form field
 */

var hiddenACid = "";

function passID(id)
{
    tj_getElem(hiddenACid).value=id;
    //tj_getElem("knownid").value=id;
}


function formatChoices( sText )
{
	return sText.name.substr( 0, this.sActiveValue.length ).bold().fontcolor( '#000000' ) + sText.name.substr( this.sActiveValue.length )
}


/*
 *
 *  TJ Common Library Functions - across pages
 *
 *  3/29/05 - updates to tj_getELEM in all files
 */

 function object2String(obj) {
    var val, output = "";
    if (obj) {
        output += "{";
        for (var i in obj) {
            val = obj[i];
            switch (typeof val) {
                case ("object"):
                    if (val[0]) {
                        output += i + ":" + array2String(val) + ",";
                    } else {
                        output += i + ":" + object2String(val) + ",";
                    }
                    break;
                case ("string"):
                    output += i + ":'" +(val) + "',";
                    output += i + ":'" +escape(val) + "',"; // causes problems with escape characters
                    break;
                default:
                    output += i + ":" + val + ",";
            }
        }
        output = output.substring(0, output.length-1) + "}";
    }
    return output;
}

function array2String(array) {
    var output = "";
    if (array) {
        output += "[";
        for (var i in array) {
            val = array[i];
            switch (typeof val) {
                case ("object"):
                    if (val[0]) {
                        output += array2String(val) + ",";
                    } else {
                        output += object2String(val) + ",";
                    }
                    break;
                case ("string"):
                    output += "'" + escape(val) + "',";
                    break;
                default:
                    output += val + ",";
            }
        }
        output = output.substring(0, output.length-1) + "]";
    }
    return output;
}


function string2Object(string) {
    if(string == "") return;
    eval("var result = " + string);
    return result;
}

function string2Array(string) {
    	if(string == "") return;
	eval("var result = " + string);
    	return result;
}


/*
 * utility function - returns the index value from a select drop
 * down which matches the string passed in.  Returns -1 if no
 * items in the drop down match the string
 *  select should be passed in as an object
 */
function getIndexMatchingValue(selectObj, item)
{
	for(var i=0; i<selectObj.options.length; i++)
	{
		if(selectObj.options[i].value == item) return i;
	}
	return -1; // no match
}

/*
 *  Returns the index of selected item in a Radio Button Group
 *  Pass in the Radio Button element as an object to the function
 */

function indexSelectedRadio(radioGroup)
{
	for(var i=0; i<radioGroup.length; i++)
	{
		if(radioGroup[i].checked) return i;
	}
	return -1;
}

/*
 *  Returns the value of selected item in a Radio Button Group
 *  Pass in the Radio Button element as an object to the function
 */

function valueSelectedRadio(radioGroup)
{
	var n = indexSelectedRadio(radioGroup);

	if(n != -1)
	{
		return radioGroup[n].value;
	} else {
		return "no item selected";
	}
}


/* cleans out bad escape sequences added for single
 * and double quotes in text input fields - created by c:out
 * 
 * turning off escapeXML in c:out does not solve problem
 * because you still can't asign to a string.
 */

function cleanQuotes(s)
{
	s = s.replace(/&#034;/g, '"');
	s = s.replace(/&#039;/g, "'");
	return s;
}


/* use for err Display instead of alert in timer loops */

function errD(s)
{
	if (tj_getElem("errJSHolder") == null)
	{
		alert("no errJSHolder.  s is: "+s);
		return;
	}
	tj_getElem("errJSHolder").style.visibility = "visible";
	tj_getElem("errJS").innerHTML = s;
	return;
}

/* used to supress scrolling behavior in IE  */

function supressScroll()
{
	var pos = new Array();
	pos = getXYoff();
	myXoff = pos[0];
	myYoff = pos[1];
	setTimeout('window.scrollTo(myXoff, myYoff)',100);
}

// code added to get scrolling offsets

function getXYoff() 
{ 
	var scrOfX = 0, scrOfY = 0; 
	if( typeof( window.pageYOffset ) == 'number' )
	{ 
		//Netscape compliant 
		scrOfY = window.pageYOffset; 
		scrOfX = window.pageXOffset; 
	} else if ( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
	{ 
		//DOM compliant
		 scrOfY = document.body.scrollTop;
		 scrOfX = document.body.scrollLeft; 
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) )
	{ 
		//IE6 standards compliant mode 
		scrOfY = document.documentElement.scrollTop; 
		scrOfX = document.documentElement.scrollLeft; 
	} 
	return [ scrOfX, scrOfY ]; 
}




/* Some General Array Functions */

function hasInArray(theArray, theItem)
{
	for(var i=0; i<theArray.length; i++)
	{
		if(theArray[i] == theItem) return true;
	}
	return false;
}


/* removed item at index position 'theIndex' in array 'theArray' 
    returns a new array with indexes shifted down one above
    the removed element 
*/
function removeItemAtIndex(theIndex, theArray)
{
	var r = new Array();
	var newindex = 0;
	//alert("got to removeItemAtIndex. index is:"+theIndex+" theArray[0]:"+theArray[0].ingredient+" theArray[1]:"+theArray[1].ingredient+" theArray[2]:"+theArray[2].ingredient );

	for(var i=0; i<theArray.length; i++)
	{
		//alert("got in to loop in remove item. newindex is: "+newindex);
		if (i == theIndex)
		{
			// ignore - don't copy to the new array
			// don't increment the new index
			//alert(" index matches: i is: "+i);
		} else {
			r[newindex] = theArray[i];
			newindex++;
		}
	}
	//alert("newArray. r[0]:"+r[0].ingredient+" r[1]:"+r[1].ingredient );	
	return r;
}


/* insert item 'theItem' at index position 'index' in array 'theArray' 
    returns a new array 
*/
function insertIntoArrayAtPosition(theItem, theArray, index)
{
	var r = new Array();
	r = theArray; // copy the array to r
	
	//alert("got to insertIntoArrayAtPostiong. index is: "+index+"  theArray.length is:"+theArray.length);
	
	// copy all items above 'index' to one higher position in array
	// starting from end (top) of array down to index to not destroy any items
	for(var i=theArray.length; i>=index; i--)
	{
		r[i] = r[i-1];
	}
	// next set r[index] to the new item
	r[index] = theItem;
	
	return r;
	
}

//used in prep & mod dialogs - tho general function

function indexInArray(theArray, theValue)
{
	var arLength = theArray.length;
	for(var i=0; i<arLength; i++)
	{
		if (theArray[i] == theValue)  return i;
	}
	return -1;
} 


/*
  **  Remove all occurrences of a token in a string
  **    s  string to be processed
  **    t  token to be removed
  **  returns new string
  */ 
function removeTokenInString(s, t) {

  	i = s.indexOf(t);
  	r = "";
  	if (i == -1) return s;
  	r += s.substring(0,i) + removeTokenInString(s.substring(i + t.length), t);
  	return r;
}



function nthIndexOf(theString, token, n)
{
	var pos = 0;
	var newPos = 0;
	for(var i=0; i<n; i++)
	{
		newPos = theString.indexOf(token, pos+1)
		if(newPos == -1)
		{
			// did not find token in pass = i
			return -1;
		} else {
			//alert("got in loop once pos: "+pos+" newPos: "+newPos);
			pos = newPos;
		}
	}
	//alert("got here returning pos: "+pos);
	return pos;
}



/* returns a comma separated string of the array items from theArray */ 
function makeCSLFromArray(theArray)
{
	var csl = "";
	
	for(var i=0; i<theArray.length; i++)
	{
		csl += theArray[i]+",";
	}
	csl = csl.substring(0,csl.length-1);
	return csl;
}

function makeArrayFromCSL(csl)
{
	var returnArray = new Array();
	if(csl == "") return returnArray;
	
	//remove a trailing comma if it is last character
	if (csl.charAt(csl.length-1) == ",") csl = csl.substring( 0,csl.length-1);
	//alert("got here csl is "+csl+" index of , is "+csl.indexOf(",") );
	
	while(csl.indexOf(",") != -1)
	{
		returnArray[returnArray.length] = csl.substring( 0,csl.indexOf(",") );
		csl = csl.substring( csl.indexOf(",")+1, csl.length );
		//alert("got here csl is "+csl+" index of , is "+csl.indexOf(",")+"reutrnArray.length is "+returnArray.length );
	}
	//pick up the last token - while loop wont catch it
	returnArray[returnArray.length] = csl;
	
	return returnArray;
}

/****************** end general array functions ***************/




/* premium versus non-premium edition & user identity */

var premiumLevel = 1;  // 1= food lovers edition, 2=connaisseurs edition

var userName = "Kamberly";

/* image button initialization - all common buttons */

var imagesNormal = new Object();
var imagesHilite = new Object();

function initCommonHilite()
{
	if (document.images) {
		imagesNormal["add"] = new Image(32,32);
		imagesNormal["add"].src = "images/add-01-XRSH-032.gif";
		imagesNormal["addRecipe"] = new Image(32,32);
		imagesNormal["addRecipe"].src = "images/document-new-01-XRSH-032.gif";
		imagesNormal["begin"] = new Image(32,32);
		imagesNormal["begin"].src = "images/begin-01-XRSH-032.gif";
		imagesNormal["back"] = new Image(32,32);
		imagesNormal["back"].src = "images/back-01-XRSH-032.gif";
		imagesNormal["copy"] = new Image(32,32);
		imagesNormal["copy"].src = "images/copy-01-XRSH-032.gif";
		imagesNormal["next"] = new Image(32,32);
		imagesNormal["next"].src = "images/next-01-XRSH-032.gif";
		imagesNormal["end"] = new Image(32,32);
		imagesNormal["end"].src = "images/end-01-XRSH-032.gif";
		imagesNormal["zoomIn"] = new Image(32,32);
		imagesNormal["zoomIn"].src = "images/zoom-in-01-XRSH-032.gif";
		imagesNormal["zoomOut"] = new Image(32,32);
		imagesNormal["zoomOut"].src = "images/zoom-out-01-XRSH-032.gif";
		imagesNormal["getHelp"] = new Image(32,32);
		imagesNormal["getHelp"].src = "images/help-01-XRSH-032.gif";
		imagesNormal["newfolder"] = new Image(32,32);
		imagesNormal["newfolder"].src = "images/folder-new-01-XRSH-032.gif";
		imagesNormal["mailto"] = new Image(32,32);
		imagesNormal["mailto"].src = "images/mail-new-01-XRSH-032.gif";
		imagesNormal["delete"] = new Image(32,32);
		imagesNormal["delete"].src = "images/trash-01-XRSH-032.gif";
		imagesNormal["edit"] = new Image(32,32);
		imagesNormal["edit"].src = "images/change3-01-XRSH-032.gif";
		imagesNormal["viewall"] = new Image(32,32);
		imagesNormal["viewall"].src = "images/book-open-01-XRSH-032.gif";
		imagesNormal["upsmall"] = new Image(16,16);
		imagesNormal["upsmall"].src = "images/up-01-XRSH-016.gif";
		imagesNormal["downsmall"] = new Image(16,16);
		imagesNormal["downsmall"].src = "images/down-01-XRSH-016.gif";
		imagesNormal["print"] = new Image(32,32);
		imagesNormal["print"].src = "images/printer-01-XRSH-032.gif";
		imagesNormal["switch"] = new Image(32,32);
		imagesNormal["switch"].src = "images/recycle-01-XRSH-032.gif";
		imagesNormal["note"] = new Image(32,32);
		imagesNormal["note"].src = "images/pushpin-01-XRSH-032.gif";


		imagesHilite["add"] = new Image(32,32);
		imagesHilite["add"].src = "images/add-01-XRFL-032.gif";
		imagesHilite["addRecipe"] = new Image(32,32);
		imagesHilite["addRecipe"].src = "images/document-new-01-XRFL-032.gif";
		imagesHilite["begin"] = new Image(32,32);
		imagesHilite["begin"].src = "images/begin-01-XRFL-032.gif";
		imagesHilite["back"] = new Image(32,32);
		imagesHilite["back"].src = "images/back-01-XRFL-032.gif";
		imagesHilite["copy"] = new Image(32,32);
		imagesHilite["copy"].src = "images/copy-01-XRFL-032.gif";
		imagesHilite["next"] = new Image(32,32);
		imagesHilite["next"].src = "images/next-01-XRFL-032.gif";
		imagesHilite["end"] = new Image(32,32);
		imagesHilite["end"].src = "images/end-01-XRFL-032.gif";
		imagesHilite["zoomIn"] = new Image(32,32);
		imagesHilite["zoomIn"].src = "images/zoom-in-01-XRFL-032.gif";
		imagesHilite["zoomOut"] = new Image(32,32);
		imagesHilite["zoomOut"].src = "images/zoom-out-01-XRFL-032.gif";
		imagesHilite["getHelp"] = new Image(32,32);
		imagesHilite["getHelp"].src = "images/help-01-XRFL-032.gif";
		imagesHilite["newfolder"] = new Image(32,32);
		imagesHilite["newfolder"].src = "images/folder-new-01-XRFL-032.gif";
		imagesHilite["mailto"] = new Image(32,32);
		imagesHilite["mailto"].src = "images/mail-new-01-XRFL-032.gif";
		imagesHilite["delete"] = new Image(32,32);
		imagesHilite["delete"].src = "images/trash-01-XRFL-032.gif";
		imagesHilite["edit"] = new Image(32,32);
		imagesHilite["edit"].src = "images/change3-01-XRFL-032.gif";
		imagesHilite["viewall"] = new Image(32,32);
		imagesHilite["viewall"].src = "images/book-open-01-XRFL-032.gif";
		imagesHilite["upsmall"] = new Image(16,16);
		imagesHilite["upsmall"].src = "images/up-01-XRFL-016.gif";
		imagesHilite["downsmall"] = new Image(16,16);
		imagesHilite["downsmall"].src = "images/down-01-XRFL-016.gif";
		imagesHilite["print"] = new Image(32,32);
		imagesHilite["print"].src = "images/printer-01-XRFL-032.gif";
		imagesHilite["switch"] = new Image(32,32);
		imagesHilite["switch"].src = "images/recycle-01-XRFL-032.gif";
		imagesHilite["note"] = new Image(32,32);
		imagesHilite["note"].src = "images/pushpin-01-XRFL-032.gif";

	}
}

function setImage(imgName, type)  
{
	if(document.images) {
		if (type == "hilite") {
			document.images[imgName].src = imagesHilite[imgName].src;
			return true;
		} else if (type == "normal") {
			document.images[imgName].src = imagesNormal[imgName].src;
			return true;
		}
	}
	return false;
}




/* floating layer code */

<!-- Begin
window.onerror = null;
var topMargin = 1;
var slideTime = 1200;
var ns6 = (!document.all && document.getElementById);
var ie4 = (document.all);
var ns4 = (document.layers);
function layerObject(id,left) {
if (ns6) {
this.obj = document.getElementById(id).style;
this.obj.left = left;
return this.obj;
}
else if(ie4) {
this.obj = document.all[id].style;
this.obj.left = left;
return this.obj;
}
else if(ns4) {
this.obj = document.layers[id];
this.obj.left = left;
return this.obj;
   }
}
function layerSetup() {
floatLyr = new layerObject('floatLayer', pageWidth * .5);
window.setInterval("main()", 10)
}
function floatObject() {
if (ns4 || ns6) {
findHt = window.innerHeight;
} else if(ie4) {
findHt = document.body.clientHeight;
   }
} 
function main() {
if (ns4) {
this.currentY = document.layers["floatLayer"].top;
this.scrollTop = window.pageYOffset;
mainTrigger();
}
else if(ns6) {
this.currentY = parseInt(document.getElementById('floatLayer').style.top);
this.scrollTop = scrollY;
mainTrigger();
} else if(ie4) {
this.currentY = floatLayer.style.pixelTop;
this.scrollTop = document.body.scrollTop;
mainTrigger();
   }
}
function mainTrigger() {
var newTargetY = this.scrollTop + this.topMargin;
if ( this.currentY != newTargetY ) {
if ( newTargetY != this.targetY ) {
this.targetY = newTargetY;
floatStart();
}
animator();
   }
}
function floatStart() {
var now = new Date();
this.A = this.targetY - this.currentY;
this.B = Math.PI / ( 2 * this.slideTime );
this.C = now.getTime();
if (Math.abs(this.A) > this.findHt) {
this.D = this.A > 0 ? this.targetY - this.findHt : this.targetY + this.findHt;
this.A = this.A > 0 ? this.findHt : -this.findHt;
}
else {
this.D = this.currentY;
   }
}
function animator() {
var now = new Date();
var newY = this.A * Math.sin( this.B * ( now.getTime() - this.C ) ) + this.D;
newY = Math.round(newY);
if (( this.A > 0 && newY > this.currentY ) || ( this.A < 0 && newY < this.currentY )) {
if ( ie4 )document.all.floatLayer.style.pixelTop = newY;
if ( ns4 )document.layers["floatLayer"].top = newY;
if ( ns6 )document.getElementById('floatLayer').style.top = newY + "px";
   }
}
function startfloat() {
if(ns6||ns4) {
pageWidth = innerWidth;
pageHeight = innerHeight;
layerSetup();
floatObject();
}
else if(ie4) {
pageWidth = document.body.clientWidth;
pageHeight = document.body.clientHeight;
layerSetup();
floatObject();
   }
}
//  End -->

/* end floating layer code */

/* added by MP */

var currMsg = "";
var timer;

function displayMsg(_v, msg)  
{
	currMsg=msg;

	if(_v)
	{
		timer= setTimeout('showMsg()',200);
	} else {
		if(timer)
		{
			clearTimeout(timer);
			timer=null;
		}
	}
}

function showMsg()
{
	msg=currMsg;

	document.all["messageBox"].style.backgroundColor = "#4F8EB6";
	document.all["messageBox"].style.filter = "alpha(opacity=100)";
	document.all["messageBox"].style.padding = "1em";
	document.all["messageBox"].innerHTML = '<span style="font-style:italic; letter-spacing:.05em; font-weight: 700; font-size: 11pt; font-family: comic sans ms; color:#fff">'+msg;
}


function clearMsg()  
{
	clearTimeout(timer);
	timer=null;
	
	document.all["messageBox"].style.backgroundColor = "#e4ecf6";
	document.all["messageBox"].style.padding = "0em";
	document.all["messageBox"].style.filter = "alpha(opacity=50)";
	var clrMsg="<br><br>.&nbsp .&nbsp .&nbsp .&nbsp .&nbsp .";
	document.all["messageBox"].innerHTML = '<span style="font-style:italic; font-size: 10pt; font-family: Verdana; color:#AAAAAA">'+clrMsg;
}


/* added by MP */

function tj_Browser()
{
	d=document;
	this.agt=navigator.userAgent.toLowerCase();
	this.major = parseInt(navigator.appVersion);
	this.dom=(d.getElementById)?1:0;
	this.ns=(d.layers);
	this.ns4up=(this.ns && this.major >=4);
	this.ns6=(this.dom&&navigator.appName=="Netscape");
	this.op=(window.opera? 1:0);
	this.ie=(d.all);
	this.ie4=(d.all&&!this.dom)?1:0;
	this.ie4up=(this.ie && this.major >= 4);
	this.ie5=(d.all&&this.dom);
	this.win=((this.agt.indexOf("win")!=-1) || (this.agt.indexOf("16bit")!=-1));
	this.mac=(this.agt.indexOf("mac")!=-1);
};

var oBw = new tj_Browser();

function tj_getElem(id,d)
{
	var i,x;  if(!d) d=document; 
	if(!(x=d[id])&&d.all) x=d.all[id]; 
	for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][id];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=tj_getElem(id,d.layers[i].document);
	if(!x && document.getElementById) x=document.getElementById(id); 
	return x;
};

function tj_getH(o) { return (oBw.ns)?((o.height)?o.height:o.clip.height):((oBw.op&&typeof o.style.pixelHeight!='undefined')?o.style.pixelHeight:o.offsetHeight); };
function tj_setH(o,h) { if(o.clip) o.clip.height=h; else if(oBw.op && typeof o.style.pixelHeight != 'undefined') o.style.pixelHeight=h; else o.style.height=h; };
function tj_getW(o) { return (oBw.ns)?((o.width)?o.width:o.clip.width):((oBw.op&&typeof o.style.pixelWidth!='undefined')?w=o.style.pixelWidth:o.offsetWidth); };
function tj_setW(o,w) { if(o.clip) o.clip.width=w; else if(oBw.op && typeof o.style.pixelWidth != 'undefined') o.style.pixelWidth=w; else o.style.width=w; };
function tj_getX(o) { return (oBw.ns)?o.left:((o.style.pixelLeft)?o.style.pixelLeft:o.offsetLeft); };
function tj_setX(o,x) { if(oBw.ns) o.left=x; else if(typeof o.style.pixelLeft != 'undefined') o.style.pixelLeft=x; else o.style.left=x; };
function tj_getY(o) { return (oBw.ns)?o.top:((o.style.pixelTop)?o.style.pixelTop:o.offsetTop); };
function tj_setY(o,y) { if(oBw.ns) o.top=y; else if(typeof o.style.pixelTop != 'undefined') o.style.pixelTop=y; else o.style.top=y; };
function tj_getPageX(o) { var x=0; if(oBw.ns) x=o.pageX; else { while(eval(o)) { x+=o.offsetLeft; o=o.offsetParent; } } return x; };
function tj_getPageY(o) { var y=0; if(oBw.ns) y=o.pageY; else { while(eval(o)) { y+=o.offsetTop; o=o.offsetParent; } } return y; };
function tj_getZ(o) { return (oBw.ns)?o.zIndex:o.style.zIndex; };
function tj_moveTo(o,x,y) { tj_setX(o,x);tj_setY(o,y); };
function tj_moveBy(o,x,y) { tj_setX(o,tj_getPageX(o)+x);tj_setY(o,tj_getPageY(o)+y); };
function tj_setZ(o,z) { if(oBw.ns)o.zIndex=z;else o.style.zIndex=z; };
function tj_show(o,disp) { (oBw.ns)? '':(!disp)? o.style.display="inline":o.style.display=disp; (oBw.ns)? o.visibility='show':o.style.visibility='visible'; };
function tj_hide(o,disp) { (oBw.ns)? '':(arguments.length!=2)? o.style.display="none":o.style.display=disp; (oBw.ns)? o.visibility='hide':o.style.visibility='hidden'; };
function tj_setStyle(o,s,v) { if(oBw.ie5||oBw.dom) eval("o.style."+s+" = '" + v +"'"); };
function tj_getStyle(o,s) { if(oBw.ie5||oBw.dom) return eval("o.style."+s); };
function tj_addEvt(o,e,f,c){ if(o.addEventListener)o.addEventListener(e,f,c);else if(o.attachEvent)o.attachEvent("on"+e,f);else eval("o.on"+e+"="+f) };
function tj_writeHTML(o,h) { if(oBw.ns){var doc=o.document;doc.write(h);doc.close();return false;} if(o.innerHTML)o.innerHTML=h; };

function tj_insertHTML(o,h,w)
{
	if(oBw.op) return;
	if(o.insertAdjacentHTML)
	{ 
		o.insertAdjacentHTML(w,h);
		return;
	}
	if(oBw.ns)
	{
		tj_writeHTML(o,h);
		return;
	}
	var r = o.ownerDocument.createRange();
	r.setStartBefore(o);
	var frag = r.createContextualFragment(h);
	tj_insertObj(o,w,frag);
};

function tj_insertObj(o,w,node)
{
	switch(w)
	{
		case 'beforeBegin':
			o.parentNode.insertBefore(node,o);
		break;

		case 'afterBegin':
			o.insertBefore(node,o.firstChild);
		break;

		case 'beforeEnd':
			o.appendChild(node);
		break;

		case 'afterEnd':
			if (o.nextSibling) o.parentNode.insertBefore(node,o.nextSibling);
			else o.parentNode.appendChild(node);
		break;
	}
};

var TJ_SHIFT_KEYCODE = 16;
var TJ_CTRL_KEYCODE = 17;
var TJ_ALT_KEYCODE = 18;
var TJ_SHIFT = "shift";
var TJ_CTRL = "ctrl";
var TJ_ALT = "alt";

tj_keyevt.count=0;

function tj_keyevt(elm)
{
	this.id = "keyevt"+tj_keyevt.count++;
	eval(this.id + "=this");
	this.keys = new Array();
	this.shift=0;
	this.ctrl=0;
	this.alt=0;
	this.addKey = tj_addKey;
	this.keyevent = tj_keyevent;
	this.checkModKeys = tj_checkModKeys;
};

function tj_addKey(cdom,cns4,a,m)
{
	if(oBw.ie||oBw.dom) this.keys[cdom] = [a,m];
	else this.keys[cns4] = [a,m];
};

var TJ_COUNT=0;

function tj_keyevent(evt)
{
	if(oBw.ie||oBw.op) evt=event;
	var k = (oBw.ie||oBw.op||oBw.ns6)? evt.keyCode:evt.which;
	this.checkModKeys(evt,k);
	if(this.keys[k]==null) return false;
	var m = this.keys[k][1];
	if((this.shift && (m.indexOf(TJ_SHIFT) != -1) || !this.shift && (m.indexOf(TJ_SHIFT) == -1)) && (this.ctrl && (m.indexOf(TJ_CTRL) != -1) || !this.ctrl && (m.indexOf(TJ_CTRL) == -1)) && (this.alt && (m.indexOf("alt") != -1) || !this.alt && (m.indexOf("alt") == -1)))
	{
		var a = this.keys[k][0];
		a = eval(a); 
		if(typeof a == "function") a();
	}
};

function tj_checkModKeys(e,k)
{
	if(oBw.dom)
	{ 
		this.shift = e.shiftKey;
		this.ctrl = e.ctrlKey;
		this.alt = e.altKey;
	}
	else
	{
		// for opera
		this.shift = (k==TJ_SHIFT_KEYCODE) ? 1:0;
		this.ctrl = (k==TJ_CTRL_KEYCODE) ? 1:0;
		this.alt = (k==TJ_ALT_KEYCODE) ? 1:0;
	}
};

var oKey = new tj_keyevt();

/* Buttons */

function ClickButton(p_sButtonId, p_sHiddenFieldId, p_oClickHandler)
{
	var oButton = document.getElementById(p_sButtonId);

	if(oButton && oButton.form)
	{
		var oHiddenField = document.getElementById(p_sHiddenFieldId);

		if(oHiddenField)
		{
			oButton.HiddenField = oHiddenField;
			oButton.HiddenField.value = "";
			oButton.onclick = function () {
				if(typeof p_oClickHandler != 'undefined' && p_oClickHandler) p_oClickHandler();
				this.HiddenField.value = this.value;
				this.form.submit();
			};
			
			return oButton;
		}
		else return false;
	}
	else return false;
};

function Menu_Click(p_oEvent)
{
	var oEvent = p_oEvent ? p_oEvent : window.event;
	var oSender = p_oEvent ? oEvent.target : oEvent.srcElement;

	if(p_oEvent) oEvent.stopPropagation();
	else oEvent.cancelBubble = true;
	
	this.Sender = oSender;
	this.Event = oEvent;
	
	if(typeof this.ClickHandler != 'undefined') this.ClickHandler();
};

function Menu_MouseOver(p_oEvent)
{
	var oEvent = p_oEvent ? p_oEvent : window.event;
	var oSender = p_oEvent ? oEvent.target : oEvent.srcElement;
	
	if(oSender.tagName == 'LI') oSender.className = 'hover';
	else if(oSender.tagName == 'A') oSender.parentNode.className = 'hover';
	else return false;
};

function Menu_MouseOut(p_oEvent)
{
	var oEvent = p_oEvent ? p_oEvent : window.event;
	var oSender = p_oEvent ? oEvent.target : oEvent.srcElement;
	
	if(oSender.tagName == 'LI') oSender.className = '';
	else if(oSender.tagName == 'A') oSender.parentNode.className = '';
	else return false;	
};

function Button_Click(p_oEvent)
{
	var oEvent = p_oEvent ? p_oEvent : window.event;
	var oSender = p_oEvent ? oEvent.target : oEvent.srcElement;

	if(p_oEvent) oEvent.stopPropagation();
	else oEvent.cancelBubble = true;

	this.Event = oEvent;
	this.Sender = oSender;

	HideMenu();
	this.Menu.Button = this;
	g_oMenu = this.Menu;

	if(typeof this.ClickHandler != 'undefined') this.ClickHandler();
	else g_oMenu.Show();
	
	document.onclick = Document_Click;
};

function ButtonMenu(p_sMenuId, p_oClickHandler)
{
	var oMenu = document.getElementById(p_sMenuId);

	if(oMenu)
	{
		if(typeof p_oClickHandler != 'undefined') oMenu.ClickHandler = p_oClickHandler;
			
		oMenu.Show = function () { 
			if(document.all) this.style.width = this.offsetWidth+'px';
			this.style.top = tj_getPageY(this.Button)+this.Button.offsetHeight+'px';
			this.style.left = tj_getPageX(this.Button)+'px';
			this.style.visibility = 'visible'; 
		};
			
		oMenu.onclick = Menu_Click;
		
		if(document.all)
		{
			oMenu.onmouseover = Menu_MouseOver;
			oMenu.onmouseout = Menu_MouseOut;
		}

		return oMenu;
	}
	else return false;
};

function Button(p_sButtonId)
{
	var oButton = document.getElementById(p_sButtonId);
	
	if(oButton)
	{
		oButton.onclick = Button_Click;
		return oButton;
	}
	else return false;
};

function MenuButton()
{
	var nArguments = arguments.length;
	
	function __MenuButton_TwoArguments(p_sButtonId, p_sMenuId)
	{
		var oButton = new Button(p_sButtonId);
	
		if(oButton)
		{
			oButton.Menu = new ButtonMenu(p_sMenuId);
			return oButton;
		}
		else return false;	
	};
	
	function __MenuButton_ThreeArguments(p_sButtonId, p_sMenuId, p_oMenuClickHandler)
	{
		var oButton = new Button(p_sButtonId);
			
		if(oButton)
		{
			oButton.Menu = new ButtonMenu(p_sMenuId, p_oMenuClickHandler);
			return oButton;
		}
		else return false;
	};
	
	function __MenuButton_FourArguments(p_sButtonId, p_oButtonClickHandler, p_sMenuId, p_oMenuClickHandler)
	{
		var oButton = new Button(p_sButtonId);
			
		if(oButton)
		{
			oButton.ClickHandler = p_oButtonClickHandler;	
			oButton.Menu = new ButtonMenu(p_sMenuId, p_oMenuClickHandler);
			return oButton;
		}
		else return false;
	};

	if(nArguments == 2) return __MenuButton_TwoArguments(arguments[0],arguments[1]);
	else if(nArguments == 3) return __MenuButton_ThreeArguments(arguments[0],arguments[1],arguments[2]);
	else if(nArguments == 4) return __MenuButton_FourArguments(arguments[0],arguments[1],arguments[2],arguments[3]);
	else return false;
};

/* Mail + PIM Tabs */

function Tab_MouseOver()
{
	if(!this.Selected) this.className = "hover";
	return false;
};

function Tab_MouseOut()
{
	if(!this.Selected) this.className = "";
	return false;	
};

function PIMMenu_Click(p_oEvent)
{
	var oEvent = p_oEvent ? p_oEvent : window.event;
	if(p_oEvent) oEvent.stopPropagation();
	else oEvent.cancelBubble = true;
	if(oEvent.target.parentNode.tagName == "A") window.location = oEvent.target.parentNode.href;
};

function Arrow_Click(p_oEvent)
{
	document.Selects = document.getElementsByTagName('select');

	if(document.Selects[0])
	{
		var nSelects = document.Selects.length-1;
		for(var i=nSelects;i>=0;i--) document.Selects[i].style.visibility = 'hidden';
	}
	
	var oEvent = p_oEvent ? p_oEvent : window.event;
	
	if(p_oEvent) oEvent.stopPropagation();
	else oEvent.cancelBubble = true;
	
	HideMenu();
	
	var oTab = this.parentNode.parentNode;
	var nTop = (oTab.offsetTop+oTab.parentNode.offsetHeight);
	var sTop = ((oTab.Selected) ? (nTop+2) : (nTop-1)) + "px";

	g_oMenu = document.getElementById(this.href.split('#')[1]);
	g_oMenu.style.top = sTop;
	g_oMenu.style.left = oTab.offsetLeft+"px";

	g_oMenu.onclick = PIMMenu_Click;
	g_oMenu.style.visibility = "visible";

	document.onclick = Document_Click;	

	return false;
};

function Tabs_Init()
{
	var oMailTab = document.getElementById('mailtab');
	var oAddressBookTab = document.getElementById('addressbooktab');
	var oCalendarTab = document.getElementById('calendartab');
	var oNotepadTab = document.getElementById('notepadtab');		
	
	if(oMailTab)
	{
		oMailTab.getElementsByTagName("a")[1].onclick = Arrow_Click;
		oMailTab.onmouseover = Tab_MouseOver;
		oMailTab.onmouseout = Tab_MouseOut;
		oMailTab.Selected = (oMailTab.className == 'selected' || oMailTab.className == 'first selected') ? true : false;
	}

	if(oAddressBookTab)
	{
		oAddressBookTab.getElementsByTagName("a")[1].onclick = Arrow_Click;
		oAddressBookTab.onmouseover = Tab_MouseOver;
		oAddressBookTab.onmouseout = Tab_MouseOut;
		oAddressBookTab.Selected = (oAddressBookTab.className == 'selected' || oAddressBookTab.className == 'first selected') ? true : false;
	}

	if(oCalendarTab)
	{
		oCalendarTab.getElementsByTagName("a")[1].onclick = Arrow_Click;
		oCalendarTab.onmouseover = Tab_MouseOver;
		oCalendarTab.onmouseout = Tab_MouseOut;
		oCalendarTab.Selected = (oCalendarTab.className == 'selected' || oCalendarTab.className == 'first selected') ? true : false;
	}

	if(oNotepadTab)
	{
		oNotepadTab.getElementsByTagName("a")[1].onclick = Arrow_Click;
		oNotepadTab.onmouseover = Tab_MouseOver;
		oNotepadTab.onmouseout = Tab_MouseOut;
		oNotepadTab.Selected = (oNotepadTab.className == 'selected' || oNotepadTab.className == 'first selected') ? true : false;
	}

	return false;
};

function HideMenu()
{
	if(typeof g_oMenu != 'undefined' && g_oMenu)
	{
		g_oMenu.style.visibility = 'hidden';
		g_oMenu = null;
		document.onclick = null;
	}
	else return;
};

function Document_Click()
{
	if(document.Selects)
	{
		var nSelects = document.Selects.length-1;
		for(var i=nSelects;i>=0;i--) document.Selects[i].style.visibility = 'visible';
	}

	HideMenu();
};

/* Left navigation */

function LeftNav_Click(p_oEvent)
{
	var oEvent = p_oEvent ? p_oEvent : window.event;
	var oSender = p_oEvent ? oEvent.target : oEvent.srcElement;
	if(oSender.tagName == 'LI' && oSender.getElementsByTagName('a')[0]) document.location = oSender.getElementsByTagName('a')[0].href;	
};

function LeftNav_MouseOver()
{
	var oSender = window.event.srcElement;
	var oLI;
	
	if(oSender.tagName == "LI") oLI = oSender;
	else if(oSender.parentNode.tagName == "LI") oLI = oSender.parentNode;
	else if(oSender.parentNode.parentNode.tagName == "LI") oLI = oSender.parentNode.parentNode;
	else return;

	if(oLI.className != 'selected') 
	{
		oLI.previousClassName = oLI.className;
		oLI.className = (oLI.previousClassName.length > 0) ? oLI.previousClassName+' hover' : 'hover';
	}
	else{ if(oLI.getElementsByTagName('a')[0]) oLI.getElementsByTagName('a')[0].style.textDecoration ='underline'; }
};

function LeftNav_MouseOut()
{
	var oSender = window.event.srcElement;
	var oLI;

	if(oSender.tagName == "LI") oLI = oSender;
	else if(oSender.parentNode.tagName == "LI") oLI = oSender.parentNode;
	else if(oSender.parentNode.parentNode.tagName == "LI") oLI = oSender.parentNode.parentNode;
	else return;
		
	if(oLI.className != 'selected')
	{
		var bPreviousClassName = ((typeof oLI.previousClassName != 'undefined') && (oLI.previousClassName.length > 0)) ? true : false;
		var sClassName = (bPreviousClassName) ? oLI.previousClassName+' hover':'hover';
		if(oLI.className == sClassName) oLI.className = (bPreviousClassName) ? oLI.previousClassName:'';
	}
	else{ if(oLI.getElementsByTagName('a')[0]) oLI.getElementsByTagName('a')[0].style.textDecoration ='none'; }
};

function LeftNav(p_sNavId)
{
	var oLeftNav = document.getElementById(p_sNavId);
	if(oLeftNav)
	{
	    var aULs = oLeftNav.getElementsByTagName('ul');

		if(aULs[0])
		{
			aULs[0].onclick = LeftNav_Click;
			if(document.all) aULs[0].onmouseover = LeftNav_MouseOver;
			if(document.all) aULs[0].onmouseout = LeftNav_MouseOut;
		}
		else return;

		if(aULs[1])
		{
			aULs[1].onclick = LeftNav_Click;
			if(document.all) aULs[1].onmouseover = LeftNav_MouseOver;
			if(document.all) aULs[1].onmouseout = LeftNav_MouseOut;
		}
	}
	else return false;
};

function DestinationFolder_Click()
{
	var oSender = this.Sender;
	var oLI = false;

	if(!oSender.tagName) oLI = oSender.parentNode;
	else if(oSender.tagName == 'LI') oLI = oSender;
	else if(oSender.parentNode.tagName == 'LI') oLI = oSender.parentNode;

	if(oLI)
	{
		var sFolderName = oLI.innerHTML;
		var oForm = this.Button.form;
		var bNewFolder = parseInt(oLI.value) == 0 ? true : false;

		if(bNewFolder)
		{
			var sNewFolderName = window.prompt(oForm.newfoldermessage.value,'');
			
			if(sNewFolderName) sNewFolderName = sNewFolderName;
			else return false;

			if(sNewFolderName != null && sNewFolderName != 'null' && sNewFolderName.length != 0)
			{
				oForm.NewFol.value = sNewFolderName;
				oForm.destBox.value = '@NEW';
				oForm.MOV.value = '1';
				oForm.submit();
			}
			else return false;
		}
		else
		{
			oForm.destBox.value = sFolderName;
			oForm.MOV.value = '1';
			oForm.submit();
		}
	}
	else return false;
};

function Move_Click()
{
	var y = this.offsetTop + this.offsetHeight;

	if(!this.Configured)
	{
		var bMaxWidthExceeded = g_oMenu.offsetWidth > 150 ? true : false;
		var bMaxHeightExceeded = g_oMenu.offsetHeight > 200 ? true : false;
	
		if(bMaxWidthExceeded && !bMaxHeightExceeded)
		{
			g_oMenu.style.height = g_oMenu.offsetHeight+20+"px";
			g_oMenu.className += ' overflowX';
		}
		else if(bMaxHeightExceeded && !bMaxWidthExceeded)
		{
			g_oMenu.style.width = g_oMenu.offsetWidth+20+"px";
			g_oMenu.className += ' overflowY';
		}
		else if(bMaxWidthExceeded && bMaxHeightExceeded) g_oMenu.className += ' overflow';
		else g_oMenu.style.width = g_oMenu.offsetWidth+"px";

		this.Configured = true;
	}

	window.status = g_oMenu.className;
	
	g_oMenu.style.top = y+'px';
	g_oMenu.style.left = 'auto';
	g_oMenu.style.right = '10px';
	
	g_oMenu.style.visibility = 'visible';
	document.onclick = Document_Click;
};

function PersonalFoldersDisplayToggle_Click()
{
	var sDoneURL = (g_oDoneURL) ? g_sDoneURL : document.URL;
	window.open("/"+g_sYMURI+"/Welcome?pers=1&.done=" + escape(sDoneURL) + "&"+g_sURLExtras,"_top");
};

function AddFolderControl_Click()
{
	var nn = window.prompt(g_sNewFolderMessage,'');

	if(nn != null && nn != 'null' && nn != '')
	{
		var nn_escaped = '';
		var nn_len = nn.length;

		for(i=0;i<nn_len;i++)
		{
			var nn_asc = nn.charCodeAt(i);
			if(nn_asc>128) nn_escaped += nn.charAt(i);
			else nn_escaped += escape(nn.charAt(i));
		}
	
		var sURL = '/'+g_sYMURI+'/Folders?ADD=1&Name=' + nn_escaped + '&.crumb='+g_sFoldersCrumb+'&.done=' + g_sAddFolderDoneURL + '&' + g_sURLExtras;
		window.open(sURL,'_top');
	}
};

function LHCol_Init()
{
	g_oAddFolderDoneURL = document.getElementById('addfolderdoneurl');
	g_sAddFolderDoneURL = (g_oAddFolderDoneURL) ? g_oAddFolderDoneURL.value : document.URL;

	g_oDoneURL = document.getElementById('doneurl');
	if(g_oDoneURL) g_sDoneURL = g_oDoneURL.value;

	g_oYMURI = document.getElementById('ymuri');
	if(g_oYMURI) g_sYMURI = g_oYMURI.value;
	
	g_oURLExtras = document.getElementById('urlextras');
	if(g_oURLExtras) g_sURLExtras = g_oURLExtras.value;

	g_oNewFolderMessage = document.getElementById('newfoldermessage');
	if(g_oNewFolderMessage) g_sNewFolderMessage = g_oNewFolderMessage.value;
	
	g_oFoldersCrumb = document.getElementById('folderscrumb');
	if(g_oFoldersCrumb) g_sFoldersCrumb = g_oFoldersCrumb.value;

	var oPersonalFoldersDisplayToggle = document.getElementById('personalfoldersdisplaytoggle');
	if(oPersonalFoldersDisplayToggle)
	{
		oPersonalFoldersDisplayToggle.onclick = PersonalFoldersDisplayToggle_Click;
		oPersonalFoldersDisplayToggle.onmouseover = function () { this.className = 'last hover'; };
		oPersonalFoldersDisplayToggle.onmouseout = function () { this.className = ''; };	
	}
	
	var oAddFolderControl = document.getElementById('addfoldercontrol');
	
	if(oAddFolderControl)
	{
		oAddFolderControl.onclick = AddFolderControl_Click;
		oAddFolderControl.onmouseover = function () { this.className = 'hover'; };
		oAddFolderControl.onmouseout = function () { this.className = ''; };
	}
};

//-->