$(document).ready(function() {
	var id = GetQueryString("orgId");
	/*企业信息*/
	function companyInformation() {
		$.ajax({
			url: "/ajax/org/" + id,
			type: "GET",
			timeout: 10000,
			dataType: "json",
			beforeSend: function() {},
			success: function(data, textState) {
				if(data.success) {
					var $data = data.data;
					var companytitle = $data.name + "-科袖网";
					window.setTimeout(function() {
						document.title = companytitle;
					}, 500);

					$("#comName").text($data.name);
					if($data.authStatus == 3) {
						$("#authS").addClass("authicon-com-ok").attr("title", "认证企业");
					} else {
						$("#authS").addClass("authicon-com-no").attr("title", "未认证企业");
					}
					if($data.hasOrgLogo) {
						$("#oimg").attr("src", "/images/org/" + $data.id + ".jpg");
					} else {
						$("#oimg").attr("src", "images/default-icon.jpg");
					}
					if($data.orgUrl) {
						$("#inteAddress").text($data.orgUrl);
					} else {
						$("#inteAddress").text("");
					}
					if($data.foundTime) {
						var oTime = timeGeshi($data.foundTime);
						$("#createTime").text(oTime);
					} else {
						$("#createTime").remove();
					}
					if($data.city) {
						$("#ocity").text($data.city);
					}
					if($data.descp) {
						$(".editbox").text($data.descp);
					} else {
						$("span:contains('企业简介')").parents(".introduction").hide();
						$("a:contains('企业简介')").hide();
					}
					if($data.orgSize) {
						switch($data.orgSize) {
							case '1':
								$("#qualificationList").text("50人以内")
								break;
							case '2':
								$("#qualificationList").text("50-100人")
								break;
							case '3':
								$("#qualificationList").text("100-200人")
								break;
							case '4':
								$("#qualificationList").text("200-500人")
								break;
							case '5':
								$("#qualificationList").text("500-1000人")
								break;
							default:
								$("#qualificationList").text("1000人以上")
								break;
						}
					} else {
						$("#qualificationList").remove();
					}
					if($data.orgType) {
						switch($data.orgType) {
							case '2':
								$("#orgType").text("国有企业");
								break;
							case '3':
								$("#orgType").text("上市企业");
								break;
							case '4':
								$("#orgType").text("合资企业");
								break;
							case '5':
								$("#orgType").text("私人企业");
								break;
							case '6':
								$("#orgType").text("外资企业");
								break;
							default:
								$("#orgType").text("初创企业");
								break;
						}
					}
					if($data.industry) {
						indu($data.industry, '#industryShow')
					} else {
						$("span:contains('所属行业')").parents(".introduction").hide();
						$("a:contains('所属行业')").hide();
					}
					if($data.subject) {
						indu($data.subject, '#subjectShow')
					} else {
						$("span:contains('专注领域')").parents(".introduction").hide();
						$("a:contains('专注领域')").hide();
					}
					if($data.qualification) {
						indu($data.qualification, '#qiye ')
					} else {
						$("span:contains('企业用户')").parents(".introduction").hide();
						$("a:contains('企业用户')").hide();
					}
				}
			},
			error: function(XMLHttpRequest, textStats, errorThrown) {
				$.MsgBox.Alert('提示', '服务器请求失败')
			}
		})
	}
	/*时间格式转换*/
	function timeGeshi(otm) {
		var otme = otm.substring(0, 4) + "-" + otm.substring(4, 6) + "-" + otm.substring(6, 8);
		return otme;
	}
	/*应用行业及领域及企业纸质*/
	function indu(oString, oSelector) {
		var arr = oString.split(",");
		var oArr = new Array();
		var i;
		for(i in arr) {
			if(oSelector == "#subjectShow") {
				oArr.push('<div class="acad">' + arr[i] + '</div>');
			} else {
				oArr.push('<li>' + arr[i] + '</li>');
			}
		}
		$(oSelector).html(oArr.join(""));
	}
	/*获取所有的企业用户*/
	function companyUser() {
		$.ajax({
			url: "/ajax/professor/qaOrgAuth",
			type: "GET",
			timeout: 10000,
			dataType: "json",
			data: {
				"orgId": id,
			},
			beforeSend: function() {},
			success: function(data, textState) {
				if(data.success) {
					var $info = data.data;
					userHtml($info);
				}
			},
			error: function(XMLHttpRequest, textStats, errorThrown) {
				$.MsgBox.Alert('提示', '服务器请求失败')
			}
		})
	}
	/*填充企业下用户*/
	function userHtml(arr) {
		for(var i = 0; i < arr.length; i++) {
			var tiof = "",
				img;
			if(arr[i].hasHeadImage) {
				img = "/images/head/" + arr[i].id + "_l.jpg";
			} else {
				img = "images/default-photo.jpg"
			}
			if(arr[i].title) {
				if(arr[i].office) {
					tiof = arr[i].title + " ，" + arr[i].office;
				} else {
					tiof = arr[i].title;
				}
			} else {
				if(arr[i].office) {
					tiof = arr[i].office;
				}
			}
			var oString = '<dd>'
			oString += '<div class="staffChild">'
			oString += '<img class="headRadius" src="' + img + '" width="100%" />'
			oString += '</div><div class="h4Font"><span>' + arr[i].name + '</span></div>'
			oString += '<div class="h4Font">' + tiof + '</div></dd>'
			$("#userList").append(oString);
		}
	}
	companyInformation();
	companyUser();
	/*企业文章*/
	$.ajax({
		url: "/ajax/article/qaOrg",
		dataType: 'json', //数据格式类型
		type: 'GET', //http请求类型
		data: {
			"orgId": id
		},
		timeout: 10000, //超时设置
		success: function(data) {
			if(data.success) {
					for(var i = 0; i < data.data.length; i++) {
						var add = '<li><a href="articalInfo.html?oFlag=1&articleId=' + data.data[i].articleId + '&professorId=' + data.data[i].orgId + '" style="display:block;">'
						add += '<div class="art_topicBox"><div class="art_img" style=""></div>'
						add += '<div class="art_tbox"><h6 id="artical_topic" >' + data.data[i].articleTitle + '</h6></div>'
						add += '</div><div class="tagsBox"><span></span></div>'
						add += '</a></li>';
						$add = $(add);
						$("#reachArticle").append($add);
						$add.find('.tagsBox span').text(data.data[i].industry); //data.data[i].subject
						if(data.data[i].articleImg) {
							$add.find(".art_img").attr("style", "background: url(/data/article/" + data.data[i].articleImg + ") 0 0 no-repeat;background-size:cover;");
						}

					}
					//资源轮播
					var $content2 = $(".sharescrollbox.Acrollbox");
					var childcount2 = $content2.find(".otherRes.shareshow li").length;
					Carousel(3, 3, 3, childcount2, $content2, $(".articalbtn.resounext"), $(".articalbtn.resouprev"));
			}
		},
		error: function() {
			return;
		}
	})
	
})