function getpos(element)
{
        if ( arguments.length != 1 || element == null )
        {
               return null;
        }
        var elmt = element;
        var offsetTop = elmt.offsetTop;
        var offsetLeft = elmt.offsetLeft;
        var offsetWidth = elmt.offsetWidth;
        var offsetHeight = elmt.offsetHeight;
        while( elmt = elmt.offsetParent )
        {
                // add this judge
                if ( elmt.style.position == 'absolute'
//              || elmt.style.position == 'relative'
                || ( elmt.style.overflow != 'visible' && elmt.style.overflow != '' ) )
                {
                        break;
                }
                offsetTop += elmt.offsetTop;
                offsetLeft += elmt.offsetLeft;
        }
        return {top:offsetTop, left:offsetLeft, right:offsetWidth+offsetLeft, bottom:offsetHeight+offsetTop };
}
//DataLength
function b_strlen(fData)
{
	var intLength=0;
	for (var i=0;i<fData.length;i++)
	{
		if ((fData.charCodeAt(i) < 0) || (fData.charCodeAt(i) > 255))
			intLength=intLength+2;
		else
			intLength=intLength+1;   
	}
	return intLength;
}

function CopyToClipBoard(obj)
{
	obj.select();
	js=obj.createTextRange();
	js.execCommand("Copy")
	alert("复制成功，请粘贴到你的QQ/MSN上推荐给你的好友！");
} 

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;
}
/**
 * 生成sublocation或university的下拉菜单
 * object 下拉菜单对象，如work_sublocation
 * selectValue 对应的location的value
 * defaultValue 初始值
 * isUniversity 区别sublocation列表还是university列表
 * keepFirst 是否保留第一个选项，如"请选择"
 */
function redirect(object, selectValue, defaultValue, isUniversity, keepFirst)
{
	selectValue  = parseInt(selectValue);
	defaultValue = parseInt(defaultValue);
	/**清空原有的選項**/
	if (keepFirst)
	{
		limit = 1;
	}
	else
	{
		limit = 0;
	}
	for (m = object.options.length; m >= limit; m--)
	{
		object.options[m] = null;
	}

	var newOption = '';
	
	var key;
	
	if (isUniversity)
	{
		for (key in university_array[selectValue])
		{
			newOption = new Option(university_array[selectValue][key], key);
			if (key == defaultValue)
			{
				newOption.selected = true;
			}
			object.options.add(newOption);
		}
	}
	else 
	{
		for (key in sublocation_array[selectValue])
		{
			newOption = new Option(sublocation_array[selectValue][key], key);
			if (key == defaultValue)
			{
				newOption.selected = true;
			}
			object.options.add(newOption);
		}
	}
}

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()
{
	return new Date().getTime().toString().substr(8);
}

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 ConfirmOpt(form)
{
	if(CountCheckBox(form)<1)
	{
		alert('请选择您要执行操作的对象！');
		return false;
	}
	else return confirm('您确信要对所选对象执行当前操作？');
}

function SubLogin()
{
	if($("#LoginName").val()=='')
	{
		alert('请输入您的登录用户名！');
		$("#LoginName").focus();
		return false;
	}
	else if($("#UserPass").val()=='')
	{
		alert('请输入您的登录密码！');
		$("#UserPass").focus();
		return false;
	}
	else if($("#AuthCode").val()=='')
	{
		alert('请输入当前有效的验证码！');
		$("#AuthCode").focus();
		return false;
	}
	else
	{
		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 Opt(form)
{
	if(CountCheckBox(form)<1)
	{
		alert('请选择您要执行操作的对象！');
		return false;
	}
	else return true;
}

function ActChange(form)
{
	if(Opt(form))
		form.submit();
	else
		return false;
}
/** **/
