var ajax = {
	version : 'maxtv/ajax/1.1.0.0',
	developper : 'MaxTV Labs',
	copyright : 'MaxTV Technologies',
	timeout : 10000,
	domain : '127.0.0.1',
	uid : function(){var tempuid = new Date().getTime().toString(); return tempuid;},
	createObject : function(){
		var object = null;
		if(window.XMLHttpRequest){
			object = new XMLHttpRequest();
		}else if(window.ActiveXObject){
			var msobj = new Array("Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.4.0", "Msxml2.XMLHTTP.3.0", "Msxml2.XMLHTTP", "Microsoft.XMLHTTP");
			for(x=0; x<msobj.length; x++){
				try {
					object = new ActiveXObject(msobj[x]);
				}catch(e){};
			}
		}
		return object;
	},
	url : {
		format : function(url){
			if (url){
				if (url.indexOf('?')>0){
					url = url.replace('?', '?uid=' + ajax.uid() + '&');
				}else{
					url += '?uid=' + ajax.uid();
				}
			}
			return url;
		}
	},
	get : function(url){
		url = ajax.url.format(url);
		if (url){
			var object = ajax.createObject();
			object.open('GET', url, false);
			object.send(null);
			return object.responseText;
		}else{
			return '';
		}
	},
	post : function(url, data){
		url = ajax.url.format(url);
		if (url){
			var object = ajax.createObject();
			object.open('POST',url,false);
			object.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			object.send(data);
			return object.responseText;
		}else{
			return '';
		}
	},
	update : function(url){
		url = ajax.url.format(url);
		if (url){
			var object = ajax.createObject();
			object.open('GET', url, true);
			object.send(null);
		}
	},
	updatepost : function(url,data){
		url = ajax.url.format(url);
		if (url){
			var object = ajax.createObject();
			object.open('POST', url, true);
			object.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			object.send(data);
		}
	},
	load : function(url,frame){
		url = ajax.url.format(url);
		if (url){
			var object = ajax.createObject();
			object.onreadystatechange = function(){ajax.loaded(object,frame, url);};
			object.open("GET", url, true);
			object.send(null);
		}
	},
	loadpost : function(url,data,frame){
		url = ajax.url.format(url);
		if (url){
			var object = ajax.createObject();
			object.onreadystatechange = function(){ajax.loaded(object,frame, url);};
			object.open('POST',url,true);
			object.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			object.send(data);
		}
	},
	loaded : function(object, frame, url){
		ajax_result(object, frame, url);
	}
}

var xml = {
	parse : function(xmldata){
		var object, parser;
		if (window.DOMParser){
			parser = new DOMParser();
			object = parser.parseFromString(xmldata, "text/xml");
		}else{
			object = new ActiveXObject("Microsoft.XMLDOM");
			object.async = 'false';
			object.loadXML(xmldata); 
		}
		return object;
	},
	value : function(xmldata, variable, index){
		var result = '';
		if (index >= 0){
			if (xmldata){
				if (xmldata.getElementsByTagName(variable)){
					if (xmldata.getElementsByTagName(variable)[index]){
						if (xmldata.getElementsByTagName(variable)[index].childNodes[0]){
							result = xmldata.getElementsByTagName(variable)[index].childNodes[0].nodeValue;
						}
					}
				}
			}
		}
		return result;
	},
	node : function(xmldata, variable, index){
		var result = '<?xml version="1.0" encoding="UTF-8"?><tmp><' + variable + '>';
		if (xmldata && xmldata.getElementsByTagName(variable) && xmldata.getElementsByTagName(variable)[index]){
			//for (var i = 0; i <= xmldata.getElementsByTagName(variable).length; i++){
			for (var i = 0; i <= 199; i++){
				try{
					if (xmldata.getElementsByTagName(variable)[index].childNodes[i]){
						if (xmldata.getElementsByTagName(variable)[index].childNodes[i].nodeName.indexOf('#text') < 0){
							result += '<' + xmldata.getElementsByTagName(variable)[index].childNodes[i].nodeName + '>' + xmldata.getElementsByTagName(variable)[index].childNodes[i].textContent + '</' + xmldata.getElementsByTagName(variable)[index].childNodes[i].nodeName + '>';
						}
					}
				}catch(e){
				
				}
			}
		}
		result += '</' + variable + '></tmp>';
		return result;
	},
	count : function(xmldata, variable){
		try{
			return xmldata.getElementsByTagName(variable).length;
		}catch(e){
			return 0;
		}
	}
}

