//=====================================================
//	CMS Copyright
//	Copyright (c) 2008-2009 by CMS
//	ALL RIGHTS RESERVED
//=====================================================
// javascript document

var agt = navigator.userAgent.toLowerCase();
var OP = (agt.indexOf("opera") != -1) && window.opera;
var IE = (agt.indexOf("msie") != -1) && document.all && !OP;
//var IE8 = (agt.indexOf("msie 8.0") != -1) && document.all && !OP;
var IE8 = (agt.indexOf("ie8;") != -1) && document.all && !OP;
var IE7 = IE && !IE8 && document.all && !OP;
var IE6 = (agt.indexOf("msie 6.0") != -1) && document.all && !OP;
var CR = (agt.indexOf('chrome') != -1);
var SF = (agt.indexOf("safari") != -1);
var KQ = (agt.indexOf("khtml") != -1) && (!SF);
var GK = (agt.indexOf("gecko") != -1) && !KQ && !SF;
var MC = (agt.indexOf('mac') != -1)

function checkBrowser(){
 if(OP) alert('Opera');
 if(IE) alert('IE');
 if(IE7) alert('IE7');
 if(IE8) alert('IE8');
 if(CR) alert('Chrome');
 if(SF) alert('Safari');
 if(KQ) alert('Konqueror');
 if(MC) alert('Mac');
 if(GK) alert('FireFox');
return 0;
}

function empty(obj){
	if(is_null(obj)) return true;
	if(obj == false) return true;
	if((obj == 0) || (obj == '0')) return true;
	if(is_string(obj) && (obj == '')) return true;
	if(is_array(obj) && (obj.length == 0)) return true;
return false;
}

function is_null(obj){
	if(obj==null) return true;
return false;
}

function is_numeric(obj){
	return (typeof(obj) == 'number');
}

function is_string(obj){
	return (typeof(obj) == 'string');
}

function is_array(obj) {
	return obj != null && typeof obj == "object" &&
      'splice' in obj && 'join' in obj;	  
}

function SDI(msg){
	var div_help = document.getElementById('div_help');

	if((div_help == 'undefined') || empty(div_help)){
		var div_help = document.createElement('div');
		var doc_body = document.getElementsByTagName('body')[0];
		doc_body.appendChild(div_help);
		
		div_help.setAttribute('id','div_help');
		div_help.setAttribute('style','position: absolute; left: 10px; top: 100px; border: 1px red solid; width: 500px; height: 400px; background-color: white; overflow: auto; z-index: 20;');
		
//		new Draggable(div_help,{});
	}
	
	div_help.appendChild(document.createTextNode("DEBUG INFO: "));
	div_help.appendChild(document.createElement("br"));
	div_help.appendChild(document.createTextNode(msg));
	div_help.appendChild(document.createElement("br"));
	div_help.appendChild(document.createElement("br"));
}

/*
function SDI(msg){
	alert("DEBUG INFO: " + msg);
}
//*/

function SDJ(obj){
	var debug = '';
	for(var key in obj) {
		var value = obj[key];
		debug+=key+': '+value+'\n';
	}
	SDI('\n'+debug);
}

/// Alpha-Betic sorting

function addListener(element, eventname, expression, bubbling){
	bubbling = bubbling || false;

	element = $(element);
	if(window.addEventListener){
		element.addEventListener(eventname, expression, bubbling);
		return true;
	} 
	else if(window.attachEvent){
		element.attachEvent('on'+eventname, expression);
		return true;
	} 
	else return false;
}

function add_variable(o_el, s_name, x_value, s_formname, o_document){
	var form;
	
	if(!o_document)	o_document = document;
	
	if(s_formname){
		if( !(form = o_document.forms[s_formname]) )
			 throw "Missed form with name '"+s_formname+"'.";
	}
	else if(o_el){
		if( !(form = o_el.form) )
			throw "Missed form in 'o_el' object";
	}
	else{
		if( !(form = this.form) )
			throw "Missed form in 'this' object";
	}
	
	var o_variable = o_document.createElement('input');
	
	if( !o_variable )	throw "Can't create element";
	
	o_variable.type = 'hidden';
	o_variable.name = s_name;
	o_variable.id = s_name;
	o_variable.value = x_value;

	form.appendChild(o_variable);
	
return true;
}

