now=new Date();
static_now=new Date();
week=new Array("ÀÏ","¿ù","È­","¼ö","¸ñ","±Ý","Åä");


	//´Þ·ÂÇÔ¼ö
	function reserve_calender(val,element_name,pDay,st){

	///alert(pDay);
  //alert( now.getFullYear() );
	var p;
	var z=0;
	
	switch(val){
		case 1:now.setYear(now.getFullYear()-1);break;
		case 2:now.setMonth(now.getMonth()-1);break;
		case 3:now.setMonth(now.getMonth()+1);break;
		case 4:now.setYear(now.getFullYear()+1);break;
				//	now.setMonth(now.getMonth() - val);
	}

	sc="<input type=\"button\" onclick=\"reserve_calender(1,'"+element_name+"','"+pDay+"','"+st+"')\" style=\"cursor:hand\" value=\"¢¸\">";
	sc+="<input type=\"button\" onclick=\"reserve_calender(2,'"+element_name+"','"+pDay+"','"+st+"')\" style=\"cursor:hand\" value=\"¢·\"> ";
	sc+="<b>"+now.getFullYear()+" ³â / ";
	sc+=(now.getMonth()+1)+" ¿ù</b>";  
	sc+="<input type=\"button\" onclick=\"reserve_calender(3,'"+element_name+"','"+pDay+"','"+st+"')\" style=\"cursor:hand\" value=\"¢¹\">";
	sc+="<input type=\"button\" onclick=\"reserve_calender(4,'"+element_name+"','"+pDay+"','"+st+"')\" style=\"cursor:hand\" value=\"¢º\">";


	

	//ÇØ´ç¿ù ¸¶Áö¸· ÀÏÀÚ
	last_date = new Date(now.getFullYear(),now.getMonth()+1,1-1);
	
	//ÇØ´ç¿ù Ã³À½ÀÏÀÚ ¿äÀÏ
	first_date= new Date(now.getFullYear(),now.getMonth(),1);

	//½ºÅ²
	calender_area="<table style='border:1 solid #dcdcdc' cellspacing='0' cellpadding='0'><tr><td><table cellpadding='1' cellspacing='0' bgcolor='#dcdcdc' style='border:1 solid #808080'>";
	calender_area+="<tr bgcolor='#006699'><td colspan='10' style='border-bottom:1 solid #808080;font-size:9pt' align='center' style='color:#ffffff'>"+sc+"</td></tr><tr>";

		//¿äÀÏÇ¥½Ã
		var color='#FF6600';
		for(i=0;i<week.length;i++){
			calender_area+="<td width=60 bgcolor='#2E8BAF'  style='border-left:1 solid #dcdcdc;border-bottom:1 solid #808080;color:"+color+";font-size:9pt' align='center'><b>"+week[i]+"</b></td>";
			color='#ffffff';
		}
			calender_area+="</tr><tr>";

		for(i=1;i<=first_date.getDay();i++){
			calender_area+="<td align='right' valign='top' bgcolor='#ffffff'  style='border-left:1 solid #dcdcdc;border-bottom:1 solid #dcdcdc'>&nbsp;</td>";
		}
		
		
		z=(i-1);
		for (i=1;i<=last_date.getDate();i++)
		{
			z++;
			p=z%7;
			var pmonth=now.getMonth()+1;
			var pmonth2=now.getMonth()+1;

			if(i<10){var ii="0"+i;}else{var ii=i;}
			if(pmonth<10){pmonth="0"+pmonth;}

			if(p == 0)
			{
				pValue = 6;
			}
			else
			{
				pValue = p-1;
			}



			sDate = mktime(1, 1, 1, pmonth, i, now.getFullYear());
			tDate = mktime(1,1,1, static_now.getMonth()+1,static_now.getDate(),static_now.getFullYear());
			var g = 0;
			if (st!="") {
			  var arr_date	= st.split("|");
			  for (var t=0; t<arr_date.length;t++)
			  {
			  	var arr =arr_date[t].split("-");
			  	var arr_year = arr[0];
			  	var arr_month = arr[1];
			  	var arr_day = arr[2];
			  	if ((static_now.getFullYear() == arr_year) && (pmonth == arr_month) && (i== arr_day))
			  	{
			  		 g=1;
			  		 calender_area+="<td align='right' valign='top' bgcolor='#ffffff' style='border-left:1 solid #dcdcdc;border-bottom:1 solid #dcdcdc'  align='center'  onclick=\"red_alert()\"  onmouseover=\"this.bgColor='#eeeeee'\" onmouseout=\"this.bgColor='#ffffff'\" style='cursor:hand' height='22' width='22'>";
			  	}
			  	
			  }
			} 
			if(sDate>tDate)
			{
				if ( g == 0) {
					if(pDay == '9/')
					{
					calender_area+="<td align='right' valign='top' bgcolor='#ffffff' style='border-left:1 solid #dcdcdc;border-bottom:1 solid #dcdcdc'  align='center'  onclick=\"change_date('"+now.getFullYear()+"-"+pmonth+"-"+ii+"','"+element_name+"')\"  onmouseover=\"this.bgColor='#eeeeee'\" onmouseout=\"this.bgColor='#ffffff'\" style='cursor:hand' height='22' width='22'>";
					}
					else
					{
						if(strpos(pDay,pValue) == 1 || strpos(pDay,pValue) == 2 || strpos(pDay,pValue) == 3 || strpos(pDay,pValue) == 4 || strpos(pDay,pValue) == 5 || strpos(pDay,pValue) == 6)
						{
							calender_area+="<td align='right' valign='top' bgcolor='#ffffff' style='border-left:1 solid #dcdcdc;border-bottom:1 solid #dcdcdc'  align='center'  onclick=\"change_date('"+now.getFullYear()+"-"+pmonth+"-"+ii+"','"+element_name+"')\"  onmouseover=\"this.bgColor='#eeeeee'\" onmouseout=\"this.bgColor='#ffffff'\" style='cursor:hand' height='22' width='22'>";
						}
						else if(strpos(pDay,pValue) === 0)
						{
							calender_area+="<td align='right' valign='top' bgcolor='#ffffff' style='border-left:1 solid #dcdcdc;border-bottom:1 solid #dcdcdc'  align='center'  onclick=\"change_date('"+now.getFullYear()+"-"+pmonth+"-"+ii+"','"+element_name+"')\"  onmouseover=\"this.bgColor='#eeeeee'\" onmouseout=\"this.bgColor='#ffffff'\" style='cursor:hand' height='22' width='22'>";
						}
						else
						{
							calender_area+="<td align='right' valign='top' bgcolor='#ffffff' style='border-left:1 solid #dcdcdc;border-bottom:1 solid #dcdcdc'  align='center'  onclick=\"red_alert()\"  onmouseover=\"this.bgColor='#eeeeee'\" onmouseout=\"this.bgColor='#ffffff'\" style='cursor:hand' height='22' width='22'>";
						}
					}
			  }
			}
			else
			{
				if (g == 0) {
					calender_area+="<td align='right' valign='top' bgcolor='#ffffff' style='border-left:1 solid #dcdcdc;border-bottom:1 solid #dcdcdc'  align='center'  onclick=\"red_alert()\"  onmouseover=\"this.bgColor='#eeeeee'\" onmouseout=\"this.bgColor='#ffffff'\" style='cursor:hand' height='22' width='22'>";
			  }
			}
			


			//if(i == now.getDate() && now.getFullYear()==static_now.getFullYear() && now.getMonth()==static_now.getMonth()
      var k = 0;
			if (st!="") {
			  var arr_date	= st.split("|");
			  for (var t=0; t<arr_date.length;t++)
			  {
			  	var arr =arr_date[t].split("-");
			  	var arr_year = arr[0];
			  	var arr_month = arr[1];
			  	var arr_day = arr[2];
			  	if ((static_now.getFullYear() == arr_year) && (pmonth == arr_month) && (i== arr_day))
			  	{
			  		 k=1;
			  		 calender_area+="<span style='color:#339900;;font-size:8pt'><B>"+i+"</B></span>";
			  	}
			  	
			  }
			} 


			if(sDate>tDate)
			{
				if (k == 0) {
						if(pDay == '9/')
						{
							calender_area+="<span style='color:#000000;font-size:8pt'><B>"+i+"</B></span>";
						}
						else
						{
							if(strpos(pDay,pValue) == 1 || strpos(pDay,pValue) == 2 || strpos(pDay,pValue) == 3 || strpos(pDay,pValue) == 4 || strpos(pDay,pValue) == 5 || strpos(pDay,pValue) == 6)
							{
								calender_area+="<span style='color:#000000;font-size:8pt'><B>"+i+"</B></span>";
		
										//¿À´ÃÀÇ »ö»ó
										/*
										if(i == now.getDate() && now.getFullYear()==static_now.getFullYear() && now.getMonth()==static_now.getMonth()) {
																		   calender_area+="<span style='color:#339900;font-size:8pt'><B>"+i+"</B></span>";}
											else if(p == 0){calender_area+="<span style='color:#0000ff;font-size:8pt' ><B>"+i+"</B></span>";}
											else if(p == 1){calender_area+="<span style='color:#ff0000;font-size:8pt'><B>"+i+"</B></span>";}
																else{calender_area+="<span style='color:#4b4b4b;font-size:8pt'><B>"+i+"</B></span>";}
										*/
							}
							else if(strpos(pDay,pValue) === 0)
							{
								calender_area+="<span style='color:#000000;font-size:8pt'><B>"+i+"</B></span>";
							}
							else
							{
								calender_area+="<span style='color:#cccccc;font-size:8pt'><B>"+i+"</B></span>";
							}
						}
			  }

			}
			else
			{
				if (k == 0) {
				   calender_area+="<span style='color:#cccccc;font-size:8pt'><B>"+i+"</B></span>";
			  }
			}



			




			calender_area+="</td>";
			
			if(p==0 && last_date.getDate() != i){calender_area+="</tr><tr>";}
		}
	
		if(p !=0){
			for(i=p;i<7;i++){
					calender_area+="<td align='right' valign='top' bgcolor='#ffffff' style='border-left:1 solid #dcdcdc;border-bottom:1 solid #dcdcdc'>&nbsp;</td>";
			}
		}

	//½ºÅ²
	calender_area+="</tr></table>";
	s_area.innerHTML=calender_area;
	

	}
	function check_mouse(val,pDay,st){
		
		reserve_calender('not',val,pDay,st);
		s_area.style.visibility="visible";
		s_area.style.left=event.clientX-10+document.body.scrollLeft; 
		s_area.style.top=event.clientY+document.body.scrollTop; 
	}
	function change_date(val,element_name){

		calDate = str_replace('-','',val);
		/*
		var now = new Date();
		tDate = now.format("isoDate");
		alert(tDate);


		if(calDate > tDate)
		{
			alert('¿À´Ãº¸´Ù Å©´Ù');
		}
		else
		{
			alert('¿À´Ãº¸´Ù ÀÛ´Ù');
		}
		*/
    alert(element_name);
		eval(element_name).value=val;
		s_area.style.visibility="hidden";

		
	}
	function red_alert(){
		alert('ÀÌ ³¯Àº Ãâ¹ßÀÏÀÌ ¾Æ´Õ´Ï´Ù.');
	}

	function strpos( haystack, needle, offset){
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Onno Marsman    
    // *     example 1: strpos('Kevin van Zonneveld', 'e', 5);
    // *     returns 1: 14
 
    var i = (haystack+'').indexOf( needle, offset ); 
    return i===-1 ? false : i;
	}
	function str_replace(search, replace, subject) {
		// http://kevin.vanzonneveld.net
		// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
		// +   improved by: Gabriel Paderni
		// +   improved by: Philip Peterson
		// +   improved by: Simon Willison (http://simonwillison.net)
		// +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
		// +   bugfixed by: Anton Ongson
		// +      input by: Onno Marsman
		// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
		// +    tweaked by: Onno Marsman
		// *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
		// *     returns 1: 'Kevin.van.Zonneveld'
		// *     example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
		// *     returns 2: 'hemmo, mars'
	 
		var f = search, r = replace, s = subject;
		var ra = r instanceof Array, sa = s instanceof Array, f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;
	 
		while (j = 0, i--) {
			if (s[i]) {
				while (s[i] = (s[i]+'').split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
			}
		};
	 
		return sa ? s : s[0];
	}

function mktime() {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: baris ozdil
    // +      input by: gabriel paderni 
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: FGFEmperor
    // +      input by: Yannoo
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: jakes
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Marc Palau
    // *     example 1: mktime(14, 10, 2, 2, 1, 2008);
    // *     returns 1: 1201871402
    // *     example 2: mktime(0, 0, 0, 0, 1, 2008);
    // *     returns 2: 1196463600
    // *     example 3: make = mktime();
    // *     example 3: td = new Date();
    // *     example 3: real = Math.floor(td.getTime()/1000);
    // *     example 3: diff = (real - make);
    // *     results 3: diff < 5
    
    var no, ma = 0, mb = 0, i = 0, d = new Date(), argv = arguments, argc = argv.length;
 
    if (argc > 0){
        d.setHours(0,0,0); d.setDate(1); d.setMonth(1); d.setYear(1972);
    }
 
    var dateManip = {
        0: function(tt){ return d.setHours(tt); },
        1: function(tt){ return d.setMinutes(tt); },
        2: function(tt){ var set = d.setSeconds(tt); mb = d.getDate() - 1; return set; },
        3: function(tt){ var set = d.setMonth(parseInt(tt)-1); ma = d.getFullYear() - 1972; return set; },
        4: function(tt){ return d.setDate(tt+mb); },
        5: function(tt){ return d.setYear(tt+ma); }
    };
    
    for( i = 0; i < argc; i++ ){
        no = parseInt(argv[i]*1);
        if (isNaN(no)) {
            return false;
        } else {
            // arg is number, let's manipulate date object
            if(!dateManip[i](no)){
                // failed
                return false;
            }
        }
    }
 
    return Math.floor(d.getTime()/1000);
}
	document.write("<div id='s_area' style='font-size:9pt;position:absolute;width:200px;height:100px'>&nbsp;</div>");
