addEvent(window, 'load', formatScreen);

function formatScreen() {
	initLinks();	// popup windows and print windows
}

// redefining default features
var _POPUP_FEATURES = 'location=0,scrollbars=1,resizable=1,statusbar=0,menubar=0,width=800,height=600';

function raw_popup(url, target, features) {
    // pops up a window containing url optionally named target, optionally having features
    if (isUndefined(features)) features = _POPUP_FEATURES;
    if (isUndefined(target  )) target   = '_blank';
    var theWindow = window.open(url, target, features);
	if (theWindow.opener == null) {
		theWindow.opener = self;
	}
	// tool bar = yes?

    theWindow.focus();
    return theWindow;
}

function link_popup(src, features) {
    // to be used in an html event handler as in: <a href="..." onclick="link_popup(this,...)" ...
    // pops up a window grabbing the url from the event source's href
    return raw_popup(src.getAttribute('href'), src.getAttribute('target') || '_blank', features);
}
/*
function event_popup(e) {
    // to be passed as an event listener
    // pops up a window grabbing the url from the event source's href
    link_popup(e.currentTarget);
    e.preventDefault();
}
*/

var tempLink;
var tempHref;
function event_popup_features(features) {
    // generates an event listener similar to event_popup, but allowing window features
    return function(e) { 
    	link_popup(e.currentTarget, features); 
    	if (e.preventDefault) {
			e.preventDefault();

    		// Safari will end up in here but won't actually do anything
			if (BrowserDetect.browser.toLowerCase() == 'safari') {
				tempLink = e.currentTarget;
				tempHref = tempLink.href;	// store the original link
				tempLink.href = 'javascript:void(0);';
				setTimeout('tempLink.href=tempHref; tempHref=null; tempLink=null;',100);	// set it back
			}
    	}
    }
}

function initLinks() {
	mlisten('click', getElementsByClass('popUp','a'), event_popup_features('location=0,scrollbars=1,resizable=1,statusbar=0,menubar=1,width=800,height=600') );
	mlisten('click', getElementsByClass('littlePop','a'), event_popup_features('location=0,scrollbars=1,resizable=1,statusbar=0,menubar=0,width=600,height=400')  );
	mlisten('click', getElementsByClass('printLink','a'), printScreen);
}

function printScreen() {
	window.print();
}

<!--
// This function verifies that the length of the text in a textarea is less than maxLength.
var global_textArray = null;
function checkLength(textArray, maxLength) {
		if (textArray.value.length > maxLength) {
			alert("Your text is " + textArray.value.length + " characters! " + "Please limit your input to " + maxLength + " characters!");
			global_textArray = textArray;
			window.setTimeout("global_textArray.focus()",1);
			return false;
		} 
		return true;
}

// This function launches a new browser window
function openWindow(url,name,win_width,win_height) {
popupWin = window.open(url,name,'toolbar,scrollbars,resizable,width=' + win_width + ',height=' + win_height)
}

// This function checks all textarea fields within thisForm to make sure they don't exceed 2000 char limit
function checkAllTextarea(thisForm) {
    var thisElement;
    var i;
    for (i = 0; i < thisForm.elements.length; i++) {
        thisElement = thisForm.elements[i];
        if (thisElement.type == "textarea") {
        	if ((thisElement.name == "x_custom_field_value") && (thisElement.rows == 5)) {
                if (thisElement.value.length > 2000) {
                    alert("Your text exceeded 2000 characters! Please limit your input and try submitting again.");
                    return false;
                }
            }
        }
    }
    return true;
}

function validate(checkboxArray, message){
var selected = 0;
var i = 0;
if (checkboxArray.length) {
	while (selected == 0 && i < checkboxArray.length) {
		if (checkboxArray[i].checked)
			selected = 1;
		i++;
	}
} else {
	if (checkboxArray.value != null)
		selected = 1;
}
if (selected != 1) {
	alert(message);
	return false;
} else
	return true;
}

