/* 
    Copyright Notice ========================================================

    This file contains proprietary information of Alpine Internet Solutions. 
    Copying or reproduction without prior written approval is prohibited. 

    Copyright (c) 2000-2005 =================================================

    Purpose: Javascript support functions

    $Id: functions.js,v 2.3 2005/03/24 18:39:28 bcash Exp $
    $Author: bcash $
    $Revision: 2.3 $
    $Date: 2005/03/24 18:39:28 $
 
*/

var lastMouseX;
var lastMouseY;
var curPopupWindow = null;
var helpWindow = null;


// js Browser Detection
isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
NS4 = (document.layers) ? true : false;
IEmac = ((document.all)&&(isMac)) ? true : false;
IE4plus = (document.all) ? true : false;
IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
ver4 = (NS4 || IE4plus) ? true : false;
NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;


function confirmLink( theLink, promptText ) {

//    var is_confirmed;

//    is_confirmed = confirm( promptText );

//    if ( is_confirmed ) {

     // Remove .docs 
//     var mylink = theLink.href;
//        link = mylink.replace( //.docs/, '');
//        theLink.href = link + "&confirmed=Yes";
//    }

    return is_confirmed;
} 

function setLastMousePosition(e) {
	if (navigator.appName.indexOf("Microsoft") != -1) e = window.event;
	lastMouseX = e.screenX;
	lastMouseY = e.screenY;
}

function openClickout(url) {
		// Taken out due to inconsistent escape results between java and javascript
        //window.open('/sales/linkout.jsp?url='+escape(url), "_blank", 'width=640,height=480,dependent=no,resizable=yes,toolbar=yes,status=yes,directories=yes,menubar=yes,scrollbars=1', false);
	window.open(url, "_blank", 'width=640,height=480,dependent=no,resizable=yes,toolbar=yes,status=yes,directories=yes,menubar=yes,scrollbars=1', false);
}

function alpineRedir( formName, aobj, url ) {

	var IdElement = eval( "document." + formName + "['" + aobj + "']" );

	if ( IdElement.type == "select-one" ) {
	
		var itemIndex = IdElement.selectedIndex;
		if ( itemIndex != 0 ) {
		
			var rid = IdElement.options[IdElement.selectedIndex].value;
			
			var pos = url.indexOf('[RID]');
			var nurl = url.substr(0,pos) + rid + url.substring(pos+5);
			// alert( "New URL: " + nurl + "." );
			
			// alert( "Field: " + IdElement.name + " Type: " + IdElement.type + " Index: " + IdElement.selectedIndex + " Value: " +  IdElement.options[IdElement.selectedIndex].value  + "." );
			if ( window.confirm('Any unsaved changes will be lost.  Are you sure?') ) {
			
				if (document.images) {
					top.location.replace(nurl);
				} else {
					top.location.href = nurl;
				}
			} else {
				return;
			}
		} else {
			alert( "Option not selected.  Please select an option from the list." );
			return;
		}
		
	} else if ( IdElement.type == "hidden" ) {

			var rid = IdElement.value;
			
    		if ( rid != 0 ) {
    			var pos = url.indexOf('[RID]');
    			var nurl = url.substr(0,pos) + rid + url.substring(pos+5);
    			// alert( "New URL: " + nurl + "." );
			
    			// alert( "Field: " + IdElement.name + " Type: " + IdElement.type + " Index: " + IdElement.selectedIndex + " Value: " +  IdElement.options[IdElement.selectedIndex].value  + "." );
    			if ( window.confirm('Any unsaved changes will be lost.  Are you sure?') ) {
    			
    				if (document.images) {
    					top.location.replace(nurl);
    				} else {
    					top.location.href = nurl;
    				}
    			} else {
    				return;
                }
            } else {
    			alert( "Nothing selected.  Please select an option from the list." );
    			return;
            }
    }
	
}

function placeFocus() {
	if (document.forms.length > 0) {
		var field = document.forms[0];
		for (i = 0; i < field.length; i++) {
			if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") ) {
				document.forms[0].elements[i].focus();
				break;
			}
		}
	}
}

// || (field.elements[i].type.toString().charAt(0) == "s")

