function moveCat(fbox, tbox) {
	var arrFbox = new Array();
	var arrTbox = new Array();
	var arrLookup = new Array();
	var i;
	var iSelInd;

	iSelInd = fbox.selectedIndex;
	
	if ((fbox.options[0].text != 'No Categories') && (fbox.options[0].text != 'No Topics'))
	{
		for (i = 0; i < tbox.options.length; i++) {
			arrLookup[tbox.options[i].text] = tbox.options[i].value;
			/*alert(fbox.options[fbox.selectedIndex].text);
			alert(tbox.options[i].text);*/
			if (tbox.options[i].text != fbox.options[fbox.selectedIndex].text)
			{
				arrTbox[i] = tbox.options[i].text;
			}
		}
		
		var fLength = 0;
		var tLength = arrTbox.length;
		for(i = 0; i < fbox.options.length; i++) {
			arrLookup[fbox.options[i].text] = fbox.options[i].value;
			if (fbox.options[i].selected && fbox.options[i].value != "") {
				arrTbox[tLength] = fbox.options[i].text;
				tLength++;
			}
			arrFbox[fLength] = fbox.options[i].text;
			fLength++;
		}

		arrFbox.sort();
		arrTbox.sort();
		fbox.length = 0;
		tbox.length = 0;
		var c;

		for(c = 0; c < arrFbox.length; c++) {
			var no = new Option();
			no.value = arrLookup[arrFbox[c]];
			no.text = arrFbox[c];
			fbox[c] = no;
		}

		fbox.selectedIndex = iSelInd;
		
		for(c = 0; c < arrTbox.length; c++) {
			var no = new Option();
			if (arrLookup[arrTbox[c]] != undefined)
			{
			no.value = arrLookup[arrTbox[c]];
			no.text = arrTbox[c];
			tbox[c] = no;
			}
		}
	}
}

function changeOptions(value, form)
{
	var sSource;
	var oSource;
	sSource = "sel" + value;
	oSource = document.getElementById(sSource);
	form.selCatSrc.length = 0;
	for (i=0;i<oSource.length;i++)
	{
		form.selCatSrc.options[i] = new Option(oSource.options[i].text, oSource.options[i].value);
	}
}

function changeOptionsSearch(value, form)
{
	var sSource;
	var oSource;
	sSource = "sel" + value;
	oSource = document.getElementById(sSource);
	form.ARCH_Category_List.length = 0;
	for (i=0;i<oSource.length;i++)
	{
		form.ARCH_Category_List.options[i] = new Option(oSource.options[i].text, oSource.options[i].value);
	}
}

function changeTopics(value, form)
{
	var sSource;
	var oSource;
	sSource = "topic" + value;
	oSource = document.getElementById(sSource);
	form.selTopicSrc.length = 0;
	for (i=0;i<oSource.length;i++)
	{
		form.selTopicSrc.options[i] = new Option(oSource.options[i].text, oSource.options[i].value);
	}
}


function removeCat(box)
{
	var arrItems = new Array();
	var i;
	
	for (i=0;i<box.options.length;i++)
	{
		var no = new Option;
		if (box.options[i].selected != true)
		{
			no.text = box.options[i].text;
			no.value = box.options[i].value;
			arrItems[i] = no;
		}
	}
	
	arrItems.sort();
	box.length = 0;
	
	for (i=0;i<arrItems.length;i++)
		box.options[i] = arrItems[i];
}

function newSelectAll(form)
{
	form.lstTopicID.value = "";
	form.lstTopicText.value = "";
	for (i=0; i<form.selTopicTrg.length;i++)
	{
		form.selTopicTrg.options[i].selected = true;
		form.lstTopicID.value = form.lstTopicID.value + form.selTopicTrg.options[i].value + ";";
		form.lstTopicText.value = form.lstTopicText.value + form.selTopicTrg.options[i].text + ";";
	}

	form.lstCatID.value = "";
	form.lstCatText.value = "";
	for (i=0; i<form.selCatTrg.length;i++)
	{
		form.selCatTrg.options[i].selected = true;
		form.lstCatID.value = form.lstCatID.value + form.selCatTrg.options[i].value + ";";
		form.lstCatText.value = form.lstCatText.value + form.selCatTrg.options[i].text + ";";
	}
}

function isDate(sInput)
{
	var oDate = new RegExp;
	oDate = /^\d{2}[/]{1}\d{2}[/]{1}\d{4}$/;
	if ((sInput.substring(0,2) > 12) || (sInput.substring(3,5) > 31))
		return 0;
	var x = new Date(sInput);
	if (x.getDate() != sInput.substring(3,5))
		return 0;
	return CheckReg(oDate, sInput);
}

