﻿/**
 * 启动日期选择框
 */
function fPopUpCalendarDlg() {
	if( arguments.length == 0 ){
		return;
	}

	var ctl = arguments[0];
	var ext = null;
	if (arguments.length>1){
		ext = arguments[1];
	}
    showx = event.screenX - event.offsetX - 4 ;// + deltaX;
    showy = event.screenY - event.offsetY + 18;// + deltaY;

	var qry = "";
	if(arguments.length>1){
		qry += arguments[1];
	}
	var fileName = "/js/calendardlg.html";
	var wHeight = "210px";
	if (ext!=null){
    	fileName = "/js/calendarprodlg.html";
    	wHeight = "255px";
	}
	retval = window.showModalDialog(fileName, "", "dialogWidth:210px; dialogHeight:"+wHeight+"; dialogLeft:"+showx+"px; dialogTop:"+showy+"px; status:no; directories:yes; help:no;"  );
    if( retval != null ){
        ctl.value = retval;
    }else{
    }
}





/**
 * 改变板块大小
 * 控制按键
 * a缩小宽度 A加速缩小宽度 d增大宽度 D加速增大宽度
 * w缩小高度 W加速缩小高度 s增大高度 S加速增大高度
 * 板块内存储变量
 * modulewidth 板块宽增量
 * moduleheight 板块高增量
 * @param tag 指定板块
 */
function changeTagAreaSize(tagOrId,changeTagId){

	var tag = getNodeByObject(tagOrId);
	if (tag==null){
		return tag;
	}
	var changeSizeTag;
	if (changeTagId==null){
		changeSizeTag = tag;
	}else{
		changeSizeTag = getNodeElementById(tag,changeTagId);
		if (changeSizeTag==null){
			changeSizeTag = tag;
		}
	}
	var widthTag = getNodeElementById(tag,"modulewidth");
	var heightTag = getNodeElementById(tag,"moduleheight");
	if (widthTag.value==""){
		widthTag.value = "0";
	}
	
	var addNum;
	if (event.keyCode==100){
		//d
		addNum = (new Number(widthTag.value))+1;
		if (doChangeTagAreaSize(changeSizeTag,1,0)){
			widthTag.value = addNum;
		}
	}else if (event.keyCode==68){
		//D
		addNum = (new Number(widthTag.value))+10;
		if (doChangeTagAreaSize(changeSizeTag,10,0)){
			widthTag.value = addNum;
		}
	}else if (event.keyCode==97){
		//a
		addNum = (new Number(widthTag.value))-1;
		if (doChangeTagAreaSize(changeSizeTag,-1,0)){
			widthTag.value = addNum;
		}
	}else if (event.keyCode==65){
		//A
		addNum = (new Number(widthTag.value))-10;
		if (doChangeTagAreaSize(changeSizeTag,-10,0)){
			widthTag.value = addNum;
		}
	}else if (event.keyCode==119){
		//w
		addNum = (new Number(heightTag.value))-1;
		if (doChangeTagAreaSize(changeSizeTag,0,-1)){
			heightTag.value = addNum;
		}
	}else if (event.keyCode==87){
		//W
		addNum = (new Number(heightTag.value))-10;
		if (doChangeTagAreaSize(changeSizeTag,0,-10)){
			heightTag.value = addNum;
		}
	}else if (event.keyCode==115){
		//s
		addNum = (new Number(heightTag.value))+1;
		if (doChangeTagAreaSize(changeSizeTag,0,1)){
			heightTag.value = addNum;
		}
	}else if (event.keyCode==83){
		//S
		addNum = (new Number(heightTag.value))+10;
		if (doChangeTagAreaSize(changeSizeTag,0,10)){
			heightTag.value = addNum;
		}
	}
}

/**
 * 修改板块中所有带尺寸的元素大小
 * @param tag 指定板块
 * @param width 宽增量
 * @param height 高增量
 * @return true修改成功
 */
