/* function CurrWindow(mypage, myname, resize) {
	settings="width=350,height=400,top=300,left=350,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable="+resize;
	CurrWin=window.open(mypage,"CurrWin",settings);
	CurrWin.focus();
	CurrWin.opener.name="MainWin";
} */

function popbit(BitID) {
	mypage="/popbit.cfm?BitID="+BitID;
	settings="width=550,height=400,top=50,left=50,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes";
	PopWin = window.open(mypage,"PopWin",settings);
	PopWin.focus();
	PopWin.opener.name="MainWin";
}

function Curr(CatID) {
	mypage ="/popcat.cfm?CatID="+CatID;	
	settings="width=350,height=400,top=50,left=350,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";
	CurrWin=window.open(mypage,"CurrWin",settings);
	CurrWin.focus();
	CurrWin.opener.name="MainWin";
}

function MSCurr(CatID) {
	mypage ="/popcat.cfm?CatID="+CatID;
	settings="width=550,height=400,top=50,left=50,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes";
	CurrWin=window.open(mypage,"CurrWin",settings);
	CurrWin.focus();
	CurrWin.opener.name="MainWin";
}

function MSCurrBit(BitID) {
	mypage ="/popcat.cfm?BitID="+BitID;
	settings="width=550,height=400,top=50,left=50,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes";
	CurrWin=window.open(mypage,"CurrWin",settings);
	CurrWin.focus();
	CurrWin.opener.name="MainWin";
}

function changed(caller) {
	selected_value="/popup.cfm?Cat="+caller.options[caller.selectedIndex].value;
	selected_name=caller.options[caller.selectedIndex].text;
	CurrWindow(selected_value, selected_name);
}

function EdPermWindow(PermID, EdUser) {
	settings="width=400,height=200,top=30,left=50,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";
	mypage="/mums/perms.cfm?PermID="+PermID+"&EdUser="+EdUser;
	EdPermWin=window.open(mypage,"EdPermWin",settings);
	EdPermWin.opener = window;
	EdPermWin.opener.name = "MainWin";
}

function AddPermWindow(EdUser) {
	settings="width=400,height=200,top=30,left=50,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";
	mypage="/mums/perms.cfm?Add=1&EdUser="+EdUser;
	EdPermWin=window.open(mypage,"EdPermWin",settings);
	EdPermWin.opener = window;
	EdPermWin.opener.name = "MainWin";
}

function ClosePermWindow(MyWin) {
	MyWin.opener.location.reload();
	MyWin.close();
}

var ImageWin = null;

function ShowImage(tFile, ImgName, Width, Height) {
	if(ImageWin != null) {
		ImageWin.close();
	}
	settings="width="+Width+",height="+Height+",top=30,left=50,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";
	mypage="/showimage.cfm?FileName="+tFile+"&ImgName="+ImgName;
	ImageWin=window.open(mypage,"ImageWin",settings);
	ImageWin.focus();
	//ImageWin.opener = window;
}

var popupwin = null;
var popupwin2 = null;

function pop() {
  var argv = arguments;
  var loc        = argv[0];
  var Width      = argv[1];
  var Height     = argv[2];
  var Resizable  = argv[3];
  var Scrollbars = argv[4];
  
  if(Scrollbars == null)
    Scrollbars = 0;

  if (popupwin == null || popupwin.closed) {
  	settings = "menubar=0,status=0,location=0,titlebar=0,toolbar=0,scrollbars="+Scrollbars+",top=141,left=400,width=" + Width + ",height=" + Height + ",resizable=" + Resizable;
    popupwin = window.open (loc, 'popupwin', settings);
  
  } else {
    popupwin.focus();
    popupwin.location.href = loc;
  }
}

function popnews(loc, Width, Height, Resizable, Top, Left) {
  if (popupwin2 == null || popupwin2.closed) {
  	settings = "menubar=0,status=0,location=0,titlebar=0,toolbar=0,scrollbars=1,top=" + Top + ",left=" + Left + ",width=" + Width + ",height=" + Height + ",resizable=" + Resizable;
    popupwin2 = window.open (loc, 'popupwin2', settings);
	popupwin2.opener = window;
	popupwin2.opener.name = "MainWin";
  } else {
    popupwin2.focus();
    popupwin2.location.href = loc;
  }
}
	 
function ShowImageCat() {
	var argv = arguments;
	var PhotoCatID = argv[0];
	var Insert = argv[1];
	var ImageList = argv[2];
	var SaveURL = argv[3];
	
	settings="width=550,height=550,top=30,left=50,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes";
	mypage="/imagecat.cfm?PhotoCatID="+PhotoCatID;
	if(Insert) {
		mypage = mypage+"&Insert=1";
	}
	
	if(SaveURL != null) {
		mypage = mypage + "&SaveURL=" + SaveURL;
	}
	
	if(ImageList != null) {
		mypage = mypage + "&ImageList=" + ImageList;
	}
	
	ImageCatWin=window.open(mypage,"ImageCatWin",settings);
	ImageCatWin.focus();
	ImageCatWin.opener = window;
}