function openAlpineConsoleModal(url, pWidth, pHeight ) {

   closePopup();
	if (snapToLastMousePosition) {
		if (lastMouseX - pWidth < 0) {
			lastMouseX = pWidth;
		}
		if (lastMouseY + pHeight > screen.height) {
			lastMouseY -= (lastMouseY + pHeight + 50) - screen.height;
		}
        lastMouseX -= ( pWidth - 100 );
        lastMouseY += 10;
		features +=	"screenX=" + lastMouseX + ",left=" + lastMouseX + "screenY=" + lastMouseY + ",top=" + lastMouseY;
	}
	curPopupWindow = modelessDialogShow(url, pWidth, pHeight);

}




function openPopup(url, name, pWidth, pHeight, features, snapToLastMousePosition) {

   closePopup();
	if (snapToLastMousePosition) {
		if (lastMouseX - pWidth < 0) {
			lastMouseX = pWidth;
		}
		if (lastMouseY + pHeight > screen.height) {
			lastMouseY -= (lastMouseY + pHeight + 50) - screen.height;
		}
        lastMouseX -= ( pWidth - 100 );
        lastMouseY += 10;
		features +=	"screenX=" + lastMouseX + ",left=" + lastMouseX + "screenY=" + lastMouseY + ",top=" + lastMouseY;
	}
	curPopupWindow = window.open(url, name, features, false);

}

var win=null;
function openDialog(page,name,w,h,pos,infocus){
	if(pos=="center"){dleft=(screen.width)?(screen.width-w)/2:100;dtop=(screen.height)?(screen.height-h)/2:100;}
	else if((pos!='center') || pos==null){dleft=0;dtop=20}
	settings="width=" + w + ",height=" + h + ",top=" + dtop + ",left=" + dleft + ",scrollbars=no,location=no,directories=no,status=yes,menubar=no,toolbar=no,resizable=no";
	win=window.open(page,name,settings);
	win.focus();
}


function closePopup() {
	if (curPopupWindow != null) {
	   
		if (!curPopupWindow.closed) {
			curPopupWindow.close();
		}
		curPopupWindow = null;
	}
}

function openLookup(baseURL,modified,searchParam) {
	if (modified == '1') baseURL = baseURL + searchParam;
	openPopup(baseURL, "lookup", 350, 300, "width=350,height=300,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollable=no", true);
}



function pickCalendar(form,field,year,month,day) {
	eval("document."+form+".form_month_"+field+".options["+month+"].selected=true");
	eval("document."+form+".form_day_"+field+".options["+day+"].selected=true");
	eval("document."+form+".form_year_"+field+".options["+year+"].selected=true");
    closePopup();
	return false;
}

function openCalendar(url) {
	openPopup(url, "Calendar", 200, 125, "width=200,height=125,dependent=yes,resizable=yes,toolbar=no,status=no,directories=no,menubar=no", true);
}

function openComboBox(url) {
	openPopup(replaceChar(url, ' ', '%'), "Select", 750, 475, "width=750,height=475,dependent=yes,resizable=yes,toolbar=no,status=yes,directories=no,menubar=no,scrollbars=1", true);
}

function replaceChar(s, oldchar, newchar) {
	var retval = '';
	for (i = 0; i < s.length; i++) {
		if (s.charAt(i) == ' ') {
			retval = retval + '%';
		} else {
			retval = retval + s.charAt(i);
		}
	}	
	return retval;
}

function openHelp(url) {
	url = url.replace("#", "%23");
	var browserName = navigator.appName;
	if (helpWindow != null && browserName != "Netscape") { helpWindow.close(); }
	var w = window.open(url, "Help", "width=500,height=400,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,screenX=" + window.screenX + ",left=" + window.screenX + "screenY=" + window.screenY + ",top=" + window.screenY, true);
    	w.focus();
	helpWindow = w;
}

function doPrint() {
	alert("This dialog will be replaced by a new browser window containing a printable version" +
		  " of the current page. The user can then select print from the browsers file menu to"+
		  " print the page. Alternatively, this could be an automatically generated Acrobat file.");
}

function doExport() {
	alert("This dialog will be replaced by a File-Save As dialog. Clicking on save in this dialog will save the contents of the current page to a file (in .csv format).");
}

function listProperties(obj) {
	var names = "";
	for (var i in obj) names += i + ", ";
	alert(names);
}


function insertTS(field,datetime,alias) {
	field.value = "---------------------------------n"+ alias + " " +datetime + "nnn" + field.value;
}

