///******************************************************    
///	FileName: Purchase.js
///	Action: 会员中心求购添加页面JS处理文件
///	Copyright(c)  2004-2008 网胜科技公司技术开发部
///	Writer: XFY
///	Create Date: 2008-12-17
///	Rewriter:
///	Rewrite Date:
///******************************************************  
var rightIcon="../../images/websen.gif"
var rightIcons="../../images/icon_nothing.gif";
var txtjbo=new  Array("txtName","txtKey","txtBrand","txtModel","txtCount","txtPrice")
//得到焦点
for(var i=0;i<txtjbo.length;i++){ $(txtjbo[i]).onfocus =function ()
{for (var j=0;j<txtjbo.length;j++)
{if (txtjbo[j]==event.srcElement.id){postobj(j);}}}}
function postobj(num)
{
obj = "txt"+num;
document.getElementById(obj).innerHTML =Purchase[num];
}
function oo(){$("yc").style.display="none"}
//失去焦点
for(var i=0;i<txtjbo.length;i++){ $(txtjbo[i]).onblur =function ()
{for (var j=0;j<txtjbo.length;j++)
{if (txtjbo[j]==event.srcElement.id){postobjs(j);}}}}
function postobjs(num)
{
  var obj="txt"+num;
if ($(obj).innerHTML!="")
  {$(obj).innerHTML=""}
else 
  {$(obj).innerHTML=ok;}
 
}
function getobj(objName){
   if ($) {
      return eval('$("'+ objName +'")');
   }else{
      return eval('document.all["'+ objName +'"]');
   }
}

$("btnSave").onclick=function(){
 var Purases=new Array()
  var variale=0;
  var varrr=0;
  
  if($("txtCount").value!=""){
      if($("txtCount").value==0){
      document.getElementById("txt4").innerHTML = "<img src="+rightIcon+" width=\"19\" height=\"16\" align=\"absmiddle\"> <font color=#FF0000>需求数量不能为0</font>";
      varrr=1;
      }
      }else{
      
        document.getElementById("txt4").innerHTML = "<img src="+rightIcon+" width=\"19\" height=\"16\" align=\"absmiddle\"> <font color=#FF0000>需求数量不能为空</font>";
        varrr=1;
      }
     
   if ($("SortB").selectedIndex == -1) {
	         document.getElementById("hangye").innerHTML = "<img src="+rightIcon+" width=\"19\" height=\"16\" align=\"absmiddle\"> <font color=#FF0000>请选择所属行业和产品类目！</font>";
	         variale=1;
    }
  else if ($("SortM").options.length > 0 && $("SortM").selectedIndex == -1) {
	        document.getElementById("hangye").innerHTML = "<img src="+rightIcon+" width=\"19\" height=\"16\" align=\"absmiddle\"> <font color=#FF0000>您的类目没有选择完整，请继续选产品大类。</font>";
	        variale=1;
    }
  else if ($("SortS").options.length > 0 && $("SortS").selectedIndex == -1) {
	        document.getElementById("hangye").innerHTML = "<img src="+rightIcon+" width=\"19\" height=\"16\" align=\"absmiddle\"> <font color=#FF0000>您的类目没有选择完整，请继续选择产品子类。</font>";
	       variale=1;
    }else
    {
       document.getElementById("hangye").innerHTML="";
    }
     if($("txtPrice").value!=0){
       if(!(rep.test($("txtPrice").value))){ 
         document.getElementById("txt5").innerHTML="<img src="+rightIcon+" width=\"19\" height=\"16\" align=\"absmiddle\"> <font color=#FF0000>单价格式不正确</font>";
         varrr=1;
        }
      }else{
          document.getElementById("txt5").innerHTML="<img src="+rightIcon+" width=\"19\" height=\"16\" align=\"absmiddle\"> <font color=#FF0000>单价必须大于0小于9999999</font>";
          varrr=1;
      }
       if(variale!=0){
          window.location.href="#flagKeyword";
      }
      else if(varrr!=0){
          window.location.href="#xiangxi";
          return false;
      }
      else
      {
           document.getElementById("hangye").innerHTML="";
           document.getElementById("txt5").innerHTML="";
           document.getElementById("txt4").innerHTML="";
         return true;
      }

   var flag=1;
   Purases[0]=Purchases(txtjbo[0],0,0)
   Purases[1]=Purchases(txtjbo[1],1,0)
   Purases[2]=Purchases(txtjbo[4],4,1)
   Purases[3]=Purchases(txtjbo[5],5,0)
   for (i=0;i<Purases.length;i++){
      if (Purases[i]==false){
         flag=0;
         break;
      } 
   } 
   if(flag==0){
      return false;
   }else
   {
     return true;
   }
}

//方法
function Purchases(name,num,bernum)
{
   var obj="txt"+num
   if($(name).value.replace(/\s/g,'')==""){
     $(obj).innerHTML=QgFb[num]
     return false;
   }else if(bernum==1){
      if (!isNumber(getobj(txtjbo[num]).value.replace(/\s/g,''))){
         $(obj).innerHTML=QgFb[6];
         return false 
      }else{
         $(obj).innerHTML=ok;
         return true
      } 
   }else{
      $(obj).innerHTML=ok;
      return true
   }
}

//显示信息
var ok="";
var title="<p>";
var titles="</p>"
var Purchase=new Array()
Purchase[0]=title+"<font color=#FF0000>请输入商机名称</font>"+titles
Purchase[1]=title+"<font color=#FF0000>请输入关键字，以便快速搜索该产品</font>"+titles
Purchase[2]=title+"<font color=#FF0000>请输入该产品的品牌名称</font>"+titles
Purchase[3]=title+"<font color=#FF0000>请输入该产品的型号</font>"+titles
Purchase[4]=title+"<font color=#FF0000>请输入需求多少数量</font>"+titles
Purchase[5]=title+"<font color=#FF0000>请输入产品的单价</font>"+titles

//求购信息
var QgFb=new Array(9);
QgFb[0]="<img src="+rightIcon+" width=\"19\" height=\"16\" align=\"absmiddle\"> <font color=#FF0000>商机名称不能为空</font>";
QgFb[1]="<img src="+rightIcon+" width=\"19\" height=\"16\" align=\"absmiddle\"> <font color=#FF0000>关键字不能为空</font>";
QgFb[2]="<font></font>";
QgFb[3]="<font></font>";
QgFb[4]="<img src="+rightIcon+" width=\"19\" height=\"16\" align=\"absmiddle\"> <font color=#FF0000>需求数量不能为空</font>";
QgFb[5]="<img src="+rightIcon+" width=\"19\" height=\"16\" align=\"absmiddle\"> <font color=#FF0000>产品单价不能为空</font>";
QgFb[6]="<img src="+rightIcon+" width=\"19\" height=\"16\" align=\"absmiddle\"> <font color=#FF0000>输入不符合规范,请输入数字!</font>";



var rep=/^(0|[1-9]\d*)(\.\d{1,2})?$/;
var reprice=new RegExp(rep);
$("txtPrice").onblur=function(){
      if($("txtPrice").value!=0){
        if(!(rep.test($("txtPrice").value))){ 
            document.getElementById("txt5").innerHTML="<img src="+rightIcon+" align=\"absmiddle\"> <font color=#FF0000>单价格式不正确</font>";
            return false;
        }
        else{
            document.getElementById("txt5").innerHTML="";
            return true;
        } 
    }else
    {
     document.getElementById("txt5").innerHTML="<img src="+rightIcon+" align=\"absmiddle\"> <font color=#FF0000>单价必须大于0小于9999999</font>";
    }
}