<!--
var errBG = '#fa9900', errTX = '#000000';
var nrmBG = '#ffffff', nrmTX = '#606060';
var errMsgTX = '#f06000'; //'#ff8000';
var blockLinks = false;

var submitted = false;

////////////////////////////////////////////////////////////////////////////////////
function FullLogin(uid, pwd, msg)
{
	var u = GetObject(uid);
	var p = GetObject(pwd);
	var m = GetObject(msg);
	var res = '';
	
	if(u == null || p == null || u == 'undefined' || p == 'undefined') return true;

	// user name	
	if(u.value == '')
	{
		u.style.backgroundColor = errBG;
		u.style.color = errTX;
		res = 'Missing values:';
	}
	else 
	{ 
		u.style.backgroundColor = nrmBG; 
		u.style.color = nrmTX;
	}
	
	// password
	if(p.value == '')
	{
		p.style.backgroundColor = errBG;
		p.style.color = errTX;
		res = 'Missing values:';
	}
	else 
	{ 
		p.style.backgroundColor = nrmBG; 
		p.style.color = nrmTX;
	}

	// output results:
	if(res != '')
	{
		if(m == null || m == 'undefined')	
		{
			alert(res);
		}
		else			
		{
			m.style.color = errMsgTX;
			m.innerHTML = res;
		}
		return false;
	}
	else
	{
		if(m != null && m != 'undefined')	m.innerHTML = 'Processing ...';
		return true;
	}
}

////////////////////////////////////////////////////////////////////////////////////
function Trim(victim) 
{
    if(victim == null || victim == '') return victim;
    
    var len = victim.length;
    
    while (victim.substring(0,1) == ' ')          {  victim = victim.substring(1, len--);  }
    
    while (victim.substring(len - 1, len) == ' ') {  victim = victim.substring(0, --len);  }
    
    return victim;
}

////////////////////////////////////////////////////////////////////////////////////
function ValidEMailAddr(id, msg)
{
	var m = GetObject(msg);
	var c = GetObject(id);
	if(c == null || c == 'undefined')	return true;
	
	var e = c.value;
	var res = ''
		
	if(e != ''  &&  e.indexOf('@') > 0  &&  (e.length - e.lastIndexOf('.')) < 5) 
	{
		c.style.backgroundColor = nrmBG;
		c.style.color = nrmTX;
		
		if(m != null && m != 'undefined')	
		{
			m.style.color = errMsgTX;	
			m.innerHTML = 'Processing ...';
		}

		var cmdSend = GetObject('cmdSend');
		if(cmdSend != null)	{ cmdSend.disabled = true; }
		
		return true;
	}
	else
	{
		c.style.backgroundColor = errBG;
		c.style.color = errTX;
		
		if(e == '')	res = 'Missing e-mail address';
		else		res = 'Invalid e-mail address';
		
		if(m == null || m == 'undefined')	
		{
			alert(res);
		}
		else			
		{
			m.style.color = errMsgTX;
			m.innerHTML = res;
		}
		
		var cmdSend = GetObject('cmdSend');
		if(cmdSend != null)	{ cmdSend.disabled = false; }
		
		return false;
	}
}

////////////////////////////////////////////////////////////////////////////////////
function ValidPassword(id, confId, minLen, msg)
{
	var res = '', p0 = '', p1 = '';
	var m = GetObject(msg);
	var pwd = GetObject(id);
	var conf = null;

	if(pwd == null || pwd == 'undefined')	
	{
		alert('Missing password control');
		return false;
	}
	
	if(confId != '')
	{
		conf = GetObject(confId);
		if(conf == null || conf == 'undefined')	
		{
			alert('Missing password confirmation control');
			return false;
		}
	}
	
	p0 = pwd.value;	
	if(p0 == '')	
	{
		res = 'Please choose your password';
	}
	else if(p0.length < minLen)	
	{
		res = 'Password must be at least ' + minLen + ' characters.';
	}

	else if(confId != '')
	{
		p1 = conf.value;
		if(p1 == '')
		{
			res = 'Please confirm the password';
		}
		else if(p0 != p1)
		{
			pwd.value = '';
			conf.value = '';
			res = 'Please re-type your password';
		}
	}
	
	if(res == '')
	{
		if(m != null && m != 'undefined')	
		{
			m.style.color = errMsgTX;	
			m.innerHTML = 'Processing ...';
		}
		return true;
	}
	else
	{
		if(m == null || m == 'undefined')	
		{
			alert(res);
		}
		else			
		{
			m.style.color = errMsgTX;
			m.innerHTML = res;
		}
		return false;
	}	
}

