var splitIndex = 0;
var splitArray = new Array();

function emailWM(t) {
  if (t == "1") {
    navigate('mai' + 'lto:' + 'webmaster' + '@' + 'icm.' + 'gov' + '.mo');
  } else if (t == "2") {
    navigate('mai' + 'lto:' + 'ocm' + '@' + 'icm.' + 'gov' + '.mo');
  }
}

function openWin(url, wName, wWidth, wHeight) {
	var newWindow, screenWidth, screenHeight, winLeft, winTop;

	winLeft = (screen.availWidth - wWidth - 10) * 0.5;
	winTop = (screen.availHeight - wHeight - 30) * 0.5;

	newWindow = window.open(url, wName, "height = " + wHeight + ", width = " + wWidth + ", left = " + winLeft + ", top = " + winTop + ", fullscreen = no, channelmode = no, toolbar = no, location = no, directories = no, status = no, menubar = no, scrollbars = yes, resizable = yes");
	newWindow.focus();
}

function openFixWin(url, wName, wWidth, wHeight) {
	var newWindow, screenWidth, screenHeight, winLeft, winTop;

	winLeft = (screen.availWidth - wWidth - 10) * 0.5;
	winTop = (screen.availHeight - wHeight - 30) * 0.5;

	newWindow = window.open(url, wName, "height = " + wHeight + ", width = " + wWidth + ", left = " + winLeft + ", top = " + winTop + ", fullscreen = no, channelmode = no, toolbar = no, location = no, directories = no, status = no, menubar = no, scrollbars = no, resizable = no");
	newWindow.focus();
}

function printWindow() {
	if (window.print != null) {
		window.print();
	} else {
		alert('Your browser does not support this feature. Please select Print from the File menu.');
	}
}

function formSubmit(formName, url, urlTarget) {
	var objStr = formName, obj;
	obj = eval(objStr);
	obj.action = url;
	obj.target = urlTarget;
	obj.submit();
}

function openSubmit(url, wName, wWidth, wHeight, formName) {
	openWin('/blank.htm', wName, wWidth, wHeight);
	formSubmit(formName, url, wName);
}

function openFixSubmit(url, wName, wWidth, wHeight, formName) {
	openFixWin('/blank.htm', wName, wWidth, wHeight);
	formSubmit(formName, url, wName);
}

function fullDateValidate(fullDate) {
	if (fullDate.length != 10) {
		return false;
	}

	if ((fullDate.charAt(4) != '/') || (fullDate.charAt(7) != '/')) {
		return false;
	}

	return dateValidate(fullDate.substr(0, 4), fullDate.substr(5, 2), fullDate.substr(8, 2));
}

function dateValidate(inYear, inMonth, inDay) {
	var checkSign = 0;
	var currentMonthDay = 0;

	currentMonthDay = monthDay(inMonth, inYear);
	if ((inDay <= 0) || (inDay > currentMonthDay)) {
		checkSign = 1;
	} else if ((inMonth <= 0) || (inMonth > 12)) {
		checkSign = 1;
	} else if ((inYear <= 0)) {
		checkSign = 1;
	}

	if (checkSign == 1) {
		return true;
	} else {
		return false;
	}
}

function monthDay(inMonth, inYear) {
	var monthDay;

	if ((inMonth == 4) || (inMonth == 6) || (inMonth == 9) || (inMonth == 11)) {
		monthDay = 30;
	} else if (inMonth == 2) {
		monthDay = isLeapYear(inYear) ? 29 : 28;
	} else {
		monthDay = 31;
	}
	return monthDay;
}

function isLeapYear(inYear) {
	if (inYear % 4 == 0) return true;
	return false;
}

function checkNumber() {
	if ((event.keyCode<48) || (event.keyCode>57))
		event.keyCode = 0;
}

function nonZeroNumber() {
	if ((event.keyCode<48) || (event.keyCode>57))
		event.keyCode = 0;
}

function nonCurrency() {
	if ((event.keyCode<48) || (event.keyCode>57))
		event.keyCode = 0;
}

function IsNull(val) {
	if (val+"" == "null")
		return true;
	else
		return false;
}

function IsUndef(val) {
	if (val+"" == "undefined")
		return true;
	else
		return false;
}

function IsBlank(str) {
	if (IsNull(str) || IsUndef(str) || (str+"" == "") || (Trim(str)==""))
		return true;
	else
		return false;
}

function TrimLeft(str) {
	var resultStr = "";
	var i = len = 0;

	if (str+"" == "undefined" || str == null)
		return null;

	str += "";

	if (str.length == 0) {
		resultStr = "";
	} else {
		len = str.length;

  		while ((i <= len) && (str.charAt(i) == " "))
			i++;
		resultStr = str.substring(i, len);
  	}
  	return resultStr;
}

function TrimRight(str) {
	var resultStr = "";
	var i = 0;

	if (str+"" == "undefined" || str == null)
		return null;

	str += "";

	if (str.length == 0)
		resultStr = "";
	else {
  		i = str.length - 1;
  		while ((i >= 0) && (str.charAt(i) == " "))
 			i--;
  		resultStr = str.substring(0, i + 1);
  	}

  	return resultStr;
}

