url = document.location.href;
xend = url.lastIndexOf("/") + 1;
var base_url = url.substring(0, xend);

function ajax_do(call, action, j_id, j_conf, j_post, j_extra) {
        // Does URL begin with http?
        call += '?' + Math.random(0, 1000) + '=' + Math.random(0, 1000);
        if (call.substring(0, 4) != 'http') {
                call = base_url + call + '&action=' + encodeURIComponent(action) + '&j_id=' + encodeURIComponent(j_id) + '&j_conf=' + encodeURIComponent(j_conf) + '&j_post=' + jsap(j_post) + '&j_extra=' + jsap(j_extra);
        }
        // Create new JS element
        var jsel = document.createElement('SCRIPT');
        jsel.type = 'text/javascript';
        jsel.src = call;

        // Append JS element (therefore executing the 'AJAX' call)
        document.body.appendChild(jsel);
}

function jsap(a)
{
    var a_php = "";
    var total = 0;
    for (var key in a)
    {
        ++ total;
        a_php = a_php + "s:" +
                String(key).length + ":\"" + String(key) + "\";s:" +
                String(a[key]).length + ":\"" + encodeURIComponent(String(a[key])) + "\";";
    }
    a_php = "a:" + total + ":{" + a_php + "}";
    return a_php;
}

function submit_form(action, id, conf) {
	var input_array = document.getElementsByTagName('input');
	var select_array = document.getElementsByTagName('select');
	var addons_status = document.getElementById('addons');
	var input_post = new Array();
	var extra_post = new Array();
	for(i=0;i<input_array.length;i++) {
		input_name = encodeURIComponent(input_array[i].getAttribute('name'));
		input_type = encodeURIComponent(input_array[i].getAttribute('type'));
		input_value = input_array[i].value;
		//var input_incl = input_name.substring(0,5);
		//if (input_incl=='incl_') {
			//input_name = input_name.substring(5,input_name.length);
			if (input_type=='text' || input_type=='password' || input_type=='hidden') {
				input_post[input_name] = input_value;
			}
			else if (input_type=='checkbox') {
				if (input_array[i].checked) {
					input_post[input_name] = 'yes';
				}
				else {
					input_post[input_name] = 'no';
				}
			}
			else if (input_type=='radio') {
				if (input_array[i].checked) {
					input_post[input_name] = input_value;
				}
			}
			else {
				extra_post[input_type] = input_value;
			}
		//}
	}
	for(i=0;i<select_array.length;i++) {
		input_name = encodeURIComponent(select_array[i].getAttribute('name'));
		input_value = select_array[i].value;
		input_post[input_name] = input_value;
	}
	if (addons_status) {
		//ie suuuuuuuuuuuuuucks :)
		if (addons_status.getAttribute('className')) {
			input_value=addons_status.getAttribute('className');
		}
		if (addons_status.getAttribute('class')) {
			input_value=addons_status.getAttribute('class');
		}
		input_post['addons'] = input_value;
	}
	//var div = document.getElementById('contentdiv');
	//div.innerHTML = '<center><p><br /><br /><br /><br /></p><img src=\"/img/loader.gif\" /><p>loading</p><br /><br /><br /><br /></center>';
	ajax_do('action.php', action, id, conf, input_post, extra_post);
}

window.onload = function()
{
  submit_form('time_manager');
}
	//window.console.log(input_name);