	var theyear = 0;
	var themonth = 0;
	var theday = 0;
	var movey = 0;
	var timer = 0;
	var timeID = 0;
	var date = new Date();
	function dofixdate()
	{
		var y_val;
		var isBC = ( theyear<0);
		if( isBC )
		{
			y_val = String(Math.abs(theyear));
			$('#date_y .badge').show();
		}
		else
		{
			y_val = String(theyear);
			$('#date_y .badge').hide();
		}		
		var len = 4-y_val.length;
		var i;
		for(i=0;i<len;i++)
			y_val = '0'+y_val;

		$('#date_y .date').text(y_val);
		$('#year').val(theyear) ;
		$('#date_y div.up').width($('#date_y div.date').width());
		$('#date_y div.down').width($('#date_y div.date').width());
	}
	function setupDate(year,month,day)
	{
		theyear = parseInt(year,10);
		themonth = parseInt(month,10);
		theday = parseInt(day,10);
		dofixdate();
	}
	function docheckdate()
	{
		if( theday > 28)
		{
			while( ! isValidDate(theyear,themonth,theday))
			{
				theday = theday -1;
				if( theday <= 28 )
					break;
			}
			$('#date_d .date').text(theday);
		}
		$('#day').val(theday);
		$('#date_m div.up').width($('#date_m div.date').width());
		$('#date_m div.down').width($('#date_m div.date').width());
		$('#date_d div.up').width($('#date_d div.date').width());
		$('#date_d div.down').width($('#date_d div.date').width());
	}
	function yscroll()
	{
		theyear = theyear+movey;
		if( theyear > 9999)
			theyear = 9999;
		else if(theyear < -9999)
			theyear = -9999;
		else if(theyear==0)
		{
			if(movey > 0)
				theyear = 1;
			else
				theyear = -1;
		}

		docheckdate();
		$('#date_y div.date').text(String(theyear));
		$('#year').val(theyear) ;
		dofixdate();
		
		if( timeID != 0 )
			clearTimeout(timeID);
		
		timer ++;
		if( timer <= 2 )
			timeID = setTimeout("yscroll()", 500);
		else if( timer <= 5 )
			timeID = setTimeout("yscroll()", 300);
		else if( timer <= 10 )
			timeID = setTimeout("yscroll()", 200);
		else if( timer <= 15 )
			timeID = setTimeout("yscroll()", 100);
		else
		{
 			if( timer > 50 )
 				if( timer > 100 )
 				{
 					if( movey > 0 )
 						movey = 100;
					else
 						movey = -100;
 				}
				else
				{
 					if( movey > 0 )
 						movey = 10;
					else
 						movey = -10;
				}
			 timeID = setTimeout("yscroll()", 100);
		}
	}
	function mscroll()
	{
		 if( (themonth >= 12)&&(movey>0))
		{
			var dt = new Date(theyear,themonth,theday);
			theyear = dt.getFullYear();
			themonth = dt.getMonth()+1;
			theday = dt.getDate();
		}
		else if( (themonth <= 1)&&(movey<0))
		{
			var dt = new Date(theyear,themonth-2,theday);
			theyear = dt.getFullYear();
			themonth = dt.getMonth()+1;
			theday = dt.getDate();
		}
		else
		{
			if( movey > 0 )
				themonth = themonth+1;
			else
				themonth = themonth-1;
		}

		docheckdate();
		if( themonth<10 )
			$('#date_m div.date').text("0"+themonth);
		else
			$('#date_m div.date').text(themonth);
		$('#date_y div.date').text(String(theyear));
		$('#year').val(theyear) ;
		$('#month').val(themonth) ;
		$('#date_m div.up').width($('#date_m div.date').width());
		$('#date_m div.down').width($('#date_m div.date').width());
		if( timeID != 0 )
			clearTimeout(timeID);

		timeID = setTimeout("mscroll()", 200);
	}
	function dscroll()
	{
		 if( (theday >= 28)&&(movey>0))
		{
			var dt = new Date(theyear,themonth-1,theday);
			dt.setTime(dt.getTime() + 86400000);
			dt.getTime();
			theyear = dt.getFullYear();
			themonth = dt.getMonth()+1;
			theday = dt.getDate();
		}
		else if( (theday <= 1)&&(movey<0))
		{
			var dt = new Date(theyear,themonth-1,theday);
			dt.setTime(dt.getTime() - 86400000);
			theyear = dt.getFullYear();
			themonth = dt.getMonth()+1;
			theday = dt.getDate();
		}
		else
		{
			if( movey > 0 )
				theday = theday+1;
			else
				theday = theday-1;
		}
		docheckdate();

		if( theday<10 )
			$('#date_d div.date').text("0"+theday);
		else
			$('#date_d div.date').text(theday);
		$('#date_y div.date').text(String(theyear));
		$('#year').val(theyear) ;
		$('#month').val(themonth) ;

		if( themonth<10 )
			$('#date_m div.date').text("0"+themonth);
		else
			$('#date_m div.date').text(themonth);


		$('#date_d div.up').width($('#date_d div.date').width());
		$('#date_d div.down').width($('#date_d div.date').width());
		if( timeID != 0 )
			clearTimeout(timeID);
		
		timeID = setTimeout("dscroll()", 200);
	}
	$(document).ready(function(){
		$('#date_y div.up').bind('mousedown',function( event ){
			movey = 1;
			timer = 0;
			yscroll();
			$('#date_y div.down').hide();
		});
		$('#date_y div.down').bind('mousedown',function( event ){
			movey = -1;
			timer = 0;
			yscroll();
			$('#date_y div.up').hide();
		});
		$('#date_m div.up').bind('mousedown',function( event ){
			movey = 1;
			timer = 0;
			mscroll();
			$('#date_m div.down').hide();
		});
		$('#date_m div.down').bind('mousedown',function( event ){
			movey = -1;
			timer = 0;
			mscroll();
			$('#date_m div.up').hide();
		});
		$('#date_d div.up').bind('mousedown',function( event ){
			movey = 1;
			timer = 0;
			dscroll();
			$('#date_d div.down').hide();
		});
		$('#date_d div.down').bind('mousedown',function( event ){
			movey = -1;
			timer = 0;
			dscroll();
			$('#date_d div.up').hide();
		});
		$('div.up').bind('mouseup',function( event ){
			clearTimeout(timeID);
		});
		$('div.down').bind('mouseup',function( event ){
			clearTimeout(timeID);
		});
		$('#date_y').bind("mouseover",function() {
			$('#date_y div.up').css('left',$('#date_y div.date').offset().left);
			$('#date_y div.down').css('left',$('#date_y div.date').offset().left);
			$('#date_y div.up').width($('#date_y div.date').width()).show();
			$('#date_y div.down').width($('#date_y div.date').width()).show();
		}).bind("mouseout",function() {
			$('#date_y div.up').hide();
			$('#date_y div.down').hide();
		});
		$('#date_m').bind("mouseover",function() {
			$('#date_m div.up').css('left',$('#date_m div.date').offset().left);
			$('#date_m div.down').css('left',$('#date_m div.date').offset().left);
			$('#date_m div.up').width($('#date_m div.date').width()).show();
			$('#date_m div.down').width($('#date_m div.date').width()).show();
		}).bind("mouseout",function() {
			$('#date_m div.up').hide();
			$('#date_m div.down').hide();
		});
		$('#date_d').bind("mouseover",function() {
			$('#date_d div.up').css('left',$('#date_d div.date').offset().left);
			$('#date_d div.down').css('left',$('#date_d div.date').offset().left);
			$('#date_d div.up').width($('#date_d div.date').width()).show();
			$('#date_d div.down').width($('#date_d div.date').width()).show();
		}).bind("mouseout",function() {
			$('#date_d div.up').hide();
			$('#date_d div.down').hide();
		});
		$("#arrowtab").bind("click",function() {
			if( $('#header').css('height') == '320px' )
			{
				$('#header').animate({height:'140px'},'fast','linear',function(){dofixdate();});
				$('#arrowtab').animate({top:'128px'},'fast','linear');
				$('#date_form').hide();
				$('#date_y .badge').hide();
				$('#menu').animate({top:'128px'},'fast','linear');
			}
			else
			{		
				$('#date_form').show();
				$('#header').animate({height:'320px'},'fast','linear',function(){dofixdate();});
				$('#arrowtab').animate({top:'308px'},'fast','linear');
				$('#menu').animate({top:'308px'},'fast','linear');
			}
		});
		$('.noselect').disableTextSelect();
	});

