function printDateFieldInput(){
	var inDate = printDateFieldInput.arguments;
	var fieldname = 'date';
	var argv = new Array();
	var title = '';
	var showDate = true;
	var notMandatoryClass = '';
	if (inDate.length>0) MandatoryClass = inDate[0];
	if (inDate.length>1) fieldname += inDate[1];
	if (inDate.length>2) {
		var field = inDate[2].split('/');
		if (field.length==3) {
			argv[0] = field[2];	//dd
			argv[1] = field[1];	//MM
			argv[2] = field[0];	//yyyy
		}
	}
	if(inDate.length>3) title = inDate[3];
	if(inDate.length>4) showDate = inDate[4];
	
	document.write("<table type='date' border=0 cellpadding=0 cellspacing=0>");
	document.write("<tr><td nowrap>");
	/*
	if (argv[2]==undefined)
		document.write("<input type='text' size=3 name='"+fieldname+"yyyy'  id='"+fieldname+"yyyy' maxlength='4' class='"+MandatoryClass+"' alt='dig' value='' style='width:30px' title='"+title+"'>");
	else
		document.write("<input type='text' size=3 name='"+fieldname+"yyyy'  id='"+fieldname+"yyyy' maxlength='4' class='"+MandatoryClass+"' alt='dig' value='"+argv[2]+"' style='width:30px' title='"+title+"'>");
	*/
	document.write("<select name='"+fieldname+"yyyy' id='"+fieldname+"yyyy' class='"+MandatoryClass+"' title='"+title+"'>");
	document.write("<option value=''>YYYY</option>");
	for (var i = 1999; i <= 2019; i++){
		var output = i;
		if (argv.length>2 && argv[2]==i)
			document.write("<option value='"+output+"' selected>"+output+"</option>");
		else
			document.write("<option value='"+output+"'>"+output+"</option>");
	}
	document.write("</select>");
	document.write(" / ");
	document.write("<select name='"+fieldname+"mm' id='"+fieldname+"mm' class='"+MandatoryClass+"' title='"+title+"'>");
	document.write("<option value=''>MM</option>");
	for (var i = 1; i <= 12; i++){
		var output = "0"+i;
		output = output.substr(output.length-2);
		if (argv.length>1 && argv[1]==i)
			document.write("<option value='"+output+"' selected>"+output+"</option>");
		else
			document.write("<option value='"+output+"'>"+output+"</option>");
	}
	document.write("</select>");
	if(!showDate){
		DateMandatoryClass = '';
	} else {
		DateMandatoryClass = MandatoryClass;
	}
		document.write(" / ");
		document.write("<select name='"+fieldname+"dd' id='"+fieldname+"dd' class='"+DateMandatoryClass+"' title='"+title+"'>");
		document.write("<option value=''>DD</option>");
		for (var i = 1; i <= 31; i++){
			var output = '0'+i;
			output = output.substr(output.length-2);
			if (argv.length>0 && argv[0]==i)
				document.write("<option value='"+output+"' selected>"+output+"</option>");
			else
				document.write("<option value='"+output+"'>"+output+"</option>");
		}
		document.write("</select>");
	document.write("</td></tr>");
	document.write("</table>");
}


function submitToAction(url, event) {
	var thisform = document.forms[0];
	var oldAction = thisform.action;
	var finalAction = url;
	if (event != null && event.length > 0) {
		if (finalAction.indexOf('?') > 0) {
			finalAction = finalAction + '&' + event + '=';
		} else {
			finalAction = finalAction + '?' + event + '=';
		}
	}
	thisform.action = finalAction;
	thisform.submit();
	thisform.action = oldAction;
}

function submitEvent(event) {
	var thisform = document.forms[0];
	var oldAction = thisform.action;
	thisform.action = thisform.action + '?' + event;
	thisform.submit();
	thisform.action = oldAction;
}

