/*
* WEBCONSOLE RESIZE and SERCHFORM CONTROLLER
* 2003 - 2007 scripted by Takehisa Mashimo
*/

var selectedNum;
var searchForm;
//window.alert("Debug OK");

function setup() {
	selectedNum = 0;
	searchForm = document.forms[0];
	searchForm.contentsSelect.options[4].text = "Directory";
	searchForm.contentsSelect.selectedIndex = selectedNum;
	window.resizeTo(screen.width*0.5, screen.height*0.75);
	window.moveTo(screen.width*0.5 - 400, screen.height*0.05);
	changeSelectForm();
	swapLatestYear();
}

function swapLatestYear() {
	dateObj = new Date(); 
	var lastmodifiedElements = document.getElementsByName("lastmodfied");
	for (var i=0; i<lastmodifiedElements.length; i++) {
		var text = document.createTextNode(dateObj.getFullYear());
		lastmodifiedElements[i].appendChild(text);
	}
	//showErrorMessage(lastmodifiedElements.length);
}

function changeSelectForm() {
	try {
		selectedNum = searchForm.contentsSelect.selectedIndex;
		searchForm.contentsSelect.options[4].text = "Directory";
		
		if (selectedNum==0) {}				
		if (selectedNum==1) {}
		if (selectedNum==2) {}
		if (selectedNum==3) {}
		if (selectedNum==4) {}
		if (selectedNum==5) {
			try {
				windowURL = "webconsole/webconsole/index.html";
				windowName = "consoleWindow"
				windowSetting = "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes,";
				windowSize = "width=300, height=500,left=100, top=100";
				windowStatus = windowSetting + windowSize;
				windowObj = window.open(windowURL, windowName, windowStatus);
				windowObj.focus();
			} catch(e) {}
		}
	} catch(e) {
		showErrorMessage("Failed");
	}
}

function jumpToLink() {
	try {
		searchForm.action = "";
		searchForm.method = "";
		searchForm.target = "_parent";
		if (selectedNum==0) {
			searchForm.action = "http://www.google.co.jp/search";
			searchForm.method = "get";
			searchForm.target = "_parent";
			searchForm.outputform.name = "q";
			searchForm.submit();
		}
		if (selectedNum==1) {
			searchForm.action = "http://dic.yahoo.co.jp/bin/dsearch";
			searchForm.method = "get";
			searchForm.target = "_parent";
			searchForm.outputform.name = "p";
			searchForm.submit();
		}
		if (selectedNum==2) { location.href = 'javascript:' + searchForm.outputform.value + '; showErrorMessage("OK")';}
		if (selectedNum==3) { location.href = 'http://' + searchForm.outputform.value; }
		if (selectedNum==4) { location.href = searchForm.outputform.value; }
	} catch(e) {
		showErrorMessage("Failed");
	}
}	

function showErrorMessage(errorMessage) {
	searchForm.outputform.value = errorMessage;
}
