//try{
//	if(self!=top) top.location=self.location;
//}catch(e)
//{}

var $ = function(id)
{
	return document.getElementById(id);
}

String.prototype.trim = function()
{
	return this.replace(/(^[\s]*)|([\s]*$)/g, '');
}
String.prototype.trim2 = function()
{
  var vStr = this.trim();
  vStr = vStr.replace(/(^[\s]*)|([\s]*$)/g,   '');   
  vStr = vStr.replace(/(^[　]*)|([　]*$)/g,'');
  return  vStr;
}
String.prototype.strLength = function()
{
    var vStr = this.trim().split("");
    var vLength = 0;
    
    for (i = 0 ; i < vStr.length ; i++)
    {
		vTemp = escape(vStr[i]);
		vLength += (vTemp.indexOf("%u", 0) == -1) ? 1 : 2;
    }
    
    return vLength;
}

String.prototype.isUserName = function()
{
	var vStr = this.trim();
	var vReg = /^[a-zA-Z][\w]{3,50}$/;
	
	if(vStr.isEmail()) return true;
        if(vStr.isMobile()) return true;
	
	if(vReg.test(vStr))
        {
                return true;
        }
        else
        {
                var vRegAlipay = /[@(alipay|gld)]$/;
                return vRegAlipay.test(vStr);
        }
}

String.prototype.isNickName = function()
{
	var vStr = this.trim();
	var vReg = /^([\u4E00-\u9FA5]|[\uFE30-\uFFA0]|[\w])+$/;
	
	if (vStr.strLength() < 6 || vStr.strLength() > 25)
	{
		return false;
	} else {
		return vReg.test(vStr);
	}
}

String.prototype.isEmail = function()
{
	var vStr = this.trim();
	var vReg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	
	var ret = false;
	
	if (vStr.strLength() < 3 || vStr.strLength() > 50)
	{
		ret = false;
	} else {
		ret = vReg.test(vStr);
	}
	
	return ret;
}

String.prototype.isPassword = function()
{
	var vStr = this.trim();
	var vReg = /^[\w\W]{6,20}$/;
	return vReg.test(vStr);
}

String.prototype.isRealName = function()
{
	var vStr = this.trim();
	var vReg = /^([\u4E00-\u9FA5]|[\uFE30-\uFFA0]|[\w])+$/;
	
	if (vStr.strLength() < 1 || vStr.strLength() > 20)
	{
		return false;
	} else {
		return vReg.test(vStr);
	}
}

String.prototype.isAnswer = function()
{
	var vStr = this.trim();
	var vReg = /^([\u4E00-\u9FA5]|[\uFE30-\uFFA0]|[\w])+$/;
	
	if (vStr.strLength() < 1 || vStr.strLength() > 30)
	{
		return false;
	} else {
		return vReg.test(vStr);
	}
}

String.prototype.isZipCode = function()
{
	var vStr = this.trim();
	var vReg = /^([0-9]{6})$/;
	return vReg.test(vStr);
}

String.prototype.isTel = function()
{
	var vStr = this.trim();
	var vReg = /^[\d\-]{6,20}$/;
	return vReg.test(vStr);
}

String.prototype.isMobile = function()
{
	var vStr = this.trim();
	//var vReg = /^(13[4-9]|15(0|1|2|7|8|9))\d{8}$/;
	var vReg = /^1(3|4|5|8)\d{9}$/;
	return vReg.test(vStr);
}

String.prototype.isProof = function()
{
	var vStr = this.trim();
	var vReg = /^[\d]{8}\-0[\d]+\-[0-9a-fA-F]{6}$/;
	return vReg.test(vStr);
}