function setFocus() {
    var sidebarSearch;
	// search for a tabIndexed field to focus on
    for(var firstIndex=1; firstIndex < 5; firstIndex ++ ){
	    var nextIndex = firstIndex;
        for (var frm = 0; frm < document.forms.length; frm++) {
            for (var fld = 0; fld < document.forms[frm].elements.length; fld++) {
                var elt = document.forms[frm].elements[fld];
			    if ( elt.tabIndex != nextIndex ) continue;
                if ((elt.type == "text" || elt.type == "textarea" || elt.type == "password")
                   && elt.name != "sbstr" &&  elt.name.indexOf("owner") != 0) {
				    elt.focus();
	                if (elt.type == "text") {
	                    elt.select();
	                }
	                return true;
			    } else {
				    nextIndex++;
				    fld = 0;
			    }
		    }
	    }
    }

	// failed to find a tabIndexed field, try to find the field based on it's natural position.
    for (var frm = 0; frm < document.forms.length; frm++) {
        for (var fld = 0; fld < document.forms[frm].elements.length; fld++) {
            var elt = document.forms[frm].elements[fld];
            // skip buttons, radio, or check-boxes
            // to skip "select" types, remove from if statement
            if (elt.type == "text" || elt.type == "textarea" || elt.type == "password") {
                if (elt.name == "sbstr" && document.forms[frm].name == "sbsearch") { 
                    sidebarSearch = elt; 
                } else if (elt.name.indexOf("owner") != 0) {
                    elt.focus();
                    // select text in text field or textarea
                    if (elt.type == "text") {
                        elt.select();
                    }
                    return true;
                }
            }
        }
    }

    if (sidebarSearch != null) {
       sidebarSearch.focus();
    }
    return true;
}

function setNamedFocus(element_name) {
    for (var frm = 0; frm < document.forms.length; frm++) {
        for (var fld = 0; fld < document.forms[frm].elements.length; fld++) {
            var elt = document.forms[frm].elements[fld];
            if (elt.name == element_name) {
                elt.focus();
                if (elt.type == "text") {
                    elt.select();
                }
                return true;
            }
        }
    }
    return true;
}

// removes the leading and trailing spaces from a string, 
// similar to the java.lang.String.trim() function
// added by lturetsky, taken from http://www.voy.com/1888/58.html
function trim(st) {
	st = this != window? this : st;
	return st.replace(/^\s+/g, '').replace(/\s+$/g, '');
}


function formatPhone (field) {
	field.value = trim(field.value);

    var ov = field.value;
    var v = "";
    var x = -1;

	// is this phone number 'escaped' by a leading plus?
	if (0 < ov.length && '+' != ov.charAt(0)) {	// format it
	    // count number of digits
	    var n = 0;
		if ('1' == ov.charAt(0)) {	// skip it
			ov = ov.substring(1, ov.length);
		}

	    for (i = 0; i < ov.length; i++) {
	        var ch = ov.charAt(i);

	        // build up formatted number
	        if (ch >= '0' && ch <= '9') {
	            if (n == 0) v += "(";
	            else if (n == 3) v += ") ";
	            else if (n == 6) v += "-";
	            v += ch;
	            n++;
	        }
	        // check for extension type section; 
	        // are spaces, dots, dashes and parentheses the only valid non-digits in a phone number?
	        if (! (ch >= '0' && ch <= '9') && ch != ' ' && ch != '-' && ch != '.' && ch != '(' && ch != ')') {
	            x = i;
	            break;
	        }
	    }
	    // add the extension
	    if (x >= 0) v += " " + ov.substring(x, ov.length);

	    // if we recognize the number, then format it
	    if (n == 10 && v.length <= 40) field.value = v;
	}
    return true;
}

function dc () {
    return window.confirm('Are you sure?');
}

function clearcols () {
    for (var frm = 0; frm < document.forms.length; frm++) {
        for (var fld = 0; fld < document.forms[frm].elements.length; fld++) {
            var elt = document.forms[frm].elements[fld];
            if (elt.name == "c" || elt.name.substring(0,2) == "c_") {
                elt.checked = false;
            }
        }
    }
}

function setcols () {
    for (var frm = 0; frm < document.forms.length; frm++) {
        for (var fld = 0; fld < document.forms[frm].elements.length; fld++) {
            var elt = document.forms[frm].elements[fld];
            if (elt.name == "c" || elt.name.substring(0,2) == "c_") {
                elt.checked = true;
            }
        }
    }
}

