var marker = null;
var right_type = new Array(".jpg",".gif",".bmp");
function checkFileType(text)
{
    var txt = text;
    var right_typeLen=right_type.length;
    var imgUrl=trim(document.getElementById(txt).value);
    var postfixLen=imgUrl.length;
    var len4=imgUrl.substring(postfixLen-4,postfixLen).toLowerCase();
    for (i=0;i<right_typeLen;i++)
    {
        if(len4==right_type[i])
        {
            return true;
        }
    }
    return false;
}
function TypeName(NAME)//选择类型
{
    type=NAME;
    var menu = "";
    var count = typeCode.length;

    if(NAME == "GIS"){
        map=new LTMaps("mapDiv");
        map.centerAndZoom(new LTPoint(11631256,4003209),6);
        map.addControl(new LTStandMapControl());

        LTEvent.addListener(map,"click",onMapCLick);//在地图被点击时，执行onMapCLick函数
    }

    m_src = "";
    document.getElementById('img_' + type).src = "";
    document.getElementById('tab_' + type + "SHPIC").style.display = "none";
    document.getElementById('tab_' + type + "HIPIC").style.display = "";
    ClearAll();
}
function ChangePage(PAGE)
{
    location.href = 'CreateCode'+ PAGE +".jsp?size="+ size +"&imgtype="+ imgtype +"&level="+ level;
}
function ClearAll()
{
    if(type == "BM"){
        document.getElementById('txt_BMURL').value = "";
        document.getElementById('txt_BMURL').focus();
    }else if(type == "PHONE"){
        document.getElementById('txt_PHONETEL').value = "";
        document.getElementById('txt_PHONETELP').value = "";
        document.getElementById('txt_PHONETEL').focus();
    }else if(type == "BOOKMARK"){
        document.getElementById('txt_BOOKMARKSUB').value = "";
        document.getElementById('txt_BOOKMARKURL').value = "";
        document.getElementById('txt_BOOKMARKSUB').focus();
    }else if(type == "CARD"){
        document.getElementById('txt_CARDFNAME').value = "";
        document.getElementById('txt_CARDLNAME').value = "";
        document.getElementById('txt_CARDTEL').value = "";
        document.getElementById('txt_CARDTELP').value = "";
        document.getElementById('txt_CARDM').value = "";
        document.getElementById('txt_CARDEM').value = "";
        document.getElementById('txt_CARDFNAME').focus();
    }else if(type == "CARDFULL"){
        document.getElementById('txt_CARDFNAME').value = "";
        document.getElementById('txt_CARDLNAME').value = "";
        document.getElementById('txt_CARDTEL').value = "";
        document.getElementById('txt_CARDTELP').value = "";
        document.getElementById('txt_CARDM').value = "";
        document.getElementById('txt_CARDFAX').value = "";
        document.getElementById('txt_CARDFAXP').value = "";
        document.getElementById('txt_CARDEM').value = "";
        document.getElementById('txt_CARDTIL').value = "";
        document.getElementById('txt_CARDDIV').value = "";
        document.getElementById('txt_CARDCOR').value = "";
        document.getElementById('txt_CARDADR').value = "";
        document.getElementById('txt_CARDZIP').value = "";
        document.getElementById('txt_CARDURL').value = "";
        document.getElementById('txt_CARDFNAME').focus();
    }else if(type == "SMS"){
        document.getElementById('txt_SMSSM').value = "";
        document.getElementById('txt_SMSTXT').value = "最多输入40个字";
        document.getElementById('txt_SMSSM').focus();
    }else if(type == "MAIL"){
        document.getElementById('txt_MAILTO').value = "";
        document.getElementById('txt_MAILSUB').value = "";
        document.getElementById('txt_MAILTXT').value = "最多输入30个字";
        document.getElementById('txt_MAILTO').focus();
    }else if(type == "DTXT"){
        document.getElementById('txt_DTXTSUB').value = "";
        document.getElementById('txt_DTXTTXT').value = "最多输入30个字";
        document.getElementById('txt_DTXTSUB').focus();
    }else if(type == "ENC"){
        document.getElementById('txt_ENCTXT').value = "最多输入25个字";
        document.getElementById('txt_ENCPWD').value = "";
    }else if(type == "IMGS"){
        document.getElementById('div_IMGNAME').innerHTML = "<input id='file_IMGNAME' name='UPLOAD' type='file' onchange='EncImgs()' size='30'>";
        document.getElementById('txt_IMGNAME').value = "";
        document.getElementById('tr_IMGNAME').style.display = "none";
        document.getElementById('img_IMGNAME').src = "";
    }else if(type == "GIS"){
        document.getElementById('txt_GISURL').value = "";
    }else if(type == "BLOG"){
        document.getElementById('txt_BLOGSUB').value = "";
        document.getElementById('txt_BLOGURL').value = "";
        document.getElementById('txt_BLOGSUB').focus();
    }
}

