/*** ***
License
This software is published under the BSD license as listed below.
 
Copyright (c) 2007 pennycms.com

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met:

 . Redistributions of source code must retain the above copyright notice, 
   this list of conditions and the following disclaimer. 

 . Redistributions in binary form must reproduce the above copyright notice, 
   this list of conditions and the following disclaimer in the documentation 
   and/or other materials provided with the distribution. 

 . Neither the name of the pennycms.com nor the names of its contributors 
   may be used to endorse or promote products derived from this software without 
   specific prior written permission. 

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*** ***/

/**
 * 
 */
function key_down_event (obj) {
	var events = Pennyutils.events.getEvent();
	if ((obj.type == 'text' ||
		obj.type == 'select-list' ||
		obj.type == 'radio' ||
		obj.type == 'password') &&
		(events.keyCode == 13)) {
			events.keyCode = 9;
	}

	if ((obj.type == 'textarea') &&
		((events.ctrlKey)&&(events.keyCode == 13))) {
		events.keyCode = 9;
	}
}

/**
 * 
 */
function mouse_over_event (obj) {
	obj.focus();

	if (obj.type == 'text' ||
		obj.type == 'textarea' ||
		obj.type == 'password') {
		obj.select();
	}
}

/**
 * 
 */
function set_count_down_time (obj_id, count_down_time) {
	if (count_down_time<=0)  {
		
	} else {
		count_down_time-=1000;
		set_new_text_node(obj_id, count_down_time/1000);
		document.getElementById(obj_id).value = (count_down_time/1000);
		setTimeout("set_count_down_time('" + obj_id + "', "+count_down_time+")", 1000);
	}
}

/**
 * 
 */
function set_new_text_node (obj_id, text) {
		remove_child_node(obj_id);
		append_text_node(obj_id, text);
}

/**
 * 
 */
function append_text_node (obj_id, text) {
		var obj = document.getElementById(obj_id);
		txt_node = document.createTextNode(text);
		obj.appendChild(txt_node);
}

/**
 * 
 */
function remove_child_node (obj_id) {
	var obj = document.getElementById(obj_id);
	var ind = obj.childNodes.length;
	for (var i = ind - 1; i >= 0 ; i--) {
		obj.removeChild(obj.childNodes[i]);
	}
}

/**
 * 
 */
function set_element_value (src_id, src_value) {
	var src_obj = document.getElementById(src_id);
	set_object_value(src_obj, src_value);
}

/**
 * 
 */
function set_object_value (src_obj, src_value) {
	if (src_obj!=null) {
		if (src_obj.type == 'select') {
			var si = src_obj.selectedIndex;
			if (si >= 0) {
				src_obj.options[si].value = src_value;
			}
		}
		if (
			src_obj.type == 'file' ||
			src_obj.type == 'hidden' ||
			src_obj.type == 'password' ||
			src_obj.type == 'select' ||
			src_obj.type == 'select-one' ||
			src_obj.type == 'text' ||
			src_obj.type == 'textarea'
		) {
			src_obj.value = src_value;
		}
		if (
			src_obj.type == 'checkbox' ||
			src_obj.type == 'radio'
		) {
			if (src_obj.checked) {
				src_obj.value = src_value;
			}
		}
	}
}

/**
 * 
 */
function get_element_value (src_id) {
	var src_obj = document.getElementById(src_id);
	
	return get_object_value(src_obj);
}

/**
 * 
 */
function get_object_value (src_obj) {
	var src_value = "";
	
	if (src_obj!=null) {
		if (
			src_obj.type == 'select' ||
			src_obj.type == 'select-list'
		) {
			var si = src_obj.selectedIndex;
			if (si >= 0) {
				src_value = src_obj.options[si].value;
			}
		}
		if (
			src_obj.type == 'file' ||
			src_obj.type == 'hidden' ||
			src_obj.type == 'password' ||
			src_obj.type == 'select' ||
			src_obj.type == 'select-one' ||
			src_obj.type == 'text' ||
			src_obj.type == 'textarea'
		) {
			src_value = src_obj.value;
		}
		if (
			src_obj.type == 'checkbox' ||
			src_obj.type == 'radio'
		) {
			if (src_obj.checked) {
				src_value = src_obj.value;
			}
		}
	}
	
	return src_value;
}