function submitEventToNewWindow(event, aname, callbacks, awidth, aheight) {
	if (aname == null) {
		aname = '_' + Math.round(Math.random() * 1000000);
	}
	var width = 550;
	var height = 550;
	if (awidth) {
		width = awidth;
	}
	if (aheight) {
		height = aheight;
	}
	var popupWindow = popup('', aname, width, height);
	var thisform = document.forms[0];
	var oldAction = thisform.action;
	var oldTarget = thisform.target;
	thisform.action = thisform.action + '?' + event;
	thisform.target = aname;
	thisform.submit();
	thisform.action = oldAction;
	thisform.target = oldTarget;
	
	if (!window.windowCallback) {
		window.windowCallback = new Array();
	}
	window.windowCallback[aname] = callbacks;
}

function popup(ahref, aname, awidth, aheight) {
	var name = '';
	var width = 760;
	var height = 550;
	if (aname) {
		name = aname;
	}
	if (awidth) {
		width = awidth;
	}
	if (aheight) {
		height = aheight;
	}
	return window.open(ahref, 
				name, 
				'toolbar=0,location=0,status=0,menubar=0,scrollbars=yes,'
				+ 'resizable=yes,top=50,left=50,width=' 
				+ width + ',height=' + height + ''); 
}

function openWindow(path, aname, callbacks) {
	if (aname == null) {
		aname = '_' + Math.round(Math.random() * 1000000);
	}
	var popupWindow = popup('', aname, 550, 550);
	jsSubmit(path, aname);
	/*
	var docBody = document.body;
	
	var requestObj = parseUrl(path)
	var genForm = document.createElement('form');
	genForm.setAttribute('name', 'genForm');
	genForm.setAttribute('action', requestObj['action']);
	genForm.setAttribute('method', 'post');
	genForm.setAttribute('target', aname);
	for (var i in requestObj['parameters']) {
		var key = i;
		var values = requestObj['parameters'][i];
		for (var j = 0; j < values.length; j++) {
			var formField = document.createElement('input');
			formField.setAttribute('type', 'hidden');
			formField.setAttribute('name', key);
			formField.setAttribute('value', values[j]);
			genForm.appendChild(formField);
		}
	}
	document.body.appendChild(genForm);
	genForm.submit();
	docBody.removeChild(genForm);
	*/
	if (!window.windowCallback) {
		window.windowCallback = new Array();
	}
	window.windowCallback[aname] = callbacks;
}

function jsSubmit(url, target) {
	var requestObj = parseUrl(url)
	var genForm = document.createElement('form');
	genForm.setAttribute('action', requestObj['action']);
	genForm.setAttribute('method', 'post');
	if (target) {
		genForm.setAttribute('target', target);
	}
	for (var i in requestObj['parameters']) {
		var key = i;
		var values = requestObj['parameters'][i];
		for (var j = 0; j < values.length; j++) {
			var formField = document.createElement('input');
			formField.setAttribute('type', 'hidden');
			formField.setAttribute('name', key);
			formField.setAttribute('value', values[j]);
			//alert(key + ":" + values[j]);
			genForm.appendChild(formField);
		}
	}
	document.body.appendChild(genForm);
	genForm.submit();
	document.body.removeChild(genForm);
}

function addParameter(form, name, value) {
	var formField = document.createElement('input');
	formField.setAttribute('type', 'hidden');
	formField.setAttribute('name', name);
	formField.setAttribute('value', value);
	form.appendChild(formField);
}

function parseUrl(url) {
	var action = url;
	var queryString = '';
	if (url.indexOf('?') > 0) {
		queryString = url.substring((url.indexOf('?')) + 1);
		action = url.substring(0, (url.length - queryString.length -1));
	}
	var requestObj = new Object();
	requestObj['action'] = action;
	requestObj['parameters'] = new Array();
	if (queryString.length > 0) {
		var pairs = queryString.split("&"); 
		for (var i = 0; i < pairs.length; i++) {
			var pos = pairs[i].indexOf('='); 
			var key = '';
			var value = '';
			if (pos >= 0) {
				var key = urlDecode(pairs[i].substring(0, pos)); 
				var value = urlDecode(pairs[i].substring(pos + 1)); 
			} else {
				key = urlDecode(pairs[i]);
			}
			var values = requestObj['parameters'][key];
			if (!values) {
				values = new Array();
			}
			values.push(value);
			requestObj['parameters'][key] = values;
		}
	}
	return requestObj;
}

