var ie;
if (document.all) ie=1;
else ie=0;

function openTi(){
	var openTiToday;
	if(!(openTiToday = GetCookie("openTiToday"))) 
		openTiToday="";
	alert(openTiToday);
	if(isnull(openTiToday)){
		window.open("http://www.laddercn.com");
		var expdate = new Date();
	  expdate.setTime(expdate.getTime() +  (12 * 60 * 60 * 1000 )); 
	  SetCookie("openTiToday", 'openTiToday', expdate, "/", null, false);
	}		 
}
function commonJump(){
	skipToPage(document.getElementById('page.currentPage').value);
}
function initMsgInput()
{
	var visits;
	if(!(visits = GetCookie("visitsUser"))) 
	   visits = "";
	document.form1.UserName.value=visits;
	if(!(visits = GetCookie("visitsEmail"))) 
	   visits = "@";
	document.form1.txtTitle.value=visits;
}

function CopyText(obj) {
	ie = (document.all)? true:false
	if (ie){
		var rng = document.body.createTextRange();
		rng.moveToElementText(obj);
		rng.scrollIntoView();
		rng.select();
		rng.execCommand("Copy");
		rng.collapse(false);
	}
}

function getInitSkin()
{
	var weidongSkin="0";
	if(!(weidongSkin = GetCookie("weidongSkin"))) 
   weidongSkin = "0";
	document.write('<link rel="stylesheet" href="skin/skin' + weidongSkin+ '/style.css" type="text/css" media="all"/>');
}


function isnull(str)
{if(str==null||str=="")return true;
 return false;
}


function killErrors() { 
return true; 
} 
window.onerror = killErrors; 
//日期-----------------------------------------------------


function incMonth(delta) 
{
	
	var displayMonth=document.getElementById("calendarInfo.month").value;
	displayMonth = parseInt(displayMonth + '') +delta;
	if (displayMonth > 12) 
	{
		displayMonth = 1;
		document.getElementById("calendarInfo.month").value=displayMonth;
		incYear(1);
	} 
	else if (displayMonth <= 0) 
	{
		displayMonth = 12;
		document.getElementById("calendarInfo.month").value=displayMonth;
		incYear(-1);
	} 
	
	document.getElementById("calendarInfo.month").value=displayMonth;	
	document.getElementById("calendarInfo.type").value=2;
	document.form1.action="blog.action";
	document.form1.submit();
	
}


function incYear(delta,eltName) 
{
	var displayYear=document.getElementById("calendarInfo.year").value;
	displayYear = parseInt(displayYear + '') + delta;
	document.getElementById("calendarInfo.year").value=displayYear;
	document.getElementById("calendarInfo.type").value=2;
	document.form1.action="blog.action";
	document.form1.submit();

}
function getBlog(sYear,sMonth,sDay) 
{
	document.getElementById("calendarInfo.type").value=1;
	document.getElementById("calendarInfo.year").value=sYear;
	document.getElementById("calendarInfo.month").value=sMonth;
	document.getElementById("calendarInfo.day").value=sDay;
	document.form1.action="blog.action";
	document.form1.submit();

}
//------------分类----------------------------------------------
function getType(sType,actionObj) 
{
	document.form1.typeId.value=sType;
	document.form1.action=actionObj;
	document.form1.submit();

}
function toType(id,type,target)
{
		document.form2.typeId.value=type;
		document.form2.action=id+".html";
		if(!isnull(target))
			document.form2.target=target;
		document.form2.submit();
}


function getLevel(sType) 
{
	document.form1.levelId.value=sType;
	document.form1.action="collect.action";
	document.form1.submit();

}
function getArchives(sYear,sMonth) 
{
	if(sYear=='')
		document.getElementById("calendarInfo.type").value=0;
	else{
	document.getElementById("calendarInfo.type").value=2;
	document.getElementById("calendarInfo.year").value=sYear;
	document.getElementById("calendarInfo.month").value=sMonth;
	}
	document.form1.action="blog.action";
	document.form1.submit();

}
function getOrderType(ordertype,actionObj) 
{
	document.form1.ordertype.value=ordertype;
	document.form1.orderFlag.value=1-document.form1.orderFlag.value;
	document.form1.action=actionObj;
	document.form1.submit();

}

//-----------------分页-----------------------------------------------

function skipToPage(page)
{
	document.getElementById('page.currentPage').value=page;
	document.form1.submit();
}

function skipToPage2(page)
{
	document.getElementById('page.currentPage').value=page-1;
	document.form1.submit();
}

