var currentForm = null;
var currentObj=null;
var getContextPath = function() {
        var ctxPath = "";
    $A(document.getElementsByTagName("script")).findAll( function(s) {
      return (s.src && s.src.match(/buffalo\.js(\?.*)?$/))
    }).each( function(s) {
      var path = s.src.replace(/script\/buffalo\.js(\?.*)?$/,'');
          ctxPath = path;
    });

        return ctxPath;
}

function selectType(theForm) {
    currentForm = theForm;
    var buffaloURL =getContextPath()+"bfapp";
    var buffalo = new Buffalo(buffaloURL);
    buffalo.events["onLoading"] = myloading;
  
    buffalo.remoteCall("article.getLanmu", [currentForm.pid.value], callback) ;
    return true;
} 


function callback(reply) {

        var results = reply.getResult();  
       
            var types  = results;
            currentForm.lid.options.length = 0;

			 
            for (var i = 0; i <types.length; i++) {
                var type = types[i];
                var op=document.createElement('option') ;
                op.text = type.name;
                op.value = type.id;
                currentForm.lid.add(op);
			}
        
}

function myloading(state) {
  if (state) {window.status = "选择栏目....."; } 
  else {window.status = "选择栏目完成."; }
}
function selectTypes(theForm,sourceparam,toparam) {
    currentForm = theForm;
    var buffaloURL =getContextPath()+"bfapp";
    var buffalo = new Buffalo(buffaloURL);
       currentObj=toparam;
    if(sourceparam=='ind1'){
    buffalo.remoteCall("pubdata.getIndustry", [currentForm.ind1.value], callbacks) ;}

  if(sourceparam=='ind2'){
    buffalo.remoteCall("pubdata.getIndustry", [currentForm.ind2.value], callbacks) ;}

    return true;
} 


function callbacks(reply) {

        var results = reply.getResult();  
       
            var types  = results;
			
			if(currentObj=='ind2'){
            currentForm.ind2.options.length = 0;
  currentForm.ind3.options.length = 0;
			 var op=document.createElement('option') ;
                op.text = "";
                op.value = "";
				 currentForm.ind2.add(op);
            for (var i = 0; i <types.length; i++) {
                var type = types[i];
                var op=document.createElement('option') ;
                op.text = type.ktname;
                op.value = type.ktname;
                currentForm.ind2.add(op);
			}
			}
				if(currentObj=='ind3'){
            currentForm.ind3.options.length = 0;

			 
            for (var i = 0; i <types.length; i++) {
                var type = types[i];
                var op=document.createElement('option') ;
                op.text = type.ktname;
                op.value = type.ktname;
                currentForm.ind3.add(op);
			}
			}
        
}
function selectTypebs(theForm,sourceparam,toparam) {
    currentForm = theForm;
    var buffaloURL =getContextPath()+"bfapp";
    var buffalo = new Buffalo(buffaloURL);
       currentObj=toparam;
    if(sourceparam=='bind1'){
    buffalo.remoteCall("pubdata.getIndustry", [currentForm.bind1.value], callbackbs) ;}

  if(sourceparam=='bind2'){
    buffalo.remoteCall("pubdata.getIndustry", [currentForm.bind2.value], callbackbs) ;}

    return true;
} 


function callbackbs(reply) {

        var results = reply.getResult();  
       
            var types  = results;
			
			if(currentObj=='bind2'){
            currentForm.bind2.options.length = 0;
  currentForm.bind3.options.length = 0;
			 var op=document.createElement('option') ;
                op.text = "";
                op.value = "";
				 currentForm.bind2.add(op);
            for (var i = 0; i <types.length; i++) {
                var type = types[i];
                var op=document.createElement('option') ;
                op.text = type.ktname;
                op.value = type.ktname;
                currentForm.bind2.add(op);
			}
			}
				if(currentObj=='bind3'){
            currentForm.bind3.options.length = 0;

			 
            for (var i = 0; i <types.length; i++) {
                var type = types[i];
                var op=document.createElement('option') ;
                op.text = type.ktname;
                op.value = type.ktname;
                currentForm.bind3.add(op);
			}
			}
        
}

function selectResume(theForm,sourceparam,toparam) {
    currentForm = theForm;
    var buffaloURL =getContextPath()+"bfapp";
    var buffalo = new Buffalo(buffaloURL);
       currentObj=toparam;
    if(sourceparam=='ind1'){
    buffalo.remoteCall("pubdata.getResume", [currentForm.ind1.value], callbackResume) ;}

  if(sourceparam=='ind2'){
    buffalo.remoteCall("pubdata.getResume", [currentForm.ind2.value], callbackResume) ;}

    return true;
} 