function ValidateRequiredControls()
{
	var err = 0;
	var new_err = 0;
	var b, c;


	// Validate:
	// if any issues found - no controls are required:
	if(reqCntrNames != '')
	{
		var cType = '';
		var i = 0;
		var j = reqCntrNames.length;

		for(;i<j;i++)
		{
			c = GetObject(reqCntrNames[i]);
			if(c == null || c == '')			continue;
			else if(c.style.display == 'none')	continue;

			cType = c.type;			
			switch(cType)
			{
				case 'text':
					if(c.value == '')		{	new_err = 1;	}	
					break;	
					
				case 'hidden':
					if(c.value == '')		{	new_err = 1;	}	
					break;	

				case 'password':
					if(c.value == '')		{	new_err = 1;	}	
					break;	
					
				case 'checkbox':
					if(!c.checked)			{	new_err = 1;	}	
					break;	
					
				case 'select-one':
					if(c.selectedIndex < 1)	{	new_err = 1;	}	
					break;	
			}
			
			if(new_err == 1)
			{
				err = 1;
				new_err = 0;
				PaintInvalid(c);
			}
			else
			{
				PaintValid(c);
			}
		}
	}
	c = GetObject('errMsgSpan');

	if(err != 0)
	{
		if(c != null && c != '')
		{
			c.innerHTML = 'Please fill all the fields marked with asterisks';
			c.style.color = errMsgTX;
		}
		else
		{
			alert('Please fill all the fields marked with asterisks');
		}
		return false;
	}
	else
	{
		if(c != null && c != '')
		{
			c.innerHTML = 'Processing ...';
			c.style.color = errMsgTX;	
		}	
			
		return true;
	}
	

}	// ------------------------------------------------------

function ValidatePositiveInteger(txt)
{
	var temp = txt.value;
	var valid = true;
	
	if(temp != '')
	{
		if(isNaN(temp)) { valid = false; }
		else
		{
			valid = ( parseFloat(temp) % 1.0 == 0.0 && parseInt(temp) >=0 );
		}
	}
	
	//////////////////////////// valid entry: 
	if(valid)
	{
		PaintValid(txt);
		DispErrMsg('','errMsgSpan');
		return true;
	}
	//////////////////////////// invalid entry:
	else	
	{	
		PaintInvalid(txt);
		DispErrMsg('Invalid entry. The field accepts only whole positive numeric values. ','errMsgSpan');
		return false;
	}
}


function ValidateRequiredHiddenFields()
{
	// Validate:
	// if any issues found - no controls are required:
	if(reqCntrNames != '')
	{
		var c;
		var i = 0;
		var j = reqCntrNames.length;
		var m = GetObject('errMsgSpan');

		for(; i<j; i++)
		{
			c = GetObject(reqCntrNames[i]);
			if(c == null || c == '')			continue;

			if(c.type == 'hidden' && c.value == '')
			{
				if(m != null && m != '') { m.innerHTML = c.name.replace('_', ' ') + ' is a required field';	}
				else					 { alert(c.name + ' is a required field');							}
				return false;
			}	
		}
		
		if(c != null && c != '') { m.innerHTML = 'Processing ...'; }
		return true;
	}
}	// ------------------------------------------------------

function openInfo(url)
{
		popup = window.open(url,'IG','location=0,toolbar=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=600,height=495');
		popup.focus();
}	// ------------------------------------------------------

