// ///////////////////////////////////////////////////////////////////////////////////////
// for XML Http
// ///////////////////////////////////////////////////////////////////////////////////////
// create XMLHttpRequest object
function createHttpRequest(){
  if(window.ActiveXObject){
    // for Windows IE 
    try {
            return new ActiveXObject("Msxml2.XMLHTTP") ;
        } catch (e) {
            try {
                return new ActiveXObject("Microsoft.XMLHTTP") ;
            } catch (e2) {
                return null;
            }
         }
    } else if(window.XMLHttpRequest){

        return new XMLHttpRequest(); // not a Windows IE
    } else {
        return null;
    }
}

function DBFeed( postData, objDiv, PHPFile)
{
	// create XMLHttpRequest object
	var ajax = createHttpRequest();

	ajax.open( "POST", PHPFile);

	ajax.onreadystatechange = function() { 
		if (ajax.readyState == 4) { 
			var obj = document.getElementById( objDiv );
			obj.innerHTML = ajax.responseText;
		}
	}

	//send 
	ajax.setRequestHeader("Content-Type" , "application/x-www-form-urlencoded;");
	ajax.send(postData);
}

function setCopyright() {
	var obj = document.getElementById("copyright");
	var str ='';
	str = 'Copyright (c) 2006-2009 Japan Science and Technology Agency. All Rights Reserved';

	obj.innerHTML = str;
}

