//====================================
// error treatment
//====================================
function zerror(inn,text)
{
	alert("error happend in "+inn+"() !!!\n\n"+text);
}

function zerror_clientw(msg)
{
	// get errorbox handle
	var theBox = idd_errorbox;
	if (!theBox)
	{
		zerror("zerror_clientw","errorbox hanle can not be finded");
	}
	if("none"==theBox.currentStyle.display)
	{
		theBox.style.display="block";
	}
	var oldContent = theBox.innerHTML;
	var newContent;
	newContent = "<div>"+msg+"</div>";
	// refrash content
	theBox.innerHTML = oldContent + newContent;
}
//====================================
// open window
//====================================
//
// open a Fixed Window
// param:
//    [inn]required		new window URL
var	Z_OPENWIN_S1=1;
var	Z_OPENWIN_S2=2;
var	Z_OPENWIN_S3=3;
var	Z_OPENWIN_S4=4;
function zopenWinFix(iurl,istyle)
{
	if(!iurl)
		zerror("zopenWinFix","required a URL as the first param;")
	// calculate the style	
	var theStyle;
	if(istyle)
		theStyle = istyle;
	else
		theStyle = Z_OPENWIN_S1;
	// open window by style
	switch (theStyle)
	{
	case Z_OPENWIN_S1:
		window.open(iurl,"_blank","width=500,height=400,toobar=no,menubar=no,scrollbars=yes");		
		break;
	case Z_OPENWIN_S2:
		window.open(iurl,"_blank","width=600,height=500,toobar=no,menubar=no,scrollbars=yes");		
		break;
	case Z_OPENWIN_S3:
		window.open(iurl,"_blank","width=640,height=480,toobar=no,menubar=no,scrollbars=yes");		
		break;
	case Z_OPENWIN_S4:
		window.open(iurl,"_blank","width=400,height=320,toobar=no,menubar=no,scrollbars=no");		
		break;
	default:
		zerror("zopenWinFix","bad window style!!!!")
	}

	return false;
}
//-------------------------------------------------------------------
function showImage(isrc)
{
	if(!isrc) return;
	window.open("/pics/pop.asp?src="+isrc,"_blank","width=800,height=600,top=10,left=10,toobar=no,menubar=no,scrollbars=yes,resizable=yes");
}
//-------------------------------------------------------------------
function openMrWindow(mrid)
{
	if(!mrid) return;
	window.open("/pics/pop_showmr.asp?mrid="+mrid,"_blank","width=760,height=560,top=10,left=10,toobar=no,menubar=no,scrollbars=yes,resizable=no,status=no");
}
//-------------------------------------------------------------------
function updateNicety(inum,tid,itype)
{
	//alert("updateNicety("+inum+")")
	window.open("/travel/setrate.asp?nc="+inum+"&tid="+tid+"&itype="+itype,"_blank","width=400,height=500,toobar=no,menubar=no,scrollbars=yes,resizable=no");
}
//-------------------------------------------------------------------
function updateUseful(inum,tid,itype)
{
	//alert("updateUserful("+inum+")")
	window.open("/travel/setrate.asp?uf="+inum+"&tid="+tid+"&itype="+itype,"_blank","width=400,height=500,toobar=no,menubar=no,scrollbars=yes,resizable=no");
}
//-------------------------------------------------------------------
function deleteUseful(tid,itype)
{
	//alert("updateUserful("+inum+")")
	window.open("/travel/setrate.asp?uf=NULL&tid="+tid+"&itype="+itype,"_blank","width=400,height=500,toobar=no,menubar=no,scrollbars=yes,resizable=no");
}
//-------------------------------------------------------------------
function deleteNicety(tid,itype)
{
	//alert("updateUserful("+inum+")")
	window.open("/travel/setrate.asp?nc=NULL&tid="+tid+"&itype="+itype,"_blank","width=400,height=500,toobar=no,menubar=no,scrollbars=yes,resizable=no");
}
//-------------------------------------------------------------------
function openwindow(iurl,iw,ih)
{
	var w = (iw?iw:400);
	var h = (ih?ih:400);
	window.open(iurl,"_blank","width="+w+",height="+h+",top=10,left=10,toobar=no,menubar=no,scrollbars=yes,resizable=yes");
	return false;
}

//====================================
// About Date
//====================================
//
// creat a chinese traditional DATE format
// param:
//		[idate]implied	if without the param, current local time will be used
//
function zformatDate(idate)
{
	var theDate;
	var res;
	if(idate)
		theDate = idate;
	else
		theDate = new Date();
	
	//res =theDate.getYear()+"年"+(theDate.getMonth()+1)+"月"+theDate.getDate()+"日";
	res =theDate.getYear()+"/"+(theDate.getMonth()+1)+"/"+theDate.getDate();
	res += " , " + zfmtNumToStrWeek(theDate.getDay());

	return res;
}

function zformatDateX(iyear,imonth,iday)
{
	var re;
	re = iyear + "-" + imonth + "-" + iday;
	return re;
}