function LoadFormContainers(id)
{
	var c = 0, cc = document.forms[0].elements.length;
	var name = '';
	var txt;
	var contr;
	
	//  clean up:
	GetObject('errMsgSpan').innerHTML = '';
	
	// copy all values into hidden form containers
	for(; c<cc; c++)
	{
		contr = document.forms[0].elements[c];
		if(contr == null || contr == '' || contr == 'undefined') continue;
		
		name = contr.name;

		txt = GetObject(name + '_' + id);		
		if(txt != null && txt != '' && txt != 'undefined')	
		{ 
			document.forms[0].elements[c].value = txt.value; 
		}	
	}
	
	// copy user name into lables:
	var n = 0;
	var lbl = GetObject('userName_' + n++);
	while(lbl != null && lbl != ''  && lbl != 'undefined' )
	{
		lbl.innerHTML = document.forms[0].First_Name.value + ' ' + document.forms[0].Last_Name.value;
		lbl = GetObject('userName_' + n++);
	}	

	
	// set current roles:	
	var role = document.forms[0].role.value;		
	var m = allRoles.length;

	// un-check
	for(n = 0; n < m; n++)
	{
		c = GetObject('ckbRole_' + allRoles[n]);
		if(c != null)	c.checked = false;
	}
	
	// check
	if(role != null && role != '')
	{
		var roles = role.split(delim_0);
		m = roles.length;
		
		for(n = 0; n < m; n++)
		{
			c = GetObject('ckbRole_' + roles[n]);
			if(c != null)	c.checked = true;
		}
	}	
	
	// clear password controls
	var pwd1 = GetObject('pwd1');
	var pwd2 = GetObject('pwd2');
	pwd1.value='';
	pwd2.value='';

}	// ------------------------------------------------------

function ChangeRole()
{
	var userRoles = '';
	var m = allRoles.length;
	
	for(n = 0; n < m; n++)
	{
		c = GetObject('ckbRole_' + allRoles[n]);
		if(c == null)	continue;
		if(c.checked)
		{
			if(userRoles != '')	userRoles += delim_0;
			userRoles += allRoles[n];
		}
	}
	
	// forward data:
	document.forms[0].role.value = userRoles;
	
	// submit form:
	document.forms[0].submit();
	

}	// --------------------------------------------------

function ChangePassword()
{

	var pwd = GetObject('pwd1').value;
	

	if(pwd == null || pwd == '')
	{
		GetObject('errDialogMsg').innerHTML = 'Please type the password!';
	}
	else
	{
		while(pwd.indexOf(' ') != -1) { pwd = pwd.replace(' ',''); }
		
		if(pwd.length < 5)
		{
			GetObject('errDialogMsg').innerHTML = 'Please type at least 5 characters.';
		}

		else if(pwd != GetObject('pwd2').value)
		{
			GetObject('errDialogMsg').innerHTML = 'Please re-type the password!';
		}
		else
		{
			document.forms[0].PWD.value = pwd;
			document.forms[0].exec.value='save'; 
			document.forms[0].submit();
		}
	}
}	// ------------------------------------------------------

function ValidateEMail(errMsgBoardName)
{ 
	var to = document.forms.wfEMail.E_Mail;
	var from = document.forms.wfEMail.e_from;
	var subj = document.forms.wfEMail.e_subj;
	var body = document.forms.wfEMail.e_body;
	var cmdSend = GetObject('cmdSend');
	var	err = '';

	if(to == null || to == '' || from == null || from == '' || subj == null || subj == '' || body == null || body == '') 
	{
		err = 'Unable to send.';
	}	
	else
	{
		if(to.value == "")		err += ( err == '' ? ' "To" '      : '<br/>"To" ' );
		if(from.value == "")	err += ( err == '' ? ' "From" '    : '<br/>"From" ' );
		if(subj.value == "")	err += ( err == '' ? ' "Subject" ' : '<br/>"Subject" ' );
	}
	
	if(err == '')
	{
		DispErrMsg('Processing ...', errMsgBoardName);
		if(cmdSend != null)	{ cmdSend.disabled = true; }
		return true;
	}
	else
	{
		if(body.value == ""	)	err = "Please type your message" 
		else					err = "Missing message attributes " + err;

		DispErrMsg(err, errMsgBoardName);
		if(cmdSend != null)	{ cmdSend.disabled = false; }
		return false;
	}	
}	// ------------------------------------------------------



