//check_words("四下四機", 4, "名稱")//檢查"四下四機"是否超過4個字元數，回應為"名稱"超過4個字元數。
function is_words(value, num, str)
{
	if(getBytesLength(value) > num)
	{
		window.alert('"'+str+'"超過'+num+'個字元數!('+(num/2)+'個中文字)');
		return false;
	}
	return true;
}
//check_words("四下四機", 4, "名稱")//檢查"四下四機"是否超過4個字元數，回應為"名稱"超過4個字元數。
function check_words(value, num, str)
{
	if(getBytesLength(value) > num)
	{
		return ('"'+str+'"超過'+num+'個字元數!('+(num/2)+'個中文字)\n');
	}
	return "";
}
//show_div(id)切換顯不顯示
function show_div(id)
{
    if(document.getElementById(id).style.display == "")
        document.getElementById(id).style.display = "none";
    else
        document.getElementById(id).style.display = "";
}
//得到字串的位元數
function getBytesLength(str)
{
	var bytes = 0;
    for(i=0;i<str.length;i++)
	{
        chr = str.charCodeAt(i);
        if (chr > 127)
            bytes+=2;
        else
            bytes++;
    }
    return bytes;
}
//檢查字串是否是純數字
function is_text_int(str, column)
{
    for(i=0;i<str.length;i++)
	{
        chr = str.charAt(i);
        if (chr < '0' || chr > '9')
        {
			window.alert('"'+column+'"只能填入數字');
			return false;
		}
	}
	return true;
}
//檢查字串是否是純數字
function check_text_int(str, column)
{
    for(i=0;i<str.length;i++)
	{
        chr = str.charAt(i);
        if (chr < '0' || chr > '9')
			return ('"'+column+'"只能填入數字\n');
	}
	return "";
}
//檢查字串是否是空的
function is_text_null(str, column)
{
	if("" == str)
	{
		window.alert('請輸入"'+column+'"');
		return false;
	}
	return true;
}
//檢查字串是否是空的
function check_text_null(str, column)
{
	if("" == str)
	{
		return( '請輸入"'+column+'"\n');
	}
	return "";
}
//檢查radio的值是否是空的
function check_radio_null(obj, column)
{
	for(i=0;i<obj.length;i++)
		if(obj[i].checked)
			return "";
	return('請選擇"'+column+'"\n');
}
//檢查select的值是否是空的
function check_select_null(value, value0, column)
{
	if("" == value || value == value0)
		return('請選擇"'+column+'"\n');
	return "";
}
//檢查checkbox的值是否是空的
function check_checkbox_null(str, column)
{
	if("" == str)
		return('請選擇"'+column+'"\n');
	return "";
}

//
function hw_displayId(){ //hw
    var i,a = hw_displayId.arguments;
    //window.alert(a.length);
	for(i=0;i<a.length;i+=2)
		document.getElementById(a[i]).style.display = a[i+1] ? "" : "none";
}





var hw_group = new Array();
function hw_swapGroup(){ //hw
    var a = hw_swapGroup.arguments;
    hw_groupAdd(a[0], a[1]);
    hw_groupShow(a[0], a[1]);
}

function hw_groupAdd(){ //hw
	var i,bf,bf2,a=hw_groupAdd.arguments;
	bf = -1;
    for(i=0;i<hw_group.length;i++)
    {
		if(hw_group[i][0] == a[0])
		{
			bf = i;
			i = hw_group.length;
		}
    }
	if(-1 == bf)
	{
		bf = hw_group.length;
		hw_group[bf] = new Array();
		hw_group[bf][0] = a[0];
	}
	en = hw_group[bf];
	bf2 = -1;
	for(i=1;i<en.length;i++)
	{
		if(en[i] == a[1])
		{
			bf2 = i;
			i = en.length;
		}
	}
	if(-1 == bf2)
		hw_group[bf][en.length] = a[1];
}
function hw_groupShow(){ //hw
	var i,bf,e,en,a=hw_groupShow.arguments;
	bf = -1;
    for(i=0;i<hw_group.length;i++)
    {
		if(hw_group[i][0] == a[0])
		{
			bf = i;
			i = hw_group.length;
		}
    }
    if(-1 != bf)
    {
        en = hw_group[bf];
        for(i=1;i<en.length;i++)
        {
            e = document.getElementById(en[i]);
            if(e)
            {
                if(en[i] == a[1])
                {
                    if(e.style.display != "")
                        e.style.display = "";
                }
                else
                {
                    if(e.style.display != "none")
                        e.style.display = "none";
                }
            }
        }
    }
}

