// JavaScript Document

// 系统管理员登录表单提交检查
function CheckAdminloginForm(objs)
{
	if (!CheckIsLoginUserName(objs.loginUserName,"登录帐号")){
		return false;
	}
	if (!CheckIsLoginPassword(objs.loginPassword,"登录密码")){
		return false;
	}
	if (!CheckIsGetCode(objs.getCode,objs.getCodeID,"验证码")){
		return false;
	}
	
}

// 检查系统管理员登录名称
function CheckIsLoginUserName(obj,strMsg)
{
	if (!CheckIsEmpty(obj,strMsg)){
		return false;
	}
	if (!CheckIsChar(obj,strMsg)){
		return false;
	} 
	if (!CheckMinMaxChar(obj,strMsg,4,20)){
		return false;
	} 
	return true;	
}

// 检查系统管理员登录密码
function CheckIsLoginPassword(obj,strMsg)
{
	if (!CheckIsEmpty(obj,strMsg)){
		return false;
	}
	if (!CheckIsChar(obj,strMsg)){
		return false;
	} 
	if (!CheckMinMaxChar(obj,strMsg,6,20)){
		return false;
	}
	return true;	
}

// 检查系统验证码
function CheckIsGetCode(obj,obj1,strMsg)
{
	if (!CheckIsEmpty(obj,strMsg)){
		return false;
	}
	if (!CheckIsChar(obj,strMsg)){
		return false;
	} 
	if (!CheckMinMaxChar(obj,strMsg,4,4)){
		return false;
	}
	return true;	
}




// 判断指定的内容是否为空，若为空则弹出 警告框 
function CheckIsEmpty(obj,strMsg){ 
	if(obj.value==""){ 
		alert(strMsg+"| 不能为空!"); 
		obj.focus();
		return false; 
	} 
	return true;	
} 

// 检查是否字母数字上下划线及字符quot;
function CheckIsChar(obj,strMsg){
	var filter=/^[A-Za-z0-9_-]+$/;
	if (!filter.test(obj.value)) { 
		alert(strMsg+"| 填写不正确,请重新填写！可使用的字符为（A-Z a-z 0-9 _ -）。"); 
		obj.focus();
		return false; 
	}
	return true;	
}
//检查字符数
function CheckMinMaxChar(obj,strMsg,Min,Max){
	if ((obj.value.length<Min)|(obj.value.length>Max)){
		alert(strMsg+"| 字符数应介于"+Min+"与"+Max+"之间！"); 
		obj.focus();
		return false; 
	}
	return true;	
}

// 检查两次密码是否一致
function CheckIsPasswordSameness(obj1,obj2,strMsg){
	if (!CheckIsEmpty(obj1,strMsg)){
		return false;
	}
	if (!CheckIsEmpty(obj2,strMsg)){
		return false;
	}
	if (obj1.value!=obj2.value){
		alert(strMsg+"| 两次输入不一致");
		obj1.focus();
		return false;
	} 
	return true;	
}


// 检查email
function CheckIsEmail(obj){
	str=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
	if(!str.exec(obj.value)){
		alert("请输入正确邮箱地址");
		obj.focus();
		return false;
	} else{
		return true;	
	}
}


// 检查是否符合要求，不符合返回 
function CheckIsSafe(strMsg){ 
		alert(strMsg+"| 错误！"); 
		history.go(-1);
} 


// 全部选取或全部取消checkbox
function SelectAllCheckBox() {
	var objs = window.document.getElementsByTagName("input");
	for(var i=0; i<objs.length; i++)
	{
		if(objs[i].type.toLowerCase() == "checkbox" ) objs[i].checked = true;
	}
}

//  反选CheckBox
function RevCheckBox()
{
	var objs = window.document.getElementsByTagName("input");
	for(var i=0; i<objs.length; i++)
	{
		if(objs[i].type.toLowerCase() == "checkbox" )
		{
			if(objs[i].checked == true)
			{
				objs[i].checked = false;
			}
			else
			{
				objs[i].checked = true;
			}
		}
	}
}