////////////////////////////////////////////////// FILTER CBO FUNCTIONS

function UpdateURL(key, cbo, clearKeys)
{
	var url = location.href;

	url = SetKey(url, key, cbo);
	
	if(clearKeys != null)
	{
		var n = 0;
		var m = clearKeys.length;
		for(; n < m; n++)
		{	
			if(clearKeys[n] != '') url = SetKey(url, clearKeys[n], null);
		}
	}

	location.href = url;

}	// ------------------------------------------------------

function SetKey(url, key, cbo)
{
	var q = url.indexOf('?');
	var i = url.indexOf('&' + key + '=');
	var val = cbo == null ? '-1' : cbo.value;

	if(q == -1)
	{
		url = url + '?' + key + '=' + val;
	}
	else if(i == -1)
	{
		var j = url.indexOf('?' + key + '=');
		
		if(j == -1)
		{
			url = url + '&' + key + '=' + val;
		}
		else
		{
			var n = url.indexOf('&', j + 1);
			
			if(n == -1)	{ url = url.substring(0,j) + '?' + key + '=' + val;	}
			else		{ url = url.substring(0,j) + '?' + key + '=' + val + url.substring(n);	}
		}
	}
	else
	{
		var n = url.indexOf('&', i + 1);
		
		if(n == -1)	{	url = url.substring(0,i) + '&' + key + '=' + val;	}
		else		{	url = url.substring(0,i) + '&' + key + '=' + val + url.substring(n);	}		
	}
	return url;		
}	// ------------------------------------------------------

////////////////////////////////////////////////// GRID FUNCTIONS

function SetUpdateFlag(rowUpdFlag, grdUpdFlag)
{
	var row = GetObject(rowUpdFlag);
	if(row != null && row != '')	row.value = 1;
	
	var grd = GetObject(grdUpdFlag);
	if(grd != null && grd != '')	grd.value = 1;

}	// ------------------------------------------------------

function UpdateCheckbox(src, resId, rowUpdFlag, grdUpdFlag)
{
	if(src == null) return;
	
	var srcId = src.id;
	var u = srcId.indexOf('_');
	if(u != -1) srcId = srcId.substr(0, u);
	var ckbAllTop = GetObject(srcId + '_allTop');
	var ckbAllBottom = GetObject(srcId + '_allBottom');
	
	var res = GetObject(resId);
	if(src != null && res != null)	
	{
		if(src.checked) 
		{
			res.value = 1;
		}
		else
		{
			res.value = 0;
			if(ckbAllTop != null) ckbAllTop.checked = false;
			if(ckbAllBottom != null) ckbAllBottom.checked = false;
		}
	}

	SetUpdateFlag(rowUpdFlag, grdUpdFlag);
}	// ------------------------------------------------------

function CheckAll(src, rows, ckbPrefix, hidPrefix, rowUpdPrefix, grdUpdFlag)
{
	if(src == null) return;
	//status='ckbPrefix=' + ckbPrefix + '  hidPrefix=' + hidPrefix;
	var res = null;
	var checkAll = src.checked;
	var peerId = src.id;
	var peer = null;
	
	if(peerId.indexOf('_allBottom') != -1)		peer = GetObject(peerId.replace('_allBottom','_allTop'));
	else if(peerId.indexOf('_allTop') != -1)	peer = GetObject(peerId.replace('_allTop','_allBottom'));

	for(var r = 0; r < rows; r++)
	{
	
		// get row update flag container:
		res = GetObject(rowUpdPrefix + r);
				
		if(res == null)	continue;		
		
		// set row update flag:
		res.value = 1;

		// check the box:
		res = GetObject(ckbPrefix + r);
		if(res != null && !res.disabled)	
		{
			res.checked = checkAll;
		}
	
		// update checkbox hidden value container:
		res = GetObject(hidPrefix + r);
		if(res != null && !res.disabled)	
		{
			res.value = checkAll ? 1 : 0;
		}
		
		if(peer != null)	peer.checked = checkAll;
	}	

	// update grid flag
	var grd = GetObject(grdUpdFlag);
	if(grd != null && grd != '')	grd.value = 1;

}	// ------------------------------------------------------

