function showtip(tip) {
    var ajax = document.getElementById("infoa");
    ajax.innerHTML = tip;
    if (tip != "") 
	{
		ajax.style.display="block";
		alert(tip);
	}
	else
	{
		ajax.style.display="none";
	}	
    return true;
}

function checktxt_Title(){
	var txt_Title = document.getElementById("txt_Title");
	if(!isLengthBetween(txt_Title.value, 12, 64)){
		showtip("企业名字应该在12~64字节，一个汉字为两个字节");
		txt_Title.focus();
		return false;
	}
	return true;
}

function checktxt_ShengFen() {
    var txt_DaLei = document.getElementById("txt_ShengFen");
    var txt_XiaoLei = document.getElementById("txt_ChengShi");
    if (txt_DaLei.value < 1) {
        showtip("没有选择省份！");
		txt_DaLei.focus();
        return false;
    }
    if (txt_XiaoLei.value < 32) {
        showtip("没有选择地区！");
		txt_XiaoLei.focus();
        return false;
    }
    return true;
}

function checktxt_DaLei() {
    var txt_DaLei = document.getElementById("txt_DaLei");
    var txt_XiaoLei = document.getElementById("txt_XiaoLei");
    if (txt_DaLei.value < 1) {
        showtip("没有选择分类！");
		txt_DaLei.focus();
        return false;
    }
    if (txt_XiaoLei.value < 1) {
        showtip("没有选择次级分类！");
		txt_XiaoLei.focus();
        return false;
    }
    return true;
}

function checktxt_FaRen(){
	var txt = document.getElementById("txt_FaRen");
	if(!isLengthBetween(txt.value, 4, 10)){
		showtip("法人代表应该在4~10字节，一个汉字为两个字节");
		txt.focus();
		return false;
	}
	return true;
}

function checktxt_YZM() {
    var txt = document.getElementById("txt_YZM");
    if (!isLengthBetween(txt.value, 4, 4)) {
        showtip("验证码为四位数字");
        txt.focus();
        return false;
    }
    return true;
}

function checktxt_LianXiRen(){
	var txt = document.getElementById("txt_LianXiRen");
	if(!isLengthBetween(txt.value, 4, 10)){
		showtip("联系人应该在4~10字节，一个汉字为两个字节");
		txt.focus();
		return false;
	}
	return true;
}

function checktxt_ShouJi(){
	var txt = document.getElementById("txt_ShouJi");
	if(!isLengthBetween(txt.value, 6, 20)){
		showtip("手机号格式错误");
		txt.focus();
		return false;
	}
	return true;
}

function checktxt_DianHua(){
	var txt = document.getElementById("txt_DianHua");

	if(!isLengthBetween(txt.value, 6, 20)){
		showtip("电话号码格式错误，分机号以/分开");
		txt.focus();
		return false;
	}
	return true;
}

function checktxt_YouXiang(){
	var txt = document.getElementById("txt_YouXiang");
	
	if(txt.value!="")
	{
		if(!isLengthBetween(txt.value, 6, 20)){
			showtip("电子邮箱格式错误");
			txt.focus();
			return false;
		}
	}
	
	return true;
}

function checktxt_QQ(){
	var txt = document.getElementById("txt_QQ");
	if(txt.value!="")
	{
		if(!isLengthBetween(txt.value, 5, 11)){
			showtip("QQ号码格式错误");
			txt.focus();
			return false;
		}
	}
	return true;
}

function checktxt_ChuanZhen(){
	var txt = document.getElementById("txt_ChuanZhen");
	if(!isLengthBetween(txt.value, 6, 20)){
	    showtip("传真号码格式错误，分机号以/分开");
		txt.focus();
		return false;
	}
	return true;
}

function checktxt_ZiJin() {
    var txt = document.getElementById("txt_ZiJin");
    if (!isLengthBetween(txt.value, 1, 20)) {
        showtip("注册资金不能为空");
		txt.focus();
        return false;
    }
    return true;
}

function checktxt_ZhuCeDi() {
    var txt = document.getElementById("txt_ZhuCeDi");
    if (!isLengthBetween(txt.value, 2, 20)) {
        showtip("注册地不能为空");
		txt.focus();
        return false;
    }
    return true;
}

function checktxt_YuanGongShu() {
    var txt = document.getElementById("txt_YuanGongShu");
    if (!isLengthBetween(txt.value, 1, 20)) {
        showtip("员工人数不能为空");
		txt.focus();
        return false;
    }
    return true;
}