var xml_node = function(){
	this.cache_namespace = new Array();
	this.cache_data = new Array();
	this.cache_expires = new Array();
	this.cache_index = 0-1;
	this.index = 0;
	this.data = function(){
		return this.cache_data[this.cache_index];
	}
	this.update = function(){
		this.load(this.cache_namespace[this.cache_index]);
	}
	this.namespace = function(){
		return this.cache_namespace[this.cache_index];
	}
	this.load = function(namespace){
		var cached = 0-1;
		for (var i=0; i <= this.cache_namespace.length - 1; i++){
			if ((this.cache_namespace[i] == namespace) && (parseInt(this.cache_expires[i]) > parseInt(DateTime.NowHMS()))){
				cached = i;
			}
		}
		if (cached == 0-1){
			var data = xml.parse(ajax.get(namespace));
			var expires = xml.value(data, 'expires', 0);
			this.cache_namespace.push(namespace);
			this.cache_data.push(data);
			if (expires != ''){
				this.cache_expires.push(expires);
			}else{
				this.cache_expires.push('000000000000');
			}
			this.cache_index = this.cache_namespace.length - 1;
		}else{
			this.cache_index = cached;
		}
	}
	this.parse = function(xmldata){
		this.cache_namespace.push('simple_node');
		this.cache_data.push(xml.parse(xmldata));
		this.cache_expires.push('999999999999');
		this.cache_index = this.cache_namespace.length - 1;
	}
	this.loadxml = function(xmldata){
		this.cache_namespace.push('simple_node');
		this.cache_data.push(xml.parse(xmldata));
		this.cache_expires.push('000000000000');
		this.cache_index = this.cache_namespace.length - 1;
	}
	this.count = function(variable){
		return xml.count(this.data(), variable);
	}
	this.value =  function(variable){
		return xml.value(this.data(), variable, this.index);
	}
	this.valueAt =  function(variable, index){
		return xml.value(this.data(), variable, index);
	}
	this.node =  function(variable){
		return xml.node(this.data(), variable, this.index);
	}
	this.nodeAt =  function(variable, index){
		return xml.node(this.data(), variable, index);
	}
}	
	
