
$(document).ready(formInit);

function formInit() {

  var theform = $('form:first');
  var formelement = {
    'name':     {'check':'Require', 'warningparam':'name'},
    //'sex_1':    {'check':'Require', 'warningparam':'sex'},
    //'phone':    {'check':'Phone',   'warningparam':'phone'},
    'phone':    {'check':'Phone_Mobile',   'warningparam':'phone'},
    'email':    {'check':'Email',   'warningparam':'email'},
    //'idcard':   {'check':'Idcard',  'warningparam':'idcard'},
    //'company':  {'check':'Require', 'warningparam':'company'},
    'store':    {'check':'Require', 'warningparam':'store'},
   // 'channel' : {'check':'Require', 'warningparam':'channel'},
    'input_interest_0': {'check':'Require', 'warningparam':'interest'}
  };
    //alert($('#input_interest_0', theform)[0]);
  for (var e in formelement) {
    var attrs = formelement[e];
    var element = $('#'+e, theform);
    for (var attr in attrs) {
      element[0][attr] = attrs[attr];
    }
    element[0].warning=function(el){warn(el.warningparam)};
    //element.attr(attrs);
    //alert(element[0].check);
  }

}


/**
 * 提交时的处理
 */
function sent(form){
  resetformstyle();
  return CheckForm(form);
}

function changeColor(str){
  var colorList = new Array('span_name','span_tel','span_email','span_idcard','span_store','span_url','span_read');
  for(var i = 0; i < colorList.length;i++){
    if( colorList[i] == str){
      document.getElementById(str).style.color="red";
      continue;
    }
    document.getElementById(colorList[i]).style.color="";
    if(str == "span_read"){
      document.getElementById('span_read').style.display="";
      continue;
    }
  }
}

function warn(str) {
  var theform = $('form:first');
  //alert('#li_'+str);
  $('#li_'+str, theform).css({'border':'1px solid red','color':'red', 'background-color':'#ffeeee'});
}

function resetformstyle() {
  var theform = $('form:first');
  //var lis = ['name','phone','email','idcard','store','channel','company','interest'];
  var lis = ['name','phone','email','channel','store','interest'];
  $(lis).each(function(i,e){
    $('#li_'+e, theform).css({'border':'none','color':'black', 'background-color':'#ffffff'});
  });
}
