/*
by Edream.
v0.293
*/
/*-------------------------------------DEFINE---------------------------------------*/
var Server = {
	main : "www.ufo007.com",
	UPay : "www.ufo007.com",
	zh_CN : "cn.ufo007.com",
	en : "en.ufo007.com",
	fr : "fr.ufo007.com",
	de : "fr.ufo007.com",
	it : "it.ufo007.com",
	es : "es.ufo007.com",
	ko : "ko.ufo007.com",
	ja : "ja.ufo007.com",
	fax : "fax.ufo007.com",
	mail : "mail.ufo007.com"
}

var Error = {}, Message;
Error.Login = {
	none : 0,
	invalidPassport : 1,
	wrongPassword : 2,
	wrongVerifyCode : 3,
	xmlhttpWaiting : 4,
	communicateFailure : 5,
	unexpectedReturn : 6,
	createDecoderFailed : 7,
	storeProcedureFailure : 8,
	unknownError : 9
};
Error.UPay = {
	none : 0,
	invalidAccount : 1,
	wrongPassword : 2,
	wrongVerifyCode : 3,
	invalidCurrency : 4,
	xmlhttpWaiting : 5,
	communicateFailure : 6,
	unexpectedReturn : 7,
	unauthorized : 8,
	createDecoderFailed : 9,
	storeProcedureFailure : 10,
	accountNotExist : 11,
	locked : 12,
	noExchangeRate : 13,
	logFailed : 14,
	updateFailed : 15,
	unknownDatabaseError : 16,
	moduleAdjusting : 17,
	unknownError : 18
};


var __OK = 1, __CANCEL = 2, __YES = 4, __NO = 8;
var __OKCANCEL = __OK + __CANCEL;
var __YESNO = __YES + __NO;

var __POST = "POST";
var __GET = "GET";

var __PERMANENT = 1;
/*-----------------------------------END DEFINE-------------------------------------*/
var Language;
//var IE = (navigator && navigator.appVersion && navigator.appVersion.indexOf("MSIE") > -1) ? true : false;
var __IE = (document.all && document.getElementById && !window.opera) ? true:false; 
var __MOZILLA = (!document.all && document.getElementById && !window.opera) ? true:false; 
var __OPERA = window.opera ? true : false;
//----------------------------------------------------------------------------------------------------//
function __Extend__(destination, source){
	for(property in source){
		destination.prototype[property] = source[property];
	}
}

__Extend__( String
,
	{
		trim : function(){
			return (this.length) ? this.replace(/(^\s*)|(\s*$)/g,"") : this.concat("");
		},
	
		ltrim : function(){
			return (this.length) ? this.replace(/(^\s*)/g,"") : this.concat("");
		},
	
		rtrim : function(){
			return (this.length) ? this.replace(/(\s*$)/g,"") : this.concat("");
		},
	
		byteLen : function(){
			return (this.length) ? this.replace(/[^\x00-\xFF]/gi,"xx").length : 0;
		},
		
		isEmail : function(){
			if(!this.length){return false;}
			if(!this.replace(/^[A-Za-z0-9]+(?:[A-Za-z0-9\+\-\._]*[A-Za-z0-9]+)?\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z]+$/ ,"")){return true;}
			return false;
		},
		
		string : function(number, character){
			if((number != 0 && !Number(number)) || !character){return "";}
			var str = "";
			for(var i = 0; i < number; i++){str.concat(character);}
			return str;
		},
		
		space : function(number){
			return this.string(number, " ");
		},
		
		emptyValue : function(substitute){
			return this.toString() ? this : substitute.toString();
		}
	}
);

__Extend__( Number
,
	{
		format : function(iDecimal_digits){
			var Str = this.toString();
			var Radix_point_pos;
			var Integral_part;
			var Decimal_part;
		
			if(!iDecimal_digits > 0)iDecimal_digits = 0;
			
			Radix_point_pos = Str.indexOf(".");
			if(Radix_point_pos < 0){
				Integral_part = Str;
				Decimal_part = ".";
			}
			else{
				Integral_part = Str.slice(0,Radix_point_pos);
				Decimal_part = "." + Str.substr(Radix_point_pos + 1);
			}
			for(var i=0;i<iDecimal_digits;i++){Decimal_part += "0";}
		
			Str = "";
			while(Integral_part){
				if(Str)Str = "," + Str;
				Str = Integral_part.substr(Integral_part.length - 3 >= 0 ? Integral_part.length - 3 : 0) + Str;
				Integral_part = Integral_part.substr(0,Integral_part.length - 3);
			}
		
			if(iDecimal_digits > 0)Str += Decimal_part.substr(0,iDecimal_digits + 1);
		
			return Str;
		}
	}
);

