
// Set all checkbox states for a column. Works with tablebuilder.tpl code...

function setAllCheckboxes(colName, checkedState, thisForm) {

	for (z = 0; z < thisForm.elements.length; z++) {
			if (thisForm.elements[z].name.indexOf(colName) > -1) {
				thisForm.elements[z].checked = checkedState;
			}
	}
}

// Verify that at least one checkbox has been selected in a form.

function verifyCheckboxSelection(thisForm, thisAction) {
	for (z = 0; z < thisForm.elements.length; z++) {
		if (thisForm.elements[z].checked) return true;
	}
	confirm("You must select at least one item in order to " + thisAction + ".");
	return false;
}

// Change state of a form image button

function setButtonState( buttonId, buttonEnabled, imgSrc, cursorType ) {
	var theButton = document.getElementById( buttonId ) ;
	theButton.disabled = !buttonEnabled ;
	theButton.src = imgSrc ;
	return ;
}

function submitToPopup (thisFrm, windowName, submitViaScript) {
	window.open('', windowName, 'titlebar=no,status=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes') ;
	thisFrm.target = windowName ;
	if (submitViaScript) thisFrm.submit() ;
}

function redirectOpener(thisURL, closeMe) {
	opener.location = thisURL ;
	if (closeMe) self.close();
}

function closeDiv(thisDivID) {
	thisDiv = document.getElementById(thisDivID);
	thisDiv.style.display = 'none';
}
// makes sure you want to delete a record in backoffice--applies to project, users, and photos
function confirmDelete() {
	var isDeleted =confirm("Are you sure you want to delete this record?");
		if(isDeleted) {
			return true;
		}
		else {
			return false ;
		}
}


/*
 *	draggable element stuff for the error messages...
 */


//*****************************************************************************
// Do not remove this notice.
//
// Copyright 2001 by Mike Hall.
// See http://www.brainjar.com for terms of use.
//*****************************************************************************

// Determine browser and version.

function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();

// Global object to hold drag information.

var dragObj = new Object();
dragObj.zIndex = 0;

function dragStart(event, id) {

  var el;
  var x, y;

  // If an element id was given, find it. Otherwise use the element being
  // clicked on.

  if (id)
    dragObj.elNode = document.getElementById(id);
  else {
    if (browser.isIE)
      dragObj.elNode = window.event.srcElement;
    if (browser.isNS)
      dragObj.elNode = event.target;

    // If this is a text node, use its parent element.

    if (dragObj.elNode.nodeType == 3)
      dragObj.elNode = dragObj.elNode.parentNode;
  }

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Save starting positions of cursor and element.

  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);

  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;

  // Update element's z-index.

  dragObj.elNode.style.zIndex = ++dragObj.zIndex;

  // Capture mousemove and mouseup events on the page.

  if (browser.isIE) {
    document.attachEvent("onmousemove", dragGo);
    document.attachEvent("onmouseup",   dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS) {
    document.addEventListener("mousemove", dragGo,   true);
    document.addEventListener("mouseup",   dragStop, true);
    event.preventDefault();
  }
}

function dragGo(event) {

  var x, y;

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Move drag element by the same amount the cursor has moved.

  dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
  dragObj.elNode.style.top  = (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";

  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS)
    event.preventDefault();
}

function dragStop(event) {

  // Stop capturing mousemove and mouseup events.

  if (browser.isIE) {
    document.detachEvent("onmousemove", dragGo);
    document.detachEvent("onmouseup",   dragStop);
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", dragGo,   true);
    document.removeEventListener("mouseup",   dragStop, true);
  }
}

// ITEM DETAIL PAGE - javascript photo gallery
// loads large image in right panel
function loadImg(img){ 	document.bigImg.src=img;	}

// scrolls the thumbnails on the project detail page
function scrollup() { document.getElementById('thumbnails').scrollTop += 62; }
function scrolldown() { document.getElementById('thumbnails').scrollTop -= 62; }

