function menuFunc(_type, _obj)
{ 
	var _soundObj = document.getElementById('_sound');
	if(_type!=null && _obj!=null)
	{
		switch(_type)
		{
			case 1:
				_obj.style.backgroundColor = '#1882D6';
				if(_soundObj!=null){ _soundObj.src = 'link_sound2.mp3'; _soundObj.disabled = false;}
			break;
			case 2:
				_obj.style.backgroundColor = '';
				if(_soundObj!=null){ _soundObj.src = ''; _soundObj.disabled = true;}
			break;
			case 3:
				var _id = _obj.id;
				var _page = _id.substring(5,_id.length);
				window.location.href = './' + _page + '.php';
			break;
			case 4:
				history.back();
			break;
			case 5:
				var _id = _obj.id;
				var _page = _id.substring(5,_id.length);
				window.location.href = './' + _page + '.php';
			break;
			case "new":
			case "partner":
			case "invoice":
			case "service":
			case "count":
				var _id = _obj.id;
				var _page = _id.substring(5,_id.length);
				window.location.href = './' + _page + '.php?func=' + _type;
			break;
			case 6:
				var _id = _obj.id;
				var _objId = _id.substring(4,_id.length);
				window.location.href = './form_invoice.php?func=mod&id='+_objId;
			break;
			case 7:
				var _id = _obj.id;
				var _objId = _id.substring(4,_id.length);
				window.location.href = './form_invoice.php?func=del&id='+_objId;
			break;
			case 8:
				var _id = _obj.id;
				var _array = _id.split("_");
				var _func = _array[1];
				var _objId = _array[2]; // invoiceItemDataId
				window.location.href = './report_invoice.php?func='+_func+'&iid='+_objId;
			break;
			case 9:
				var _id = _obj.id;
				var _objId = _id.substring(4,_id.length);
				window.location.href = './form_invoice_balloon.php?func=mod&id='+_objId;
			break;
			case 10:
				var _id = _obj.id;
				var _objId = _id.substring(4,_id.length);
				window.location.href = './form_invoice_balloon.php?func=del&id='+_objId;
			break;
		}
	}
}
//*********************************************************************
function changePartnerType(_obj)
{
	if(_obj != null)
	{
		location.href = "./form_invoice.php?func=new&type=" + _obj.value;
	}
}
//*********************************************************************
function showRows(_param, _num, _obj)
{
	var _table = document.getElementById("table_CO2");
	if(_table != null && _table != "undefined")
	{
		if(_obj.checked)
		{
			_table.style.display = "inline";
		}
		else
		{
			_table.style.display = "none";
		}
	}
	/*
	if(_param!=null && _num!=null && _obj!=null)
	{
		for(var i=1; i<=_num; i++)
		{
			_row = document.getElementById("row_" + _param + "_" + i);
			if(_row!=null)
			{
				switch(_param)
				{
					case "CO2":
					if(_obj.checked)
					{
						_row.style.display = "inline";
					}
					else
					{
						_row.style.display = "none";
					}
					break;
				}
			}
		}
	}
	*/
}
//**********************************************************
// show-hide box content
//**********************************************************
function showHideContent(imgObj)
{
    if(imgObj != null)
    {
        postFix = imgObj.id.substring(imgObj.id.lastIndexOf("_")+1, imgObj.id.length);
        tableName = "table_" + postFix;
        contentTable = document.getElementById(tableName);
        if(contentTable != null)
        {
            if(imgObj.src.indexOf("icon_expand")>0)
            {
                contentTable.style.display = "none";                
                imgObj.src = "../images/icon_collapse.gif";
            }
            else
            {
                contentTable.style.display = "inline";
                imgObj.src = "../images/icon_expand.gif";
            }
        }
    }
}
//*********************************************************************
_tabClick = null;
function tabClick(_obj)
{
	_num = _obj.id.substring(_obj.id.length-1,_obj.id.length);
	
	_obj.style.backgroundColor = '#ffffff';
	_obj.style.borderBottom = 'solid 1px #ffffff';
	document.getElementById('tr_'+_obj.id).style.display = 'inline';
	
	if(_tabClick != null && _tabClick != 'undefined')
	{
		_tabClick.style.backgroundColor = '#C6E2AD';
		//_tabClick.style.borderBottom = 'solid 1px #82BF4B';
		_tabClick.style.borderBottom = 'solid 1px #aaaaaa';
		document.getElementById('tr_'+_tabClick.id).style.display = 'none';
	}
	
	_tabClick = _obj;
	
}
//*********************************************************************
_selectedCell = '';
function showInfo(_pict)
{
	if(_pict != null)
	{
		var _num = _pict.id.substring(7,8);
		var _cell = document.getElementById('machine_info'+_num);
		var _selCell = document.getElementById('machine_info'+_selectedCell);
		if(_selCell != null && _selCell != '')
		{
			_selCell.style.display = 'none';
		}
		if(_cell != null && _cell != '')
		{
			_cell.style.display = 'inline';
		}
		_selectedCell = _num;
	}
}
//*********************************************************************
function checkIsEmpty(_fieldName)
{
	_flag = false;
	if(_fieldName != null)
	{
		_field = document.getElementById(_fieldName);
		if(_field != null && _field != 'undefined')
		{
			if(_field.value == "")
			_flag = true;
		}
	}	
	return _flag;
}

