/**
 * @Remark  常用的js函数
 * @Author  miracle
 * @Create  time 2010-02-04 15:00
 * @Version v1.0 
 * 此文件需和jquery一起调用
 */

var isIE=(document.all&&document.getElementById&&!window.opera)?true:false;
var isMozilla=(!document.all&&document.getElementById&&!window.opera)?true:false;
var isOpera=(window.opera)?true:false;
var seturl='url(#default#homepage)';
var weburl=window.location.href;
var webname=document.title;

/**
 * tab菜单鼠标滑过调用函数，时间间隔为0.1秒
 * @Param name 滑过的元素的ID前缀
 * @Param x 当前为第几个
 * @Param n 共有多少个需要切换
 * DEMO
 * tabMenu命名：id="one_1" onmouseover="tagOver('one',1,3)" onmouseout="tagOut();"
 * 隐藏显示的div命名：id="con_one_1"
 */
var fodTime = 0;   //tab菜单切换参数
function tagOver(name,x,n,m){
	if(m)
	{
		setTab(name,x,n);
		$('#foo'+m).carouFredSel({
		prev: '#prev'+m,
		next: '#next'+m,
		pagination: "#pager"+m,
		auto: false
		});
	}else{
		//clearTimeout(fodTime);
		//fodTime = setTimeout(function(){
		setTab(name,x,n);
		//},100);
	}
}
function setTab(name,x,n){
    for(i=1;i<=n;i++){
	    var menu=document.getElementById(name+"_"+i);
	    var con=document.getElementById("con_"+name+"_"+i);
	    menu.className=i==x?"hover"+" li"+i:"";
	    con.style.display=i==x?"block":"none";
    }
}
/**
 * 鼠标滑出清除原先的滑动效果
 */
function tagOut(){
	clearTimeout(fodTime);
	fodTime=0;
}

/**
 * 登录时的前台JS验证
 */
function checkLogin()
{
    reg = /^\w{6,16}$/;
	pwd = /^[a-zA-Z0-9]{6,16}$/;
    sLogin = $("#username").val();
    sPassword = $("#password").val();
    sRegcode = $("#code").val();
	if (!reg.test(sLogin))
	{
		alert('请输入正确的通行证账号！');
		$("#username").focus();
		return false;
	}
	if (!pwd.test(sPassword))
	{
		alert('请输入正确的通行证密码！');
		$("#password").focus();
		return false;
	}
	if (sRegcode.length != 4)
	{
		alert('请输入验证码！');
		$("#code").focus();
		return false;
	}
}

/**
 * 单击更换验证码
 */
function changeRegImg()
{
	document.getElementById("codeimg").src = "https://passport.aiaigame.com/passport/code/"+Math.random();
}

/**
 * 取得字符串长度，将中文转换为2个字符
 */
function getLength(str) {
	var totallength=0;  
	for (var i=0;i<str.length;i++){
		var intCode=str.charCodeAt(i);
		if (intCode>=0&&intCode<=128) {
			totallength=totallength+1; //非中文单个字符长度加 1
		} else {
			totallength=totallength+2; //中文字符长度则加 2
		}
	}
	return totallength;
}

/*
 * 检查表单元素是否为空
 * @Param name 控件名称
 * @Param text 弹出的文字
 */
function isEmpty(name,text){
	if($("#"+name+"").val()==""){
		alert(text+"不能为空！");
		$("#"+name+"").focus();
		return true;
	}else{
		return false;
	}
}
/*
 * 检查表单元素是否在某个位数之间
 * @Param name 控件名称
 * @Param text 弹出的文字
 * @Param min  最小位数
 * @Param max  最大位数
 */
function isLength(name,text,min,max){
	var len = getLength($("#"+name+"").val());
	if(len<min || len>max){
		alert(text+"在"+min+"-"+max+"位字符之间！");
		$("#"+name+"").focus();
		return true;
	}else{
		return false;
	}
}

/*
 * 验证控件里的内容是否符合要求
 * @Param name：控件名称
 * @Param text：弹出的文字
 * @Param rextext：正则表达式的名称
 */
function RegexValid(name,text,rextext){
	var regexpress = eval("regexEnum."+rextext);
	var exp = new RegExp(regexpress,"i");
	if (!exp.test($.trim($("#"+name).val()))){
		alert(text);
		$("#"+name+"").focus();
		return true;
	}else {
		return false;
	}
}