// 打开链接
function OpenFileUrl(Url)
{
	window.location.href=Url;
}

// 打开操作链接
function ActionSubmit(ActType,id,pageid)
{
	var url;
	url = "?Act=" + ActType + "&page="+ pageid + "&ID="+id;
	if((ActType == "Passed")|(ActType == "DPassed")|(ActType == "Del"))
	{
		url = "?Act=" + ActType +  "&page="+ pageid + "&IDList="+id;
	}
	if(ActType == "Del")
	{
		Msg = confirm("确定要删除该内容吗？特别说明，删除后无法恢复！");
		if (Msg != "0")
		{
			OpenFileUrl(url);
		}
	}
	else
	{
		OpenFileUrl(url);
	}
}

// 打开操作选项链接
function OptionSubmit(ActType,pageid)
{
	var idArray = new Array();//定义一个数组
	var cv = document.getElementsByTagName("input");
	var m = 0;
	for(var i=0; i<cv.length; i++)
	{
		if(cv[i].type.toLowerCase() == "checkbox")
		{
			if(cv[i].checked)
			{
				idArray[m] = cv[i].value;
				m++;
			}
		}
	}
	var id = idArray.join(",");
	if(!id || id == "0")
	{
		alert("没有勾选要操作的主题！");
		return false;
	}
	var url;
	url = "?Act=" + ActType + "&page="+ pageid + "&IDList=" + id;
	if(ActType == "Del")
	{
		Msg = confirm("确定要删除所选内容吗？特别说明，删除后无法恢复！");
		if (Msg != "0")
		{
			OpenFileUrl(url);
		}
	}
	else
	{
		OpenFileUrl(url);
	}
}


// 打开操作选项链接
function OptionSelectSubmit(pageid)
{
	var ActType = document.getElementById("OptionSelect").options[document.getElementById("OptionSelect").options.selectedIndex].value;
	var idArray = new Array();//定义一个数组
	var cv = document.getElementsByTagName("input");
	var m = 0;
	for(var i=0; i<cv.length; i++)
	{
		if(cv[i].type.toLowerCase() == "checkbox")
		{
			if(cv[i].checked)
			{
				idArray[m] = cv[i].value;
				m++;
			}
		}
	}
	var id = idArray.join(",");
	if(!id || id == "0")
	{
		alert("没有勾选要操作的主题！");
		return false;
	}
	var url;
	url = "?Act=" + ActType + "&page="+ pageid + "&IDList=" + id;
	if(ActType == "Del")
	{
		Msg = confirm("确定要删除所选内容吗？特别说明，删除后无法恢复！");
		if (Msg != "0")
		{
			OpenFileUrl(url);
		}
	}
	else
	{
		OpenFileUrl(url);
	}
}

// 显示或关闭隐藏层
function IsShowLayerFocus(LayerPicID,Tid){
	if(Tid==1){
		document.getElementById(LayerPicID).style.visibility="";
	}else{
		document.getElementById(LayerPicID).style.visibility="hidden";
	}
}

// 鼠标点击切换效果
function topSwitchTag(id,MenuCount){
	var c=MenuCount;
	for(var i=1;i<=c;i++){
		document.getElementById('topTagMenu'+i).className='';
	}
	document.getElementById('topTagMenu'+id).className="topmenuhere";
	switch (id){
		case 1:
			window.open("menu.asp","menu");
			break;
		case 2:
			window.open("menu_set.asp","menu");
			break;
		case 3:
			window.open("menu_sys.asp","menu");
			break;
		default:
			window.open("menu.asp","menu");
			break;
	}
}

// 鼠标点击切换效果
function LangSwitchTag(id,MenuCount){
	var c=MenuCount;
	for(var i=1;i<=c;i++){
		document.getElementById('LangSwitchTag'+i).style.display='none';
		document.getElementById('TagLangMenu'+i).className='';
	}
	document.getElementById('LangSwitchTag'+id).style.display='';
	document.getElementById('TagLangMenu'+id).className="langmenuhere";

}