function setUsername(uname, fname, lname, suffix) {
	if (uname.value.length == 0) {
		uname.value = 
					fname.value.substring(0,1).toLowerCase() 
					+ lname.value.toLowerCase()
					+ "@"
					+ suffix.value;
	}
}
function setAlias(alias, fname, lname) {
	if (alias.value.length == 0) {
		alias.value = fname.value.substring(0,1).toLowerCase() +
					  lname.value.substring(0,4).toLowerCase();
	}
}

// POPUP WINDOW NUMBER 1 
function popWin(url) {
  	closePopup();
  	curPopupWindow = window.open(url,"win","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=550,height=300",false);
}
function popWin2(url) {
   win = window.open(url,"win","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=720,height=500",false);
   //self.name = "tutWindow";
}
function adminWin(url) {
   win = window.open(url,"win","toolbar=1,location=1,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=800,height=600",false);
}

// Changed name of window for printWin so that Printable views do not disappear
// Newname is popWin, Oldname(changed) was curPopupWindow
function printWin(url) {
  popWin = window.open(url,"win","dependent=no,toolbar=1,directories=0,location=0,status=1,menubar=1,scrollbars=1,resizable=1,width=705,height=400",false);
  popWin.focus();
}

function moveSelectElement2(sourceSelect, targetSelect, sourceLabel, targetLabel) {
	moveSelectElement3(sourceSelect, targetSelect, sourceLabel, targetLabel, false);
}


function moveSelectElement3(sourceSelect, targetSelect, sourceLabel, targetLabel, keepTarget) {
	if (sourceSelect.selectedIndex > -1) {
		for (i=0; i < sourceSelect.length; ++i) {  
			var selectedOption = sourceSelect.options[i];
			if (selectedOption.selected) {
				if (selectedOption.text != sourceLabel) {
					var newOption = new Option(selectedOption.text, selectedOption.value);
					if (targetSelect.options.length > 0 && targetSelect.options[0].text == targetLabel) {
						targetSelect.options[0] = newOption;
					} else {
						targetSelect.options[targetSelect.options.length] = newOption;
					}
				} else {
					sourceSelect.selectedIndex = -1;
				}
			}
		}
		if(!keepTarget)
		{	removeSelectElement3(sourceSelect, sourceLabel);
		}
	}
}


function removeSelectElement3(sourceSelect, sourceLabel)
{	if (sourceSelect.selectedIndex > -1)
	{	for (i=sourceSelect.length-1; i > -1; i--) 
		{	if (sourceSelect.options[i].selected) sourceSelect.options[i] = null;
		}
		if (sourceSelect.length == 0) 
		{	var placeHolder = new Option(sourceLabel, sourceLabel);
			sourceSelect.options[0] = placeHolder;
		}
	}
}


function moveUp(sourceSelect)
{	var sel_id;
	sel_id = sourceSelect.selectedIndex;
	if (sourceSelect.length > 1 && sel_id > 0) //got to have at least 2 items and not the first one is selected
	{	var prevOption = sourceSelect.options[sel_id-1];
		var newOption = new Option(prevOption.text, prevOption.value);
		var selectedOption = sourceSelect.options[sel_id];
		sourceSelect.options[sel_id-1] = new Option(selectedOption.text, selectedOption.value);
		sourceSelect.options[sel_id] = newOption;
		sourceSelect.focus();
		sourceSelect.selectedIndex = sel_id -1;
	}
}


function moveDown(sourceSelect)
{	var sel_id;
	sel_id = sourceSelect.selectedIndex;
	if (sourceSelect.length > 1 && sel_id < sourceSelect.length -1) //got to have at least 2 items and not the last one is selected
	{	var nextOption = sourceSelect.options[sel_id+1];
		var newOption = new Option(nextOption.text, nextOption.value);
		var selectedOption = sourceSelect.options[sel_id];
		sourceSelect.options[sel_id+1] = new Option(selectedOption.text, selectedOption.value);
		sourceSelect.options[sel_id] = newOption;
		sourceSelect.focus();
		sourceSelect.selectedIndex = sel_id + 1;
	}
}

function saveSelected(fromSelObj, toHidObj, delim, empty_label) {
    var i;
	toHidObj.value = '';
    for (i=0; i<fromSelObj.length; i++) {
        if (i > 0) {
            toHidObj.value += delim;
        }
        if (!(fromSelObj.length == 1 && fromSelObj.options[0].value == empty_label)) {
            toHidObj.value += fromSelObj.options[i].value;
        }
    } 
}

