// JavaScript Document
// Get base url
var Url = {
 
	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},
 
	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}





url = document.location.href;
xend = url.lastIndexOf("/") + 1;
var base_url = 'http://'+window.location.hostname+'/';

var ajax_get_error = false;

function ajax_do (url) {
	// Does URL begin with http?
	if (url.substring(0, 4) != 'http') {
		url = base_url + url;
	}
	
	//url = url.replace(/\%20/g,'+');
	//alert(url);
	// Create new JS element
	var jsel = document.createElement('SCRIPT');
	jsel.type = 'text/javascript';
	jsel.src = url;
//	alert(url);
	// Append JS element (therefore executing the 'AJAX' call)
	document.body.appendChild (jsel);

	
}
function check_reload()
	{
		if(ke_byID('reload_page'))
			if(ke_byID('reload_page').value==1)
				history.go(0);
			else{}
		else{
			setTimeout('check_reload()','100');
		}
	}	

function ajax_get (url, el, loading) {
		
	// Has element been passed as object or id-string?
	if (typeof(el) == 'string') {
		el = document.getElementById(el);
	}

	// Valid el?
	if (el == null) { return false; }

	// Does URL begin with http?
	if (url.substring(0, 4) != 'http') {
		url = base_url + url;
	}

	// Create getfile URL
	var scrol=getScrollXY();
	if (navigator.appName == "Microsoft Internet Explorer")
	{	
		var comm_left=screenSizeW/2-225 + 1*scrol[0];
		var comm_top=screenSizeH/2-250 + 1*scrol[1];
		
	}
	else{
		var comm_left=screenSizeW/2-225 + 1*scrol[0];
		var comm_top=screenSizeH/2-250 + 1*scrol[1];
	}
	
//	hideSelects('hidden');
/*	el.style.width='500px';
	el.style.height='600px';
	el.style.top=comm_top + 'px';
	el.style.left=comm_left + 'px';
	el.style.display='';
*/
	
	
	if(!loading)
	el.innerHTML='<img src="/ke_images/loading.gif" border="0" alt="loading...">';
/*	
	document.getElementById('transpbg').style.display='';
	document.getElementById('transpbg').style.width=(screenSizeW+1*scrol[0]) + 'px';
	
	document.getElementById('transpbg').style.height=(screenSizeH+1*scrol[1]) + 'px';
	*/
	getfile_url = base_url+'ajaxdo/getfile~000-0!el=' + escape(el.id) + '|url='+Url.encode(url);

	// Do Ajax
//	document.getElementById(el.id).innerHTML='asdsdsas';
//alert(getfile_url);
	ajax_do (getfile_url);
	check_reload();
	
	return true;
}


var screenSizeW,screenSizeH;
		
		alertSize();
		function alertSize() {
		  var myWidth = 0, myHeight = 0;
		  if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		  }
		//  window.alert( 'Width = ' + myWidth );
		 // window.alert( 'Height = ' + myHeight );
		  screenSizeW=myWidth;
		  screenSizeH=myHeight;
		}
		
		function getScrollXY() {
		  var scrOfX = 0, scrOfY = 0;
		  if( typeof( window.pageYOffset ) == 'number' ) {
			//Netscape compliant
			scrOfY = window.pageYOffset;
			scrOfX = window.pageXOffset;
		  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
			//DOM compliant
			scrOfY = document.body.scrollTop;
			scrOfX = document.body.scrollLeft;
		  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
			//IE6 standards compliant mode
			scrOfY = document.documentElement.scrollTop;
			scrOfX = document.documentElement.scrollLeft;
		  }
		  return [ scrOfX, scrOfY ];
		}