var DateTime = {
	current : '',
	loop : '',
	second : 950,
	set : function(timecode){
		this.loop = '';
		this.current = new Date();
		this.current.setFullYear(parseInt(timecode.substring(0,4)));
		this.current.setMonth(parseInt(timecode.substring(4,6)) - 1);
		this.current.setDate(timecode.substring(6,8));
		this.current.setHours(parseInt(timecode.substring(8,10)));
		this.current.setMinutes(parseInt(timecode.substring(10,12)));
		this.current.setSeconds(parseInt(timecode.substring(12,14)));
		this.loop = setTimeout('DateTime.autoset()', 975);
	},
	autoset:function(){
		if (this.current != ''){
			var secondes = this.current.getSeconds();
			var minutes = this.current.getMinutes();
			var hours = this.current.getHours();
			var day = this.current.getDate();
			var month = this.current.getMonth() + 1;
			var year = this.current.getFullYear();
			secondes++;
			if (parseInt(secondes) > 59){
				minutes++;
				secondes = 0;
			}
			if (parseInt(minutes) > 59){
				hours++;
				minutes = 0;
			}
			if (parseInt(hours) > 23){
				day++;
				hours = 0;
			}
			if (parseInt(day) > 30){
				month++;
				day = 1;
			}
			if (parseInt(month) > 12){
				year++;
				month = 1;
			}
			this.current.setFullYear(parseInt(year));
			this.current.setMonth(parseInt(month) - 1);
			this.current.setDate(day);
			this.current.setHours(parseInt(hours));
			this.current.setMinutes(parseInt(minutes));
			this.current.setSeconds(parseInt(secondes));
			this.loop = setTimeout('DateTime.autoset()', 975);
		}
	},
	format : function(data){
		var result = '' + data;
		if (parseInt(data) < 10){
			result = '0' + result;
		}
		if (result.length < 2){
			result = '0' + result;
		}
		return result;
	},
	Now : function(){
		var d = new Date();
		var result = DateTime.format(d.getFullYear()) + "" + DateTime.format(d.getMonth() + 1) + "" + DateTime.format(d.getDate()) + "" + DateTime.format(d.getHours()) + "" + DateTime.format(d.getMinutes());
		if (this.current != ''){
			result = DateTime.format(this.current.getFullYear()) + "" + DateTime.format(this.current.getMonth() + 1) + "" + DateTime.format(this.current.getDate()) + "" + DateTime.format(this.current.getHours()) + "" + DateTime.format(this.current.getMinutes());
		}
		return result;
	},
	NowHMS : function(){
		var d = new Date();
		var result = DateTime.format(d.getFullYear()) + "" + DateTime.format(d.getMonth() + 1) + "" + DateTime.format(d.getDate()) + "" + DateTime.format(d.getHours()) + "" + DateTime.format(d.getMinutes()) + "" +  + DateTime.format(d.getSeconds());
		if (this.current != ''){
			result = DateTime.format(this.current.getFullYear()) + "" + DateTime.format(this.current.getMonth() + 1) + "" + DateTime.format(this.current.getDate()) + "" + DateTime.format(this.current.getHours()) + "" + DateTime.format(this.current.getMinutes() + "" + DateTime.format(this.current.getSeconds()));
		}
		return result;
	},
	Date : function(){
		var d = new Date();
		var result = DateTime.format(d.getDate()) + "/" + DateTime.format(d.getMonth() + 1) + "/" + DateTime.format(d.getFullYear()) + " " + DateTime.format(d.getHours()) + ":" + DateTime.format(d.getMinutes()) + ":" + DateTime.format(d.getSeconds());
		if (this.current != ''){
			result = DateTime.format(this.current.getDate()) + "/" + DateTime.format(this.current.getMonth() + 1) + "/" + DateTime.format(this.current.getFullYear()) + " " + DateTime.format(this.current.getHours()) + ":" + DateTime.format(this.current.getMinutes()) + ":" + DateTime.format(this.current.getSeconds());
		}
		return result;
	}
}

function ctrl(name){
	return document.getElementById(name);
}

function dl(url){
	document.getElementById('dl').src = url;
}

function base64_encode( data ) {      
    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1;
    var o2;
    var o3;
    var h1;
    var h2;
    var h3;
    var h4;
    var bits;
    var i = 0;
    var ac = 0;
    var enc="";
    var tmp_arr = [];
    data = utf8_encode(data);
    
    do { // pack three octets into four hexets
        o1 = data.charCodeAt(i++);
        o2 = data.charCodeAt(i++);
        o3 = data.charCodeAt(i++);
 
        bits = o1<<16 | o2<<8 | o3;
 
        h1 = bits>>18 & 0x3f;
        h2 = bits>>12 & 0x3f;
        h3 = bits>>6 & 0x3f;
        h4 = bits & 0x3f;
 
        // use hexets to index into b64, and append result to encoded string
        tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
    } while (i < data.length);
    
    enc = tmp_arr.join('');
    
    switch( data.length % 3 ){
        case 1:
            enc = enc.slice(0, -2) + '==';
        break;
        case 2:
            enc = enc.slice(0, -1) + '=';
        break;
    }
 
    return enc;
}

