function pics(img,ref)
{
	document.getElementById(img).src = ref;
}

function openwin(img,w,h,title)
{
 var hWnd;
 if(hWnd!=null) hWnd.close();
 hWnd=window.open(img,"","toolbar=no,location=no,directories=no,resizable=yes,scrollbars=yes,left=100,top=100,width="+w+",height="+h);
 hWnd.document.open();
 hWnd.document.write("<html><head><title>"+title+"</title></head><body topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>");
 hWnd.document.write("<img src=\""+img+"\" width="+w+" height="+h+">");
 hWnd.document.write("</body></html>");
 hWnd.document.close();
}

function IEPngFix(pngimg, gifimg, width, height)
{
	var code = '<img src="'+ gifimg +'" width="' + width + '" height="' + height + '" border="0" style="background:url('+pngimg+') no-repeat 0px 0px;"/>';
	if( navigator.userAgent.indexOf("Opera") > 1 ) document.write(code);
	else
		if( navigator.userAgent.indexOf("MSIE 6") > 1 ) document.write('<img src="'+gifimg+'" width="' + width + '" height="' + height + '" border="0" style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader (src=' + pngimg + ' , sizingMethod=crop );"/>');
		else
			if(navigator.userAgent.indexOf("MSIE 5") != -1) document.write(code);
			else document.write(code);
}


function switch_class(cn, obj)
{
	obj.className = cn;
}


function addFileInput(cont_id, add_num)
{
	if (add_num == null) add_num = true;
	$cont = $('#' + cont_id);
	name = 	$('input:first', $cont).attr('name');
	$input = $('input:last', $cont);
	$new_input = $input.clone(true);
	new_name = (add_num)?(name + ($('input', $cont).length + 1)):name;
	$new_input.attr('name', new_name);
	$new_input.val('');
	$new_input.insertAfter($input);
	return false;
}



function init_selects()
{
	$('#city_select').change(function(){
		$.ajax({
			url: "/inc/refresh_numbers_form.php?ajax_process=1&city_id="+$(this).val(),
			cache: false,
			success: update_numbers_form
		});
	});

	$('#object_select').change(function(){
		$.ajax({
			url: "/inc/refresh_numbers_form.php?ajax_process=1&object_id="+$(this).val(),
			cache: false,
			success: update_numbers_form
		});
	});

}


function update_numbers_form(data) {
	$("#numbers_form_block").html(data);
	init_selects();
}

$(document).ready(function()
{
	init_selects();

	$('#weather_cities').change(
		function(){
			num = $(this).val();
			$.ajax({
				url: "/inc/read_weather.php?weathercity_id="+num,
				cache: false,
				success: refresh_weather_block
			});
			return false;
		}
	);	

});

function refresh_weather_block(data)
{
	$("#w_block").html(data);
}