function doChangeTagAreaSize(tag,width,height){
	
	if (tag==null){
		return;
	}
	var addNum; //累加后的果
	var reDoOk = true; //是否执行成功
	if (tag.style!=null){
		if (width!=0){
			if (tag.style.width!=""){
				addNum = (new Number(tag.style.width.substring(0,tag.style.width.length-2)))+width;
				if (addNum>0){
					tag.style.width = addNum;
				}else{
					reDoOk = false;
				}
			}
		}
		if (height!=0){
			if (tag.style.height!=""){
				addNum = (new Number(tag.style.height.substring(0,tag.style.height.length-2)))+height;
				if (addNum>0){
					tag.style.height = addNum;
				}else{
					reDoOk = false;
				}
			}
		}
	}
	if (tag.width!=null && tag.width!="" && width!=0){
		addNum = (new Number(tag.width))+width;
		if (addNum>0){
			tag.width = addNum;
		}else{
			reDoOk = false;
		}
	}
	if (tag.height!=null && tag.height!="" && height!=0){
		addNum = (new Number(tag.height))+height;
		if (addNum>0){
			tag.height = addNum;
		}else{
			reDoOk = false;
		}
	}
	if (tag.canHaveChildren){
		//获取当前节点下的所有子节点
		var childNodes = tag.children;
		var nodeCount = childNodes.length;
		var i=0;
		while(i<nodeCount){
			if (reDoOk){
				reDoOk = doChangeTagAreaSize(childNodes[i],width,height);
			}
			i++;
		}
	}
	return reDoOk;
}


/**
 * 修改板块样式
 * 板块内变量 modulestyle 0正常下排 1左排 2右排
 * @param tag 指定板块
 * @param isFloat 是否为浮动模式 true是 false清除模式
 */
function changeTagAreaStyle(tag,isFloat){
	//样式标识
	var styleStatus = getNodeElementById(tag,"modulestyle");
	if (styleStatus==null){
		return false;
	}
	if (styleStatus.value=="00"){                //00
		if (isFloat){
			tag.style.styleFloat = "left";
			styleStatus.value = "10";
		}else{
			tag.style.clear = "left";
			styleStatus.value = "01";
		}
	}else if (styleStatus.value=="10"){          //10
		if (isFloat){
			tag.style.styleFloat = "right";
			styleStatus.value = "20";
		}else{
			tag.style.clear = "left";
			styleStatus.value = "11";
		}
	}else if (styleStatus.value=="20"){          //20
		if (isFloat){
			tag.style.styleFloat = "none";
			styleStatus.value = "00";
		}else{
			tag.style.clear = "left";
			styleStatus.value = "21";
		}
	}else if (styleStatus.value=="01"){          //01
		if (isFloat){
			tag.style.styleFloat = "left";
			styleStatus.value = "11";
		}else{
			tag.style.clear = "right";
			styleStatus.value = "12";
		}
	}else if (styleStatus.value=="11"){          //11
		if (isFloat){
			tag.style.styleFloat = "right";
			styleStatus.value = "21";
		}else{
			tag.style.clear = "right";
			styleStatus.value = "12";
		}
	}else if (styleStatus.value=="21"){          //21
		if (isFloat){
			tag.style.styleFloat = "none";
			styleStatus.value = "01";
		}else{
			tag.style.clear = "right";
			styleStatus.value = "22";
		}
	}else if (styleStatus.value=="02"){          //02
		if (isFloat){
			tag.style.styleFloat = "left";
			styleStatus.value = "12";
		}else{
			tag.style.clear = "both";
			styleStatus.value = "03";
		}
	}else if (styleStatus.value=="12"){          //12
		if (isFloat){
			tag.style.styleFloat = "right";
			styleStatus.value = "22";
		}else{
			tag.style.clear = "both";
			styleStatus.value = "13";
		}
	}else if (styleStatus.value=="22"){          //22
		if (isFloat){
			tag.style.styleFloat = "none";
			styleStatus.value = "02";
		}else{
			tag.style.clear = "both";
			styleStatus.value = "23";
		}
	}else if (styleStatus.value=="03"){          //03
		if (isFloat){
			tag.style.styleFloat = "left";
			styleStatus.value = "13";
		}else{
			tag.style.clear = "none";
			styleStatus.value = "00";
		}
	}else if (styleStatus.value=="13"){          //13
		if (isFloat){
			tag.style.styleFloat = "right";
			styleStatus.value = "23";
		}else{
			tag.style.clear = "none";
			styleStatus.value = "10";
		}
	}else if (styleStatus.value=="23"){          //23
		if (isFloat){
			tag.style.styleFloat = "none";
			styleStatus.value = "03";
		}else{
			tag.style.clear = "none";
			styleStatus.value = "20";
		}
	}
	return false;
}

