﻿var selectSchoolCtrlId;
var selectSchoolObjCtrlId;
(function($) {
    $.fn.selectSchool = function(objId) {
        //debugger;
        //if (typeof (this) != "text")
        //return;
        document.write('<div style="DISPLAY: none; left: 140px; top: 904px; width: 618px;" id="selectSchool" class="popup-wrapper" >');
        document.write('<div class="popup-content">');
        document.write('<ul class="my-province" id="popup-province"></ul>');
        document.write('<ul class="my-province" id="popup-city" style="display:none;"></ul>');
//        document.write('<ul class="my-province" id="popup-area" style="display:none;"></ul>');
        document.write('<ul class="my-province" id="popup-school" style="display:none;"></ul>');
        document.write('<ul class="my-province" style="text-align: center;">');
        document.write('    <li style="width: 156px">&nbsp;</li>');
        document.write('    <li style="width: 226px">&nbsp;</li>');
        document.write('    <li style="text-align:left;">');
        document.write('        <input id="closeButton" onclick="return hidepan();" type="button" value="关闭窗口" /> ');
        document.write('    </li>');
        document.write('</ul>');
        document.write('</div><IFRAME src="about:blank"></IFRAME></div>');

        selectSchoolObjCtrlId = objId;
        
        this.attr("readonly", true);
        selectSchoolCtrlId = this.attr("id");
        //this.attr("onclick", showpan);
        this[0].onclick = showpan;
    }
})(jQuery);

function showpan() {
    //debugger;
    var e = window.event.srcElement;
    var left = ($(document).width() - 618) / 2;
    $("#selectSchool")[0].style.left = left + "px";
    $("#selectSchool")[0].style.top = $(e).offset().top + "px";
    $("#selectSchool")[0].style.display = "block";
    getProvince();
    getCity(sProvinceID);
    getSchool(sCityID);
}
function hidepan() {
    $("#selectSchool")[0].style.display = "none";
}
function getData(furl, param, updateid) {
    //debugger;
    $.ajaxSetup({ async: false });
    var datas;
    var url = furl + '/' + param;

    $.get(url, function(xml) {
        datas = xml;
    });
    if (datas == undefined) {
        //alert("no datas");
        return;
    }
    $('#' + updateid).html(datas);
}

function getProvince() {
    var furl = "/Publish/ssamGetProvince";
    var updateid = "popup-province";
    getData(furl, "", updateid);

    document.getElementById('popup-city').style.display = "none";
    //document.getElementById('popup-area').style.display = "none";
    document.getElementById('popup-school').style.display = "none";
}

var osubpa;
function getCity(id) {
    //var e = window.event.srcElement;
    //var id = e.value;
    $(osubpa).removeClass("c");
    $("#subpa" + id).addClass("c");
    osubpa = $("#subpa" + id);
    
    var furl = "/Publish/ssamGetCity";
    var param = id;
    var updateid = "popup-city";
    getData(furl, param, updateid);

    document.getElementById('popup-city').style.display = "";
    //document.getElementById('popup-area').style.display = "none";
    document.getElementById('popup-school').style.display = "none";
}
function getArea(id) {
    //var e = window.event.srcElement;
    //var id = e.value;
    var furl = "/Publish/ssamGetArea";
    var param = id;
    var updateid = "popup-area";
    getData(furl, param, updateid);

    document.getElementById('popup-area').style.display = "";
    document.getElementById('popup-school').style.display = "none";
}

var osubca;
function getSchool(id) {
    //var e = window.event.srcElement;
    //var id = e.value;
    $(osubca).removeClass("c");
    $("#subca" + id).addClass("c");
    osubca = $("#subca" + id);
    
    var furl = "/Publish/ssamGetSchool";
    var param = id;
    var updateid = "popup-school";
    getData(furl, param, updateid);

    document.getElementById('popup-school').style.display = "";
}
function selectSchool(id, text) {
    //debugger;
    //var e = window.event.srcElement;
    //var id = e.value;
    $("#" + selectSchoolCtrlId).val(text);
    $('#' + selectSchoolObjCtrlId).val(id);

    changeSchoolID(id); //++
    hidepan();
}
