var color0, color1;
var page;
var calendar = null;

//var requiredFields = new Array("");
//var fieldNames = new Array("");

function checkRequiredFields(input, english)
{
	var fieldCheck = true; 
	var fieldsNeeded;
	
	if (english)
		fieldsNeeded = "\n Please fill data in fields listed below :\n\n　　"; 
	else
		fieldsNeeded = "\n 請輸入以下欄位的資料 :\n\n　　"; 

	if (!input)
		input = document.frm;
	for(var fieldNum=0; fieldNum < requiredFields.length; fieldNum++)
	{ 
		if ((input.elements[requiredFields[fieldNum]].value == "") || (input.elements[requiredFields[fieldNum]].value == " "))
		{ 
			fieldsNeeded += fieldNames[fieldNum] + "\n　　"; 
			fieldCheck = false; 
		}
	}
	if (fieldCheck == true) 
		return true;
	else
	{
		alert(fieldsNeeded); 
		return false;
	}
}

function checkBlank(obj, msg)
{
	if (obj.value.length == 0)
	{
		alert(msg);
		return true;
	}
	return false;
}

function checkPositive(obj, msg, msg2)
{
	if (msg2 != '' && checkBlank(obj, msg2))
		return false;
	var x = parseInt(obj.value);
	if (x < 0)
	{
		alert(msg);
		return true;
	}
	return false;
}

function checkZeroLength(obj, msg)
{
	if (obj.length == 0)
	{
		alert(msg);
		return true;
	}
	return false;
}

function checkMustOne(obj, msg)
{
	for (i = 0; i < obj.length; i++)
		if (obj[i].checked)
			break;
	if (i == obj.length)
	{
		alert(msg);
		return true;
	}
	return false;
}

function checkNotFirst(obj, msg)
{
	if (obj.selectedIndex == 0)
	{
		alert(msg);
		return true;
	}
	return false;
}

function choose(obj, value)
{
	for (i = 0; i < obj.length; i++)
	{
		if (obj.options[i].value == value)
		{
			obj.selectedIndex = i;
			break;
		}
	}
}

function chooseOne(obj, value)
{
	if (!obj.length)
		obj.checked = true;
	else
	{
		for (i = 0; i < obj.length; i++)
		{
			if (obj[i].value == value)
			{
				obj[i].checked = true;
				break;
			}
		}
	}
}

function chooseBox(obj, value)
{
	if (obj.value == value)
		obj.checked = true;
	else
		obj.checked = false;
}

function getSelect(obj)
{
	return obj.options[obj.selectedIndex].value;
}

function go(url)
{
	window.location.href = url;
}

function goback()
{
	window.location.href = 'index.php?fn=back';
}

function col0(obj, over)
{
	if (over)
	{
		color0 = obj.style.backgroundColor;
		obj.style.backgroundColor = '#66CCFF';
	}
	else
		obj.style.backgroundColor = color0;
}

function col1(obj, over)
{
	if (over)
	{
		color1 = obj.style.backgroundColor;
		obj.style.backgroundColor = '#66CCFF';
	}
	else
		obj.style.backgroundColor = color1;
}

// Calendar
function selectHandler(cal, date)
{
  cal.sel.value = date;
  if (cal.dateClicked)
    cal.callCloseHandler();
}

function closeHandler(cal)
{
  cal.hide();
  calendar = null;
}

function showCalendar(obj)
{
  if (calendar != null)
    calendar.hide();
  else
	{
    var cal = new Calendar(0, null, selectHandler, closeHandler);
    cal.showsTime = false;
    cal.showsOtherMonths = true;
    calendar = cal;
	var d = new Date();
	var y = d.getFullYear();
    cal.setRange(y, y + 4);
    cal.create();
  }
  calendar.setDateFormat('%Y-%m-%d');
  calendar.parseDate(obj.value);
  calendar.sel = obj;
  calendar.showAtElement(obj.nextSibling, "Br");
}