﻿// 共通関数クラス.
function Common()
{
	this.MODELINE			= "MeasureLine";		// 定数　距離計測.
	this.MODEAREA			= "MeasureArea";		// 定数　面積計測.
	this.MODEMEMO			= "Memo";						// 定数　メモ.
	this.MODEMEASURE	= "Measure";				// 定数　計測.

	this.IE6					= 1;
	this.FOX2					= 2;
	this.NN7					= 3;
	this.OP9					= 4;
	this.SF3					= 5;
	this.OTHER				= -1;
	

	// 指定したオブジェクト内の指定した子オブジェクトを取得する.
	// parentObj	対象オブジェクト.
	// childId		子オブジェクトID.
	this.GetChildNode = function(parentObj, childId)
	{
		if (parentObj == null)
		{
			return null;
		}
		
		childObj = null;
		for(i = 0; i < parentObj.childNodes.length; i++) 
		{
			childObj = parentObj.childNodes[i];
			
			if (childObj != null )
			{
				if (childObj.id ==  childId)
				{
					return childObj;
				}
			}
		}
		return null;
	}

	// キーコード削除.
	this.ClearKeyCode = function(e)
	{
		
		if (e != null) 
		{
			ctrl = typeof e.modifiers == 'undefined' ? e.ctrlKey : e.modifiers & Event.CONTROL_MASK; 
			shift = typeof e.modifiers == 'undefined' ? e.shiftKey : e.modifiers & Event.SHIFT_MASK; 
			if (ctrl || shift)
			{
				currentDocument.KeycodeCancel = true;
				return;
			}
			
			keycode = e.which; 
			if (keycode != 46)
			{
				currentDocument.KeycodeCancel = true;
			}
		}
		else
		{
			if (event.ctrlKey)
			{
				currentDocument.KeycodeCancel = true;
				return;
			}
		
			switch(event.keyCode)
			{
				//shift
				case 16:
					currentDocument.KeycodeCancel = true;
					break;
				//del
				case 46:
					break;
				default:
					//event.keyCode = 0;
					currentDocument.KeycodeCancel = true;
					break;
			}
		}
	}
	
	// バイト数取得.
	this.getByte=function(text)
	{
		var count = 0;
		for (i=0; i<text.length; i++)
		{
			n = escape(text.charAt(i));
			if (n.length < 4) count++; else count+=2;
		}
		return count;
	}
	
	// キーコード変換.
	this.GetKeyCode = function(e)
	{
		var keyCode
		if(document.all)
		{
			keyCode = event.keyCode;
		}           
    else if(document.getElementById)
		{
			keyCode = (e.keyCode!=0)?e.keyCode:e.charCode;
		}
    else if(document.layers)
    {
			keyCode = e.which;
    }
    return keyCode;
	}
	
	// XMLの読み込み.
	this.ReadXmlDocument = function(fileName)
	{
		var xmlDoc = null;
		
		if (document.implementation.createDocument)
		{
			xmlDocument = document.implementation.createDocument("", "data", null);
			xmlDocument.load(fileName);
		}
		else
		{
			xmlDocument = new ActiveXObject("Microsoft.XMLDOM");
			xmlDocument.async = false;
			xmlDocument.load(fileName);
		}
		return xmlDoc;
	}
	
	// ノードテキストの取得.
	this.GetNodeText = function(node)
	{
		var text = "";
		
		if(document.all)
		{
			text = node.text;
		}           
    	else if(document.getElementById)
		{
			text = node.textContent;
		}
		
		return text;
	}
	
	// Windowチェック関数.
	this.CheckWindowClosed = function(windowObject)
	{
		var ua = navigator.userAgent;
	  if( !!windowObject )
	  {
	    if( ( ua.indexOf('Gecko')!=-1 || ua.indexOf('MSIE 4')!=-1 )
	      && ua.indexOf('Win')!=-1 ) 
	    {
				return windowObject.closed;
	    }
	    else
	    {
				return typeof windowObject.document != 'object';
			}
	  }
	  else
	  {
			return true;
		}
	}
	
		// ブラウザチェック.
	this.CheckBrowser = function()
	{
		var version = common.OTHER;
		
		if(navigator.userAgent.indexOf("MSIE")!=-1)
		{
			var IEVersion=/*@cc_on function(){ switch(@_jscript_version){ case 1.0:return 3; case 3.0:return 4; case 5.0:return 5; case 5.1:return 5; case 5.5:return 5.5; case 5.6:return 6; case 5.7:return 7; case 5.8:return 8;}}()||@*/0;
			
			if (parseInt(IEVersion) >= 6)
			{
				version = common.IE6;
			}
		}
		else if(navigator.userAgent.indexOf("Firefox") > -1)
		{
			if(navigator.userAgent.indexOf("Firefox/2") > -1)
			{
				version = common.FOX2;
			}
		}
		else if(navigator.userAgent.indexOf("Netscape") > -1)
		{
			if(navigator.userAgent.indexOf("Netscape/7") > -1)
			{
				version = common.NN7;
			}
		}
		else if(navigator.userAgent.indexOf("Opera") > -1)
		{
			if(navigator.userAgent.indexOf("Opera/9") > -1)
			{
				version = common.OP9;
			}
		}
		else if(navigator.userAgent.indexOf("Safari") > -1)
		{
			if(navigator.userAgent.indexOf("Version/3") > -1)
			{
				version = common.SF3;
			}
		}
		
		return version;
	}
	
	// クリップボードにコピー.
	// FireFoxはセキュリティーの問題でFlashを使用.
	this.SetClipboard = function(text)
	{
		if (text.length > 0)
		{
			var version = common.CheckBrowser();
			
			if (version == common.IE6)
			{
				clipboardData.setData("Text", text);
			}
			else if (version == common.FOX2)
			{
				document.getElementById('copy').innerHTML = "";
				var swf = "<embed src='MapForm/setClipboard.swf' FlashVars='code="+encodeURIComponent(text)+"' width='0' height='0' type='application/x-shockwave-flash'></embed>";
				document.getElementById('copy').innerHTML = swf;
			}
		}
	}
	
}

Number.prototype.d=function(wide)
{
　return String(Math.pow(10,wide)+this).slice(1);
}

// ステータス非表示イベント設定.
function StatusHide(){
		var anchor = document.getElementsByTagName('a');
		var func = 'hide(); return true;';
		for(var i=0; i<anchor.length ;i++)
		{
			addEventListener(anchor[i], 'mouseover', new Function(func));
			addEventListener(anchor[i], 'focus', new Function(func));
		}
}

// ステータス非表示.
function hide(){
		window.status = '';
}

// イベントリスナー追加.
function addEventListener(target, type, func) 
{
	if(target.attachEvent) {
	  target.attachEvent("on" + type, func);
	} else if(target.addEventListener) {
	  target.addEventListener(type, func, false);
	} else {
	  target["on" + type] = func;
	}
}
