﻿// JavaScript Document

var flag=false;
//var imgw,imgh,imgid;
//比例缩小图片
function DrawImage(ImgD,w,h){ 
 var image=new Image(); 
 image.src=ImgD.src; 
 if(image.width>0 && image.height>0){ 
  flag=true; 
  if(image.width/image.height>= w/h){ 
   if(image.width>w){
    ImgD.width=w; 
    ImgD.height=(image.height*w)/image.width; 
   }else{ 
    ImgD.width=image.width;
    ImgD.height=image.height; 
   } 
   //ImgD.alt="点击查看详细信息..."; 
  } 
  else{ 
   if(image.height>h){
    ImgD.height=h; 
    ImgD.width=(image.width*h)/image.height; 
   }else{ 
    ImgD.width=image.width;
    ImgD.height=image.height; 
   } 
   //ImgD.alt="点击查看详细信息..."; 
  } 
 }
}

function checkInput(e)
{
	var i,j,inputs;
	inputs = document.getElementsByTagName("input");
	for(i=0;i<e.length;i++)
	{
		for(j=0;j<inputs.length;j++)
		{
			if( e[i]==inputs[j].name || e[i]==inputs[j].id )
				if(inputs[j].value.length==0)
				{
					var OutPut = '请输入' ;
					OutPut += inputs[j].title != '' ? inputs[j].title : '必填内容' ;
					alert( OutPut );
					if( inputs[j].type == "text" ) inputs[j].focus();
					return false;
				}
		}
	}
	inputs = document.getElementsByTagName("textarea");
	for(i=0;i<e.length;i++)
	{
		for(j=0;j<inputs.length;j++)
		{
			if( e[i]==inputs[j].name || e[i]==inputs[j].id )
				if(inputs[j].value.length==0)
				{
					var OutPut = '请输入' ;
					OutPut += inputs[j].title != '' ? inputs[j].title : '必填内容' ;
					alert( OutPut );
					if( inputs[j].style.display == '' ) inputs[j].focus();
					return false;
				}
		}
	}
	return true;
}


function selectCheckbox(n,o)
{
	/*
	*checkbox选择函数
	*n => checkbox的name值
	*o => 操作符(all,none,rev)
	*/
	var cbList = document.getElementsByName(n);
	var i;
	for(i=0;i<cbList.length;i++)
	{
		if(o=="all")
		{
			cbList[i].checked=true;
		}
		else if(o=="none")
		{
			cbList[i].checked=false;
		}
		else if(o=="rev")
		{
			if(cbList[i].checked==true)
				cbList[i].checked=false;
			else
				cbList[i].checked=true;
		}
	}
}

function submitForm(n,t)
{
	if(t!="")
		if(!confirm(t))
			return false;
	eval(n).submit();
}

/*
*注释过时函数
function upLoadImage(value,show)
{
	var width=450;
	var height=350;
	var url= '../eWebEditor/customDialog/img.htm';
	upLoadFunction(value,show,url,width,height);
}

function upLoadFile(value,show)
{
	var width=350;
	var height=160;
	var url= '../eWebEditor/customDialog/file.htm';
	upLoadFunction(value,show,url,width,height);
}

function upLoadFunction(value,show,url,width,height)
{
	var f = false,t = false;
	if(value!='') f = document.getElementById(value);
	if(show!='') t = document.getElementById(show);
	var result=showModalDialog(url,window,"dialogWidth:"+width+"px;dialogHeight:"+height+"px;help:no;scroll:no;status:no");
	if(result!=null)
		if(f&&f.tagName=="INPUT")
		{
			if(result.charAt(0)=='/') result=result.slice(1);
			f.value=result;
			getAttachmentLink(result,show);
			increaClearBtn(value,show);
		}
}*/

