// Location variables
var HostName = "www.jgormanbuilders.com:8888";
var DatabasePath = "websites/gorman.nsf";
function imgMgr(unid)
{
	url = (unid=="") ? '/websites/gorman.nsf/webimagefile?OpenForm&tab=2' : '/websites/gorman.nsf/imagemanager/' + unid + '?OpenDocument';
	window.open(url, 'imgMgr', 'width=650,height=450,scrollbars=1,status=0');
}
function removeDoc(deleteurl)
{
   var f = document.forms[0];
   if(confirm('Are you sure you want to delete this ?'))
   {
      f.Action.value = 'Delete';
      f.Delete.value = '1';
      f.submit();
   }
   return;
}
// Delete a document
function submitDoc()
{
  var f = document.forms[0];
   if(itPasses()){
	isEdited = false;	// this cancels the confirmation on unload
	if(confirm('Are you sure you want to save your changes ?'));
	f.submit();
   }
   return;
}
// Confirm and submit document
function itPasses()
{
   elm = document.getElementById('REQ_TITLE');
   if(elm.value == "")
   {
      showID();
      alert("Please enter a title for this page.");
      elm.focus();
      return false;
   }
   return true;
}
// Check that the document has a title field
function updateSorting()
{
   var f = document.forms[0];
   n = 0;
   var longString = "";
   var posString = "";
   for(var i = 0; i < f.elements.length; i++)
   {
      if(f.elements[i].name == "unid")
      {
       //  if(f.elements[i].checked)
//         {
            if(longString.length != 0)
            {
               longString += ";";
               posString += ";";
            }
            longString += f.elements[i].value;
            posString += getPositionValue(f, n);
//         }
         n = n + 1;
      }
      // Ends the check to see if it's one of our fields or not
   }
   // Move on to the next form field
   f.unids.value = longString;
   // put the value into the hidden field
   f.pos.value = posString;
   // put the value into the hidden field
}
//  Update document sorting
function deleteDocuments()
{
   order = document.forms['updateOrder'];
   if(confirm("Are you sure you wish to remove the selected items ?"))
   {
      setUNIDS(order);
      order.Action.value = "Delete";
      order.submit();
   }
   return true;
}
// Delete documents
function markPaid()
{
   var f = document.forms[0];
   if(confirm("Are you sure you wish to mark the selected orders paid ?"))
   {
      setUNIDS(f);
      f.Action.value = "Paid";
      f.submit();
   }
   else 
   {
      return false;
   }
}
// Mark Orders Paid
function markShipped()
{
   var f = document.forms[0];
   if(confirm("Are you sure you wish to mark the selected orders shipped ?"))
   {
      setUNIDS(f);
      f.Action.value = "Shipped";
      f.submit();
   }
   return true;
}
// Mark Orders Shipped
function setUNIDS(f)
{
   n = 0;
   var longString = "";
   for(var i = 0; i < f.elements.length; i++)
   {
      if(f.elements[i].name == "unid")
      {
         // if it's one of the user input fields
         if(f.elements[i].checked)
         {
            if(longString.length > 0)
            {
               longString += ";";
            }
            longString += f.elements[i].value;
         }
         n = n + 1;
      }
   }
   f.unids.value = longString;
}
// Set the UNIDS field to have all the checked values
function getPositionValue(f, which)
{
   n = 0;
   for(var i = 0; i < f.elements.length; i++)
   {
      if(f.elements[i].name == "mpos")
      {
         // if it's one of the user input fields
         if(n == which)
         return f.elements[i].value;
         n = n + 1;
      }
   }
}
function show(targetId)
{
   document.getElementById(targetId).style.display = "";
}
// Shows an element on a page
function hide(targetId)
{
   document.getElementById(targetId).style.display = "none";
}
// Hides an element on a page
function assignMenu(menuID)
{
   doc = document.forms['updateOrder'];
   if(confirm("Click OK to assign the menu to the selected items."))
   {
      setUNIDS(doc);
      doc.MENU_ID.value = menuID;
      doc.Action.value = "Menu";
      doc.submit();
   }
   return true;
}
// Assign a menu to a group of items
function addToGallery(galleryID)
{
   doc = document.forms['updateOrder'];
   if(confirm("Click OK to put the selected items in the gallery."))
   {
      setUNIDS(doc);
      doc.GALLERY_ID.value = galleryID;
      doc.Action.value = "Gallery";
      doc.submit();
   }
   return true;
}
// Put documents into a gallery
function openHelp(page)
{
   window.open(page + '?ReadForm', 'helpWin', 'width=400,height=400,scrollbars=1,status=0');
   return;
}
// Open a help page
function tbButtonOvr(image)
{
   if(image.className == "buttonNor")
   {
      image.className = "buttonOvr";
   }
   return true;
}
function tbButtonOut(image)
{
   if(image.className == "buttonOvr")
   {
      image.className = "buttonNor";
   }
   return true;
}
function tbButtonDown(image)
{
   if(image.className == "buttonOvr")
   {
      image.className = "buttonPress";
   }
   return true;
}
function tbButtonUp(image)
{
   if(image.className == "buttonPress")
   {
      image.className = "buttonOvr";
   }
   return true;
}
function replaceDbPath(content)
{
   //FIND OUT CURRENT SERVER NAME AND REPLACE ".." IN URL 
   var newString = "http://" + HostName + "/" + DatabasePath;
   var contentArray = content.split(newString);
   content = contentArray.join("..");
   return content;
}
function getDbPath(content)
{
   var newstring = "http://" + HostName + "/" + DatabasePath + "/";
   var contentArray = content.split("../");
   content = contentArray.join(newstring);
   return content;
}
// SHOWN TO ALL
function changePage(url, idx)
{
   document.location.href = url + "&Start=" + idx;
}
// Change the page
function isNumber(val)
{
   var digits = "0123456789";
   for(var i = 0; i < val.length; i++)
   {
      temp = val.substring(i, i + 1);
      if(digits.indexOf(temp) == - 1 && val != "")
      {
         return false;
      }
   }
   return true;
}
// Check for numeric value
function showmenu(unid)
{
   document.location.href = document.location.href + '&menuid=' + unid;
   return true;
}
// Menu switcher
function showTab(i)
{
	if ( document.getElementById('tab' + i.toString() ) ) {
//alert('showTab - global.scripts');
		show('tab' + i.toString());
		document.getElementById('t' + i.toString()).className = 'tab_selected';
		document.getElementById('l' + i.toString()).className = 'link_selected';
	}
}
function hideTab(i)
{
	if ( document.getElementById('tab' + i.toString() ) ) {
		hide('tab' + i.toString());
		document.getElementById('t' + i.toString()).className = 'tab_normal';
		document.getElementById('l' + i.toString()).className = 'link_normal';
	}
}