// scrolls the thumbnails on the Projects/List featured projects list
function leftscroll() { document.getElementById('projects_featured').scrollLeft += 30; }
function rightscroll() { document.getElementById('projects_featured').scrollLeft -= 30; }



// generic MM functions for UGA template - controls rollovers for header section
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null) {
		document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];
	}
}


// loads the MM dropdowns for Projects or pages

function mmLoadMenus() {
	  	if (window.projectsmenu) return;

		// projects menu
		window.projectsmenu = new Menu("root",200,21,"Arial, Helvetica, sans-serif",12,"#cccccc","#ffffff","#666666","#ff0000","left","middle",3,0,1000,-10,7,true,true,true,0,false,true);
			 projectsmenu.addMenuItem("Current Projects","location='/ouaapps/Projects/List'");
			 projectsmenu.addMenuItem("Completed Projects Gallery","location='/completedprojectsgallery.html'");
			 projectsmenu.hideOnMouseOut=true;
			 projectsmenu.menuBorder=1;
			 projectsmenu.menuLiteBgColor='#666666';
			 projectsmenu.menuBorderBgColor='#444444';
			 projectsmenu.bgColor='#000000';

		// planning menu
	    window.planningmenu = new Menu("root",200,21,"Arial, Helvetica, sans-serif",12,"#cccccc","#ffffff","#666666","#ff0000","left","middle",3,0,1000,-10,7,true,true,true,0,false,true);
			 planningmenu.addMenuItem("Current Master Plan","location='/currentmasterplan.html'");
			 planningmenu.addMenuItem("Master Plan History","location='/masterplanhistory.html'");
			 planningmenu.addMenuItem("Precinct Plans","location='/precinctplans.html'");
			 planningmenu.addMenuItem("Planned Projects","location='/plannedprojects.html'");
			 planningmenu.addMenuItem("Transportation","location='/transportation.html'");
			 planningmenu.addMenuItem("Sustainable Design","location='/sustainabledesign.html'");
			 planningmenu.hideOnMouseOut=true;
			 planningmenu.menuBorder=1;
			 planningmenu.menuLiteBgColor='#666666';
			 planningmenu.menuBorderBgColor='#444444';
			 planningmenu.bgColor='#000000';

		// gis/maps menu
	    window.gismenu = new Menu("root",200,21,"Arial, Helvetica, sans-serif",12,"#cccccc","#ffffff","#666666","#ff0000","left","middle",3,0,1000,-10,7,true,true,true,0,false,true);
			 gismenu.addMenuItem("Interactive Campus Map","location='http://maps.uga.edu/website/htmlviewer/hyperlink/viewer.htm'");
			 gismenu.addMenuItem("Current Campus Maps","location='/currentcampusmaps.html'");
			 gismenu.addMenuItem("Historic Campus Maps","location='/historiccampusmaps.html'");	
			 gismenu.addMenuItem("Historic Planning Maps","location='/historicplanningmaps.html'");
			 gismenu.hideOnMouseOut=true;
			 gismenu.menuBorder=1;
			 gismenu.menuLiteBgColor='#666666';
			 gismenu.menuBorderBgColor='#444444';
			 gismenu.bgColor='#000000';

	    // news menu
	    window.newsmenu = new Menu("root",200,21,"Arial, Helvetica, sans-serif",12,"#cccccc","#ffffff","#666666","#ff0000","left","middle",3,0,1000,-10,7,true,true,true,0,false,true);
			 newsmenu.addMenuItem("News Archive","location='/newsarchive.html'");
			 newsmenu.hideOnMouseOut=true;
			 newsmenu.menuBorder=1;
			 newsmenu.menuLiteBgColor='#666666';
			 newsmenu.menuBorderBgColor='#444444';
 			 newsmenu.bgColor='#000000';
			 newsmenu.writeMenus();

} // mmLoadMenus()

