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_LeiXing() {
    var txt_LeiXing = document.getElementById("txt_LeiXing");
    if (txt_LeiXing.value < 1) {
        showtip("没有选择商机类型！");
		txt_LeiXing.focus();
        return false;
    }
    return true;
}

function checktxt_Title(){
	var txt_Title = document.getElementById("txt_Title");
	if(!isLengthBetween(txt_Title.value, 10, 100)){
		showtip("商机标题应该在10~100字节，一个汉字为两个字节");
		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_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_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_DiZhi(){
	var txt = document.getElementById("txt_DiZhi");
	if(!isLengthBetween(txt.value, 16, 64)){
		showtip("地址应该在16~64字节，尽量精确");
		txt.focus();
		return false;
	}
	return true;
}

function checktxt_JieShu(){
	var txt = document.getElementById("txt_JieShu");
	if(txt.value<7 || txt.value>365){
		showtip("商机过期时间应该小于一年，且不小于一周，即在7~365天");
		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 ShangJi=trim(document.getElementById("txt_Title").value);	
    var Title = stringreplace(ShangJi);
	var SortID = stringreplace(document.getElementById("txt_LeiXing").value);
	var LeiXing = stringreplace(document.getElementById("txt_LeiXing").options[document.getElementById("txt_LeiXing").selectedIndex].text);
    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 FenLei1=stringreplace(document.getElementById("txt_DaLei").options[document.getElementById("txt_DaLei").selectedIndex].text);
    var FenLei2 = stringreplace(document.getElementById("txt_XiaoLei").options[document.getElementById("txt_XiaoLei").selectedIndex].text);
	var MingCheng = stringreplace(document.getElementById("txt_MingCheng").value);
    var LianXiRen = stringreplace(document.getElementById("txt_LianXiRen").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 DiZhi = stringreplace(document.getElementById("txt_DiZhi").value);    
    var JieShu = stringreplace(document.getElementById("txt_JieShu").value);
    var Content = stringreplace(document.getElementById("txt_Content").value);

    var YZM = stringreplace(document.getElementById("txt_YZM").value);
	
	var now = new Date();
	now.addDays(parseInt(JieShu));
	JieShu=now.Format("yyyy-MM-dd hh:mm:ss");
	

    var sendUrl = "/xn/article/BeyondAdd.aspx?TypeNum=6&Title=" + Title;
	sendUrl += "&yzm=" + YZM;
	sendUrl += "&SortID=" + SortID;
    sendUrl += "&LeiXing=" + LeiXing;
    sendUrl += "&ShengFen=" + ShengFen;
    sendUrl += "&ChengShi=" + ChengShi;
	sendUrl += "&FenLei1=" + FenLei1;
    sendUrl += "&FenLei2=" + FenLei2;    
    sendUrl += "&LianXiRen=" + LianXiRen;
    sendUrl += "&MingCheng=" + MingCheng;
    sendUrl += "&DianHua=" + DianHua;
	sendUrl += "&YouXiang=" + YouXiang;
	sendUrl += "&QQ=" + QQ;
    sendUrl += "&JieShu=" + JieShu;
    sendUrl += "&DiZhi=" + DiZhi;
    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">'+ShangJi+'</a><br />　　<a href="#" onclick="SetHomepage(\''+isExist+'\');">设为首页</a><br />　　<a href="#" onclick="AddFavorite(\''+isExist+'\', \''+ShangJi+'\')">加入收藏</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_LeiXing()) return false;
    if (!checktxt_ShengFen()) return false;
    if (!checktxt_DaLei()) return false;
    if (!checktxt_LianXiRen()) return false;
    if (!checktxt_DianHua()) return false;
	if (!checktxt_YouXiang()) return false;
	if (!checktxt_QQ()) return false;
    if (!checktxt_DiZhi()) return false;
	if (!checktxt_JieShu()) 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();
}

Date.prototype.Format = function(fmt) 
{
    //author: meizz 
    var o =
    { 
        "M+" : this.getMonth() + 1, //月份 
        "d+" : this.getDate(), //日 
        "h+" : this.getHours(), //小时 
        "m+" : this.getMinutes(), //分 
        "s+" : this.getSeconds(), //秒 
        "q+" : Math.floor((this.getMonth() + 3) / 3), //季度 
        "S" : this.getMilliseconds() //毫秒 
    }; 
    if (/(y+)/.test(fmt)) 
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); 
    for (var k in o) 
        if (new RegExp("(" + k + ")").test(fmt)) 
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); 
    return fmt; 
}


Date.prototype.addDays = function(d)
{
    this.setDate(this.getDate() + d);
};
