function AreaSelClick( aoEvent )
{
	if( aoEvent == null )
		aoEvent = event;
	if( aoEvent != null )
	{
		var loSrc = aoEvent.srcElement;
		if( loSrc == null )
			loSrc = aoEvent.target;
			
		if( loSrc != null && loSrc.tagName.toLowerCase( ) === "select" )
		{
			var loAreaSearch = CHUFindParentByTagAndClass( loSrc, "div", "areaSearch" );
			if( loAreaSearch != null )
				$( ".areaSearchWarn", loAreaSearch ).hide( );
		}
	}

	return true;
}

function AreaList( aoEvent )
{
	if( aoEvent == null )
		aoEvent = event;
	if( aoEvent != null )
	{
		var loSrc = aoEvent.srcElement;
		if( loSrc == null )
			loSrc = aoEvent.target;

		if( loSrc != null && loSrc.tagName.toLowerCase( ) === "select" && loSrc.value != "0" )
		{
			var loCurrListItem = loSrc.parentNode;
			if( loCurrListItem != null && loCurrListItem.tagName.toLowerCase( ) === "li" )
			{
				var loList = loCurrListItem.parentNode;
				if( loList != null && loList.tagName.toLowerCase( ) === "ul" )
				{
					var loDiv = loList.parentNode;
					if( loDiv != null && loDiv.tagName.toLowerCase( ) === "div" )
					{
						var loSpans = $( "span", loDiv );
						if( loSpans.length > 5 )
						{
							var lsUrl = loSpans.eq( 0 ).text( );
							var lsIOF = loSpans.eq( 2 ).text( );
							var lsScM = loSpans.eq( 3 ).text( );
							var lsScId = loSpans.eq( 4 ).text( );
							var lsPrefixes = loSpans.eq( 5 ).text( );
							var lsPreSel = loSpans.eq( 6 ).text( );
							if( lsUrl != null && lsUrl !== "" && lsScM != null && lsScM !== ""  &&
								lsScId != null && lsScId !== "" )
							{
								var loSel;
								var loListItems = $( "li", loList );
								var liIdx, liFnd = -1, liDiv, loListDiv;
								for( liIdx = 0; liIdx < loListItems.length; liIdx++ )
								{
									if( liFnd >= 0 )
									{
										loSel = $( "select", loListItems[liIdx] );
										if( loSel.length > 0 )
										{
											while( loSel[0].options.length > 0 )
												loSel[0].remove( 0 );
											loSel[0].value = "";
										}
										loSel = $( "div", loListItems[liIdx] );
										for( liDiv = 0; liDiv < loSel.length; liDiv++ )
											if( loSel[liDiv].id.indexOf( "slc" ) >= 0 )
												$( loSel[liDiv] ).html( "" );
									}
									if( loListItems[liIdx] === loCurrListItem )
										liFnd = liIdx;
								}

								if( liFnd >= 0 && liFnd < loListItems.length - 1 )
								{
									var loCtrlToUpdate = null;
									var loNextListItem = loListItems[liFnd + 1];
									loSel = $( "select", loNextListItem );
									if( loSel[0] == null )
									{
										loSel = $( "div", loNextListItem );
										for( liDiv = 0; liDiv < loSel.length && loCtrlToUpdate == null; liDiv++ )
											if( loSel[liDiv].id.indexOf( "slc" ) >= 0 )
											{
												loCtrlToUpdate = loSel[liDiv];
												lsScM = "2";
											}
									}
									else
									{
										loCtrlToUpdate = loSel[0];
										lsScM = "1";
									}

									var loImg = $( "img", loNextListItem );
									if( loCtrlToUpdate != null && loImg[0] != null )
									{
										loImg.show( );
										$.ajax( {
											cache: false,
											complete: AreaListFinal,
											data: "iof=" + lsIOF + "&pid=" + loSrc.value + "&scm=" + lsScM +
												"&tgtid=" + loCtrlToUpdate.id + "&imgid=" + loImg[0].id +
												"&scid=" + lsScId + "&pfx=" + lsPrefixes + "&prs=" + lsPreSel,
											error: AreaListErr,
											success: AreaListOk,
											url: lsUrl
											} );
									}
								}
							}
						}
					}
				}
			}
		}

		aoEvent.returnValue = false;
	}

	return false;
}

