// last modified 2005/05/27
function MM_openBrWindow(theURL,winName,features) {
  var win = window.open(theURL,winName,features);
  win.focus();
}

function setTitle(newTitle){
	parent.document.title = newTitle;
	document.title = newTitle;
}

function checkInString(instr){
	for (i = 0; i < instr.value.length; i++){
        c = instr.value.charAt(i);
        if (c == '"' || c == '<' || c == '>')
        {
          alert("You have used invalid characters.\nThese invalid characters are: \", <, >.\n");
          instr.focus();
          instr.select();
          return 0;
        }
    }

   return 1;
}

function selectTheRadioButton(radioName, radioNum, targetVal)
{
	for (i=0; i<radioNum; i++)
	{
		if (radioName[i].value == targetVal)
		{
			//radioName[i].defaultChecked = true;
			radioName[i].checked = true;
		}
	}
}

function saveInputValue(inputName, isChecked)
{
	if (isChecked)	inputName.value = "1";
	else			inputName.value = "0";
}

function selectTheDropdownEnt(selObj, targetVal) 
{
	for (i = 0; i < selObj.length; i ++)
	{
	    if (isNaN(targetVal))
		{
			if (selObj.options[i].value.toLowerCase() == targetVal.toLowerCase())
			{
				selObj.options[i].selected = true;
				break;
			}
		}
		else
		{
			if (selObj.options[i].value == targetVal)
			{
				selObj.options[i].selected = true;
				break;
			}
		}
	}
}

function updateDynSelOpt(x, aList)
{
	var cnt;

	cnt = 0;
	for (i = 0; i < aList.length; i ++) {
		if (aList[i][0])	cnt ++;
	}

	if (cnt != 0) {
		x.length = cnt;
		j = 0;
		for (i = 0; i < aList.length; i ++) {
			if (aList[i][0]) {
				x.options[j].text = aList[i][1];
				x.options[j].value = aList[i][2];
				j ++;
			}
		}
	}
	return cnt;
}

function checkPort(thisObj, defaultPort, servName)
{
	if (thisObj.value == defaultPort)
		return 0;
	if ((thisObj.value > 1024) && (thisObj.value <= 65535))
		return 0;
	alert(servName + " port must be " + defaultPort + " or from 1025 to 65535");
	thisObj.select();
	thisObj.focus();
	return -1;
}

function checkPortSimple(thisObj)
{
	if ((thisObj.value >= 0) && (thisObj.value <= 65535))
		return 0;
	alert("Port must be a number from 0 to 65535");
	thisObj.select();
	thisObj.focus();
	return -1;
}

function checkemail(input){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(input.value))
		return true;
	else{
		alert("Please input a valid email address!");
		input.focus();
		input.select();
		return false;
	}
}

function checkIPaddr(input)
{
	var filter=/\d+\.\d+\.\d+\.\d+/;
	if (!filter.test(input.value)){
		alert("Please enter a valid IP address!");
		input.focus();
		input.select();
		return -1;
	}
	input.value = input.value.match(filter)[0];
	subip = input.value.split(".");
	for (i = 0; i < subip.length; i ++)
	{
		if ((parseInt(subip[i]) > 255) || (parseInt(subip[i]) < 0 ))
		{
			alert("Please enter a valid IP address!");
			input.focus();
			input.select();
			return -1;
		}
	}
	
	return 0;
}

function checkFilenameString(instr){
  for (i = 0; i < instr.value.length; i++){
    c = instr.value.charAt(i);
    if (c == '"' || c == '<' || c == '>' || c == '/' || c == ':' || c == '*' || c == '?' || c == '|' || c == '\\')
    {
       alert("You have used invalid characters. These invalid characters are: \\, /, :,*, ?, \", <, >, |.");
       instr.focus();
       instr.select();
       return 0;
    }
  }
  return 1;
}

function checkNumRange(thisObj, up, down, msg)
{
	if ((thisObj.value >= down) && (thisObj.value <= up))
		return 0;
	alert(msg);
	thisObj.select();
	thisObj.focus();
	return -1;
}

function checkHHMM(input)
{
	var filter=/\d\d:\d\d/;
	if (!filter.test(input.value)){
		alert("Please enter a valid time [hh:mm], like 12:00");
		input.focus();
		input.select();
		return -1;
	}
	input.value = input.value.match(filter)[0];
	sub_item = input.value.split(":");
	if ((parseInt(sub_item[0]) >= 24) || (parseInt(sub_item[1]) >= 60))
	{
		alert("Please enter a valid time [hh:mm], like 12:00");
		input.focus();
		input.select();
		return -1;
	}
	
	return 0;
}

// For debug
function showMe(mine, target)
{
	mine.value = target.value;
}


