I have a problem with undefined variables...

In my index.php i have (opens a popup with a calendar)

<input type="text" name="ankomstdatum" size="" value="<?php echo $_SESSION['ankomstdatum']; ?>">
<input type="button" onClick='targetitem = document.forms[0].ankomstdatum; dataitem = window.open("kalender.php", "dataitem", "toolbar=no,menubar=no,scrollbars=yes,width=1000,height=800"); dataitem.targetitem = targetitem' value="Välj ankomstdatum">

in my kalender.php I have (javascript for returning date)

//Script för att returnera datum...
function select_item(item)
targetitem.value = item;
return false;

and (the links for previous and next month)

<td width="50%" align="left">&nbsp;&nbsp;<a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $prev_month . "&year=" . $prev_year; ?>" style="color:#FFFFFF" title="Föregående månad">F&ouml;reg&aring;ende</a></td>
<td width="50%" align="right"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $next_month . "&year=" . $next_year; ?>" style="color:#FFFFFF" title="Nästa månad">N&auml;sta</a>&nbsp;&nbsp;</td>

and (the link in calendar with date to return)

echo "<a href='' onClick='return select_item(\"".$newdate."\")'><td align='left' valign='top' style='height:40px;' width='40' title='".$newdate."'>".($i - $startday + 1) ."</a>";

It works as long as I don't change the month, if I do I get this

"Detaljerad information om felet på webbsidan

Användaragent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Win64; x64; Trident/4.0; GTB6.5; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)
Tidsstämpling: Thu, 26 Aug 2010 15:21:05 UTC

Message: 'targetitem' is undefined.
Row: 15
Character: 1
Code: 0
URI: http://www.briardliv.se/marcus/skola/php/projekt/kalender.php?month=9&year=2010"

You can see all of it at http://www.briardliv.se/marcus/skola...jekt/index.php

It's in Swedish but the calendar is still understandable.