function ValueIsTrue()//判断输入是否正确
{
    var strValue = "";
    if(type == "BM"){
        strValue = returnValue('txt_BMURL');
        if(strValue == ""){
            alert('请输入 WAP网址');
            document.getElementById('txt_BMURL').select();
            return false;
        }
    }else if(type == "PHONE"){
        strValue = returnValue('txt_PHONETEL');
        if(strValue == ""){
            alert('请输入 电话号码');
            document.getElementById('txt_PHONETEL').select();
            return false;
        }
        if(isNaN(strValue) || strValue.indexOf(".")!=-1 || strValue < 0){
            alert('电话号码 格式不正确');
            document.getElementById('txt_PHONETEL').select();
            return false;
        }
        strValue = returnValue('txt_PHONETELP');
        if(strValue!=""){
            if(isNaN(strValue) || strValue.indexOf(".")!=-1 || strValue < 0){
                alert('电话号码分机号 格式不正确');
                document.getElementById('txt_PHONETELP').select();
                return false;
            }
        }
    }else if(type == "BOOKMARK"){
        strValue = returnValue('txt_BOOKMARKSUB');
        if(strValue == ""){
            alert('请输入 标题');
            document.getElementById('txt_BOOKMARKSUB').select();
            return false;
        }

        strValue = returnValue('txt_BOOKMARKURL');
        if(strValue == ""){
            alert('请输入 网址');
            document.getElementById('txt_BOOKMARKURL').select();
            return false;
        }
    }else if(type == "CARD"){
        strValue = returnValue('txt_CARDFNAME');
        if(strValue == ""){
            alert('请输入 姓');
            document.getElementById('txt_CARDFNAME').select();
            return false;
        }

        strValue = returnValue('txt_CARDLNAME');
        if(strValue == ""){
            alert('请输入 名');
            document.getElementById('txt_CARDLNAME').select();
            return false;
        }

        if(trim(document.getElementById('txt_CARDTEL').value) == "" && trim(document.getElementById('txt_CARDM').value) == ""){
            alert('固定电话，移动电话 必须填写一个');
            document.getElementById('txt_CARDTEL').select();
            return false;
        }

        strValue = returnValue('txt_CARDTEL');
        if(strValue != ""){
            if(isNaN(strValue) || strValue.indexOf(".")!=-1 || strValue < 0){
                alert('固定电话 格式不正确');
                document.getElementById('txt_CARDTEL').select();
                return false;
            }
        }
        strValue = returnValue('txt_CARDTELP');
        if(strValue != ""){
            if(trim(document.getElementById('txt_CARDTEL').value) == ""){
                alert('请先填写固定电话');
                document.getElementById('txt_CARDTEL').select();
                return false;
            }
            if(isNaN(strValue) || strValue.indexOf(".")!=-1 || strValue < 0){
                alert('固定电话分机号 格式不正确');
                document.getElementById('txt_CARDTELP').select();
                return false;
            }
        }
        strValue = returnValue('txt_CARDM');
        if(strValue != ""){
            if(isNaN(strValue) || strValue.indexOf(".")!=-1 || strValue < 0){
                alert('移动电话 格式不正确');
                document.getElementById('txt_CARDM').select();
                return false;
            }
        }

        strValue = returnValue('txt_CARDM');
        if(strValue != ""){
            if(isNaN(strValue) || strValue.indexOf(".")!=-1 || strValue < 0){
                alert('移动电话 格式不正确');
                document.getElementById('txt_CARDM').select();
                return false;
            }
        }
    }else if(type == "CARDFULL"){
        strValue = returnValue('txt_CARDFNAME');
        if(strValue == ""){
            alert('请输入 姓');
            document.getElementById('txt_CARDFNAME').select();
            return false;
        }

        strValue = returnValue('txt_CARDLNAME');
        if(strValue == ""){
            alert('请输入 名');
            document.getElementById('txt_CARDLNAME').select();
            return false;
        }

        if(trim(document.getElementById('txt_CARDTEL').value) == "" && trim(document.getElementById('txt_CARDM').value) == ""){
            alert('固定电话，移动电话 必须填写一个');
            document.getElementById('txt_CARDTEL').select();
            return false;
        }
        strValue = returnValue('txt_CARDTEL');
        if(strValue != ""){
            if(isNaN(strValue) || strValue.indexOf(".")!=-1 || strValue < 0){
                alert('固定电话 格式不正确');
                document.getElementById('txt_CARDTEL').select();
                return false;
            }
        }
        strValue = returnValue('txt_CARDTELP');
        if(strValue != ""){
            if(trim(document.getElementById('txt_CARDTEL').value) == ""){
                alert('请先填写固定电话');
                document.getElementById('txt_CARDTEL').select();
                return false;
            }
            if(isNaN(strValue) || strValue.indexOf(".")!=-1 || strValue < 0){
                alert('固定电话分机号 格式不正确');
                document.getElementById('txt_CARDTELP').select();
                return false;
            }
        }
        strValue = returnValue('txt_CARDM');
        if(strValue != ""){
            if(isNaN(strValue) || strValue.indexOf(".")!=-1 || strValue < 0){
                alert('移动电话 格式不正确');
                document.getElementById('txt_CARDM').select();
                return false;
            }
        }
        strValue = returnValue('txt_CARDFAX');
        if(strValue != ""){
            if(isNaN(strValue) || strValue.indexOf(".")!=-1 || strValue < 0){
                alert('传真 格式不正确');
                document.getElementById('txt_CARDFAX').select();
                return false;
            }
        }
        strValue = returnValue('txt_CARDFAXP');
        if(strValue != ""){
            if(trim(document.getElementById('txt_CARDFAX').value) == ""){
                alert('请先填写传真');
                document.getElementById('txt_CARDFAX').select();
                return false;
            }
            if(isNaN(strValue) || strValue.indexOf(".")!=-1 || strValue < 0){
                alert('传真分机号 格式不正确');
                document.getElementById('txt_CARDFAXP').select();
                return false;
            }
        }

        strValue = returnValue('txt_CARDM');
        if(strValue != ""){
            if(isNaN(strValue) || strValue.indexOf(".")!=-1 || strValue < 0){
                alert('移动电话 格式不正确');
                document.getElementById('txt_CARDM').select();
                return false;
            }
        }

        strValue = returnValue('txt_CARDZIP');
        if(strValue != ""){
            if(isNaN(strValue) || strValue.indexOf(".")!=-1 || strValue < 0){
                alert('邮编 格式不正确');
                document.getElementById('txt_CARDZIP').select();
                return false;
            }
        }
    }else if(type == "SMS"){
        strValue = returnValue('txt_SMSSM');
        if(strValue == ""){
            alert('请输入 收件人');
            document.getElementById('txt_SMSSM').select();
            return false;
        }
        if(isNaN(strValue) || strValue.indexOf(".")!=-1 || strValue < 0){
            alert('收件人 格式不正确');
            document.getElementById('txt_SMSSM').select();
            return false;
        }

        TextSelect('txt_SMSTXT');
        strValue = returnValue('txt_SMSTXT');
        if(strValue == ""){
            alert('请输入 短信内容');
            document.getElementById('txt_SMSTXT').select();
            return false;
        }
    }else if(type == "MAIL"){
        strValue = returnValue('txt_MAILTO');
        if(strValue == ""){
            alert('请输入 收件人');
            document.getElementById('txt_MAILTO').select();
            return false;
        }
        TextSelect('txt_MAILTXT');
        }else if(type == "DTXT"){
        TextSelect('txt_DTXTTXT');
        strValue = returnValue('txt_DTXTTXT');
        if(strValue == ""){
            alert('请输入 正文');
            document.getElementById('txt_DTXTTXT').select();
            return false;
        }
    }else if(type == "ENC"){
        TextSelect('txt_ENCTXT');
        strValue = returnValue('txt_ENCTXT');
        if(strValue == ""){
            alert('请输入 正文');
            document.getElementById('txt_ENCTXT').select();
            return false;
        }

        strValue = returnValue('txt_ENCPWD');
        if(strValue == ""){
            alert('请输入 加密密码');
            document.getElementById('txt_ENCPWD').select();
            return false;
        }
//        var str = /^[0-9a-zA-Z]+$/;
//        if(!str.test(strValue))
//        {
//            alert("加密密码 只能为数字或者字母");
//            document.getElementById('txt_ENCPWD').select();
//            return false;
//        }
//    }else if(type == "IMGS"){
//        strValue = returnValue('file_IMGNAME');
//        if(strValue == ""){
//            alert('请选择 图片地址');
//            document.getElementById('file_IMGNAME').select();
//            return false;
//        }
//        strValue = returnValue('txt_IMGNAME');
//        if(strValue == ""){
//            alert('请先上传图片');
//            document.getElementById('txt_IMGNAME').select();
//            return false;
//        }
    }else if(type == "GIS"){
        strValue = returnValue('txt_GISURL');
        if(strValue == ""){
            alert('请点击地图选择');
            document.getElementById('txt_GISURL').select();
            return false;
        }
    }else if(type == "BLOG"){
        strValue = returnValue('txt_BLOGSUB');
        if(strValue == ""){
            alert('请输入 名字');
            document.getElementById('txt_BLOGSUB').select();
            return false;
        }

        strValue = returnValue('txt_BLOGURL');
        if(strValue == ""){
            alert('请输入 网址');
            document.getElementById('txt_BLOGURL').select();
            return false;
        }
    }
    return true;
}