function EnableTxt(ckb, txtId)
{
	var txt = GetObject(txtId);
	if(ckb != null && txt != null)	
	{
		if(ckb.checked)
		{
			txt.disabled = false;
			txt.style.backgroundColor = nrmBG; 
		}
		else
		{
			txt.value = '';
			txt.disabled = true;
			txt.style.backgroundColor = '#dddddd'; 
		}
	}
}	// ------------------------------------------------------


function ConfirmSave(url, form, confirmed)
{
	var guf = GetObject('gridUpdFlag');

	if(confirmed > 0)		{  GoAhead(null, form)							}
	else if(confirmed < 0)
	{
		guf.value = 0;		
		GoAhead(url, form);	 
	}
	else if(guf.value == 1) {	SwitchObjects('DialogSaveChanges', null);	}	
	else					{	GoAhead(url, form);							}
}	// ------------------------------------------------------

function GoAhead(url, form)
{
	if(url != null)			{	location.href = url;			}
	else if(form != null)	{	document.forms[form].submit();	}
	else					{	document.forms[0].submit();	 	}
}	// ------------------------------------------------------

function CopyTxtValue(txt, hidId, oldStr, newStr)
{
	var hid = GetObject(hidId);
	
	if(hid != null) 
	{ 		
		var src = txt.value;
		while(src.indexOf(oldStr) != -1) { src = src.replace(oldStr, newStr); }		
		hid.value = src; 
	}	
}	// ------------------------------------------------------

////////////////////////////////////////////////// WFCombo
function ExpandWFCombo(id)
{
    var lbl = GetObject(id);
    var list = GetObject(id + '_list');
    
    if(lbl == null || list == null) return false;
    
    list.style.top  = parseInt(lbl.style.top);
    list.style.left = parseInt(lbl.style.left);
    list.style.display = '';
}

function SetWFComboValue(id, val)
{
    var lbl = GetObject(id);
    var list = GetObject(id + '_list');
    
    if(lbl == null || list == null) return false;
    
    lbl.innerHTML = val;
    list.style.display = 'none';
}

////////////////////////////////////////////////// MISC FUNCTIONS

function SwitchObjects(show, hide)
{
	ShowObject(show, true);
	ShowObject(hide, false);
}	// ------------------------------------------------------

function ShowObject(id, visible)
{
	var o = id == null ? null : GetObject(id);	
	if(o != null) {	o.style.display = visible ? '' : 'none'; }
}	// ------------------------------------------------------

function GetObject(id)
{
	var res = document.getElementById(id);
	if(res == '' || res == 'undefined') { return null; }
	else								{ return res;  }
}	// ------------------------------------------------------

function PaintValid(c)
{
    c.style.backgroundColor = nrmBG;
	if(c.type == 'checkbox')    {   if(c.parentNode != null) c.parentNode.style.backgroundColor = nrmBG;    }
    else                        {   c.style.color = nrmTX;    }
}	// ------------------------------------------------------

function PaintInvalid(c)
{
    c.style.backgroundColor = errBG;
    if(c.type == 'checkbox')    {   if(c.parentNode != null) c.parentNode.style.backgroundColor = errBG;    }
    else                        {   c.style.color = errTX;    }
}	// ------------------------------------------------------

function DispErrMsg(msg, board)
{
	DisplayMessage(msg, board, true);
	
}	// ------------------------------------------------------

function DisplayMessage(msg, msgBoard, alertBox)
{
	var mb = GetObject(msgBoard);
	if(mb != null)		{ mb.innerHTML = msg; }
	else if(alertBox)	{ alert(msg);  }
	
}	// ------------------------------------------------------

//-->

