﻿var selectedCityId = 0;
var selectedPointCityName;
var selectedPointCatId = 0;
var selectedPointCatName;
var x = 0;
var y = 0;

function submitIt() {
    document.all.cityId.value = selectedCityId;
    document.all.catId.value = selectedPointCatId;
    document.all.theCatName.value = selectedPointCatName;
    document.all.theCityName.value = selectedPointCityName;
    document.all.x.value = x;
    document.all.y.value = y;

    if(document.all.userName.value == null || document.all.userName.length == 0 || document.all.userName.value == "") {
        alert("请输入用户名");
        return;
    }
    if(document.all.password1.value == null || document.all.password1.length == 0 || document.all.password1.value == "") {
        alert("请输入密码");
        return;
    }
    if(document.all.isRegister.value == 1) {
        if(document.all.password2.value == null || document.all.password2.length == 0 || document.all.password2.value == "") {
            alert("请输入第二次密码");
            return;
        }
        if(document.all.email.value == null || document.all.email.length == 0 || document.all.email.value == "") {
            alert("请输入Email");
            return;
        }
        if(document.all.mobilePhone.value == null || document.all.mobilePhone.length == 0 || document.all.mobilePhone.value == "") {
            alert("请输入手机号码");
            return;
        }
        if(!isNumber(document.all.mobilePhone.value) || (document.all.mobilePhone.value.length != 11)) {
            alert("手机号码格式不对");
            return;
        }
        
        if(document.all.password2.value != document.all.password1.value) {
            alert("两次密码不一致");
            return;
        }
        if(!checkEmail(document.all.email.value)) {
            alert("Email格式不对");
            return;
        }
    }

    if(document.all.catId.value == 0) {
        alert("请选择分类");
        return;
    }
    if(document.all.x.value == 0 || document.all.y.value == 0) {
        alert("请在地图上标注企业的位置");
        return;
    }
    if(document.all.title.value == null || document.all.title.length == 0 || document.all.title.value == "") {
        alert("请输入店名");
        return;
    }
    if(document.all.address.value == null || document.all.address.length == 0 || document.all.address.value == "") {
        alert("请输入详细地址");
        return;
    }
    if(document.all.phone.value == null || document.all.phone.length == 0 || document.all.phone.value == "") {
        alert("请输入电话号码");
        return;
    }
    if(document.all.validator.value == null || document.all.validator.length == 0 || document.all.validator.value == "") {
        alert("请输入验证码");
        return;
    }
    
    var oEditor = FCKeditorAPI.GetInstance('detail') ;
    var oDOM = oEditor.EditorDocument ;
    document.all.clearDetail.value = oDOM.body.innerText;
    
    document.forms[0].submit();
}

function hideCity() {
    var daps = document.all.cityDiv.style;
    daps.display = "none";
}

function selectCity(cityId, cityName) {
    selectedCityId = cityId;
    selectedPointCityName = cityName;
    document.getElementById("cityName").innerText = cityName;
    hideCity();
}

function showCity(tt)
{
    var daps = document.all.cityDiv.style;
    if(daps.display == null || daps.display == "" || daps.display.length == 0) {
        hideCity();
        return;
    }
    
    var ttop = tt.offsetTop; //TT控件的定位点高   
    var thei = tt.clientHeight; //TT控件本身的高   
    var tleft = tt.offsetLeft; //TT控件的定位点宽   
    var ttyp = tt.type; //TT控件的类型   
    while (tt = tt.offsetParent) {
        ttop += tt.offsetTop;
        tleft += tt.offsetLeft;
    }

    daps.top = ttop + thei + 4;  //层的Y坐标
    daps.left = tleft + 1;  //层的X坐标
    daps.display = ""; //层显示
}

function hideCat() {
    var daps = document.all.pointCatDiv.style;
    daps.display = "none";
}

function selectCat(catId, catName) {
    selectedPointCatId = catId;
    document.getElementById("catName").innerText = catName;
    selectedPointCatName = catName;
    hideCat();
}

function showCat(tt)
{
    var daps = document.all.pointCatDiv.style;
    if(daps.display == null || daps.display == "" || daps.display.length == 0) {
        hideCat();
        return;
    }
    
    var ttop = tt.offsetTop; //TT控件的定位点高   
    var thei = tt.clientHeight; //TT控件本身的高   
    var tleft = tt.offsetLeft; //TT控件的定位点宽   
    var ttyp = tt.type; //TT控件的类型   
    while (tt = tt.offsetParent) {
        ttop += tt.offsetTop;
        tleft += tt.offsetLeft;
    }

    daps.top = ttop + thei + 4;  //层的Y坐标
    daps.left = tleft + 1;  //层的X坐标
    daps.display = ""; //层显示
}

function checkEmail(cEmail)
{
  var arr=cEmail.split('@');
  var c=true;
  if(arr.length!=2)
    c=false;
  else if(!arr[0].length||!arr[1].length)
    c=false;
  else if(arr[1].split('.').length<2)
    c=false;
  else if(!arr[1].split('.')[0].length||arr[1].split('.')[1].length<2||arr[1].split('.')[1].length>4)
    c=false;
  return c;
}

function isNumber(phoneNum){
	
 strRef = "1234567890";
 
 for (i=0;i<phoneNum.length;i++) {
  tempChar= phoneNum.substring(i,i+1);
  if (strRef.indexOf(tempChar,0)==-1) {
   return false; 
  }
 }
 return true;
}