// *********************************************************************************
// * function name : JST Library for Editor
// *********************************************************************************
function JSTLib() {
	this.SelFontSize = '2';
	try {
	}
	catch(e) {
		
	}
}
JSTLib.prototype = {
	SelFontSize: '2',
	
	createEditBox : function(strMsgEdit){
		var strHTML = '';

		var objMsgEdit = document.getElementById(strMsgEdit);

		if (document.all) {
			var oPD = document.createElement('div');
			oPD.setAttribute('id', 'paintdecoration');
			oPD.style.cssText = 'top:0px;left:0px;width:550px;height:32px;background-color:#F8F8EE';

			strHTML  = '<div style="height:32px;background-color:#F8F8EE"><table><tr><td height="1px"></td></tr></table>';
			strHTML += '<img src="./imgs/btn_editor1.gif" title="Bold" style="cursor:pointer;" onclick="if (' + strMsgEdit + 'MsgArea.isContentEditable==true) document.execCommand(\'Bold\');">&nbsp;';
			strHTML += '<img src="./imgs/btn_editor2.gif" title="Italic" style="cursor:pointer;" onclick="if (' + strMsgEdit + 'MsgArea.isContentEditable==true) document.execCommand(\'Italic\');">&nbsp;';
			strHTML += '<img src="./imgs/btn_editor3.gif" title="Underline" style="cursor:pointer;" onclick="if (' + strMsgEdit + 'MsgArea.isContentEditable==true) document.execCommand(\'Underline\');">&nbsp;&nbsp;&nbsp;&nbsp;';

			strHTML += '<img src="./imgs/btn_editor4.gif" title="Left" style="cursor:pointer;" onclick="if (' + strMsgEdit + 'MsgArea.isContentEditable==true) document.execCommand(\'JustifyLeft\');">&nbsp;';
			strHTML += '<img src="./imgs/btn_editor5.gif" title="Center" style="cursor:pointer;" onclick="if (' + strMsgEdit + 'MsgArea.isContentEditable==true) document.execCommand(\'JustifyCenter\');">&nbsp;';
			strHTML += '<img src="./imgs/btn_editor6.gif" title="Right" style="cursor:pointer;" onclick="if (' + strMsgEdit + 'MsgArea.isContentEditable==true) document.execCommand(\'JustifyRight\');">&nbsp;&nbsp;&nbsp;&nbsp;';
			strHTML += '<img src="./imgs/btn_editor7.gif" title="Font Size" style="cursor:pointer;" onclick="if (' + strMsgEdit + 'MsgArea.isContentEditable==true) document.execCommand(\'Fontsize\', false, oJSTLib.SelFontSize);" />&nbsp;';
			strHTML += '<span id="' + strMsgEdit + 'editbox_fontsize"></span>&nbsp;&nbsp;';

			strHTML += '<img src="./imgs/btn_editor8.gif" title="link" style="cursor:pointer;" onclick="if (' + strMsgEdit + 'MsgArea.isContentEditable==true) document.execCommand(\'createlink\');">&nbsp;';

			strHTML += '</div>';

			oPD.innerHTML = strHTML;
			objMsgEdit.appendChild(oPD);

			var oWebF = this.WebFontSize(strMsgEdit + 'editbox_fontsize');

			var oMsgArea = document.createElement('div');
			oMsgArea.setAttribute('id', strMsgEdit + 'MsgArea');
			oMsgArea.style.cssText = 'width:550px;';
			oMsgArea.setAttribute('className', 'msgbox_font');
			objMsgEdit.appendChild(oMsgArea);

		} else if (document.getElementsByTagName) {
			var oPD = document.createElement('div');
			oPD.setAttribute('id', 'paintdecoration');
			oPD.style.cssText = 'top:0px;left:0px;width:550px;';

			strHTML  = '<div style="height:32px;background-color:#F8F8EE"><table><tr><td height="3px"></td></tr></table>';

			strHTML += '<img src="./imgs/btn_editor1.gif" title="Bold" style="cursor:pointer;" onclick="document.getElementById(\'' + strMsgEdit + 'MsgArea\').contentDocument.execCommand(\'bold\', false, null);" />&nbsp;';
			strHTML += '<img src="./imgs/btn_editor2.gif" title="Italic" style="cursor:pointer;" onclick="document.getElementById(\'' + strMsgEdit + 'MsgArea\').contentDocument.execCommand(\'italic\', false, null);" />&nbsp;';
			strHTML += '<img src="./imgs/btn_editor3.gif" title="Underline" style="cursor:pointer;" onclick="document.getElementById(\'' + strMsgEdit + 'MsgArea\').contentDocument.execCommand(\'underline\', false, null);" />&nbsp;&nbsp;&nbsp;&nbsp;';

			strHTML += '<img src="./imgs/btn_editor4.gif" title="Left" style="cursor:pointer;" onclick="document.getElementById(\'' + strMsgEdit + 'MsgArea\').contentDocument.execCommand(\'JustifyLeft\', false, null);" />&nbsp;';
			strHTML += '<img src="./imgs/btn_editor5.gif" title="Center" style="cursor:pointer;" onclick="document.getElementById(\'' + strMsgEdit + 'MsgArea\').contentDocument.execCommand(\'JustifyCenter\', false, null);" />&nbsp;';
			strHTML += '<img src="./imgs/btn_editor6.gif" title="Right" style="cursor:pointer;" onclick="document.getElementById(\'' + strMsgEdit + 'MsgArea\').contentDocument.execCommand(\'JustifyRight\', false, null);" />&nbsp;&nbsp;&nbsp;&nbsp;';
			strHTML += '<img src="./imgs/btn_editor7.gif" title="Font Size" style="cursor:pointer;" onclick="document.getElementById(\'' + strMsgEdit + 'MsgArea\').contentDocument.execCommand(\'FontSize\', false, oJSTLib.SelFontSize);" />';
			strHTML += '<span id="' + strMsgEdit + 'editbox_fontsize"></span>&nbsp;&nbsp;';

			strHTML += '<img src="./imgs/btn_editor8.gif" title="link" style="cursor:pointer;" onclick="var szURL = prompt(\'リンクの追加\', \'http://\'); document.getElementById(\'' + strMsgEdit + 'MsgArea\').contentDocument.execCommand(\'createlink\', false, szURL);" />&nbsp;';
			strHTML += '</div>';

			oPD.innerHTML = strHTML;
			objMsgEdit.appendChild(oPD);

			var oWebF = this.WebFontSize(strMsgEdit + 'editbox_fontsize');

			var oMsgArea = document.createElement('iframe');
			oMsgArea.setAttribute('id', strMsgEdit + 'MsgArea');
			oMsgArea.setAttribute('class', 'msgbox_font');
			oMsgArea.style.cssText = 'position:relative;top:0px;left:0px;width:550px;height:350px;';
			objMsgEdit.appendChild(oMsgArea);
		}

	},

	// *********************************************************************************
	// * function name : enableEditBox
	// *********************************************************************************
	enableEditBox : function(strMsgEdit){
		var oPaintArea = document.getElementById(strMsgEdit + 'MsgArea');

		oPaintArea.style.borderStyle = 'dotted';
		oPaintArea.style.borderColor = '#CCCCCC';
		oPaintArea.style.borderWidth = '3px';

		if (document.all) {
			oPaintArea.contentEditable = 'true';
		} else if (document.getElementsByTagName) {
			setTimeout(function() {  document.getElementById(strMsgEdit + 'MsgArea').contentDocument.designMode = 'on'; }, 500);
		}
	},
		
	// *********************************************************************************
	// * function name : WebFontSize
	// *********************************************************************************
	WebFontSize : function(parentObjID) {
		//alert();
		this.selectColor = '';
		this.objSelectID = parentObjID + '_sel';

		var strHTML = '';

		var objParent = document.getElementById(parentObjID);

		var oWebF = document.createElement('span');
		oWebF.setAttribute('id', 'pageFontSizeValueID');
		oWebF.setAttribute('title', 'Font Size');

		var strFontSizeName = new Array('1','2','3','4','5','6','7');
	
		strHTML = '<select name="' + this.objSelectID + '" id="' + this.objSelectID + '" onchange="oJSTLib.SelFontSize = document.getElementById(\'' + this.objSelectID + '\').value;">'

		for (i = 0 ; i < strFontSizeName.length ; i ++ ) {
			if (strFontSizeName[i] == '1') 
				strSelected = 'selected';
			else
				strSelected = '';
				
			strHTML += '<option value="' + strFontSizeName[i] + '" ' + strSelected + '>' + strFontSizeName[i] + '</option>';
		}
		strHTML += '</select>'

		oWebF.innerHTML = strHTML;
		objParent.appendChild(oWebF);
	}
}
var oJSTLib = new JSTLib();

