function loadcities( country, divnum, city )
{
	htmldata = "<img src=\"images/ajax-loader.gif\">";
	$( '#citiesdiv' + divnum ).html(htmldata);
	$.get( 'index.php?module=content&action=getcities&id=' + country + '&city=' + city , function(data) {
		last_options = data;
		last_country = country;
		htmldata = "<select name=\"cities[]\">" + data + "</select>";
		$( '#citiesdiv' + divnum ).html(htmldata);

	});
}
function countChildElements(parent, child)
{
	var parent = document.getElementById(parent);
	var childCount = parent.getElementsByTagName(child).length;
	return childCount;
}
function addpoint(  )
{
	c_data = document.getElementById( 'routes' ).innerHTML;

	numroutes = countChildElements('routes', 'div')/2 + 1;

	var newdiv = document.createElement('div');
	c_div = document.getElementById('routes').appendChild(newdiv);
	c_div.setAttribute('id', 'route' + numroutes);
	c_div.setAttribute('class', 'route_row');
	div_inner = "<p class=\"sort\">Sort</p>";
	div_inner = div_inner + "<span>Точка " + numroutes + "</span>" ;
	div_inner = div_inner + "<select id=\"country" + numroutes + "\" name=\"country[" + numroutes + "]\" onChange=\"loadcities( this.value, " + numroutes + " )\">";
	div_inner = div_inner + countries_options;	
	div_inner = div_inner + "</select>";
	div_inner = div_inner + "<div id=\"citiesdiv" + numroutes + "\"  class=\"citiesdiv\">";
	if( last_options != "" )
		div_inner = div_inner + "<select name=\"cities[" + numroutes + "]\">" + last_options + "</select>";
	div_inner = div_inner + "<a href=\"javascript:delete_point( " + numroutes + " );\" class=\"redremark\">удалить</a>";		
	div_inner = div_inner + "</div>";


    c_div.innerHTML = div_inner;
    
    if( last_country != 0 )
    	document.getElementById('country' + numroutes ).value = last_country;
    
}

function delete_point(id)
{
	var d = document.getElementById('routes');
	var olddiv = document.getElementById('route' + id);
	d.removeChild(olddiv);
}

function addmember(  )
{
	c_data = document.getElementById( 'members' ).innerHTML;

	nummembers = countChildElements('members', 'div') + 1;

	var newdiv = document.createElement('div');
	c_div = document.getElementById('members').appendChild(newdiv);
	c_div.setAttribute('id', 'member' + nummembers);
	c_div.setAttribute('class', 'member_row');

	div_inner = "<select id=\"member" + nummembers + "\" name=\"members[" + nummembers + "]\"><option value=\"0\">- Выберите пользователя</option>";
	div_inner = div_inner + members_options;	
	div_inner = div_inner + "</select>";

	div_inner = div_inner + "<a href=\"javascript:delete_member( " + nummembers + " );\" class=\"redremark\">удалить</a>";		


    c_div.innerHTML = div_inner;
   
	
}
function delete_member(id)
{
	var d = document.getElementById('members');
	var olddiv = document.getElementById('member' + id);
	d.removeChild(olddiv);
}

function empty_comment( id )
{
	if( document.getElementById( id ).value=="Добавить комментарий" )
	{
		document.getElementById( id ).value = "";
		document.getElementById( id ).style.color = "#000";
	}

}
