// Set a table row style to "selected" when the row's radio button or checkbox is checked

function style_row(obj) {
	if (document.forms[0].elements['radiobutton']) {
		radioButtons = document.forms[0].elements['radiobutton']

 		for(var i=0; i<radioButtons.length; i++){
			row=radioButtons[i].parentNode.parentNode;

			if (radioButtons[i].checked==true) {
				row.className='selected';
			}

			else row.className='';
		}
	}

	else {
		row=obj.parentNode.parentNode;
		if (obj.checked==true) {
			row.className='selected';
		}
		else row.className='';
	}
	
}

// select or deselect all checkbox
function ToggleCheckboxes(field, value) {
	for (i = 0; i < field.length; i++) {
		field[i].checked = value;
		if (field[i].name.indexOf('checkbox') != -1) style_row(field[i]);
	}
}

// toggle or set layer display
function toggleDisp(theLayer,dispType) {
	if(!dispType) dispType = "block"
	
	if(document.getElementById(theLayer).style.display == dispType || document.getElementById(theLayer).style.display == "") setDisp(theLayer,'none');
	else setDisp(theLayer,dispType);
}
function setDisp(theLayer,dispType) {
	document.getElementById(theLayer).style.display = dispType
}

function togglePopup(theLayer) {
			if(document.getElementById(theLayer).style.display == "block" || document.getElementById(theLayer).style.display == "") {
				new Effect.PhaseOut($(theLayer), { duration: .3});
				new Effect.Opacity($('pageWrapper'), {duration:0.3, from:0.6, to:1});
			}
	else {
		new Effect.PhaseIn($(theLayer), { duration: .3});
		new Effect.Center($(theLayer)); 
		new Effect.Opacity($('pageWrapper'), {duration:0.3, from:1.0, to:0.6}); 
	}
}

//SHOW/HIDE LAYER FUNCTION
function toggleVis(theLayer) {
	if(document.getElementById(theLayer).style.visibility == "visible") {
		document.getElementById(theLayer).style.visibility = "hidden";
	
	}
	else { 
		document.getElementById(theLayer).style.visibility = "visible";
	}
}


// ALLOW "TIP" TEXT IN TEXT ENTRY BOXES

function clickclear(thisfield, defaulttext) {
 	if (thisfield.value == defaulttext) {
 		thisfield.value = "";
 		thisfield.className = "normalText"
 	}
 }

function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
		thisfield.value = defaulttext;
		thisfield.className = "hintText"
	 }
 }
 
 

 

// BEGIN PLACEHOLDER MENUING FUNCTIONS
// The following functions should not be used in the final code.  They are placeholders for a menuing solution.  However, the use of scriptaculous effects within these functions should be retained in the final menuing code -- ie Effect.PhaseOut(), Effect.Appear()

// GET X,Y COORDINATES OF MOUSE
var IE = document.all?true:false
// If not IE then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)
// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;
// Temporary variables to hold mouse x-y pos.s
var mouseX = 0
var mouseY = 0

// Main function to retrieve mouse x-y pos.s
function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    mouseX = event.clientX + document.body.scrollLeft
    mouseY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    mouseX = e.pageX
    mouseY = e.pageY
  }  
  // catch possible negative values in NS4
  if (mouseX < 0){mouseX = 0}
  if (mouseY < 0){mouseY = 0}  
}

// returns true of oNode is contained by oCont (container)
function contained(oNode, oCont) {
  if (!oNode) return; // in case alt-tab away while hovering (prevent error)
  while ( oNode.parentNode ) {
    oNode = oNode.parentNode;
    if ( oNode == oCont ) return true;
  }
  return false;
}

function showContextualMenu(theLayer){
	mouseY = mouseY-5
	mouseX = mouseX-5
	new Effect.MoveBy($(theLayer), mouseY, mouseX, {from: 1, to: 1, duration: .3 });
//	document.getElementById(theLayer).style.top = mouseY-3;
	new Effect.Appear($(theLayer), {duration: .3})
}

function hideMe(obj,e,theDiv) {
  var toEl;
  if (window.event) toEl = window.event.toElement;
  else if (e.relatedTarget) toEl = e.relatedTarget;
  if ( obj != toEl && !contained(toEl, obj) ) {
		new Effect.PhaseOut($(obj), {  duration: .3		});
  }
}

// END PLACEHOLDER MENUING FUNCTIONS


 
// My MODIFIED version of a script from dynamic drive
// used to show "previews" of work orders
// SCRIPT DOES NOT PROPERLY ADJUST POSITIONING of layer when appearing off screen
// needs to be FIXED or REPLACED

