function raw_popup(url, target, features) {
	var theWindow = window.open(url, target, features);
  theWindow.focus();
  return theWindow;
}

function openWindow(src, windowType) {
	var features = "";

  	switch (windowType) {
		case "task":
			features = "width=760,height=580,scrollbars=YES,toolbar=NO,resizable=NO";
			target = "popUp"; //always opens in the same window. use _blank for a new one
			break;
		case "simple":
			features = "width=350,height=400,scrollbars=YES,toolbar=NO,resizable=YES";
			target = "popUp"; //always opens in the same window. use _blank for a new one
			break;
		case "medium1":
			features = "width=400,height=300,scrollbars=YES,toolbar=NO,resizable=YES";
			target = "popUp"; //always opens in the same window. use _blank for a new one
			break;
		case "medium2":
			features = "width=570,height=300,scrollbars=YES,toolbar=NO,resizable=YES";
			target = "popUp"; //always opens in the same window. use _blank for a new one
			break;
		case "medium3":
			features = "width=820,height=360,scrollbars=YES,toolbar=NO,resizable=YES";
			target = "popUp"; //always opens in the same window. use _blank for a new one
			break;
		case "wide":
			features = "width=1000,height=500,scrollbars=YES,toolbar=NO,resizable=YES";
			target = "popUp"; //always opens in the same window. use _blank for a new one
			break;
		case "long":
			features = "width=760,height=680,scrollbars=YES,toolbar=NO,resizable=NO";
			target = "popUp"; //always opens in the same window. use _blank for a new one
			break;
		default:
			features = "width=450,height=500,scrollbars=NO,toolbar=NO,resizable=YES";
			target = "_blank";
 	}
 	if (typeof(src) == 'string'){
 		//alert(src+": "+target+": "+features);
		return raw_popup(src, target, features);
 	} else {
		return raw_popup(src.getAttribute('href'), src.getAttribute('target') || target, features);
 	}
}

//open a task window triggered from a drop down
//use a ? to separate the window type from the page to load in the value field
//e.g. home?wide opens the home page in the window type 'wide'
function openTask(obj) {
	var task = obj.value;
	if(task == '') return; //don't go further if the "select task..." label is chosen 
	var taskInfo = task.split('?');
	var winType = 'task';
	if(taskInfo.length != 1) {
		var winType = taskInfo[1];
	}
	openWindow('index.cfm?action='+taskInfo[0], winType);
	//reset the selection of the drop down
	obj.value = '';
}
  
//<a class="popLk" href="#baseLink#remember" onclick="openWindow(this);return false">Link text</a>

/* 
 * Cross-browser event handling, by Scott Andrew
 */
function addEvent(element, eventType, lamdaFunction, useCapture) {
    if (element.addEventListener) {
        element.addEventListener(eventType, lamdaFunction, useCapture);
        return true;
    } else if (element.attachEvent) {
        var r = element.attachEvent('on' + eventType, lamdaFunction);
        return r;
    } else {
        return false;
    }
}

//clear out the content of a field
addEvent(window, 'load', initTextArea, false);

/**
 * clear given text in a text field when clicked
 * this is not persistent between pages
 * text field must have class="cleardefault"
 */
 
function initText() {
    var formInputs = document.getElementsByTagName('input');
    for (var i = 0; i < formInputs.length; i++) {
        var theInput = formInputs[i];
        
        if (theInput.type == 'text' && theInput.className.match(/\bcleardefault\b/)) {  
            /* Add event handlers */          
            addEvent(theInput, 'focus', clearDefaultText, false);
            addEvent(theInput, 'blur', replaceDefaultText, false);
            /* Save the current value */
            if (theInput.value != '') {
                theInput.defaultText = theInput.value;
            }        }
    }
}

/**
 * clear given text in a textarea when clicked
 * Specify content in var defaultText below for persistent use between page loads
 * textarea must have class="cleardefault"
 */
 
var defaultText = 'Notepad, enter text here.';
function initTextArea() {
    var formInputs = document.getElementsByTagName('textarea');
    for (var i = 0; i < formInputs.length; i++) {
        var theInput = formInputs[i];

        if (theInput.type == 'textarea' && theInput.className.match(/\bcleardefault\b/)) {
        //alert("textara");
            /* Add event handlers */          
            addEvent(theInput, 'focus', clearDefaultText, false);
            addEvent(theInput, 'blur', replaceDefaultText, false);
			theInput.defaultText = defaultText;
  			/* Set the field's content */
            if (theInput.value == '') {
            	theInput.value = defaultText;
            }
        }
    }
}

function clearDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == target.defaultText) {
        target.value = '';
    }
}

function replaceDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == '' && target.defaultText) {
        target.value = target.defaultText;
    }
}