function urlDecode(str){
    str=str.replace(new RegExp('\\+','g'),' ');
    return decodeURIComponent(str);
}

function urlEncode(str){
    str=decodeURIComponent(str);
    str=str.replace(new RegExp('\\+','g'),'%2B');
    return str.replace(new RegExp('%20','g'),'+');
}

function confirmSubmit(msg) {
	return confirm(msg);
}

function confirmUpdate(msg) {
	return confirm(msg);
}

function confirmDelete(msg) {
	return confirm(msg);
}

function closeWindow(msg) {
	if (msg) {
		if (confirm(msg)) {
			window.close();
		}
	} else {
		window.close();
	}
}

function resizeWindow(newWidth, newHeight, win) {
	if (!win) {
		win = window;
	}
	if (win.innerWidth) {
		iWidth = win.innerWidth;
		iHeight = win.innerHeight;
	} else if (win.document.documentElement && win.document.documentElement.clientWidth) {
		iWidth = win.document.documentElement.clientWidth;
		iHeight = win.document.documentElement.clientHeight;
	} else if (win.document.body) {
		iWidth = win.document.body.clientWidth;
		iHeight = win.document.body.clientHeight;
	} else return;

	var dWidth = parseInt(newWidth) - parseInt(iWidth);
	var dHeight = parseInt(newHeight) - parseInt(iHeight);
	win.resizeBy(isNaN(dWidth) ? 0 : dWidth , 
		isNaN(dHeight) ? 0 : dHeight);

}

function currentScroll() {
	var deltaX =  window.pageXOffset
                || document.documentElement.scrollLeft
                || document.body.scrollLeft
                || 0;
    var deltaY =  window.pageYOffset
                || document.documentElement.scrollTop
                || document.body.scrollTop
                || 0;
	var pos = [deltaX, deltaY];
	return pos;
}

function saveScroll() {
	try {
		var thisform = document.forms[0];
		var scrollfield = thisform.elements['scroll'];
		if (scrollfield == null) {
			scrollfield = document.createElement('input');
			scrollfield.setAttribute('type', 'hidden');
			scrollfield.setAttribute('name', 'scroll');
			thisform.appendChild(scrollfield);
		}
		scrollfield.setAttribute('value', currentScroll());
	} catch (e) {
		alert(e);
	}
}

function checkRadio(name, value) {
	var f = document.forms[0];
	var radio = f.elements[name];
	if (radio) {
		$(radio).each(function(){
			if (this.value == value) {
				$(this).attr('checked', true);
			} else {
				$(this).attr('checked', false);
			}
		});
	}
}

function getRadioCheckedValue(name) {
	var checkedValue = null;
	var f = document.forms[0];
	var radio = f.elements[name];
	if (radio) {
		$(radio).each(function(){
			var thisChecked = $(this).attr('checked');
			if (thisChecked && thisChecked == true) {
				checkedValue = $(this).val();
			}
		});
	}
	return checkedValue;
}

function getRadioCheckedValueByFormname(formname, name) {
	var checkedValue = null;
	var f = document.forms[formname];
	var radio = f.elements[name];
	if (radio) {
		$(radio).each(function(){
			var thisChecked = $(this).attr('checked');
			if (thisChecked && thisChecked == true) {
				checkedValue = $(this).val();
			}
		});
	}
	return checkedValue;
}

