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

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

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

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

// used in confirm when change status
//function statusConfirm(msg) {

//	if(!window.confirm(msg)) {

//	}
//}


// 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);

	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) {
	var div = document.getElementById(div);
	div.style.display = 'inline';
}

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

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

	var width = (width) ? width : 170;
	var div = document.getElementById(div);
	var html = '<div>';
	html += (title) ? '<b>' + title + '</b><br>' : '';
	html += desc + '</div>';

	div.style.display = 'inline';
	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';
}

// set focus to obj, use true for second argument to set select to obj
function SetFocus(obj) {
	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 RowHighlightByCheckBox(row_id, ch_id, normal_class, highlight_class) {

	var row = document.getElementById(row_id);
	var ch = document.getElementById(ch_id);

	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;
		}
	}
}

// POP UP
function InsertFromPopUp(field_name, field_id, choosed_name, choosed_id) {

	
	id_values = window.opener.document.getElementById(field_id).value; 
	name_values = window.opener.document.getElementById(field_name).value;
	if(id_values=='' || name_values=='')
	{
	    window.opener.document.getElementById(field_id).value =  choosed_id;
	    window.opener.document.getElementById(field_name).value =  choosed_name;
	}
	else
	{
	    window.opener.document.getElementById(field_id).value = id_values + ',' + choosed_id;
	    window.opener.document.getElementById(field_name).value = name_values + ',' + choosed_name;	
	    
	}    

	window.close();
}


function OpenPopup(page, field_name, field_id) {
	OpenWin(page+'&field_name='+field_name+'&field_id='+field_id+'&popup=1', 'popup', '700', '450', 'yes', false, true);
}


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



function setUsername(field) {
	f = document.getElementById(field);
	u = document.getElementById('username');

	//if(u.value == '') {
		u.value = f.value;
	//}
}


function setPasswordDisabled() {

	if(!document.getElementById('not_change_pass')) {
		return;
	}

	ch = document.getElementById('not_change_pass');
	p = document.getElementById('password');
	p2 = document.getElementById('password_2');

	if(ch.checked == true) {
		p.disabled = true;
		p2.disabled = true;
	} else {
		p.disabled = false;
		p2.disabled = false;
	}
}

// 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=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}

function checkAll() 
{
	var reverse = false;

	whichEl = document.getElementById('select_all');
	
	if (whichEl.checked == true) reverse = true;
	else reverse = false;
	
	whichEl = document.getElementById('items');
		
	var c = whichEl.length;
	for (i=0; i < c; i++) 
	if (whichEl.elements[i].type=='checkbox' && !whichEl.elements[i].disabled)
	{
			whichEl.elements[i].checked = reverse;
	}
}

function expandEl(el) 
{
	whichEl = document.getElementById(el);
	if (whichEl) {
		if ( whichEl.style.display != "") {
		  whichEl.style.display = "";
		}
		else {
		  whichEl.style.display = "none";
		}
	}
}
