<!--
var initial_submit_value = "";
var db = -1;
var result_text = "";
var result_ok = false;
var id_array = null;

function ajax_request(url, data, responseFunc)
{ 
	var aj = new Ajax.Request(url, {
							  method:'get',
							  parameters: data,
							  onComplete: responseFunc
							  }
	);
}

function ajax_updater(id, url) 
{  
 	new Ajax.Updater(id,url,{
					 method:'get',
					 asynchronous:true
					 });  
}

function refresh_db(page_id) 
{  
	var id = "guestbook_main";
	var url = "refresh_db.php5";
	var page_link = "guestbook.php5";
	
 	new Ajax.Updater(id,url,{
					 method:'get',
					 parameters: {update:'1',
					 			  id: page_id,
						 		  cur_page_link: page_link},
					 asynchronous:true
					 });  
}

function update_page(page_id) 
{  
	refresh_db(page_id);
}

function init_process(text) 
{
	var name_input = $('id_name');
	if (name_input != null)
	{
		name_input.focus();
	}
	ajax_request('timezone.php5', 'tz=' + get_timezone(), set_timezone);
	ajax_request('browser.php5', 'text=' + text, set_pc_info);
	style_browser();
	start_fade();
}

function processForm()
{
	$('id_date').value = get_date();
	$('id_timezone').value = get_timezone();
	$('id_x_info').value = get_info();
    $('submit').disabled = true;
	initial_submit_value = $('submit').value;
   	$('submit').value = "Processing...";
	result_ok = false;
	db = $('id_db').value;
	
    $('id_form').request({
      onSuccess: function(transport)
      {
		  result_text = transport.responseText;
		  if(result_text.match(/^OK/) != null) 
		  {
			  result_ok = true;
		  }
		  window.setTimeout(change_submit, 1000); 
		  window.setTimeout(end_submit, 3000); 
      }
    });

    return false;
}

function change_submit()
{
	var text = "OK";
	var ar = null;
	if (!result_ok)
	{
		ar = result_text.split(',');
		text = "Error";
	}
	
	set_colors(ar);
	$('submit').value = text;
}

function set_colors(array_msg)
{
	var color = "#FF0000";
	var border_color = color;
	
	if (db == 0)
	{
		id_array = new Array("name", "email", "subject", "message", "code");
	}
	else if (db == 1)
	{
		id_array = new Array("name", "email", "message", "code");
	}
	
	var result_text = "";
	if (array_msg != null)
	{
		result_text += "<br/>The following errors occured:<br/>";
		for (var i = 0; i < array_msg.length; i++)
		{
			var c = array_msg[i].charAt(0);
			if (c == 0)
			{
				color = "#FF0000";
				border_color = color;
				result_text += array_msg[i].substring(1) + "<br/>";
			}
			else if (c == 1)
			{
				color = "#BBBBBB";
				border_color = "#686868";
			}
			
			var lid = "l_id_" + id_array[i];
			var iid = "id_" + id_array[i];		
			document.getElementById(lid).style.color = color;
			document.getElementById(iid).style.borderColor = border_color;
		}
		result_text += "<br/>";
		$('result').style.color = "#FF0000";		
		$('result').innerHTML = result_text;
		update_captcha();
	}
	else
	{
		if (db == 0)
		{
			result_text += "<br/>Thank you for your e-mail!<br/><br/>"
		}
		else if (db == 1)
		{
			result_text += "<br/>Thank you for your message!<br/><br/>";
		}
		clear_entries(db);
		$('result').style.color = "#927f24";		
		$('result').innerHTML = result_text;
	}
}

function update_captcha()
{
	$('id_captcha').src = "securimage/securimage_show.php5?" + Math.random();
	$('id_code').value = "";	
}

function clear_entries(local_db)
{
	if (id_array == null)
	{
		if (local_db == 0)
		{
			id_array = new Array("name", "email", "subject", "message", "code");
		}
		else if (local_db == 1)
		{
			id_array = new Array("name", "email", "message", "code");
		}
	}
	$('clear').blur();
	var color = "#BBBBBB";
	var border_color = "#686868";
	for (var i = 0; i < id_array.length; i++)
	{
		var lid = "l_id_" + id_array[i];
		var iid = "id_" + id_array[i];		
		document.getElementById(lid).style.color = color;
		document.getElementById(iid).style.borderColor = border_color;			
	}
	
	update_captcha();
	$('result').innerHTML = "<br/>";
}

function end_submit() 
{
    $('submit').value = initial_submit_value;
    $('submit').disabled = false;
	if (result_ok)
	{
    	$('id_form').reset();
		$('id_name').focus();
		if (db == 1)
		{
			refresh_db(1);
		}
		$('result').innerHTML = "<br/>";
	}
	$('submit').style.color = "#000000"
	$('submit').style.borderColor = "#686868";
	$('clear').style.color= "#000000"
	$('clear').style.borderColor = "#686868";
}
//-->
