/* This is the various JS scripts required throughout the software */
/* Admin Menu */
function adminmenushow() {
document.getElementById('AD1').style.visibility = "visible";
}
function adminmenuhide() {
document.getElementById('AD1').style.visibility = "hidden";
}
var newwindow;
function adminwindow(url) {
 newwindow=window.open(url,'adminwindow','height=600,scrollbars=yes,resizable=yes,toolbar=yes');
 if (window.focus) {newwindow.focus()}
}
function ccwindow(url) {
 newwindow=window.open(url,'ccwindow','height=600,scrollbars=yes,resizable=yes,toolbar=yes');
 if (window.focus) {newwindow.focus()}
}
function regwindow(url) {
 newwindow=window.open(url,'regwindow','width=780,height=600,scrollbars=yes,resizable=yes,toolbar=yes');
 if (window.focus) {newwindow.focus()}
}
function asub() { document.forms[0].submit() ; }		
/* Disable submit buttons after click */
function submitForm(s)  {
s.value = "In Progress";
s.disabled = true;
return true;
}
/* Disable link after click */
function cancelLink () {
  return false;
}
function disableLink (link) {
  if (link.onclick)
    link.oldOnClick = link.onclick;
  link.onclick = cancelLink;
  if (link.style)
    link.style.cursor = 'default';
}
function enableLink (link) {
  link.onclick = link.oldOnClick ? link.oldOnClick : null;
  if (link.style)
    link.style.cursor = 
      document.all ? 'hand' : 'pointer';
}
function toggleLink (link) {
  if (link.disabled) 
    enableLink (link)
  else 
    disableLink (link);
  link.disabled = !link.disabled;
}
/* WebRez popup window */
function webrezwindow(url) {
 newwindow=window.open(url,'webrezwin','width=780,height=580,scrollbars=yes,resizable=yes,toolbar=no');
 if (window.focus) {newwindow.focus()}
}		
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=640,height=480,left = 0,top = 0');");
}
/* Standard POP UP Window script - should make available in the editor */
function popupWin(thePage,theWidth,theHeight) {
popUp = window.open(thePage,"window","menubar=no,toolbar=no,scrollbars=no,resizable=no,status=no,width="+theWidth+",height="+theHeight)
popUp.focus()
}
/* Custom POP UP Window script - should make available in the editor */
function popupCustomWin(thePage,theMenu,theToolbar,theScrollbar,theResize,theStatus,theWidth,theHeight) {
popUp = window.open(thePage,"window","menubar="+theMenu+",toolbar="+theToolbar+",scrollbars="+theScrollbar+",resizable="+theResize+",status="+theStatus+",width="+theWidth+",height="+theHeight)
popUp.focus()
}
/* Code to allow required fields in forms - needs form attribute onSubmit="return checkrequired(this)" and each field
must have prefix "required". EG. "requiredFirstName" */
function checkrequired(which) {
	var pass=true
	if (document.images)
	{
		for (i=0;i<which.length;i++)
		{
			var tempobj=which.elements[i]
			if (tempobj.name.substring(0,8)=="required")
			{
				if (((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==-1))
				{
					pass=false
					break
				}				
				if ((tempobj.type=="checkbox"&&!tempobj.checked))
				{
					pass=false
					break
				}				
			}
		}
	}
	if (!pass)
	{
		alert("One or more of the required elements are not completed. Please complete them, then submit again!")
		return false
	}
	else
	return true
}
function taLimit() {
var taObj=event.srcElement;
if (taObj.value.length==taObj.maxLength*1) return false;
}
function taCount(visCnt) { 
var taObj=event.srcElement;
if (taObj.value.length>taObj.maxLength*1) taObj.value=taObj.value.substring(0,taObj.maxLength*1);
if (visCnt) visCnt.innerText=taObj.maxLength-taObj.value.length;
}

function toggle_visibility(id) 
{
 var e = document.getElementById(id);
 if(e.style.display == 'none')
 	e.style.display = 'block';
 else
	e.style.display = 'none';
}

function toggle_icon(id,idvis,path) 
{
 var e = document.getElementById(idvis);
 var a = document.getElementById(id);
 if(e.style.display == 'none')
 	a.src = path + '/REMarrow_dn.png';
 else
	a.src = path + '/REMarrow_up.png';
}

function MOver(id,img) 
{
 var i = document.getElementById(id);
 	i.src = img;
}

function MOut(id,img) 
{
 var i = document.getElementById(id);
 	i.src = img;
}
/* controlling font size */
var min=8;
var max=18;
function increaseFontSize() {
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=max) {
         s += 1;
      }
      p[i].style.fontSize = s+"px"
   }
}
function decreaseFontSize() {
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=min) {
         s -= 1;
      }
      p[i].style.fontSize = s+"px"
   }   
}

/* tabs for info pages */

var panes = new Array();

function setupPanes(containerId, defaultTabId) {
  panes[containerId] = new Array();
  var maxHeight = 0; var maxWidth = 0;
  var pcontainer = document.getElementById(containerId);
  var paneContainer = pcontainer.getElementsByTagName("div")[0];
  var paneList = paneContainer.childNodes;
  for (var i=0; i < paneList.length; i++ ) {
    var pane = paneList[i];
    if (pane.nodeType != 1) continue;
    if (pane.offsetHeight > maxHeight) maxHeight = pane.offsetHeight;
    if (pane.offsetWidth  > maxWidth ) maxWidth  = pane.offsetWidth;
    panes[containerId][pane.id] = pane;
    pane.style.display = "none";
  }
    paneContainer.style.height = maxHeight + "px";
    paneContainer.style.width  = maxWidth + "px";
    document.getElementById(defaultTabId).onclick();
}

function showPane(paneId, activeTab) {  
    for (var cont in panes) {
    activeTab.blur();
    activeTab.className = "tab-active";
    if (panes[cont][paneId] != null) { // tab and pane are members of this container
      var pane = document.getElementById(paneId);
      pane.style.display = "block";
      var pcontainer = document.getElementById(cont);
      var tabs = pcontainer.getElementsByTagName("ul")[0];
      var tabList = tabs.getElementsByTagName("a")
      for (var i=0; i<tabList.length; i++ ) {
        var tab = tabList[i];
        if (tab != activeTab) tab.className = "tab-disabled";
      }
      for (var ii in panes[cont]) {
		var pane = document.getElementById(ii);
        if (pane == undefined) continue;
        if (pane.id == paneId) continue;
        pane.style.display = "none";
      }
    }
  }  
  return false;    
}

function loadPane(paneId,FormField) {
	var theField = document.getElementById(FormField);
	theField.value = paneId;
	}
	
function setupAllPanes() {
setupPanes("firstcont", "firsttab");
}