/**
 * 
 */
function change_char() {
	var allcookies = document.cookie;
	var pos = allcookies.indexOf("language_id=");
	if (pos != -1) {
		var start=pos+12;
		var end = allcookies.indexOf(";", start);
		if (end == -1) end = allcookies.length;
		var value = allcookies.substring(start, end);
		value = unescape(value);
		if (value==2) {
			document.body.innerHTML=traditionalized(document.body.innerHTML);
		}
	}
}

/**
 * 
 */
function over_menu (src_id) {
	change_class(src_id, "menu_over");
}

/**
 * 
 */
function out_menu (src_id) {
	change_class(src_id, "menu_out");
}

/**
 * 
 */
function set_element_style(src_id, style_script) {
	var obj = document.getElementById(src_id);
	set_object_style(obj, style_script);
}

/**
 * 
 */
function set_object_style(obj, style_script) {
	if (!obj) return;
	obj.setAttribute("style", style_script);
	obj.style.cssText = style_script;
}

/**
 * 
 */
function show_element(src_id) {
	var obj = document.getElementById(src_id);
	show_object(obj);
}

/**
 * 
 */
function show_object(obj) {
	if (!obj) return;
	obj.setAttribute("style", "display:inline");
	obj.style.cssText = "display:inline";
	obj.style.visibility="visible";
}

/**
 * 
 */
function hide_element(src_id) {
	var obj = document.getElementById(src_id);
	hide_object(obj);
}

/**
 * 
 */
function hide_object(obj) {
	if (!obj) return;
	obj.setAttribute("style", "display:none");
	obj.style.cssText = "display:none";
	obj.style.visibility="hidden";
}

/**
 * 
 */
function change_class(src_id, class_name) {
	var src_obj = document.getElementById(src_id);
	change_object_class(src_obj, class_name);
}

/**
 *
 */
function change_object_class(src_obj, class_name) {
	if (!obj) return;
	src_obj.setAttribute("class", class_name);
	src_obj.setAttribute("className", class_name);
}

/**
 * 
 */
function nextControl() {
//	e=(window.event)?event:e;
//	var k=e.keyCode;
//	if(k==13) {
//		e.keyCode=9;
//	}

	var events = Pennyutils.events.getEvent();
	if (events.keyCode == 13) {
		events.keyCode = 9;
//		events.preventDefault();
	}
}

/**
 * 
 */
function nextControlCtrl() {
	var events = Pennyutils.events.getEvent();
	if ((events.ctrlKey)&&(events.keyCode == 13)) {
		events.keyCode = 9;
	}
}

/**
 *
 */
function openWindowModel(url_text, target, width, height) {
	if (width==undefined) {
		width=360;
	}
	if (height==undefined) {
		height=300;
	}
	window.open(url_text, target, 'width='+width+', height='+height+', status=yes, scrollbars=yes, resizable=yes');
}

/**
 *
 */
function append_semicolon(souce_text, append_text) {

	souce_text = del_first_semicolon(souce_text, " ");

	souce_text = del_last_semicolon(souce_text, " ");
	
	if (souce_text.length > 0) {
		souce_text = del_first_semicolon(souce_text, ";");
		
		souce_text = del_last_semicolon(souce_text, ";");

		souce_text += ";"+append_text+";";
		
		souce_text = del_first_semicolon(souce_text, ";");

	} else {
		souce_text = append_text+";";
	}

	return souce_text;
}

/**
 *
 */
function del_first_semicolon(souce_text, find_text) {
	if (souce_text.charAt(0) == find_text) {
		souce_text = souce_text.substring(1, souce_text.length);
		
		souce_text = del_first_semicolon(souce_text, find_text);
	} else {
		return souce_text;
	}
	
	return souce_text;
}

/**
 *
 */
