/* 
 * $Header: 公用JS
 * $Source: /Manage/js/global.js
 * $Author: Jerry
 * $CreateDate:06-10-29 10:27  $
 * 
 * *****************  Version 1  *****************
 * User: Jerry        Date: 06-10-29   Time: 10:27 
 * Created in $/Manage/js
 * 
*/

var loader = '<div id="loader"></div>';
var thisEmot = 1;

//重置URL
function redirect(url) {window.location.replace(url);}

//检查Email地址格式
function isMail(mail)
{
	return(new RegExp(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(mail));
}

/* 
* 判断是否为整数，是则返回true,否则返回false 
*/ 
function f_check_integer(str)   
{
	return(new RegExp(/^\d+$/).test(str));
}

/* 
* 判断是否为整数，是则返回true,否则返回false 
*/ 
function f_check_z_integer(str)   
{
	return(new RegExp(/^[0-9]*[1-9][0-9]*$/).test(str));
}
//жϵ绰,Էfalse
function IsTel(number)
{
    len=number.length;
    dotNum=0;
    if (len==0)
        return true;
    for(var i=0;i<len;i++)
    {
        oneNum=number.substring(i,i+1);
        if (oneNum=="-")
        {
            if(i==0)
            {
                return false;
            }
            if(i+1==len)
            {
                return false;
            }
            dotNum++;
        }
        if ((oneNum<"0" || oneNum>"9") && oneNum!="-")
            return false;
    }
    return true;
}


function IsMinute(min)
{
    //жǷ ' зfalse
    len=min.length;
    if (len==0)
        return true;
    for(var i=0;i<len;i++)
    {
        oneNum=min.substring(i,i+1);
        if (oneNum=="'")
        {
            //alert("ӛŤΤߤäˤʤޤ");
            return false;
        }
    }
    return true;
}

function getHost(url) 
{ 
	var host = "null";
	if ( typeof url == "undefined" || null == url )
		url = window.location.href;
	var regex = /.*\:\/\/([^\/]*).*/;
	var match = url.match(regex);
	if ( typeof match != "undefined" && null != match )
		host = match[1];
	return host;
}

function getQuery(name)
{
    var reg = new RegExp('(^|&)'+ name +'=([^&]*)(&|$)');
    var r = window.location.search.substr(1).match(reg);
    if (r!=null) return unescape(r[2]); return null;
}

function setCookie(name,value,path)
{
    var Days = 30; //?cookie 将被保存 30 ?
    var exp  = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime());
    document.cookie = name + '='+ escape (value) + ';path=' + path;//expires=" + exp.toGMTString();
}

//读取COOKIE
function getCookie(name)
{
    var arr = document.cookie.match(new RegExp('(^| )'+name+'=([^;]*)(;|$)'));
    if(arr != null && arr[2] != "") return unescape(arr[2]); return null;
}

function delCookie(name)
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
    if(cval!=null) document.cookie= name + '='+cval+';expires='+exp.toGMTString();
}

var is_ie = document.all ? true : false;
var is_ff = window.addEventListener ? true : false;

function getCurrentLocation()
{
	var url  = window.location.href;
	if(window.opera)
		url=window.location.hash;
	
	if( url == null || url == undefined )
		return null;

	if( url.indexOf("#") == -1 )
		return "";
	else
	{
		var num = url.indexOf("#");
		if( url.length == (num+1) )
			return "";
		else
			return url.substring(num+1);
	}
}

function getXMLDom()
{
	//--------------------------建立XMLDOM对象-------------------------------// 

	if (window.ActiveXObject)
		return new ActiveXObject("Microsoft.XMLDOM"); 
	else
	{ 
		if (document.implementation && document.implementation.createDocument)
			return document.implementation.createDocument("","",null); 
	} 

}

function getElementValue(node,key)
{
	if (window.ActiveXObject)
		return node.selectSingleNode(key).text;
	else
		return node.getElementsByTagName(key).item(0).childNodes[0].nodeValue
}

function formatIPAddress(ip)
{
	var num = ip.lastIndexOf(".")+1;
	return ip.substring(0,num)+"*";
}

function checkAll(thisCol,cb)
{
	var cbCol = document.getElementsByName(cb);
	
	//var cbCol = document.all(cb);
	var hasCheck = true;

	if ( cbCol.length == null )
	{
		if ( cbCol.checked )
		{
			cbCol.checked = false;
			hasCheck = false;
		}
		else
			cbCol.checked = true;
	}
	else
	{
		for ( var i=0;i<cbCol.length;i++ )
		{
			if ( cbCol[i].checked )
			{
				hasCheck = false;
			}
		}

		for ( var e=0;e<cbCol.length;e++ )
		{
			cbCol[e].checked = hasCheck;
		}
	}

	thisCol.checked = hasCheck;
}

function getCheckBoxValues(cb)
{
	var ret = new Array();
	
	var cbCol = document.getElementsByName(cb);
	if ( cbCol == null )return ret;

	if ( cbCol.length == null && cbCol.checked )
		ret[0] = cbCol.value;
	else
	{
		var j = 0;

		for ( var i=0;i<cbCol.length;i++ )
		{
			if ( cbCol[i].checked )
			{
				ret[j] = cbCol[i].value;
				j++;
			}
		}
	}

	return ret;
}

function display(col)
{
	if ( col.style.display == 'none' )
		col.style.display = '';
	else
		col.style.display = 'none';
}

function getOptionText(select)
{
	var i = $(select).selectedIndex; // 取得选择的序列号
	return $(select).options[i].text;  // 取得结果
}

function addOption(List,obj)
{
	//先清空所有下拉项
	obj.length = 0;

	for ( var i=0;i<List.length;i++ )
	{
		//添加条目
		obj.options.add(new Option(List[i].key,List[i].value));
	}
}

String.prototype.len=function()
{   
	return this.replace(/[^\x00-\xff]/g,"**").length;   
}  

function toLogout()
{
	RMT.AjaxProvider.toLogout(toLogout_CallBack);
}

function toLogout_CallBack(retVal)
{
	eval('ret='+retVal.value);
	top.location.replace(ret.returnURL);
}

//弹出新窗?
function DispFun(DetailURL,InWidth,InHeight,scroll)
{
	var inw=InWidth;
	var inh=InHeight;
	window.open(encodeURI(DetailURL),"DispWindow","toolbar=no,location=no,directories=no,z-look=yesstatus=no,menubar=no,scrollbars=" + scroll + ",resizable=no,copyhistory=yes,top=0,left=0,width="+inw+",height="+inh);
	//return false;
}

function setNewsBtn(obj,no,link)
{
	if ( obj.className == 'on' )return;

	for (var i=1;i<=2;i++ )
	{
		$('nb_'+i).className = (i==no)?'on':'';
	}
	$('newslist').src = link;
}

function setCurrentMenu(menuid)
{
	var menus = $('menu').getElementsByTagName('a');

	for ( var i=0;i<menus.length;i++ )
	{
		menus[i].className = (menus[i].id == 'menu_'+menuid)?'on':'';
	}
}

function getUserTopLink()
{
	var myAjax = new Ajax.Request(getLoginStatePage,{method: "get",parameters:'&timeStamp=' + new Date().getTime(),onComplete :setTopLink});
}

function setTopLink(retVal)
{
	$("toplink").innerHTML = retVal.responseText;
}