function checkAll(fieldName) {
	var f = document.forms[0];
	var checkBox = f.elements[fieldName];
	if (checkBox) {
		$(checkBox).attr('checked', true);
	}
}

function isAnyChecked(fieldName) {
	var b = false;
	$(document.forms[0].elements[fieldName]).each(
		function() {
			if (this.checked == true) {
				b = true;
				return false;
			}
		}
	);
	return b;
}

function countChecked(fieldName) {
	var c = 0;
	$(document.forms[0].elements[fieldName]).each(
		function() {
			if (this.checked == true) {
				c++;
			}
		}
	);
	return c;
}

function isInteger(s) {
	return (s.toString().search(/^-?[0-9]+$/) == 0);
}

function isEmpty(o) {
	return $.trim(o).length == 0;
}

function isEmptyByElementId(elementId) {
	var validateField;
	var validateValue;
	
	validateField = document.getElementById(elementId);
	validateValue = validateField.value;
	if (isEmpty(validateValue)) {
		return true;
	} else {
		return false;
	}
}

function isNull(val){return(val==null);}

function isValidDate(val) {
	//format: yyyy/MM/dd;
	val=val+"";
	var now=new Date();
	var year=1;
	var month=1;
	var date=1;

	if (val.length != 10) {return false};
	if (val.substr(4,1)!="/") {return false};
	if (val.substr(7,1)!="/") {return false};

	year = val.substr(0,4);
	if (!isInteger(year)) {return false;}
	
	month = val.substr(5,2);
	if (!isInteger(month)) {return false;}
	if ((month<1)||(month>12)){return false;}

	date = val.substr(8,2);
	if (!isInteger(date)) {return false;}
	if ((date<1)||(date>31)){return false;}


	// Is the date valid for month?
	if (month==2) {
		// Check for leap year
		if (((year%4==0)&&(year%100!=0)) || (year%400==0)) { // leap year
			if (date > 29) { return false; }
		} else { 
			if (date > 28) { return false; }
		}
	}
	if ((month==4)||(month==6)||(month==9)||(month==11)) {
		if (date > 30) { return false; }
	}

	return true;
}

function getDateFromString(dateString) {
	//Assumption: the dateString is in valid format
	//format: yyyy/MM/dd;
	var year=1;
	var month=1;
	var date=1;

	year = dateString.substr(0,4);
	month = dateString.substr(5,2);
	date = dateString.substr(8,2);
	var newDate = new Date(year,month-1,date);
	return newDate;
}

function compareDates(dateStr1, dateStr2) {
	//format: yyyy/MM/dd;
	var d1 = getDateFromString(dateStr1);
	var d2 = getDateFromString(dateStr2);
	if (d1 > d2) {
		return 1;
	} else { 
		if (d1 < d2) {return -1;}
	}
	return 0;
}

