/*  Function Equivalent to java.net.URLEncoder.encode(String, "UTF-8")
    Copyright (C) 2002, Cresc Corp.
    Version: 1.0
*/

function encodeURL(str){
    var s0, i, s, u;
    s0 = "";                // encoded str
    for (i = 0; i < str.length; i++){   // scan the source
        s = str.charAt(i);
        u = str.charCodeAt(i);          // get unicode of the char
        if (s == " "){s0 += "+";}       // SP should be converted to "+"
        else {
            if ( u == 0x2a || u == 0x2d || u == 0x2e || u == 0x5f || ((u >= 0x30) && (u <= 0x39)) || ((u >= 0x41) && (u <= 0x5a)) || ((u >= 0x61) && (u <= 0x7a))){       // check for escape
                s0 = s0 + s;            // don't escape
            }
            else {                  // escape
                if ((u >= 0x0) && (u <= 0x7f)){     // single byte format
                    s = "0"+u.toString(16);
                    s0 += "%"+ s.substr(s.length-2);
                }
                else if (u > 0x1fffff){     // quaternary byte format (extended)
                    s0 += "%" + (oxf0 + ((u & 0x1c0000) >> 18)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0x3f000) >> 12)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
                else if (u > 0x7ff){        // triple byte format
                    s0 += "%" + (0xe0 + ((u & 0xf000) >> 12)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
                else {                      // double byte format
                    s0 += "%" + (0xc0 + ((u & 0x7c0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
            }
        }
    }
    return s0;
}

function search(theForm)
{
    if (theForm.c.value == "") {
        return false;
    }

    c  = theForm.c.value;
    if(c.search(/,/)){
        cat = c.split(",");
        pc = cat[0];
        c = cat[1];
    }

    sr = theForm.sr.value;
    rc = theForm.rc.value;

	ss = new Array();
	// dirty hack
    for(j=1; j <= 5; j++){
		if(j<=2) elname = 'ss['+j+']';
		else elname = 'ss['+j+'][]';

		elem = document.getElementsByName(elname);
		for(i=0; i < elem.length; i++){
			if(elem[i].checked){
				ss.push(elem[i].value);
			}
		}
    }

    if (typeof pc != 'undefined') url = "http://www.chuukouikkan-search.com/search/" + pc + "/" + c + "/";
    else url = "http://www.chuukouikkan-search.com/search/" + c + "/";
    if (typeof sr != 'undefined' && sr != 0) url += sr + "/";
    if ((typeof ss != 'undefined' && ss.length != 0) ||
        (typeof rc != 'undefined' && rc != 0)){

		theForm.action = url;
		theForm.method = "post";
		theForm.submit();
	}
    return url;
}

function jumpto(roma, reco)
{
    if (roma == "" || reco == "") {
        return false;
    }

	url = "http://www.chuukouikkan-search.com/detail/" + roma + "/";

	theForm = document.getElementById("detailform");
	theForm.action = url;
	theForm.sr.value = reco;
	theForm.method = "post";
	theForm.submit();

    return url;
}

function clearForm()
{
	$("select option:selected").each(function() {
		$(this).attr("selected", "");
	});
	$("input:checked").each(function() {
		$(this).attr("checked", "");
	});
}