/**
*  提示窗口样式
*  参数 str 
*  窗口显示内容 str
**/

function sAlert(content){
	var msgw,msgh,bordercolor;
	msgw=400;//提示窗口的宽度
	msgh=100;//提示窗口的高度
	bordercolor="#336699";//提示窗口的边框颜色
	titlecolor="#99CCFF";//提示窗口的标题颜色
	
	var sWidth,sHeight;
	sWidth=document.body.offsetWidth;
	sHeight=document.body.offsetHeight;
	
	var bgObj=document.createElement("div");
	bgObj.setAttribute('id','bgDiv');
	bgObj.style.position="absolute";
	bgObj.style.top="0";
	bgObj.style.background="";
	bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
	bgObj.style.opacity="0.6";
	bgObj.style.left="0";
	bgObj.style.width=sWidth + "px";
	bgObj.style.height=sHeight + "px";
	document.body.appendChild(bgObj);
	var msgObj=document.createElement("div")
	msgObj.setAttribute("id","msgDiv");
	msgObj.setAttribute("align","center");
	msgObj.style.position="absolute";
	msgObj.style.background="white";
	msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
	msgObj.style.border="1px solid " + bordercolor;
	msgObj.style.width=msgw + "px";
	msgObj.style.height=msgh + "px";
	msgObj.style.top=(document.documentElement.scrollTop + (sHeight-msgh)/5) + "px";
	msgObj.style.left=(sWidth-msgw)/2 + "px";
	var title=document.createElement("h4");
	title.setAttribute("id","msgTitle");
	title.setAttribute("align","right");
	title.style.margin="0";
	title.style.padding="3px";
	title.style.background=bordercolor;
	title.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);";
	title.style.opacity="0.75";
	title.style.border="1px solid " + bordercolor;
	title.style.height="18px";
	title.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif";
	title.style.color="white";
	title.style.cursor="pointer";
	title.innerHTML="关闭";
	title.onclick=function(){
	document.body.removeChild(bgObj);
	document.getElementById("msgDiv").removeChild(title);
	document.body.removeChild(msgObj);
	}
	document.body.appendChild(msgObj);
	document.getElementById("msgDiv").appendChild(title);
	var txt=document.createElement("p");
	txt.style.margin="1em 0"
	txt.setAttribute("id","msgTxt");
	var titlecont = content.substring(0,content.indexOf("#"));
	var showcontent = content.substring(content.indexOf("#")+1,content.length);	
	txt.innerHTML="<table><tr><td><h5>"+titlecont+"</h5></td></tr><tr><td><div>"+showcontent+"</div></td></tr></table>";
	document.getElementById("msgDiv").appendChild(txt);
}



function changeop(){

  if(document.getElementById('zys').value==''||document.getElementById('zys').value==0){

  }else {
    if(!isNaN(document.getElementById('zys').value)){
    
       document.getElementById("checkbox1").checked=true;
       document.getElementById("checkbox2").checked=true;
       document.getElementById("checkbox3").checked=true;
 
    } else{alert("您输入的格式不正确,请重新输入");
       document.getElementById('zys').value='';
	   document.getElementById('zys').focus();
      }  
   }
}