function getRadioCheckedValue(FormName, FieldName) {
	if(!document.forms[FormName])
		return "";
	var radioObj = document.forms[FormName].elements[FieldName];
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function setRadioCheckedValue(FormName, FieldName, newValue) {
	if(!document.forms[FormName])
		return;
	var radioObj = document.forms[FormName].elements[FieldName];
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

function setOptionSelectedValue(FormName, FieldName, newValue) {
	if(!document.forms[FormName])
		return;
	var selectObj = document.forms[FormName].elements[FieldName];
	if(!selectObj)
		return;
	optionsObj = selectObj.options; 
	if(!optionsObj)
		return;
	var optionsLength = optionsObj.length;
	if(optionsLength == undefined) {
		selectObj.options.selected = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < optionsLength; i++) {
		selectObj.options[i].selected = false;
		if(selectObj.options[i].value == newValue.toString()) {
			selectObj.options[i].selected = true;
		}
	}
}

function getOptionSelectedValue(FormName, FieldName) {
	if(!document.forms[FormName])
		return "";
	var selectObj = document.forms[FormName].elements[FieldName];
	if(!selectObj)
		return "";
	optionsObj = selectObj.options; 
	if(!optionsObj)
		return "";
	var optionsLength = optionsObj.length;
	if(optionsLength == undefined)
		if(optionsObj.selected)
			return optionsObj.value;
		else
			return "";
	for(var i = 0; i < optionsLength; i++) {
		if(optionsObj[i].selected) {
			return optionsObj[i].value;
		}
	}
	return "";
}

function getCheckboxesValues(FormName, FieldName) {
	var values = new Array();
  
	if(!document.forms[FormName])
		return "";
	var checkboxObj = document.forms[FormName].elements[FieldName];
	if(!checkboxObj)
		return "";
		
	var checkboxObjLength = checkboxObj.length;
	if(checkboxObjLength == undefined) {
		if(checkboxObj.checked) {
			values.push(checkboxObj.value);
		} else {
			return "";
		}
	}
	
	for(var i = 0; i < checkboxObjLength; i++) {
		if(checkboxObj[i].checked) {
			values.push(checkboxObj[i].value);
		}
	}
	
	return values;
}

function setAllCheckBoxes(FormName, FieldName, CheckValue) {
	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		for(var i = 0; i < countCheckBoxes; i++)
			objCheckBoxes[i].checked = CheckValue;
}

function setCheckBoxesDisabled(FormName, FieldName, disabledValue) {
	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return;
	objCheckBoxes.disabled = disabledValue;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.disabled = disabledValue;
	else
		for(var i = 0; i < countCheckBoxes; i++)
			objCheckBoxes[i].disabled = disabledValue;
}

function setCheckBoxesDisabledExceptValue(FormName, FieldName, disabledValue, theValue, checkedValue) {
	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return;
	objCheckBoxes.disabled = disabledValue;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes) {
		if (objCheckBoxes.value != theValue) {
			objCheckBoxes.disabled = disabledValue;
			objCheckBoxes.checked = false;
		} else
			objCheckBoxes.checked = checkedValue;
	} else {
		for(var i = 0; i < countCheckBoxes; i++)
			if (objCheckBoxes[i].value != theValue) {
				objCheckBoxes[i].disabled = disabledValue;
				objCheckBoxes[i].checked = false;
			} else
				objCheckBoxes[i].checked = checkedValue;
	}
}

function setCheckBoxValue(FormName, FieldName, CheckBoxValue, CheckValue) {
	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes) {
		//objCheckBoxes.checked = CheckValue;
	} else {
		for(var i = 0; i < countCheckBoxes; i++)
			if (objCheckBoxes[i].value == CheckBoxValue)
				objCheckBoxes[i].checked = CheckValue;
	}
} 

function isCheckBoxesEmpty(FormName, FieldName) {
	if(!document.forms[FormName])
		return true;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return true;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes) {
	} else {
		for(var i = 0; i < countCheckBoxes; i++)
			if (objCheckBoxes[i].checked)
				return false;
	}
	return true;
}

function clearOptions(FormName, FieldName) {
	if(!document.forms[FormName])
		return null;
	var objOptions = document.forms[FormName].elements[FieldName];
	if(!objOptions)
		return null;
	if (objOptions != null) {
		var length = objOptions.options.length;
	    for (i=length-1 ; i>=0; i--) {
	    	if(objOptions.options[i].text!="" && objOptions.options[i].value!="")
	    		objOptions.options.remove(i);
	    }
	}
	return objOptions;
}

function setControlDisabled(FormName, FieldName, disabledValue) {
	if(!document.forms[FormName])
		return;
	var objControl = document.forms[FormName].elements[FieldName];
	if(!objControl)
		return;
	objControl.disabled = disabledValue;
}

function getControlValue(FormName, FieldName) {
	if(!document.forms[FormName])
		return "";
	var objControl = document.forms[FormName].elements[FieldName];
	if(!objControl)
		return "";
	return objControl.value;
}

