function addSrcToDestList() {
    destList = document.roleForm.selRight;
    srcList = document.roleForm.selLeft;
    var len = destList.length;
    for (var i = 0; i < srcList.length; i++) {
        if (( srcList.options[i] != null ) && ( srcList.options[i].selected )) {
            var found = false;
            for (var count = 0; count < len; count++) {
                if (destList.options[count] != null) {
                    if (srcList.options[i].value == destList.options[count].value) {
                        found = true;
                        alert("found: " + i + destList.options[i].value + ":" + count + srcList.options[count].value + destList.options[i].value);
                        break;
                    }
                }
            }
            if (found != true) {
                destList.options[len] = new Option(srcList.options[i].text);
                destList.options[len].value = srcList.options[i].value;
                len++;
            }
        }
    }
    deleteFromSrcList();
}

function deleteFromSrcList() {
    srcList = document.roleForm.selLeft;
    var len = srcList.options.length;
    for (var i = (len - 1); i >= 0; i--) {
        if ((srcList.options[i] != null) && (srcList.options[i].selected == true)) {
            srcList.options[i] = null;
        }
    }
}

function deleteFromDestList() {
    addDestToSrcList();
    var destList = document.roleForm.selRight;
    var len = destList.options.length;
    for (var i = (len - 1); i >= 0; i--) {
        if ((destList.options[i] != null) && (destList.options[i].selected == true)) {
            destList.options[i] = null;
        }
    }
}

function addDestToSrcList() {
    destList = document.roleForm.selRight;
    srcList = document.roleForm.selLeft;
    var len = srcList.length;
    for (var i = 0; i < destList.length; i++) {
        if (( destList.options[i] != null ) && ( destList.options[i].selected )) {
            var found = false;
            for (var count = 0; count < len; count++) {
                if (srcList.options[count] != null) {
                    if (destList.options[i].value == srcList.options[count].value) {
                        found = true;
                        break;
                    }
                }
            }
            if (found != true) {
                srcList.options[len] = new Option(destList.options[i].text);
                srcList.options[len].value = destList.options[i].value;
                len++;
            }
        }
    }
}


/**
 *
 */
function onKeyUpSearchSelect(sel, inputText) {
    if (event.keyCode == 13) {
        searchSelect(sel, inputText);
        return false;
    }

}

/**
 *
 */
function searchSelect(sel, inputText) {
    var cri = inputText.value;
    cri = cri.toUpperCase();

    if (cri.length == 0) {
        alert("关键字不能为空！");
        return false;
    }

    var target = null;
    for (var i = 0; i < sel.length; ++i) {
        sel.options[i].selected = false;
        target = sel.options[i].text.toUpperCase();

        if (target.indexOf(cri) != -1) {
            sel.options[i].selected = true;
        }
    }

}

// Different methods ...
function addSrcToDestList(srcList, destList) {
    var len = destList.length;
    for (var i = 0; i < srcList.length; i++) {
        if (( srcList.options[i] != null ) && ( srcList.options[i].selected )) {
            var found = false;
            for (var count = 0; count < len; count++) {
                if (destList.options[count] != null) {
                    if (srcList.options[i].value == destList.options[count].value) {
                        found = true;
                        alert("found: " + i + destList.options[i].value + ":" + count + srcList.options[count].value + destList.options[i].value);
                        break;
                    }
                }
            }
            if (found != true) {
                destList.options[len] = new Option(srcList.options[i].text);
                destList.options[len].value = srcList.options[i].value;
                len++;
            }
        }
    }
    deleteFromSrcList(srcList, destList);
}

// Different methods ...
function addAllSrcToDestList(srcList, destList) {
    var len = destList.length;
    for (var i = 0; i < srcList.length; i++) {
        if (( srcList.options[i] != null )) {
            var found = false;
            for (var count = 0; count < len; count++) {
                if (destList.options[count] != null) {
                    if (srcList.options[i].value == destList.options[count].value) {
                        found = true;
                        alert("found: " + i + destList.options[i].value + ":" + count + srcList.options[count].value + destList.options[i].value);
                        break;
                    }
                }
            }
            if (found != true) {
                destList.options[len] = new Option(srcList.options[i].text);
                destList.options[len].value = srcList.options[i].value;
                len++;
            }
        }
    }
    deleteAllFromSrcList(srcList, destList);
}


function deleteFromSrcList(srcList, destList) {
    var len = srcList.options.length;
    for (var i = (len - 1); i >= 0; i--) {
        if ((srcList.options[i] != null) && (srcList.options[i].selected == true)) {
            srcList.options[i] = null;
        }
    }
}