function getAttachmentLink(id,target)
{
	var t = document.getElementById(target);
	var url;
	if(t)
	{
		if(isNaN(id)){
			if(id.search(/http:\/\//i)==-1)
				url = '../'+id;
			else
				url = id;
			t.innerHTML = '{<a href="'+url+'" target="_blank" style="color:#FC0000;">点击查看<a>}';
		}else
			t.innerHTML = '{<a href="'+getAttachmentURL(id)+'" target="_blank" style="color:#FC0000;">点击查看<a>}';
		t.style.display = "";
	}
}

function increaClearBtn(f,t)
{
	var targetObj = document.getElementById(t);
	targetObj.innerHTML = targetObj.innerHTML + '&nbsp;<a title="删除" href="javascript:void(0);" style="color:#EC0000;border:1px solid #E00; padding:0 2px;" onclick="clearAttachment(\''+f+'\',\''+t+'\');">X</a>';
}

function clearAttachment(i,t)
{
	var inputObj = document.getElementById(i);
	var displayObj = document.getElementById(t);
	inputObj.value = '';
	displayObj.innerHTML = '';
	displayObj.style.display = 'none';
}

function getAttachmentURL(id)
{
	var baseURL = getBaseURL('admin/')+'UploadFiles/';
	var url = "response.asp?t=attachment&g=PostContent&PostID="+id;
	url = baseURL+getResponse(url);
	return url;
}

function getBaseURL(e)
{
	var baseURL = location.host+location.pathname;
	var arr = baseURL.split("/");
	baseURL = 'http://'+baseURL.replace(arr[arr.length-1],'').replace(e,'');
	return baseURL;
}

function getResponse(url)
{
	var xmlobj = new ActiveXObject("Microsoft.XMLHTTP");
	xmlobj.open("POST",url,false); 
	xmlobj.send();
	var strResult = unescape(xmlobj.responseText);
	return strResult;
}

warning = function (e,w,h)
{
	var msg = new CMSMsgBox();
	msg.Width = w || 300;
	msg.Height = h || 80;
	msg.Mask = true;
	msg.Skin = 'loading';
	msg.DblClick = false;
	msg.Value = '<div style="margin:9px;">提示：</div><div style="margin:9px;padding:6px;">'+e+'<li><a href="javascript:history.back();">返回上一页</a></li></div>';
	msg.show();
}

function postSubmit(e)
{
	return checkInput( arguments );
}

function checkAllBox(e)
{
	if(e.checked==true)
		selectCheckbox(e.value,'all');
	else
		selectCheckbox(e.value,'none');
}

function UpLoadFile( e ){
    var Result = showModalDialog( 'uploaddialog/customDialog/file.htm' , '' , 'dialogWidth:23em; dialogHeight:9em; status:0;help=no' ) ;
    if ( Result != null && Result != 'http://' )
        document.getElementById( e ).value = Result ;
	else if ( Result == 'http://' )
		document.getElementById( e ).value = '' ;
	if( typeof( arguments[1] ) == 'function' ) arguments[1]( e , Result ) ;
	
}


function FCKeditor_OnFocus( editorInstance )
{
	editorInstance.ToolbarSet.Expand() ;
}

function FCKeditor_OnBlur( editorInstance )
{
	editorInstance.ToolbarSet.Collapse() ;
}

function changeFontZise(size)
{
	var i=0;
	var c = document.getElementById("content")
		if(size == "big")
			c.style.fontSize = "18px";
		else if(size == "mid")
			c.style.fontSize = "16px";
		else if(size == "small")
			c.style.fontSize = "12px";
}


function EchoPageContent( content )
{
	var iHTML = '' ;
	
	if( content.search( /<div>\[pagebreak\]<\/div>/ ) == -1 )
	{
		iHTML = content ;
	}else{
		var iContent = content.split( '<div>[pagebreak]</div>' ) ;
		
		for( var i = 0;i < iContent.length; i++ )
		{
			iHTML += '<div id="iPage' + i + '" ' ;
			if( i > 0 )
				iHTML += 'style="display:none;"' ;
			iHTML += '>' + iContent[i] + '</div>' ;
		}
		
		iHTML += '<div id="iPageList">' + ReturnPageList( iContent.length ) + '</div>' ;
	}
	
	document.write( iHTML ) ;
}

function TurnPage( total,current )
{
	var iCurrent = current || 0 ;
	
	for(var i = 0; i < total; i++ )
		i == iCurrent ? document.getElementById( 'iPage' + i ).style.display = '' : document.getElementById( 'iPage' + i ).style.display = 'none' ;
		
	document.getElementById( 'iPageList' ).innerHTML = ReturnPageList( total,current ) ;

}

function ReturnPageList( total,current )
{
	var iCurrent = current || 0 ;
	var iHTML = '' ;
	
	iCurrent <= 0 ? iHTML += '<span class="disabled">&lt;</span>&nbsp;' : iHTML += '<a href="javascript:void(0);" onclick="TurnPage( ' + total + ',' + (iCurrent - 1) + ' );">&lt;</a>&nbsp;' ;
	
	for(var i = 0; i < total; i++ )
		i == iCurrent ? iHTML += '<span class="current">' + (i + 1) + '</span>&nbsp;' : iHTML += '<a href="javascript:void(0);" onclick="TurnPage( ' + total + ',' + i + ' );">' + (i + 1) + '</a>&nbsp;' ;			
			
	iCurrent + 1 >= total ? iHTML += '<span class="disabled">&gt;</span>' : iHTML += '<a href="javascript:void(0);" onclick="TurnPage( ' + total + ',' + (iCurrent + 1) + ' );">&gt;</a>&nbsp;' ;
	
	return iHTML ;
}

function CreateElement( parentID,element )
{
	var iElement = document.createElement( element ) ;
	var iParent = document.getElementById( parentID ) ;
	iParent.appendChild( iElement );
	return iParent.document.getElementById( element ) ;
}