function Trim(str) {
	var resultStr = "";

	resultStr = TrimLeft(str);
	resultStr = TrimRight(resultStr);

	return resultStr;
}

function splitString(str, val) {
	var resultStr = "";
	var i = 0;
	str = Trim(str);

	if (str+"" == "undefined" || str == null)
		return null;

	str += "";

	if (str.length == 0)
		resultStr = "";
	else {
  		i = str.length - 1;
  		while ((i >= 0) && (str.charAt(i) == val))
 			i--;
  		resultStr = str.substring(0, i + 1);
  	}

  	return resultStr;
}

function split(string, text) {
	splitIndex = 0;
	splits(string,text);
}

function splits(string, text) {
	var strLength = string.length;
	var txtLength = text.length;
	var i = string.indexOf(text);

	if ((strLength == 0) || (txtLength == 0)) return;

	if ((!i) && (text != string.substring(0, txtLength))) return;

	if (i == -1) {
		splitArray[splitIndex++] = string;
		return;
	}

	splitArray[splitIndex++] = string.substring(0,i);

	if (i+txtLength < strLength) {
		splits(string.substring(i+txtLength,strLength),text);
	}

	return;
}

function msgBox(message) {
   var agree = confirm(message);

   if (agree) {
	   return true;
   } else {
	   return false;
   }
}

function checkYear(str) {
	var yearStr = "";
	var i = len = 0;

	if (str.length == 0) {
		yearStr = "0000";
	} else {
		yearStr = str;
		len = str.length;

		for (i = 1; i <= 4-len; i++) {
			yearStr = "0" + yearStr;
		}
	}
	return yearStr;
}

function mailValidate(emailad){
	var userPat=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
	var emailPat=/@[\w\-]+\./;
	var domainPat=/\.[a-zA-Z]{2,3}$/;

	if(((emailad.search(userPat) != -1)||(emailad.search(emailPat)) == -1)||(emailad.search(domainPat) == -1)){
		return true;
	} else {
		return false;
	}
}

function moveValues(moveButton, from, to) {
	if (document.layers) {
		fromObj = document.layers[from];
		to = document.layers[to];
	} else if (document.all) {
		fromObj = document.all(from);
		to = document.all(to);
	}

	if (moveButton == 1 || moveButton == 2) {
		var indTo = to.length-1;
		for (i=fromObj.length-1; i>=0; i--) {
			if ((moveButton==1 || fromObj.options[i].selected) && (fromObj.options[i].value != "")) {
				indTo++;
				to.options[indTo] = new Option(fromObj.options[i].text, fromObj.options[i].value);
				fromObj.options[i] = null;
			}
		}
	} else if (moveButton == 3 || moveButton == 4) {
		var indFrom = fromObj.length-1;
		for (i=to.length-1; i>=0; i--) {
			if ((moveButton==4 || to.options[i].selected) && (to.options[i].value != "")) {
				indFrom++;
				fromObj.options[indFrom] = new Option(to.options[i].text, to.options[i].value);
				to.options[i] = null;
			}
		}
	}
}

function Zoom_view(what) {
   var imgwin = window.open("","WIN","scrollbars=no,status=no,toolbar=no,resizable=1,location=no,menu=no,width=10,height=10");
   imgwin.focus();
   imgwin.document.open();
   imgwin.document.write("<html>\n");
   imgwin.document.write("<head>\n");
   imgwin.document.write("<title>¹Ï¤ù©ñ¤j</title>\n");

   imgwin.document.write("<sc"+"ript>\n");
   imgwin.document.write("function resize() {\n");
   imgwin.document.write("pic = document.il;\n");
   imgwin.document.write("if (eval(pic).height) { var name = navigator.appName\n");
   imgwin.document.write("  if (name == 'Microsoft Internet Explorer') { myHeight = eval(pic).height + 110; myWidth = eval(pic).width + 60;\n");
   imgwin.document.write("  } else { myHeight = eval(pic).height + 9; myWidth = eval(pic).width; }\n");
   imgwin.document.write("  clearTimeout();\n");
   imgwin.document.write("  var height = screen.height;\n");
   imgwin.document.write("  var width = screen.width;\n");
   imgwin.document.write("  var leftpos = width / 2 - myWidth / 2;\n");
   imgwin.document.write("  var toppos = height / 2 - myHeight / 2; \n");
   imgwin.document.write("  self.moveTo(leftpos, toppos);\n");
   imgwin.document.write("  self.resizeTo(myWidth, myHeight);\n");
   imgwin.document.write("}else setTimeOut(resize(), 100);}\n");
   imgwin.document.write("</sc"+"ript>\n");
   imgwin.document.write("</head>\n");
   imgwin.document.write('<body topmargin="10" leftmargin="0" marginheight="0" marginwidth="0" bgcolor="#FFFFFF">\n');
   imgwin.document.write("<center><a href='javascript:window.close()'><table align='center' border='0' cellpadding='0' cellspacing='0'><tr><td><img border=0 src='"+what+"' style='border-width:1px;border-color:aaaaaa' name=il onload='resize();'></td></tr></table></a>\n");
   imgwin.document.write("<br><a href='javascript:window.close()' style='font-size:9pt;color=black;'>Close</a>\n");
   imgwin.document.write("</center>");
   imgwin.document.write("</body>\n");
   imgwin.document.close();
}
