
$(document).ready(formInit);

function formInit() {
  //alert($("form[#name]").length);
  //$('form[#name]').val('test');
  var theform = $('form:first');
  var formelement = {
    'name':   {'check':'Require','warningparam':'name'},
    //'sex_1':  {'check':'Require','warningparam':'sex'},
    //'cardno':  {'check':'Require','warningparam':'cardno'},
    'phone':  {'check':'Phone_Mobile','warningparam':'phone'},
    //'email':  {'check':'Email','warningparam':'email'},
    //'idcard': {'check':'Idcard','warningparam':'idcard'},
    'store':  {'check':'Require','warningparam':'store'},
    'channel':{'check':'Require','warningparam':'channel'},
    'clevel': {'check':'Require','warningparam':'clevel'},
    //'age':    {'check':'Require','warningparam':'age'},
    'class':  {'check':'Require','warningparam':'class'}
  };
  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','clevel','age','class','cardno'];
  $(lis).each(function(i,e){
    $('#li_'+e, theform).css({'border':'none','color':'black', 'background-color':'#ffffff'});
  });
}