function del_last_semicolon(souce_text, find_text) {
	if (souce_text.charAt(souce_text.length - 1) == find_text) {
		souce_text = souce_text.substring(0, souce_text.length - 1);
		
		souce_text = del_last_semicolon(souce_text, find_text);
	} else {
		return souce_text;
	}
	
	return souce_text;
}

/**
 * 
 */
function set_focus(src_id) {
	var obj = document.getElementById(src_id);
	
	if (obj!=null) {
		obj.focus();
	}
}

/**
 * Generate date format yyyy-MM-dd
 */
function generateDate (obj) {
	dateText = obj.value
	
	if (dateText.length == 8) {	// String length 8 character.
		if (dateText.indexOf("-") < 1) {	// String text have "-"
//			alert(dateText.substr(0, 4)+"-"+dateText.substr(4, 2)+"-"+dateText.substr(6, 2));
			obj.value = dateText.substr(0, 4)+"-"+dateText.substr(4, 2)+"-"+dateText.substr(6, 2)
		}
	}
//	form[oRange[x][0]].value = 
}

function isDate(obj, alert_msg) {
//	obj = document.getElementById(src_id);
	if (obj==null) {
		return;
	}
	str = obj.value;
	if ((str == null)||(str.length == 0)||(str == "0000-00-00")) {
		return false;
	}
//	var r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
	var r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
	if(r==null) {
		alert(PENNYCMD.I18N.msg["error_date_format"]);
		obj.value="";
		obj.focus();
		return false;
	}
	var d = new Date(r[1], r[3]-1, r[4]);
	
	if (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]) {
		return true;
	} else {
		alert(alert_msg);
		obj.value="";
		obj.focus();
		return false;
	}
}

function set_cookie(sName, sValue, oExpires, sPath, sDomain, bSecure) {
	var sCookie = sName + "=" + encodeURIComponent(sValue);

	if (oExpires) {
		sCookie += "; expires=" + oExpires.toGMTString();
	}

	if (sPath) {
		sCookie += "; path=" + sPath;
	}

	if (sDomain) {
		sCookie += "; domain=" + sDomain;
	}

	if (bSecure) {
		sCookie += "; secure";
	}

	document.cookie = sCookie;
}

function get_cookie(sName) {

	var sRE = "(?:; )?" + sName + "=([^;]*);?";
	var oRE = new RegExp(sRE);
	
	if (oRE.test(document.cookie)) {
		return decodeURIComponent(RegExp["$1"]);
	} else {
		return null;
	}

}                

function delete_cookie(sName, sPath, sDomain) {
	var sCookie = sName + "=; expires=" + (new Date(0)).toGMTString();
	if (sPath) {
		sCookie += "; path=" + sPath;
	}

	if (sDomain) {
		sCookie += "; domain=" + sDomain;
	}
	
	document.cookie = sCookie;
}

function repaint_png(png_img) {
	var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion[1]);

	var src_img=new Image();
	src_img.src = png_img.src;
//	alert(src_img.width+":"+src_img.height);
	
	if ((version >= 5.5) && (version < 7) && (document.body.filters)) {
		var img_id = (png_img.id) ? "id='" + png_img.id + "' " : "";
		var img_class = (png_img.className) ? "class='" + png_img.className + "' " : "";
		var img_title = (png_img.title) ? "title='" + png_img.title  + "' " : "title='" + png_img.alt + "' ";
		var img_style = "display:inline-block;" + png_img.style.cssText;
		var strNewHTML = "<span " + img_id + img_class + img_title
				  + " style=\"" + "width:" + src_img.width 
				  + "px; height:" + src_img.height 
				  + "px;" + img_style + ";"
				  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				  + "(src=\'" + png_img.src + "\', sizingMethod='scale');\"></span>";
		png_img.outerHTML = strNewHTML;
	}
}