function checktxt_DiZhi(){
	var txt = document.getElementById("txt_DiZhi");
	if(!isLengthBetween(txt.value, 16, 64)){
		showtip("地址应该在16~64字节，尽量精确");
		txt.focus();
		return false;
	}
	return true;
}

function checktxt_YouBian() {
    var txt = document.getElementById("txt_YouBian");
    if (!isLengthBetween(txt.value, 6, 6)) {
        showtip("邮编应该是六位数字");
		txt.focus();
        return false;
    }
    return true;
}

function checktxt_WangZhan(){
	var txt = document.getElementById("txt_WangZhan").value;
	if(txt!=""){
		var regex=/^(http:\/\/)?([\w-]+\.)+[\w-]+(\/[\w-   \.\/?%&=]*)?$/i; 
		if(!regex.test(txt)){
			showtip("网站格式如http://www.okbole.com/，如暂无网站，请留空");
			txt.focus();
			return false;
		}
	}
	return true;
}

function checktxt_Content(){
	var txt = document.getElementById("txt_Content");
	if(!isLengthBetween(txt.value, 16, 1000)){
	    showtip("简介应该在16~1000字节，一个汉字为两个字节");
	    txt.focus();
		return false;
	}
	return true;
}

function stringreplace(str) {
    str = encodeURIComponent(trim(str))    
    return str;
}

function _submit() {
    showtip("");
	
	var but_TJ=document.getElementById("but_TJ");
	but_TJ.value="正在提交企业信息,请稍等...";
	but_TJ.disabled="disabled";
	
	var QiYeMing=trim(document.getElementById("txt_Title").value);
	
    var Title = stringreplace(QiYeMing);
    var ShengFen=stringreplace(document.getElementById("txt_ShengFen").options[document.getElementById("txt_ShengFen").selectedIndex].text);
    var ChengShi = stringreplace(document.getElementById("txt_ChengShi").options[document.getElementById("txt_ChengShi").selectedIndex].text);
    var SortID = stringreplace(document.getElementById("txt_XiaoLei").value);
    var FaRen = stringreplace(document.getElementById("txt_FaRen").value);
    var LianXiRen = stringreplace(document.getElementById("txt_LianXiRen").value);
    var ChengHu = stringreplace(document.getElementById("txt_ChengHu").value);
    var ShouJi = stringreplace(document.getElementById("txt_ShouJi").value);
    var DianHua = stringreplace(document.getElementById("txt_DianHua").value);
	var YouXiang = stringreplace(document.getElementById("txt_YouXiang").value);
	var QQ = stringreplace(document.getElementById("txt_QQ").value);
    var ChuanZhen = stringreplace(document.getElementById("txt_ChuanZhen").value);
    var ZiJin = stringreplace(document.getElementById("txt_ZiJin").value+"万元");
    var ZhuCeDi = stringreplace(document.getElementById("txt_ZhuCeDi").value);
    var YuanGongShu = stringreplace(document.getElementById("txt_YuanGongShu").value);
    var DiZhi = stringreplace(document.getElementById("txt_DiZhi").value);
    var YouBian = stringreplace(document.getElementById("txt_YouBian").value);
    var WangZhan = stringreplace(document.getElementById("txt_WangZhan").value);
    var Content = stringreplace(document.getElementById("txt_Content").value);

    var YZM = stringreplace(document.getElementById("txt_YZM").value);

    var sendUrl = "/xn/article/BeyondAdd.aspx?TypeNum=5&Title=" + Title;
	sendUrl += "&yzm=" + YZM;
    sendUrl += "&ShengFen=" + ShengFen;
    sendUrl += "&ChengShi=" + ChengShi;
    sendUrl += "&SortID=" + SortID;
    sendUrl += "&FaRen=" + FaRen;
    sendUrl += "&LianXiRen=" + LianXiRen;
    sendUrl += "&ChengHu=" + ChengHu;
    sendUrl += "&ShouJi=" + ShouJi;
    sendUrl += "&DianHua=" + DianHua;
	sendUrl += "&YouXiang=" + YouXiang;
	sendUrl += "&QQ=" + QQ;
	sendUrl += "&ChuanZhen=" + ChuanZhen;
    sendUrl += "&ZiJin=" + ZiJin;
    sendUrl += "&ZhuCeDi=" + ZhuCeDi;
    sendUrl += "&YuanGongShu=" + YuanGongShu;
    sendUrl += "&DiZhi=" + DiZhi;
    sendUrl += "&YouBian=" + YouBian;
    sendUrl += "&WangZhan=" + WangZhan;
    sendUrl += "&Content=" + Content;

    var isExist = sendRequest(sendUrl);
	
	if(isExist.indexOf("http://www.okbole.com/") ==0 )
	{
        var ajax = document.getElementById("infob");
        ajax.innerHTML = '<h3>您的提交我们已经收到，12个小时内就会更新到相应分类。</h3>1、请记住您的公司网站地址：<br />　　<a href="'+isExist+'" target="_blank">'+isExist+'</a><br />　　<a href="'+isExist+'" target="_blank">'+QiYeMing+'</a><br />　　<a href="#" onclick="SetHomepage(\''+isExist+'\');">设为首页</a><br />　　<a href="#" onclick="AddFavorite(\''+isExist+'\', \''+QiYeMing+'\')">加入收藏</a><br />2、本站数据准确可靠，每日更新，用户活跃，是您理想的推广展示平台；<br />3、如果您需要在本站推广您的企业，可以<a href="http://www.okbole.com/fuwu.html#lxwm" target="_blank">联系我们</a>，会有专人尽快联系您；<br />4、如果你需要同行业或者竞争对手的数据资料，请联系我们获得最新资料；<br />5、感谢您对本站的支持，让我们共同努力做得更好!';
        return true;
    }
	
    showtip(isExist);
	changeVcode();
	
    return false;
}

