﻿// JScript File

if(!Array.prototype.splice)
{
    Array.prototype.splice = function(a,b)
    {
        var tmp=[];
        for(var i=a+b;i<this.length;i++)
        {
            tmp[tmp.length]=this[i];
        }
        var rem=[];
        for(i=a;i<a+b;i++)
        {
            rem[rem.length]=this[i];
        }
        this.length=a;
        for(i=2;i<arguments.length;i++)
        {
            this[this.length]=arguments[i];
        }
        for(i=0;i<tmp.length;i++)
        {
            this[this.length] = tmp[i];
        }
        return rem;
    }
}
String.prototype.trim = function()
{
	return this.replace(/(^[ |　]*)|([ |　]*$)/g, "");
}

String.prototype.getQuery = function(name)
{
	var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
	var r = this.substr(this.indexOf("\?")+1).match(reg);
	if(r!=null)
	{
		return unescape(r[2]);
	}
	return null;
}
String.prototype.cn_length = function()
{
	var i, sum;
	sum = 0;
	for(i=0; i < this.length; i++)
	{
		sum ++;
		if (this.charCodeAt(i) > 255)
		{
	  		sum ++;
	  	}
	}
	return sum;
}
function setCopy(_sTxt)
{
	try {
		clipboardData.setData('Text',_sTxt)
		return true;
	}
	catch(e){
		return false;
	}
}
function $(s)
{
	if(document.getElementById)
	{
		return document.getElementById(s);
	}
	else
	{
		return document.all[s];
	}
}
function $n(s, o)
{
	if (o == null)
	{
		return document.getElementsByName(s);
	}
	else
	{
		return o.getElementsByName(s);
	}
}
function $t(s, o)
{
	if (o == null)
	{
		return document.getElementsByTagName(s);
	}
	else
	{
		return o.getElementsByTagName(s);
	}
}
function $$(s)
{
	return document.frames?document.frames[s]:$(s).contentWindow;
}
function $c(s)
{
	return document.createElement(s);
}
function $ct(s)
{
    return document.createTextNode(s);
}
function exist(s)
{
	return s != null;
}
function dw(s)
{
	document.write(s);
}
function hidden(obj)
{
	obj.style.display = (obj.style.display == 'none') ? '' : 'none';
}
function block(obj)
{
	obj.style.display = "block";
}

function getXY(obj)
{
	var o		= new Object();
	o.left		= 0;
	o.top		= 0;
	o.right		= 0;
	o.bottom		= 0;
	var oWidth	= obj.offsetWidth;
	var oHeight	= obj.offsetHeight;
	while(obj)
	{
		o.left += obj.offsetLeft;
		o.top += obj.offsetTop;
		obj = obj.offsetParent;
	}
	o.right = o.left + oWidth;
	o.bottom = o.top + oHeight;
	return o;
}
function isNull(_sVal)
{
	return (_sVal === "" || _sVal == null || _sVal == "undefined");
}
function removeNode(s)
{
	if(exist(s))
	{
		s.innerHTML = '';
		s.removeNode?s.removeNode():s.parentNode.removeChild(s);
	}
}

function str2ascJS(str)
{
	if(str.length > 0)
	{
		return str.charCodeAt(0).toString(16);
	}
}

function asc2strJS(asc)
{
	return String.fromCharCode(asc);
}
function UrlEncode(str){ 
  var ret=""; 
  var strSpecial="!\"#$%&'()*+,/:;<=>?[]^`{|}~%"; 
  for(var i=0;i<str.length;i++){ 
   var chr = str.charAt(i); 
    var c=str2asc(chr); 
    tt += chr+":"+c+"n"; 
    if(parseInt("0x"+c) > 0x7f){ 
      ret+="%"+c.slice(0,2)+"%"+c.slice(-2); 
    }else{ 
      if(chr==" ") 
        ret+="+"; 
      else if(strSpecial.indexOf(chr)!=-1) 
        ret+="%"+c.toString(16); 
      else 
        ret+=chr; 
    } 
  } 
  return ret; 
} 
function UrlDecode(str){ 
  var ret=""; 
  for(var i=0;i<str.length;i++){ 
   var chr = str.charAt(i); 
    if(chr == "+"){ 
      ret+=" "; 
    }else if(chr=="%"){ 
     var asc = str.substring(i+1,i+3); 
     if(parseInt("0x"+asc)>0x7f){ 
      ret+=asc2str(parseInt("0x"+asc+str.substring(i+4,i+6))); 
      i+=5; 
     }else{ 
      ret+=asc2str(parseInt("0x"+asc)); 
      i+=2; 
     } 
    }else{ 
      ret+= chr; 
    } 
  } 
  return ret; 
} 
function AddLoadEvent(func)
{
    var oldload = window.onload;
    if(typeof window.onload != 'function')
    {
        window.onload = func;
    }
    else
    {
        window.onload = function()
        {
            oldload();
            func();
        }
    }
}