/***********************************************
* Fixed ToolTip script- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
var tipwidth=275	
var vertical_offset="-125px" //horizontal offset of tooltip from anchor link
var horizontal_offset="100px" //horizontal offset of tooltip from anchor link

/////No further editting needed

var ie4=document.all
var ns6=document.getElementById&&!document.all
var lastX = 0
var lastY = 0

function getposOffset(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}




function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
	var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
	if (whichedge=="rightedge"){
		var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
		dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
		if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure) edgeoffset=dropmenuobj.contentmeasure-(obj.offsetWidth - 90)
	}
	else{
		var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
		dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
		if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure) edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
	}
	return edgeoffset
}

var cursorOn = 0
var cursorOvr = 0

function showtip() {
	if (cursorOn == 1) 	toggleVis("fixedtipdiv");
	clearTimeout(extrainfo)
}

function fixedtooltip(obj, e) {
	cursorOn = 1
	if (window.event) event.cancelBubble=true
	else if (e.stopPropagation) e.stopPropagation()
	dropmenuobj=document.getElementById? document.getElementById("fixedtipdiv") : fixedtipdiv
	dropmenuobj.x=getposOffset(obj, "left")
	dropmenuobj.y=getposOffset(obj, "top")
	dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
	dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
	extrainfo = setTimeout("showtip()",800)
}

function showDropdown(obj, e, objID, vert, horiz) {
	cursorOvr = 1
	if (window.event) event.cancelBubble=true
	else if (e.stopPropagation) e.stopPropagation()
	vertical_offset = vert
	horizontal_offset = horiz
	dropmenuobj=document.getElementById? document.getElementById(objID) : objID
	dropmenuobj.x=getposOffset(obj, "left")
	dropmenuobj.y=getposOffset(obj, "top")
	dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
	dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px";
	new Effect.Appear($(objID), {duration: .3})
}

function hidetip() {
	if(document.getElementById('fixedtipdiv')) {
		cursorOn = 0;
		clearTimeout(extrainfo)
		if (document.getElementById('fixedtipdiv').style.visibility == "visible") {
			toggleVis('fixedtipdiv')
		}
	}
	else {
		if(document.getElementById('contextualMenu1') && cursorOvr == 0 && document.getElementById('contextualMenu1').style.display != "none") 	{
			new Effect.PhaseOut($('contextualMenu1'), {  duration: .3, afterFinish: function() {
			document.getElementById('contextualMenu1').style.top = 0;
			document.getElementById('contextualMenu1').style.left = 0;
			}
			});
			clearTimeout(dropmenu)
		}	
		if(document.getElementById('contextualMenu2') && cursorOvr == 0 && document.getElementById('contextualMenu2').style.display != "none") 	{
			new Effect.PhaseOut($('contextualMenu2'), {  duration: .3, afterFinish: function() {
			document.getElementById('contextualMenu2').style.top = 0;
			document.getElementById('contextualMenu2').style.left = 0;
			}
			});
			clearTimeout(dropmenu)
		}		

	}

}

function delayhidetip() {
	cursorOvr = 0;
	dropmenu = setTimeout("hidetip()",800)
}



function containsDOM (container, containee) {
  var isParent = false;
  do {
    if ((isParent = container == containee))
      break;
    containee = containee.parentNode;
  }
  while (containee != null);
  return isParent;
}

function checkMouseEnter (element, evt) {
  if (element.contains && evt.fromElement) {
    return !element.contains(evt.fromElement);
  }
  else if (evt.relatedTarget) {
    return !containsDOM(element, evt.relatedTarget);
  }
}

function checkMouseLeave (element, evt) {
  if (element.contains && evt.toElement) {
    return !element.contains(evt.toElement);
  }
  else if (evt.relatedTarget) {
    return !containsDOM(element, evt.relatedTarget);
  }
}

function toggleFolder(num) {
	folderName = "folder" + num;
	editMode = "edit" + num;
	toggleDisp(editMode);
	toggleDisp(folderName);
	
	if ($(editMode).style.display == "block") { $(editMode).focus(); $(editMode).select() };
}


function showPopup(divID) {	
	setShimHeight() ; 
	setDisp('shim','block') ;
	new Effect.Center($(divID));
	new Effect.Appear($(divID), { duration: .3});
}
function closePopup(divID) {
	setDisp('shim','none') ;
	new Effect.Fade($(divID), { duration: .3});
}

// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}


function setShimHeight() {
	var arrayPageSize = getPageSize();
	document.getElementById('shim').style.height = (arrayPageSize[1] - 40 + 'px');
}

function accordionPane(currentPanel) {
	
	if (lastPanel != currentPanel) {
	
		new Effect.BlindUp(lastPanel, {duration: .3});
		new Effect.BlindDown(currentPanel, {duration: .3});
		lastPanel = currentPanel
		if (currentPanel == "library") $('actions').style.display = 'inline';
		else $('actions').style.display = 'none'
	}
}


function showConfirmation(notificationName) {
	new Effect.Move(notificationName, { x:0, y:20, mode: 'relative'});
	new Effect.Appear(notificationName, {duration: .3, from: 0, to: 0.8});
	autohide = setTimeout("hideConfirmation('"+notificationName+"')",4000);
	
}

function hideConfirmation(notificationName) {
	new Effect.Move(notificationName, { x:0, y:20, mode: 'relative'});
	new Effect.Fade(notificationName, {duration: .3,  afterFinish: function(effect){ new Effect.Move(notificationName, { x:0, y:-25, mode: 'relative'}) } });
	clearTimeout(autohide);
}


function showError(notificationName) {
	new Effect.Move(notificationName, { x:0, y:20, mode: 'relative'});
	new Effect.Appear(notificationName, {duration: .3, from: 0, to: 0.8});
}

function hideError(notificationName) {
	new Effect.Move(notificationName, { x:0, y:20, mode: 'relative'});
	new Effect.Fade(notificationName, {duration: .3,  afterFinish: function(effect){ new Effect.Move(notificationName, { x:0, y:-25, mode: 'relative'}) } });
}




function showActions(theID) {
	
		new Effect.Appear(theID, {duration: .3});

}

function hideActions(theID) {

	new Effect.Fade($(theID), {duration: .3});

}
