if(window.addEventListener){
	window.addEventListener('load',function(){
		searchInit();
		checkForm();
		initSearch();
	},false);
}else if(window.attachEvent){
	window.attachEvent('onload',function(){
		searchInit();
		checkForm();
		initSearch();
	});
}

function sDisplay(){
	var searchDisplayState = document.getElementById('tpsDetail').style.display;
	if(searchDisplayState == 'none') {
		document.frmSearch.COMMON_FRONTITEM_SEARCH_TYPE.value = 'detail';
	}else{
		document.frmSearch.COMMON_FRONTITEM_SEARCH_TYPE.value = 'simple';
	}
	
	if(searchDisplayState == 'none'){
		document.getElementById('tpsDetail').style.display = 'block';
		document.getElementById('tpsMorebtn1').style.display = 'none';
		document.getElementById('tpsMorebtn2').style.display = 'block';
	}else{
		document.getElementById('tpsDetail').style.display = 'none';
		document.getElementById('tpsMorebtn1').style.display = 'block';
		document.getElementById('tpsMorebtn2').style.display = 'none';
	}
}

function formSubmit(){
	var searchDisplayState = document.getElementById('tpsDetail').style.display;
	if(searchDisplayState == 'none') {
		document.frmSearchSimple.COMMON_FRONTITEM_KEYWORD.value = document.frmSearch.COMMON_FRONTITEM_KEYWORD.value;
		document.frmSearchSimple.COMMON_FRONTITEM_SEARCH_INSTRUMENTS.value = document.frmSearch.COMMON_FRONTITEM_SEARCH_INSTRUMENTS.value;
		document.frmSearchSimple.submit();
	}else{
		document.frmSearch.submit();
	}
}

function checkForm(){
	//radio1
	if(document.getElementById('rcomp1').checked == true){
		document.getElementById('composer_initial').value = "";
		document.getElementById('composer').value = "";
		document.getElementById('composer_alphabet').disabled = false;
		document.getElementById('composer_initial').disabled = true;
		document.getElementById('composer').disabled = true;
		document.getElementById('composer_alphabet').style.backgroundColor = "#ffffff";
	}
	if(document.getElementById('rcomp2').checked == true){
		document.getElementById('composer_alphabet').value = "";
		document.getElementById('composer_alphabet').disabled = true;
		document.getElementById('composer_initial').disabled = false;
		document.getElementById('composer').disabled = false;
		document.getElementById('composer_alphabet').style.backgroundColor = "#aaaaaa";
	}
	
	//radio2
	if(document.getElementById('rpub1').checked == true){
		document.getElementById('publisher').value = "";
		document.getElementById('publisher').disabled = true;
		document.getElementById('publisher_alphabet').disabled = false;
	}
	if(document.getElementById('rpub2').checked == true){
		document.getElementById('publisher_alphabet').value = "";
		document.getElementById('publisher').disabled = false;
		document.getElementById('publisher_alphabet').disabled = true;
	}
}

//auto complete (unsupport safari2.0)
$(document).ready(function(){
	$('#composer_alphabet').autocomplete('autocomplete_ajax.php',{minChars:2,delay:500});
});

function setComposer(initial){
	checkForm();
	initial = encodeURI(initial);
	src = "/set_composer.html?COMMON_COMPOSER_INITIAL="+ initial;
	nums = new Date().getTime();
	document.getElementById('ifrComposerOutput').innerHTML = '<iframe class="jsIframe" id="ifr_composer'+nums+'" width="1" height="1" src="'+src+'"></iframe>';
}

function searchInit(){
	document.getElementById('rcomp2').checked = true;
	document.getElementById('rpub2').checked = true;
}


function initSearch(){
	nums = new Date().getTime();
	if(document.getElementById('composer_initial').value != ''){
		var intVal = document.getElementById('composer_initial').value;
		if(document.getElementById('composer').value != ''){
			var compVal = encodeURI(document.getElementById('composer').value);
		}else{
			var compVal = '';
		}
		intVal = encodeURI(intVal);
		document.getElementById('ifrComposerOutput').innerHTML = '<iframe class="jsIframe" id="ifr_composer'+nums+'" width="1" height="1" src="/set_composer.html?COMMON_COMPOSER_INITIAL='+intVal+'&amp;COMMON_COMPOSER_NAME='+compVal+'"><\/iframe>';
	}
}
