//try{
//	if(self!=top) top.location=self.location;
//}catch(e)
//{}

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,20}$/;
	return vReg.test(vStr);
}

String.prototype.isNickName = function()
{
	var vStr = this.trim();
	var vReg = /^([\u4E00-\u9FA5]|[\uFE30-\uFFA0]|[\w])+$/;
	
	if (vStr.strLength() < 4 || 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+)*$/;
	
	if (vStr.strLength() < 6 || vStr.strLength() > 50)
	{
		return false;
	} else {
		return vReg.test(vStr);
	}
}

String.prototype.isPassword = function()
{
	var vStr = this.trim();
	if(vStr.strLength() < 6)
	{
		return false;
	}
	return true;
//	var vStr = this.trim();
//	var vReg = /^[\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}$/;
	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.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);
}

function $(vId)
{
	if (typeof(vId) == 'object') return vId;
	return document.all ? document.all[vId] : document.getElementById(vId);
}

function changeVerify()
{
	try
	{
		$("verifyImg").src = './?act=index.verify&r=' + Math.random();
	} catch (e) {}
}

function checkLogin(vForm)
{
	
	if (vForm.elements['username'].value=='')
	{
		alert('Please enter your account.');
		vForm.elements['username'].focus();
		return false;
	}
		
	if (!vForm.elements['username'].value.isEmail())
	{
		alert('Please enter a valid Email address');
		vForm.elements['username'].focus();
		return false;
	}

	if (vForm.elements['password'].value=='')
	{
		alert('Please enter your password.');
		vForm.elements['password'].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 textdown(e)
{textevent = e ;
if(textevent.keyCode == 8)
{
	return;
}
if(document.getElementById('details').value.length >= 64000)
{
	if(!document.all)
	{
		textevent.preventDefault();
	}
	else
	{
		textevent.returnValue = false;
	}
}
}
function textup()
{
	var s = document.getElementById('details').value;
	if(s.length > 64000)
	{
		document.getElementById('details').value=s.substring(0,64000);
	}
}

function updown(divid)
{
	if($("rdiv_"+divid).style.display=="none")
	{

		$("rdiv_"+divid).style.display="";
		$("title_"+divid).className="now";
	}
	else
	{
		$("rdiv_"+divid).style.display="none";
		$("title_"+divid).className="nav";
	}
}

function subemail(){
	var img = new Image();
	if($("email").value)
	{
		img.src='http://tk.koramgame.com/thankyou.php?email='+encodeURI($("email").value);
		alert("Successfully booked");
	}
	else
	{
		$("email").focus();
	}
	$("email").value="";
}

function facebook_onlogin() {
	location.href='/?act=index.checklogin';
}
function fbs_click() {
	u=location.href;
	t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}
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 bebo_click() {
	u=location.href;
	t=document.title;
	window.open('http://www.bebo.com/c/share?Url='+encodeURIComponent(u)+'&Title='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}

function SignOutFromFaceBook()
{
	try
	{
		FB.Connect.logout(function() {

			document.location.href = "http://www.koramgame.com/?act=index.logout";
		});
	}
	catch( Error )
	{
		document.location.href = "http://www.koramgame.com/?act=index.logout";
	}
	return false;
}

function popupFacebookInvite(){
FB.IFrameUtil.CanvasUtilServer.run(true);
var _d2=document.createElement("div");
_d2.setAttribute("iframeHeight","500px");
_d2.setAttribute("iframeWidth","770px");
var _d3=new FB.UI.PopupDialog("Invite Your Friends to Join The KoramGame",_d2,false,false);
_d3.setContentWidth(760);
_d3.setContentHeight(500);
_d3.set_placement(FB.UI.PopupPlacement.center);
_d2.setAttribute("fbml","<fb:fbml>"+"<fb:request-form style=\"width:630px; height:560px;\" action=\""+document.location.href+"\"\tmethod=\"POST\" invite=\"false\" type=\"The KoramGame Friend\" "+"content=\"I'd like to add you as a friend on The KoramGame: <fb:req-choice url='http://www.koramgame.com/?ref=fbinvite' label='Confirm' />\">"+"<fb:multi-friend-selector\tshowborder=\"false\" actiontext=\"Invite your friends to The KoramGame\" rows=\"3\" bypass=\"cancel\"\tshowborder=\"false\" />"+"</fb:request-form>"+"</fb:fbml>");
_d3.show();
FB_RequireFeatures(["XFBML"],function(){
var _d4=new FB.XFBML.ServerFbml(_d2);
FB.XFBML.Host.addElement(_d4);
});
}