﻿
/**
函数:验证用户名格式有效性
参数:用户名
返回:bool (true:有效的用户名)
*/
function Check_UserName(str)
{
    return str.search(/^[a-z0-9_]{2,20}$/i) == -1?false:true;
}

/**
函数:验证权限标识Key格式
参数:权限标识
返回:bool (true:有效)
*/
function Check_PopedomKey(str)
{
    return str.search(/^[a-z0-9_]{2,50}$/i) == -1?false:true;
}

//窗口大小不可变
function OpenWin(win,url,w,h)
{
    parameter = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width="+w+",height="+h+"";
    return window.open(url,win,parameter);
}

//文本编辑使用
function OpenWin2(win,url,w,h)
{
    parameter = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width="+w+",height="+h+"";
    return window.open(url,win,parameter);
}

//对话框
function OpenMWin(url,w,h)
{
    var theDes = "status:no;center:yes;help:no;minimize:no;maximize:no;dialogWidth:"+w+"px;scroll:no;dialogHeight:"+h+"px;border:think";
    return self.showModalDialog(url,null,theDes);
}

//频道选择器
function RCSelector_Open(type, val, title, all)
{
	val = val?val:'';
	title = title?title:'';
	all = all?all:'';
	return OpenMWin("Selector_Article.asp?Type=" + type + "&IdList=" + val + "&WinTitle=" + title + "&ShowAll=" + all, 600, 300);
}

//地区选择器
function Area_Selector(type, val, title, all)
{
	val = val?val:'';
	title = title?title:'';
	all = all?all:'';
	return OpenMWin("Selector_Area.asp?Type=" + type + "&IdList=" + val + "&WinTitle=" + title + "&ShowAll=" + all, 600, 300);
}


//资源特性选择器
function SCSelector_Open(type, val, title, all)
{
	val = val?val:'';
	title = title?title:'';
	all = all?all:'';
	return OpenMWin("Selector_Special.asp?Type=" + type + "&IdList=" + val + "&WinTitle=" + title + "&ShowAll=" + all, 600, 300);
}

//行业分类选择器
function Ins_Selector(type, val, title, all)
{
	val = val?val:'';
	title = title?title:'';
	all = all?all:'';
	return OpenMWin("Selector_Industry.asp?Type=" + type + "&IdList=" + val + "&WinTitle=" + title + "&ShowAll=" + all, 400, 300);
}

//系统权限选择器
function PoPeSelector_Open(type, val, title)
{
	val = val?val:'';
	title = title?title:'';
	return OpenMWin("Popedom_Selector.asp?Type=" + type + "&IdList=" + val + "&WinTitle=" + title, 400, 300);
}

function SelectAllCheckBox(objName)
{
	var coll=document.all.item(objName);
	if(!coll) return;
	if(coll.length){
		for(var i=0;i<coll.length;i++)
		{
			coll.item(i).checked=!coll.item(i).checked;
		}
	}else{
		document.all.item(objName).checked=!document.all.item(objName).checked;
	}
}

function GetCheckBoxList(objName)
{
	var result = "";
	var coll=document.all.item(objName);
	if(!coll) return result;
	if(coll.length){
		for(var i=0;i<coll.length;i++)
		{
			if(coll.item(i).checked)
			{
				result += (result == "")?coll.item(i).value:("," + coll.item(i).value);
			}
		}
	}else{
		if(document.all.item(objName).checked)
		{
			result = document.all.item(objName).value;
		}
	}
	return result;
}

function GetRadioBox(objName)
{
    var Coll = document.all.item(objName);
	if(!Coll) return null;
	if(Coll.length)
	{
		for(var i=0;i<Coll.length;i++)
		{
			if(Coll.item(i).checked)
			{
				return Coll.item(i).value;
			}
		}
		return null;
	}else{
		return Coll.checked?Coll.value:null;
	}
}

function IsDate(str)
{
	return (str.search(/^[\d]{4,4}\-[\d]{1,2}\-[\d]{1,2}[\s]{1,1}[\d]{1,2}\:[\d]{1,2}\:[\d]{1,2}$/i)!=-1?true:false);
}

var obj_PopTool_Current = null;
function PopTool_Show(obj, obj2)
{
	if(obj2 == obj_PopTool_Current)
	{
		return true;
	}

	if(obj2 && obj)
	{
		var t=obj.offsetTop;
		var l=obj.offsetLeft;
		var h=obj.offsetHeight;
		var w=obj.offsetWidth;
		while(obj = obj.offsetParent){
			t+=obj.offsetTop;
			l+=obj.offsetLeft;
		}
		obj2.style.top=t;
		obj2.style.left=l+w;
		obj2.style.visibility = "visible";
	}

	PopTool_Hidden();

	obj_PopTool_Current = obj2;
}

function PopTool_Hidden()
{
	if(!obj_PopTool_Current)
	{
		return;
	}

	if(obj_PopTool_Current.style.visibility == "visible")
	{
		obj_PopTool_Current.style.visibility = "hidden";
		obj_PopTool_Current = null;
	}
}

//input标签不同类型的样式设定
function Input_Style(obj) {
  switch (obj.type) {
    case 'text':
    case 'password':
      return '1px #CCCCCC solid';
    case 'file':
    case 'button':
    case 'submit':
      return '1px black solid';
    case 'radio':
    case 'checkbox':
    default:
      return 'none;';
  }
}