String.prototype.isIDCard = function()
{
	var vCid = this.trim();
	var vSum = 0;
	var vReg = /^([\d]{17}[xX\d]|[\d]{15})$/;
	var vCity = '|11|12|13|14|15|21|22|23|31|32|33|34|35|36|37|41|42|43|44|45|46|50|51|52|53|54|61|62|63|64|65|71|81|82|91|';
	
	if (!vReg.test(vCid)) return false;
	
	if(vCity.indexOf(parseInt(vCid.substr(0,2))) == '-1') return false;
	
	vCid = vCid.replace(/[xX]$/i, 'a');
	
	if (vCid.length == 18)
	{
		vBirthday = vCid.substr(6, 4) + '/' + Number(vCid.substr(10, 2)) + '/' + Number(vCid.substr(12, 2));
	} else {
		vBirthday = '19' + vCid.substr(6, 2) + '/' + Number(vCid.substr(8, 2)) + '/' + Number(vCid.substr(10, 2));
	}
	
	var vDate = new Date(vBirthday);
	
	if (vBirthday != (vDate.getFullYear() + '/' + (vDate.getMonth() + 1) + '/' + vDate.getDate())) return false;
	
	if (vCid.length == 18)
	{
		for(var i = 17 ; i >= 0 ; i--) vSum += (Math.pow(2, i) % 11) * parseInt(vCid.charAt(17 - i), 11);
  		if(vSum % 11 != 1) return false;
  	}
  	
  	return true;
}

String.prototype.isInt = function()
{
	var vStr = this.trim();
	var vReg = /^([1-9]+)([0-9]*)$/;
	return vReg.test(vStr);
}

String.prototype.isMoney = function()
{
	var vStr = this.trim();
	var vReg = /^\d+(\.\d{1,2})?$/;
	return vReg.test(vStr);
}

String.prototype.isEnglish = function()
{
	var vStr = this.trim();
	var vReg = /^[A-Za-z]+$/;
	return vReg.test(vStr);
}

String.prototype.isChinese = function()
{
	var vStr = this.trim();
	var vReg = /^[\u0391-\uFFE5]+$/;
	return vReg.test(vStr);
}

String.prototype.isCardNo = function()
{
	var vStr = this.trim();
	var vReg = /^[0-9A-Z]{2}[\d]{14}$/;
	return vReg.test(vStr);
}

String.prototype.isCardPwd = function()
{
	var vStr = this.trim();
	var vReg = /^[\d]{8,12}$/;
	return vReg.test(vStr);
}

String.prototype.isSzxCardNo = function()
{
	var vStr = this.trim();
	var vReg = /^[\d]{17}$/;
	return vReg.test(vStr);
}

String.prototype.isSzxCardPwd = function()
{
	var vStr = this.trim();
	var vReg = /^[\d]{18}$/;
	return vReg.test(vStr);
}

function $(vId)
{
	if (typeof(vId) == 'object') return vId;
	return document.all ? document.all[vId] : document.getElementById(vId);
}

function keepSameHeight()
{
	var vAct = action.split('.');
	
	try
	{
		$('rightContent').style.height = ($('sideBar').clientHeight - $('navBar').clientHeight - 60) + 'px';
	} catch (e) {}
}

function showBox(vHTML)
{
	$('MsgBoxBackground').style.height = document.body.scrollHeight + 'px';
	$('MsgBoxBackground').style.width = document.body.scrollWidth + 'px';
	$('MsgBoxContent').innerHTML = vHTML;
	$('MsgBoxContent').style.top = (document.documentElement.scrollTop + 
		(document.documentElement.clientHeight - $('MsgBoxContent').clientHeight) / 2) + 'px'; 
	$('MsgBoxContent').style.left = (document.documentElement.scrollLeft + 
		(document.documentElement.clientWidth - $('MsgBoxContent').clientWidth) / 2) + 'px'; 
	
	var allSelects = document.getElementsByTagName('SELECT');
	
	for (i = 0 ; i < allSelects.length ; i++)
	{
		allSelects[i].style.visibility = 'hidden';
	}
	
	$('MsgBoxBackground').style.visibility = 'visible';
	$('MsgBoxContent').style.visibility = 'visible';
}

function hideBox()
{
	$('MsgBoxContent').innerHTML = '';
	$('MsgBoxContent').style.top = '0px';
	$('MsgBoxContent').style.left = '0px'; 
	
	var allSelects = document.getElementsByTagName('SELECT');
	
	for (i = 0 ; i < allSelects.length ; i++)
	{
		allSelects[i].style.visibility = 'visible';
	}
	
	$('MsgBoxBackground').style.visibility = 'hidden';
	$('MsgBoxContent').style.visibility = 'hidden';
}

function showCaptcha(){
	if($("captchaimage"))
	{
		$("captchaimage").style.display = '';
	}
	else
	{
		flashCaptcha();
	}
}