function cancelEvent(e){
	if (!e) var e = window.event;	
//SDI(e);
	if(e){
		if(IE){
			e.cancelBubble = true;
			e.returnValue = false;
		}
		else{
			e.stopPropagation();
			e.preventDefault();
		}
	}
return false;
}

function close_window(){
	
	window.setTimeout("window.close()", 500); /* Solve bug for Internet Explorer */
	return false;
}

function create_var(form_name, var_name, var_val, subm){
	var frmForm = (is_string(form_name))?document.forms[form_name]:form_name;
	if(!frmForm) return false;

	var objVar = (typeof(frmForm[var_name]) != 'undefined')?frmForm[var_name]:null;
//	objVar=(objVar.length>0)?objVar[0]:null;

	if(is_null(objVar)){
		objVar = document.createElement('input');
		objVar.setAttribute('type', 	'hidden');
		
		if(!objVar) return false;

		frmForm.appendChild(objVar);
		
		objVar.setAttribute('name', 	var_name);
		objVar.setAttribute('id', 		var_name);
	}

	objVar.value = var_val;
	
	if(subm)
		frmForm.submit();

return false;
}


function deselectAll(){
	if(IE){
		document.selection.empty();
	}
	else if(!KQ){	
		var sel = window.getSelection();
		sel.removeAllRanges();
	}
}

function eventTarget(e){
	var targ = false;
	
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	
// defeat Safari bug
	if (targ.nodeType == 3) targ = targ.parentNode;
	
return targ;
}

function getPosition(obj){
	obj = $(obj);
	var pos = {top: 0, left: 0};
	if(!is_null(obj) && (typeof(obj.offsetParent) != 'undefined')){
		pos.left = obj.offsetLeft;
		pos.top = obj.offsetTop;
		try{
			while(!is_null(obj.offsetParent)){
				obj=obj.offsetParent;
				pos.left += obj.offsetLeft;
				pos.top += obj.offsetTop;
				
				if(IE && (obj.offsetParent.toString() == 'unknown')){
//					alert(obj.offsetParent.toString());
					break;
				}
			}
		} catch(e){
		}
	}
return pos;
}

function getSelectedText(obj){
	if(IE){
		obj.focus();
		return document.selection.createRange().text;
	}
	else if(obj.selectionStart){
		if(obj.selectionStart != obj.selectionEnd) {
			var s = obj.selectionStart;
			var e = obj.selectionEnd;
			return obj.value.substring(s, e);
		}
	}
	return obj.value;
}