//new time validation function to avoid reg exp error on macintosh
function newIsTime(sInput)
{
	var blnGood;
	var hTen, hOne, sTen, sOne;

	if (sInput.length != 5)
		return false;
	if (sInput.charAt(2) != ":")
		return false;
	hTen = parseInt(sInput.charAt(0));
	hOne = parseInt(sInput.charAt(1));
	sTen = parseInt(sInput.charAt(3));
	sOne = parseInt(sInput.charAt(4));
	if (hTen > 2)
		return false;
	if (hTen == 2)
	{
		if (hOne > 3)
			return false;
	}
	if (sTen > 5)
		return false;

	return true;

}

function ValidateForm(form){
	if (isDate(form.edition_date.value) == false){
		alert("Please enter a valid date.\ni.e. 'MM/DD/YYYY'")
		form.edition_date.focus();
		return false;
	}
	if (newIsTime(form.edition_time.value) == false){
		alert("Please enter a valid time including the leading zero.\ni.e.'HH:MM' 00:00~23:59")
		form.edition_time.focus();
		return false;
	}
	if (form.headline.value == ""||form.text.value==""){
	 	alert("Headline and Story cannot be blank.");
	 	form.headline.focus();
	 	return false;
	}
	//Previously omitted checks on OH
	if (form.lstCatText.value == "")
	{
		alert("You must select at least one category");
		form.selCatSrc.focus();
		return false;
	}
	if (form.lstTopicText.value == "")
	{
		alert("You must select at least one topic");
		form.selTopicSrc.focus();
		return false;
	}
	return true;
}			

function ValidateArchiveForm(form){
	if (form.lstCatText.value == "")
	{
		alert("You must select at least one category");
		form.selCatSrc.focus();
		return false;
	}
	if (form.lstTopicText.value == "")
	{
		alert("You must select at least one topic");
		form.selTopicSrc.focus();
		return false;
	}
	form.submit();
	return true;
}			

function CheckReg(oRegExp, sInput){
	oRegExp.IgnoreCase = true
	if(oRegExp.test(sInput)){
		return true;
	}
	//else if (/^[\s]*$/.test(sInput)){// if empty, return true too.
	//	return true;
	//}
	else{
		return false;
	}
}

function AddPicture(){
	//Change the page to which is submitted if user click the add_pic button.
	var oForm;
	oForm = document.getElementById('frmDNEdit');
	oForm.action = "add_pic.asp"
	oForm.submit()
}

function openWindow(url, w, h, loct, locl) {
	var options = "width=" + w + ",height=" + h + ",top=" + loct + ",left=" + locl + ",";
	options += "resizable=yes,scrollbars=yes,status=no,";
	options += "menubar=no,toolbar=no,location=no,directories=no";
	var newWin = window.open(url, 'newWin', options);
	newWin.focus();
}

function openCompanyWindow()
{
	var winH, winW;
	winH = 290;
	winW = 500;
	window.open('/common_Scripts/Taxonomy/NewsAdmin/compWinAdd.asp', 'win1', 'height=' + winH + ', width=' + winW + ', menu=yes, toolbars=yes');
}

function openRemovalWindow()
{
	var winH, winW;
	var x;
	x = document.getElementById("compName");

	winH = 180;
	winW = 500;
	
	if (x.value == '')
		alert("There are no companies to remove.");
	else
		window.open('/common_Scripts/Taxonomy/NewsAdmin/compWinDel.asp', 'win1', 'height=' + winH + ', width=' + winW + ', menu=no, toolbars=no');
}

function favoriteSelectAll(form)
{
	form.lstTopicID.value = "";
	for (i=0; i<form.selTopicTrg.length;i++)
	{
		form.selTopicTrg.options[i].selected = true;
		form.lstTopicID.value = form.lstTopicID.value + form.selTopicTrg.options[i].value + ";";
	}
	form.submit();
}

function ViewPhoto(url, w, h, loct, locl) {
//open a separate window to show the actual size of the article's pictures

  var options = "width=" + w + ",height=" + h + ",top=" + loct + ",left=" + locl + ",";
  options += "resizable=yes,scrollbars=yes,status=no,";
  options += "menubar=no,toolbar=no,location=no,directories=no";
  var newWin = window.open(url, 'newWin', options);
  newWin.focus();
  }
