//设为首页方法
//<a href="" class="SetAsHomepage" rel="setAsHomepage">设为首页</a>
function setAsHomepage(element,Url){
	try{
		element.style.behavior='url(#default#homepage)';element.setHomePage(Url);
	}
	catch(e){
		if(window.netscape){
			try{
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
			}  
			catch (e) { 
				alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将[signed.applets.codebase_principal_support]设置为'true'"); 
				return false;  
			}
			var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
			prefs.setCharPref('browser.startup.homepage',Url);
		}
	}
}

//添加书签方法
//<a href="" title="" class="AddToBookmark" rel="addToBookmark">加入书签</a>
function addToBookmark(WebsiteName,Url,Description)   
{
	if (window.sidebar) {  
		window.sidebar.addPanel(WebsiteName,Url,Description); //Mozilla browser  
	} else if( document.all ) { //IE browser  
		window.external.AddFavorite(Url, WebsiteName);   
	} else if( window.opera && window.print ) { //Not Support Now  
		return true;  
	}  
}

//去掉字符串左右空格方法   
function trim(m){
	 while((m.length>0)&&(m.charAt(0)==''))   
		m   =   m.substring(1, m.length);   
	 while((m.length>0)&&(m.charAt(m.length-1)==''))   
		m = m.substring(0, m.length-1);   
	 return m;   
}

/* 
**************图片预加载 等比例缩放 插件****************** 
///说明：在图片加载前显示一个加载标志，当图片下载完毕后显示图片出来 
可对图片进行是否自动缩放功能 
此插件使用时可让页面先加载，而图片后加载的方式， 
解决了平时使用时要在图片显示出来后才能进行缩放时撑大布局的问题 
///参数设置： 
scaling 是否等比例自动缩放 (为false时按参数值直接缩放)
width 图片最大高 (宽小于等于0时，根据高缩放)
height 图片最大宽 (高小于等于0时，根据宽缩放)
loadpic 加载中的图片路径 
*/ 
jQuery.fn.LoadImage=function(scaling,width,height,loadpic){ 
	if(loadpic==null) loadpic="images/imgload.gif";
	return this.each(function(){
		var t=$(this); 
		var src=$(this).attr("src") 
		var img=new Image(); 
		//alert("Loading") 
		img.src=src; 
		//自动缩放图片 
		var autoScaling=function(){ 
			if(scaling){ 
				if(img.width>0 && img.height>0){ 
					if(width<=0){
						if(height<img.height){
							t.height(height);
							t.width((img.width/img.height)*height);
						}
						else{
							t.height(img.height);
							t.width(img.width);
						}
					}
					else if(height<=0){
						if(width<img.width){
							t.width(width);
							t.height((img.height/img.width)*width); 
						}
						else{
							t.height(img.height);
							t.width(img.width);
						}
					}
					else if(img.width/img.height>=width/height){ 
						if(img.width>width){ 
							t.width(width); 
							t.height((img.height*width)/img.width); 
						}else{ 
							t.width(img.width); 
							t.height(img.height); 
						} 
					} 
					else{ 
						if(img.height>height){ 
							t.height(height); 
							t.width((img.width*height)/img.height); 
						}
						else{ 
							t.width(img.width); 
							t.height(img.height); 
						} 
					} 
				} 
			} 
			else{
				t.width(width);
				t.height(height);	
			}
		} 
		//处理ff下会自动读取缓存图片 
		if(img.complete){ 
			//alert("getToCache!"); 
			autoScaling(); 
			return; 
		} 
		$(this).attr("src",""); 
		var loading=$("<img alt=\"加载中\" title=\"图片加载中\" src=\""+loadpic+"\" />"); 
		
		t.hide(); 
		//t.after(loading); 
		$(img).load(function(){ 
			autoScaling(); 
			loading.remove(); 
			t.attr("src",this.src); 
			t.show(); 
			//alert("finally!") 
		}); 
	
	}); 
} 
/*
使用说明：
1.$("div img").LoadImage(true,100,100); 
2.onload="$(this).LoadImage(true,100,100)"
*/

/*选项卡函数js*/
/*顶部菜单选项卡*/
function show1(n){
	var li1=$('#menu li a');
	var li2=$('#menu2 li');
	for(i=0;i<li1.length;i++){
		if(i==n){
			$(li1[i]).addClass("ahover");
			$(li2[i]).show();
		}
		else{
			$(li1[i]).removeClass("ahover");
			$(li2[i]).hide();
		}
	}
}
/*左侧伸缩选项卡*/
function show2(n){
	var li1=$('.l1 a');
	var li2=$('.l2');
	for(i=0;i<li1.length;i++){
		if(i==n){
			$(li2[i]).slideToggle('fast');
			//$(li1[i]).addClass("ahover");
		}
		else{
			$(li2[i]).slideUp('fast');
			//$(li1[i]).removeClass("ahover");
		}
	}
}
/*首页培训外包产品选项卡*/
function show3(n){
	var li1=$('#tab_top li.li_tab1');
	var li2=$('#tab_bottom div.li_tab2');
	for(i=0;i<li1.length;i++){
		if(i==n){
			$(li1[i]).addClass("lihover");
			$(li2[i]).fadeIn(300);
		}
		else{
			$(li1[i]).removeClass("lihover");
			$(li2[i]).hide();
		}
	}
}