function move(box,index,to) { //index is a dummy parameter from the old version of move. Now, we get it directly from box.selectedIndex
	var copyText, copyValue, si;
	si = box.selectedIndex;
	
	if(si == -1)
		return;
	
	if( si + to > box.options.length - 1 )
		{ to = 0; }
	
	if( si + to < 0 )
		{ to = 0; }
		
	copyText = box.options[si+to].text;
	copyValue = box.options[si+to].value;
	
	box.options[si+to].text = box.options[si].text;
	box.options[si+to].value = box.options[si].value;
	
	box.options[si].text = copyText;
	box.options[si].value = copyValue;
	
	box.selectedIndex = si + to;
	box.focus();
}

function spell(Content) 
{
	window.open("/spellchecker/window.cfm?jsvar=" + Content,null, "height=230,width=450,status=no,toolbar=no,menubar=no,location=no");
}

function SearchList(searchString, list) {
	if (searchString == '') {
		list.selectedIndex = 0;
	}
	else {
		i = Search(0, list.length-1, searchString, list);
		if (i != -1) {
			list.selectedIndex = i;
		}
	}
}

function Search(start, end, key, list) {
	if (start > end) {
		return -1;
	}
	mid = Math.floor((end + start) / 2);
	if (list.options[mid].text.toLowerCase().indexOf(key.toLowerCase()) != -1 && list.options[mid].text.toLowerCase().indexOf(key.toLowerCase()) == 0) {
		return mid;
	}
	else {
		if (key.toLowerCase() < list.options[mid].text.toLowerCase())
			return Search(start, mid-1, key, list);
		else
			return Search(mid+1, end, key, list);
	}
}

/*function SearchList(searchString, list) {
	var i = 0;
	for (i = 0; i < list.options.length; i++) {
		if (list.options[i].text.toLowerCase().indexOf(searchString.toLowerCase()) != -1 && list.options[i].text.toLowerCase().indexOf(searchString.toLowerCase()) == 0) {
			list.selectedIndex = i;
			break;
		}
	}
}*/

function windowShade( targetName, imgObjName ) {
    var target;
    var imgObj;
    
    if( document.getElementById ) { // NS6+
        target = document.getElementById(targetName);
		imgObj = document.getElementById(imgObjName);
    } else if( document.all ) { // IE4+
        target = document.all[targetName];
		imgObj = document.all[imgObjName];
    }
    
    // only attempt the show hide if a target is found, could be looking at user's other cookie name that doesn't fit as a node name
    if( target ) {
        // IE & NS6 like 'none'/'block', a value is needed for the cookie
        if( target.style.display == "none" ) {
            target.style.display = "block";
//            setCookie( targetName, "block" );
        } else {
            target.style.display = "none";
//            setCookie( targetName, "none" );
        }
    }
    if( imgObj ) {
        var imgPath = imgObj.src;
        if( imgPath ) {
            imgPath = imgPath.substring(0,imgPath.lastIndexOf("/")) + "/";
            if( imgObj.src == imgPath + "close.gif" ) {
                imgObj.src = imgPath + "open.gif";
            } else {
                imgObj.src = imgPath + "close.gif";
            }
        }
    }
} // windowShade


/* I created this function because windowShade seemed to blow up outside LSRC (JWH)*/
function showHide(targetName, displayStyle) {
	if(displayStyle == null) displayStyle = "inline";
    if( document.getElementById ) { // NS6+
        target = document.getElementById(targetName);
    } else if( document.all ) { // IE4+
        target = document.all[targetName];
    }
    
    // only attempt the show hide if a target is found, could be looking at user's other cookie name that doesn't fit as a node name
    if( target ) {
        // IE & NS6 like 'none'/'block', a value is needed for the cookie
        if( target.style.display == "none" ) {
            target.style.display = displayStyle;
        } else {
            target.style.display = "none";
        }
    }
}

function confirm_entry(message,url) {
	input_box=confirm(message);
	if (input_box==true) { 
		// Output when OK is clicked
		window.location = url;
	}
}

vidwin=null;

function popvid(loc, Width, Height, Resizable, Top, Left) {
	if (vidwin == null || vidwin.closed) {
		settings = "menubar=0,status=0,location=0,titlebar=0,toolbar=0,scrollbars=0,top=" + Top + ",left=" + Left + ",left=0,width=" + Width + ",height=" + Height + ",resizable=" + Resizable;
		vidwin = window.open (loc, 'vidwin', settings);
 			}
	else {
		vidwin.focus();
		vidwin.location.href = loc;
		}
}