function setHiddenFieldValue(FormName, FieldName, fieldValue) {
	if(!document.forms[FormName])
		return;
	var objControl = document.forms[FormName].elements[FieldName];
	if(!objControl)
		return;
	objControl.value = fieldValue;
}

function getElementsByClassName(className) { 
    var el = [],
    _el = document.getElementsByTagName('*');
    for (var i=0; i<_el.length; i++ ) {
    	if (_el[i].className == className ) {
    		el[el.length] = _el[i];
    	}
    }
    return el;
}

function getElements(att,val,loose){
	var C,i=0,A=[],tem,temp;
	var pa = this.nodeType? this : document;
	C = pa.getElementsByTagName('*');
	while((tem=C[i++]) != undefined){
		temp = tem.getAttribute(att) || tem[att];
		if(temp){
			if(!val || temp == val) A.push(tem);
			else if(loose === true && temp.search(val) > -1) A.push(tem);
		}
	}
	return A;
}

//URL must be in same domain
function loadPopup(url, ele, width, height, offsetX, offsetY){
	if (ele!=undefined) { 
		ele.style.color = 'purple';
	}
	
	$("#popup").css("position", "absolute");
	$("#popup").css("overflow", "hidden");
	$("#popup").css("z-index", "100");

	//default in middle	
	$("#popup").css("height", document.documentElement.clientHeight-100);
	$("#popup").css("width", document.documentElement.clientWidth-100);
	$("#popup").css("top", document.documentElement.scrollTop + document.body.scrollTop +50);
	$("#popup").css("left", document.documentElement.scrollLeft + document.body.scrollLeft +50);

	$("#popupContent").css("height", document.documentElement.clientHeight-125);
	$("#popupContent").css("width", document.documentElement.clientWidth-100);
	$("#popupContent").css("top", document.documentElement.scrollTop + document.body.scrollTop +50);
	$("#popupContent").css("left", document.documentElement.scrollLeft + document.body.scrollLeft+50);
	
	if(width!=undefined && !isNaN(width)){
		$("#popup").css("width", width);
		$("#popupContent").css("width", width);
	}
	if(height!=undefined && !isNaN(height)){
		$("#popup").css("height", height);
		$("#popupContent").css("height", height-25);
	}
	if(offsetX!=undefined && !isNaN(offsetX)){
		$("#popup").css("left", document.documentElement.scrollLeft + document.body.scrollLeft+offsetX);
		$("#popupContent").css("left", document.documentElement.scrollLeft + document.body.scrollLeft+offsetX);
	}
	if(offsetY!=undefined && !isNaN(offsetY)){
		$("#popup").css("top", document.documentElement.scrollTop + document.body.scrollTop +offsetY);
		$("#popupContent").css("top", document.documentElement.scrollTop + document.body.scrollTop+offsetY);
	}

	$("#popupContent").attr("src", url);
	$("#popup").css("display", "block");
	
	$(window).scroll(function(){
			$("#popup").css("left", document.documentElement.scrollLeft + document.body.scrollLeft+50);
			$("#popup").css("top", document.documentElement.scrollTop + document.body.scrollTop+50);
			
			if(offsetX!=undefined && !isNaN(offsetX)){
				$("#popup").css("left", document.documentElement.scrollLeft + document.body.scrollLeft+offsetX);
			}
			if(offsetY!=undefined && !isNaN(offsetY)){
				$("#popup").css("top", document.documentElement.scrollTop + document.body.scrollTop+offsetY);
			}
		}
	)
}

//Real popup
function loadRealPopup(url, ele, width, height, offsetX, offsetY){
	if (ele!=undefined) { 
		ele.style.color = 'purple';
	}
	wwidth = "900";
	wheight="450";
	if(width!=undefined && !isNaN(width)){
		wwidth = width; 
	}
	if(height!=undefined && !isNaN(height)){
		wheight = height;
	}
	style = "scrollbars=yes,menubar=yes,resizable=yes,toolbar=yes,location=no,status=yes,"
			 +"width="+wwidth+",height="+wheight
	window.open(url, '', style);
}

