//Constructor
var old_bg="";
function inStyle(obj){   
	old_bg=obj.style.background;	
	obj.style.background="#FFFF99";
}
function outStyle(obj){  obj.style.background=old_bg;}
function selectAll(form,obj){
	for(i=0;i<form.length;i++){
		if(form[i].name.indexOf("DomainList[]")!=-1){
			if(obj.checked) form[i].checked=true;
			else form[i].checked=false;
		} 
	}
}
function formSubmit(obj){
	for (var i=0;i<obj.elements.length;i++)
    {
    	var e = obj.elements[i];		
    	if (e.name == "DomainList[]" && e.checked==true){
			obj.action="register.php";
			obj.submit();
			return true;
		}
    }
	alert('请选择要预定的域名.');
	return false;	
}
function checkForm(Obj){
	if(Obj.chrDomain.value.trim()==""){
		alert("请输入搜索字符.");return false;
	}
	
}
String.prototype.trim  =  function(){  
	return  this.replace(/(^\s*)|(\s*$)/g,"");  
}  

function calendar(id,d){
	this.id = id;
	this.dateObject = d;
	this.write = writeCalendar;
	this.length = getLength;
	this.month = d.getMonth();
	this.date = d.getDate();
	this.day = d.getDay();
	this.year = d.getFullYear();
	this.getFormattedDate = getFormattedDate;
	//get the first day of the month's day
	d.setDate(1);
	this.firstDay = d.getDay();
	//then reset the date object to the correct date
	d.setDate(this.date);
}

var days = new Array('日','一','二','三','四','五','六');
var months = new Array('一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月');

function getFormattedDate(){
	TmpMonth = (this.month + 1)<10?"0"+(this.month + 1):(this.month + 1);
	TmpDay =  (this.date<10)?"0"+this.date:this.date;
	return this.year + '-' + (TmpMonth) + '-' + TmpDay;
	//return this.month + '/' + this.date + '/' + this.year;
}

function writeCalendar(){
	var calString = '<div id="calContainer">';
	//write month and year at top of table
	calString += '<table id="cal' + this.id + '" cellspacing="0" width="95%" height="170" style="border:1px #1a76b7 solid; padding-left: 5px;">';
	//write the image ?comment out to hide images
	//calString += '<tr><th colspan="7"><img src="' + this.pix[this.month].src + '"/></th></tr>';
	//write the month
	calString += '<tr style="background:#1a76b7;"><th colspan="7" style="color:#ffffff;">' + this.year + '&nbsp;' + '&nbsp;' + months[this.month] + '</th></tr>';
	//write a row containing days of the week
	calString += '<tr>';
	
	for(i=0;i<days.length;i++){
		calString += '<th align="left" style="padding:5px 0 0 8px;">' + days[i].substring(0,3) + '</th>';
	}
	calString += '</tr>'
	//write the body of the calendar
	calString += '<tr>';
	//create 6 rows so that the calendar doesn't resize
	for(j=0;j<42;j++){
		var displayNum = (j-this.firstDay+1);
		if(j<this.firstDay){
			//write the leading empty cells
			calString += '<td height=1px align="center"><table border=0px><tr><td height="1px"></td></tr></table></td>';
		}else if(displayNum==this.date){
			calString += '<td id="' + this.id +'selected" align="center" style="cursor: pointer" onmouseover="this.bgColor=\'#fccbcb\';" onmouseout="this.bgColor=\'#eeeeee\';" bgcolor="#eeeeee" onClick="javascript:changeDate(this,\'' + this.id + '\')">' + displayNum + '</td>';
		}else if(displayNum > this.length()){
			//Empty cells at bottom of calendar
			calString += '<td height=1px align="center"><table border=0px><tr><td height="1px"></td></tr></table></td>';
		}else{
			//the rest of the numbered cells
			calString += '<td id="" align="center" onmouseover="this.bgColor=\'#fccbcb\';" onmouseout="this.bgColor=\'#eeeeee\';" bgcolor="#eeeeee"     style="cursor: pointer" onClick="javascript:changeDate(this,\'' + this.id + '\')">' + displayNum + '</td>';
		}
		if(j%7==6){
			calString += '</tr><tr>';
		}
	}
	//close the last number row
	calString += '</tr>';
	//write the nav row
	calString += '<tr>';
	if (dtNowDate.getYear() == this.year)
	{
		if (dtNowDate.getMonth() < this.month)
		{
			calString += '<td align="left" class="nav" colspan="2" onClick="changeMonth(-1,\'' + this.id + '\')" style="cursor: pointer">&nbsp;&nbsp;向上</td>';
		}
		else
		{
			calString += '<td align="left" class="navdisabled" colspan="2"></td>';
		}
	}
	else if (dtNowDate.getYear() < this.year)
	{
		calString += '<td align="left" colspan="2" onClick="changeMonth(-1,\'' + this.id + '\')" style="cursor: pointer">&nbsp;&nbsp;向上</td>';
	}
	
	calString += '<td align="center" colspan="3"><font style="color: #de0c10; text-decoration: underline;cursor: hand; cursor: pointer;" title="Click here to clear the closing date" onclick="javascript:document.getElementById(\'fClosingDate\').innerHTML=\'\';document.getElementById(\'dtClosingDate\').value=\'\';">清除日期</font></td>';
	calString += '<td align="right" colspan="2" onClick="changeMonth(1,\'' + this.id + '\')" style="cursor: pointer">向下&nbsp;&nbsp;</td>';
	calString += '</tr>';
	
	calString += '</table>';
	calString += '</div>';
	return calString;
}

function getLength(){
	switch(this.month){
		case 1:
			if((this.dateObject.getFullYear()%4==0&&this.dateObject.getFullYear()%100!=0)||this.dateObject.getFullYear()%400==0)
				return 29; //leap year
			else
				return 28;
		case 3:
			return 30;
		case 5:
			return 30;
		case 8:
			return 30;
		case 10:
			return 30
		default:
			return 31;
	}
}
function changeDate(td,cal){
	//set the text box to the clicked date
	cal = eval(cal);
	document.getElementById(cal.id + "selected").className = "days";
	document.getElementById(cal.id + "selected").id = "";
	td.className = "date";
	td.id = cal.id + "selected";
	cal.dateObject.setDate(td.firstChild.nodeValue);
	cal = new calendar(cal.id,cal.dateObject);
	//if (dtNowDate > cal.dateObject) alert('请选择当前日期之后的日期.');
	document.getElementById('fClosingDate').innerHTML = cal.getFormattedDate();
	document.getElementById('dtClosingDate').value = cal.getFormattedDate();
}

function changeMonth(mo,cal){
	
	
	cal = eval(cal);
	//The Date object is smart enough to know that it should roll over in December
	//when going forward and in January when going back
	cal.dateObject.setMonth(cal.dateObject.getMonth() + mo);
	cal = new calendar(cal.id,cal.dateObject);
	cal.formattedDate = cal.getFormattedDate();
	document.getElementById('calContainer').innerHTML = cal.write();
	
}