function checkDisabled(input, output) {
	if(input.checked == 1) {
		output.style.display = 'block';
	} else {
		output.style.display = 'none';
	}
}

//The function to move bits between boxes.
function movebox(fbox, tbox) {
	var i = 0; //Counter to loop through boxes.
	var t = fbox.options.length-1; //The last valid index of the box.
	while(i <= t) { //We don't use a simple for loop because when items are deleted, box.options.length gets smaller.
		if ( fbox.options[i].selected ) { //If this item is selected, move it.
			//Add the new item to the destination box.
			tbox.options[tbox.options.length] = new Option(fbox.options[i].text, fbox.options[i].value);
			//Delete the old item.
			fbox.options[i] = null;
			//Important! Decrement t so that we have the right maximum index.
			t--;
		} else i++; //Only increment i if the item is not selected. Otherwise, leave the index the
					//same; there's a new item there already.
	}
}

//The function to copy bits between boxes.
function copybox(fbox, tbox) {
	for(i=0; i <= fbox.options.length-1; i++) { 
		if ( fbox.options[i].selected ) { //If this item is selected, copy it.
			//Add the new item to the destination box.
			tbox.options[tbox.options.length] = new Option(fbox.options[i].text, fbox.options[i].value);
		}
	}
}

function SelectToList(listBox, delim) {
	if(delim == null) delim = "~";
	var theList = "";
	//Loop through each of the items and add its value to the list.
	for (i = 0; i <= listBox.options.length-1; i++) { 
		//Add the value of each option to the list.
		theList += listBox.options[i].value;
		if(i != listBox.options.length-1) theList += delim; //Add a comma if we need it.
	}
	return theList;
}


/* ZEBRA TABLE STRIPING - Added by JWH, picked up from http://www.alistapart.com/articles/zebratables 6.28.04 */

 // this function is needed to work around 
 // a bug in IE related to element attributes
 function hasClass(obj) {
    var result = false;
    if (obj.getAttributeNode("class") != null) {
        result = obj.getAttributeNode("class").value;
    }
    return result;
 }
 
 var a = 0;
 function setClass(obj, className) {
 	var classString = "";
	if (obj.getAttributeNode("class") != null && obj.getAttributeNode("class") != "") {
		//alert("!");
        classString = obj.getAttributeNode("class").value+" "
    }	
	classString += className;

	a++;
	//if(a<5) alert(obj.getAttributeNode("class").value);
 	//obj.setAttribute("class", classString);
	obj.className = classString;
 }
 

 
function stripe(elem) {

	// the flag we'll use to keep track of 
	// whether the current row is odd or even
	var even = false;
	
	// if arguments are provided to specify the colours
	// of the even & odd rows, then use the them;
	// otherwise use the following defaults:
	var evenColor = arguments[1] ? arguments[1] : "#FFF";
	var oddColor = arguments[2] ? arguments[2] : "#EEE";
	var evenClass = "even";
	var oddClass = "odd";
	
	// obtain a reference to the desired table
	// if no such table exists, abort
	var table = elem;
	if (! table) { return; }
	
	var tableClasses = hasClass(table);
	var showSeparator;

	var tbodies;
	
	if(table.tagName.toLowerCase() == "tbody") {
		tbodies = new Array(table);
		showSeparator = (((tableClasses && tableClasses.indexOf("NoSeparator") == -1) || !tableClasses)
			|| hasClass(table.parentNode).indexOf("NoSeparator") == -1);
	} else {
		// by definition, tables can have more than one tbody
		// element, so we'll have to get the list of child
		// &lt;tbody&gt;s 
		tbodies = table.getElementsByTagName("tbody");
		showSeparator = (tableClasses.indexOf("NoSeparator") == -1);
	}

	// and iterate through them...
	for (var h = 0; h < tbodies.length; h++) {
		if(tbodies[h].parentNode != table && tbodies[h] != table) continue;
		// find all the &lt;tr&gt; elements... 
		var trs = tbodies[h].getElementsByTagName("tr");

		// ... and iterate through them
		for (var i = 0; i < trs.length; i++) {
			if(trs[i].parentNode != tbodies[h]) { continue;}
			myClasses = hasClass(trs[i]);

			// avoid rows that have a class attribute (unless it's "Same")
			// or backgroundColor style
			//if ( !myClasses && ! trs[i].style.backgroundColor && !(trs[i].style.display == "none")) {
			
			// No, forget that, just do all displayed TRs
			if (!(trs[i].style.display == "none")) {

				// If it's a "Same" row, make it the same color as the last row
				if(myClasses && myClasses.indexOf("Same") >= 0) {
					even = ! even;
				}
				
				// get all the cells in this row...
				var tds = trs[i].getElementsByTagName("td");
				
				
				// and iterate through them...
				for (var j = 0; j < tds.length; j++) {
					var mytd = tds[j];
					// avoid cells that have a class attribute
					// or backgroundColor style
					if (! hasClass(mytd) && ! mytd.style.backgroundColor && elem.className.indexOf('NoStripe') == -1
						&& mytd.parentNode == trs[i]) {
						//mytd.style.backgroundColor = even ? evenColor : oddColor;
						setClass(mytd, even ? evenClass : oddClass);
					}
				}
				// flip from odd to even, or vice-versa
				if(tds.length > 0)
					even =  ! even;
			}
		}
		
		var tbodyClasses = hasClass(tbodies[h]);
		//alert(tbodyClasses);
		var showTbodySeparator = (showSeparator && ((tbodyClasses && tbodyClasses.indexOf("NoSeparator") == -1) || !tbodyClasses));
		
		// While we're here, we'd also like to check whether a Separator is needed
		if(tbodies.length > 1 && showTbodySeparator) {
			var frag = document.createDocumentFragment();
		
			var separatorTr = document.createElement("tr");
			var separatorTd = document.createElement("td");
			
			if(document.all) {
				separatorTd.innerHTML = "<img src='/imgaes/blank.gif' height='1' width='1'>";
			} else {
				separatorTd.innerHTML = " ";
			}
			setClass(separatorTr, "Separator");
					
			separatorTr.appendChild(separatorTd);
			frag.appendChild(separatorTr);
			tbodies[h].appendChild(frag);
		}
	}
}