function openwizard(url, name, resizable) {
  var win = window.open('', name, 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable='+resizable+',width=675,height=550',false)
  if ((win.document.URL == '') || (win.document.URL == 'about:blank')) win.location = url; 
  win.focus ();
}

function escapeUTF(src) {
	var ret = "";
	for (i = 0; i < src.length; i++) {
		var ch = src.charCodeAt(i);
		if (ch <= 0x7F) {
			ret += escape(src.charAt(i));
		} else if (ch <= 0x07FF) {
			ret += '%' + ((ch >> 6) | 0xC0).toString(16) + '%' + ((ch & 0x3F) | 0x80).toString(16);
		} else if (ch >= 0x0800) {
			ret += '%' + ((ch >> 12) | 0xE0).toString(16) +
				   '%' + (((ch >> 6) & 0x3F) | 0x80).toString(16) + '%' + ((ch & 0x3F) | 0x80).toString(16);
		}
	}
	return ret;
}

function openRefer(url) {
	window.open(url, 'referv2', 'resizable=no,toolbar=no,status=no,directories=no,scrollbars=yes,width=420,height=500', false); 
}

function printpage() {
window.print();
}

   // Tab panels
   
   var currentPanel;
   
   function showPanel(panelNum) {
      //hide visible panel, show selected panel, 
      //set tab
      if (currentPanel != null) {
         hidePanel();
      }
      document.getElementById 
         ('panel'+panelNum).style.visibility = 'visible';
         currentPanel = panelNum;
         setState(panelNum);
   }
   
   function hidePanel() {
      //hide visible panel, unhilite tab
      document.getElementById
        ('panel'+currentPanel).style.visibility = 
         'hidden';
      document.getElementById
        ('tab'+currentPanel).style.backgroundColor = 
        '#ffffff';
      document.getElementById
        ('tab'+currentPanel).style.color = 'navy';
   }
   
   function setState(tabNum) {
      if (tabNum==currentPanel) {
         document.getElementById 
           ('tab'+tabNum).style.backgroundColor = 
           '#ddddff';
         document.getElementById
           ('tab'+tabNum).style.color = 'red';
      }
      else {
         document.getElementById
           ('tab'+tabNum).style.backgroundColor = 
           '#ffffff';
         document.getElementById
           ('tab'+tabNum).style.color = 'navy';
      }
   }
   
	function hover(tab) {
		tab.style.backgroundColor = 'ddddff';
	}

	// Adds H3 tags to breadcrumbs using DOM - IE and moz
	function addToBreadcrumbs ( mid, melement, mclass, add_sep ){

		if (document.getElementById) {

			var itemText; 
			var itemLink;
	   
			if (mid != null) {
				if (document.getElementById(mid)) {
					itemText = document.createTextNode(document.getElementById(mid).childNodes[0].nodeValue);
				}
			}

			if(melement != null && mclass != null) {
				var elms = document.getElementsByTagName(melement)
				if (elms) {
					for (var i = 0; i < elms.length; i++) {
						if ( mclass != "" && elms[i].className == mclass) {
							if (elms[i].childNodes[0].nodeType == 3) {
								myval = trim( elms[i].childNodes[0].nodeValue );
								itemText = document.createTextNode(myval);
								break;
							} else if (elms[i].childNodes[0].getAttribute('href') != null){
								itemLink = elms[i].childNodes[0].getAttribute('href');
								myval = trim( elms[i].childNodes[0].childNodes[0].nodeValue );
								itemText = document.createTextNode(myval);
								break;
							}
						} else if ( mclass == "" ) {
							myval = trim( elms[i].childNodes[0].nodeValue );
							itemText = document.createTextNode(myval);
							break;
						}
					}
				}         
			}

			if (document.getElementById('breadLast') && itemText != null) {

				var linkItem = document.createElement("LI");
				if ( add_sep != null ) {
					var itemSep = document.createTextNode( add_sep );
					linkItem.appendChild(itemSep);
				}

				if (itemLink != null ) {
					var linkA = document.createElement("A")
					linkA.setAttribute('href',itemLink);
					linkItem.appendChild(linkA);
					linkA.appendChild(itemText);

				} else {

					linkItem.appendChild(itemText);

				}

				document.getElementById('breadLast').parentNode.appendChild(linkItem); 
				document.getElementById('breadLast').removeAttribute('class');
				document.getElementById('breadLast').setAttribute('class','on');
				document.getElementById('breadLast').removeAttribute('id');   

				linkItem.setAttribute('id','breadLast');
				linkItem.setAttribute('class','on current');
			}
		}
	}

	function addClassToLastListItem (tag,lclass,nclass){
		var lcount = 0;
		if (document.getElementsByTagName) {
			if (tag != null && lclass != null) {
				var lists = document.getElementsByTagName(tag);
				for (var i = 0; i < lists.length; i++) {
					if (lists[i].className == lclass) {
						if (lists[i].nodeType == 1 ) {	
							var items = lists[i].getElementsByTagName('LI');	
							items[items.length - 1].className = nclass;				
						}			
					} 
				}
			}
		}
	}

    h = "<script type='text/javascript' src='/js/cross-browser.com/x/x.js'></script>";
	document.writeln(h);



//DOM-ready watcher
function domFunction(f, a)
{
	//initialise the counter
	var n = 0;
	//start the timer
	var t = setInterval(function()
	{
		//continue flag indicates whether to continue to the next iteration
		//assume that we are going unless specified otherwise
		var c = true;
		//increase the counter
		n++;
		//if DOM methods are supported, and the body element exists
		//(using a double-check including document.body, for the benefit of older moz builds [eg ns7.1] 
		//in which getElementsByTagName('body')[0] is undefined, unless this script is in the body section)
		if(typeof document.getElementsByTagName != 'undefined' && (document.getElementsByTagName('body')[0] != null || document.body != null))
		{
			//set the continue flag to false
			//because other things being equal, we're not going to continue
			c = false;

			//but ... if the arguments object is there
			if(typeof a == 'object')
			{
				//iterate through the object
				for(var i in a)
				{
					//if its value is "id" and the element with the given ID doesn't exist 
					//or its value is "tag" and the specified collection has no members
					if
					(
						(a[i] == 'id' && document.getElementById(i) == null)
						||
						(a[i] == 'tag' && document.getElementsByTagName(i).length < 1)
					) 
					{ 
						//set the continue flag back to true
						//because a specific element or collection doesn't exist
						c = true; 

						//no need to finish this loop
						break; 
					}
				}
			}

			//if we're not continuing
			//we can call the argument function and clear the timer
			if(!c) { f(); clearInterval(t); }
		}
		
		//if the timer has reached 60 (so timeout after 15 seconds)
		//in practise, I've never seen this take longer than 7 iterations [in kde 3 
		//in second place was IE6, which takes 2 or 3 iterations roughly 5% of the time]
		if(n >= 60)
		{
			//clear the timer
			clearInterval(t);
		}
		
	}, 250);
};



Array.prototype.inArray = function (value) {
	var i;
	for (i=0; i < this.length; i++) {
		if (this[i] === value) {
			return true;
		}
	}
	return false;
};

function addEvent( obj, type, fn ) {
	if (obj.addEventListener) {
		obj.addEventListener( type, fn, false );
		EventCache.add(obj, type, fn);
	}
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
		EventCache.add(obj, type, fn);
	}
	else {
		obj["on"+type] = obj["e"+type+fn];
	}
}
	
