/******************************
 *Filename:      random.js
 *Version:       1.0.0(05/22/2009)
 *Website:       http://
 *Author:        S.SL
 *Update:        33(09/14/2009)
                 millet(11/20/2009)
*******************************/

function CookieDAO(){
	var o = this;

	this.getCookie = function( exit_cookie_name ){
		var cookieStr = document.cookie;
		
		if (cookieStr == ""){
			return; 
		}

		var cookieValue = cookieStr.split("; "); 
		
		var startPos = -1;
		var endPos = -1;
		for( var i=0; i < cookieValue.length; i++ ){
			startPos = cookieValue[i].indexOf( exit_cookie_name );

			if (startPos != 0){
				continue;
			}

			startPos += exit_cookie_name.length + 1;
			endPos = cookieValue[i].length;
			
			var exit_cookie_value = unescape( cookieValue[i].substring( startPos,endPos ) );
			return exit_cookie_value;
		}
		return;
	}
	
	this.setCookie = function( new_cookie_name ,new_cookie_value){
		var the_date = new Date("December 31, 2020");
		var expiresDate = the_date.toGMTString();
		document.cookie = new_cookie_name + "=" + escape( new_cookie_value ) + ";expires=" + expiresDate + ";path=/;"; 
	}
	
	this.deleteCookie = function( del_cookie_name ){
		var exp = new Date();   
		exp.setTime( exp.getTime() - 1 );   
		var cval = o.getCookie( del_cookie_name );   
		document.cookie = del_cookie_name + "=" + cval + "; expires=" + exp.toGMTString();  
	}
	
	function init(){
	}
	
	init();
	
}

function toversion(){
	var o = this;
	var newcookie = new CookieDAO();
	
	if( newcookie == null ) return;
	
	/*Update cookie name[33:2009/09/14]*/
	var cookie_name = "index_auth";

	function do_style(){
		var css = '';

		css += '<style type="text/css">';
		
		css += '.version{ float:left; padding-top:7px; display:inline; text-align:left;position:relative;}';
		css += '.version, .version a{ color:#ffffff;}';
		css += '.choose_version, .choose_version dt, .version_welcome{ float:left;}';
		css += '.version_welcome{padding-left:5px; line-height:18px;}';
		css += '.version_welcome a{text-decoration:underline; color:#ffcf0f;}';
		css += '.noteico, .btn_jump{background:url(http://images.mmosite.com/www/images200909/version_ico.gif) no-repeat;}';
		css += '.noteico, .notebox{position:absolute;}';
		css += '.noteico{ width:20px; height:18px; background-position:left -20px; left:60px; top:30px; z-index:4;}';
		css += '.notebox{ width:214px; left:10px; top:45px; z-index:3;}';
		css += '.notebox_top, .notebox_center, .notebox_bottom{background:url(http://images.mmosite.com/www/images200909/notebox.gif) no-repeat;}';
		css += '.notebox_top, .notebox_bottom{ width:100%;  height:14px;}';
		css += '.notebox_bottom{ background-position:right top;}';
		css += '.notebox_center{ width:194px; padding:5px 10px; background-position:center top; background-repeat:repeat-y;}';
		css += '.notebox_center p{ line-height:16px; font-size:12px; padding:0px 5px;}';
		css += '.notebox_center ul{ width:100%; padding:10px 0;}';
		css += '.notebox_center li{ float:left; width:147px; color:#ffc961; line-height:26px;}';
		css += '.btn_jump{ width:106px; height:20px; background-position:left -38px; cursor:pointer; border:none; margin:5px 0 0 40px; color:#474747;}';
		css += '</style>';

		document.write( css );
		
	}
	
	function do_div( k ){
		var div_cnt = '';
		
		div_cnt += '<div class="version">';
		div_cnt += '<span class="version_welcome" id="version_welcome">Go to <a href="#" id="version1" onclick="my_v.toJR(\'http://www.mmosite.com/\',\'NOR\');return false;">US-EU</a><a href="#"  id="version2" onclick="my_v.toJR(\'http://www.mmosite.com/iphome/index_sea.shtml\',\'SEA\');return false;">Southeast Asia</a> | <a href="http://news.mmosite.com/specials/adult/" target="_blank">18+</a> Version</span>';
		div_cnt += '  <div class="choose_version">';
		
		if( k == 1 ){
			div_cnt += '  <div class="firstopen" id="firstopen">';
			div_cnt += '	<span class="noteico"></span>';
			div_cnt += '	<div class="notebox">';
			div_cnt += '	  <div class="notebox_top"></div>';
			div_cnt += '	  <div class="notebox_center">';
			div_cnt += '		<p>You can click here to choose from US-EU / Southeast Asia Version and record it.</p>';
			div_cnt += '		<input name="" type="button" class="btn_jump" value="OK I get it" onclick="my_v.toJR(\'#\',\'NOTE\')" />';
			div_cnt += '	  </div>';
			div_cnt += '	  <div class="notebox_bottom"></div>';
			div_cnt += '	</div>';
			div_cnt += '  </div>';
		}
		
		div_cnt += '  </div>';
		div_cnt += '</div>';
		div_cnt += '<div class="top_contest"><a href="http://forum.mmosite.com/topics/54/200911/16/11544,1.html?time=1258428021#tip96364" target="_blank">Help Improve MMOsite</a>&nbsp;&nbsp;&nbsp;<a href="http://download.mmosite.com/download.php?id=3909" target="_blank">SpeederXP</a></div>';

		document.write( div_cnt );

	}
	
	function toJump( url ){
		if( url == "#" ){
			var firstopen = document.getElementById("firstopen");
			if( firstopen != null )
				firstopen.style.display = "none";
		} else {
			window.location = url;
		}
		
		return false;
	}
	
	this.toJR = function( url,cookieStr ){
		newcookie.setCookie( cookie_name,cookieStr );
		toJump( url );
	}
	
	this.init = function(){
		do_style();
		var url;
		var area = newcookie.getCookie( cookie_name );
		
		/*Update cookie url[millet:10/20/2009]*/
		switch(area){
			case 'EU':	
				url = 'http://www.mmosite.com/'
				break
			case 'US':	
				url = 'http://www.mmosite.com/'
				break
			case 'SEA':	
				url = 'http://www.mmosite.com/iphome/index_sea.shtml'
				break
			case 'NOR':	
				url = 'http://www.mmosite.com/'
				break
			case 'NOTE':	
				url = window.location.href;
				break
			default:
				//url = 'http://www.mmosite.com/'
		}
                            
		if( url == null || url == undefined ){
			do_div(1);
		} else {
			//alert( url )
			do_div(0);
			
			var prv_url = window.location.href;
			if( prv_url != url ){
				toJump( url );
			}
		
		}
	}
	
	//init();
	
}
var my_v = new toversion();

// store cookie value with optional details as needed
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape (value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getExpDate(days, hours, minutes) {
    var expDate = new Date( );
    if (typeof days == "number" && typeof hours == "number" &&
        typeof hours == "number") {
        expDate.setDate(expDate.getDate( ) + parseInt(days));
        expDate.setHours(expDate.getHours( ) + parseInt(hours));
        expDate.setMinutes(expDate.getMinutes( ) + parseInt(minutes));
        return expDate.toGMTString( );
    }
}

var sExpDate = getExpDate(24, 0, 0);	//cookie save 24 hours

function nowVersion(nowVersion){
	if(nowVersion != "Southeast Aisa"){
	document.getElementById("version1").style.display="none";	
	}else{
	document.getElementById("version2").style.display="none";	}
}