function countryChange (country)
{
	switch (parseInt (country))
	{
		case 1:
			document.getElementById ('user_zip_code').style.display = 'table-row';
			document.getElementById ('user_when_emigration').style.display = 'table-row';
			document.getElementById ('user_how_long_are').style.display = 'none';
			document.getElementById ('user_how_long_stay').style.display = 'none';
		break;

		case 2:
		case 3:
			document.getElementById ('user_zip_code').style.display = 'none';
			document.getElementById ('user_when_emigration').style.display = 'none';
			document.getElementById ('user_how_long_are').style.display = 'table-row';
			document.getElementById ('user_how_long_stay').style.display = 'table-row';
		break;

		default:
			document.getElementById ('user_zip_code').style.display = 'none';
			document.getElementById ('user_when_emigration').style.display = 'none';
			document.getElementById ('user_how_long_are').style.display = 'none';
			document.getElementById ('user_how_long_stay').style.display = 'none';
		break;
	}
}

function showDiv (show_id)
{
	tmp = document.getElementsByTagName ('div');
	re = /tab_(.+)/;
	for (i=0; i<tmp.length; i++)
	{
		if (tmp[i].id.indexOf ('tab_') == 0)
		{
			sub_id = tmp[i].id.match (re);
			if (show_id == sub_id[1])
				tmp[i].style.display = 'block';
			else
				tmp[i].style.display = 'none';
		}
	}
}

function changeFoto (uid, finx, ftype)
{
	document.getElementById ('foto_preview').src = "foto.php?m=user&id="+uid+"&f="+finx+"&t="+ftype+"&s=n";
}

function createRequestObject()
{
	if (window.XMLHttpRequest)
		return new XMLHttpRequest();
	else if (window.ActiveXObject)
		return new ActiveXObject("Microsoft.XMLHTTP");
}



/*function loadContent (id, url)
{
var http = createRequestObject();
http.open('get', url, true);
tag_id = id;

document.getElementById (id).innerHTML = "wczytywanie";

http.onreadystatechange = function () {
if (http.readyState == 4)
{
document.getElementById (id).innerHTML = http.responseText;
}
}
http.send(null);
}*/


function skipChildNodes (element, tag_name)
{
	if (!element)	return null;

	for (i=0; i<element.childNodes.length; i++)
	{
		if (element.childNodes[i].nodeType == 1 && element.childNodes[i].tagName.toLowerCase() == tag_name.toLowerCase())
			return element.childNodes[i];
	}
	return null;
}

function ajaxChangeText (html)
{
	if (document.getElementById('ajax_info'))
		document.getElementById('ajax_info').innerHTML = html;
	else
	{
		main_div = document.getElementById ('tekst');
		element = skipChildNodes (main_div, 'table');
		element = skipChildNodes (element, 'tbody');
		element = skipChildNodes (element, 'tr');
		element = skipChildNodes (element, 'td');
		if (!element)	element = main_div;

		var ajax_div = document.createElement ('div');
		ajax_div.id = 'ajax_info';
		element.insertBefore (ajax_div, element.firstChild);
		ajax_div.innerHTML = html;
	}
}

function sendSmile (uid, wait_msg)
{
	var http = createRequestObject();
	http.open('get', 'index.php?m=msg&s=sendsmile&uid='+uid, true);
	ajaxChangeText ('<div class="info">'+wait_msg+'</div>');
	http.onreadystatechange = function () {	if (http.readyState == 4) ajaxChangeText (http.responseText); }
	http.send (null);
}

function sendKiss (uid, wait_msg)
{
	var http = createRequestObject();
	http.open('get', 'index.php?m=msg&s=sendkiss&uid='+uid, true);
	ajaxChangeText ('<div class="info">'+wait_msg+'</div>');
	http.onreadystatechange = function () {	if (http.readyState == 4) ajaxChangeText (http.responseText); }
	http.send (null);
}

function addToAddressBook (uid, wait_msg)
{
	var http = createRequestObject();
	http.open('get', 'index.php?m=msg&s=addtoab&uid='+uid, true);
	ajaxChangeText ('<div class="info">'+wait_msg+'</div>');
	http.onreadystatechange = function () {	if (http.readyState == 4) ajaxChangeText (http.responseText); }
	http.send (null);
}

function addToBlackList (uid, wait_msg)
{
	var http = createRequestObject();
	http.open('get', 'index.php?m=msg&s=addtobl&uid='+uid, true);
	ajaxChangeText ('<div class="info">'+wait_msg+'</div>');
	http.onreadystatechange = function () {	if (http.readyState == 4) ajaxChangeText (http.responseText); }
	http.send (null);
}

function selectContact ()
{
	my_win = window.open ('index.php?m=msg&s=popcontact', 'ContactBrowser', 'menubar=no, toolbar=no, location=no, scrollbars=yes, resizable=yes, status=no');
	my_win.focus ();
}

function putContact (login)
{
	if (window.opener)
	{
		window.opener.document.forms['sendmsg'].elements['login'].value = login;
		window.close ();
	}
	else
		alert ('No parent window');
}