function EncImgs()//显示图片
{
    var img = document.getElementById('file_IMGNAME').value;
    document.getElementById('img_IMGNAME').src = 'file:///' + img;
    document.getElementById('tr_IMGNAME').style.display = "";
}

function onMapCLick(p)//在地图被点击时执行的函数，p是点击的位置相对于地图左上角的像素位置
{

    //用户自己的代码
    var point=map.getClickLatLng(p);//根据像素位置p求出经纬度坐标
    if(marker!=null)
    {
        map.removeOverLay(marker);
    }
    marker = new LTMarker(point);//创建并添加标记
    map.addOverLay(marker);


    document.getElementById('txt_GISURL').value = sMapUrl + "?x=" + point.getLongitude() + "&y=" + point.getLatitude() + "&type=" + map.getCurrentZoom();
}

//function getSize()//条码尺寸
//{
//    return  document.getElementById('select3').selectedIndex;
//
//}
//
//function getType()//条码类型
//{
//    return document.getElementById('select2').selectedIndex;
//}

function TextSelect(NAME)//选择输入框
{
    var value = trim(document.getElementById(NAME).value);
    if(value == "最多输入40个字" || value == "最多输入30个字" || value == "最多输入25个字"){
        document.getElementById(NAME).value = "";
    }
}

function ReturnUrl(URL)//转换URL
{
    var url = trim(URL);
    if(url == ""){
        return "";
    }
    if(url.toLowerCase().indexOf("http://")==-1){
        url = "http://" + url;
    }
    return url;
}