function _company() {
    if (!checktxt_Title()) return false;
    if (!checktxt_ShengFen()) return false;
    if (!checktxt_DaLei()) return false;
    if (!checktxt_FaRen()) return false;
    if (!checktxt_LianXiRen()) return false;
    if (!checktxt_ShouJi()) return false;
    if (!checktxt_DianHua()) return false;
	if (!checktxt_YouXiang()) return false;
	if (!checktxt_QQ()) return false;
    if (!checktxt_ChuanZhen()) return false;
    if (!checktxt_ZiJin()) return false;
    if (!checktxt_ZhuCeDi()) return false;
    if (!checktxt_YuanGongShu()) return false;
    if (!checktxt_DiZhi()) return false;
    if (!checktxt_YouBian()) return false;
    if (!checktxt_WangZhan()) return false;
    if (!checktxt_Content()) return false;
    if (!checktxt_YZM()) return false;
    if (!_submit()) return false;
    return true;
}

function isLengthBetween(value, minLength, maxLength) {
    value = trim(value);
    if (maxLength > 0) {
        return (value.replace(/[^\x00-\xff]/g, "**").length > (minLength - 1) && value.replace(/[^\x00-\xff]/g, "**").length < (maxLength + 1));
    }
    else {
        return (value.replace(/[^\x00-\xff]/g, "**").length > (minLength - 1));
    }
}

function trim(value){
	if (value.length == 0) return value;
	return ltrim(rtrim(value));
}

function ltrim(value){
	if (value.length == 0) return value;
	var re = /^\s*/;
	return value.replace(re,'');
}

function rtrim(value){
	if (value.length == 0) return value;
	var re = /\s*$/;
	return value.replace(re,'');
}

function sendRequest(url) {
	return send_request(url, false);
}

function send_request(url, isAsynchronous) {
    var xmlHttp = null;
    if (window.XMLHttpRequest) {   // Mozilla 浏览器
        xmlHttp = new XMLHttpRequest();
        if (xmlHttp.overrideMimeType) { // 设置MIME类别
            xmlHttp.overrideMimeType("text/xml");
        }
    }
    else if (window.ActiveXObject) { // IE浏览器
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) { }
        }
    }
    if (xmlHttp == null) { // 异常，创建对象实例失败；
        return false;
    }
    xmlHttp.open("GET", url, isAsynchronous);   // 同步方式；
    xmlHttp.send(null);
    if (!isAsynchronous) {
        return xmlHttp.responseText;
    }
}

function loadyzm() {
    if (document.getElementById("img_CheckCode").style.display != "inline-block") {
        changeVcode();
        document.getElementById("img_CheckCode").style.display = "inline-block";
    }

}

function changeVcode() {
    document.getElementById("img_CheckCode").src = "/xn/comm_CheckCode.aspx?k=" + Math.random();
}