function convertTextToUpperCase(FormName, FieldName) {	
	var objText = document.forms[FormName].elements[FieldName];	
	objText.value = objText.value.toUpperCase();
}

function isContainEnglish(FormName, FieldName) {
	var patt=new RegExp("[a-zA-Z]");
	
	var objText = document.forms[FormName].elements[FieldName];
	
	return patt.test(objText.value);    		
}




function doEncrypt( pass ) {
  if ( pass.length < 6 ) {
    alert( "Please assign a key" );
    return false;
  } else {
    doChange( pass );
  }
}


function hideIt(obj) {
  obj = document.getElementById(obj);
  obj.style.visibility = 'hidden';
}


function placeIt(obj) {
  obj = document.getElementById(obj);
  if (obj == null) return;
  
  if (document.documentElement)	{
	theLeft = document.documentElement.scrollLeft;
	theTop = document.documentElement.scrollTop;
  } else if (document.body) {
    theLeft = document.body.scrollLeft;
    theTop = document.body.scrollTop;
  }
       
  theLeft += x;
  theTop += y;
  obj.style.left = theLeft + 'px' ;
  obj.style.top = theTop + 'px' ;
}


function dokey(e, passvalue ) {
  var keynum;
  var keychar;

  if (window.event) {			// I.E.
	keynum = e.keyCode;
  } else if (e.which) {			// Mozilla, Opera, Netscape
    keynum = e.which;
  }

  if (keynum == 13) {
    doEncrypt( passvalue );
  }
		
  // Backspace key
  if (keynum == 8)
 	return true;
	
  // Shift can only be a..z or A..Z
  if (e.shiftKey && (keynum < 65 || (keynum > 90 && keynum < 97) || keynum > 122))
	return false;
	
  // Only allow 0..9, a..z, A..Z
  if ((keynum < 48) || (keynum > 57 && keynum < 65) || (keynum > 90 && keynum < 97) || (keynum > 122)) {
	if (window.event) {
	  return false;
	} else if (e.which) {
      return false;
    }
  }
  return true;
}	


function showIt(obj) {
  obj = document.getElementById(obj);
  obj.style.visibility = 'visible';
}


function validateGeneralYear(formName, inputYear) {
	var timeValue = getControlValue(formName, inputYear);
	if (!isInteger(timeValue) || (timeValue.length!=4)) {
		alert("The year ["+getControlValue(formName, inputYear)+"] must be 4 digits integer.");
		var element = document.getElementById(inputYear);
		element.focus();
		return false;
	}
	
	return true;
}

var POPUPREPORT_ELEMENT = null;
var POPUPREPORT_URL = "";
function loadPopupReport( myURL, ele, width, height, offsetX, offsetY){

	POPUPREPORT_ELEMENT = window.open('/tcs/common/popupReport/report.htm', 'popupReport', 'width=' + width + ',height=' + height + ',resizable=yes'  );

	myFrame = POPUPREPORT_ELEMENT.frames["popupContent"];
	if ( myFrame != null ) {
      myLocation = myFrame.location;
	  if ( myLocation != null ) {
	    myLocation.href = myURL;
	  }
	}
	
	if ( myFrame == null ) {
	  POPUPREPORT_URL = myURL;
	  setTimeout( 'loadPopupReportAgain()', 1000 );
	}
	return false;
}


function loadPopupReportAgain() {
	
  if ( POPUPREPORT_ELEMENT != null ) {
    myFrame = POPUPREPORT_ELEMENT.frames["popupContent"];
    if ( myFrame != null ) {
      myLocation = myFrame.location;
	  if ( myLocation != null ) {
	    myLocation.href = POPUPREPORT_URL;
	  }
    } else {
	  alert( "System busy, please reload the report" );
	  POPUPREPORT_ELEMENT.close();
    }
  }
	
  return false;
}