function checkop(){
  if(document.getElementById('zys').value==0&&(document.getElementById("checkbox1").checked==true|| document.getElementById("checkbox2").checked==true||document.getElementById("checkbox3").checked==true)){
     alert("不能进行此操作,将显示文章列表!");
	 document.getElementById("checkbox1").checked=false;
     document.getElementById("checkbox2").checked=false;
     document.getElementById("checkbox3").checked=false;
     document.getElementById('zys').focus();
	 return false;	  
   }
  }
  
  
  function checkisknow(){
  
  var ele = document.getElementById('isknow');
   if(ele.checked==true){
       if(ele.value==0){
       
       		if(document.getElementById('qcontent').value==''){
			     alert('您如需设为常见问答，问题内容为必填!');
			     ele.checked=true;
				 document.getElementById('qcontent').focus();	 
			}
			 if(document.getElementById('rcontent').value==''){
				 alert('您如需设为常见问答，回答为必填!');
				 ele.checked=true;
				 document.getElementById('rcontent').focus();				  
		    }
		     if(document.getElementById('questtypeid').value==''){
			     alert('您如需设为常见问答，问答类型为必填!');
			     ele.checked=true;
				 document.getElementById('questtypeid').focus();	
			 }
       }
   } 
}
  
  
  
  
function checkgross(){
    var gross = document.getElementById("gross");
    if(gross.value=="aaa"){
        alert("您输入的文章列表数,摘要数之和大于该栏目下的文章数,请重新输入!");
        return false;
    }
  }
  
  

function Trim(sText) 
{ 
	return sText.replace(new RegExp("(^[\\s]*)|([\\s]*$)", "g"), ""); 
}

  
  

  
  
  
function checkedvalue(){
  if(document.getElementById('zys').value!=0&&document.getElementById("checkbox1").checked==false&&document.getElementById("checkbox2").checked==false&&document.getElementById("checkbox3").checked==false)
     {
       alert("您有未填选项,将显示文章列表!"); 
       document.getElementById('zys').focus();
       return false;	  
  }
}
   
   


			function changeradio(tag){
				var t=document.getElementById("zys");
				if(tag=="open"){
					if(t.disabled){
						t.disabled=false;
					}
				}else{
					if(!t.disabled){
						t.disabled=true;
					}
				}
			}


function fillZero(number){
	if(number<10 && number >0){
		number="0"+number;
	}
	return number;
}


function getCompareDate(minusmonths){

	var nowdate = new Date();
	
	var nowyear = nowdate.getFullYear();
	
	var nowmonth =nowdate.getMonth()+1;
	
	var nowdate = nowdate.getDate();
	
	
	if(minusmonths>0){
		
		if(nowmonth-minusmonths<=0){
			nowmonth=12-(minusmonths-nowmonth);
			nowyear=nowyear-1;
		}else{
			nowmonth-=minusmonths
		}
		
	}
	
	nowmonth=fillZero(nowmonth);
	
	nowdate=fillZero(nowdate-1);
	
	return nowyear+"-"+nowmonth+"-"+nowdate;
	
}





function datechang()
{
	
	var sets=document.zstForm.sets.value;

	var nowdate=getCompareDate(0);
	
	var startdate;
	
	if(sets=="month") {
		
	    startdate=getCompareDate(1);
		
	}else if(sets=="quarter") {
	
		startdate=getCompareDate(3);
		
	}else if(sets=="hyear") {
		
		startdate=getCompareDate(6);
		
	}else if(sets=="year") {
		
		startdate=getCompareDate(12);
		
	}else{
		return;
	}
	
	document.zstForm.enddate.value=nowdate;
			
	document.zstForm.begindate.value=startdate;
}

function datacom(){
 	document.zstForm.enddate.value=getCompareDate(0);
			
	document.zstForm.begindate.value=getCompareDate(1);
}