function utf8_encode ( string ) {
    string = string.replace(/\r\n/g,"\n");
    var utftext = "";
    var start, end;
 
    start = end = 0;
    for (var n = 0; n < string.length; n++) {
        var c = string.charCodeAt(n);
        var enc = null;
 
        if (c < 128) {
            end++;
        } else if((c > 127) && (c < 2048)) {
            enc = String.fromCharCode((c >> 6) | 192) + String.fromCharCode((c & 63) | 128);
        } else {
            enc = String.fromCharCode((c >> 12) | 224) + String.fromCharCode(((c >> 6) & 63) | 128) + String.fromCharCode((c & 63) | 128);
        }
        if (enc != null) {
            if (end > start) {
                utftext += string.substring(start, end);
            }
            utftext += enc;
            start = end = n+1;
        }
    }
    
    if (end > start) {
        utftext += string.substring(start, string.length);
    }
 
    return utftext;
}

function base64_decode( data ) {
    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1;
    var o2;
    var o3;
    var h1;
    var h2;
    var h3;
    var h4;
    var bits;
    var i = 0;
	var ac = 0;
    var dec = "";
    var tmp_arr = [];
 
    data += '';
 
    do {  // unpack four hexets into three octets using index points in b64
        h1 = b64.indexOf(data.charAt(i++));
        h2 = b64.indexOf(data.charAt(i++));
        h3 = b64.indexOf(data.charAt(i++));
        h4 = b64.indexOf(data.charAt(i++));
 
        bits = h1<<18 | h2<<12 | h3<<6 | h4;
 
        o1 = bits>>16 & 0xff;
        o2 = bits>>8 & 0xff;
        o3 = bits & 0xff;
 
        if (h3 == 64) {
            tmp_arr[ac++] = String.fromCharCode(o1);
        } else if (h4 == 64) {
            tmp_arr[ac++] = String.fromCharCode(o1, o2);
        } else {
            tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
        }
    } while (i < data.length);
 
    dec = tmp_arr.join('');
    dec = utf8_decode(dec);
 
    return dec;
}

function utf8_decode ( str_data ) {
    var tmp_arr = [];
    var i = 0;
    var ac = 0;
	var c1 = 0;
	var c2 = 0;
	var c3 = 0;
 
    str_data += '';
 
    while ( i < str_data.length ) {
        c1 = str_data.charCodeAt(i);
        if (c1 < 128) {
            tmp_arr[ac++] = String.fromCharCode(c1);
            i++;
        } else if ((c1 > 191) && (c1 < 224)) {
            c2 = str_data.charCodeAt(i+1);
            tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
            i += 2;
        } else {
            c2 = str_data.charCodeAt(i+1);
            c3 = str_data.charCodeAt(i+2);
            tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
            i += 3;
        }
    }
 
    return tmp_arr.join('');
}



function getPlayer(name){
	if (window.document[name]){return window.document[name];}
	if (navigator.appName.indexOf('Microsoft Internet')==-1){
		if (document.embeds && document.embeds[name]){
			return document.embeds[name];
		}else{
			return document.getElementById(name);
		}
	}
	return 'null';
}

function getElementHeight(Elem) {if(document.getElementById) {var elem = document.getElementById(Elem);} else if (document.all){var elem = document.all[Elem];}xPos = elem.offsetHeight;return xPos;}
function getElementWidth(Elem) {if(document.getElementById) {var elem = document.getElementById(Elem);} else if (document.all){	var elem = document.all[Elem];}xPos = elem.offsetWidth;	return xPos;}
function RedirectTo(PageURL){document.location.href = PageURL;}
String.prototype.replaceAll = function(pcFrom, pcTo){var i = this.indexOf(pcFrom);var c = this;while (i > -1){c = c.replace(pcFrom, pcTo);i = c.indexOf(pcFrom);}return c;}

var query_parser = function(){
	this.qsParm = new Array();
	this.initialize = function(namespace){
		var query = namespace.substring(namespace.indexOf('?') + 1);
		var parms = query.split('&');
		for (var i=0; i<parms.length; i++) {
			var pos = parms[i].indexOf('=');
			if (pos > 0) {
				var key = parms[i].substring(0,pos);
				var val = parms[i].substring(pos+1);
				this.qsParm[key] = val;
			}
		}
	}
	this.value = function(variable){
		var result = '' + this.qsParm[variable];
		if (result == 'undefined'){
			result = '';
		}
		return result;
	}
}