var gmapManage;
var icon2;
var markerCenter;

function ManageGoogleMapLoad(strlat, strlon){
	if (GBrowserIsCompatible()) {
		gmapManage = new GMap2(document.getElementById("googlemap"));
		if (strlat == '') {
			gmapManage.setCenter(new GLatLng(19.49218588813379, -43.00959633118105), 2, G_PHYSICAL_MAP);
		}
		else {
			gmapManage.setCenter(new GLatLng(strlon, strlat), 8, G_PHYSICAL_MAP);
		}
		gmapManage.enableScrollWheelZoom();

		icon2 = new GIcon();
    	icon2.image = "./imgs/pin.gif";
    	icon2.iconSize = new GSize(16, 16);
    	icon2.iconAnchor = new GPoint(8, 16);
    	markerCenter = new GMarker(gmapManage.getCenter(), icon2);
	    gmapManage.addOverlay(markerCenter);
		
		GEvent.addListener(gmapManage, "click", function(overlay, point) {
			gmapManage.clearOverlays();
			if (point) {
				marker2 = new GMarker(point, icon2);
				gmapManage.addOverlay(marker2);

				//座標を表示
				showLatLonManage(point);
			}
		});

		showLatLonManage = function (pointCenter){
			document.getElementById('datalatlon').innerHTML = pointCenter;
			document.f1.lat.value = pointCenter.x;
			document.f1.lon.value = pointCenter.y;
		};
		
		showLatLonManage(gmapManage.getCenter());
	}
}
