function restore() {
	parent.moveTo(0,0);
	parent.window.focus();
}

function Back(){
	history.go(-1)
}


function SubmitForm(tab){
	document.data.TabClicked.value = tab;
	document.data.submit();
}


function doSubmit(){
	document.data.submit();
}

function move(fromField, toField, len){
	//Only do it on numbers
	var key = event.keyCode;
	if((key >= 48 && key <= 57) || (key >=96 && key <=105)){
		if(document.all(fromField).value.length == len){
			document.all(toField).focus();
			document.all(toField).select();
		}
	}
}

/**************************************************************
                    START DROP DOWN MENUS
**************************************************************/

//dropdowns
droplayer = new Array();
droplayer[0] = "drop1";

//simple browser check
v4 = (parseInt(navigator.appVersion) >= 4 && parseInt(navigator.appVersion) <= 5) ? 1 : 0;
ie = (document.all && v4) ? 1 : 0;
ns = (document.layers && v4) ? 1 : 0;

// default current layer to -1
currentLayer = -1;

//code for drops
function showdrop(layerIndex){
	currentLayer = layerIndex; 
	hideall();
	if(ie) eval(droplayer[layerIndex] + '.style.visibility="visible"');
	if(ns) eval('document.' + droplayer[layerIndex] + '.visibility="show"');
}

function hidedrop(){
	currentLayer = -1;
	setTimeout('hideall()', 100);
}

function hideall(){
	for(i=0; i < droplayer.length; i++){
		if(ie && currentLayer != i)
			eval(droplayer[i] + '.style.visibility="hidden"');
		if(ns && currentLayer != i)
			eval('document.' + droplayer[i] + '.visibility="hide"');
	}
}

/**************************************************************
                    END DROP DOWN MENUS
**************************************************************/


var cal = null;
function showCalendar(field){
	var left, top, oRect;
	if(checkDate(document.all(field).value)){
		if(window.navigator.appName == "Microsoft Internet Explorer"){
			oRect = document.all(field).getBoundingClientRect();
			left = window.screenLeft + oRect.left + 2;
			top = window.screenTop + oRect.bottom + 2;
		}
		else{
			left = (screen.width / 2) - (134 / 2);
			top = (screen.height / 2) - (160 / 2);
		}
		cal = window.open("../include/calendar_window.asp?Field=" + field + "&DateEntered=" + document.all(field).value, "calendar", "width=134,height=160,left=" + left + ",top=" + top + ",minimize=no,resizable=0,scrollbars=0,status=0");
	}
	else
		alert("You must enter a valid date.");
}
	
function checkDate(dateString){
	if(dateString != "" && isNaN(Date.parse(dateString)))
		return false;
	else
		return true;
			
}
	
function closeCalendar(){
	if(cal != null && !cal.closed)
		cal.close();
}



function moveOption(cboFrom, cboTo, cmdFrom, cmdTo){
	var oOption = document.createElement("OPTION");
	oOption.value = document.all(cboFrom).options[document.all(cboFrom).selectedIndex].value;
	oOption.text = document.all(cboFrom).options[document.all(cboFrom).selectedIndex].text;
	document.all(cboTo).add(oOption);
	document.all(cboTo).selectedIndex = document.all(cboTo).options.length - 1;
	document.all(cmdTo).disabled = false;
	document.all(cboFrom).remove(document.all(cboFrom).selectedIndex)
	document.all(cboFrom).selectedIndex = 0;
	if(document.all(cboFrom).selectedIndex == null || document.all(cboFrom).selectedIndex < 0)
		document.all(cmdFrom).disabled = true;
	document.all('HasChanged').value = 'Yes';
}


function rememberList(fldIDs, cboFrom, cboTo, cmdFrom, cmdTo){
	var IDs = document.all(fldIDs).value;
	if(IDs != null && IDs != ''){
		if(IDs.length > 0){
			var lstOptions = document.all(cboFrom)
			var j = 0
			while(j < lstOptions.length){
				var tmpStr = IDs;
				var strt = 0;
				var end = tmpStr.indexOf(',')
				if(end < 0) end = tmpStr.length;
				while(strt <= end){
					var id = tmpStr.substring(strt, end);
					if(id == lstOptions.options[j].value){
						lstOptions.selectedIndex = j;
						moveOption(cboFrom, cboTo, cmdFrom, cmdTo);
						j--;
						break;
					}
					strt = end + 1;
					end = tmpStr.indexOf(',',strt);
					if(end < 0) end = tmpStr.length;
				}
				j++;
			}
		}
	}
}


