//-------------------------------------------------------------------------------------
//Layout-management

/*
function correct_layout()
{
	var x = document.getElementById('content').offsetHeight;
	var y = document.getElementById('navigation_small').offsetHeight;
	
	if (x > y)
	{
		document.getElementById('navigation_small').style.height = x+"px";
		document.getElementById('wrapper').style.height = x+133+"px";
	}
}
*/

//Functions to encrypt mails!------------------------------------------------------
//http://jumk.de/nospam/stopspam.html
function UnCryptMailto( s )
{
    var n = 0;
    var r = "";
    for( var i = 0; i < s.length; i++)
    {
        n = s.charCodeAt( i );
        if( n >= 8364 )
        {
            n = 128;
        }
        r += String.fromCharCode( n - 1 );
    }
    return r;
}
 function linkTo_UnCryptMailto( s )
{
    location.href=UnCryptMailto( s );
}
//-------------------------------------------------------------------------------------------

function login_focus(field)
{
	document.getElementById(field).value = "";
	document.getElementById(field).style.color = "#333333";
}

function login_lost_focus(field)
{
	var f = document.getElementById(field);
	
	f.style.color = "#6D6D6D";
	if (f.value == "" && field == "login_username")
		f.value = "username";
		
	if (f.value == "" && field == "login_password")
		f.value = "password";
	
}



function comment_focus(field,but)
{
	document.getElementById(field).innerHTML = "";
	document.getElementById(field).style.color = "#333333";
	document.getElementById(but).style.visibility = "visible";
}

function navi_caption(item)
{
	strings = new Array("» my green profile", "» my settings", "» my articles", "» my bookmarks", "» my first steps");
	document.getElementById('navi_caption').innerHTML = "<b>"+strings[item]+"</b>";
}

function navi_caption_out()
{
	document.getElementById('navi_caption').innerHTML = "» choose your page";
}

function close_me(field)
{
	var element = document.getElementById('box');
	element.style.margin = '0px';
	element.style.padding = '0px';
	element.style.border = '0px';
	element.style.height = '0px';
	element.style.visibilty = 'false';
	element.innerHTML = "";
	
}

//-------------------------------------------------------------------------------------
//Form-input-management
function check_pass()
{
	var pass1 = document.getElementById('in_pass1').value;
	var pass2 = document.getElementById('in_pass2').value;
		
	if (pass1 == pass2)
	{
		document.getElementById('check_pass').innerHTML = "<span style='color:#7CD400'>Passwords match</span>";
		//document.getElementById('form_pass').style.borderLeftColor = "#7CD400";
	}
	else
	{
		document.getElementById('check_pass').innerHTML = "<span style='color:#CC0000'>Passwords doesn't match</span>";
		//document.getElementById('form_pass').style.borderLeftColor = "#CC0000";
	}
}

function check_length(min_length, read_div, out_div, border_name, string)
{
	var checked_text = document.getElementById(read_div).value;
	
	if (checked_text.length >= min_length && checked_text.indexOf(' ') == -1)
	{
		document.getElementById(out_div).innerHTML = "<span style='color:#7CD400'>Valid " + string + "</span>";
		//document.getElementById(border_name).style.borderLeftColor = "#7CD400";
	}
	else
	{
		document.getElementById(out_div).innerHTML = "<span style='color:#CC0000'>Invalid " + string + "</span>";
		//document.getElementById(border_name).style.borderLeftColor = "#CC0000";
	}
	
	if (string == "password")
		document.getElementById('in_pass2').value = ''
	
}

//-------------------------------------------------------------------------------------
//AJAX-FUNCTIONS!!!

//arg_for_get - this gives the arguments that are later in the request url (username, ...)
//in_id - the value that will be checked
//e.g. -> ajax.check.php?check="arg_for_get"&value="in_id"
function ajax_check(arg_for_get, in_id, out_id)
{
	var input = document.getElementById(in_id).value;
	
	if (input == "")
		document.getElementById(out_id).innerHTML = "<span style='color:#CC0000'>No text inserted.</span>";
	else if (input.length < 3)
		document.getElementById(out_id).innerHTML = "<span style='color:#CC0000'>Invalid " + arg_for_get + ".</span>";
	else
	{
		var script_url = "php/ajax/ajax.check_form.php";
		var send_url = script_url + "?check=" + arg_for_get + "&value=" + input;
		do_http_get_request("text", send_url, out_id);
	}
	
	
	
	
}
//-------------------------------------------------------------------------------------
//MyFF FUNCTIONS!!!

function home_box_over(box_id, box_inside_id)
{
	document.getElementById(box_id).style.marginTop = '203px';
	document.getElementById(box_inside_id).style.height = '85px';	
}

function home_box_out(box_id, box_inside_id)
{
	document.getElementById(box_id).style.marginTop = '253px';
	document.getElementById(box_inside_id).style.height = '35px';	
}


//-------------------------------------------------------------------------------------
//NOT T.G.P. (C) FUNCTIONS!!!

function textbox_insert_tag(aTag, eTag) {
  var input = document.forms['formular'].elements['content'];
  //var input = document.getElementById['write_article_box'];
  input.focus();
  /* für Internet Explorer */
  if(typeof document.selection != 'undefined') {
    /* Einfügen des Formatierungscodes */
    var range = document.selection.createRange();
    var insText = range.text;
    range.text = aTag + insText + eTag;
    /* Anpassen der Cursorposition */
    range = document.selection.createRange();
    if (insText.length == 0) {
      range.move('character', -eTag.length);
    } else {
      range.moveStart('character', aTag.length + insText.length + eTag.length);      
    }
    range.select();
  }
  /* für neuere auf Gecko basierende Browser */
  else if(typeof input.selectionStart != 'undefined')
  {
    /* Einfügen des Formatierungscodes */
    var start = input.selectionStart;
    var end = input.selectionEnd;
    var insText = input.value.substring(start, end);
    input.value = input.value.substr(0, start) + aTag + insText + eTag + input.value.substr(end);
    /* Anpassen der Cursorposition */
    var pos;
    if (insText.length == 0) {
      pos = start + aTag.length;
    } else {
      pos = start + aTag.length + insText.length + eTag.length;
    }
    input.selectionStart = pos;
    input.selectionEnd = pos;
  }
  /* für die übrigen Browser */
  else
  {
    /* Abfrage der Einfügeposition */
    var pos;
    var re = new RegExp('^[0-9]{0,3}$');
    while(!re.test(pos)) {
      pos = prompt("Einfügen an Position (0.." + input.value.length + "):", "0");
    }
    if(pos > input.value.length) {
      pos = input.value.length;
    }
    /* Einfügen des Formatierungscodes */
    var insText = prompt("Bitte geben Sie den zu formatierenden Text ein:");
    input.value = input.value.substr(0, pos) + aTag + insText + eTag + input.value.substr(pos);
  }
}
