var windows;

function addHouse()
{
    document.location.href="?act=add&on=house";
}

function addCategory()
{
    document.location.href="?act=add&on=category";
}

function addItem(houseId)
{
    document.location.href="?act=add&on=item&houseid="+houseId;
}

function editHouse(id)
{
    document.location.href="?act=edit&on=house&id="+id;
}

function editItem(id)
{
    document.location.href="?act=edit&on=item&id="+id;
}

function editCategory(name)
{
    document.location.href="?act=edit&on=category&name="+name;
}

function deleteHouse(id)
{
    document.location.href="?act=delete&on=house&id="+id;
}

function deleteItem(id,houseid)
{
    document.location.href="?act=delete&on=item&id="+id+"&houseid="+houseid;
}

function deleteCategory(name)
{
    document.location.href="?act=delete&on=category&name="+name;
}

function showItem(id)
{
    document.location.href="?act=show&on=item&id="+id;
}

function openDialog(path,name,width,height,posX,posY)
{
    if (width==null || width<=0)
    {
		width=window.screen.availWidth*0.8;
    }
    if (height==null || height<=0)
    {
		height=window.screen.availHeight*0.8;
    }
    if (posX==null || posX<0)
    {
    	posX=(window.screen.availWidth-width)/2;
    }
    if (posY==null || posY<0)
    {
	    posY=(window.screen.availHeight-height)/2;
    }
    if (posX<0)
    {
        posX=0;
    }
    if (posY<0)
    {
        posY=0;
    }
    win=window.open(path,name,"height="+height+",width="+width+",scrollbars=1,directories=0,location=0,menubar=0,toolbar=0,resizable=1,status=1,top="+posY+",left="+posX);
    if (windows==null)
    {
        windows=new Array();
    }
    windows.push(win);
    return win;
}

function closeMySelf()
{
    window.close();
    window.opener.focus();
}

function closeWindows()
{
    if (windows!=null)
    {
        for (;windows.length>0;)
        {
            win=windows.pop();
            win.close();
        }
    }
}

function reloadOpener()
{
    toReload=window.opener;
    if (toReload!=null)
    {
        toReload.location.reload();
    }
}

function writeDate()
{
	now = new Date();
	switch(now.getDay())
	{
		case 0:
			document.write("Sunday, ");
			break;
		case 1:
			document.write("Monday, ");
			break;
		case 2:
			document.write("Tuesday, ");
			break;
		case 3:
			document.write("Wednesday, ");
			break;
		case 4:
			document.write("Thursday, ");
			break;
		case 5:
			document.write("Friday, ");
			break;
		case 6:
			document.write("Saturday, ");
			break;
	}
	document.write(now.getDate()," ");
	switch(now.getMonth())
	{
		case 0:
			document.write("January ");
			break;
		case 1:
			document.write("February ");
			break;
		case 2:
			document.write("March ");
			break;
		case 3:
			document.write("April ");
			break;
		case 4:
			document.write("May ");
			break;
		case 5:
			document.write("June ");
			break;
		case 6:
			document.write("July ");
			break;
		case 7:
			document.write("August ");
			break;
		case 8:
			document.write("September ");
			break;
		case 9:
			document.write("October ");
			break;
		case 10:
			document.write("November ");
			break;
		case 11:
			document.write("December ");
			break;
	}

	document.write(now.getFullYear());
}