function resize_img($img, $set_width, $set_height) {
	if ($img.width <= $set_width && $img.height <= $set_height) {
		return;
	}
	
	$re_width = $img.width > $set_width ? $set_width : $img.width;
	$re_height = $img.height > $set_height ? $set_height : $img.height;
	
	$width_rate = $re_width / $img.width;
	$height_rate = $re_height / $img.height;
	
	$rate = $width_rate < $height_rate ? $width_rate : $height_rate; // get min rate.
	
	$re_width = $img.width * $rate;	// if set width then compute height error.
	$re_height = $img.height * $rate;
	
	$img.width = $re_width;
	$img.height = $re_height;
	
//	alert($width_rate + " : " + $height_rate + "\n" + $img.width + " : " + $img.height);
}

var $MASK_TARGET;
function openMask () {
	if ($MASK_TARGET) {
		return;
	}
	var s = "";
	s+="\n document.body.clientWidth :"+ document.body.clientWidth ;
	s+="\n document.body.clientHeight :"+ document.body.clientHeight ;
	s+="\n document.documentElement.clientWidth :"+document.documentElement.clientWidth;
	s+="\n document.documentElement.clientHeight :"+document.documentElement.clientHeight;
	s+="\n document.body.offsetWidth :"+ document.body.offsetWidth ;
	s+="\n document.body.offsetHeight :"+ document.body.offsetHeight ;
	s+="\n document.body.scrollWidth :"+ document.body.scrollWidth ;
	s+="\n document.body.scrollHeight :"+ document.body.scrollHeight ;
	s+="\n document.body.scrollTop :"+ document.body.scrollTop ;
	s+="\n document.documentElement.scrollTop :"+ document.documentElement.scrollTop ;
	s+="\n document.body.scrollLeft :"+ document.body.scrollLeft ;
	s+="\n window.screenTop :"+ window.screenTop ;
	s+="\n window.screenLeft :"+ window.screenLeft ;
	s+="\n window.screen.height :"+ window.screen.height ;
	s+="\n window.screen.width :"+ window.screen.width ;
	s+="\n window.screen.availHeight :"+ window.screen.availHeight ;
	s+="\n window.screen.availWidth :"+ window.screen.availWidth ;
	s+="\n window.screen.colorDepth :"+ window.screen.colorDepth ;
	s+="\n window.screen.deviceXDPI :"+ window.screen.deviceXDPI ;
//	alert(s);
	var sWidth=document.documentElement.clientWidth>document.body.clientWidth?document.documentElement.clientWidth:document.body.clientWidth;
	var sHeight=document.documentElement.clientHeight>document.body.clientHeight?document.documentElement.clientHeight:document.body.clientHeight;
	if(navigator.appName=="Microsoft Internet Explorer") {
	} else {
		sHeight+=25;	// fill.
	}
	var bgObj=document.createElement("div");
	$MASK_TARGET = bgObj;
	bgObj.setAttribute('id','bgDiv');
	bgObj.style.background="#000022";
	bgObj.style.position="absolute";
	if(navigator.appName=="Microsoft Internet Explorer") {
		bgObj.style.filter="alpha(opacity=50)";
	} else {
		bgObj.style.MozOpacity="0.5";
	}
	bgObj.style.top="0";
	bgObj.style.left="0";
	bgObj.style.width="100%";
	bgObj.style.height=sHeight + "px";
	bgObj.style.zIndex = "10000";
	document.body.appendChild(bgObj);
	
	window.onresize=function(){
		if ($MASK_TARGET) {
			var sHeight=document.documentElement.clientHeight>document.body.clientHeight?document.documentElement.clientHeight:document.body.clientHeight;
			if(navigator.appName=="Microsoft Internet Explorer") {
			} else {
				sHeight+=25;	// fill.
			}
			$MASK_TARGET.style.height=sHeight + "px";	// W3C DTD IE/FF;
		}
	}
}

function closeMask () {
	if ($MASK_TARGET) {
		document.body.removeChild($MASK_TARGET);
		$MASK_TARGET=null;
	}
}