function flashCaptcha(){
	var captchaurl = '/?act=index.verify&r=' + Math.random();
	$("captchaimagediv").innerHTML='<div style="position: absolute;left:50px;top:-85px"><a href="javascript:changeVerify(\'captchaimage\');" title="点击更换验证码"><img id="captchaimage" src="' + captchaurl + '" /></a>';
}

function hiddenCaptcha(){
        $("captchaimage").style.display = 'none';
}

function changeVerify(img_id, input_id)
{
        try
        {
        	var id = img_id || 'verifyImg';
            $(id).src = './?act=index.verify&r=' + Math.random();
            showVerify(img_id);
            if (input = $(input_id || 'verify_input')) input.value = '';
        } catch (e) {}
}

function changeVerifyCode()
{
	try
	{
		var id = 'verifyImg';
		$(id).src = 'http://www2.koramgame.com/?act=index.verify&r=' + Math.random();
		if (input = $('verify')) input.value = '';
	} catch (e) {}
}

function checkLogin(vForm)
{
	if (!vForm.elements['username'].value.isUserName() && !vForm.elements['username'].value.isEmail())
	{
		alert('请输入正确的用户名！');
		vForm.elements['username'].focus();
		return false;
	}
	
	if (!vForm.elements['userpass'].value)
	{
		alert('请输入密码！');
		vForm.elements['userpass'].focus();
		return false;
	}
		
	if(!vForm.elements['usercode'].value)
	{
	    alert('请输入正确的验证码！');
		vForm.elements['usercode'].focus();
		return false;
	}
	
	return true;
}

function add2Favorite()
{	
	try{
		
		if (window.sidebar) {
			window.sidebar.addPanel(document.title, location.href,"#");
		} else if( document.all ) {
			window.external.AddFavorite( location.href,document.title);
		}
		
	}catch(e){}
}

function addHome()
{
    if (window.sidebar)
    {
        try {
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
        }
        catch (e)
        {
            alert("您的浏览器不支持第三方【设为首页】功能，需手动设置，谢谢您的支持");
        }

        var prefs =  Components.classes["@mozilla.org/preferences-service;1"].getService( Components.interfaces.nsIPrefBranch );
        prefs.setCharPref("browser.startup.homepage",location.href);
    }
    else if(document.all)
    {
        document.body.style.behavior="url(defaulthomepage)";
        document.body.setHomePage(location.href);
    }
    else
    {
        alert("您的浏览器不支持第三方【设为首页】功能，需手动设置，谢谢您的支持");
    }
}

function showVerify(container_id)
{
	var container = $(container_id || 'verify_container');
	if (!container) return;
	container.style.display = (container.tagName.toLowerCase() == 'img' ? 'inline' : 'block');
	
	img = container.getElementsByTagName('img')[0];
	
	if (img.src.indexOf('/?act=') == -1)
	{
		changeVerify(img.id);
	}
}

function hideVerify(container_id)
{
	var container = $(container_id || 'verify_container');
	if (!container) return;
	container.style.display = 'none';
}

function facebook_onlogin() {
	location.href='/?act=index.checklogin';
}

function GetThis(T, C, U, L){ 
	var targetUrl = 'http://www.myspace.com/index.cfm?fuseaction=postto&' + 't=' + encodeURIComponent(T) + '&c=' + encodeURIComponent(C) + '&u=' + encodeURIComponent(U) + '&l=' + L;
	
	window.open(targetUrl);
}

function subemail()
{
	var img = new Image();
	if($('email').value.isEmail())
	{
		img.src='http://tk.koramgame.com/thankyou.php?email='+encodeURI($("email").value);
		alert(vSubscribe['success']);
	}
	else
	{
		alert(vLoginNotice['username'][1]);
		$("email").focus();
	}
	$("email").value="#";
}


function cannel_subemail()
{
	var img = new Image();
	if($('email').value.isEmail())
	{
		img.src='http://tk.koramgame.com/thankyou.php?del=1&email='+encodeURI($("email").value);
		alert(vSubscribe['cannel']);
	}
	else
	{
		alert(vLoginNotice['username'][1]);
		$("email").focus();
	}
	$("email").value="#";
}

function showlanglist()
{
	$('tab390').style.display = '';
}

function hiddenlanglist()
{
	$('tab390').style.display = 'none';
}
