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/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;
}