// JavaScript Document
// this requires jquery to be included.
function jui() {

		
}

jui.showLoading = function() {
	var elements = document.body.getElementsByTagName('*');
	var newSpan = document.createElement('span');
	newSpan.style.position = 'fixed';
	newSpan.style.backgroundColor = '#F00';
	newSpan.style.color = '#FFF';
	newSpan.style.right = '0px';
	newSpan.style.top = '0';
	newSpan.style.padding = '5px';
	newSpan.innerHTML = 'Please wait...';
	newSpan.setAttribute('id', 'ajaxLoadingBox');
	document.body.insertBefore(newSpan, elements[0]);
}

jui.removeLoading = function() {
	if(document.getElementById('ajaxLoadingBox')) {
		document.body.removeChild(document.getElementById('ajaxLoadingBox'));
	}
}

jui.showResult = function(text, debug) {
	if(debug != true) {
		debug == false;	
	}
	if(text != '') {
		var elements = document.body.getElementsByTagName('*');
		var newSpan = document.createElement('span');
		newSpan.style.position = 'fixed';
		newSpan.style.backgroundColor = '#009933';
		newSpan.style.color = '#FFF';
		newSpan.style.right = '40%';
		newSpan.style.top = '0';
		newSpan.style.padding = '5px';
		newSpan.innerHTML = text;
		newSpan.setAttribute('id', 'ajaxResultBox');
		document.body.insertBefore(newSpan, elements[0]);
		if(!debug) {
			setTimeout('jui.removeResult()', 1500);
		}
	}
}

jui.removeResult = function() {
	if(document.getElementById('ajaxResultBox')) {
		document.body.removeChild(document.getElementById('ajaxResultBox'));
	}
}

jui.cover = function() {
	var elements = document.body.getElementsByTagName('*');
	var newDiv = document.createElement('div');
	newDiv.style.width = '100%';
	newDiv.style.height = '100%';
	newDiv.style.border = '1px solid #000';
	newDiv.style.position = 'fixed';
	newDiv.style.backgroundColor = '#000';
	newDiv.style.top = '0';
	newDiv.style.left = '0'
	newDiv.style.opacity = '0.4';
	newDiv.style.filter = 'alpha(opacity=40)';
	newDiv.setAttribute('id', 'pageCover');
	document.body.insertBefore(newDiv, elements[0]);
}

jui.uncover = function() {
	if(document.getElementById('pageCover')) {
		document.body.removeChild(document.getElementById('pageCover'));
	}
}

jui.slideUp = function(obj, callBack) {
	if(typeof(obj) == 'object') {
		if(obj.style)  {
			var flag = false;
			if(obj.id == '') {
				var id = Math.random();
				id = id.toString();
				id = id.replace(/\./i, 'fx');
				obj.setAttribute('id', id);
				flag = true;
			}
			
			
			if($('#'+id))  {
				$('#'+id).slideUp('normal', callBack);
			}
			if(flag) {
				obj.removeAttribute('id', 2);	
			}
		}
	} else if(typeof(obj) == 'string') {
		$('#'+obj).slideUp();
	}
}

jui.remove = function(obj) {
	if(typeof(obj) == 'object') {
		if(obj.id == '') {
			var id = Math.random();
			id = id.toString();
			id = id.replace(/\./i, 'fx');
			obj.setAttribute('id', id);
			flag = true;
		}
		
		if(obj.style)  {
			$('#'+id).remove();
		}
		
		if(flag) {
			obj.removeAttribute('id', 2);	
		}
	} else if(typeof(obj) == 'string') {
		if($('#'+obj)) {
			$('#'+obj).remove();
		}
	}
}

jui.show = function(element) {
	if(document.getElementById(element)) {
		document.getElementById(element).style.display = 'block';
	}
}

jui.hide = function(element) {
	if(document.getElementById(element)) {
		document.getElementById(element).style.display = 'none';
	}
}

jui.center = function(size) {
	if(size == '' || size == null) {
		alert('Please provide a width value of the popup element to get the center position');
		return false;
	}
	var win_size = get_window_size();
	var win_width = win_size['width'];
	var max_val = Math.max(win_width, size);
	var min_val = Math.min(win_width, size);
	var diff = max_val - min_val;
	var final = Math.round(diff/2);
	return final+'px';
}

jui.windowSize = function() {
  var myWidth = 0, myHeight = 0;
  var size = new Array();
  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 );
*/  
	size['width'] = myWidth;
  	size['height'] = myHeight;
 	return size;
}


