function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}






function getElementPosition(elemID) {
    var offsetTrail = document.getElementById(elemID);
    var offsetLeft = 0;
    var offsetTop = 0;
    while (offsetTrail) {
        offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;
        offsetTrail = offsetTrail.offsetParent;
    }
    if (navigator.userAgent.indexOf("Mac") != -1 && 
        typeof document.body.leftMargin != "undefined") {
        offsetLeft += document.body.leftMargin;
        offsetTop += document.body.topMargin;
    }
    offsetLeft -= f_scrollLeft();
    offsetTop -= f_scrollTop();
    return {left:offsetLeft, top:offsetTop};
}



function insertAfter(newElement,targetElement) {
  var parent = targetElement.parentNode;
  if (parent.lastChild == targetElement) {
    parent.appendChild(newElement);
  } else {
    parent.insertBefore(newElement,targetElement.nextSibling);
  }
}


function addLoadEvent(func){
	var oldonload = window.onload;
	if(typeof window.onload != 'function'){
		window.onload = func;
	} else {
		window.onload = function(){
			oldonload();
			func();
		}
	}	
}

addLoadEvent(prepareDeCheck);
addLoadEvent(prepareDeCheck2);

function prepareDeCheck(){	
	var inputs = document.getElementsByTagName('input');	
	for(i = 0; i < inputs.length; i++){		
		inp = inputs[i];
		if(inp.className == "cb_all"){
		
			inp.setAttribute('onClick', ' deCheck("'+inp.parentNode.parentNode.id+'") ');
			
			
		}
	}
}

function deCheck(ul_id){
	var ul = document.getElementById(ul_id);
	var cbs = ul.getElementsByTagName('input');
	//alert(ul_id);
	for(i = 0; i < cbs.length; i++){
		if(cbs[i].className != 'cb_all'){
			cbs[i].checked = false;	
		}
	}	
}

function prepareDeCheck2(){	
	var main = document.getElementById('main');
	var inputs = main.getElementsByTagName('input');	
	for(i = 0; i < inputs.length; i++){		
		inp = inputs[i];
		if(inp.className != "cb_all"){
		
			inp.setAttribute('onClick', ' deCheck2("'+inp.parentNode.parentNode.id+'") ');
			
			
		}
	}
}

function deCheck2(ul_id){
	var ul = document.getElementById(ul_id);
	var cbs = ul.getElementsByTagName('input');
	//alert(ul_id);
	for(i = 0; i < cbs.length; i++){
		if(cbs[i].className == 'cb_all'){
			cbs[i].checked = false;	
		}
	}	
}