if(__MOZILLA){
	
	__Extend__( XMLDocument
	,
	{
		loadXML : function(xmlString){
			var childNodes = this.childNodes;
			for(var i = childNodes.length - 1; i >= 0; i--){this.removeChild(childNodes[i]);}
			
			var oDOMParser = new DOMParser();
			var DOM = oDOMParser.parseFromString(xmlString, "text/xml");
			this.appendChild(this.importNode(DOM.documentElement, true));
		},

		selectNodes : function(XPath){
			var oXPathEvaluator = new XPathEvaluator();
			var oXPathResult = oXPathEvaluator.evaluate(XPath, this, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
			var oNodes = [];
			for(var i = 0; i < oXPathResult.snapshotLength; i++){
				oNodes[i] =  oXPathResult.snapshotItem(i);
			}
			return oNodes;
		},
		
		selectSingleNode : function(XPath){
			var oNodes = this.selectNodes(XPath);
			if(oNodes.length > 0){return oNodes[0];}
			else{return null;}
		}
	}
	);

	__Extend__( Element
	,
	{
		selectNodes : function(XPath){
			if(this.ownerDocument.selectNodes){
				var oXPathEvaluator = new XPathEvaluator();
				var oXPathResult = oXPathEvaluator.evaluate(XPath, this, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
				var oNodes = [];
				for(var i = 0; i < oXPathResult.snapshotLength; i++){
					oNodes[i] =  oXPathResult.snapshotItem(i);
				}
				return oNodes;
			}
			else{throw "For XML Elements Only";}
		},
		
		selectSingleNode : function(XPath){    
			if(this.ownerDocument.selectSingleNode){
				var oNodes = this.selectNodes(XPath);
				if(oNodes.length > 0){return oNodes[0];}
				else{return null;}
			}
			else{throw "For XML Elements Only";}
		}
	}
	);
	
	window.constructor.prototype.__defineGetter__("event", __geckoEvent);
	
	Event.prototype.__defineGetter__("srcElement",
		function(){return this.target;}
	); 
	
	Element.prototype.__defineGetter__("text",
		function(){
			if(this.ownerDocument.selectSingleNode){
				return this.textContent;
			}
			else{throw "For XML Elements Only";}
		}
	);
	
	HTMLElement.prototype.__defineGetter__("runtimeStyle",
		function(){return this.style;}
	);
	
	HTMLElement.prototype.__defineGetter__("innerText",
		function(){
			return this.textContent ? this.textContent : "";
		}
	);
	HTMLElement.prototype.__defineSetter__("innerText",
		function(text){
			this.textContent = text;
		}
	);
	
	HTMLElement.prototype.__defineGetter__("className",
		function(){return this.getAttribute("class");}
	);
	HTMLElement.prototype.__defineSetter__("className",
		function(text){
			this.setAttribute("class", text);
		}
	);
	
	HTMLElement.prototype.click = function(){
		var evt = this.ownerDocument.createEvent("MouseEvents");
		evt.initMouseEvent("click", true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
		this.dispatchEvent(evt);
	};
}

var __Cookie = {
	set : function(name, value, path, domain, date){
		if(!name || typeof(name) != "string"){return false;}
		if(!path || typeof(path) != "string"){path = false;}
		if(!domain || typeof(domain) != "string"){domain = false;}
		if(!date || !date.constructor || date.constructor != Date){
			if(date == __PERMANENT){date = new Date(2031, 2, 12);}
			else{date = false;}
		}
		document.cookie = escape(name) + "=" + escape(value) + (domain ? "; domain=" + domain : "") + (path ? "; path=" + path : "") + (date ? "; expires=" + date.toGMTString() : "");
	},

	get : function(name){
		var arrCoolie;
		var arrCookies = document.cookie.split("; ");
		for(var i = 0; i < arrCookies.length; i++){
			var arrCoolie = arrCookies[i].split("=");
			if(name == unescape(arrCoolie[0])){return unescape(arrCoolie[1]);}
		}
		return null;
	},

	del : function(name){
		var date = new Date(1983, 2, 12);
		document.cookie = escape(name) + "=; expires=" + date.toGMTString();
	}
};
//----------------------------------------------------------------------------------------------------//
function $(id){return document.getElementById(id);}
function $n(name){return document.getElementsByName(name);}
function $t(tagName){return document.getElementsByTagName(tagName);}

function _(tagName){return document.createElement(tagName);}

function __closeWindow(){
	if(__IE){window.opener = window.name;}
	window.close();
}

function __reloadPage(b){
	b = b ? true : false;
	window.location.reload(b);
}

function __addFavorite(url, title){
	if(__IE){window.external.addFavorite(url, title);}
	else if(window.sidebar){window.sidebar.addPanel(title, url, "");}
}

function __setHomePage(url){
	if(__IE){
		var a = _("a");
		a.style.behavior = "url('#default#homePage')";
		a.setHomePage(url);
		a = null;
	}
}

function __geckoEvent(){
	var caller = arguments.callee.caller;
	var e = null;
	while(caller){
		e = caller.arguments[0];
		caller = caller.caller;
	}
	return e;
}

function __stopDefaultBehavior(){
	if(__IE){
		if(window.event){window.event.returnValue = false;}
	}
	else{
		var e = __event();
		if(e){e.preventDefault();}
		e = null;
	}
	return false;
}

function __stopPropagation(){
	if(__IE){
		if(window.event){window.event.cancelBubble = true;}
	}
	else{
		var e = __event();
		if(e){e.stopPropagation();}
		e = null;
	}
	return false;
}

function __NULL(){}

function __Msgbox(text, buttons, timeout){
	text = text ? text : "";
	buttons = buttons ? buttons : __OK;
	timeout = timeout ? timeout : 20000;
	return window.showModalDialog("/Common/Msgbox.asp", Array(text, buttons, timeout), "dialogWidth:400px;dialogHeight:220px;scroll:0;status:0;");
}

function __Inputbox(text, timeout){
	text = text ? text : "";
	timeout = timeout ? timeout : 20000;
	return window.showModalDialog("/Common/Inputbox.asp", Array(text, timeout), "dialogWidth:400px;dialogHeight:220px;scroll:0;status:0;");
}

function __Pwdbox(text, timeout){
	text = text ? text : "";
	timeout = timeout ? timeout : 20000;
	return window.showModalDialog("/Common/Pwdbox.asp", Array(text, timeout), "dialogWidth:400px;dialogHeight:158px;scroll:0;status:0;");
}

function __QueryString(){
	var data = [];
	var array = window.location.search.substr(1).split("&");
	for(var i = 0; i < array.length; i++){
		array[i] = array[i].split("=");
		if(typeof(array[i][1]) != "undefined"){eval("data[\"" + array[i][0] + "\"] = \"" + decodeURIComponent(array[i][1]).replace(/"/g, "\\\"") + "\";");}
	}
	return data;
}

function __DOM(){
	try{return new ActiveXObject("Msxml2.XMLDocument");}
	catch(Err){
		try{return new ActiveXObject("Microsoft.XMLDOM");}
		catch(Err){
			try{return document.implementation.createDocument("", "", null);}
			catch(Err){return null;}
		}
	}
}

function __XMLHTTP(){
	try{return new ActiveXObject("Msxml2.XMLHTTP");}
	catch(Err){
		try{return new ActiveXObject("Microsoft.XMLHTTP");}
		catch(Err){
			try{return new XMLHttpRequest();}
			catch(Err){return null;}
		}
	}
}

function HTTP(URL, Method, Async, User, Password){
	var XMLHTTP = __XMLHTTP();
	if(!XMLHTTP){return null;}
	if(URL){
		Method = (Method && Method.toUpperCase() == __GET) ? __GET : __POST;
		URL = URL.trim();
		Async = Async ? true : false;
		User = User ? User.trim() : false;
		Password = Password ? Password.trim() : false;
		
		XMLHTTP.open(Method, URL, Async, User, Password);
	}
	return XMLHTTP;
}

function __addListener(object, evt, fun, useCapture){
	if(!object || (!object.attachEvent && !object.addEventListener)){return false;}
	if(!evt || !evt.substr){return false;}
	if(typeof(fun) != "function"){
		try{fun = new Function(fun);}
		catch(e){return false;}
	}
	useCapture = useCapture ? true : false;
	
	if(__IE){
		object.attachEvent("on" + evt, fun);
	}
	else{
		object.addEventListener(evt, fun, useCapture);
	}
	return true;
}

function __bindingEvent(object, evt, fun){
	if(!object || (!object.attachEvent && !object.addEventListener)){return false;}
	if(!evt || !evt.substr){return false;}
	if(typeof(fun) != "function"){
		try{fun = new Function(fun);}
		catch(e){return false;}
	}
	eval("object.on" + evt + " = fun");
	return true;
}
//----------------------------------------------------------------------------------------------------//datetime
function __lastDayOfThisMonth(year, month){
	if(!Number(year) || !Number(month)){return 0;}
	try{return new Date(year, month, 0).getDate();}
	catch(e){return 0;}
}
//----------------------------------------------------------------------------------------------------//select
function __clearOptions(oSelect){
	if(!oSelect || !oSelect.tagName || oSelect.tagName != "SELECT"){return false;}
	for(var i = oSelect.length - 1; i >=0; i--){oSelect.remove(i);}
}

function __resetDay(year, month, oDay){
	if(!oDay || !oDay.tagName || oDay.tagName != "SELECT"){return false;}
	var i;
	var pre_Day = oDay.selectedIndex < 0 ? 0 : oDay.selectedIndex;
	var lastDay = __lastDayOfThisMonth(year, month);
	if(oDay.length >= lastDay){
		for(i = oDay.length - 1; i >= lastDay; i--){oDay.remove(i);}
	}
	else{
		for(i = oDay.length + 1; i <= lastDay; i++){oDay.options.add(new Option(i, i));}
	}
	oDay.selectedIndex = pre_Day >= lastDay  ? lastDay - 1 : pre_Day;
}
//----------------------------------------------------------------------------------------------------//login
function __webLogin(target, message){
	var uri = "https://www.ufo007.com/Member/?Lang=" + (Language ? encodeURI(Language) : "");
	uri += target ? "&T=" + encodeURI(target) : "";
	uri += message ? "&M=" + encodeURI(message) : "";
	window.location = uri;
}

function __UFO__(Passport, Password, VerifyCode){
	this.Passport = Passport;
	this.Password = Password;
	this.VerifyCode = VerifyCode;
	this.LoginCallback = false;
	this.LogoutCallback = false
	this.http = false;
}

__UFO__.prototype = {
	Logout : function(){
		if(!this.http){this.http = HTTP();}
		
		if(this.http.readyState == 2 || this.http.readyState == 3){
			if(typeof(this.LogoutCallback) == "function"){this.LogoutCallback(Error.Login.xmlhttpWaiting, "");}
			return false;
		}
		if(this.http.readyState > 1){this.http.abort();}
		
		this.http.open(__POST, "/Portal/?I=Logout", true, false, false);
		this.http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		var parent = this;
		this.http.onreadystatechange = function(){
			if(parent.http.readyState != 4){return false;}
			if(parent.http.status != 200){
				if(typeof(parent.LogoutCallback) == "function"){parent.LogoutCallback(Error.Login.communicateFailure, parent.http.responseText);}
				return false;
			}
			var xml = parent.http.responseXML;//.documentElement;
			var err = xml.selectSingleNode("/Response/Error/Number");
			var debug = xml.selectSingleNode("/Response/Error/Debug");
			debug = debug ? debug.text : "";
			if(!err || !err.text){
				if(typeof(parent.LogoutCallback) == "function"){parent.LogoutCallback(Error.Login.unexpectedReturn, parent.http.responseText);}
				return false;
			}
			switch(err.text){
				case "0":
					if(typeof(parent.LogoutCallback) == "function"){parent.LogoutCallback(Error.Login.none, "");}
					return false;
					break;
				default:
					if(typeof(parent.LogoutCallback) == "function"){parent.LogoutCallback(Error.Login.unknownError, parent.http.responseText);}
					return false;
					break;
			}
		};
		this.http.send("");
	},
	
	Login : function(){
		if(!this.Passport){
			if(typeof(this.LoginCallback) == "function"){this.LoginCallback(Error.Login.invalidPassport, "");}
			return false;
		}
		if(!this.Password){
			if(typeof(this.LoginCallback) == "function"){this.LoginCallback(Error.Login.wrongPassword, "");}
			return false;
		}
		if(!this.VerifyCode || this.VerifyCode.replace(/\d{5}/, "")){
			if(typeof(this.LoginCallback) == "function"){this.LoginCallback(Error.Login.wrongVerifyCode, "");}
			return false;
		}
		
		if(!this.http){this.http = HTTP();}
		
		if(this.http.readyState == 2 || this.http.readyState == 3){
			if(typeof(this.LoginCallback) == "function"){this.LoginCallback(Error.Login.xmlhttpWaiting, "");}
			return false;
		}
		if(this.http.readyState > 1){this.http.abort();}
		
		this.http.open(__POST, "/Portal/?I=Login", true, false, false);
		this.http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		var parent = this;
		this.http.onreadystatechange = function(){
			if(parent.http.readyState != 4){return false;}
			if(parent.http.status != 200){
				if(typeof(parent.LoginCallback) == "function"){parent.LoginCallback(Error.Login.communicateFailure, parent.http.responseText);}
				return false;
			}
			var xml = parent.http.responseXML;//.documentElement;
			var err = xml.selectSingleNode("/Response/Error/Number");
			var debug = xml.selectSingleNode("/Response/Error/Debug");
			debug = debug ? debug.text : "";
			if(!err || !err.text){
				if(typeof(parent.LoginCallback) == "function"){parent.LoginCallback(Error.Login.unexpectedReturn, parent.http.responseText);}
				return false;
			}
			switch(err.text){
				case "0":
					if(typeof(parent.LoginCallback) == "function"){parent.LoginCallback(Error.Login.none, "");}
					return false;
					break;
				case "8":
				case "512":
					if(typeof(parent.LoginCallback) == "function"){parent.LoginCallback(Error.Login.invalidPassport, "sp");}
					return false;
					break;
				case "16":
					if(typeof(parent.LoginCallback) == "function"){parent.LoginCallback(Error.Login.wrongPassword, "sp");}
					return false;
					break;
				case "64":
					if(typeof(parent.LoginCallback) == "function"){parent.LoginCallback(Error.Login.wrongVerifyCode, "sp");}
					return false;
					break;
				case "128":
					if(typeof(parent.LoginCallback) == "function"){parent.LoginCallback(Error.Login.createDecoderFailed, "");}
					return false;
					break;
				case "256":
					if(typeof(parent.LoginCallback) == "function"){parent.LoginCallback(Error.Login.storeProcedureFailure, debug);}
					return false;
					break;
				default:
					if(typeof(parent.LoginCallback) == "function"){parent.LoginCallback(Error.Login.unknownError, parent.http.responseText);}
					return false;
					break;
			}
		};
		var data = "Passport=" + escape(this.Passport) + "&Password=" + escape(this.Password) + "&VerifyCode=" + escape(this.VerifyCode);
		this.http.send(data);
		return true;
	}
}
//----------------------------------------------------------------------------------------------------//image
function __reloadImage(o){
	if(!o){o = this;}
	if(!o || !o.tagName || o.tagName.toLowerCase() != "img"){return false;}
	var imageURI = o.src;
	if(!imageURI){return false;}
	imageURI = imageURI.replace(/&Seed=[^&]*/gi, "").replace(/\?Seed=[^&]*&?/ig, "?");
	if(imageURI.indexOf("?") < 0){
		imageURI += "?Seed=" + Math.random();
	}
	else{
		imageURI += (imageURI.indexOf("?") == imageURI.length - 1 ? "" : "&") + "Seed=" + Math.random();
	}
	o.src = imageURI;
}

function __displayVerifyCodeImage(){//verify code
	var img = $("VCImage");
	if(!img || !img.style || img.style.display == ""){return false;}
	img.src = "/Common/VCode/?Seed=" + Math.random();
	img.style.display = "";
	img = null;
}
//----------------------------------------------------------------------------------------------------//alias
var Msgbox = __Msgbox;
var Pwdbox = __Pwdbox;
var Inputbox = __Inputbox;
//----------------------------------------------------------------------------------------------------//onPageLoad
function __pageLoad(){
	__addListener($("VerifyCode"), "focus", __displayVerifyCodeImage, false);
	__bindingEvent($("VCImage"), "click", "__reloadImage(this)", false);
	var oPassport = $("Passport");
	if(oPassport && (oPassport.offsetHeight > 0 || oPassport.offsetWidth > 0)){oPassport.focus();}
	oPassport = null;
}
__addListener(window, "load", __pageLoad, false);
