function MakeArray(n) { this.length = n; return this; }

function getFirstDay(theYear){
	var firstDate = new Date(theYear,this.offset,1)
	return firstDate.getDay()
}

function aMonth(name,length,offset) {
	this.name = name
	this.length = length
	this.offset = offset
	this.getFirstDay = getFirstDay
}

function getFebLength(theYear) {
	theYear = (theYear < 1900) ? theYear + 1900: theYear
	if ((theYear % 4 == 0 && theYear % 100 != 0) || theYear % 400 == 0) {
		return 29;
	}
	return 28;
}


theMonths = new MakeArray(12)
theMonths[1] = new aMonth("January",31,0)
theMonths[2] = new aMonth("February",28,1)
theMonths[3] = new aMonth("March",31,2)
theMonths[4] = new aMonth("April",30,3)
theMonths[5] = new aMonth("May",31,4)
theMonths[6] = new aMonth("June",30,5)
theMonths[7] = new aMonth("July",31,6)
theMonths[8] = new aMonth("August",31,7)
theMonths[9] = new aMonth("September",30,8)
theMonths[10] = new aMonth("October",31,9)
theMonths[11] = new aMonth("November",30,10)
theMonths[12] = new aMonth("December",31,11)

//¿À´Ã
var today= new Date()
var toy = today.getYear()
var tom = today.getMonth()
var tod = today.getDate()
var toh = today.getHours()
var ton = today.getMinutes()

//±âº»Æ² »Ñ·ÁÁÖ±â
function writedate(gotp,form,name)
{

    var	content = ""
    content += "<DIV id='div1' style='DISPLAY:none;WIDTH:164px;border:0px' onblur='closeCarlender()'><CENTER>"
    content += "<table width='188' border='0' cellspacing='0' cellpadding='0'> "
    content += "<tr>  "
    content += "  <td width='15' height='30'><img src='../image/goods/day_img1.gif' width='15' height='30'></td> "
    content += "  <td width='158' background='../image/goods/day_img2.gif' align='center'>  "
    content += "	<table width='120' border='0' cellspacing='0' cellpadding='0'> "
    content += "	  <tr>  "
    content += "		<td width='15'><img src='../image/goods/day_pre.gif' width='13' height='12' align='absmiddle' border='0' onclick='stepmove(\""+form+"\",\""+name+"\",-1);return false;' style='cursor:hand'></td> "
    content += "		<td align='center' height='18' valign='bottom'><b><input type=text style='width:32px;' name='"+ name +"Year'  class='txt_bold txt_99' style='border:0; height:18;background-color:#DEE7F6' readonly></b>³â <b><input type=text style='width:18px;' name='"+ name +"Month' class='txt_bold txt_99' style='border:0' readonly class='txt_bold txt_99' style='border:0; height:18;background-color:#DEE7F6'  ></b>¿ù</td> "
    content += "		<td width='15' align='right'><img src='../image/goods/day_next.gif' width='13' height='12' align='absmiddle' border='0' style='font-size:10;' onclick='stepmove(\""+form+"\",\""+name+"\",1);return false;'  style='cursor:hand'></td> "
    content += "	  </tr> "
    content += "	</table> "
    content += "  </td> "
    content += "  <td width='15'><img src='../image/goods/day_img3.gif' width='15' height='30'></td> "
    content += "</tr> "
    content += "<tr>  "
    content += "  <td colspan='3'><img src='../image/goods/day_img4.gif' width='188' height='7'></td></tr><tr>  "
    content += "  <td width='15' background='../image/goods/day_img5.gif'>&nbsp;</td> "
    content += "  <td width='158' valign='top' align='center'>  "
    content += "	<table width='147' border='0' cellspacing='0' cellpadding='0'> "
    content += "	  <tr align='center'>  "
    content += "		<td width='21' height='17' class='day'><b>ÀÏ</b></td> "
    content += "		<td width='21' class='day'><b>¿ù</b></td> "
    content += "		<td width='21' class='day'><b>È­</b></td> "
    content += "		<td width='21' class='day'><b>¼ö</b></td> "
    content += "		<td width='21' class='day'><b>¸ñ</b></td> "
    content += "		<td width='21' class='day'><b>±Ý</b></td> "
    content += "		<td width='21' class='day'><b>Åä</b></td> "
    content += "	  </tr> "
    content += "	  <tr valign='top'>  "
    content += "		<td colspan='7' height='7'><img src='../image/goods/day_img8.gif' width='148' height='2'></td> "
    content += "	  </tr> "



    for (i=1,d=1; i<=6; i++) {
	    content += "<tr align='center'>"
	    content += "<td width='21' height='17' class='day' align='center'><INPUT class='Carlender' TYPE='text' NAME='"+name+"Day' style='width:20px;border:0;color:red;' readonly onclick='clickday(\""+gotp+"\",\""+form+"\",\""+name+"\","+d+")' onmouseover='mouseoverit1(this)' onmouseout='mouseoutit(this)' style='text-align:center;'></TD>"
	    d++
	    for (k=2; k<7; k++,d++) {
		    content += "<td width='21' height='17' class='day' align='center'><INPUT class='day' TYPE='text' NAME='"+name+"Day' style='width:20px;border:0;' readonly onclick='clickday(\""+gotp+"\",\""+form+"\",\""+name+"\","+d+")' onmouseover='mouseoverit2(this)' onmouseout='mouseoutit(this)' style='text-align:right;'></TD>"
	    }
	    content += "<td width='21' height='17' class='day' align='center'><INPUT TYPE='day' class='Carlender' NAME='"+name+"Day' style='width:20px;border:0;color:blue' readonly onclick='clickday(\""+gotp+"\",\""+form+"\",\""+name+"\","+d+")' onmouseover='mouseoverit3(this)' onmouseout='mouseoutit(this)' style='text-align:right;'></TD>"
	    content += "</tr>"
	    d++
    }	


    content += "  	</table>  </td><td width='15' background='../image/goods/day_img6.gif'>&nbsp;</td> "
    content += "</tr><tr>   <td colspan='3'><img src='../image/goods/day_img7.gif' width='188' height='15'></td></tr></table> </div>"
    content += "<div class='Carlender' id='div2' style='DISPLAY:none'; border:'0px'><TABLE>"
    content += "</td></tr></TABLE></div>"
	
	
	//content +=


	document.write(content)
	return
}