// This function is written for AOL file upload to refresh the file names
// callerAnchor - name of anchor/link of the upload field which opened the upload window
function close_and_refresh(callerAnchor) {
     var secform;
     if (opener.document.sectionform) {
    	  if (callerAnchor) {
    	  		opener.document.sectionform.action = opener.document.sectionform.action + "#" + callerAnchor;
    	  }
          secform = opener.document.sectionform;
          secform.ignore_errors.value = "S";
          secform.submit();
     }
     self.close();
}

function togglediv(e,status) {
	if (document.getElementById || document.all || document.layers) {
		//basic support for DHTML - IE5+ or NS6+
		if (status == 'on') {
		    document.getElementById(e).style.display = '';
		} else if (status == 'off') {
		    document.getElementById(e).style.display = 'none';	
		} else {
			if (document.getElementById(e).style.display == 'none') {
		    	document.getElementById(e).style.display = '';
			} else {
		    	document.getElementById(e).style.display = 'none';	
			}
		}
	} 
//	else if (document.layers) { }
}

function toggleClass(c,status) {
	var obj = getElementsByClass(c);

	for (var i = 0; i < obj.length; i++) {
		if (status == 'on') {
		    obj[i].style.display = '';
		} else if (status == 'off') {
		    obj[i].style.display = 'none';	
		} else {
			if (obj[i].style.display == 'none') {
		    	obj[i].style.display = '';
			} else {
		    	obj[i].style.display = 'none';	
			}
		}
	} 
}

// helper functions for user-defined lists
function synchUserDefinedList(labelPrefix) {
	if (document.getElementById)
		{
			// grab the three components
			text = document.getElementById(labelPrefix + '.entry');
			select = document.getElementById(labelPrefix + '.select');
			hidden = document.getElementById(labelPrefix);

			// blank out hidden before building the new string
			hidden.value = "";
			for (var i = 0; i < select.length; i++) {
				if (i != 0) {
					hidden.value = hidden.value + String.fromCharCode(10) + select.options[i].text;
				} else {
					hidden.value = select.options[i].text;
				}
  			}
  		}
}

function addToList(labelPrefix)
{
	if (document.getElementById)
		{
			text = document.getElementById(labelPrefix + '.entry');
			select = document.getElementById(labelPrefix + '.select');

			// create new option and add to other list
			if (text.value && text.value.length > 0) {
				insertOption = new Option(text.value);
				select.options[select.length] = insertOption;

				// clear out option from text box
				text.value = '';

				// add to hidden list form element
				synchUserDefinedList(labelPrefix);
			}
		}
	else
		alert("Element access by ID didn't work");
}

function removeFromList(labelPrefix)
{
	if (document.getElementById)
		{
			select = document.getElementById(labelPrefix + '.select');

			for (var i = select.options.length - 1; i >= 0; i--) {
				if (select.options[i].selected) {
					select.options[i] = null;
				}
  			}
			// remove from hidden list form element
			synchUserDefinedList(labelPrefix);
		}
	else
		alert("Element access by ID didn't work");
}

function getOffsetTop(cgObject) {
    if (cgObject.offsetParent) {
        return cgObject.offsetTop + getOffsetTop(cgObject.offsetParent);
    } else {
        return cgObject.offsetTop;
    }   
}

function getOffsetLeft(cgObject) {
    if (cgObject.offsetParent) {
        return cgObject.offsetLeft + getOffsetLeft(cgObject.offsetParent);
    } else {
        return cgObject.offsetLeft;
    }
}
function selectAll(checkboxArray) {
        if (checkboxArray) {
                if (checkboxArray.length) {
                        for (var i=0; i<checkboxArray.length; i++)
                                checkboxArray[i].checked = true;
                } else if (checkboxArray) {
                        checkboxArray.checked = true;
                }
        }
}
function selectNone(checkboxArray) {
        if (checkboxArray) {
                if (checkboxArray.length) {
                        for (var i=0; i<checkboxArray.length; i++)
                                checkboxArray[i].checked = false;
                } else if (checkboxArray) {
                        checkboxArray.checked = false;
                }
        }
}
