school_form = { fields: ['detail_education_country', 'detail_education_city_suggest', 'detail_education_city_dropdown', // 'detail_education_subcity', 'detail_education_univercity', 'detail_education_school', 'detail_education_gschool', 'detail_education_start_year', 'detail_education_finish_year', 'detail_education_field', 'detail_education_subject', 'detail_education_school_email'], fields_map: [[0,0,0,0,0,0,0,0,0,0,0], [1,0,0,1,0,0,1,0,1,0,1], [1,0,0,1,0,0,1,1,1,0,1], [1,0,0,0,1,0,0,0,0,0,0], [1,0,0,0,0,1,0,0,0,0,0],], fields_map_set: null, education_type: null, set_fields: function(type) { this.fields_map_set = type; for (var i = 0; i < this.fields.length; ++i) { if (this.fields_map[type][i]) { this.show(i); } else { this.hide(i); } } }, set_fields_country: function(country) { var type = this.fields_map_set; if (country == 'TR') { this.hide(1); this.show(2); if (this.fields_map[type][8]) { this.show(8, 'TR'); } else { this.hide(8); } this.hide(9); } else { this.hide(2); this.show(1); if (this.fields_map[type][8]) { if (country == 'DE') { this.show(8, 'DE'); } else { this.show(8, main_language.substr(3, 2)); } if (country != 'DE' && main_language == 'tr_TR') { this.hide(9); } else { this.show(9); } } else { this.hide(8); this.hide(9); } } }, set_country: function(country) { this.set_fields_country(country); if (country == 'TR') { this.get_city(this.fields[2], country); } this.get_school('', ''); if (country != 'TR' && country != 'DE') { country = main_language.substr(-2, 2); } this.get_subject(''); }, show: function(id) { var country = '' if (arguments.length > 1) { var country = '_' + arguments[1]; } if (document.getElementById){ obj = document.getElementById(this.fields[id] + '_tr'); obj.style.display=""; selobjs = obj.getElementsByTagName("select"); for (var i = 0; i < selobjs.length; i++) { if (selobjs[i].getAttribute('name') == this.fields[id] + country) { selobjs[i].style.display=""; } else { selobjs[i].style.display="none"; } } } }, hide: function(id) { if (document.getElementById){ obj = document.getElementById(this.fields[id] + '_tr'); if (obj != null) { obj.style.display="none"; selobjs = obj.getElementsByTagName("select"); if (selobjs.length > 0) { selobjs[0].style.display="none"; } } } }, set_visible: function(status) { var country = document.getElementById(this.fields[0]).value; this.education_type = status; switch (status) { case 'sou': this.set_fields(1); this.set_fields_country(country); break; case 'aou': this.set_fields(2); this.set_fields_country(country); break; case 'eou': this.set_fields(1); this.set_fields_country(country); break; case 'soh': this.set_fields(3); this.set_fields_country(country); break; case 'sog': this.set_fields(4); this.set_fields_country(country); break; default: this.set_fields(0); break; } }, get_data: function(data) { if (data != null) { var xmlhttp = null; try { xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); } catch (e) { try { xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); } catch (e) { xmlhttp = null; } } if (xmlhttp == null && typeof(XMLHttpRequest) != 'undefined') { xmlhttp = new XMLHttpRequest(); } if (xmlhttp != null) { xmlhttp.open('GET', data.url, true); xmlhttp.onreadystatechange = function() { this.get_data_callback(xmlhttp, data); }.bind(this); xmlhttp.send(null); } } }, get_data_callback: function(xmlhttp, data_object) { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { var xmldoc = xmlhttp.responseXML; try { var rapidsuggest = xmldoc.getElementsByTagName('rapidsuggest').item(0); if (rapidsuggest.getElementsByTagName('suggestion').length == 0) { school_form.dropdown_clear(data_object.dropdown_list); school_form.dropdown_add_option(data_object.dropdown_list, data_object.no_data_text, 'null', true); data_object.dropdown_list.parentNode.replaceChild(data_object.dropdown_list, data_object.dropdown_list); // for IE6 return; } var list = ''; for (var j = 0; j < rapidsuggest.getElementsByTagName('suggestion').length; ++j) { list += rapidsuggest.getElementsByTagName('suggestion').item(j).firstChild.data; } list += ''; school_form.dropdown_add_hoptions(data_object.dropdown_list, list); } catch (e) { } } }, dropdown_add_option: function(dropdown_list, text, value, is_default, is_selected) { var dropdown_option = document.createElement("option"); dropdown_option.appendChild(document.createTextNode(text)); dropdown_option.setAttribute("value", value); dropdown_option.setAttribute("label", text); if (is_default) dropdown_option.defaultSelected = true; else if (is_selected) dropdown_option.selected = true; dropdown_list.appendChild(dropdown_option); }, dropdown_add_hoptions: function(dropdown_list, html) { try //Internet Explorer { var xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async="false"; xmlDoc.loadXML(html); } catch(e) { try //Firefox, Mozilla, Opera, etc. { parser=new DOMParser(); var xmlDoc=parser.parseFromString(html,"text/xml"); } catch(e) {alert(e.message)} } try { var xml_options = xmlDoc.getElementsByTagName('option'); var new_dropdown_list = dropdown_list.cloneNode(true); this.dropdown_clear(new_dropdown_list); this.dropdown_add_option(new_dropdown_list, field_string_table.sp01, 'null', true); for (var j = 0; j < xml_options.length; ++j) { var text = xml_options[j].childNodes[0].nodeValue; var value = xml_options[j].getAttribute('value'); this.dropdown_add_option(new_dropdown_list, text, value); } // alert(new_dropdown_list.getAttribute('id')); new_dropdown_list.disabled = false; // dropdown_list.setAttribute("id", new_dropdown_list.getAttribute('id') + "_old"); dropdown_list.parentNode.replaceChild(new_dropdown_list, dropdown_list); } catch(e) {alert(e.message)} }, dropdown_clear: function(dropdown_list) { for (var i=dropdown_list.options.length; i > 0; i--) { dropdown_list.remove(i-1); } }, dropdown_loading_status: function(dropdown_list) { this.dropdown_clear(dropdown_list); this.dropdown_add_option(dropdown_list, field_string_table.sp02, 'null', true); dropdown_list.disabled = true; }, get_city: function(dropdown_id, country, school_type, additional_city_id) { var dropdown_list = document.getElementById(dropdown_id); this.dropdown_loading_status(dropdown_list); dropdown_list.parentNode.replaceChild(dropdown_list, dropdown_list); // for IE6 this.get_data({url: "/ajax-city.html?query_set=" + country + (this.education_type ? "&school_type=" + this.education_type : "") + (additional_city_id ? "&acid=" + additional_city_id : ""), dropdown_list: dropdown_list, no_data_text: ''}); }, get_school: function(city, city_type) { switch (this.education_type) { case 'sou': case 'aou': case 'eou': dropdown_id = this.fields[3]; var type = 1; break; case 'soh': dropdown_id = this.fields[4]; var type = 0; break; case 'sog': dropdown_id = this.fields[5]; var type = 2; break; default: this.set_fields(0); break; } var dropdown_list = document.getElementById(dropdown_id); this.dropdown_loading_status(dropdown_list); dropdown_list.parentNode.replaceChild(dropdown_list, dropdown_list); // for IE6 if (city == null) { this.dropdown_clear(dropdown_list); this.dropdown_add_option(dropdown_list, field_string_table.sp08, 'null', true) return; } this.get_data({url: "/school-get.html?city=" + encodeURIComponent(city) + "&city_type=" + city_type + "&type=" + type, dropdown_list: dropdown_list, no_data_text: field_string_table.sp08}); }, get_subject: function(field) { var dropdown_list = document.getElementById(this.fields[9]); this.dropdown_loading_status(dropdown_list); dropdown_list.parentNode.replaceChild(dropdown_list, dropdown_list); // for IE6 this.get_data({url: "/ajax-subject.html?field=" + field, dropdown_list: dropdown_list, no_data_text: field_string_table.sp03}); } }