//***********************网页监听区******************************/
//监听网页的单击事件
document.onclick = function(e)
{
  var target = e ? e.target : window.event.srcElement;
  while (target && !/^(a|body)$/i.test(target.nodeName))
  {
    target = target.parentNode;
  }
  if (target && target.getAttribute('rel'))
  {
  	if (target.rel == 'external'){ /*打开新窗口*/
	    var external = window.open(target.href);
	    return external.closed;
    } 
	else if (target.rel == 'setAsHomepage'){ /*设为首页*/
    	setAsHomepage(target,target.href);
    	return false;
    } 
	else if (target.rel == 'addToBookmark'){  /*添加书签*/
    	addToBookmark(target.title,target.href,"");
    	return false;
    }
  }
}

//***********************预加载区******************************//
$(document).ready(function(){
	$(".con img").LoadImage(true,673,0);
	//--限制 文章图片列表缩略图比例
	$(".art_img_list img.path_thumb").LoadImage(true,100,100);
	//--限制 新闻详情页缩略图比例
	$(".news_info img.path_thumb").LoadImage(true,100,100);
	//--限制 图片列表页缩略图比例
	$(".imglist img.path_thumb").LoadImage(false,101,118);
	//--限制 团队详情页图比例
	$(".teaminfo img.path_thumb").LoadImage(true,120,0);
	
	/*弹出注册与登陆框 artdialog插件*/
	$('#login').click(function(){
		art.dialog({id:'reg_box'}).close();
		art.dialog({id:'login_box', width:'350', height:'220', title:'会员登陆', iframe:'/login.php'}, function(){
			var msg = art.dialog({id:'login_box'}).data.iframe;// 使用内置接口获取iframe对象

			var username = msg.document.getElementById('username');
			var pwd = msg.document.getElementById('pwd');
			var code_text = msg.document.getElementById('code_text');
			if (username.value == '') {
				username.focus();
				msg.document.getElementById('tips').innerHTML = '请输入用户名！';
				return false; // 返回false即可阻止对话框关闭
			}
			else if (pwd.value == '') {
				pwd.focus();
				msg.document.getElementById('tips').innerHTML = '请输入密码！';
				return false; // 返回false即可阻止对话框关闭
			}
			else if (code_text.value == '') {
				code_text.focus();
				msg.document.getElementById('tips').innerHTML = '请输入验证码！';
				return false; // 返回false即可阻止对话框关闭
			}
			msg.document.getElementById('loginform').submit();
		}, function(){});
		return false;
	});
	
	/*弹出注册与登陆框 artdialog插件*/
	$('#reg').click(function(){
		art.dialog({id:'login_box'}).close();
		art.dialog({id:'reg_box', width:'350', height:'475', title:'会员注册', iframe:'/reg.php'}, function(){
			var msg = art.dialog({id:'reg_box'}).data.iframe;// 使用内置接口获取iframe对象

			var username = msg.document.getElementById('username');
			var pwd = msg.document.getElementById('pwd');
			var dbpwd = msg.document.getElementById('dbpwd');
			var email = msg.document.getElementById('email');
			var code_text = msg.document.getElementById('code_text');
			var name = msg.document.getElementById('name');
			var tel = msg.document.getElementById('tel');
			var mobile = msg.document.getElementById('mobile');
			var qq = msg.document.getElementById('qq');
			if (username.value == '') {
				username.focus();
				msg.document.getElementById('tips').innerHTML = '用户名不能为空！';
				return false; // 返回false即可阻止对话框关闭
			}
			else if (pwd.value == '') {
				pwd.focus();
				msg.document.getElementById('tips').innerHTML = '密码不能为空！';
				return false; // 返回false即可阻止对话框关闭
			}
			else if (pwd.value != dbpwd.value) {
				dbpwd.focus();
				msg.document.getElementById('tips').innerHTML = '两次输入的密码不一致！';
				return false; // 返回false即可阻止对话框关闭
			}
			else if (email.value == '') {
				dbpwd.focus();
				msg.document.getElementById('tips').innerHTML = '注册邮箱不能为空！';
				return false; // 返回false即可阻止对话框关闭
			}
			else if (code_text.value == '') {
				code_text.focus();
				msg.document.getElementById('tips').innerHTML = '验证码不能为空！';
				return false; // 返回false即可阻止对话框关闭
			}
			else if (name.value == '') {
				name.focus();
				msg.document.getElementById('tips').innerHTML = '请输入您的真实姓名！';
				return false; // 返回false即可阻止对话框关闭
			}
			else if (tel.value == '' && mobile.value == '' && qq.value == '') {
				msg.document.getElementById('tips').innerHTML = '电话、手机和qq请至少输入一个！';
				return false; // 返回false即可阻止对话框关闭
			}
			msg.document.getElementById('regform').submit();
		}, function(){});
		return false;
	});
});

