function GetByID(id)
{
   itm = null;
   if (document.getElementById)
   {
      itm = document.getElementById(id);
   }
   else if (document.all)
   {
      itm = document.all[id];
   }
   else if (document.layers)
   {
      itm = document.layers[id];
   }
   
   return itm;
}

function QueryTip(url)
{
	$.get(
		url,
		function(data)
		{
			try
			{
				ShowTempTip(data);
			}
			catch (e)
			{
			}
		}
	);
	return false;
}

function IsMobile(ipt)
{
	var filter=/(^13{1}[0-9]{9}$)|(^15{1}[0-9]{9}$)/;
	if (!filter.test(ipt))        return false; 
	return true;   
}

function CheckNumber(value)
{
	var patten = /[^0-9]/;
		
	if(value <= 0)
		return false;	
	var patrn = /[0-9]+$/;
	if( patrn.test(value) ) return true;
}

function isEmail(s)
{
	var patrn = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	if( patrn.test(s) )
		return true;
	else
		return false;
}

function QueryCheck(ObjName, ObjValue)
{
	$.get(
		AjaxURL+"&Opt=Check&"+ObjName+"="+encodeURI(ObjValue),
		function(data){$('#Tip'+ObjName).html(data);}
	);
}

function TimeOutHide(TipName)
{
	TipTime = typeof(arguments[1]) == "undefined" ? '3000' : arguments[1];

	$(TipName).hide();
	$(TipName).show("slow");
	setTimeout('$("'+TipName+'").hide()', TipTime);
}
/*
ShowTempTip(Tip, TipTime, TipName)
*/
function ShowTempTip(Tip)
{
	var TipName; var TipTime;

	TipTime = typeof(arguments[1]) == "undefined" ? '3000' : arguments[1];
	TipName = typeof(arguments[2]) == "undefined" ? '#result-hints' : '#'+arguments[2];

	document.getElementById(TipName.replace('#', '')).style.left = ((document.body.clientWidth-300)/2) + "px";
	document.getElementById(TipName.replace('#', '')).style.top  = ((document.documentElement.clientHeight-100)/2) + "px";
	document.getElementById(TipName.replace('#', '')).style.position = 'absolute';
	$(TipName).html(Tip);
	TimeOutHide(TipName, TipTime);
}

function GetTime()
{
	now =   new Date();   
	y   =   now.getYear();   
	m   =   now.getMonth()+1;   
	d   =   now.getDate();   
	H   =   now.getHours();   
	i   =   now.getMinutes();   
	s   =   now.getSeconds();   
	return  y+""+m+""+d+""+H+""+i+""+s;  
}

function PassDate(CreateDate, PassTime)
{
	sDay = parseInt(PassTime/86400);
	if (sDay > 0){document.write(sDay+"天");return true;}
	iHour = parseInt(PassTime/3600);
	if (iHour > 0){document.write(iHour+"小时");return true;}
	iMinute = parseInt((PassTime/60)%60);
	if (iMinute > 0){document.write(iMinute+"分");return true;}
	iSecond = parseInt(PassTime%60);
	if (iSecond >= 0){document.write(iSecond+"秒");return true;}
}


function SelectedVal(SelName, Val)
{
	if(Val=='') return false;
	$("select[@name="+SelName+"] option").each(function(i){
		if(this.value==Val) this.selected = true;
	});
}

function CheckedVal(BoxName, Val)
{
	if(Val=='') return false;
	$("input[@name="+BoxName+"]").each(function(i){
		if(this.value==Val) this.checked = true;
	});
}

/** **/
function SetHasValue(Str, ByName)
{
	if(Str.length>0)
	{
		var toArray = Str.split(',');
		var e = document.getElementsByName(ByName);
		for(q=0; q<toArray.length; q++)
		{
			for (i=0;i<e.length;i++) 
			{
				if ( toArray[q]==e[i].value)
					e[i].checked = true;
			}
		}
	}
}