/**
 * 隐藏或者移除某个div
 * @Param id   div的id
 * @Param type 类型：1、隐藏，2、移除
 */
function hideBox(id,type){
	if(type==2){
		$("#"+id).hide();
	}else{
		$("#"+id).remove();
	}
}

/**
 * 复制文本框的值
 * @Param vn  input id
 */
function copyborad(vn)
{
	var txt = document.getElementById(vn).value;
	try
	{
		window.clipboardData.clearData();
		if(window.clipboardData.setData("text",txt))alert("代码已经复制到剪贴板");
	}
	catch(e)
	{
		if(navigator.userAgent.indexOf("Opera") != -1)
		{
			  window.location = txt;
		}
		 else if (window.netscape)
		{
			try
			{
				   netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
				   alert("脚本内容已经复制到剪贴板");
			}
			catch (e)
			{
				alert("您的浏览器不支持剪贴板操作，请自行复制代码");
			}
			  var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
			  if (!clip)
				   return;
			  var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
			  if (!trans)
				   return;
			  trans.addDataFlavor('text/unicode');
			  var str = new Object();
			  var len = new Object();
			  var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
			  var copytext = txt;
			  str.data = copytext;
			  trans.setTransferData("text/unicode",str,copytext.length*2);
			  var clipid = Components.interfaces.nsIClipboard;
			  if (!clip)
				   return false;
			  clip.setData(trans,null,clipid.kGlobalClipboard);
		 }
	}
	return false;
}

/**
 * 设为首页
 */
function myhomepage() {
	if(isMozilla){
	   try {netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");}
	   catch (e){alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]设置为'true'");}
	   var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
	   prefs.setCharPref('browser.startup.homepage',weburl);
	}
	if(isIE){
	   this.homepage.style.behavior=seturl;this.homepage.sethomepage(weburl);
	}
}

/**
 * 加入收藏
 */
function addfavorite()
{
	if(isMozilla){
	   if (document.all){ window.external.addFavorite(weburl,webname);}
	   else if (window.sidebar){ window.sidebar.addPanel(webname, weburl,"");}
	}
	if(isIE){window.external.AddFavorite(weburl, webname);}
}

/**
 * 复制本页地址
 */
function copyToClipBoard(){
	if(isMozilla){
	   try {netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");}
	   catch (e){alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]设置为'true'");}
	   var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
	   prefs.setCharPref('browser.startup.homepage',weburl);
	}
	if(isIE){
		var clipBoardContent="";
		clipBoardContent+=webname+"："+weburl;//获取地址
		window.clipboardData.setData("Text",clipBoardContent);
		alert("您已成功复制了本页的地址!");
	}
} 

/**
 * 统一调用的页脚文件
 */
function jgfooter(){
	document.writeln('<a href="http://www.auroragame.net/introduction.html" target="_blank">公司介绍</a> ︱ <a href="http://www.auroragame.net/hr/join.html" target="_blank">联系我们</a> ︱ <a href="http://www.auroragame.net/hr/join.html" target="_blank">招聘信息</a> ︱  <a href="http://www.aiaigame.com/html/news/201001/427.html" target="_blank">商务合作</a>︱ <a href="http://www.aiaigame.com/default.html" target="_blank">友情链接</a><br />&copy; 2008 - 2010 极光互动 京ICP证090065号 <a href="http://www.aiaigame.com/common/image/www.jpg" target="_blank">文网文</a>[2010]008号<br />抵制不良游戏, 拒绝盗版游戏。 注意自我保护, 谨防受骗上当。 适度游戏益脑, 沉迷游戏伤身。');
}
/**
 * 其他页面调用的统一页脚
 */
function otherfooter(){
	document.writeln('&copy; 2008 - 2010 极光互动 京ICP证090065号 <a href="http://www.aiaigame.com/common/image/www.jpg" target="_blank">文网文</a>[2010]008号<br />抵制不良游戏, 拒绝盗版游戏。 注意自我保护, 谨防受骗上当。 适度游戏益脑, 沉迷游戏伤身。');
}

/**
 * 字体大小
 */
function fontsize(size,cls){
	$(cls).css("font-size",size);
}