function dispaly_select_elements (hidden_or_visible) {   //ÏÔÊ¾ºÍÒþ²Øselect¿Ø¼þ
//	alert(document.getElementsByTagName("select"));
	var arrObjSelect=document.getElementsByTagName("select");
//	alert(arrObjSelect);
//	alert(arrObjSelect.length);
	for (var index=0;index<arrObjSelect.length;index++) {
		arrObjSelect[index].style.visibility=hidden_or_visible;
	}
}

function open_x () {
	var msgBox=document.createElement("div");
	msgBox.setAttribute("id","msgBox1");
	msgBox.setAttribute("align","center");
	msgBox.style.background="white";
	msgBox.style.border="1px solid buttonface";
	msgBox.style.position="absolute";
	msgBox.style.left="50%";
	msgBox.style.top="50%";
	msgBox.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
	msgBox.style.width="250px";
	msgBox.style.height="100px";
	msgBox.style.textAlign="center";
	msgBox.style.lineHeight="25px";
	msgBox.style.zIndex="10001";
	
	var title=document.createElement("h4");
	title.onclick=function(){
		close_mask();
		document.body.removeChild(msgBox);
	}
	title.innerHTML="CLOSE";
	msgBox.appendChild(title);
	
	document.body.appendChild(msgBox);
}

var $MASK_RUN_TARGET;
var $MASK_RUN_INNER_TARGET;
function openRunMask () {
	if ($MASK_RUN_TARGET) {
		return;
	}
	var sWidth=document.documentElement.clientWidth>document.body.clientWidth?document.documentElement.clientWidth:document.body.clientWidth;
	var sHeight=document.documentElement.clientHeight>document.body.clientHeight?document.documentElement.clientHeight:document.body.clientHeight;
	if(navigator.appName=="Microsoft Internet Explorer") {
	} else {
		sHeight+=25;	// fill.
	}
	var bgObj=document.createElement("div");
	$MASK_RUN_TARGET = bgObj;
	bgObj.setAttribute('id','bgDiv');
	bgObj.style.background="#ffffff";
	bgObj.style.position="absolute";
	if(navigator.appName=="Microsoft Internet Explorer") {
		bgObj.style.filter="alpha(opacity=50)";
	} else {
		bgObj.style.MozOpacity="0.5";
	}
	bgObj.style.top="0";
	bgObj.style.left="0";
	bgObj.style.width="100%";
	bgObj.style.height=sHeight + "px";
	bgObj.style.zIndex = "20000";
	document.body.appendChild(bgObj);
	
	var loadingObj=document.createElement("div");
	$MASK_RUN_INNER_TARGET=loadingObj;
	loadingObj.innerHTML="<img src=\""+$PENNY_CMS_CMS_URL_PATH+"/utils/img/loading.gif\" alt=\"loading\" title=\"loading\" />";
	loadingObj.style.position="absolute";
	loadingObj.style.top="50%";
	loadingObj.style.left="50%";
	loadingObj.style.zIndex = "20100";
	document.body.appendChild(loadingObj);
	
//	bgObj.style.position="absolute";
//	bgObj.style.top=sWidth/2+"px";
//	bgObj.style.left=sHeight/2+"px";
//	bgObj.appendChild(loadingObj);
	
	window.onresize=function(){
		if ($MASK_RUN_TARGET) {
			var sHeight=document.documentElement.clientHeight>document.body.clientHeight?document.documentElement.clientHeight:document.body.clientHeight;
			if(navigator.appName=="Microsoft Internet Explorer") {
			} else {
				sHeight+=25;	// fill.
			}
			$MASK_RUN_TARGET.style.height=sHeight + "px";	// W3C DTD IE/FF;
		}
	}
}

function closeRunMask () {
	if ($MASK_RUN_TARGET) {
		document.body.removeChild($MASK_RUN_TARGET);
		$MASK_RUN_TARGET=null;
	}
	if ($MASK_RUN_INNER_TARGET) {
		document.body.removeChild($MASK_RUN_INNER_TARGET);
		$MASK_RUN_INNER_TARGET=null;
	}
}