function isValidDate(y,m,d){ var di = new Date(y,m-1,d); if(di.getFullYear() == y && di.getMonth() == m-1 && di.getDate() == d){ return true; } return false; }
function URLencode(str){
 // Unicode to URL encoded UTF-8
 var i, encoded_str, char_code, padded_str;
         encoded_str = "";
         for (i = 0; i < str.length; i++){
             char_code = str.charCodeAt(i);
             if (char_code == 0x20){
                // space -> "+"
//                encoded_str += "+";}
                encoded_str += " ";}
             else { // else 1
                  if (((0x30 <= char_code) && (char_code <= 0x39)) || ((0x41 <= char_code) && (char_code <= 0x5a)) || ((0x61 <= char_code) && (char_code <= 0x7a))){
		     // [0-9a-z-A-Z]
                     // no escape
                     encoded_str += str.charAt(i);
                  }
		  else if ((char_code == 0x2a) || (char_code == 0x2e) || (char_code == 0x2d) || (char_code == 0x5f)) {
		     // [.-_]
                     // no escape
                     encoded_str += str.charAt(i);
		  }
                  else { // else 2
                       // for internal unicode to UTF-8
		       // Ref. http://homepage3.nifty.com/aokura/jscript/utf8.html
		       // Ref. http://homepage1.nifty.com/nomenclator/unicode/ucs_utf.htm
                       if ( char_code > 0xffff ) {
                          encoded_str += "%" + ((char_code >> 18) | 0xf0).toString(16).toUpperCase();
                          encoded_str += "%" + (((char_code >> 12) & 0x3f) | 0x80).toString(16).toUpperCase();
			  encoded_str += "%" + (((char_code >> 6) & 0x3f) | 0x80).toString(16).toUpperCase();
			  encoded_str += "%" + ((char_code & 0x3f) | 0x80).toString(16).toUpperCase();
		       }
                       else if ( char_code > 0x7ff ) {
                          encoded_str += "%" + ((char_code >> 12) | 0xe0).toString(16).toUpperCase();
			  encoded_str += "%" + (((char_code >> 6) & 0x3f) | 0x80).toString(16).toUpperCase();
			  encoded_str += "%" + ((char_code & 0x3f) | 0x80).toString(16).toUpperCase();
                       }
                       else if ( char_code > 0x7f ) {
		          encoded_str += "%" + (((char_code >> 6) & 0x1f) | 0xc0).toString(16).toUpperCase();
			  encoded_str += "%" + ((char_code & 0x3f) | 0x80).toString(16).toUpperCase();
                       }
                       else {
                          // for ascii
                          padded_str = "0" + char_code.toString(16).toUpperCase();
                          encoded_str += "%" + padded_str.substr(padded_str.length - 2, 2);
                       }
                    } // else 2
                } // else 1
        } // for
        return encoded_str;
}

(function($) {if ($.browser.msie) {$.fn.disableTextSelect = function() {return this.each(function() {$(this).bind('selectstart.disableTextSelect', function() {return false;});});};$.fn.enableTextSelect = function() {return this.each(function() {$(this).unbind('selectstart.disableTextSelect');});};} else {$.fn.disableTextSelect = function() {return this.each(function() {$(this).bind('mousedown.disableTextSelect', function() {return false;});});};$.fn.enableTextSelect = function() {return this.each(function() {$(this).unbind('mousedown.disableTextSelect');});};}})(jQuery);