function SetOrder(str)
{
	var orderFlag=0;
	document.getElementById('page.orderString').value=str;
	if(!isnull(document.getElementById('page.orderFlag').value)) 
		orderFlag=document.getElementById('page.orderFlag').value;
	document.getElementById('page.orderFlag').value=1 - orderFlag;
	document.form1.submit();
}
//----------------setWeidongSkin-----------------------------------------
function setWeidongSkin(weidongSkin)
{
	 var expdate = new Date();
  	 expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 
		 SetCookie("weidongSkin", weidongSkin, expdate, "/", null, false);
		 document.location="blog.action";
}
//----------------setBlogStyle-----------------------------------------
function setBlogStyle(weidongStyle)
{
	 var expdate = new Date();
  	 expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 
		 SetCookie("weidongStyle", weidongStyle, expdate, "/", null, false);
		 document.form1.action="blog.action";
		 document.form1.submit();
}
function setCollectStyle(weidongStyle)
{
	 var expdate = new Date();
  	 expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 
		 SetCookie("weidongStyle", weidongStyle, expdate, "/", null, false);
		 
		 document.form1.action="collect.action";
		 document.form1.submit();
}


function toBlogIndex(weidongStyle)
{
	 var expdate = new Date();
  	 expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 
	 SetCookie("weidongStyle", weidongStyle, expdate, "/", null, false);
	 document.form1.action="blog.action";
	 document.form1.submit();
}

function toTag(id,tag,target)
	{
		document.form2.tag.value=tag;
		if(id=='')
		document.form2.action="blog.action";
		else
		document.form2.action=id+".html";
		if(isnull(target)) target="_blank";
		document.form2.submit();
	}	
//------------------cookie----------------------------------

function getCookieVal (offset) 
   {
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1)
      endstr = document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
   }
function GetCookie (name) 
   {
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;
   while (i < clen) 
      {
      var j = i + alen;
      if (document.cookie.substring(i, j) == arg)
         return getCookieVal (j);
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0) 
         break; 
      }
   return null;
   }