//*********************************************************************
function checkPasswordIsOk()
{
	_flag = true;
	_pass1 = document.getElementById("NewPassword");
	_pass2 = document.getElementById("NewPassword2");
	if(_pass1 != null && _pass2 != null)
	{
		if(_pass1.value != _pass2.value)
		_flag = false;
	}
	return _flag;
}
//*********************************************************************
function submitRegistration()
{
	if(checkIsEmpty("NewName") || checkIsEmpty("NewEmail") || checkIsEmpty("NewPassword") || checkIsEmpty("NewPassword2") || checkIsEmpty("NewTel") || checkIsEmpty("NewAddress") || checkIsEmpty("NewInvoiceAddress") || checkIsEmpty("NewInvoiceName"))
	{
		alert("A csillaggal jelölt mezők kitöltése kötelező!");
	}
	else
	{
		if(checkPasswordIsOk())
		document.form_registration.submit();
		else
		alert("A két jelszó nem egyezik!");
	}
}
//*********************************************************************
function submitOrder()
{
	if(checkIsEmpty("OrderName") || checkIsEmpty("OrderTel") || checkIsEmpty("OrderAddress") || checkIsEmpty("OrderInvoiceAddress") || checkIsEmpty("OrderInvoiceName"))
	{
		alert("A csillaggal jelölt mezők kitöltése kötelező!");
	}
	else
	{
		document.form_order.submit();
	}
}

//*********************************************************************
function submitInvoice()
{
	if(checkIsEmpty("PartnerName") || checkIsEmpty("PartnerAddress") || checkIsEmpty("DeploymentDate") || checkIsEmpty("AmountService") || checkIsEmpty("LastInvoiceDateService") 
	|| checkIsEmpty("AmountMachine") || checkIsEmpty("InvoicePeriodMachine") || checkIsEmpty("LastInvoiceDateMachine") 
	)
	{
		alert("A csillaggal jelölt mezők kitöltése kötelező!");
	}
	else
	{
		if(document.getElementById("IsCO2").checked)
		{
			if(checkIsEmpty("WeightCO2") || checkIsEmpty("AmountCO2") || checkIsEmpty("InvoicePeriodCO2") || checkIsEmpty("LastInvoiceDateCO2"))
			{
				alert("A csillaggal jelölt mezők kitöltése kötelező!");
			}
			else
			{
				document.form_invoice.submit();
			}
		}
		else
		{
			document.form_invoice.submit();
		}
	}
}

//*********************************************************************
function submitInvoiceBalloon()
{
	if(checkIsEmpty("PartnerName") || checkIsEmpty("PartnerAddress") || checkIsEmpty("DeploymentDate") || checkIsEmpty("AmountService") || checkIsEmpty("LastInvoiceDateService"))
	{
		alert("A csillaggal jelölt mezők kitöltése kötelező!");
	}
	else
	{
		document.form_invoice_balloon.submit();
	}
}

//*********************************************************************
function getAddress(_obj)
{
	if(_obj.checked == true)
	{
		_addr = document.getElementById('NewAddress').value;
		_comp = document.getElementById('NewCompanyName').value;
		_name = document.getElementById('NewName').value;
		_invName = _comp;
		if(_comp == "")
		{ _invName = _name; }
		if(_invName!="" && _addr!="")
		{
			document.getElementById('NewInvoiceAddress').value = _addr;
			document.getElementById('NewInvoiceName').value = _invName;
		}
		else
		{
			alert("Nincsenek kitöltve az átemeléshez szükséges mezők:"+"\n"+"- Név vagy cégnév"+"\n"+"- Szállítási cím");
			_obj.checked = false;
		}
	}
	else
	{
		document.getElementById('NewInvoiceAddress').value = "";
		document.getElementById('NewInvoiceName').value = "";
	}
}
//*********************************************************************

function detectFlash()
{ alert("detectFlash");
	var flashinstalled = 0;
	var flashversion = 0;
	var MSDetect = "false";
	if (navigator.plugins && navigator.plugins.length)
	{alert("navigator.plugins: "+navigator.plugins);
		x = navigator.plugins["Shockwave Flash"];
		if (x)
		{alert("navigator.plugins[shockwave]: "+x);
			flashinstalled = 2;
			if (x.description)
			{
				y = x.description;
				flashversion = y.charAt(y.indexOf('.')-1);
			}
		}
		else
		flashinstalled = 1;
		if (navigator.plugins["Shockwave Flash 2.0"])
		{
			flashinstalled = 2;
			flashversion = 2;
		}
	}
	else if (navigator.mimeTypes && navigator.mimeTypes.length)
	{alert(navigator.mimeTypes);
		x = navigator.mimeTypes['application/x-shockwave-flash'];
		if (x && x.enabledPlugin)
		flashinstalled = 2;
		else
		flashinstalled = 1;
	}
	else
	{ MSDetect = "true"; }
	
	for(var i=7; i>0; i--){
		flashversion = 0;
		try{
			var flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + i);
			flashversion = i;
			return; alert(flash)
		}
		catch(e){ alert("nem ok")
		}
	}
	alert(flashversion)

	
}


document.onkeypress = function(e) {        
    var keyCode;
    if(typeof e=='undefined') //IE
    {        
        e = window.event;
        keyCode = e.keyCode;
    }
    else //mozilla
    {
        keyCode = e.which; 
    }
    
    if(keyCode == 13)
    {
        return false;
    }
    else
    {        
        var srcElement;
        if(typeof e.srcElement=='undefined') //mozilla
        {
            srcElement = e.target;
        }
        else //IE
        {
            srcElement = e.srcElement;
        }
                
        if(srcElement.nodeName == "INPUT")
        {   
            if(srcElement.className.indexOf("justNumber") >= 0)
            {                
                if(keyCode > 47 && keyCode < 58)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }            
        }        
        return true;
    }   
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