var $MASK_TARGET;
var $MASK_INNER_TARGET;
function openMask () {
	if ($MASK_TARGET) {
		return;
	}
	var sWidth=document.documentElement.clientWidth>document.body.clientWidth?document.documentElement.clientWidth:document.body.clientWidth;
	var sHeight=document.documentElement.clientHeight>document.body.clientHeight?document.documentElement.clientHeight:document.body.clientHeight;
	if(navigator.appName=="Microsoft Internet Explorer") {
	} else {
		sHeight+=25;	// fill.
	}
	var bgObj=document.createElement("div");
	$MASK_TARGET = bgObj;
	bgObj.setAttribute('id','bgDiv');
	bgObj.style.background="#000";
	bgObj.style.position="absolute";
	if(navigator.appName=="Microsoft Internet Explorer") {
		bgObj.style.filter="alpha(opacity=50)";
	} else {
		bgObj.style.MozOpacity="0.5";
	}
	bgObj.style.top="0";
	bgObj.style.left="0";
	bgObj.style.width="100%";
	bgObj.style.height=sHeight + "px";
	bgObj.style.zIndex = "10000";
	document.body.appendChild(bgObj);
	
	window.onresize=function(){
		if ($MASK_TARGET) {
			var sHeight=document.documentElement.clientHeight>document.body.clientHeight?document.documentElement.clientHeight:document.body.clientHeight;
			if(navigator.appName=="Microsoft Internet Explorer") {
			} else {
				sHeight+=25;	// fill.
			}
			$MASK_RUN_TARGET.style.height=sHeight + "px";	// W3C DTD IE/FF;
		}
	}
}

function closeMask () {
	if ($MASK_TARGET) {
		document.body.removeChild($MASK_TARGET);
		$MASK_TARGET=null;
	}
	if ($MASK_INNER_TARGET) {
		document.body.removeChild($MASK_INNER_TARGET);
		$MASK_INNER_TARGET=null;
	}
}

var edit_able = false;

function editTrue() {	
	edit_able = true;
}

function editFalse() {
	edit_able = false;
}

function gotoNextElemnt (src_obj, tag_id) {
	var $src_obj=$(arguments[0]);
	var $tag_obj=$(arguments[1]);
	var maxlength = $src_obj.getAttribute("maxlength");
	var length = $src_obj.value.length;
	var events = Pennyutils.events.getEvent();
	var keyCode = events.keyCode;
	
	if (
		(keyCode == 33) || (keyCode == 34) || (keyCode == 35) || (keyCode == 36) ||
		(keyCode == 37) || (keyCode == 38) || (keyCode == 39) || (keyCode == 40)
	) {
		edit_able = false;
		return;
	}
	
	if (edit_able) {return;}
	
	if ((length==maxlength)&&($tag_obj!=null)) {$tag_obj.focus();}
}

function gotoNextDateTimeElemnt () {
	var $src_obj=$(arguments[0]+arguments[1]);
	var $tag_obj=$(arguments[0]+arguments[2]);
	var maxlength = $src_obj.getAttribute("maxlength");
	var length = $src_obj.value.length;
	var events = Pennyutils.events.getEvent();
	var keyCode = events.keyCode;
	
	if (
		(keyCode == 33) || (keyCode == 34) || (keyCode == 35) || (keyCode == 36) ||
		(keyCode == 37) || (keyCode == 38) || (keyCode == 39) || (keyCode == 40)
	) {
		edit_able = false;
		return;
	}
	
	if (edit_able) {return;}
	
	if ((length==maxlength)&&($tag_obj!=null)) {generateDateTime(arguments[0]);$tag_obj.focus();$tag_obj.select()}
}