function zdate_day(idate)
{
	var ps;
	ps = idate.indexOf("-")+1;
	idate = idate.substr(ps,idate.length-ps);
	ps = idate.indexOf("-")+1;
	idate = idate.substr(ps,idate.length-ps);
	return idate;
}

function zdate_month(idate)
{
	var ps;
	ps = idate.indexOf("-")+1;
	idate = idate.substr(ps,idate.length-ps);
	ps = idate.indexOf("-");
	idate = idate.substr(0,ps);
	return idate;
}

function zdate_year(idate)
{
	var ps;
	ps = idate.indexOf("-");
	idate = idate.substr(0,ps);
	return idate;
}
//-------------------------------------------------------------------
// format a Number(1~7) to string
// param:
//		[dayNum]required	day number 
//		[type]implied	its must be FNTSW_TYPE	<- without implement
// note:
//		if dayNum out of its scope, function will return nothing
// var FNTSW_TYPE = new Enumerator(estr,estrs,cstr)
function zfmtNumToStrWeek(dayNum)
{
	if(!dayNum && dayNum!=0)
		zerror("fmtNumToStrWeek");
	var res = "";
	switch (dayNum)
	{
	case 1:
		res = "星期一";
		break;
	case 2:
		res = "星期二";
		break;
	case 3:
		res = "星期三";
		break;
	case 4:
		res = "星期四";
		break;
	case 5:
		res = "星期五";
		break;
	case 6:
		res = "星期六";
		break;
	case 0:
		res = "星期日";
		break;
	}
	return res;
}

//-------------------------------------------------------------------
// init vars
//
var theShirt =0;
var theDoc =0;
var theFrmObj=0;
function init()
{
//alert("Initial finished	")
}

//-------------------------------------------------------------------
// show list
//
function showList()
{
// if current list still visiable, hidden it.
if(theShirt!=0)hiddenCurrentList();

var i;
var tempobj;

//checking
var fobj = event.srcElement;
var fbox = fobj.parentNode.parentNode;
if(fobj.tagName!="IMG"){zerror("showlist()","not valid fire element, it should be img!");return;}
if(!fobj.mark){zerror("showlist()","without @mark !");return;}
if(fobj.mark!=1*fobj.mark){zerror("showlist()","@mark must be a number!!!");return;}
i = 1*fobj.mark;

// get objects
theShirt= idd_listshirt.all.tags("DIV").item(i);
theDoc	= document.frames(i).document;
if(!theDoc) return;
theFrmObj= theShirt.childNodes.item(0);

// get the list document table real size
var realw, realh;
if(!theDoc.body) return;
tempobj = theDoc.body.getElementsByTagName("table").item(0);
if (tempobj)
{
	realw = tempobj.offsetWidth;
	realh = tempobj.offsetHeight;
}else{
	realw = 1;
	realh = 1;
}

// get the list document table real postion
var reall = fbox.getBoundingClientRect().left + document.body.scrollLeft;
var realt = fbox.getBoundingClientRect().bottom + document.body.scrollTop;

// set the size and position to shirt
theFrmObj.width=realw;
theFrmObj.height=realh;

theShirt.style.top = realt-3;
theShirt.style.left = reall-3;

// display
theShirt.style.visibility="visible";
}

//-------------------------------------------------------------------
// two function to set flag
function markMouseOverList()
{
	ismouserOverList = 1;
}
function markMouserOutList()
{
	ismouserOverList = 0;
}