function AreaListOk( asData, asStatus )
{
	var liIdx1 = asData.indexOf( "/" );
	if( liIdx1 > 0 )
	{
		var lsSelId = asData.substring( 0, liIdx1 );
		var liIdx2 = asData.indexOf( "/", liIdx1 + 1 );
		if( liIdx2 > 0 )
		{
			var lsImgId = asData.substring( liIdx1 + 1, liIdx2 );
			var liIdx3 = asData.indexOf( "/", liIdx2 + 1 );
			if( liIdx3 > 0 )
			{
				var lsResType = asData.substr( liIdx2 + 1, 1 );
				if( lsResType === "H" )
					$( "#" + lsSelId ).html( asData.substring( liIdx3 + 1 ) );

				else if( lsResType === "J" )
				{
					var loColl, loSelect = $( "#" + lsSelId );
					if( loSelect[0] != null )
					{
						loColl = eval( asData.substring( liIdx3 + 1 ) );
						if( typeof loColl === "object" && loColl.length > 0 )
						{
							var liOpt;
							var loOption;
							for( liOpt = 0; liOpt < loColl.length; liOpt++ )
							{
								loOption = document.createElement( "option" );
								loOption.text = loColl[liOpt].name;
								loOption.value = loColl[liOpt].value;
								try
								{
									loSelect[0].add( loOption, null ); // standards compliant
								}
								catch (loEx)
								{
									loSelect[0].options.add( loOption ); // IE only
								}
							}
						}
					}
				}
			}

			$( "#" + lsImgId ).hide( );
		}
	}
}

function AreaListErr( aoReq, asErr, aoEx )
{
}

function AreaListFinal( aoReq, asType )
{
}

function AreaLink( asSelectId, asDlgId, asDlgEPContId, aoEvent )
{
	if( aoEvent == null )
		aoEvent = event;
	if( aoEvent != null )
	{
		var loSrc = aoEvent.srcElement;
		if( loSrc == null )
			loSrc = aoEvent.target;

		if( loSrc != null )
		{
			var loSel = document.getElementById( asSelectId );
			if( loSel != null )
			{
				var loAreaSearchContLink = CHUFindParentByTagAndClass( loSrc, "div", "areaSearchContLink" );
				if( loAreaSearchContLink != null )
				{
					if( loSel.value == null || loSel.value === "" || loSel.value === "0" )
						$( ".areaSearchWarn", loAreaSearchContLink ).show( );
					else
					{
						$( ".areaSearchWarn", loAreaSearchContLink ).hide( );
						var lsTgtUrl = location.protocol + "//" + location.host +
							$( "span", loAreaSearchContLink ).text( ) + loSel.value;
						if( asDlgId == null || asDlgEPContId == null )
							window.location = lsTgtUrl;
						else
						{
							$("#" + asDlgId).dialog({
								bgiframe: true,
								width: 780,
								height: 510,
								closeOnEscape: false,
								modal: true
							});
							$( "#" + asDlgId + " iframe[name=" + asDlgEPContId + "]" ).attr( "src", lsTgtUrl );
							//popup( lsTgtUrl );
						}
					}
				}
			}
		}

		aoEvent.returnValue = false;
	}

	return false;
}

function AreaLBCloseMap( asDlgId, asDlgEPContId )
{
	$( "#" + asDlgId + " iframe[name=" + asDlgEPContId + "]" ).attr( "src", "about:blank" );
	//$( "#" + asDlgId ).dialog( "close" );
	$( "#" + asDlgId ).dialog( "destroy" );
}

function AreaLBPrintMap( asDlgEPContId )
{
	top[asDlgEPContId].window.focus( );
	top[asDlgEPContId].window.print( );
}

//function popup(file)
//{
//	if(typeof file=='undefined')
//		file='about:blank';
//	var screenWidth = screen.availWidth||screen.width||1024;
//	var screenHeight = screen.availHeight||screen.height||768;
//	var	popupWidth=770;
//	var	popupHeight=500;
//	var	popupLeft=(screenWidth-popupWidth)/2;
//	var	popupTop=(screenHeight-popupHeight)/2-20;

//	if(typeof popup.ref=='undefined' || !popup.ref || popup.ref.closed)
//	{
//		popup.ref=window.open(file,'',"width="+popupWidth+",height="+popupHeight+",top="+popupTop+",left="+popupLeft+
//			",scrollbars=yes,resizable=yes,status=no,personalbar=no,toolbar=no,location=no,menubar=no,directories=no");
//	}

//	if(typeof popup.ref=='undefined' || !popup.ref || popup.ref.closed)
//	{
////		link.target = '_blank';
//		return true;
//	}
//	if( popup.ref.location.href != 'about:blank'&& popup.ref.location.href != file )
//	{
//		popup.ref.document.body.style.block = 'none';
//		popup.ref.location.replace(file);
//	}
//	popup.ref.focus();
//}

//if( typeof $ != 'undefined' )
//{
//	$(document).ready(function() {
//		$('#container .groupage.geoarea-search .grpllist .grplli a').click( function(){
//			popup( this.href );
//			return false;
//		});
//		$('#container .groupage.geoarea-search .grpslbl').text('');
//	});
//}