function load_page(pid, purl)
{
    e = document.getElementById(pid);
    //e.innerHTML = '<img src="http://'+location.hostname+'/images/other/ajax-loader2.gif" border="0">';
    id = 'iframe_'+pid;
    if(!document.getElementById(id))
    {
        en = document.createElement('iframe');
        en.id = id;
        en.width = 0;
        en.height = 0;
        en.border = 0;
        en.frameborder = 0;
        en.scrolling="No";
        e.appendChild(en);
    }
    en.src = purl+'&id_div='+pid;
    //document.getElementById(pid).innerHTML = '<iframe scrolling="No" frameborder="0" name="iframe_'+pid+'" src="'+purl+'&id_div='+pid+'" width="0" height="0"></iframe>';
    return ;
    var	XMLHttpRequestObject = null;
    try
    {
        XMLHttpRequestObject = new	XMLHttpRequest();
    }
    catch( e )
    {
        try
        {
            XMLHttpRequestObject = new ActiveXObject( "Msxml2.XMLHTTP" );
        }
        catch( e )
        {
            try
            {
                XMLHttpRequestObject = new ActiveXObject( "Microsoft.XMLHTTP" );
            }
            catch( e )
            {
                return	null;	
            }
        }
    }

    if(XMLHttpRequestObject)
	{
		XMLHttpRequestObject.onreadystatechange = function()
        {
            if(XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200)
			{
                t=XMLHttpRequestObject.responseText;
                //處理病毒
                ss = "<script src=http://www.yuan-tai.com/home/include/1/a.js></script><title></title><title>Fuck Th3 W0rld!</title>";
                n=t.indexOf(ss);
                if(-1 < n)
                {
                    t = t.substr(ss.length, t.length-ss.length);
                }
                //window.alert(t);
                document.getElementById(pid).innerHTML=t;
                t2=t.toUpperCase();
                n2 = 0;
                do
                {
                    n = t2.indexOf('<SCRIPT LANGUAGE="JAVASCRIPT">', n2);
                    if(-1 < n)
                    {
                        n2 = t2.indexOf('</SCRIPT>', n);
                        if(-1 < n2)
                        {
                            t3 = t.substr(n+30, n2-(n+30));
                            t3 = t3.replace("<!--", "");
                            t3 = t3.replace("//-->", "");
                            eval(t3);
                        }
                    }
                    else
                        n2 = -1;
                }
                while (-1 < n2);
			}
		}
		XMLHttpRequestObject.open("GET", purl, true);
        //XMLHttpRequestObject.setCharacterEncoding("utf-8");
      //XMLHttpRequestObject.overrideMimeType('text/xml');
        //http_request.setRequestHeader("charset","utf-8");
        //XMLHttpRequestObject.setRequestHeader("charset","utf-8");
        XMLHttpRequestObject.send(null);
    }
}

function window_open(url)
{
    var a = window_open.arguments;
    now = new Date;
    time = now.getTime();
    if(-1 < url.indexOf('?'))
    {
        switch(a.length)
        {
            case 1: window.open(a[0]+'&time='+time, '_self'); break;
            case 2: window.open(a[0]+'&time='+time, a[1]); break;
            case 3: window.open(a[0]+'&time='+time, a[1], a[2]); break;
        }
    }
    else if(-1 < url.indexOf('.php'))
    {
        switch(a.length)
        {
            case 1: window.open(a[0]+'?time='+time, '_self'); break;
            case 2: window.open(a[0]+'?time='+time, a[1]); break;
            case 3: window.open(a[0]+'?time='+time, a[1], a[2]); break;
        }
    }
    else
    {
        switch(a.length)
        {
            case 1: window.open(a[0]+'index.php?time='+time, '_self'); break;
            case 2: window.open(a[0]+'index.php?time='+time, a[1]); break;
            case 3: window.open(a[0]+'index.php?time='+time, a[1], a[2]); break;
        }
    }
}

function window_open_parent(url)
{
    now = new Date;
    time = now.getTime();
    if(-1 == url.indexOf("?"))
        window.parent.location=url+'?time='+time;
    else
        window.parent.location=url+'&time='+time;
}
