function nHtmlRemoveChild(e){
	while(e.hasChildNodes()){
		e.removeChild(e.lastChild);
	}
}
function nHtmlStyleDisplayByObject(o,s){if(o&&o.style)o.style.display=s}
function nHtmlStyleDisplayByName(n,s){var o=document.getElementsByName(n);if(!o)return;if(!o.length)nHtmlStyleDisplayByObject(o,s);for(var i=0;i<o.length;i++)nHtmlStyleDisplayByObject(o[i],s)}
function nHtmlStyleDisplayById(d,s){nHtmlStyleDisplayByObject(document.getElementById(d),s)}
function nHtmlInnerHtml(e,c) {
	if(document.all){e.innerHTML=c;return}
	// Firefox
	var r = document.createRange();
	r.setStartBefore(e);
	var h = r.createContextualFragment(c);
	nHtmlRemoveChild(e);
	e.appendChild(h);
}

function doView (id)
{
 f=document.myform;
 f.action.value='view';
 f.xid.value=id;
 f.submit();
}

function alertAndFocus(obj, msg){alert(msg);obj.focus();return false;}

function nStrLen(s){if(s)return s.length;return 0}
function isDigit(c){return(c>="0")&&(c<="9")}
function nStrIsEmpty(s){return(s==null)||(s.length==0)}
function isInteger(s){r=/^[0-9]*$/;return r.test(s)}
function isFloat(s){r=/^[0-9]*.[0-9]$/;return r.test(s)}
function validateFloat(obj, msg)
{
	if (obj==null)
	{
		alert('Debug: object is null in validateFloat');
		return false;
	}
	
	if (obj.value.length==0)
	{
		return alertAndFocus(obj, msg);
	}
	
	var f = parseFloat(obj.value);
	
	if (isNaN(f))
	{
		return alertAndFocus(obj, msg);
	}

	return true;
}

function validateEmail(m){r=/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.([a-z]){2,4})$/;return r.test(m);}

function validateDate (obj, msg)
{
	if (obj.value.length==0)
	{
		return alertAndFocus(obj, msg);
	}
	
	var dates = obj.value.split('-');
	
	if (!dates)
	{
		return alertAndFocus(obj, msg);
	}
	
	if (dates.length!=3)
	{
		return alertAndFocus(obj, msg);
	}
	
	var dd = parseInt(dates[0]);
	var mm = parseInt(dates[1]);
	var yy = parseInt(dates[2]);
	
	if (isNaN(dd) || isNaN(mm) || isNaN(yy))
	{
		return alertAndFocus(obj, msg);
	}
	
	if (yy < 1990 || yy > 2100)
	{
	    return alertAndFocus(obj, msg);
	}
	
	mm = mm - 1;
	
	var date = new Date(yy, mm, dd, 0, 0, 0);
	if (date.getDate()!=dd || date.getMonth()!=mm || date.getFullYear()!=yy)
	{
		return alertAndFocus(obj, msg);
	}
	
	return true;
}


function validateIsEmpty (obj, msg)
{
	if (obj==null)
	{
		alert('Debug: object is null in validateIsEmpty');
		return false;
	}
	
	if (obj.value.length==0)
	{
		alert(msg);
		obj.focus();
		return false;
	}
	
	return true;
}

function validateRadioSelected (name, msg)
{
	var objs = document.myform.elements[name];
	
	if (objs==null)
	{
		alert('Debug: object ' + name + ' not found in validateRadioSelected.');
		return false;
	}
	
	for (i = 0; i < objs.length; i++)
	{
		if (objs[i].checked)
			return true;
	}

	alert(msg);
	return false;
}


function doCancel ()
{
	var url = 'main.php?action=cancel';
	
	if (document.myform.transaction_id)
	{
		url += '&transaction_id=' + document.myform.transaction_id.value;
	}
		
	if (document.myform.company_id)
	{
		url += '&company_id=' + document.myform.company_id.value;
	}
		
	if (document.myform._object)
	{
		url += '&_object=' + document.myform._object.value;
	}
		
	if (document.myform._cid)
	{
		url += '&_cid=' +  document.myform._cid.value;
	}
	
	if (document.myform.page) {
		url += '&page=' + document.myform.page.value;
	}
	
	if (document.myform.menu) {
		url += '&menu=' + document.myform.menu.value;
	}
	
	window.location = url;
	return false;
}

function swapPage (page) {
f=document.myform;
f.editPage.value=page;
f.submit();
}