﻿String.prototype.trim = function()
{
	return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.replaceFirst = function(s1, s2)
{
	var firstposition = this.indexOf(s1);
	if (firstposition == -1) {
		return;
	}
	var output;
	output = this.substring(0, firstposition);
	output += s2;
	output += this.substring(firstposition + s1.length);
	return output;
}
try{document.execCommand("BackgroundImageCache", false, true);}catch(e){}
function resize(that)
{
	try{
	var height = that.scrollHeight+20;
	if (height<200)
	{
		height = 200;
	}
	that.style.height = height;
	}catch(e){}
}
function text_format(that)
{
	var body = "\n"+that.value;
	body = body.replace(/ |　/ig,"");
	body = body.replace(/\r\n/ig,"\n");
	body = body.replace(/\n\n/ig,"\n");
	body = body.replace(/\n\n/ig,"\n");
	body = body.replace(/\n\n/ig,"\n");
	body = body.replace(/\n\n/ig,"\n");
	body = body.replace(/\n/ig,"\n\n");
	body = body.replace("\n\n","");
	that.value=body;
}
function getCookie(namex)
{
	var cookies = document.cookie;
	var cookieHeader = namex + "=";
	var beginPosition = cookies.indexOf(cookieHeader);
	if (beginPosition != -1) 
	{
		var acookie = cookies.substring(beginPosition + cookieHeader.length);
		if (acookie.indexOf(";")>-1)
		{
			acookie = acookie.substring(0, acookie.indexOf(";"));
		}
		return acookie;
	}
	return "";
}
function setCookie( name, value, expires, path, domain, secure ) 
{
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000;
	}
	var expires_date = new Date( today.getTime() + (expires) );  
	document.cookie = name + '=' + escape( value ) +   
	( ( expires ) ? ';expires=' + expires_date.toGMTString() : '' ) + //expires.toGMTString()   
	( ( path ) ? ';path=' + path : '' ) +      
	( ( domain ) ? ';domain=' + domain : '' ) +    
	( ( secure ) ? ';secure' : '' ); 
} 
function clogin()
{
	if (getCookie("x_username")!=""&&getCookie("x_password")!="")
	{
		return true;
	}
	return false;
}
function not()
{
	return true;
}
function removejs(obj)
{
	var childs = obj.childNodes;
	for (i=0;i<childs.length;i++)
	{
		var tagname = childs[i].tagName;
		if (tagname!=null&&childs[i]!=obj)
		{
			childs[i].onabort = new Function("not()");
			childs[i].oninput = new Function("not()");
			childs[i].onblur = new Function("not()");
			childs[i].onchange = new Function("not()");
			childs[i].onclick = new Function("not()");
			childs[i].ondblclick = new Function("not()");
			childs[i].onerror = new Function("not()");
			childs[i].onfocus = new Function("not()");
			childs[i].ondblclick = new Function("not()");
			childs[i].onkeydown = new Function("not()");
			childs[i].onkeypress = new Function("not()");
			childs[i].onkeyup = new Function("not()");
			childs[i].onload = new Function("not()");
			childs[i].onmousedown = new Function("not()");
			childs[i].onmousemove = new Function("not()");
			childs[i].onmouseout = new Function("not()");
			childs[i].onmouseover = new Function("not()");
			childs[i].onmouseup = new Function("not()");
			childs[i].onreset = new Function("not()");
			childs[i].onresize = new Function("not()");
			childs[i].onselect = new Function("not()");
			childs[i].onsubmit = new Function("not()");
			childs[i].onunload = new Function("not()");
			childs[i].onpropertychange = new Function("not()");		
			removejs(childs[i]);	
		}
	}
}
function getDate()
{
	var d = new Date()
	var vYear = d.getFullYear()
	var vMon = d.getMonth() + 1
	var vDay = d.getDate()
	var sb = "";
	sb += (vYear)
	sb += ("-")
	sb += (vMon<10 ? "0" + vMon : vMon)
	sb += ("-")
	sb += (vDay<10 ?  "0"+ vDay : vDay )
	return sb;
}
function getDateTime()
{
	var d = new Date();
	var vYear = d.getFullYear();
	var vMon = d.getMonth() + 1;
	var vDay = d.getDate();
	var vHour = d.getHours();
	var vMinute = d.getMinutes();
	var vSecond = d.getSeconds();
	var sb = "";
	sb += (vYear);
	sb += ("-");
	sb += (vMon<10 ? "0" + vMon : vMon);
	sb += ("-");
	sb += (vDay<10 ?  "0"+ vDay : vDay );
	sb += (" ");
	sb += (vHour<10 ?  "0"+ vHour : vHour );
	sb += (":");
	sb += (vMinute<10 ?  "0"+ vMinute : vMinute );
	sb += (":");
	sb += (vSecond<10 ?  "0"+ vSecond : vSecond );
	return sb;
}
function getSmallDateTime()
{
	var d = new Date();
	var vMon = d.getMonth() + 1;
	var vDay = d.getDate();
	var vHour = d.getHours();
	var vMinute = d.getMinutes();
	var sb = "";
	sb += (vMon<10 ? "0" + vMon : vMon);
	sb += ("-");
	sb += (vDay<10 ?  "0"+ vDay : vDay );
	sb += (" ");
	sb += (vHour<10 ?  "0"+ vHour : vHour );
	sb += (":");
	sb += (vMinute<10 ?  "0"+ vMinute : vMinute );
	return sb;
}
function setAd2(ad)
{
	try
	{
		document.getElementById(ad).appendChild ( document.getElementById(ad+"s") );
		document.getElementById(ad+"s").style.display = "";
	}
	catch(e)
	{}
}
function setAd(ad)
{
	try
	{
		document.getElementById(ad).innerHTML = document.getElementById(ad+"s").innerHTML;
	}
	catch(e)
	{}
}
function str_len(txt)
{
	txt = txt.replace(/(<.*?>)/ig,'');
	txt = txt.replace(/([\u0391-\uFFE5])/ig,'11');
	var count = txt.length/2;
	return count;
}
function fcDecode(str)
{
	return decodeURIComponent(str);
}
function checkSilverlight()
{
	var isSilverlightInstalled = false;
	try 
	{
		try 
		{
			var slControl = new ActiveXObject('AgControl.AgControl'); //IE
			isSilverlightInstalled = true;
		}
		catch(e) 
		{
			if(navigator.plugins["Silverlight Plug-In"]) //OTHER
			{
				isSilverlightInstalled = true;
			}
		}
	}
	catch(e){}
	return isSilverlightInstalled;
}
function loadHtml(f, method, url)
{
	var http;
	try
	{
		http = new XMLHttpRequest();
	}
	catch(e)
	{
		http = new ActiveXObject( "Microsoft.XMLHTTP" );
	}
	try
	{
		http.open(method, url, true);
		http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		http.onreadystatechange = function () 
		{
			if (http.readyState == 4)
			{
				if(http.status==200)
				{
					var text = http.responseText.trim();
					f(text);
					text = null;
				}
				else
				{
				}
				http = null;
			}
		}
		http.send('');
	}
	catch(e)
	{
		window.status = e.message;
	}
}
function getPosLeft(obj) 
{ 
	var l = obj.offsetLeft; 
	while(obj = obj.offsetParent) 
	{ 
		l += obj.offsetLeft; 
	} 
	return l; 
}
function getPosTop(obj) 
{ 
	var l = obj.offsetTop; 
	while(obj = obj.offsetParent) 
	{ 
		l += obj.offsetTop; 
	} 
	return l; 
}
function clearAuthenticationCache(page) 
{
	if (document.all)
	{
		document.execCommand("ClearAuthenticationCache");
		document.location.href = page;
	}
	else
	{
		var f = function(txt) 
		{
			document.location.href = page;
		}
		loadHtml(f, "GET", "https://logout:logout@"+document.location.host);
	}
}
Function.prototype.bindNode=function(oNode){  
    var foo=this,iNodeItem  
    if(window.__bindNodes==null)  
        __bindNodes=[]  
    __bindNodes.push(oNode)  
    iNodeItem=__bindNodes.length-1  
    oNode=null  
    return function(e){  
        foo.call(__bindNodes[iNodeItem],e||event)  
    }  
}  
function bind(object, event, callback)
{
	if (document.all)
	{
		object.attachEvent("on"+event, callback.bindNode(object));
	}
	else
	{
		object.addEventListener(event, callback.bindNode(object), false);
	}
}
function unbind(object, event)
{
	eval("object.on"+event+"='';");
}
function find_count(str, s1) {
	var count = 0;
	var fromindex = -1;
	while ((fromindex = str.indexOf(s1, fromindex + 1)) > -1) {
		count++;
	}
	return count;
}
function loadJs(url, callback, params)
{
	var script = document.createElement("script");
	script.src = url;
	if (callback)
	{
		if (script.readyState)
		{  //IE   
			script.onreadystatechange = function()
			{   
				if (script.readyState == "loaded" || script.readyState == "complete")
				{   
					if (params)
					{
						eval("callback("+params+");");   
					}
					else
					{
						callback();
					}
					script.parentNode.removeChild(script);
					script = null;
				}   
			};   
	    } else {  //Others   
			script.onload = function()
			{  
				if (params)
				{
					eval("callback("+params+");");   
				}
				else
				{
					callback();
				}
				script.parentNode.removeChild(script);
				script = null;
			};   
		} 
	}  
	document.getElementsByTagName('head')[0].appendChild(script);
}
function detect_flash_version()   
{  
    var ua = navigator.userAgent.toLowerCase();  
    var flash_version = 0;  
      
    if (navigator.plugins && navigator.plugins.length)   
    {  
    	for (var i in navigator.plugins) {
    		var plugin = navigator.plugins[i];
    		if (plugin.name=="Shockwave Flash") {
    			return parseInt(plugin.description.split(" ")[2]);
    		}
    	}
    	var plugins = navigator.plugins;
        var p = navigator.plugins['Shockwave Flash'];
        if (typeof p == 'object')   
        {  
            for (var i = 10; i >= 3; i--)   
            {  
                if (p.description && p.description.indexOf(' ' + i + '.') != -1) { flash_version = i; break; }  
            }  
        }  
    }  
    else if (ua.indexOf("msie") != -1 && ua.indexOf("win")!=-1 && parseInt(navigator.appVersion) >= 4 && ua.indexOf("16bit")==-1)   
    {  
        for (var i = 10; i >= 2; i--)  
        {  
            try  
            {  
                var object = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + i + "');");  
  
                if (object)  
                {  
                    flash_version = i;  
  
                    break;  
                }  
            }  
            catch (e) {}  
        }  
    }  
    else if (ua.indexOf("webtv/2.5") != -1) flash_version = 3;  
    else if (ua.indexOf("webtv") != -1) flash_version = 2;  
  
    return flash_version;  
}  