//-------------------------------------------------------------------
// hidden current list
//
var isMouserOverList = 0;
function hiddenCurrentList()
{
	//alert("hidden command from: "+event.srcElement.tagName)
	if(1==isMouserOverList) return;
	if(theShirt==0) return;
	// hidden it.
	theShirt.style.visibility="hidden";
	
	theShirt =0;
	theDoc =0;
	theFrmObj=0;
}
//-------------------------------------------------------------------
// set checkbox named "iname" , if name is ivalue, then set
// it checked.
function set_checkbox(iname,ivalue)
{
	var boxs = document.getElementsByName(iname);
	var i;
	for(i=0;i<boxs.length;i++)
	{
		if(ivalue.indexOf(boxs.item(i).value)>=0)
		{
			boxs.item(i).checked =true;
		}
	}
}
//-------------------------------------------------------------------
// set radiobox named "iname" , if name is ivalue, then set
// it checked.
function set_radio(iname,ivalue)
{
	var boxs = document.getElementsByName(iname);
	//alert("iname="+iname+"\nivalue="+ivalue+"\nhow many:"+boxs.length)
	var i;
	ivalue=ivalue+"";
	for(i=0;i<boxs.length;i++)
	{
		//alert("check the "+i+"obj\n\nboxs item value is:["+boxs.item(i).value+"]\ncheck value:["+ivalue+"]")
		if(boxs.item(i).value==ivalue)
		{
			//alert("ok, matched!!!")
			boxs.item(i).checked =true;
			return;
		}
	}
}
//-------------------------------------------------------------------
// set select, make its child option selected by its attribute @ivalue
// only for single select element
function set_select(ise,ivalue)
{
	var v;
	if(ivalue)
		v = ivalue;
	else
		v = (ise.ivalue?ise.ivalue:"");
	if (v.length>0)
	{
		for(var i=0;i<ise.options.length;i++)
		{
			if (ise.options.item(i).value==v)
			{
				ise.options.item(i).selected = true;
				return;
			}
		}
	}
}
//-------------------------------------------------------------------
// set bstr object
function set_bstr(iname,ivalue)
{
	var bc,objs,i;
	objs = document.getElementsByName(iname);
	if(objs.length==ivalue.length)
	{
		for (i=0;i<ivalue.length;i++)
		{
			bc = parseInt(ivalue.substr(i,1));
			//alert("loop:"+i+"\nget bc:"+bc)
			//alert(objs.item(i).outerHTML)
			objs.item(i).checked = (bc==0?false:true);
			//alert(objs.item(i).outerHTML)
		}
	}
	else
	{
		zerror("set_bstr","length can not match!!!\n"
				+"objs.length:"+objs.length+"\nivalue.length:"+ivalue.length
				+"\niname:"+iname
				+"\nivalue:"+ivalue);
	}
}
//---------------------------------------------------------
// form(DA) {photo information}
//
function subform_photo()
{
	// get obj form
	var theForm;
	theForm = document.DAimg;
	if (theForm.file1.value.length>0)
	{
		// submit current form
		theForm.submit();
	}
	else
	{
		alert("请从您的机器上选择一个照片")
	}
}
//---------------------------------------------------------
// Change URL
function goToTravel()
{
	window.location="hp_travel.asp";
}
//---------------------------------------------------------
function showIconIntro(url)
{
	window.open(url,"_blank","width=260px,height=240px;");
	return false;
}
//-------------------------------------------------------------
function gotoPage(iobj)
{
	if(!iobj) return;
	var theForm = document.DA;
	theForm.pn.value = iobj.pn;
	theForm.submit();
}
//-------------------------------------------------------------
function shobj(iobj)
{
	if(!iobj)return;
	if(iobj.style.display="none")
		iobj.style.display="block";
	else 
		iobj.style.display="none";
}
//-------------------------------------------------------------
function showmenu(iobj)
{
	var suit = iobj.all.tags("DIV")[0];
	suit.style.display = "inline";
}
//-------------------------------------------------------------
function hidemenu(iobj)
{
	var suit = iobj.all.tags("DIV")[0];
	suit.style.display = "none";
}
//-------------------------------------------------------------
function setCate(max)
{
	var theMax = (max?max:3);
	if(!document.DA.cate)
	{
		alert("Lack @cate in DA!!!");
		return;
	}
	var boxes = picker.all.tags("INPUT")
	var ct = document.DA.cate;
	ct.value = "";
	var count = 0;
	for(var i=0;i<boxes.length;i++)
	{
		if(boxes[i].checked)
		{
			ct.value += ","+boxes[i].value;
			count++;
		}
	}
	if(count>theMax)
	{
		alert("你最多只能选择"+theMax+"个分类");
		ct.value="";
		return;
	}
	if(ct.value.length>0)
		ct.value = ct.value.substring(1,ct.value.length);
	form_submit();
}
//-------------------------------------------------------------
function form_submit()
{
	document.DA.submit();
}
//-------------------------------------------------------------
function deleteSubChap(ibtn)
{
	if (confirm("你确定要删除这个段落吗？"))
	{
		var theurl;
		theurl = "/bin/pro_delchap.asp?chapid="+ibtn.chapid;
		theurl = theurl+ "&itype=" + ibtn.itype;
		theurl = theurl+ "&tid=" + ibtn.tid;
		theurl = theurl+ "&surl=" + ibtn.surl;
		theurl = theurl+ "&furl=" + ibtn.furl;
		theurl = theurl+ "&isan=" + ibtn.isan;
		theurl = theurl+ "&isFirst=" + ibtn.isFirst;
		if(ibtn.adrID) theurl = theurl+"&adrID="+ibtn.adrID;
		//alert(theurl)
		document.location = theurl;
	}
}
//---------------------------------------------------------
function showProtocol(iHref)
{
	var theHref = (iHref?iHref:"/main/protocol.asp");
	window.open(theHref,"_blank","width=600,height="+(screen.height-140)+",scrollbars=yes,resizable=yes,status=yes,menubar=yes");
}
//---------------------------------------------------------
function showNavTitle(iObj)
{
	if(iObj)
	{
		hideNavTitle();
		aTitle = iObj.id;
		var objIcon = iObj.all.tags("IMG")[0];
		var objSuit = iObj.nextSibling;
		objIcon.src = "/style/images/icon/16_07_show.gif";
		objSuit.style.display = "block";
		navStateRecorder.document.location.href="/main/record_state.asp?navActivedTitle="+iObj.title;
	}
}
function hideNavTitle()
{
	if(aTitle && aTitle.length>0)
	{
		var objTitle = getElementById(aTitle);
	}
	if(objTitle)
	{
		var objIcon = objTitle.all.tags("IMG")[0];
		var objSuit = objTitle.nextSibling;
		objIcon.src = "/style/images/icon/16_07_hide.gif";
		objSuit.style.display = "none";
	}
	aTitle = "";
}