function callbackResume(reply) {
        var results = reply.getResult();
        var types  = results;
			if(currentObj=='ind2'){
            currentForm.ind2.options.length = 0;			
			 var op=document.createElement('option') ;
                op.text = "";
                op.value = "";
				 currentForm.ind2.add(op);
            for (var i = 0; i <types.length; i++) {
                var type = types[i];
                var op=document.createElement('option') ;
                op.text = type.rtname;
                op.value = type.rtname;
                currentForm.ind2.add(op);
			}
			}       
}

function selectEntype(theForm,sourceparam,toparam) {
    currentForm = theForm;
    var buffaloURL =getContextPath()+"bfapp";
    var buffalo = new Buffalo(buffaloURL);
       currentObj=toparam;
    if(sourceparam=='ind1'){
    buffalo.remoteCall("pubdata.getEnType", [currentForm.ind1.value], callbackEntype) ;}

  if(sourceparam=='ind2'){
    buffalo.remoteCall("pubdata.getEnType", [currentForm.ind2.value], callbackEntype) ;}

    return true;
} 

function callbackEntype(reply) {
        var results = reply.getResult();
        var types  = results;
			if(currentObj=='ind2'){
            currentForm.ind2.options.length = 0;			
			 var op=document.createElement('option') ;
                op.text = "";
                op.value = "";
				 currentForm.ind2.add(op);
            for (var i = 0; i <types.length; i++) {
                var type = types[i];
                var op=document.createElement('option') ;
                op.text = type.rtname;
                op.value = type.rtname;
                currentForm.ind2.add(op);
			}
			}       
}

function checkloginname(theForm) {
    
    var buffaloURL =getContextPath()+"bfapp";
    var buffalo = new Buffalo(buffaloURL,false);

    buffalo.remoteCall("business.checkLoginname", [theForm.loginname.value], callback1) ;
    return true;
}

function callback1(reply) {
        var results = reply.getResult();  
       
            var jieguo = results;
          
            
            if(jieguo=="1"){
          alert("该登录名已经存在");
          return "1";
          }
             
            return "0";
          
}
//注册邮箱只能用一次   2010 03 01 开始(lihong)
function checkRegEmail(theForm) {
    
    var buffaloURL =getContextPath()+"bfapp";
    var buffalo = new Buffalo(buffaloURL,false);

    buffalo.remoteCall("business.checkRegEmail", [theForm.email.value], callback2) ;
    return true;
}

function callback2(reply) {
        var results = reply.getResult();  
       
            var jieguo = results;
          
            
            if(jieguo=="1"){
          alert("该邮箱已经用过了！");
          return "1";
          }
             
            return "0";
          
}

//注册邮箱只能用一次   2010 03 01 结束
function selectM(theForm) {
    currentForm = theForm;
    var buffaloURL =getContextPath()+"bfapp";
    var buffalo = new Buffalo(buffaloURL);
    buffalo.remoteCall("pubdata.getMagazine", [currentForm.mid.value], callbackm) ; 
    return true;
} 


function callbackm(reply) {

        var results = reply.getResult();  
       
            var types  = results;
			
			 
            currentForm.zid.options.length = 0;

			 
            for (var i = 0; i <types.length; i++) {
                var type = types[i];
                var op=document.createElement('option') ;
                op.text = type.name;
                op.value = type.id;
                currentForm.zid.add(op);
			}
			 
        
}
function selectZ(theForm) {
	
    currentForm = theForm;
 
    var buffaloURL =getContextPath()+"bfapp";
    var buffalo = new Buffalo(buffaloURL);
    buffalo.remoteCall("pubdata.getZhuanjia", [currentForm.ind1.value], callbackz) ; 
    return true;
} 


function callbackz(reply) {

        var results = reply.getResult();  
       
            var types  = results;
			
			 
            currentForm.zid.options.length = 0;

			 
            for (var i = 0; i <types.length; i++) {
                var type = types[i];
                var op=document.createElement('option') ;
                op.text = type.name;
                op.value = type.id;
                currentForm.zid.add(op);
			}
			 
        
}
function selectP(theForm) {
    currentForm = theForm;
    var buffaloURL =getContextPath()+"bfapp";
    var buffalo = new Buffalo(buffaloURL);
    buffalo.remoteCall("pubdata.getProduct", [currentForm.xuan.value], callbackp) ; 
    return true;
} 


function callbackp(reply) {

        var results = reply.getResult();  
       
            var types  = results;
			
			 
          

			 
            for (var i = 0; i <types.length; i++) {
                var type = types[i];
                 currentForm.guige.value=type.jianjie;
				  currentForm.des.value=type.des;
				 //  currentForm.imgurlid.value=type.imgurlid;
				    currentForm.imgurl.value=type.imgurl;
					currentForm.pname.value=type.productname;
					 currentForm.ind1.value=type.ind1;
				    currentForm.ind2.value=type.ind2;
					currentForm.ind3.value=type.ind3;
                
			}
			 
        
}