
var cache={};  //公司网站缓存  

function SetMainFrameHeight() {
	var iframeid = document.getElementById("mid_content");
	if (document.getElementById) {
		if (iframeid) {
			if (iframeid.contentDocument
					&& iframeid.contentDocument.body.offsetHeight) {
				iframeid.height = iframeid.contentDocument.body.offsetHeight;
			} else if (iframeid.Document && iframeid.Document.body.scrollHeight) {
				iframeid.height = iframeid.Document.body.scrollHeight;
			}
		}
	}
	
}
//禁止右键菜单和禁止复制
function onbodyatrr(obj){
	obj.oncontextmenu=function(){return false} ;	
	obj.ondragstart=function(){return false}; 
	obj.onselectstart =function(){return false}; 
	obj.onselect=function(){document.selection.empty()}; 
	obj.oncopy=function(){document.selection.empty()} 
	obj.onbeforecopy=function(){return false};
}

// 判断浏览器的版本

function getVersion(){
	var Sys = {}; 
	var ua = navigator.userAgent.toLowerCase(); 
	var s; 
	(s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] : 
	(s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] : 
	(s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] : 
	(s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] : 
	(s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0; 
	//以下进行测试,并返回浏览器类型
	if (Sys.ie) return('IE' + Sys.ie); //返回IE7.0
	//if (Sys.firefox) return('Firefox' + Sys.firefox); 
	//if (Sys.chrome) return('Chrome' + Sys.chrome); 
	//if (Sys.opera) return('Opera' + Sys.opera); 
	//if (Sys.safari) return('Safari' + Sys.safari); 
	if (Sys.firefox) return('Firefox'); 
	if (Sys.chrome) return('Chrome'); 
	if (Sys.opera) return('Opera'); 
	if (Sys.safari) return('Safari'); 
}

/**
 * 判断是否为 safari浏览器
 * @return {}
 */
function isSafari(){
	var version = getVersion();
	var isSaf = false;
	if(version == 'Safari'){
		isSaf = true;
	}
	return isSaf;
}
function clickMenu(showChild, picbox) {
	window.frames["mid_content"].location= showChild;
}

function chooseMenu() {
	document.getElementById("main_1").style.background = "url(portal/main/face/default/images/nav_first_normol.gif)"
	document.getElementById("main_8").style.background = "url(portal/main/face/default/images/nav_last.gif)"
	for (var i = 2; i < 8; i++) {
		document.getElementById("main_" + i).style.background = "url(portal/main/face/default/images/nav.gif) repeat-x"
	}
}

function mainpage() {
	window.frames["mid_content"].location= "portal/main/home.html";
	document.getElementById("adrNodeMsg").style.display = "none";
}
function changeImg(picbox,i){
	chooseMenu();
	document.getElementById("main_head").style.display = "none";
	document.getElementById("child_head").style.display = "block";
	if(i==8){
		document.getElementById("main_8").style.background = "url(portal/main/face/default/images/nav_last_hover.gif)";
	}else{
		document.getElementById("main_"+i).style.background = "url(portal/main/face/default/images/nav_hover.gif) repeat-x";
	}
	document.getElementById("second_banner1").src="portal/main/face/default/images/"+picbox+"/1.png"
	document.getElementById("second_banner2").src="portal/main/face/default/images/"+picbox+"/2.png"
	document.getElementById("second_banner3").src="portal/main/face/default/images/"+picbox+"/3.png"
	document.getElementById("second_banner4").src="portal/main/face/default/images/"+picbox+"/4.png"
	document.getElementById("second_banner5").src="portal/main/face/default/images/"+picbox+"/5.png"
	document.getElementById("adrNodeMsg").style.display = "block";
}
function changeTit(msg,menunum,childmsg){
	document.getElementById("position").innerHTML='<a href="javascript:void(0)" onclick="clickImg('+menunum+')">'+msg+'</a>';
	if(childmsg){
		document.getElementById("position_child").innerHTML='<span class="sp_mark">>></span>'+childmsg;
	}else{
		document.getElementById("position_child").innerHTML='';
	}
}

function homeImg() {
	document.getElementById("main_head").style.display = "block";
	document.getElementById("child_head").style.display = "none";
	document.getElementById("banner2").style.display = "none";
	document.getElementById("banner3").style.display = "none";
	document.getElementById("adrNodeMsg").style.display = "none";
	chooseMenu();
	document.getElementById("main_1").style.background = "url(portal/main/face/default/images/nav_one.gif)"
}
var showImg = null;
var n = 0;
var len
window.onload = function(){
	onbodyatrr(window.document);
	window.frames["mid_content"].location= "portal/main/home.html";
	
	loadNewsData();
	
	loadPositionData();

	document.getElementById("main_1").onclick = function() {
		mainpage();
	}
	document.getElementById("main_2").onclick = function() {
		clickMenu("portal/about/about.html","about")
		return false;
	}

	document.getElementById("main_3").onclick = function() {
		clickMenu("portal/product/product.html","product")
		return false;
	}

	document.getElementById("main_4").onclick = function() {
		clickMenu("portal/news/news.html","news")
		return false;
	}
	document.getElementById("main_5").onclick = function() {
		clickMenu("portal/culture/culture.html","culture")
		return false;
	}
	document.getElementById("main_6").onclick = function() {
		clickMenu("portal/cooperate/cooperate.html","cooperate")
		return false;
	}
	document.getElementById("main_7").onclick = function() {
		clickMenu("portal/resume/onlineResume.html","resume")
		return false;
	}
	document.getElementById("main_8").onclick = function() {
		clickMenu("portal/comment/connection_us.html","comment")
		document.getElementById("position").innerHTML="联系我们";
		return false;
	}		
	
	len = $("#playShow a").size();
	$("#playShow a").not(":first").hide();
	$(".playNum a:first").css({
		"background" : "url(portal/main/face/default/images/pic_num_curbg.gif) repeat-x",
		"color" : "#fff"
	});
	$(".pic_str li:first").addClass("pic_str_licur");
	$(".playNum a").click(function() {
		var i = $(this).text() - 1;
		n = i;
		if (i > len)
			return;
		$("#playShow a").filter(":visible").hide()
		$("#playShow a").eq(i).fadeIn("slow");
		$("li.pic_str_licur").removeClass().addClass("pic_str_li");
		$("li.pic_str_li").eq(i).addClass("pic_str_licur");
		$(this).css({
			"background" : "url(portal/main/face/default/images/pic_num_curbg.gif) repeat-x",
			"color" : "#fff"
		}).siblings().css({
					"background" : "url(portal/main/face/default/images/pic_num_bg.gif) repeat-x",
					"color" : "#a0a0a0"
				});
	});
	showImg = setInterval(showAuto,5000);
	$("#playShow").hover(function() {
				clearInterval(showImg);
			}, function() {
				showImg = setInterval(showAuto,5000);
			});
	loadLinkList();	
};

function showAuto() {
	n = (n >= (len - 1)) ? 0 : ++n;
	$(".playNum a").eq(n).trigger("click");
}


function loadLinkList(){
	if(window.cache.linkList){
		DsrUtil.loadSelect("linkList",window.cache.linkList);
	}else{
		AjaxExecute.setParameter({
					url : "eli/portal/links/getPortalLinksPage.do",
					data : 'startIndex='+1+'&pageSize='+10,
					type : 'json',
					onSuccess : function(rs) {						
						if(rs && rs.linkList){
							window.cache.linkList=rs.linkList;
							DsrUtil.loadSelect("linkList",rs.linkList);
						}
					}					
		})
	}
//	var linkDiv=document.getElementById("linkDiv");
//	var linkUL=document.getElementById("linkUL");	
//	var len = 0;
//	if(linkUL.innerHTML==""){
//		AjaxExecute.setParameter({
//					url : "eli/portal/links/getPortalLinksPage.do",
//					data : 'startIndex='+1+'&pageSize='+10,
//					type : 'json',
//					async:false,
//					onSuccess : function(rs) {						
//						if(rs && rs.linkList){
//							for(var i=0;i<rs.linkList.length;i++){
//								var obj=rs.linkList[i];
//								linkUL.innerHTML+="<li onmouseover='this.style.background=\"#277abe\"' onmouseout='this.style.background=\"\"'><a href='"+obj.url+"'>"+obj.name+"</a></li>";
//							}
//						}
//						len = rs.linkList.length;
//					}					
//		})
//	}
//		
//	linkDiv.style.display="block";	
//	var e = event||window.event;		
//	linkDiv.style.left=e.clientX +"px";
//	linkDiv.style.top =(document.body.clientHeight- len*20+2-125)+"px";
	
}

function clickImg(i,flag){
	if(i==1){
		exeClick(document.getElementById("main_1"));
		if(isSafari()){window.frames["mid_content"].location= "portal/main/home.html"}
		window.parent.scrollTo(0,0);
		return ;
	}
	if(i==2){
		exeClick(document.getElementById("main_3"));
		if(isSafari()){ window.frames["mid_content"].location= "portal/product/product.html"}
		window.parent.scrollTo(0,0);
		return ;
	}
	if(i==3){
		exeClick(document.getElementById("main_7"));
		if(isSafari()){window.frames["mid_content"].location= "portal/resume/onlineResume.html"}
		window.parent.scrollTo(0,0);
		return ;
	}
	if(i==4){
		exeClick(document.getElementById("main_8"));
		if(isSafari()){
			window.frames["mid_content"].location= "portal/comment/connection_us.html";
			if(flag == false){window.frames["mid_content"].location= "../../portal/comment/connection_us.html"}
		}	
		window.parent.scrollTo(0,0);
		return ;
	}
	if(i==5){
		window.frames["mid_content"].location="portal/main/webmap.html";
		changeTit("网站地图");
		window.parent.scrollTo(0,0);
		return ;
	}
	if(i==0){
		window.frames["mid_content"].location="portal/legalnotices/privacy.html";		
		changeTit("法律及隐私声明");
		window.parent.scrollTo(0,0);		
		return ;
	}
	if(i==10){
		window.frames["mid_content"].location="../../portal/legalnotices/privacy.html";	
		window.parent.scrollTo(0,0);
		return ;
	}
	if(i==6){
		exeClick(document.getElementById("main_4"));
		if(isSafari()){
			window.frames["mid_content"].location= "portal/news/news.html";
			if(flag == false){window.frames["mid_content"].location= "../../portal/news/news.html"}
		}
		window.parent.scrollTo(0,0);
		return ;
	}
	if(i==7){
		exeClick(document.getElementById("main_5"));
		if(isSafari()){
			window.frames["mid_content"].location= "portal/culture/culture.html";
			if(flag == false){window.frames["mid_content"].location= "../../portal/culture/culture.html"}
			}
		window.parent.scrollTo(0,0);
		return ;
	}
	if(i==8){
		exeClick(document.getElementById("main_6"));
		if(isSafari()){
			window.frames["mid_content"].location= "portal/cooperate/cooperate.html";
			if(flag == false){window.frames["mid_content"].location= "../../portal/cooperate/cooperate.html"}
			}
		window.parent.scrollTo(0,0);
		return ;
	}
	if(i==9){
		exeClick(document.getElementById("main_2"));
		if(isSafari()){
			window.frames["mid_content"].location= "portal/about/about.html"
			if(flag == false){window.frames["mid_content"].location= "../../portal/about/about.html"}
			}
		window.parent.scrollTo(0,0);
		return ;
	}	
}

/**
 * 选择友情链接函数
 * @param {} obj
 */
function selectLink(obj){
	try{
		url=obj.options[obj.selectedIndex].data.url;
		window.open(url);
	}catch(e){
		
	}
}
/*banner链接*/
function LeadBannerlocate(left,right){
	window.hrefData={"leftIdx":left,"rightIdx":null,"flag":"produce"};
	exeClick(window.parent.document.getElementById("main_3"));
	if(isSafari()){
		window.frames["mid_content"].location=="../../portal/product/product.html";
	}
	showDetail(new Date());
	window.parent.scrollTo(0,0);
}

/**
 * 点击首页时，跳转到详细模块的详细地方
 * @param {} obj
 */
function showDetail(obj){
	/**
	 * 判断主iframe是否加载完成
	 */
	window.fmState("mid_content",function(){
		var test = setInterval(function(){
			/**
			 * 关于应聘方面的超链接点击
			 */
			if(window.hrefData.flag=="job"){
				if(cache.position!=null){
					clearInterval(test);
					if(window.hrefData.rightIdx==null){
						if(window.hrefData.leftIdx==0){
							var test4 = setInterval(function(){
								var schoolObj=document.getElementById("mid_content").contentWindow.document.getElementById("school");
								var resumeIframe=document.getElementById("mid_content").contentWindow.document.getElementById("res_content");
								if(schoolObj && resumeIframe &&resumeIframe.contentWindow.document.readyState=="complete"){
									if(window.getVersion()=="Opera"){
										setTimeout(function(){
											exeClick(schoolObj);
	
										},500)
									}else{
										exeClick(schoolObj);
									}
									if(window.isSafari){
										resumeIframe.src="../../portal/resume/school.html";
									}
									clearInterval(test4);
									if(document.all){
										document.getElementById("mid_content").contentWindow.document.getElementById("res_content").contentWindow.location.hash=window.hrefData.rightIdx;
									}
								}
							},10)
						}else if(window.hrefData.leftIdx==2){
							var test7 = setInterval(function(){
								var loginObj=document.getElementById("mid_content").contentWindow.document.getElementById("login");
								var resumeIframe=document.getElementById("mid_content").contentWindow.document.getElementById("res_content");
								if(loginObj && resumeIframe &&resumeIframe.contentWindow.document.readyState=="complete"){
									exeClick(loginObj);
									if(window.isSafari){
										resumeIframe.src="../../portal/resume/login.html";
									}
									clearInterval(test7);
								}
							},10)
						}
					}else{
						var test1 = setInterval(function(){
							var resumeIframe=document.getElementById("mid_content").contentWindow.document.getElementById("res_content");
							if(document.getElementById("mid_content").contentWindow.document.getElementById("school") && resumeIframe && resumeIframe.contentWindow.document.readyState=="complete"){
								clearInterval(test1);
								if(window.hrefData.leftIdx==0){
									if(window.getVersion()=="Opera"){
										setTimeout(function(){
											exeClick(document.getElementById("mid_content").contentWindow.document.getElementById("school"));
										},500)
									}else{
										exeClick(document.getElementById("mid_content").contentWindow.document.getElementById("school"));
									}
									if(window.isSafari){
										resumeIframe.src="../../portal/resume/school.html";
									}
								}
								var test2 = setInterval(function(){
									if(resumeIframe && resumeIframe.contentWindow.document.readyState=="complete"){
										clearInterval(test2);
										if(document.all){
											document.getElementById("mid_content").contentWindow.document.getElementById("res_content").contentWindow.location.hash="#"+window.hrefData.rightIdx;
										}
									}
								},10)
							}
						},10)
						
					}
				}
			/**
			 * 关于新闻方面的超链接点击
			 */
			}else if(window.hrefData.flag=="news"){
				if(cache.categoryList!=null){
					clearInterval(test);
					if(window.hrefData.rightIdx==null){
						var test2 = setInterval(function(){
							var categoryObj=document.getElementById("mid_content").contentWindow.document.getElementById(window.hrefData.leftIdx);
							if(categoryObj){
								clearInterval(test2);
								exeClick(categoryObj);
							}
						},10)
							
					}else{
						window.newsIdx=window.hrefData.rightIdx;
						var test3 = setInterval(function(){
							var categoryObj=document.getElementById("mid_content").contentWindow.document.getElementById(window.hrefData.leftIdx);
							if(categoryObj){
								clearInterval(test3);
								exeClick(categoryObj);
								var test4 = setInterval(function(){
									if(document.getElementById("mid_content").contentWindow.document.getElementById("news_iframe").contentWindow.document.readyState=="complete"){
										clearInterval(test4);
										document.getElementById("mid_content").contentWindow.document.getElementById("news_iframe").src="new_detail.html?id="+window.hrefData.rightIdx;
									}
									
								},10);
							}
						},10);
						
					}
				}
			/**
			 * 关于产品解决方案的超链接点击
			 */
			}else if(window.hrefData.flag=='produce'){
				clearInterval(test);
				if(window.hrefData.leftIdx==1){
					var test6 = setInterval(function(){
						var produceIframe=document.getElementById("mid_content");
						var lead_left_menu = document.getElementById("mid_content").contentWindow.document.getElementById("lead_left_menu");
						if(produceIframe &&produceIframe.contentWindow.document.readyState=="complete" && lead_left_menu){
							exeClick(lead_left_menu);
							clearInterval(test6);
							
						}
					},10);
				}else if(window.hrefData.leftIdx==0){
					var test11 = setInterval(function(){
						var produceIframe=document.getElementById("mid_content");
						var produ_left_menu = document.getElementById("mid_content").contentWindow.document.getElementById("produ_left_menu");
						if(produceIframe &&produceIframe.contentWindow.document.readyState=="complete" && produ_left_menu){
							exeClick(produ_left_menu);
							clearInterval(test11);							
						}
					},10);
				}	
			/**
			 * 关于联系我们超链接的点击
			 */
			}else if(window.hrefData.flag=='connection'){
				clearInterval(test);
				if(window.hrefData.leftIdx==0){
					var test9 = setInterval(function(){
									var messageObj=document.getElementById("mid_content");
									if(messageObj && messageObj.contentWindow.document.readyState=="complete"){
										exeClick(messageObj.contentWindow.document.getElementById("adress"));
										clearInterval(test9);
									}
								},10)
						}
				else if(window.hrefData.leftIdx==1){
					var test10 = setInterval(function(){
								var messageObj=document.getElementById("mid_content");
								if(messageObj && messageObj.contentWindow.document.readyState=="complete"){
									exeClick(messageObj.contentWindow.document.getElementById("messge"));
									clearInterval(test10);
								}
							},10)
				
				}
			}
		},10)
	})
}



/**
 * 加载首页新闻 
 */
function loadNewsData(){
	AjaxExecute.setParameter({
				url : "eli/personal/getHomePageNews.do",
				data : '',
				type : 'json',
				onSuccess : function(rs) {
					cache.headNews=rs;
				}
	})
}


function loadPositionData(){
	AjaxExecute.setParameter({
				url : "resume/resumeAction.do?method=getOrgRecruitTitle",
				data : '',
				type : 'json',
				onSuccess : function(rs) {
					cache.headPosition=rs.position;
				}
	})
}
/**
 * 判断id为id 的iframe是否加载完成，加载完成后执行fn方法
 * @param {} id
 * @param {} fn
 */
function fmState(id,fn) {
		var state = null;
		if(document.all){
			state=window.frames[id].document.readyState;
		}else{
			state=window.document.getElementById(id).contentWindow.document.readyState;
		}
		if (state) {
			
			if (state == "complete" || !state) {// loading,interactive,complete
				fn();
				return;
			}
			window.setTimeout(function() {
						fmState(id, fn)
					}, 10);
		}

	};
	
/**
 * 兼容所有浏览器的点击函数
 * @param {} domObj
 */
function exeClick(domObj){
	if(document.all  && typeof(document.all)=="object"){//判断是否是IE浏览器
		domObj.click();//或者domObj.fireEvent("onclick");  
	}else if(document.createEvent){
		var evt = document.createEvent("MouseEvents"); 
		evt.initEvent("click", true, true); 
		domObj.dispatchEvent(evt); 
	}else if(document.createEventObject){
		domObj.fireEvent('onclick') 
	}
}

