﻿// JavaScript Document
var __gba = 0;
if (typeof  ogx == 'undefined') {
	ogx = {};
}
ogx.URLParser = function(url){
	this._fields = {  
        'Username' : 4,   
        'Password' : 5,   
        'Port' : 7,   
        'Protocol' : 2,   
        'Host' : 6,   
        'Pathname' : 8,   
        'URL' : 0,   
        'Querystring' : 9,   
        'Fragment' : 10  
    };  

    this._values = {};  
    this._regex = null;  
    this.version = 0.1;  
    this._regex = /^((\w+):\/\/)?((\w+):?(\w+)?@)?([^\/\?:]+):?(\d+)?(\/?[^\?#]+)?\??([^#]+)?#?(\w*)/;  
    for(var f in this._fields) {  
        this['get' + f] = this._makeGetter(f);  
    }  

    if (typeof url != 'undefined')  
    {  
        this._parse(url);  
    }  
}

ogx.URLParser.prototype.setURL = function(url) {  
    this._parse(url);  
}  

ogx.URLParser.prototype._initValues = function() {  
    for(var f in this._fields)  
    {  
        this._values[f] = '';  
    }  
}  

ogx.URLParser.prototype._parse = function(url) {  
    this._initValues();  
    var r = this._regex.exec(url);  
    if (!r) throw "DPURLParser::_parse -> Invalid URL";  

    for(var f in this._fields) if (typeof r[this._fields[f]] != 'undefined')  
    {  
        this._values[f] = r[this._fields[f]];  
    }  
}  
ogx.URLParser.prototype._makeGetter = function(field) {  
    return function() {  
        return this._values[field];  
    }  
} 

$(document).ready(function(){
	var url = location.href;
	var p = new ogx.URLParser(url);
	var path = p.getPathname();
	var Qstring = url.substring(url.indexOf("?")+1,url.length);
	var sArr = (path.replace("/","").substr(0,path.replace("/","").lastIndexOf("."))).split("-") || '';
	var m = sArr[0] || '';
	var a = sArr[1] || '';
	
	$.ajax({
		url: '/ajax/',
		dataType: 'json',
		type: 'post',
		data: 'module=member&action=behaviorAnalyse&url='+escape(window.location)+'&p='+path.replace("/","")+'&q='+escape(Qstring)+'&m='+m+'&a='+a,
		success:function(data){
			__gba = data['data'];
		}
	});
});
$(window).unload(function(){
	if (__gba !== 0) {
		$.ajax({
			url: '/ajax/',
			type: 'post',
			dataType: 'json',
			data: 'module=member&action=dieBehaviorAnalyse&id='+__gba,
			success:function(){}
		});
	}
});