// 2007/09 make


// 問い合わせページへ(日本語デフォルト)
function contact_jp_def(){
	go_contact_def("jp");
}
// 問い合わせページへ(英語デフォルト)
function contact_en_def(){
	go_contact_def("en");
}

// 問い合わせページへ(日本語_問い合わせ製品指定)
function contact_jp(p_name, p_code) {
	go_contact(p_name, p_code,"jp");
}
// 問い合わせページへ(英語_問い合わせ製品指定)
function contact_en(p_name, p_code) {
	go_contact(p_name, p_code,"en");
}
function go_contact(p_name, p_code, lang) {
	product = "";
	if(p_name != "") {
		product += URLencode(p_name);
	}
	if(p_code != "") {
		if(product != "")
			product += " ";
		product += URLencode(p_code);
	}
	if(lang == "") {
		lang = "jp";
	}
	
	param_str = "?mode=form&";
	if(product != "") {
		if(lang == "jp")
			param_str += "name10=" + product;
		else
			param_str += "name25=" + product;
	}
	param_str += "&lang=" + lang;
	
//	url = "/cgi-bin/contact/form.cgi" + param_str;
	url = "https://www.tokyoinst.co.jp/cgi-bin/contact/form.cgi" + param_str;
	win=window.open(url,"tiiContact","");
}

// パラメータなしのお問い合わせ画面遷移JS
function go_contact_def(lang){
//	url = "/cgi-bin/contact/form.cgi?mode=form&lang=" + lang;
	url = "https://www.tokyoinst.co.jp/cgi-bin/contact/form.cgi?mode=form&lang=" + lang;
	win=window.open(url,"tiiContact","");
}

// 同ウィンドウでお問い合わせ画面表示JS
function go_contact_nowin(lang){
//	url = "/cgi-bin/contact/form.cgi?mode=form&lang=" + lang;
	url = "https://www.tokyoinst.co.jp/cgi-bin/contact/form.cgi?mode=form&lang=" + lang;
	location.href=url;
}

// 文字列をURLエンコードする(UTF-8)
function URLencode(str){
 // Unicode to URL encoded UTF-8
 var i, encoded_str, char_code, padded_str;
         encoded_str = "";
         for (i = 0; i < str.length; i++){
             char_code = str.charCodeAt(i);
             if (char_code == 0x20){
                // space -> "+"
                encoded_str += "+";}
             else { // else 1
                  if (((0x30 <= char_code) && (char_code <= 0x39)) || ((0x41 <= char_code) && (char_code <= 0x5a)) || ((0x61 <= char_code) && (char_code <= 0x7a))){
		     // [0-9a-z-A-Z]
                     // no escape
                     encoded_str += str.charAt(i);
                  }
		  else if ((char_code == 0x2a) || (char_code == 0x2e) || (char_code == 0x2d) || (char_code == 0x5f)) {
		     // [.-_]
                     // no escape
                     encoded_str += str.charAt(i);
		  }
                  else { // else 2
                       // for internal unicode to UTF-8
		       // Ref. http://homepage3.nifty.com/aokura/jscript/utf8.html
		       // Ref. http://homepage1.nifty.com/nomenclator/unicode/ucs_utf.htm
                       if ( char_code > 0xffff ) {
                          encoded_str += "%" + ((char_code >> 18) | 0xf0).toString(16).toUpperCase();
                          encoded_str += "%" + (((char_code >> 12) & 0x3f) | 0x80).toString(16).toUpperCase();
			  encoded_str += "%" + (((char_code >> 6) & 0x3f) | 0x80).toString(16).toUpperCase();
			  encoded_str += "%" + ((char_code & 0x3f) | 0x80).toString(16).toUpperCase();
		       }
                       else if ( char_code > 0x7ff ) {
                          encoded_str += "%" + ((char_code >> 12) | 0xe0).toString(16).toUpperCase();
			  encoded_str += "%" + (((char_code >> 6) & 0x3f) | 0x80).toString(16).toUpperCase();
			  encoded_str += "%" + ((char_code & 0x3f) | 0x80).toString(16).toUpperCase();
                       }
                       else if ( char_code > 0x7f ) {
		          encoded_str += "%" + (((char_code >> 6) & 0x1f) | 0xc0).toString(16).toUpperCase();
			  encoded_str += "%" + ((char_code & 0x3f) | 0x80).toString(16).toUpperCase();
                       }
                       else {
                          // for ascii
                          padded_str = "0" + char_code.toString(16).toUpperCase();
                          encoded_str += "%" + padded_str.substr(padded_str.length - 2, 2);
                       }
                    } // else 2
                } // else 1
        } // for
        return encoded_str;
}

