function changeClass(oldid, newclass)
{
window.document.getElementById(oldid).className=newclass;
}
function initXmlHttp()
{
var xmlHttp=null;
try
{ xmlHttp=new XMLHttpRequest(); }
catch (e)
{
try
{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e)
{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
}
return xmlHttp;
}
function lcal_loadData($query, $target)
{
var xmlHttp = initXmlHttp();
xmlHttp.open('POST', '/modules/evk_gather/evk.php', true);
xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xmlHttp.send($query);
xmlHttp.onreadystatechange = function()
{
if(xmlHttp.readyState == 4)
{
if($target == 'return')
{
return xmlHttp.responseText;
}
else
{
window.document.getElementById($target).innerHTML = xmlHttp.responseText;
}
}
}
}
function lcal_buildIQuery($form, $function, $return)
{
$querystring = $function;
for($i = 0; $i < window.document.getElementById($form).length; $i++)
{
switch(window.document.getElementById($form)[$i].type)
{
case 'radio':
if(window.document.getElementById($form)[$i].checked == true)
{ $querystring = $querystring + '&' + window.document.getElementById($form)[$i].name + '=' + escape(window.document.getElementById($form)[$i].value); }
break;
case 'select-one':
var sel = window.document.getElementById($form)[$i];
for(i=0; i< sel.options.length; i++)
{
if (sel.options[i].selected == true)
{
$querystring = $querystring + '&' + sel.name + '=' + escape(sel.options[i].value);
}
}
break;
case 'text':
$querystring = $querystring + '&' + window.document.getElementById($form)[$i].name + '=' + escape(window.document.getElementById($form)[$i].value);
break;
case 'textarea':
$querystring = $querystring + '&' + escape(window.document.getElementById($form)[$i].name) + '=' + escape(window.document.getElementById($form)[$i].value);
break;
case 'password':
$querystring = $querystring + '&' + escape(window.document.getElementById($form)[$i].name) + '=' + escape(window.document.getElementById($form)[$i].value);
break;
case 'hidden':
if(window.document.getElementById($form)[$i].name != '')
{
$querystring = $querystring + '&' + escape(window.document.getElementById($form)[$i].name) + '=' + escape(window.document.getElementById($form)[$i].value);
}
break;
case 'checkbox':
$querystring = $querystring + '&' + window.document.getElementById($form)[$i].name + '=' + ((window.document.getElementById($form)[$i].checked) ? '1' : '0');
break;
}
}
lcal_loadData($querystring, $return);
}
function addTime($containerId, $appendToId, $returnFunctionsTo)
{
$appendTo = window.document.getElementById($appendToId);
$newContainer = document.createElement('div');
$newContainer.id = 'Timecontrol' + $containerId;
$newContainer.className = 'Timecontrol';
$appendTo.appendChild($newContainer);
$returnFunctionsTo.innerHTML = 'Lägg till tidpunktTa bort tidpunkt';
}
function daysInMonth($month, $year, $target)
{
$date = new Date($year, $month, 0);
$daysInMonth = $date.getDate();
$daysInOld = window.document.getElementById($target).length;
if($daysInMonth > $daysInOld)
{
for($i = 1; $i <= ($daysInMonth - $daysInOld); $i++)
{
var $option = document.createElement('option');
$option.value = $daysInOld + $i;
$option.text = $daysInOld + $i;
try { window.document.getElementById($target).add($option, null); }
catch(ie) { window.document.getElementById($target).add($option); }
}
}
if($daysInMonth < $daysInOld)
{
for($i = 1; $i <= ($daysInOld - $daysInMonth); $i++)
{
window.document.getElementById($target).remove($daysInOld - $i);
}
}
}
function removeTime($appendToId, $num, $returnFunctionsTo)
{
$list = window.document.getElementById($appendToId);
$list.removeChild($list.lastChild);
$returnFunctionsTo.innerHTML = 'Lägg till tidpunkt';
$num != 1 ? $returnFunctionsTo.innerHTML = $returnFunctionsTo.innerHTML + 'Ta bort tidpunkt' : null;
}
function freeTextSearch($element, event, $archive, $query)
{
$list = window.document.getElementById('ft_search');
$archive == true ? $archivestring = '&archive=1' : $archivestring = '';
if($element.value != '')
{
switch(event.keyCode)
{
case 38: /* ArrowUp */
for($i = 0; $i < $list.childNodes.length; $i++)
{
if($list.childNodes[$i].className == 'result_focus')
{
$prev = $i-1;
$list.childNodes[$i].className = 'result';
$list.childNodes[$prev].className = 'result_focus';
$found = true;
break;
}
else
{
$found = false;
}
}
if($found == false)
{
$list.lastChild.className = 'result_focus';
}
break;
case 40: /* ArrowDown */
for($i = 0; $i < $list.childNodes.length; $i++)
{
if($list.childNodes[$i].className == 'result_focus')
{
$next = $i+1;
$list.childNodes[$i].className = 'result';
$list.childNodes[$next].className = 'result_focus';
$found = true;
break;
}
else
{
$found = false;
}
}
if($found == false)
{
$list.childNodes[0].className = 'result_focus';
}
break;
case 13: /* Enter */
for($i = 0; $i < $list.childNodes.length; $i++)
{
if($list.childNodes[$i].className == 'result_focus')
{
lcal_loadData('lcal_function=filterList&id_sit=' + $list.childNodes[$i].name + $archivestring + $query, 'evk_local');
}
}
break;
default:
if(window.document.getElementById('ft_search') == null)
{
$obj = $element;
var $xoffset = 0;
var $yoffset = 0;
do
{
$xoffset += $obj.offsetLeft;
$yoffset += $obj.offsetTop;
}
while($obj = $obj.offsetParent);
$ftContainer = window.document.createElement('div');
$ftContainer.className = 'ft_search';
$ftContainer.id = 'ft_search';
$ftContainer.style.width = $element.style.width;
$ftContainer.style.padding = $element.style.padding;
$ftContainer.style.top = $yoffset + 21 + 'px';
$ftContainer.style.left = $xoffset + 'px';
$element.parentNode.appendChild($ftContainer);
}
lcal_loadData('lcal_function=ft_search&search=' + $element.value + $archivestring + $query, 'ft_search');
try { document.attachEvent("onclick",delFreeTextSearch); } catch (e) {}
document.onclick = delFreeTextSearch;
break;
}
}
}
function delFreeTextSearch()
{
if(window.document.getElementById('ft_search') != null)
{
try
{ window.document.getElementById('ft_search').removeNode(true); }
catch(e)
{ window.document.getElementById('fts_container').removeChild(window.document.getElementById('ft_search')); }
document.onclick = '';
}
}
function resetFocus($container)
{
for($i = 0; $i < $container.childNodes.length; $i++)
{
$container.childNodes[$i].className = 'result';
}
}