function CheckFrames(page) {
	if (parent.frames.length == 0) {
		window.location.href = page;
	}
}

function OverColor(obj, new_class, highlight_class, more_id) { 
	if(obj.className != highlight_class) {
		obj.className = new_class;
		if(more_id) {
			document.getElementById(more_id).className = new_class;
		}
	}
}

function Highlight(obj, def_class, new_class, more_id) { 
	if(obj.className == def_class) { obj.className=new_class; }
	else                           { obj.className=def_class; }
	if(more_id) {
		document.getElementById(more_id).className = obj.className;
	}
}

function RowHighlightByCheckBox(row_id, ch_id, normal_class, highlight_class, row) { 
	
	var row = document.getElementById(row_id);
	var ch = document.getElementById(ch_id);
	
	if(row && ch) {
		if(ch.checked == true) { ch.checked = false; }
		else                   { ch.checked = true; }
	}

	if(row && ch) {
		if(ch.checked == true) { row.className = highlight_class; } 
		else                   { row.className = normal_class; }
	}
}


function RowHighlightOneOnly(id, normal_class, highlight_class) { 
	var rows = document.getElementsByTagName('tr');
	
	for(i=0;i<rows.length;i++){
		if(rows[i].id && rows[i].id == id) {
			rows[i].className = highlight_class;
		} else {
			if(rows[i].className != highlight_class) { continue; }
			rows[i].className = normal_class;
		}
	}
}

// redirect to path // using for tr and onDblClick
function RecordToDo(path) {
	document.location.href = path;
}

function OverColorSimple(obj, old_class, new_class) { 
	obj.className = new_class;
}

function Validate() {
	return true;
}

// centered popup
function OpenWin(URL, winName, width, height, scroll, menubar, status) {

	var winLeft = (screen.width - width) / 2;
	var winTop = (screen.height - height) / 5;
	
	winData =  'height='+height+',width='+width+',top='+winTop+',left='+winLeft+',';
	winData += 'scrollbars='+scroll+',menubar'+menubar+',status='+status+'';
	//winData += 'alwaysRaised=1';
	win = window.open(URL, winName, winData);
	
	//alert(screen.width);
	//alert(winData);
	
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

// we use it when patient pop up, to empty field
function doEmpty() {
	var field;
	for(i=0;i<arguments.length;i++){
		field = document.getElementById(arguments[i]);
		field.value = '';
	}
}

function ShowDiv(div, display_block) {
	var div = document.getElementById(div);
	div.style.display = (display_block) ? 'block' : 'inline';
}

function HideDiv(div) {
	var div = document.getElementById(div);
	div.style.display = 'none';
}

function ShowHideDiv(div, display, display_block) {
	if(display) { ShowDiv(div, display_block); } 
	else        { HideDiv(div); } 
}

function ShowHelp(div, title, desc, width, display_block, margin) {

	var width = (width) ? width : '';
	var div = document.getElementById(div);
	var html = '<div>';
	html += (title) ? '<b>' + title + '</b><br>' : '';
	html += desc;
	html += '</div>';
	
	div.style.display = (display_block) ? 'block' : 'inline';
	div.style.margin = (margin) ? margin : '5px 0px 0px 10px';
	//div.style.fontWeight = 'normal';
	
	div.style.position = 'absolute';
	div.style.width = width;
	div.style.backgroundColor = 'lightyellow';
	div.style.border = 'solid 1px black';
	div.style.padding = '3px';
	div.style.color = '#000000';
	div.innerHTML = html;
}

function HideHelp(div) {
	document.getElementById(div).style.display = 'none';
}

// in articles, news, if entry not published, no link to public area
function confirmNotPublishedEntry(msg, link) {
	if(confirm(msg)) {
		document.location.href = link;
	}
}

// set focus to obj, use true for second argument to set select to obj
function SetFocus(id) {
	var obj = document.getElementById(id);
	obj.focus();
	if(arguments[1]) { obj.select(); }
}

// show prompt to insert new value
function addOption(sel,oprompt) {
	
	var sel = document.getElementById(sel);	
	
	var other= sel.options[sel.selectedIndex];
	var newval= window.prompt(oprompt,'');
	if(!newval) { return; }
	sel.options[sel.options.length]= new Option(other.text,other.value,false,false);
	other.text = newval;
	other.value = 'new_'+newval;
}


function parseGetVars() {
    var getVars = location.search.substring(1).split("&");
    var returnVars = new Array();
    
    for(i=0; i < getVars.length; i++) {
        var newVar = getVars[i].split("=");
        returnVars[unescape(newVar[0])] = unescape(newVar[1]);
    }
    
    return returnVars;
}


function selectAll(action, id, values) {
	
	var obj = document.getElementById(id);
	
	if(values != null) {
		var values = values.split(',');
		var apos_action = (action) ? false : true;
		
		selectAll(apos_action, id);
		
		for (i=0; i<values.length; i++) {
			for (j=0; j<obj.options.length; j++) {
				if(values[i] == obj.options[j].value) {
					obj.options[j].selected = action;
					break;
				}
			}
		}
		
	} else {
		for (i=0; i<obj.options.length; i++) {
			obj.options[i].selected = action;
		}	
	}
}

function confirmFormActionLink(link, msg) {
	if(confirm(msg)) {
		location.href=link;
	}
}

// another cookie
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

// assig more than one handker on page
function addHandler(object, event, handler)
{
  if (typeof object.addEventListener != 'undefined')
    object.addEventListener(event, handler, false);
  else if (typeof object.attachEvent != 'undefined')
    object.attachEvent('on' + event, handler);
  else
    throw "Incompatible browser";
}

function removeHandler(object, event, handler)
{
  if (typeof object.removeEventListener != 'undefined')
    object.removeEventListener(event, handler, false);
  else if (typeof object.detachEvent != 'undefined')
    object.detachEvent('on' + event, handler);
  else
    throw "Incompatible browser";
}


//Univesal onload
function setGlobalOnLoad(f) {
   var root = window.addEventListener || window.attachEvent ? window : document.addEventListener ? document : null
   if (root){
      if(root.addEventListener) root.addEventListener("load", f, false)
      else if(root.attachEvent) root.attachEvent("onload", f)
   } else {
      if(typeof window.onload == 'function') {
         var existing = window.onload
         window.onload = function() {
            existing()
            f()
         }
      } else {
         window.onload = f
      }
   }
}



function checkboxToRadioBehavior(val, options) {
	var clicked = document.getElementById(val);
	if(clicked.checked == true) {
		for (var i=0;i<arguments.length;i++) {
			if(i == 0) { continue; }
			if(clicked.id == arguments[i]) { continue; }
			
			var ch = document.getElementById(arguments[i]);
			ch.checked = false;
		}		
	}
}