DTP = {
	
	pc : 0,
	
	dtps : [],
	
    show : function(config) {
        this.init0(config);
    },
	
    container : null,
    //config : null,
	params : null,
	typeParams:null,
	curParams:null,
	currentdatetime:null,
	nextdatetime:null,

    init0 : function(config) {
		for (var i = 0;i < this.dtps.length; i++) {
			if (config.srcObj === this.dtps[i].config.srcObj) {
				this.dtps[i].config.pwc.style.display = '';
				return;
			}
		}
		this.config = config;
		this.params = this.config.params;
		this.typeParams = this.config.typeParams;
		this.curParams = this.config.curParams;
		this.currentdatetime = this.config.currentdatetime;
		this.nextdatetime = this.config.nextdatetime;
		
		document.getElementById("output").style.display = "";
        this.container = document.getElementById("output");
        this.initmh1(this.config.date,this.params,this.typeParams,this.curParams,this.currentdatetime,this.nextdatetime);
        this.initmh2();
        this.initmb(this.config.date,this.params,this.typeParams,this.curParams);
    },
//显示年月
    initmh1 : function(date,params,typeParams,curParams,currentdatetime,nextdatetime) {

		var obj = document.getElementById("dtpHead");
		if (obj == null) {
			obj = this.createnode('div');
			obj.id = "dtpHead";
			obj.className = 'Release_Date_date';
        	this.container.appendChild(obj);
		}
		this.removeChild(obj);
		
		//前一月
        obj1 = this.createnode('div');
        obj1.innerHTML = '<span><input type="image" src="/Templates/Site61/Dino/images/rd_jtl.gif" /></span>';
        obj1.className = 'Release_Date_jtl';
		obj1.style.textAlign = "right";
		obj1.onclick = function() {
			var curYear = date.getRealYear();
			var curMonth = date.getRealMonth();
			var curDay = date.getRealDay();
			curMonth--;
			var curDate = Date.NewDate(curYear,curMonth,curDay);
			//DTP.initmh1(curDate);
			//DTP.initmb(curDate);
			if(currentdatetime == ""){
				currentdatetime = 1;
			}
			var DateString = curDate.getRealYear().toString()+formatMonthAndDay(curDate.getRealMonth()).toString()+currentdatetime.toString();
			window.location="http://www.dinodirect.com/shopways/New-Arrivals-"+params+"-"+DateString+"/"+curParams;
		};
		obj.appendChild(obj1);

        obj2 = this.createnode('span');
		var realMonth = date.getRealMonth();
		var curDateTime = date.getRealYear()+'-'+realMonth;
		if(realMonth == 1)
			realMonth = "Jan";
		else if(realMonth == 2)
			realMonth = "Feb";
		else if(realMonth == 3)
			realMonth = "Mar";
		else if(realMonth == 4)
			realMonth = "Apr";
		else if(realMonth == 5)
			realMonth = "May";
		else if(realMonth == 6)
			realMonth = "Jun";
		else if(realMonth == 7)
			realMonth = "Jul";
		else if(realMonth == 8)
			realMonth = "Aug";
		else if(realMonth == 9)
			realMonth = "Sept";
		else if(realMonth == 10)
			realMonth = "Oct";
		else if(realMonth == 11)
			realMonth = "Nov";
		else if(realMonth == 12)
			realMonth = "Dec";
			
		var montyAndYear = realMonth;
        obj2.innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;"+montyAndYear;
        obj2.className = 'Release_Date_jtwz';
        obj1.appendChild(obj2);
		obj.appendChild(obj1);
		//比较	
		
		serverCurTime = new Date();
		var serverCurTime = ((serverCurTime.getYear() > 200) ? serverCurTime.getYear() : (1900 + serverCurTime.getYear())) + "-" + (serverCurTime.getMonth()+1);
		//下一个月
        obj1 = this.createnode('div');
        obj1.innerHTML = '<span><input type="image" src="/Templates/Site61/Dino/images/rd_jtr.gif" /></span>';
		if(curDateTime < serverCurTime)
        	obj1.className = 'Release_Date_jtr';
		else
			obj1.className = 'Release_Date_jtr';	
		obj1.style.textAlign = "left";
		if(curDateTime < serverCurTime)
		{
			obj1.onclick = function() {
				var curYear = date.getRealYear();
				var curMonth = date.getRealMonth();
				var curDay = date.getRealDay();
				curMonth++;
				var curDate = Date.NewDate(curYear,curMonth,curDay);
				//DTP.initmh1(curDate);
				//DTP.initmb(curDate);
				var DateString = curDate.getRealYear().toString()+formatMonthAndDay(curDate.getRealMonth()).toString()+nextdatetime.toString();
				window.location="http://www.dinodirect.com/shopways/New-Arrivals-"+params+"-"+DateString+"/"+curParams;
			};
		}
		obj2 = this.createnode('span');
		 obj2.innerHTML =date.getRealYear()+"&nbsp;&nbsp;";
		 obj2.className = 'Release_Date_jtrwz';
		 obj1.appendChild(obj2);
        obj.appendChild(obj1);

        obj1 = this.createnode('div');
        obj1.className = 'clf';
        obj.appendChild(obj1);
    },
//显示星期
	
    initmh2 : function() {
		ocj = document.getElementById("dtpWeekday");
	ocj = this.createnode('div');
	ocj.id = "dtpWeekday";
	ocj.className='Release_Date_da';
	this.container.appendChild(ocj);
		var obj = document.getElementById("dtpWeek");
		if (obj == null) {
			obj = this.createnode('div');
			obj.id = "dtpWeek";
			obj.className='Release_Date_da1';
        	this.container.appendChild(obj);
		}
		this.removeChild(obj);
		
        //var obj = this.createnode('div');

        for (var i = 0; i < 7; i++) {
            obj1 = this.createnode('span');
			var weekName = "";
			if(i == 0)
				weekName = "S";
			else if(i == 1)
				weekName = "M";
			else if(i == 2)
				weekName = "T";
			else if(i == 3)
				weekName = "W";
			else if(i == 4)
				weekName = "T";
			else if(i == 5)
				weekName = "F";
			else if(i == 6)
				weekName = "S";
            obj1.innerHTML = weekName;
            obj1.className = 'Release_Date_dawz';
            obj.appendChild(obj1);
        }

        obj1 = this.createnode('div');
        obj1.className = 'clf';
        obj.appendChild(obj1);
		ocj.appendChild(obj);
        //this.container.appendChild(obj);
    },
//显示日期
    initmb : function(date,params,typeParams,curParams) {
		var mydate = new Date();
		var lpdate = null;
		var cyear = this.config.date.getRealYear();
		var cmonth = this.config.date.getRealMonth();
		var cday = this.config.date.getRealDay();

		var tyear = date.getRealYear();
		var tmonth = date.getRealMonth();
		var tday = date.getRealDay();

		var tmwday = Date.NewDate(tyear, tmonth, 1).getDay(); //返回 Date 对象中表示的一周中的日期值。

		if (tmwday == 0) {
			lpdate = Date.NewDate(tyear, tmonth, 1);
			sumday = lpdate.getMonthDays();
		} else {
			tmonth -= 1;
			if (tmonth == 0) { // 如果为第一月
				tmonth = 12;
				tyear -= 1;
			}
			maxdays = Date.NewDate(tyear, tmonth, 1).getMonthDays(); //本月天数
			lpdate = Date.NewDate(tyear, tmonth, maxdays - tmwday + 1);//上个月的末尾几天
		}

		var obj = document.getElementById("dtpBody");
		if (obj == null) {
			obj = this.createnode('div');
			obj.id = "dtpBody";
			obj.className="Release_Date_dad";
			obj2 = this.createnode('ul');
        	this.container.appendChild(obj);
			this.container.appendChild(obj2);
		}
		this.removeChild(obj);
		this.removeChild(obj2);

		var ik = date.getMonthDays() + tmwday;
		ik = parseInt(ik / 7) + (ik % 7 == 0 ? 0 : 1);
		var ioffset = 0;

		while (ik > 0)
		{
			for (var i = 0; i < 7 ; i++) {
				obj1 = this.createnode('li');
				if ( Date.DiffMonth(date, lpdate) > 0 ) {
					obj1.innerHTML = "&nbsp;";
				} else if ( Date.DiffMonth(date, lpdate) == 0) {
						obj1.innerHTML = lpdate.getRealDay();
				} else {
					obj1.innerHTML = "&nbsp;";
				}

				if (lpdate.getRealYear() == cyear && lpdate.getRealMonth() == cmonth && lpdate.getRealDay() == cday) {
					obj1.className = '';
				} else {
					if ( Date.DiffMonth(date, lpdate) > 0 ) {
						obj1.className = '';
					} else if ( Date.DiffMonth(date, lpdate) == 0) {
						if(mydate.getDate() == lpdate.getRealDay()){
						obj1.className = '';
						}
					} else {
						obj1.className = '';
					}
				}
				obj1.setAttribute('year' , lpdate.getRealYear());
				obj1.setAttribute('month' , lpdate.getRealMonth());
				obj1.setAttribute('day' , lpdate.getRealDay());
				obj1.setAttribute('id' , lpdate.getRealYear()+"-"+formatMonthAndDay(lpdate.getRealMonth())+"-"+formatMonthAndDay(lpdate.getRealDay()));			

				obj1.onclick = function() {
					year = this.getAttribute('year');
					month = formatMonthAndDay(this.getAttribute('month'));
					day = formatMonthAndDay(this.getAttribute('day'));
					dayId = this.getAttribute('id');
					className = document.getElementById(dayId).className;
					
					if(month.toString() == formatMonthAndDay(cmonth) && className == "this_date2")
					{		
						window.location="http://www.dinodirect.com/shopways/New-Arrivals/"+typeParams+params+"-"+year.toString()+month.toString()+day.toString()+"/"+curParams;
					}
				};
				obj2.appendChild(obj1);
				obj.appendChild(obj2);
				ocj.appendChild(obj);
				ioffset++;
				lpdate.addOneDay();
			}
			obj1 = this.createnode('div');
			obj1.className = 'clf';

			
			
			ik--;
		}
    },
	
    createnode : function(tagname, tagtype) {
        var str = '<' + tagname;
        if (tagname == 'input') {
            str += ' type="' + tagtype + '">';
        }
        str += '">';
        return document.createElement(tagname);
    },

    removeChild: function(obj) {
		while ( obj.firstChild ) {
            this.removeChild( obj.firstChild );
			obj.removeChild( obj.firstChild );
        }
    }
};


function createNode(tagname, tagtype) {
    var str = '<' + tagname;
    if (tagname == 'input') {
        str += ' type="' + tagtype + '">';
    }
    str += '">';
    return document.createElement(tagname);
}
function formatMonthAndDay(obj){
	if(obj<=9 && obj >=0)
	{
		return "0"+obj.toString();	
	}
	else
	{
		return obj;
	}
}
