var calWin; //a window handle for the calendar window.
var focusElement; //the element that has the focus.
function recordFocus(str){
	focusElement = str;
}

function focusLogin(){
	if (document.getElementById('loginform').username){
		if (focusElement != "password"){
			document.getElementById('loginform').username.focus;
		}
	}
}

function submitBlast(){
	if (document.getElementById("frmEmail")){
		var emailWin = window.open("", "blastEmail", "width=640,height=480,menubar=no,statusbar=no,scrollbars=yes");
		document.getElementById("frmEmail").submit();
	}
}

function moveItem(srcBox, destBox) {
	var arrDest = new Array();
	var arrSort	= new Array();
	
	//for each item in the destination, put it in the sort arr
	for (i = 0; i < destBox.options.length; i++) {
		arrSort[arrSort.length] = destBox.options[i].text + "~|~" + destBox.options[i].value;
		arrDest[destBox.options[i].value] = true;
	}
	
	//for each item in the source, put it in the sort arr
	for (i = 0; i < srcBox.options.length; i++) {
		arrSort[arrSort.length] = srcBox.options[i].text + "~|~" + srcBox.options[i].value;
		if (srcBox.options[i].selected && srcBox.options[i].value != ""){
			arrDest[srcBox.options[i].value] = true;
		}
	}

	arrSort.sort(theSortFunction);
	
	//for each item in the sort, if its listed in dest, move it there, otherwise move it back to source.
	srcBox.length = 0;
	destBox.length = 0;
	s = 0;
	d = 0;
	for (var i = 0; i < arrSort.length; i++) {
		if (arrDest[arrSort[i].substr(arrSort[i].indexOf('~|~') + 3, arrSort[i].length)] == true){
			var no = new Option();
			no.text = arrSort[i].substr(0, arrSort[i].indexOf('~|~'));
			no.value = arrSort[i].substr(arrSort[i].indexOf('~|~') + 3, arrSort[i].length);
			destBox[d] = no;
			d++;
		} else {
			var no = new Option();
			no.text = arrSort[i].substr(0, arrSort[i].indexOf('~|~'));
			no.value = arrSort[i].substr(arrSort[i].indexOf('~|~') + 3, arrSort[i].length);
			srcBox[s] = no;
			s++;
		}
	}
}
 
function theSortFunction(a, b) {
   if (a.toLowerCase() == b.toLowerCase()) {
      return 0;
   } else {
      return (a.toLowerCase() > b.toLowerCase() ? 1 : -1);
   }
}

function dateAdd (sInterval, iNum, dDat){
	if (!sInterval || iNum == 0) return false;
	var d = new Date(dDat);
	switch (sInterval.toLowerCase()){
		case "ms":
			d.setMilliseconds(d.getMilliseconds() + iNum);
			break;
		case "s":
			d.setSeconds(d.getSeconds() + iNum);
			break;
		case "n":
			d.setMinutes(d.getMinutes() + iNum);
			break;
		case "h":
			d.setHours(d.getHours() + iNum);
			break;
		case "d":
			d.setDate(d.getDate() + iNum);
			break;
		case "m":
			d.setMonth(d.getMonth() + iNum);
			break;
		case "y":
			d.setFullYear(d.getFullYear() + iNum);
			break;
	}
	return d;
}
function generateRandom(pintLength){
	var rnd = Math.random();
	var out = "";
	var val;
	var i;
	
	for (i = 1; i <= pintLength; i++){
		rnd = Math.random();
		val = Math.floor((2 - 1 + 1) * rnd + 1);
		if (val == 1){
			out = out + String.fromCharCode(Math.floor((90 - 65 + 1) * rnd + 65));
		} else {
			out = out + String.fromCharCode(Math.floor((57 - 48 + 1) * rnd + 48));
		}
	}
	return out.toLowerCase();
}
