var today = new Date();
function PadLeft(value){
	if(value.toString().length < 2){
		return "0" + value;
	}
	return value.toString();
}

function CInt(value){
	if(value.toString().substring(0,1) == "0"){
		return parseInt(value.toString().substring(1));
	}else{
		return parseInt(value)
	}
}

function getMonthDays(y,m) {
   y = CInt(y);
   m = CInt(m) - 1;
   var monthDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
   if(m==1)
	  return(((y%4 == 0) && (y%100 != 0) || (y%400 == 0))? 29: 28);
	 else
	  return(monthDays[m]);
}


function GetBirthDayLength(){
	var birthyear = document.getElementById("BirthYear");
	var birthmonth = document.getElementById("BirthMonth");
	if(birthyear == null)birthyear = document.getElementById("lunaryear");
	if(birthmonth == null)birthmonth = document.getElementById("lunarmonth");
	return getMonthDays(birthyear.value,birthmonth.value);
}

function GetBirthDay(){
	var max = GetBirthDayLength();
	var birthday = document.getElementById("BirthDay");
	if(birthday == null)birthday = document.getElementById("lunarday");
	for(var i=birthday.options.length - 1; i >=0; i--){
		birthday.options.remove(i);
	}
	for(var i=1; i<= max; i++){
		var o = document.createElement("OPTION");
		o.text = PadLeft(i);
		o.value = i;
		birthday.options.add(o);
	}
}

function ShowDropDownList(name,istart,iend,ivalue,onchange){
	document.write('<select name="' + name + '" id="' + name + '"');
	if(onchange != undefined && onchange.length > 0){
		document.write(' onchange="' + onchange + '">');
	}else{
		document.write('>');
	}
	for(var i=istart; i <= iend; i ++){
		if(i == ivalue){
			document.write('<option value="' + i + '" selected>' + PadLeft(i) + '</option>');
		}else{
			document.write('<option value="' + i + '">' + PadLeft(i) + '</option>');
		}
	}
	document.write('</select>');
}

function CopyUrl(type){
	//document.getElementById("tbCommendUrl").createTextRange().execCommand("Copy");
	var url = document.getElementById("tbCommendUrl").value;
	var title = document.title;
	var text = "";
	switch(type){
		case 1: //QQ或MSN
			text = "喂,【" + title + "】这个东西好好玩哦.测算地址是:" + url;
			break;
		case 2: //HTML
			text = "<a href=\"" + url + "\" target=\"_blank\">【" + title + "】</a>这个东西好好玩哦.点击以下地址即可测算:<a href=\"" + url + "\" target=\"_blank\">" + url + "</a>";
			break;
		default: //UBB
			text = "[url=" + url + "]【" + title + "】[/url]这个东西好好玩哦.点击以下地址即可测算:[url=" + url + "]" + url + "[/url]";
			break;
	}
	clipboardData.setData('Text',text);
	alert("本页地址已复制，你可以直接粘贴发送了^_^");
}