function GetHasValue(ByName)
{
	var n; var Str = ''; var Arr = Array();
	var e = document.getElementsByName(ByName);
	for (n=0;n<e.length;n++) 
	{
		if(e[n].checked == true)
		{
			if(!isNaN(e[n].value))
			{
				Str = Str + e[n].value + ',';
			}
			else if(typeof(arguments[1]) != "undefined")
			{
				Arr = e[n].value.split('|');
				Str = Str + Arr[arguments[1]] + ',';
			}
		}
	}
	Str = Str.substring(0, Str.length-1);
	return Str;
}

function GetSumValue(ByName, Checked)
{
	var n; var Str = 0; var Arr = Array();
	var e = document.getElementsByName(ByName);
	for (n=0;n<e.length;n++) 
	{
		if(!isNaN(e[n].value))
		{
			Str = Str + parseFloat(e[n].value);
		}
		else if(typeof(arguments[2]) != "undefined")
		{
			Arr = e[n].value.split('|');
			if(Checked==true && e[n].checked == true)
				Str = Str + parseFloat(Arr[arguments[2]]);
			else if(Checked==false)
				Str = Str + parseFloat(Arr[arguments[2]]);
		}
	}
	Str = Str.toFixed(2);
	return Str;
}

function GetValues(ByName)
{
	var n; var Str = ''; var Arr = Array();
	var e = document.getElementsByName(ByName);
	for (n=0;n<e.length;n++) 
	{
		if(!isNaN(e[n].value) && e[n].value>0)
		{
			Str = Str + e[n].value + ',';
		}
		else if(typeof(arguments[1]) != "undefined")
		{
			Arr = e[n].value.split('|');
			Str = Str + Arr[arguments[1]] + ',';
		}
	}
	Str = Str.substring(0, Str.length-1);
	return Str;
}

function CountHasValue(ByName)
{
	var n; var Num = 0;
	var e = document.getElementsByName(ByName);
	for (n=0;n<e.length;n++) 
	{
		if(e[n].checked == true && !isNaN(e[n].value))
		{
			Num++;
		}
	}
	return Num;
}
/** **/


/** **/
function CountCheckBox(form)
{
	var c = 0;
	for (var i=0;i<form.elements.length;i++) 
	{
		var e = form.elements[i];
		if (e.checked == true && e.type=='checkbox' && e.rel!='NotInAll')
			c = c + 1;
	}
	return c;
}

function CheckAll(form) 
{
	for (var i=0;i<form.elements.length;i++)
	{
		var e = form.elements[i];
		if (e.name != 'chkall' && e.type=='checkbox' && e.rel!='NotInAll')
			e.checked = form.chkall.checked;
	}
}

function ConfirmOpt(form)
{
	if(CountCheckBox(form)<1)
	{
		alert('请选择您要执行操作的对象！');
		return false;
	}
	else return confirm('您确信要对所选对象执行当前操作？');
}

function Opt(form)
{
	if(CountCheckBox(form)<1)
	{
		alert('请选择您要执行操作的对象！');
		return false;
	}
	else return true;
}

function ActChange(form)
{
	if(Opt(form))
		form.submit();
	else
		return false;
}


function OpenDialog(html)
{
	var bwidth  = document.body.clientWidth;
	var bheight = document.body.clientHeight;
	
	mwidth  = typeof(arguments[1]) == "undefined" ? '300' : arguments[1];
	mheight = typeof(arguments[2]) == "undefined" ? '80' : arguments[2];

	var s = '<div id="TipBG" style="width:'+bwidth+'px;height:'+bheight+'px;left:0px;top:0px;position:absolute;z-index:999;background-color:#666666;filter:Alpha(Opacity=50, FinishOpacity=50, Style=1, StartX=0, StartY=0, FinishX=100, FinishY=100);" ></div><div id="result-hints"></div>';
	$("body").prepend(s);

	$('#result-hints').css("width"   ,mwidth);
	$('#result-hints').css("height"  ,mheight);
	$('#result-hints').css("left"    ,((bwidth-mwidth)/2) + "px");
	$('#result-hints').css("top"     ,((document.documentElement.clientHeight-mheight)/2) + "px");
	$('#result-hints').css("position","absolute");
	$('#result-hints').html(html);
	$('#result-hints').show();
}

function CloseDialog()
{
	$("div").remove('#TipBG');
	$('#result-hints').hide();
}
/** **/