var EventCache = function(){
	var listEvents = [];
	return {
		listEvents : listEvents,
		add : function(node, sEventName, fHandler){
			listEvents.push(arguments);
		},
		flush : function(){
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1){
				item = listEvents[i];
				if(item[0].removeEventListener){
					item[0].removeEventListener(item[1], item[2], item[3]);
				};
				if(item[1].substring(0, 2) != "on"){
					item[1] = "on" + item[1];
				};
				if(item[0].detachEvent){
					item[0].detachEvent(item[1], item[2]);
				};
				item[0][item[1]] = null;
			};
		}
	};
}();
addEvent(window,'unload',EventCache.flush);


/*
Sweet Titles (c) Creative Commons 2005
http://creativecommons.org/licenses/by-sa/2.5/
Author: Dustin Diaz | http://www.dustindiaz.com
*/
var sweetTitles = { 
	xCord : 0,								// @Number: x pixel value of current cursor position
	yCord : 0,								// @Number: y pixel value of current cursor position
	tipElements : ['a','abbr','acronym'],	// @Array: Allowable elements that can have the toolTip
	obj : Object,							// @Element: That of which you're hovering over
	tip : Object,							// @Element: The actual toolTip itself
	active : 0,								// @Number: 0: Not Active || 1: Active
	init : function() {
		if ( !document.getElementById ||
			!document.createElement ||
			!document.getElementsByTagName ) {
			return;
		}
		var i,j;
		this.tip = document.createElement('div');
		this.tip.id = 'toolTip';
		document.getElementsByTagName('body')[0].appendChild(this.tip);
		this.tip.style.top = '0';
		this.tip.style.visibility = 'hidden';
		var tipLen = this.tipElements.length;
		for ( i=0; i<tipLen; i++ ) {
			var current = document.getElementsByTagName(this.tipElements[i]);
			var curLen = current.length;
			for ( j=0; j<curLen; j++ ) {
				addEvent(current[j],'mouseover',this.tipOver);
				addEvent(current[j],'mouseout',this.tipOut);
				current[j].setAttribute('tip',current[j].title);
				current[j].removeAttribute('title');
			}
		}
	},
	updateXY : function(e) {
		if ( document.captureEvents ) {
			sweetTitles.xCord = e.pageX;
			sweetTitles.yCord = e.pageY;
		} else if ( window.event.clientX ) {
			sweetTitles.xCord = window.event.clientX + document.documentElement.scrollLeft;
			sweetTitles.yCord = window.event.clientY + document.documentElement.scrollTop;
		}
	},
	tipOut: function() {
		if ( window.tID ) {
			clearTimeout(tID);
		}
		if ( window.opacityID ) {
			clearTimeout(opacityID);
		}
		sweetTitles.tip.style.visibility = 'hidden';
	},
	checkNode : function() {
		var trueObj = this.obj;
		if ( this.tipElements.inArray(trueObj.nodeName.toLowerCase()) ) {
			return trueObj;
		} else {
			return trueObj.parentNode;
		}
	},
	tipOver : function(e) {
		sweetTitles.obj = this;
		tID = window.setTimeout("sweetTitles.tipShow()",200);
		sweetTitles.updateXY(e);
	},
	tipShow : function() {		
		var scrX = Number(this.xCord);
		var scrY = Number(this.yCord);
		var tp = parseInt(scrY+15);
		var lt = parseInt(scrX+10);
		var anch = this.checkNode();
		var addy = '';
		var access = '';
		if ( anch.nodeName.toLowerCase() == 'a' ) {
			addy = (anch.href.length > 25 ? anch.href.toString().substring(0,25)+"..." : anch.href);
			var access = ( anch.accessKey ? ' <span>['+anch.accessKey+']</span> ' : '' );
		} else {
			addy = anch.firstChild.nodeValue;
		}
        var mytip = anch.getAttribute('tip')
        this.tip.innerHTML = "<p>"+mytip+"</p>";
        // this.tip.innerHTML = "<p>"+anch.getAttribute('tip')+"<em>"+access+"</em></p>";
		if ( parseInt(document.documentElement.clientWidth+document.documentElement.scrollLeft) < parseInt(this.tip.offsetWidth+lt) ) {
			this.tip.style.left = parseInt(lt-(this.tip.offsetWidth+10))+'px';
		} else {
			this.tip.style.left = lt+'px';
		}
		if ( parseInt(document.documentElement.clientHeight+document.documentElement.scrollTop) < parseInt(this.tip.offsetHeight+tp) ) {
			this.tip.style.top = parseInt(tp-(this.tip.offsetHeight+10))+'px';
		} else {
			this.tip.style.top = tp+'px';
		}
        if ( mytip.length > 0 ) {
            this.tip.style.visibility = 'visible';
            this.tip.style.opacity = '.1';
            this.tipFade(10);
        }
	},
	tipFade: function(opac) {
		var passed = parseInt(opac);
		var newOpac = parseInt(passed+10);
		if ( newOpac < 80 ) {
			this.tip.style.opacity = '.'+newOpac;
			this.tip.style.filter = "alpha(opacity:"+newOpac+")";
			opacityID = window.setTimeout("sweetTitles.tipFade('"+newOpac+"')",10);
		}
		else { 
			this.tip.style.opacity = '.90';
			this.tip.style.filter = "alpha(opacity:90)";
		}
	}
};
function pageLoader() {
	sweetTitles.init();
}
addEvent(window,'load',pageLoader);


/*

    @format.tab-size 4
    @format.use-tabs true

*/