// 选取图片文件
function SelectPhoto(url,w,h,ebyid,pbyid){
	var intLeft = (screen.availWidth/2) - w/2;
	var intTop = (screen.availHeight/2) - h/2;
	//window.document.getElementById('PicUrl').value="#FF0000";
	if (window.showModalDialog!=null)   //IE判断
	{
		var smd= window.showModalDialog(url,"","dialogWidth:"+ w +"px;dialogHeight:"+ h +"px;dialogLeft:"+ intLeft +"px;dialogTop:"+ intTop +"px;status:no;help:no;scrolling=no;scrollbars=no;resizable=no");
		if(smd!=null)
		{
			window.document.getElementById(ebyid).value=smd;
			window.document.getElementById(pbyid).style.display="";
		}
		return;
	}
	else
	{
		this.returnAction=function(strResult)
		{
			if(strResult!=null)
			{
				window.document.getElementById(ebyid).value=strResult;
				window.document.getElementById(pbyid).style.display="";
			}
		window.open(url,"","width="+ w +",height="+ h +",left="+ intLeft+",top="+ intTop +",menubar=no,toolbar=no,location=no,scrollbars=no,status=no,modal=yes,resizable=no");
		return;
		}
	}
}

// 查看图片文件
function ViewPhoto(url,w,h,ebyid){
	var intLeft = (screen.availWidth/2) - w/2;
	var intTop = (screen.availHeight/2) - h/2;
	var values=window.document.getElementById(ebyid).value;
	if (window.showModalDialog!=null)   //IE判断
	{
		var smd= window.showModalDialog(url+values,"","dialogWidth:"+ w +"px;dialogHeight:"+ h +"px;dialogLeft:"+ intLeft +"px;dialogTop:"+ intTop +"px;status:no;help:no;scrolling=no;scrollbars=no;resizable=no");
		if(smd!=null)
		{
			window.document.getElementById(ebyid).value=smd;
		}
		return;
	}
	else
	{
		this.returnAction=function(strResult)
		{
			if(strResult!=null)
			{
				window.document.getElementById(ebyid).value=strResult;
			}
		window.open(values,"","width="+ w +",height="+ h +",left="+ intLeft+",top="+ intTop +",menubar=no,toolbar=no,location=no,scrollbars=no,status=no,modal=yes,resizable=no");
		return;
		}
	}
}

// 预览缩略图
function PreviewPhoto(url,w,h){
	var intLeft = (screen.availWidth/2) - w/2;
	var intTop = (screen.availHeight/2) - h/2;
	if (window.showModalDialog!=null)   //IE判断
	{
		var smd= window.showModalDialog(url,"","dialogWidth:"+ w +"px;dialogHeight:"+ h +"px;dialogLeft:"+ intLeft +"px;dialogTop:"+ intTop +"px;status:no;help:no;scrolling=no;scrollbars=no;resizable=no");
		return;
	}
	else
	{
		this.returnAction=function(strResult)
		{
		window.open(url,"","width="+ w +",height="+ h +",left="+ intLeft+",top="+ intTop +",menubar=no,toolbar=no,location=no,scrollbars=no,status=no,modal=yes,resizable=no");
		return;
		}
	}
}

// 插入图片文件
function InsertPicture(url,w,h,inputname){
	var intLeft = (screen.availWidth/2) - w/2;
	var intTop = (screen.availHeight/2) - h/2;
	if (window.showModalDialog!=null)   //IE判断
	{
		var smd= window.showModalDialog(url+inputname,"","dialogWidth:"+ w +"px;dialogHeight:"+ h +"px;dialogLeft:"+ intLeft +"px;dialogTop:"+ intTop +"px;status:no;help:no;scrolling=no;scrollbars=no;resizable=no");
		if(smd!=null)
		{
			InsertHTML(smd,inputname);
		}
		return;
	}
	else
	{
		this.returnAction=function(strResult)
		{
			if(strResult!=null)
			{
				InsertHTML(strResult,inputname);
			}
		window.open(url+inputname,"","width="+ w +",height="+ h +",left="+ intLeft+",top="+ intTop +",menubar=no,toolbar=no,location=no,scrollbars=no,status=no,modal=yes,resizable=no");
		}
	}
}


