function Advance() {
	if(document.getElementById('advance').style.display == '')
		document.getElementById('advance').style.display = 'none';
	else
		document.getElementById('advance').style.display = '';
}
function ChangeAdvance(name) {
	var obj = document.getElementById('advance').getElementsByTagName('table');
	for(i = 0; i < obj.length; i++)	{
		if(obj[i].id == name)
			obj[i].style.display = ''
		else
			obj[i].style.display = 'none';
	}
	
}
function Condition(name, field) {
    var ret = '';
    var obj = document.getElementById(name);
    if(obj.tagName.toLowerCase() == 'select') {
	    ret = obj.selectedIndex > 0  ? field + "=" + encodeURI(obj.options[obj.selectedIndex].value) + "&" : "";
	    }
	else {
	    if(obj.type == 'text')
	        ret = obj.value.length > 0 ? field + "=" + encodeURI(obj.value) + "&" : "";
	    else if(obj.type == 'checkbox')
	        ret = obj.checked == true ? field + "=1&" : "";
	    }
	return ret;
}
function SearchAdvance() {
	var keywords = document.getElementById('advkeywords').value;
	var entity = document.getElementById('entity');
	var url = '';
	entity = entity.options[entity.selectedIndex].value;
	switch(entity)
	{
	    case 'Monster':
			url = 'MonsterList.aspx?';
			url += document.getElementById('advance').style.display == 'none' ? 'AS=0&' : 'AS=1&';
			url += Condition('Monster_Att1', 'Att1');
			url += Condition('Monster_Att2', 'Att2');
			url += Condition('Monster_Abi1', 'Abi1');
			url += Condition('Monster_Abi2', 'Abi2');
			url += Condition('Monster_Egg1', 'Egg1');
			url += Condition('Monster_Egg2', 'Egg2');
			url += Condition('Monster_AHPMin', 'AHPMin');
			url += Condition('Monster_AHPMax', 'AHPMax');
			url += Condition('Monster_ASPMin', 'ASPMin');
			url += Condition('Monster_ASPMax', 'ASPMax');
			url += Condition('Monster_AAtkMin', 'AAtkMin');
			url += Condition('Monster_AAtkMax', 'AAtkMax');
			url += Condition('Monster_ADefMin', 'ADefMin');
			url += Condition('Monster_ADefMax', 'ADefMax');
			url += Condition('Monster_AAtkSMin', 'AAtkSMin');
			url += Condition('Monster_AAtkSMax', 'AAtkSMax');
			url += Condition('Monster_ADefSMin', 'ADefSMin');
			url += Condition('Monster_ADefSMax', 'ADefSMax');
			url += 'Keyword=' + encodeURI(keywords);
			window.location.href = url;
			break;
		case 'Ability':
		    url = 'AbilityList.aspx?';
			url += 'Keyword=' + encodeURI(keywords);
			window.location.href = url;
			break;
		case 'Skill':
		    url = 'SkillList.aspx?';
			url += document.getElementById('advance').style.display == 'none' ? 'AS=0&' : 'AS=1&';
			url += Condition('Skill_Attribute', 'Attribute');
			url += Condition('Skill_Sort', 'Sort');
			url += Condition('Skill_Bound', 'Bound');
			url += 'Keyword=' + encodeURI(keywords);
			window.location.href = url;
			break;
		case 'All':
		    url = 'Default.aspx?';
			url += 'Keyword=' + encodeURI(keywords);
			window.location.href = url;
			break;
	}
}
function SelectSet(name, value) {
    var obj = document.getElementById(name);
    if(obj.type == "checkbox")
        obj.checked = value == 1 ? "checked" : "";
    else
	    obj.value = value;
}