var oldColor;

function mouseoverit1(obj)
{


	oldColor=obj.style.background;
	
	obj.style.background='#E69495';
	
}

function mouseoverit2(obj)
{
	oldColor=obj.style.background;
	
	obj.style.background='#dddddd';
	
}

function mouseoverit3(obj)
{
	oldColor='#1075DE'
	
	obj.style.background='#75B4F6';
	
}

function mouseoutit(obj)
{
		obj.style.background='#FFFFFF'
}

function getdate()
{


}

function closeCarlender()
{
	//if(document.all["div1"]!=null)
	{
		document.all["div1"].style.display="none";
		document.all["div2"].style.display="none";
	}
}

var setYear;
var setMonth;
var setDay;

function ShowCarlender(left,top,type)
{
	//setTxt_Date=Txt_Date;
	var form="Form1";
	var name="fromtime";
	
	now_set(form,name)	
	
	document.all["div2"].style.top=top+152;	
	document.all["div2"].style.left=left;	
	
	if(type=='ymd')
	{
		document.all["div2"].style.display="none";
	}
	else
	{
		document.all["div2"].style.display="block";
	}
	
	document.all["div1"].style.top=top;	
	document.all["div1"].style.left=left;		
	document.all["div1"].style.display="block";	
	
}


//¸Â´Â ¿ù·Î ¼öÁ¤ÇÏ±â
function viewdate(form,name,y,m) {

	var tar = "document."+form+"."+name

	//¿ù Ã¹³¯ ±âÁØ
	if (y<=0 || m<0) {	y=toy
						m=tom
	}
	var thisdate = new Date(y,m,1)

	var samemonth = false
	if (toy==y && tom==m) samemonth = true

	var dayoffset = thisdate.getDay()
	if (m==1) { theMonths[2].length = getFebLength(y) }

	var howlong =  theMonths[m+1].length

	eval(tar+"Year").value = y
	eval(tar+"Month").value = m+1

	
	for (var i=0; i<42; i++) {
		eval(tar+"Day["+i+"]").style.background="white"
		if (i<dayoffset || i>=(howlong + dayoffset)) {	eval(tar+"Day["+i+"]").value = "" }
		else {	eval(tar+"Day["+i+"]").value = i - dayoffset + 1 }
	}
	
	if(eval(tar+"Year").value==setYear && eval(tar+"Month").value==eval(setMonth))
	{
		eval(tar+"Day["+eval(dayoffset+eval(setDay)-1)+"]").style.background="#aaffee"
	}
	if (toy==y && tom==m) { eval(tar+"Day["+eval(dayoffset+tod-1)+"]").style.background="#C2D6EB" }
	
	

}

function now_set(form,name) {
	
	viewdate(form,name,toy,tom)
	//eval(form+"."+name+"Dayno").value = tod	
	return
}


function clickday(gotp,form,name,num) {
	
	var tar = "document."+form+"."+name
	var y = eval(tar+"Year").value
	var m = eval(eval(tar+"Month").value) - 1
	var mm = eval(eval(tar+"Month").value) 
	var thisdate = new Date(y,m,1)
	var day = eval(tar+"Day["+eval(num-1)+"]").value

	if (day.length>0) {
		for (var i=0; i<42; i++) {	eval(tar+"Day["+i+"]").style.background="white" }
		if (toy==y && tom==m) {	eval(tar+"Day["+ eval(num-day+tod-1)+"]").style.background="#C2D6EB" }
		eval(tar+"Day["+eval(num-1)+"]").style.background="#cc99cc"
		//eval(tar+"Dayno").value = day
	}
	oldColor="#cc99cc";
	if ( day.length >0 ){
    location.href = "/goods/g_search2_result.asp?s_gotp="+gotp+"&s_mon="+mm+"&s_day="+day+"&s_year="+y;
	return
	}
}

//´Þ ÀÌµ¿ ÇÏ±â
function stepmove(form,name,step) {
	var tar = "document."+form+"."+name
	var y = eval(tar+"Year").value
	var m = eval(eval(tar+"Month").value) + eval(step) - 1

	if (m>=12) {	y=eval(y)+1;	m=0;	}
	if (m<0) {		y=eval(y)-1;	m=11;	}
	var d;
	viewdate(form,name,y,m,d)
	return
}