function findStripedTables() {
	var tables = document.body.getElementsByTagName("table");
	for (var i = 0; i < tables.length; i++) {
		if((tables[i].className.indexOf('TableBox') >= 0 || tables[i].className.indexOf('Menu') >= 0)) {
		 	stripe(tables[i]);
		}
	}
 }
 
 function findElementsWithClass(tag, classname, fn) {
 	var elements = document.getElementsByTagName(tag);
	for (var i = 0; i < elements.length; i++) {
		if(elements[i].className == classname) {
		 	fn(elements[i]);
		}
	}
 }

 function get(item){
 	return document.getElementById(item);
 }
 
function getRealLeft(el) {
    if (arguments.length==0) el = this;
    xPos = el.offsetLeft;
    tempEl = el.offsetParent;
    while (tempEl != null) {
        xPos += tempEl.offsetLeft;
        tempEl = tempEl.offsetParent;
    }
    return xPos;
}

function getRealTop(el) {
    if (arguments.length==0) el = this;
    yPos = el.offsetTop;
    tempEl = el.offsetParent;
    while (tempEl != null) {
        yPos += tempEl.offsetTop;
        tempEl = tempEl.offsetParent;
    }
    return yPos;
}

function submitForm(form) {
	if(form.onsubmit != undefined) {
		form.onsubmit();
	}
	form.submit();
}
/*function WriteRealFile(Path, NamePath){
	document.all.NamePath.value = document.all.Path.value;
}*/

function makeEditable(name) {
	// There are two objects - the item we're making editable, and the input in which we're storing the results
	objStatic = document.getElementById(name);
	
	objStatic.style.display = "none";
	//objInput.style.display = "inline";
	objInput = document.createElement(input);
	
	id = objInput.createAttribute(id);
	id = name + "Input";
	
	
	
	alert(name);
}

/*function styleAbbr() {
	var oldBodyText, newBodyText, reg
	if (isIE) {
		oldBodyText = document.body.innerHTML;
		reg = /<ABBR([^>]*)>([^<]*)<\/ABBR>/g;
		newBodyText = oldBodyText.replace(reg, '<ABBR $1><SPAN class=\"abbr\" $1>$2</SPAN></ABBR>');
		document.body.innerHTML = newBodyText;
	}
}*/

function createEditor (varName, value, width, height, toolbar) {
	if(width == null){width = "100%"};
	if(height == null){height = "300"};
	if(toolbar == null){toolbar = "Default"};
	var oFCKeditor = new FCKeditor( varName ) ;
	oFCKeditor.BasePath	= '/fckeditor/' ;
	oFCKeditor.Height	= height ;
	oFCKeditor.Width	= width ;
	oFCKeditor.ToolbarSet	= toolbar ;
	oFCKeditor.Value	= value ;
	oFCKeditor.Create() ;
}

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
  alert('Query Variable ' + variable + ' not found');
}