function generateDateTime () {
	var $_year=Number($(arguments[0]+'_year').value);
	var $_month=Number($(arguments[0]+'_month').value);
	var $_date=Number($(arguments[0]+'_date').value);
	
	var $_hour=Number($(arguments[0]+'_hour').value);
	var $_minute=Number($(arguments[0]+'_minute').value);
	var $_second=Number($(arguments[0]+'_second').value);
	if (($_year+$_month+$_date+$_hour+$_minute+$_second)==0) {
		$(arguments[0]).value='';
	} else {
		var $date_time=new Date();
//		$_year=$_year.length>0?$_year:$date_time.getFullYear();
		$_year=$_year>0?$_year:$date_time.getFullYear();
		$_month=$_month>0&&$_month<13?$_month:$date_time.getMonth()+1;
		$_date=$_date>0&&$_date<32?$_date:$date_time.getDate();
		$_hour=$_hour>=0&&$_hour<24?$_hour:$date_time.getHours();
		$_minute=$_minute>=0&&$_minute<60?$_minute:$date_time.getMinutes();
		$_second=$_second>=0&&$_second<60?$_second:$date_time.getSeconds();
		
		$date_time=new Date($_year, $_month-1, $_date, $_hour, $_minute, $_second);
		$_year=$date_time.getFullYear()+'';
		$_month=$date_time.getMonth()+1+'';
		$_date=$date_time.getDate()+'';
		$_hour=$date_time.getHours()+'';
		$_minute=$date_time.getMinutes()+'';
		$_second=$date_time.getSeconds()+'';
		
		$_year=$_year;
		$_month=$_month.length==2?$_month:'0'+$_month;
		$_date=$_date.length==2?$_date:'0'+$_date;
		$_hour=$_hour.length==2?$_hour:'0'+$_hour;
		$_minute=$_minute.length==2?$_minute:'0'+$_minute;
		$_second=$_second.length==2?$_second:'0'+$_second;
		
		$(arguments[0]+'_year').value=$_year;
		$(arguments[0]+'_month').value=$_month;
		$(arguments[0]+'_date').value=$_date;
		$(arguments[0]+'_hour').value=$_hour;
		$(arguments[0]+'_minute').value=$_minute;
		$(arguments[0]+'_second').value=$_second;
		
		$(arguments[0]).value=$_year+'-'+$_month+'-'+$_date+' '+$_hour+':'+$_minute+':'+$_second;
	}
}

function gotoNextDateElemnt () {
	var $src_obj=$(arguments[0]+arguments[1]);
	var $tag_obj=$(arguments[0]+arguments[2]);
	var maxlength = $src_obj.getAttribute("maxlength");
	var length = $src_obj.value.length;
	var events = Pennyutils.events.getEvent();
	var keyCode = events.keyCode;
	
	if (
		(keyCode == 33) || (keyCode == 34) || (keyCode == 35) || (keyCode == 36) ||
		(keyCode == 37) || (keyCode == 38) || (keyCode == 39) || (keyCode == 40)
	) {
		edit_able = false;
		return;
	}
	
	if (edit_able) {return;}
	
	if ((length==maxlength)&&($tag_obj!=null)) {generateDate(arguments[0]);$tag_obj.focus();$tag_obj.select()}
}

function generateDate () {
	var $_year=Number($(arguments[0]+'_year').value);
	var $_month=Number($(arguments[0]+'_month').value);
	var $_date=Number($(arguments[0]+'_date').value);
	if (($_year+$_month+$_date)==0) {
		$(arguments[0]).value='';
	} else {
		var $date_time=new Date();
		$_year=$_year>0?$_year:$date_time.getFullYear();
		$_month=$_month>0&&$_month<13?$_month:$date_time.getMonth()+1;
		$_date=$_date>0&&$_date<32?$_date:$date_time.getDate();
		
		$date_time=new Date($_year, $_month-1, $_date);
		$_year=$date_time.getFullYear()+'';
		$_month=$date_time.getMonth()+1+'';
		$_date=$date_time.getDate()+'';
		
		$_year=$_year;
		$_month=$_month.length==2?$_month:'0'+$_month;
		$_date=$_date.length==2?$_date:'0'+$_date;
		
		$(arguments[0]+'_year').value=$_year;
		$(arguments[0]+'_month').value=$_month;
		$(arguments[0]+'_date').value=$_date;
		
		$(arguments[0]).value=$_year+'-'+$_month+'-'+$_date;
	}
}
