function $(id)
{
	return document.getElementById(id);
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

// Takakaira Js Object
// exsample: TK.bAllowPreviewFunction
function __takakaira()
{
	var agid = navigator.userAgent.toLowerCase();
	var pathUrl = window.location.href.toLowerCase();
	this.bIsIE = (agid.indexOf("msie") != -1);
	this.bIsGecko = (agid.indexOf("gecko") != -1);
	this.bIsFirefox = (agid.indexOf("firefox") != -1);
	this.browser_version = parseInt(navigator.appVersion);
	this.bAllowCopy = false;
	this.bAllowPreviewFunction = false;	// for admin see new Function
	this.oContextMenu = document.oncontextmenu;
	this.oClick = document.onclick;
	this.oMousedown = document.onmousedown;
	this.oMouseup = document.onmouseup;
	this.oMousedown = document.onmousedown;
	/*this.oEventArgInZero = function()
	{
		var event = window.event || arguments.callee.caller.arguments[0];
		return window.event || arguments.callee.caller.arguments[0];
	}*/

	if ( typeof(ClientIPAddress) != "undefined")
	{
		if (ClientIPAddress.indexOf("127.0.0.") != -1
			|| ClientIPAddress.indexOf("210.72.226.") != -1
			|| ClientIPAddress.indexOf("219.74.184.") != -1
			|| ClientIPAddress.indexOf("202.156.13.") != -1
			|| ClientIPAddress.indexOf("203.81.35.") != -1
			|| ClientIPAddress.indexOf("121.6.92.") != -1
			|| ClientIPAddress.indexOf("121.7.245.") != -1
			|| ClientIPAddress.indexOf("116.14.26.") != -1

			|| ClientIPAddress.indexOf("202.156.13.") != -1
			|| ClientIPAddress.indexOf("219.74.172.") != -1
			|| ClientIPAddress.indexOf("218.212.108.") != -1
			)
		{
			this.bAllowPreviewFunction = true;
		}
	}

	if (!this.bIsIE)
	{
		//*** Importance !!! ***
		// This Function attachEvent not compatible n2CoreLibs-events File
		if (pathUrl.indexOf('advsearchlist.aspx') != -1
				&& pathUrl.indexOf('part.aspx') != -1
				)
		{
			// added Function : attachEvent
			Object.prototype.attachEvent = function(m,func)
			{
				if(!this[m])
				{
					this[m] = func;
				}
				else
				{
					this[m] = this[m].attach(func);
				}
			}
			Function.prototype.attach=function(func)
			{
				var f = this;
				return function()
				{
					f();
					func();
				}
			}
			// end
		}

		// added Function : outerHTML
		if(typeof(HTMLElement)!="undefined" && !window.opera) 
		{
			HTMLElement.prototype.__defineGetter__("outerHTML",function()
			{
				var a=this.attributes, str="<"+this.tagName, i=0;for(;i<a.length;i++)
				if(a[i].specified)
					str+=" "+a[i].name+'="'+a[i].value+'"';
				if(!this.canHaveChildren)
					return str+" />";
				return str+">"+this.innerHTML+"</"+this.tagName+">";
			});
			HTMLElement.prototype.__defineSetter__("outerHTML",function(s)
			{
				var r = this.ownerDocument.createRange();
				r.setStartBefore(this);
				var df = r.createContextualFragment(s);
				this.parentNode.replaceChild(df, this);
				return s;
			});
			HTMLElement.prototype.__defineGetter__("canHaveChildren",function()
			{
				return !/^(area|base|basefont|col|frame|hr|img|br|input|isindex|link|meta|param)$/.test(this.tagName.toLowerCase());
			});
		}
		// end
	}
	
	this.__webPath = window.location.protocol + "://" + window.location.hostname;
	this.gotoURLByReplace = function (filepath)
	{
		if (this.bIsIE)
		{
			window.location.replace(this.__webPath + filepath);
		}
		else
		{
			window.location.replace(filepath);
		}
	}
	
	this.closeCurrentWindow = function ()
	{
		window.opener=null;window.open('','_self');window.close();
	}

	this.buildCommonFont = function ()
	{
		var sTags = "";
		sTags += '<lin'+'k hr'+'ef="'+"/Include/CommonFont.css"+'" type="text/css" rel="stylesheet">';
		document.write(sTags);
	}
}
// Global Object
TK = new __takakaira();
TK.buildCommonFont();



/* JazConvert */
var pre='%3Cbr%3E'; var post=''; function jazconvert(amount) { document.write(pre + 'JPY&nbsp;' + eval(amount) + post); } function jazlink() {document.write(arguments[0]);} function visitorCurrency() {return('JPY');} function visitorCurrency2() {return('JP');} function visitorCurrencyName() {return('Yen');} function visitorCurrencySymbol() {return('&#165;');} function reconvert() { }

// reference pre;
function toConvertPrice(objId)
{
	var separator, printbase, convpre;
	var object, target, source;
	var items, newitems, contents, value;
	separator = "\n";
	printbase = 1;	// synchronization cur.js?printbase=1
	convpre = "<BR>";	// synchronization cur.js?pre=%3Cbr%3E

	object = document.getElementById(objId);
	target = object.childNodes[0];
	source = object.childNodes[1];

	if (TK.bIsIE)
	{
		items = source.innerHTML.split(separator);

		if (items[2].indexOf(convpre) >= 0)
		{
			contents = items[2].split(convpre);
			value = contents[0] + convpre + contents[2];
		}
		else
		{
			newitems = items[2].split(pre);
			value = pre + newitems[1];
		}
	}
	else
	{
		items = source.innerHTML.split("JP");
		var txt = getCanSplitStringByFirefox(items[items.length - 1], separator);

		items = txt.split(separator);
		value = "JP" + items[0];// + "<br>" + items[1];
	}

	target.innerHTML = value;
}

function getCanSplitStringByFirefox(txt, separator)
{
	var startNum = false;
	var curCharAllow = false;
	var val = txt.split('');
	var newTxt = "";
	for(var c=0; c < val.length; c++)
	{
		curCharAllow = false;
		if (val[c] == '0' || val[c] == '1' || val[c] == '2' || val[c] == '3' || val[c] == '4' 
			|| val[c] == '5' || val[c] == '6' || val[c] == '7' || val[c] == '8' || val[c] == '9'
			)
		{
			startNum = true;
			curCharAllow = true;
		}
		if (startNum && !curCharAllow && val[c] != ',')
		{
			newTxt += separator;
		}
		newTxt += val[c];
	}
	return newTxt;
}
/* end JazConvert */

var cookieEnabled=(navigator.cookieEnabled)? true : false

if (!cookieEnabled)
{
	var curwindow=window;
	while(curwindow.frameElement!=null)
	{
		curwindow=curwindow.parent;
	}
	if (window.location.href.toLowerCase().indexOf("/cookiespec") == -1)
	{
		curwindow.location.href="/CookieSpec.aspx";;
	}
}
function StoreCurrency(cell)
{
	alert(getObject('dgParts').innerHTML);

}

var text;

function getObject(sName)
{
	if (TK.bIsIE)
	{
		return eval('document.all.' + sName);
	}
	else
	{
		return document.getElementById(sName);
	}
}
    
function findObject(sName)
{
	for (var i = 0; i < document.all.length; i++)
	{
		if (document.all[i].id.indexOf(sName) > 0)
		{
			return document.all[i];
		}
	}
}

function urlencode(strText)
{                             
	        var isObj;
            var trimReg;

            if( typeof(strText) == "string" ) {
				if( strText != null )
				{
	                trimReg = /(^\s+)|(\s+$)/g;
                    strText = strText.replace( trimReg, '');
                    
                    for(i=32;i<256;i++)
                    {               
						strText = strText.replace(String.fromCharCode(i),escape(String.fromCharCode(i)));                                                                 
                    }
				}
            }          
            return strText;
}

function popup(location,winName,fScreen,tBar,stat,mBar,sBars,resize,direc,loc,cHist,wid,hgt){
	/*
		Function for popping up windows
		location: URL to open (value String)
		winName: Name of window popup (value String)
		fScreen: If popup is fullscreen (value yes|no)
		tBar: If toolbar is present (value yes|no)
		stat: If status bar is present (value yes|no)
		mBar: If menu bar is present (value yes|no)
		sBar: If scrollbars is present (value yes|no)
		resize: If window is resizable (value yes|no)
		direc: Unknown to find out (value yes|no)
		loc: If location bar is present (value yes|no)		
		cHist: Unknown to find out (value yes|no)
		wid: Width of window (value Integer)
		hgt: Height of window (value Integer)
	*/
	attrib="fullscreen=" + fScreen +",toolbar=" + tBar +",status=" + stat + ",menubar=" + mBar + ",scrollbars=" + sBars + ",resizable=" + resize + ",directories=" + direc + ",location=" + loc + ",copyhistory=" + cHist + ",width=" + wid + ",height=" + hgt
	window.open(location, winName, attrib)
}

function ChangeButtonWidth()
{
	try
	{
		var ipt = document.getElementsByTagName("INPUT");
		for (i = 0; i < ipt.length; i ++)
		{
			if (ipt[i].type.toLowerCase() == "button")
			{
				ipt[i].style.backgroundColor = "#D4D0C9";
			}
			if (ipt[i].className == "inputbox1")
			{
				var v = ipt[i].style.width;
				if (v && v != "")
				{
					v = v.replace("px", "");
					v = parseInt(v) + 40;
					ipt[i].style.width = v + "px";
				}
			}
		}
	}
	catch (e){}
}

var myimages=new Array();
function preloadimages()
{
	for (i=0;i<preloadimages.arguments.length;i++)
	{
		myimages[i]=new Image()
		myimages[i].src=preloadimages.arguments[i]
	}
}


// using copyright.js, copyrightByAction.js
function PageCompletedCallBack()
{
	if (TK.bIsIE)
	{
	}
	else
	{
		fixedFlashEmbedOfFirefox();
	}

	// using of Jaz Currency
	//fixedJazCurrencyOpenError();
	fixedJazChangeClickEvent();
}


function fixedJazChangeClickEvent()
{
	if ('undefined' != typeof cuzChangeClickEvent)
	{
		cuzChangeClickEvent();
	}
}

// see copyright.js, copyright***.js
function fixedJazCurrencyOpenError()
{
	try
	{
		// 1. refresh
		var jazHref = document.getElementsByTagName("A")
		for (i = 0, k = jazHref.length; i < k; i ++)
		{
			if (jazHref[i].href && jazHref[i].href.indexOf("openCurrencyWindow") != -1)
			{
				var openCode = jazHref[i].href;
				openCode = openCode.replace("javascript:onClick=", "");
				jazHref[i].href = "javascript:void(0);" + openCode + ";checkingJazCurrencyWindowClosed(true);";
			}
		}
	}
	catch (e){}
}
function checkingJazCurrencyWindowClosed(timeout)
{
	try
	{
		if (timeout)
		{
			window.setTimeout("checkingJazCurrencyWindowClosed(false);", 300);
		}
		else
		{
			// checking
			if (objWindowCurrency 
				&& typeof(objWindowCurrency) == 'object' 
				&& objWindowCurrency.closed == true
				)
			{
				//window.setTimeout("self.location = self.location;", 100);
			}
			else
			{
				window.setTimeout("checkingJazCurrencyWindowClosed(false);", 300);
			}
		}
	}
	catch (e){}
}

function fixedFlashEmbedOfFirefox()
{
	// for Firefox Flash Embed
	var __objs = document.getElementsByTagName("OBJECT");
	for (i = 0; i < __objs.length; i ++)
	{
		var index = 0;
		for (j = 0; j < __objs[i].childNodes.length; j ++)
		{
			var movie = __objs[i].childNodes[index];
			var embed = __objs[i].childNodes[j];
			if (embed.toString().indexOf('HTMLParamElement') != -1 && embed.name.toLowerCase() == 'movie')
			{
				index = j;
			}
			else if (embed.toString().indexOf('HTMLEmbedElement') != -1 && index != 0)
			{
				if (movie.value.indexOf("?") != -1)
				{
					embed.setAttribute("src", movie.value + "&x=" + Math.random());
				}
				else
				{
					embed.setAttribute("src", movie.value + "?x=" + Math.random());
				}
			}
		}
		__objs[i].outerHTML = __objs[i].outerHTML;
	}
}

// for all page, load complete, set to focus
function documentOnPropertyChange()
{
	if (document && document.readyState == "complete")
	{
		if (top.location.href == window.location.href || window.location.href.toLowerCase().indexOf("/part.aspx") > -1)
		{
			// only use in copyright.js and copyrightAction.js
			//window.focus();
		}
	}
	else
	{
		setTimeout("documentOnPropertyChange();", 1000);
	}
}

setTimeout("documentOnPropertyChange();", 1000);

/*
	using for images, flash, etc...

	<span id="A0" attr="A">xxx</span>
	displaySpanObject('A1', 'A');
*/
function displaySpanObject(showId, attrId)
{
	var eles = document.getElementsByTagName("SPAN");
	for (i = 0; i < eles.length; i ++)
	{
		if (eles[i].getAttribute("attr") && eles[i].getAttribute("attr") == attrId)
		{
				eles[i].style.display = 'none';
		}
	}
	document.getElementById(showId).style.display = '';
}

var _objectIdsNameColl = "";
function hideObject(ids)
{
	var id = "";
	if (ids.indexOf(",") == -1)
	{
		id = ids;
		document.getElementById(id).style.display = 'none';
	}
	else
	{
		var idss = ids.split(",");
		for (i = 0; i < idss.length; i ++)
		{
			document.getElementById(idss[i]).style.display = 'none';
		}
	}
}
function showObject(ids)
{
	var id = "";
	if (ids.indexOf(",") == -1)
	{
		id = ids;
		document.getElementById(id).style.display = '';
	}
	else
	{
		var idss = ids.split(",");
		for (i = 0; i < idss.length; i ++)
		{
			document.getElementById(idss[i]).style.display = '';
		}
	}
}