function deleteAllFromSrcList(srcList, destList) {
    var len = srcList.options.length;
    for (var i = (len - 1); i >= 0; i--) {
        if ((srcList.options[i] != null)) {
            srcList.options[i] = null;
        }
    }
}


function deleteFromDestList(srcList, destList) {
    addDestToSrcList(srcList, destList);
    var len = destList.options.length;
    for (var i = (len - 1); i >= 0; i--) {
        if ((destList.options[i] != null) && (destList.options[i].selected == true)) {
            destList.options[i] = null;
        }
    }
}

function deleteAllFromDestList(srcList, destList) {
    addAllDestToSrcList(srcList, destList);
    var len = destList.options.length;
    for (var i = (len - 1); i >= 0; i--) {
        if ((destList.options[i] != null)) {
            destList.options[i] = null;
        }
    }
}

function addDestToSrcList(srcList, destList) {
    var len = srcList.length;
    for (var i = 0; i < destList.length; i++) {
        if (( destList.options[i] != null ) && ( destList.options[i].selected )) {
            var found = false;
            for (var count = 0; count < len; count++) {
                if (srcList.options[count] != null) {
                    if (destList.options[i].value == srcList.options[count].value) {
                        found = true;
                        break;
                    }
                }
            }
            if (found != true) {
                srcList.options[len] = new Option(destList.options[i].text);
                srcList.options[len].value = destList.options[i].value;
                len++;
            }
        }
    }
}

function addAllDestToSrcList(srcList, destList) {
    var len = srcList.length;
    for (var i = 0; i < destList.length; i++) {
        if (( destList.options[i] != null )) {
            var found = false;
            for (var count = 0; count < len; count++) {
                if (srcList.options[count] != null) {
                    if (destList.options[i].value == srcList.options[count].value) {
                        found = true;
                        break;
                    }
                }
            }
            if (found != true) {
                srcList.options[len] = new Option(destList.options[i].text);
                srcList.options[len].value = destList.options[i].value;
                len++;
            }
        }
    }
}


/**
 *以下是年的选择 FUNCTION DEFINE
 *--------------------------------------------------------------------------------------
 */
var aYears = new Array();
var d = new Date();
var endYear = d.getFullYear();
d.setFullYear(2000);
var currYear = d.getFullYear();
while (!(currYear > endYear)) {
    aYears[aYears.length] = currYear;
    currYear++;
}

function addOption(o, t, v)
{
    var op = new Option();
    op.text = t;
    op.value = v;
    o.options.add(op);
}



function addYearOptions(o) {
   aYearOptions(o,'年');
}

function aYearOptions(o,v) {
    if (typeof(v)=='undefined') v='';
    for (var i = aYears.length - 1; i >= 0; --i) {
        addOption(o, aYears[i] + v, aYears[i]);
    }
}

function addAreaOptions(o) {
    addOption(o, '北京', 2);
    addOption(o, '上海', 3);
    addOption(o, '广州', 1);
    addOption(o, '深圳', 4);
    addOption(o, '香港', 9);
    addOption(o, '广西', 5);
    addOption(o, '江苏', 8);
    addOption(o, '重庆', 6);
    addOption(o, '山东', 7);
    addOption(o, '辽宁', 10);
    addOption(o, '福建', 11);
    addOption(o, '成都', 12);
    addOption(o, '西安', 13);
    addOption(o, '江西', 14);
    addOption(o, '湖南', 15);
    addOption(o, '武汉', 16);
}

function addAreaOptions2(o) {
    addOption(o,'请选择...','');
    addOption(o, '北京', 2);
    addOption(o, '上海', 3);
    addOption(o, '广州', 1);
    addOption(o, '深圳', 4);
    addOption(o, '香港', 9);
    addOption(o, '广西', 5);
    addOption(o, '江苏', 8);
    addOption(o, '重庆', 6);
    addOption(o, '山东', 7);
    addOption(o, '辽宁', 10);
    addOption(o, '福建', 11);
    addOption(o, '成都', 12);
    addOption(o, '西安', 13);
    addOption(o, '江西', 14);   
    addOption(o, '湖南', 15);   
    addOption(o, '武汉', 16);   
}



function setDefaultOption(o, s) {
    for (var i = 0; i < o.options.length; ++i) {
        if (o.options[i].value == s) {
            o.value = s;
            break;
        }
    }
}