function InsertHTML(code,inputname)
{
	var oEditor = FCKeditorAPI.GetInstance(inputname) ;
	 if ( oEditor.EditMode == FCK_EDITMODE_WYSIWYG )
	{
		 // Insert the desired HTML.
		 oEditor.InsertHtml(code) ;
	}
	else
		alert( 'You must be on WYSIWYG mode!' ) ;
}


// 选取颜色代码
function SelectColor(url,w,h,cbyid,imgid){
	var intLeft = getOffsetLeft(window.document.getElementById(imgid));
	var intTop =  (getOffsetTop(window.document.getElementById(imgid)) + window.document.getElementById(imgid).offsetHeight);
	//var intLeft = (screen.availWidth/2) - w/2;
	//var intTop = (screen.availHeight/2) - h/2;
	//obj.style.left = getOffsetLeft(ColorImg) + "px";
	//obj.style.top = (getOffsetTop(ColorImg) + ColorImg.offsetHeight) + "px";
	//window.document.getElementById('PicUrl').value="#FF0000";
	if (window.showModalDialog!=null)   //IE判断
	{
		var smd= window.showModalDialog(url,"","dialogWidth:"+ w +"px;dialogHeight:"+ h +"px;dialogLeft:"+ intLeft +"px;dialogTop:"+ intTop +"px;status:no;help:no;scrolling=no;scrollbars=no;resizable=no");
		if(smd!=null)
		{
			window.document.getElementById(cbyid).value=smd;
			window.document.getElementById(imgid).style.backgroundColor=smd;
		}
		return;
	}
	else
	{
		this.returnAction=function(strResult)
		{
			if(strResult!=null)
			{
				window.document.getElementById(cbyid).value=strResult;
				window.document.getElementById(imgid).style.backgroundColor=smd;
			}
		window.open(url,"","width="+ w +",height="+ h +",left="+ intLeft+",top="+ intTop +",menubar=no,toolbar=no,location=no,scrollbars=no,status=no,modal=yes,resizable=no");
		return;
		}
	}
}

//Colour pallete top offset
function getOffsetTop(elm) {
	var mOffsetTop = elm.offsetTop;
	var mOffsetParent = elm.offsetParent;
	while(mOffsetParent){
		mOffsetTop += mOffsetParent.offsetTop;
		mOffsetParent = mOffsetParent.offsetParent;
	}
	return mOffsetTop;
}

//Colour pallete left offset
function getOffsetLeft(elm) {
	var mOffsetLeft = elm.offsetLeft;
	var mOffsetParent = elm.offsetParent;
	while(mOffsetParent) {
		mOffsetLeft += mOffsetParent.offsetLeft;
		mOffsetParent = mOffsetParent.offsetParent;
	}
	return mOffsetLeft;
}

// 顶部导航菜单鼠标Over/点击切换效果
function menuTopSwitchTag(id,MenuCount){
	var c=MenuCount;
	for(var i=1;i<=c;i++){
		document.getElementById('menuTopSwitchTag'+i).className='';
	}
	document.getElementById('menuTopSwitchTag'+id).className="menuTopHere";
}

function menuTopSwitchTagOut(MenuCount){
	var c=MenuCount;
	for(var i=1;i<=c;i++){
		document.getElementById('menuTopSwitchTag'+i).className='';
	}
}

// 打开链接
function openMenuUrl(Url)
{
	window.location.href=Url;
}


//鼠标点击切换效果
function switchTag(id,MenuCount){
	var c=MenuCount;
	for(var i=1;i<=c;i++){
		document.getElementById('switchTag'+i).style.display='none';
		document.getElementById('TagMenu'+i).className='';
	}
	document.getElementById('switchTag'+id).style.display='';
	document.getElementById('TagMenu'+id).className="menuhere";
}