function get_cursor_position(e){
	e = e || window.event;
	var cursor = {x:0, y:0};
	if(e.pageX || e.pageY){
		cursor.x = e.pageX;
		cursor.y = e.pageY;
	} 
	else {
		var de = document.documentElement;
		var b = document.body;
		cursor.x = e.clientX + (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
		cursor.y = e.clientY + (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
	}
	return cursor;
}

function get_scroll_pos(){
	var scrOfX = 0, scrOfY = 0;
//Netscape compliant
	if( typeof( window.pageYOffset ) == 'number' ){
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	}
//DOM compliant
	else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ){
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	}
//IE6 standards compliant mode
	else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ){
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [ scrOfX, scrOfY ];
}


function openWinCentered(loc, winname, iwidth, iheight, params){

		tp=Math.ceil((screen.height-iheight)/2);
		lf=Math.ceil((screen.width-iwidth)/2);
		if (params.length > 0){
			params = ', ' + params;
		}

	var WinObjReferer = window.open(loc,winname,"width="+iwidth+",height="+iheight+",top="+tp+",left="+lf+params);
	WinObjReferer.focus();
}

function PopUp(url,width,height,form_name){
	if(!width) width = 600;
	if(!height) height = 450;
	if(!form_name) form_name = 'zbx_popup';

	var left = (screen.width-(width+150))/2; 
	var top = (screen.height-(height+150))/2;
	
	var popup = window.open(url,form_name,'width=' + width +',height=' + height + ',top='+ top +',left='+ left +
			',resizable=yes,scrollbars=yes,location=no,menubar=no');

	popup.focus();
	
	return false;
}

function redirect(loc) {
	window.location = loc;
}

function removeListener(element, eventname, expression, bubbling){
	bubbling = bubbling || false;
	
	if(window.removeEventListener){
		element.removeEventListener(eventname, expression, bubbling);
		return true;
	} 
	else if(window.detachEvent){
		element.detachEvent('on'+eventname, expression);
		return true;
	} 
	else return false;
}


function showHide(obj,style){
	if(typeof(style) == 'undefined') var style = 'inline';
	
	obj = $(obj);
	if(!obj){
		throw 'showHide(): Object not found.';
		return false;
	}

	if(obj.style.display != 'none'){
		obj.style.display = 'none';
		return 0;
	}
	else{
		obj.style.display = style;
		return 1;
	}
}

function switchElementsClass(obj,class1,class2){
	obj = $(obj);
	if(!obj) return false;

	if(obj.className == class1){
		obj.className = class2;
		return class2;
	}
	else{
		obj.className = class1;
		return class1;
	}
return false;
}


/************************************************************************************/
/*						Automatic checkbox range selection 							*/
/************************************************************************************/
// Author: Aly

var chkbx_range_ext = {
startbox: 			null,			// start checkbox obj
startbox_name: 		null,			// start checkbox name
chkboxes:			new Array(),	// ckbx list

init: function(){
	var chk_bx = document.getElementsByTagName('input');
	for(var i=0; i < chk_bx.length; i++){
		if((typeof(chk_bx[i]) != 'undefined') && (chk_bx[i].type.toLowerCase() == 'checkbox')){
			this.implement(chk_bx[i]);
		}
	}
},

implement: function(obj){
	var obj_name = obj.name.split('[')[0];

	if(typeof(this.chkboxes[obj_name]) == 'undefined') this.chkboxes[obj_name] = new Array();
	this.chkboxes[obj_name].push(obj);

	addListener(obj, 'click', this.check.bindAsEventListener(this), false);
},

check: function(e){
	var e = e || window.event;
	if(!e.ctrlKey) return true;
	var obj = eventTarget(e);

	if((typeof(obj) != 'undefined') && (obj.type.toLowerCase() == 'checkbox')){
		var obj_name = obj.name.split('[')[0];

		if(!is_null(this.startbox) && (this.startbox_name == obj_name) && (obj.name != this.startbox.name)){
			var chkbx_list = this.chkboxes[obj_name];
			var flag = false;
			
			for(var i=0; i < chkbx_list.length; i++){
				if(typeof(chkbx_list[i]) !='undefined'){
//alert(obj.name+' == '+chkbx_list[i].name);
					if(flag){
						chkbx_list[i].checked = this.startbox.checked;
					}
					
					if(obj.name == chkbx_list[i].name) break;
					if(this.startbox.name == chkbx_list[i].name) flag = true;
				}
			}
			if(flag){
				this.startbox = null;
				this.startbox_name = null;
				return true;
			}
			else{
				for(var i=chkbx_list.length-1; i >= 0; i--){
					if(typeof(chkbx_list[i]) !='undefined'){
//alert(obj.name+' == '+chkbx_list[i].name);			
						if(flag){
							chkbx_list[i].checked = this.startbox.checked;
						}
						
						if(obj.name == chkbx_list[i].name){
							this.startbox = null;
							this.startbox_name = null;
							return true;
						}
						if(this.startbox.name == chkbx_list[i].name) flag = true;
					}
				}	
			}

		}
		else{
			if(!is_null(this.startbox)) this.startbox.checked = !this.startbox.checked;
			
			this.startbox = obj;
			this.startbox_name = obj_name;
		}
	}
}
}
$j(document).ready( function(){
			var wwin = $j(window).width();
			$j('.bgBLeft').width(wwin);
			$j('.bgBRight').width(wwin);
			$j('.bgTLeft').width(wwin);
			$j('.bgTRight').width(wwin);
			$j('body').width(wwin);			
				
			});		
