var server="http://ke.educmf.com/";
$("#myModal").on("hidden", function() {
	$(this).removeData("modal");
});

$(".bangding").click(function(){  
	var marketcount=$("#marketcount").val();
	var marketpass=$("#marketpass").val();
	$.ajax({     	
		type : "get",	    
		url : server+"index.php?g=market&m=market&a=autho&marketcount="+marketcount+"&marketpass="+marketpass,    	
		dataType : "jsonp",	    
		success : function(data){	
			if(data.states){
			   $("#states").val('success'); 
			   $("#message").val(data.message); 
			   $('.tijiao').trigger("click"); 
			}else{
			   $("#states").val('error'); 
			   $("#message").val(data.message); 
			   $('.tijiao').trigger("click"); 
			}
		}     
	});	
});

function getMyMarketCourse(){
	var marketcount=$("#marketcount").val();
	var marketpass=$("#marketpass").val();
	var host=window.location.host;
	if(marketcount.length == 0 || marketpass.length == 0){
		$("#bangdingcount").removeClass("hidden");
	}else{
		var $m_cs_list = $("#m_cs_list");
		var html='<div class="col-lg-3 col-md-4 col-xs-6">'+
				   '<div class="course-item">'+
					 '<div class="course-img" style="height:60%;">'+
						'<a href="javascript:void(0)">'+
							'<img class="img-responsive thumb" src="">'+
						'</a>'+
					 '</div>'+
					 '<div class="course-info">'+
					   '<div class="title"></div>'+
					    '<span class="Inspan"></span>'+
						'<div class="metas Indiv clearfix">'+
						'</div>'+
					  '</div>'+
					'</div>' +         
				 '</div>';
		$.ajax({     	
			type : "get",	    
			url : server+"index.php?g=market&m=market&a=getMarketCourse&marketcount="+marketcount+"&marketpass="+marketpass,    	
			dataType : "jsonp",	    
			success : function(data){	
				if(data.states==false){
					$("#empty").removeClass("hidden");
					$(".empty").html(data.message);
				}else{
					if (data.length > 0){
						$.each(data, function(i,n) {
							var $tpl = $(html);
							var picUrl=server+n.cs_picture;
							var importurl="http://"+host+"/index.php?g=teacher&m=market&a=import&id="+n.course_id;
							$(".img-responsive",$tpl).attr('src',picUrl); 
							$(".title", $tpl).html(n.cs_name);
							$.ajax({
								url :"http://"+host+"/index.php?g=teacher&m=market&a=checkimport",
								type : "post",
								data : {"markedid" :n.course_id},
								async : true,
								dataType : 'json', 
								success : function(result) {								
								   if(result.states==true){
									   $(".Indiv", $tpl).html( ' <a href="javascript:void(0)" class="btn btn-sm fr">已经导入</a>');
								   }else{
									   $(".Indiv", $tpl).html( ' <a href="'+importurl+'" class="btn btn-primary btn-sm fr import" data-toggle="modal" data-target="#myModal"><span class="glyphicon glyphicon-plus" ></span>导入</a>');
								   }
								}
							});
							$m_cs_list.append($tpl);
						});  
					}else{
						$("#empty").removeClass("hidden");
						$(".empty").html(data.message);
					}
				}
			}     
		});	
	}
 }
 function getTopType(){
	$.getJSON(server+"index.php?g=market&m=market&a=getTopType&callback=?",
    function(data) {
		var $topType = $("#topType");
		if (data.length > 0) {
			$.each(data, function(i, n) {
			   var tpl = '<li><a href="javascript:void (0)" id='+n.term_id+'><span class="content">'+n.name+'</span></a></li>';
			   $topType.append(tpl);
			});
		} else {
		}
	});
 }
 function getMarkerCourseInfo(){
	var marketcount=$("#marketcount").val();
	var marketpass=$("#marketpass").val();
	var marketid=$("#marketId").val();
	$.ajax({     	
		type : "get",	    
		url : server+"index.php?g=market&m=market&a=marketCourseInfo&marketcount="+marketcount+"&marketpass="+marketpass+"&marketid="+marketid,    	
		dataType : "jsonp",	    
		success : function(data){	
			if(data.states==false){
				$("#courseinfo").addClass("hidden");
				$("#empty").removeClass("hidden");
				$(".empty").html(data.message);
			}else{
				$("#cs_name").val(data.cs_name); 
				$("#mubiao").val(data.mubiao); 
				$("#shihe").val(data.shihe); 
				$("#sec_numbers").val(data.sec_numbers); 
				$("#cs_picture").val(server+data.cs_picture); 
				$("#cs_brief").val(data.cs_brief);
				$("#type").val(data.course_type);
				$("#markedid").val(data.id);
				$(".import").removeClass("hidden");
			}
		}     
	});
 }




