var iTitleCount=0,iSortCount1=0,iSortCount2=0,iSortCount3=0,iAddressCount1=0,iAddressCount2=0,iAddressCount3=0,iPicCount=0,iContentCount1=0,iContentCount2=0,iContentCount3=0,iContentCount4=0,iContentCount5=0,iContentCounta1=0,iContentCounta2=0,iContentCounta3=0,iContentCounta4=0,iContentCounta5=0;
var	templateBox="",sTelTemp="",sPhoneTemp="",sQqTemp="",sNameTemp="",sPicListTemp="",sPriceTemp="",sTopTemp="",sTopTemp="",sPicCountTemp="";

function acTemp()
{
	var template=$("#showBox").html();
	var sTempStr = template.match(/\${kTitle,[\d]+}/);
    if (sTempStr!=null)
    {
            iTitleCount=sTempStr[0].match(/\d+/)[0];
            template = template.replace(sTempStr[0],"${kTitle}");
    }
	sTempStr = template.match(/\${kSort,[\d]+}/);
    if (sTempStr!=null)
    {
          	iSortCount1=sTempStr[0].match(/\d+(?!,)/)[0];
			template = template.replace(sTempStr[0],"${kSort}");
    }
	sTempStr =  template.match(/\$\{kSort1,[\d]+\}/);
    if (sTempStr!=null)
    {
    	   	iSortCount2=sTempStr[0].match(/\d+(?!,)/)[0];
			template = template.replace(sTempStr[0],"${kSort1}");
	}
	sTempStr =  template.match(/\$\{kSort2,[\d]+\}/);
    if (sTempStr!=null)
    {
    	   	iSortCount3=sTempStr[0].match(/\d+(?!,)/)[0];
			template = template.replace(sTempStr[0],"${kSort2}");
	}
	sTempStr =  template.match(/\$\{kAddress,[\d]+\}/);
    if (sTempStr!=null)
    {
    	   	iAddressCount1=sTempStr[0].match(/\d+/)[0];
			template = template.replace(sTempStr[0],"${kAddress}");
	}
	sTempStr =  template.match(/\$\{kAddress1,[\d]+\}/);
    if (sTempStr!=null)
    {
    	   	iAddressCount2=sTempStr[0].match(/\d+(?!,)/)[0];
			template = template.replace(sTempStr[0],"${kAddress1}");
	}
	sTempStr =  template.match(/\$\{kAddress2,[\d]+\}/);
    if (sTempStr!=null)
    {
    	   	iAddressCount3=sTempStr[0].match(/\d+(?!,)/)[0];
			template = template.replace(sTempStr[0],"${kAddress2}");
	}
    sTempStr  = template.match(/<!--[^!]*?\${kTel}[^!]*?-->/);
    if (sTempStr!=null)
    {
			sTelTemp=sTempStr[0];
			template = template.replace(sTempStr[0],"${kTel}");
            sTelTemp = sTelTemp.replace("<!--", "").replace("-->", "");
    }
	sTempStr  = template.match(/<!--[^!]*?\${kPhone}[^!]*?-->/);
    if (sTempStr!=null)
    {
			sPhoneTemp=sTempStr[0];
			template = template.replace(sTempStr[0],"${kPhone}");
            sPhoneTemp = sPhoneTemp.replace("<!--", "").replace("-->", "");
    }
	sTempStr  = template.match(/<!--[^!]*?\${kQq}[^!]*?-->/);
    if (sTempStr!=null)
    {
			sQqTemp =sTempStr[0];
			template = template.replace(sTempStr[0],"${kQq}");
            sQqTemp  = sQqTemp .replace("<!--", "").replace("-->", "");
    }
	
	sTempStr  = template.match(/<!--[^!]*?\${kName}[^!]*?-->/);
    if (sTempStr!=null)
    {
			sNameTemp =sTempStr[0];
			template = template.replace(sTempStr[0],"${kName}");
            sNameTemp  = sNameTemp .replace("<!--", "").replace("-->", "");
    }
	
	sTempStr  = template.match(/<!--[^!]*?\$\{kPicList,[\d]+\}[^!]*?-->/);
    if (sTempStr!=null)
    {
			sPicListTemp =sTempStr[0];
			template = template.replace(sTempStr[0],"${kPicList}");
			sTempStr=sTempStr.match(/{kPicList,[\d]+/);
			 if (sTempStr!=null)
    		{
				iPicCount=sTempStr[0].match(/\d+/);
			}
            sPicListTemp= sPicListTemp.replace("<!--", "").replace("-->", "").replace("${kPicList," + iPicCount+ "}", "");
    }
	sTempStr  = template.match(/<!--[^!]*?\${kPrice1}[^!]*?-->/);
    if (sTempStr!=null)
    {
			sPriceTemp =sTempStr[0];
			template = template.replace(sTempStr[0],"${kPrice1}");
            sPriceTemp= sPriceTemp.replace("<!--", "").replace("-->", "");
    }
	sTempStr  = template.match(/<!--[^!]*?\${kPicCount1}[^!]*?-->/);
    if (sTempStr!=null)
    {
			sPicCountTemp =sTempStr[0];
			template = template.replace(sTempStr[0],"${kPicCount1}");
            sPicCountTemp= sPicCountTemp.replace("<!--", "").replace("-->", "");
    }
	
	sTempStr  = template.match(/<!--[^!]*?\${kTop}[^!]*?-->/);
    if (sTempStr!=null)
    {
			sTopTemp =sTempStr[0];
			template = template.replace(sTempStr[0],"${kTop}");
            sTopTemp= sTopTemp.replace("<!--", "").replace("-->", "");
    }
	
	sTempStr  = template.match(/\$\{kContent,[\d]+,[\d]+,[\d]+,[\d]+,[\d]+\}/);
    if (sTempStr!=null)
    {
			var sArrContentCount = sTempStr[0].match(/[\d]+,[\d]+,[\d]+,[\d]+,[\d]+/)[0].split(',');
			 if (sArrContentCount.length == 5)
            {
                iContentCount1=sArrContentCount[0];
				iContentCount2=sArrContentCount[1];
				iContentCount3=sArrContentCount[2];
				iContentCount4=sArrContentCount[3];
				iContentCount5=sArrContentCount[4];
            }
			template = template.replace(sTempStr[0],"${kContent}");
    }
	
	sTempStr  = template.match(/\$\{kContentText,[\d]+,[\d]+,[\d]+,[\d]+,[\d]+\}/);
    if (sTempStr!=null)
    {
			var sArrContentCount = sTempStr[0].match(/[\d]+,[\d]+,[\d]+,[\d]+,[\d]+/)[0].split(',');
			 if (sArrContentCount.length == 5)
            {
                iContentCounta1=sArrContentCount[0];
				iContentCounta2=sArrContentCount[1];
				iContentCounta3=sArrContentCount[2];
				iContentCounta4=sArrContentCount[3];
				iContentCounta5=sArrContentCount[4];
            }
			template = template.replace(sTempStr[0],"${kContentText}");
    }
    templateBox=template;
	$("#showBox").html(template);
	preview();
}
function preview()
{
	template=templateBox;
	var sPrice="<span>面议</span>"; 
	if($("#price").val()!="")
	{
		var vPrice=parseFloat($("#price").val());
		if(vPrice>10000)
		{
			vPrice=vPrice/10000;
			sPrice =vPrice+"<span>万</span>";
		}
		else
		{
			sPrice =vPrice;
		}
		template = template.replace("${kPrice1}", sPriceTemp.replace("${kPrice1}", sPrice));
	}
	else
	{
		template = template.replace("${kPrice1}", "");
	}
	template = template.replace("${kPrice}", sPrice);
	var sTitleAll = _q("title").value;
	var sTitle=sTitleAll;
    if (iTitleCount != 0)
    {
    	if (sTitleAll.length > iTitleCount)
        {
                sTitle = sTitleAll.substring(0, iTitleCount);
        }
    }
	template = template.replace("${kTitleAll}", sTitleAll);
    template = template.replace("${kTitle}",sTitle);
	
	if (iSortCount1 != 0)
    {
            if (sSortName.length > iSortCount1)
            {
                sSortName = sSortName.substring(0, iSortCount1);
            }
     }
	if (iSortCount2 != 0)
    {
            if (sSortName1.length > iSortCount2)
            {
               	sSortName1 = sSortName1.substring(0, iSortCount2);
            }
     }
	if (iSortCount3 != 0)
    {
            if (sSortName2.length > iSortCount3)
            {
                sSortName2 = sSortName2.substring(0, iSortCount3);
            }
     }
 	template = template.replace("${kSort}", sSortName);
    template = template.replace("${kSort1}",sSortName1);
   	template = template.replace("${kSort2}",sSortName2);
	var sAddressName="";
	var sAddressName1="";
	var sAddressName2="";
    if (iAddressCount1 != 0)
    {
            if (sAddressName.length > iAddressCount1)
            {
                sAddressName = sAddressName.substring(0, iAddressCount1);
            }
     }

     if (iAddressCount2 != 0)
     {
            if (sAddressName1.length > iAddressCount2)
            {
                sAddressName1 = sAddressName1.substring(0, iAddressCount2);
            }
      }

      if (iAddressCount3 != 0)
      {
            if (sAddressName2.length > iAddressCount3)
            {
                sAddressName2 = sAddressName2.substring(0, iAddressCount3);
            }
      }
	template = template.replace("${kAddress}", sAddressName);
    template = template.replace("${kAddress1}",sAddressName1);
    template = template.replace("${kAddress2}",sAddressName2);
   	template = template.replace("${kMid}","");
    template = template.replace("${kSortId}","");
    template = template.replace("${kSortId1}", "");
    template = template.replace("${kSortId2}", "");
    template = template.replace("${kAddressId}","");
    template = template.replace("${kAddressId1}", "");
    template = template.replace("${kAddressId2}", "");
	template = template.replace("${kIp}", "");
    template = template.replace("${kComment}", "");
	
	var iContact = 0;
	var sTel=$("#tel").val();
    if (sTel != "")
    {
     		iContact++;
            if (/1[\d]{10}/.test(sTel))
            {
                template = template.replace("${kTel}", sTelTemp.replace("${kTel}",sTel));
                template = template.replace("${kContact}", "电话：<span onclick=\"fTelSeth(this)\" onmouseover=\"fTelInfo(this,1)\" onmouseout=\"fTelInfo(this,2)\">" + sTel+ "</span>");
                template = template.replace("${kContactWap}", "<span>电话：</span><strong>" + sTel + "</strong><a href=\"tel:" + sTel + "\" class=\"bd\">拨打</a><a href=\"sms:" + sTel + "\" class=\"dx\">短信</a>");
            }
        }
        else
        {
            template = template.replace("${kTel}", "");
        }
		var sQq=$("#qq").val();
        if (sQq != "")
        {
            iContact++;
            template = template.replace("${kQq}", sQqTemp.replace("${kQq}",sQq));
            template = template.replace("${kContact}", "QQ：<span title=\"点击这里给我发消息\" onclick=\"fQQTalk('" + sQq + "')\">" + sQq + "</span>");
            template = template.replace("${kContactWap}", "<span>QQ：</span><strong>" + sQq+ "</strong>");
        }
        else
        {
            template = template.replace("${kQq}", "");
        }
        template = template.replace("${kContact}", "");
        template = template.replace("${kContactWap}", "");
		var sName=$("#name").val();
        if (sName != "")
        {
            iContact++;
            template = template.replace("${kName}", sNameTemp.replace("${kName}", sName));
        }
        else
        {
            template = template.replace("${kName}", "");
        }
		
		var iCon = 0, iConText = 0;
        switch (iContact)
        {
            case 0:
                iCon = iContentCount1;
                iConText = iContentCounta1;
                break;
            case 1:
                iCon = iContentCount2;
                iConText = iContentCounta2;
                break;
            case 2:
                iCon = iContentCount3;
                iConText = iContentCounta3;
                break;
            case 3:
                iCon = iContentCount4;
                iConText = iContentCounta4;
                break;
            case 4:
                iCon = iContentCount5;
                iConText = iContentCounta5;
                break;
        }
		sContent=$("#content").val();
		sContentText=$("#content").val();
        if (iCon != 0 && sContent.length > iCon)
        {
            sContent = sContent.substring(0,iCon)+"…";
        }
        if (iConText != 0 && sContentText.length > iConText)
        {
            sContentText = sContentText.substring(0,iConText);
        }

        template = template.replace("${kContent}", sContent);
        template = template.replace("${kContentText}", sContentText);

        template = template.replace("${kLink}", "#nogo");

       template= template.replace("${kWapLink}", "#nogo");
	   

	   	var iPic = 0;
       	var sPicList = "";
        var iPicCountTemp = 10000;
        if (iPicCount != 0)
        {
            iPicCountTemp = iPicCount;
        }
		if($("#pic").length>0)
		{
			var sPic=$("#pic").val().split(',');
        	if (sPic.length >0)
        	{
				if(sPic[0]!="")
				{
            		iPic = 1;
            		sPicList += sPicListTemp.replace("${kPic}","/" + sPic[0]);
           	 		template = template.replace("${kPic}","/" + sPic[0]);
            		iPicCountTemp--;
				}
        		else
        		{
            		template = template.replace("${kPic}","/images/noPic.png");
        		}
        	}
			if (sPic.length>1)
        	{
            	iPic = sPic.length-1;
           		 for (t = 1; t < sPic.length; t++)
            	{
                	if (sPic[t] != "")
                	{
                    	if (iPicCountTemp > 0)
                    	{
                        	iPicCountTemp--;
                        	sPicList += sPicListTemp.replace("${kPic}", "/" +sPic[t]);
                    	}
                	}
            	}
            	template = template.replace("${kPic1}","/" +sPic[1]);
        	}
        	else
        	{
            	template = template.replace("${kPic1}", "/images/noPic.png");
        	}
		}
		else
		{
			template = template.replace("${kPic}","/images/noPic.png");
			template = template.replace("${kPic1}", "/images/noPic.png");
		}

      
        template = template.replace("${kPicList}", sPicList);
        if (iPic != 0)
        {
            template = template.replace("${kPicCount1}", sPicCountTemp.replace("${kPicCount1}", iPic));
        }
        else
        {
            template = template.replace("${kPicCount1}", "");
        }
        template = template.replace("${kPicCount}", iPic);

        
        var myDate = new Date();
        template = template.replace("${kDate}",(myDate.getMonth()+1)+"月"+myDate.getDate());
		var iTop=0;
        if (iTop != 0)
        {
            template = template.replace("${kTop}", sTopTemp.replace("${kTop}", iTop));
            template = template.replace("${kDate1}", "");
            template = template.replace("${kDate2}", "");
        }
        else
        {
            template = template.replace("${kTop}", "");
            template = template.replace("${kDate1}", "");
            template = template.replace("${kDate2}","");
        }
	$("#showBox").html(template);
}// JavaScript Document