function SetCookie (name, value) 
   {
   var argv = SetCookie.arguments;
   var argc = SetCookie.arguments.length;
   var expires = (2 < argc) ? argv[2] : null;
   var path = (3 < argc) ? argv[3] : null;
   var domain = (4 < argc) ? argv[4] : null;
   var secure = (5 < argc) ? argv[5] : false;
   document.cookie = name + "=" + escape (value) +
     ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
     ((path == null) ? "" : ("; path=" + path)) +
     ((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
   }

function ResetCounts(name) 
   {
   visits = 0;
   SetCookie("visits", visits, expdate , "/", null, false);
   location.reload();
   }
   

function SetTop(skin){
	
	FunSetTop(skin,"100%","");

}

function SetBottom(skin){

	FunSetBottom(skin,"100%","");
}


function FunSetTop(skin,iWidth,sPath){
	
	var sDisp="<table cellpadding=0 cellspacing=0 width="+iWidth+" align=center><tr><td><img src="+sPath+"skin/skin"+skin+"/pic/top_left.gif></td><td width=100% background="+sPath+"skin/skin"+skin+"/pic/top_bg.gif></td><td><img src="+sPath+"skin/skin"+skin+"/pic/top_right.gif></td></tr></table>";
	switch(skin)
	{
		case 4:
		 sDisp="<TABLE cellSpacing=0 cellPadding=0 width="+iWidth+" align=center background="+sPath+"skin/skin"+skin+"/pic/top_center.gif border=0><TR id=cat><td align=left width=28 height=28><IMG height=28 src="+sPath+"skin/skin"+skin+"/pic/top_left.gif width=28 border=0></TD><TD Align=center align=left width=595  background="+sPath+"skin/skin"+skin+"/pic/top_bg.gif height=28></TD><TD vAlign=center align=left width=19><IMG height=28 src="+sPath+"skin/skin"+skin+"/pic/top_end.gif width=19 border=0></TD><td align=right width=37>&nbsp;</TD><td align=right width=315 height=28><IMG height=28 src="+sPath+"skin/skin"+skin+"/pic/top_right.gif width=296 border=0></TD></TR></TABLE>"
		
			break;
	}
document.write(sDisp);


}

function FunSetBottom(skin,iWidth,sPath){
	
	var sDisp="<table cellpadding=0 cellspacing=0 width="+iWidth+" align=center><tr><td><img src="+sPath+"skin/skin"+skin+"/pic/bottom_left.gif></td><td width=100% background="+sPath+"skin/skin"+skin+"/pic/bottom_bg.gif></td><td><img src="+sPath+"skin/skin"+skin+"/pic/bottom_right.gif></td></tr></table>";
	
document.write(sDisp)
}
//----div size------------------------------------------------------
function getIEPosPara(elt,para) { return getIEPos(elt,para); }
	function getIEPos(elt,which) {
	 var  iPos = 0
//	 while (elt!=null) 
{
	  iPos += elt["offset" + which]
	 // elt = elt.offsetParent
	 }
	 return iPos
	}

 		
function DivResize()
{
		var iHeight1,iHeight2,iMaxHeight,i;
		iHeight1=0;
		if(ie)
		 {
		 	for(i=0;i<2;i++)
		 	{
		   sObj = 'menu';
		 	 iHeight1=getIEPosPara(document.all[sObj],"Height");
		 	
			 sObj = 'content';
			 iHeight2=getIEPosPara(document.all[sObj],"Height");
			 iMaxHeight=(iHeight1>iHeight2)?iHeight1:iHeight2;
			 iMaxHeight=iMaxHeight+"px";
			 document.all['menu'].style.height=iMaxHeight;
			 document.all['content'].style.height=iMaxHeight;
			 if(iHeight1>0) break;
			 
			}
		 }
		else
			{
		 	for(i=0;i<2;i++)
		 	{
		 	 iHeight1=document.getElementById("menu").offsetHeight;
		 	 iHeight2=document.getElementById("content").offsetHeight;
		 	 iMaxHeight=(iHeight1>iHeight2)?iHeight1:iHeight2;
			 iMaxHeight=iMaxHeight+"px";
			 document.getElementById("menu").style.height=iMaxHeight;
			 document.getElementById("content").style.height=iMaxHeight;
			 if(iHeight1>0) break;
			 
			}
		 }
			
	
		 
}		 	


function initOperid()
{
	var visits;
	if(!(visits = GetCookie("nihaoblogusercode"))) 
	   visits = "";
	document.form1.operId.value=visits;
	
}

function Quit()
{
		var expdate = new Date();
	  expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 
	  SetCookie("nihaoblogusercode", '', expdate, "/", null, false);
	  document.location="userlogin.jsp?id=0";
		
}
//---------------------------------------------------------------------------
function FunSelect() 
{ 
		var tmp=document.form1.oldtags.options[document.form1.oldtags.selectedIndex].value;
		FunAddTag(tmp);
	
}

function selectAll(from)
{
	if(document.getElementById(from).length<1) return false;
	for(var i=0;i<document.getElementById(from).length;i++)
		document.getElementById(from).options[i].selected=true;  
	
}
function inList(from,val)
{
	var i,tmp;
	if(document.getElementById(from).length<1) return false;
	for(i=0;i<document.getElementById(from).length;i++)
		if(val==document.getElementById(from).options[i].value) return true;
	return false;
}	    
function FunAddTag(tmp)
{
		var from="tags";
		
		var l = document.getElementById(from).length;
		
		if(l>=5) 
		{
			alert("一篇日志最多贴5个标签！");
			return;
		}
		
		if(isnull(tmp)) 
		{
			alert("请填写标签内容！");
			return;
		}
		if(inList('tags',tmp)) 
			{
				alert("该标签已经存在！");
				return;
			}
		
  	var oOption = document.createElement('OPTION');
  	oOption.text=tmp;
		oOption.value=tmp;
		document.getElementById(from).options[l] = oOption;

	//	document.form1.tags.add(oOption);
		
	}
function FunAdd()
{
		FunAddTag(document.form1.tmptag.value);
}
	
function FunDel()
{
  var from="tags";
  if(document.getElementById(from).length<1) return;
	for(var i=document.getElementById(from).length-1;i>=0;i--)
  {
		if(document.getElementById(from).options[i].selected==true)
			document.getElementById(from).remove(i);
  }	
}
function FunAddSelect() 
{ 	var i=document.getElementById('tags').selectedIndex;
		var s=document.getElementById('tags').options[i].value;
		document.form1.tmptag.value=s;
	
}

function getSelectIndex(selectObj,value)
{
			var len=document.getElementById(selectObj).length;
			if(len<1) return;
			for(i=0;i<len;i++)
			{
					if(document.getElementById(selectObj).options[i].value==value)
						{
							document.getElementById(selectObj).selectedIndex=i;
							break;
						}
			}
	
}

function checkdata()
{
    if(isnull(document.getElementById("blogUser.operId").value)||isnull(document.getElementById("blogUser.password").value))
       {alert("字段不能为空");
       return false;
       }
    return true;
}
function login()
{		
     if(!checkdata()) return false;
     return true;
}
function getListID(ObjName,val)
{
	if(val=='') return 0;
	var i,tmp;
	if(document.getElementById(ObjName).length<1) return false;
	for(i=0;i<document.getElementById(ObjName).length;i++)
		if(val==document.getElementById(ObjName).options[i].text) return i;
	
	return 0;
}	
function queryPoem(keyword,queryType,dynasty,rhyme,target){
	document.form1.keyword.value=keyword;
	document.form1.queryType.value=queryType;
	document.form1.dynasty.selectedIndex=getListID('dynasty',dynasty);
	document.form1.rhyme.selectedIndex=getListID('rhyme',rhyme);
	if(!isnull(target))
			document.form1.target=target;
	document.form1.submit();
	
}