function saveIDs(cboFrom, cboTo, fldFromIDs, fldToIDs){
	var i = 0;
	var selVals = "";
	for(i=0;i<document.all(cboTo).options.length;i++){
		selVals = selVals + document.all(cboTo).options[i].value;
		if((i + 1) < document.all(cboTo).options.length) selVals = selVals + ",";
	}
	document.all(fldToIDs).value = selVals;
	selVals = "";
	for(i=0;i<document.all(cboFrom).options.length;i++){
		selVals = selVals + document.all(cboFrom).options[i].value;
		if((i + 1) < document.all(cboFrom).options.length) selVals = selVals + ",";
	}
	document.all(fldFromIDs).value = selVals;
	document.data.submit();
}


function prefillContent(){
	if(document.data.txtContent.value != '')
		Content.innerHTML = document.data.txtContent.value;
}




function updateDependentCombo(srcComboName, depListName, depComboName, firstOpt, selIDFieldName){
	var selID = document.all(srcComboName).value;
	var depList = document.all(depListName + selID);
	var preSelectedID = -1
	
	clearCombo(depComboName, firstOpt);
	
	if(selIDFieldName != null && selIDFieldName != '' && selIDFieldName != undefined)
		preSelectedID = document.all(selIDFieldName).value;
		
	if (depList != null){
		if (depList.length>0){
			for (i=0; i < depList.length; i++){
				var oOption = document.createElement("OPTION");
				var oStr = depList(i).value;
				var startPos = oStr.search(";");
					
				oOption.text = oStr.substr(startPos + 1, oStr.length - startPos);
				oOption.value = oStr.substr(0, startPos);
					
				document.all(depComboName).add(oOption);
				
				if(preSelectedID == oOption.value){
					if(firstOpt != null && firstOpt != '' && firstOpt != undefined)
						document.all(depComboName).selectedIndex = (i+1);
					else
						document.all(depComboName).selectedIndex = i;
				}
			}
		}
		else{
			var oOption = document.createElement("OPTION");
			var oStr = depList.value;
			var startPos = oStr.search(";");
					
			oOption.text = oStr.substr(startPos + 1, oStr.length - startPos);
			oOption.value = oStr.substr(0, startPos);
					
			document.all(depComboName).add(oOption);
			
			if(preSelectedID == oOption.value){
				if(firstOpt != null && firstOpt != '' && firstOpt != undefined)
					document.all(depComboName).selectedIndex = 1;
				else
					document.all(depComboName).selectedIndex = 0;
			}
		}
			
		document.all(depComboName).disabled = false;
	}
}
	
function clearCombo(comboName, firstOpt){
	var combo = document.all(comboName);
	if (combo.length > 0){
		for (i=0; i < combo.length; i++){
			combo.options.remove(i);
			i--;
		}
	}
	if(firstOpt != null && firstOpt != '' && firstOpt != undefined){
		var oOption = document.createElement("OPTION");
		var startPos = firstOpt.search(";");
		oOption.text = firstOpt.substr(startPos + 1, firstOpt.length - startPos);
		oOption.value = firstOpt.substr(0, startPos);
		combo.add(oOption);
		combo.disabled = true;
	}
}



/*************** START HTML Editor Stuff *************/
var usesTextSelection = false
var selTextRange;

function showHTMLDiv(imgBtn, divToShow, usesTextSel){
	var oRect = document.all(imgBtn).getBoundingClientRect();
	document.all(divToShow).style.left = oRect.right - document.all(divToShow).width + 2;
	document.all(divToShow).style.top = oRect.top - document.all(divToShow).height;
	document.all(divToShow).style.visibility = 'visible';
	
	usesTextSelection = usesTextSel;
	if(usesTextSelection) selTextRange = Content.document.selection.createRange();
}


var divLeft = 0;
var divTop = 0;
var x = 0;
var y = 0;
var divID = '';
function startDrag(id) {
	divID = id;
	divLeft = parseInt(document.getElementById(divID).style.left);
	divTop = parseInt(document.getElementById(divID).style.top);
	x = event.clientX;	
	y = event.clientY;
	document.getElementById(divID).style.cursor = "move";
	if(usesTextSelection) selTextRange.select();
}
		
function doDrag() {
	if(divID != ''){
		var newx = divLeft + event.clientX - x;
		var newy = divTop + event.clientY - y;
		document.getElementById(divID).style.left = newx;
		document.getElementById(divID).style.top = newy;
		document.getElementById(divID).style.cursor = "move";
	}
}
	
function stopDrag(){
	if(divID != ''){
		document.getElementById(divID).style.cursor = "auto";
		divID = '';
		if(usesTextSelection) selTextRange.select();
	}
}	
document.onmousemove = doDrag;
//document.onmouseup = stopDrag;
/*************** END HTML Editor Stuff ***************/

