//AJAX Functions
var SiteURL='http://www.wifi-spots.net/';


function createXMLHttp() 
{

    if (typeof XMLHttpRequest != "undefined") 
	{
        return new XMLHttpRequest();
    } 
	else if (window.ActiveXObject) 
	{
      	var aVersions = [ "MSXML2.XMLHttp.5.0",
        "MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0",
       	"MSXML2.XMLHttp","Microsoft.XMLHttp"
      	];

      	for (var i = 0; i < aVersions.length; i++) 
		{
        	try 
			{
            	var oXmlHttp = new ActiveXObject(aVersions[i]);
           		return oXmlHttp;
        	} 
			catch (oError) 
			{
            	//Do nothing
        	}
      	}
   	}
    throw new Error("XMLHttp object could be created.");
}



function sendGetRequest(url, func, working_gif,working_id) 
{ 
    var oXmlHttp = createXMLHttp();
    oXmlHttp.open("get", url, true);

    oXmlHttp.onreadystatechange = function () 
	{     
        if (oXmlHttp.readyState == 4)
		{
			if (working_id!='') Working(working_id,working_gif,1);
            if (oXmlHttp.status == 200) {
			       	var result = JSON.parse(oXmlHttp.responseText);
			       	  //alert(result);
                eval(func + "(result);");
            } else {
                alert("An error occurred: "+ oXmlHttp.statusText);
            }
        }
		else  
		{
			if (working_id!='') eval("Working" + "(working_id,working_gif,0);");		
		}
    };
    oXmlHttp.send(null);
}


function ClearSearchField(par,value)
{
	if(par==1)
	{
		$('search_wifi_spots').value='';
	}
	else 
	{
		if($('search_wifi_spots').value=='')
		{
			$('search_wifi_spots').value=value;	
		}
	}
}




function GoToLink(text, li) 
{
	var tt=text.value;
	//ArticleInsert(li.id,'0',tt);
	//window.location.href=SiteURL.''
	sendGetRequest(SiteURL+'server/redirect_to_url.php?id=' + li.id, 'displayGoToLink','','');
}

function displayGoToLink(aLink)
{
	if (aLink.length>0)
	{
		some = aLink[0];
		//alert(some.links);
		window.location.href=some.links;	
	}
}

function getComplex(id,par)
{ 

	sendGetRequest(SiteURL+'server/get_complexes.php?id=' + id+'&par='+par, 'displayComplex','','');
}

function getComplex2(id,par)
{ 
	sendGetRequest(SiteURL+'server/get_complexes.php?id=' + id+'&par='+par, 'displayComplex2','','');
}

function getR_Cities(id)
{ 

	sendGetRequest(SiteURL+'server/get_r_cities.php?id=' + id, 'displayR_Cities','','');
}
function getCities(id)
{ 

	sendGetRequest(SiteURL+'server/get_cities.php?id=' + id, 'displayCities','','');
}

function getMapItems(map,id,type_accessid,type_locationid,cityid,complexid,keyword,limitt,rand)
{ 

	sendGetRequest(SiteURL+'server/get_map_items.php?map='+map+'&id='+id+'&type_accessid='+type_accessid+'&type_locationid='+type_locationid+'&cityid='+cityid+'&complexid='+complexid+'&keyword='+keyword+'&limitt='+limitt+'&rand='+rand, 'displayMapItems','','');
}

function getMapItems_ON_LIST(map,id,type_accessid,type_locationid,cityid,complexid,keyword,limitt,rand)
{ 

	sendGetRequest(SiteURL+'server/get_map_items_on_list.php?map='+map+'&id='+id+'&type_accessid='+type_accessid+'&type_locationid='+type_locationid+'&cityid='+cityid+'&complexid='+complexid+'&keyword='+keyword+'&limitt='+limitt+'&rand='+rand, 'displayMapItems_ON_LIST','','');
}

function showThePrint(num)
{
	if ($('print_idd'))
	{
		$('print_idd').style.display='block';
		$('all_points_for_print').value=num;
	}
}


function printThePrint(par)
{
	if (par==1)
	{
		if ($('all_points_for_print'))
		{
			var rows = $('all_points_for_print').value;
			var sm='';
			for (var i=0;i<rows;i++)
			{
				if ( $('print_'+i).checked)
				{
					if (sm!='') sm+=',';
					sm+=$('print_'+i).value;
				}
			}
			if (sm!='')
				window.open(SiteURL+'print_spots.php?ids='+sm, 'Print', 'width=690,height=800,scrollbars=yes');
			else alert("Моля, изберете Wifi точки за принтиране!");
		}
	}
	else if (par==2)
	{
		window.open(SiteURL+'print_spots.php?ids='+$('all_points_for_print').value, 'Print', 'width=690,height=800,scrollbars=yes');	
	}
}

function showReminderPrint()
{
	$('img_print').style.display='block';	
}

function SaveComment(param,lg)
{
	var name = $('comm_name').value;
	var email = $('comm_email').value;
	var comment = $('comm_comment').value;
	var spotsid= $('spotsid').value;
	var code='';//$('comm_code').value;
	var recaptcha_challenge_field = $('recaptcha_challenge_field').value;
	var recaptcha_response_field = $('recaptcha_response_field').value;
	var vote=$('user_vote').value;
	
	sendGetRequest(SiteURL+'server/set_comment.php?name='+name+'&email='+email+'&spotsid='+spotsid+'&comment='+comment+'&param='+param+'&code='+code+'&vote='+vote+'&recaptcha_challenge_field='+recaptcha_challenge_field+'&recaptcha_response_field='+recaptcha_response_field, 'showComments','','');
	
	
}

function showComments(aPicComments)
{
	var res='';
	if (aPicComments.length>0)	
	{
		
		some=aPicComments[0];
		if (some.name='')
		{
			res+='<div class="list_comments"><div class="titl">'+some.WIFISPOTS_COMMENTS+'</div>';
			for (var i=0;i<aPicComments.length;i++)
			{
				some=aPicComments[i];
				res+='	<div class="comment1">';
				res+='		<table border="0" cellspacing="12" cellpadding="0">';
				res+='			<tr>';
				res+='				<td width="18"><img src="'+some.SiteURL+'images/comment.gif" /></td>';
				res+='				<td><span class="dark_blue">'+some.name+'</span><br>';
				res+='					<span class="date">'+some.WIFISPOTS_PUB+some.my_date+some.WIFISPOTS_PUB_IN+some.my_hour+'</span></td>';
				res+='			</tr>';
				res+='			<tr><td colspan="2">'+some.comment+'</td></tr>';
				res+='		</table>';
				res+='	</div>';
			}
			res+='</div>';
		}
		some=aPicComments[0];
		if (some.err==0) 
		{
			$('comm_name').value='';
			$('comm_email').value='';
			$('comm_comment').value='';	
			//$('comm_code').value='';
			$('user_vote').value=0;
		}
		$('err_div').innerHTML=some.mes;
	}
	
	$('comments_div').innerHTML=res;
	
}


function NULLIDS()
{
	if ($('id'))
		$('id').value='';;

	if ($('type_accessid'))
		$('type_accessid').value='';
	
	if ($('type_locationid'))
		$('type_locationid').value='';
	
	if ($('cityid'))
		$('cityid').value='';
	
	if ($('complexid'))
		$('complexid').value='';
	
}

function displayMapItems(aMapItems)
{
	
	if (aMapItems.length>0)
	{
		some = aMapItems[0];
		if (some.map==1) {ShowEarchMap(aMapItems);}
		else showGoogleMap(aMapItems);
	}	
}

function displayMapItems_ON_LIST(aMapItems)
{
	var res='';
	if (aMapItems.length>0)
	{
		some = aMapItems[0];
		if (some.res==1)
		{
			for (var i=0;i<aMapItems.length;i++)
			{
				some = aMapItems[i];	
				res+=some.rrr;
			}
			
			if ( $('browse_on_listing') )
				$('browse_on_listing').innerHTML=res;
			
			some = aMapItems[0];
			if ($('all_points_for_print'))
				showThePrint(some.total);
			if ($('print_idd'))
				$('print_idd').style.display='block';
		}
		else 
		{
			$('no_res_div').innerHTML=	some.TAG_NO_RESULTS;
		}
		
		
	}	
	
	
}

function hideBrowsing()
{
	$('a_browse_spots').style.display='none';	
}

function displayMapItems_ON_LIST_old(aMapItems)
{
	var res='';
	if (aMapItems.length>0)
	{
		some = aMapItems[0];
		if (some.res==1)
		{
			res+='<div class="latest_spots" style="padding-top:10px">';
			for (var i=0;i<aMapItems.length;i++)
			{
				some = aMapItems[i];
				if (some.type_accessid==1) var access=SiteURL+'images/blue_spot.gif';
				else var access=SiteURL+'images/gray_spot.gif';
						
				res+='<a href="'+some.linkss+'" ><img src="'+access+'" border="0" alt="'+some.type_access+'" title="'+some.type_access+'"/> &nbsp; <span class="light_blue">'+some.name+'</span> '+some.provider+' <span class="dark_blue">'+some.rating+'</span></a>';
				
			}
			res+='</div>';
			
			if ( $('browse_on_listing') )
				$('browse_on_listing').innerHTML=res;
		}
		else 
		{
			$('no_res_div').innerHTML=	some.TAG_NO_RESULTS;
		}
	}	
	
	
}


function DoTypeAccess()
{
	if ($('list_sel').value==1)
	{
		$('first_listing').style.display='none';
		$('browse_on_listing').style.display='block';
		if ($('id'))
		var id= $('id').value;
		else var id=0;
		
		if ($('type_accessid'))
			var type_accessid= $('type_accessid').value;
		else var type_accessid=0;
		
		if ($('type_locationid'))
			var type_locationid= $('type_locationid').value;
		else var type_locationid='';
		
		if ($('cityid'))
			var cityid= $('cityid').value;
		else var cityid='';
		
		if ($('complexid'))
			var complexid= $('complexid').value;
		else var complexid='';
		
		 if($('use_map'))
			var par = $('use_map').value;
			
		if ($('keyw'))
			var keyw= $('keyw').value;
		else var keyw='';
		
		if ($('limitt'))
			var limitt= $('limitt').value;
		else var limitt='';
		
		if ($('rand'))
			var rand= $('rand').value;
		else var rand='';
			
		 getMapItems_ON_LIST(par,id,type_accessid,type_locationid,cityid,complexid,keyw,limitt,rand);
	}
	else if ($('map_sel').value==1)
	{
		$('all_maps').style.display='block';
		if($('use_map'))
			var sss = $('use_map').value;
		else var sss=2;
		SetMap(sss);
		
	}
	else 
	{
		
		ShowTheMap();	
	}
}

function ShowTheMap()
{
	$('all_maps').style.display='block';
	if($('use_map'))
		var sss = $('use_map').value;
	else var sss=2;
	SetMap(sss);
	
	
	if ($('id'))
		var id= $('id').value;
	else var id=0;
	
	if ($('type_accessid'))
		var type_accessid= $('type_accessid').value;
	else var type_accessid=0;
	
	if ($('type_locationid'))
		var type_locationid= $('type_locationid').value;
	else var type_locationid='';
	
	if ($('cityid'))
		var cityid= $('cityid').value;
	else var cityid='';
	
	if ($('complexid'))
		var complexid= $('complexid').value;
	else var complexid='';
	
	 if($('use_map'))
	 	var par = $('use_map').value;
		
	if ($('keyw'))
		var keyw= $('keyw').value;
	else var keyw='';
	
	if ($('limitt'))
		var limitt= $('limitt').value;
	else var limitt='';
		
	if ($('rand'))
		var rand= $('rand').value;
	else var rand='';
	
	 getMapItems_ON_LIST(par,id,type_accessid,type_locationid,cityid,complexid,keyw,limitt,rand);
}

function SwitchListingMap(par)
{
	$('list_a').className='';
	$('map_a').className='';
	$('list_map_a').className='';
	
	$('list_sel').value='';
	$('map_sel').value='';
	$('list_map_sel').value='';
	
	if ($('print_idd'))
	{
		$('print_idd').style.display='none';
	}
	
	if (par==1)
	{
		$('a_spots').style.display='block';
		$('all_maps').style.display='none';	
		$('a_browse_spots').style.display='none';
		$('browse_on_listing').style.display='none';
		$('list_a').className='tab_active';
		$('list_sel').value='1';
		$('print_idd').style.display='block';
		
	}
	if (par==2)
	{
		if ($('a_spots'))
			$('a_spots').style.display='none';
		if ($('all_maps'))
			$('all_maps').style.display='block';
		if ($('a_browse_spots'))
			$('a_browse_spots').style.display='none';
		if ($('browse_on_listing'))
			$('browse_on_listing').style.display='none';
		if($('use_map'))
	 		var sss = $('use_map').value;
		else var sss=2;
		if (sss=='') sss=2;
		SetMap(sss);
		
		$('map_a').className='tab_active';
		$('map_sel').value='1';
	}
	if (par==3)
	{
		$('a_spots').style.display='none';
		$('all_maps').style.display='none';
		$('a_browse_spots').style.display='block';
		$('browse_on_listing').innerHTML='';
		$('browse_on_listing').style.display='block';
		$('list_map_a').className='tab_active';
		$('list_map_sel').value='1';
		$('first_listing').innerHTML='';
	}
}

function toggle_classes(par,id)
{
	
 	if (par==1)
	{
		document.getElementById(id+'_a').className='tab_active';
	}
	else 
	{	
		if (document.getElementById(id+'_sel').value=='')
			document.getElementById(id+'_a').className='';
		//else 
			//document.getElementById(id+'_a').className='featured_current';
	}
} 

function getMapItems_print(map,ids)
{ 

	sendGetRequest(SiteURL+'server/get_map_items_print.php?map='+map+'&ids='+ids, 'showMapItems_print','','');
}

function showMapItems_print(aMapItems)
{
	showGoogleMap_print(aMapItems);
	showGoogleMap_on_list_print(aMapItems);
}

function showGoogleMap_on_list_print(aMapItems)
{
	var res='';
	if (aMapItems.length>0)
	{
		for (var i=0; i < aMapItems.length; i++) 
			{
				some = aMapItems[i];
				var letter = String.fromCharCode("A".charCodeAt(0) + i);
				var imm='<img src="http://www.google.com/mapfiles/marker' + letter + '.png" height="20">';
				res+='<div style="width:550px;float:left;margin-top:10px;"><div class="wifi_spot">';
				res+='	<table border="0" cellpadding="0" cellspacing="7" width="535">';
				res+='		<tr>';
				res+='			<td valign="top" width="35"><img src="'+some.access+'" /></td>';
				res+='			<td valign="top" width="405"><span class="bbb">'+some.name+'</span> '+imm+'<br />'+some.address+' </td>';
				res+='			<td align="right" valign="top">';
				res+='				'+some.rating+'<br />	';
				res+='				<div style="margin-top:3px">'+some.type_netid+' '+some.location+'</div>';
				res+='			</td>';
				res+='		</tr>';
				res+='	</table>';
				res+='</div>';
				
				res+='<div class="wefi_spot_info">';
				res+='	<table border="0" cellspacing="0" cellpadding="0" width="535">';
				res+='		<tr>';
				res+='			<td valign="top" width="50%">';
				res+='				'+some.provider+'';
				res+='				'+some.provider_website+'';
				res+='				'+some.SSID+'';
				res+='				'+some.WIFISPOTS_PROVIDER_WIFI_TYPE+' <b>'+some.type_net+'</b><br />';
				res+='				'+some.WIFISPOTS_PROVIDER_ACCESS+' <b>'+some.type_access+'</b>';
				res+='			</td>';
				res+='			<td valign="top">';
				res+='				'+some.description+'';
				res+='			</td>';
				res+='		</tr>';
				res+='	</table>';
				res+='</div></div>';
				
			}
			
		$('listing').innerHTML=res;
	}
}

function showGoogleMap_print(aMapItems)
{
	var data ='';
	//<![CDATA[';
	if (aMapItems.length>0)
	{
		some = aMapItems[0];
		
		if (some.res==1)
		{
			//$('all_maps').style.display='block';

			
			function createMarker(point, index, address) 
			{
			  // Create a lettered icon for this point using our icon class
			  var letter = String.fromCharCode("A".charCodeAt(0) + index);
			  var letteredIcon = new GIcon(baseIcon);
			  letteredIcon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";
	
			  // Set up our GMarkerOptions object
			  markerOptions = { icon:letteredIcon };
			  var marker = new GMarker(point, markerOptions);
	
			  GEvent.addListener(marker, "click", function() {
				marker.openInfoWindowHtml("Marker <b>" + letter +"<br />"+address+ "</b>");
			  });
			  return marker;
			}
				  
				  
			var map = new GMap2(document.getElementById("map"));
			//var start = new GLatLng(65,25);
			map.setCenter(new GLatLng(parseFloat(some.pos1),parseFloat(some.pos2)), 13);
			map.addControl(new GMapTypeControl(1));
			map.addControl(new GLargeMapControl());
			
			map.enableContinuousZoom();
			map.enableDoubleClickZoom();
			map.setMapType(G_NORMAL_MAP) ;
			
			// "tiny" marker icon
			var icon = new GIcon();
			icon.image = SiteURL+"images/home.png";
			icon.shadow = SiteURL+"images/shadow.png";
			icon.iconSize = new GSize(26,26);
			icon.shadowSize = new GSize(28,26);
			icon.iconAnchor = new GPoint(12,26);
			icon.infoWindowAnchor = new GPoint(16,0);
			
			var baseIcon = new GIcon();
			baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
			baseIcon.iconSize = new GSize(20, 34);
			baseIcon.shadowSize = new GSize(37, 34);
			baseIcon.iconAnchor = new GPoint(9, 34);
			baseIcon.infoWindowAnchor = new GPoint(9, 2);
			baseIcon.infoShadowAnchor = new GPoint(18, 25);
			
			for (var i=0; i < aMapItems.length; i++) 
			{
				some = aMapItems[i];
				var point = new GLatLng(parseFloat(some.pos1),parseFloat(some.pos2));
				var markerN = createMarker(point,i, some.address);
				
				map.addOverlay(markerN);
				if (some.range_points!='')
				{
					var el = doTheWifiSpotRange(some.range_points);
					
					var polygon = eval('new GPolygon(['+el+'], "#8ED8F4", 3, 1, "#8ED8F4", 0.5)');
					map.addOverlay(polygon);
				}
				
			}
		}
		else 
		{
			$('all_maps').style.display='none';
			$('no_res_div').innerHTML=	some.TAG_NO_RESULTS;
		}
		
	}
	
	//]]>
}

function ShowHideADvancedSearch()
{
	
	if ($('adv_search').style.display=='none')
	{
		$('adv_search').style.display='block';
		$('search_wifi_spots').value='';
	}
	else 
	{
		$('adv_search').style.display='none';
		$('search_wifi_spots').value='Ivan Shishman';
	}
}

function ShowCompany(id)
{
	if (id==2) $('company_info').style.display='block';
	else $('company_info').style.display='none';
}


function setTypeAccess(val)
{
	if ($('type_accessid'))
		$('type_accessid').value = val;	
}

function setCityid(val)
{
	if ($('cityid'))
		$('cityid').value = val;
	if ($('complexid'))
		$('complexid').value = '';	
}

function setComplexid(val)
{
	if ($('complexid'))
		$('complexid').value = val;	
}

function setTypeLocation(val)
{
	if ($('all_type_locations'))
		var all_num = $('all_type_locations').value;
	else var all_num=0;
	
	var ids=''; 
	
	for(var i=1;i<=all_num;i++)
	{
		if ( $('type_loc_'+i).checked)
			ids+=$('type_loc_'+i).value+'_';
	}
	
	if ( $('type_locationid'))
		$('type_locationid').value = ids;

}


function AdvSearch(lg)
{

	
/*	if (document.forms['search_ff'].search_type_access.length)
	{
		for(r=0;r<document.forms['search_ff'].search_type_access.length;r++)
		{
			if (document.forms['search_ff'].search_type_access[r].checked==true) 
			{
				 var search_type_access = document.forms['search_ff'].search_type_access[r].value;
			}
		}
	}
	else 
	{
		if (document.forms['search_ff'].search_type_access.checked==true) 
			{
				var search_type_access = document.forms['search_ff'].search_type_access.value;
			}
	}*/
		
	
	var search_type_access = $('search_type_access').value;
	// type_locations
	/*
	if ($('search_all_type_locations'))
		var all_num = $('search_all_type_locations').value;
	else var all_num=0;
	
	var ids=''; 
	
	for(var i=1;i<=all_num;i++)
	{
		if ( $('search_type_loc_'+i).checked)
			ids+=$('search_type_loc_'+i).value+'_';
	}
	
	var search_type_loc = ids;
	*/
	// end of type_locations	
	
	
	if ($('search_type_loc_id'))
		var search_type_loc= $('search_type_loc_id').value;
	else var search_type_loc='';
	
	if ($('search_city_id'))
		var search_city_id= $('search_city_id').value;
	else var search_city_id='';
	
	if ($('search_complex_id'))
		var search_complex_id= $('search_complex_id').value;
	else var search_complex_id='';
	
	if($('use_map'))
	 	var use_map = $('use_map').value;
		
	if ($('search_wifi_spots'))
		var keyw= $('search_wifi_spots').value;
	else var keyw='';
		
	 window.location.href = SiteURL +lg+ "/search-wifispots/" +search_type_access+'*'+search_type_loc+'*'+search_city_id+'*'+search_complex_id+'*'+use_map+'*'+keyw+ ".html";
}

function SetMap(par)
{
	
	if ($('id'))
		var id= $('id').value;
	else var id=0;
	
	if ($('type_accessid'))
		var type_accessid= $('type_accessid').value;
	else var type_accessid=0;
	
	if ($('type_locationid'))
		var type_locationid= $('type_locationid').value;
	else var type_locationid='';
	
	if ($('cityid'))
		var cityid= $('cityid').value;
	else var cityid='';
	
	if ($('complexid'))
		var complexid= $('complexid').value;
	else var complexid='';

	if (par==1)	
	{
		$('earth_map_holder').style.display='block';
		$('google_map_holder').style.display='none';
		//ShowEarchMap(pos1,pos2);
	}
	else 
	{
		$('earth_map_holder').style.display='none';
		$('google_map_holder').style.display='block';
		//showGoogleMap(pos1,pos2);
	}
	
	 if($('use_map'))
	 	$('use_map').value=par;
		
	if ($('keyw'))
		var keyw= $('keyw').value;
	else var keyw='';
	
	if ($('limitt'))
		var limitt= $('limitt').value;
	else var limitt='';
	
	if ($('rand'))
		var rand= $('rand').value;
	else var rand='';
	
	 getMapItems(par,id,type_accessid,type_locationid,cityid,complexid,keyw,limitt,rand);
}


function showGoogleMap(aMapItems)
{
	var data ='';
	//<![CDATA[';
	if (aMapItems.length>0)
	{
		some = aMapItems[0];
		
		if (some.res==1)
		{
			$('all_maps').style.display='block';
			function createMarker(point,html,par) 
			{
				var blue_spot = new GIcon();
				blue_spot.image = SiteURL+"images/green_ping_Icon2.png";
				blue_spot.shadow = SiteURL+"images/shadow_ping2.png";
				blue_spot.iconSize = new GSize(34,59);
				blue_spot.shadowSize = new GSize(62,58);
				blue_spot.iconAnchor = new GPoint(10,59);
				blue_spot.infoWindowAnchor = new GPoint(34,0);
				
				var green_spot = new GIcon();
				green_spot.image = SiteURL+"images/red_ping_Icon2.png";
				green_spot.shadow = SiteURL+"images/shadow_ping2.png";
				green_spot.iconSize = new GSize(34,59);
				green_spot.shadowSize = new GSize(62,58);
				green_spot.iconAnchor = new GPoint(10,59);
				green_spot.infoWindowAnchor = new GPoint(34,0);
			
				if (par==1)
				{
					var marker = new GMarker(point, {icon:blue_spot});
					GEvent.addListener(marker, "click", function() {
					  marker.openInfoWindowHtml(html);
					});
				}
				else
				{
					var marker = new GMarker(point, {icon:green_spot});
					GEvent.addListener(marker, "click", function() {
					  marker.openInfoWindowHtml(html);
					});	
				}
			return marker;
			}
				  
				  
			var map = new GMap2(document.getElementById("map"));
			//var start = new GLatLng(65,25);
			map.setCenter(new GLatLng(parseFloat(some.pos1),parseFloat(some.pos2)), 13);
			map.addControl(new GMapTypeControl(1));
			map.addControl(new GLargeMapControl());
			
			map.enableContinuousZoom();
			map.enableDoubleClickZoom();
			map.setMapType(G_NORMAL_MAP) ;
			
			// "tiny" marker icon
			var icon = new GIcon();
			icon.image = SiteURL+"images/home.png";
			icon.shadow = SiteURL+"images/shadow.png";
			icon.iconSize = new GSize(26,26);
			icon.shadowSize = new GSize(28,26);
			icon.iconAnchor = new GPoint(12,26);
			icon.infoWindowAnchor = new GPoint(16,0);
			
			
			
			for (var i=0; i < aMapItems.length; i++) 
			{
				some = aMapItems[i];
			
				var point = new GLatLng(parseFloat(some.pos1),parseFloat(some.pos2));
				var markerN = createMarker(point,'<div><a href="'+some.linkss+'">'+some.name+'</a></div><br />'+some.adress+'<br />'+some.summary+'',some.type_accessid);
				map.addOverlay(markerN);
				
				if (some.range_points!='')
				{
					var el = doTheWifiSpotRange(some.range_points);
					
					var polygon = eval('new GPolygon(['+el+'], "#8ED8F4", 3, 1, "#8ED8F4", 0.5)');
					map.addOverlay(polygon);
				}
			}
		}
		else 
		{
			$('all_maps').style.display='none';
			$('no_res_div').innerHTML=	some.TAG_NO_RESULTS;
		}
		
	}
	
	//]]>
}


function doTheWifiSpotRange(range_spots)
{
	var ll=range_spots.split("*");
	var elements='';
	for (var i=0; i<ll.length;i++)
	{
		var pp=ll[i];
		var points = pp.split("%%");
		elements=elements+ 'new GLatLng('+parseFloat(points[0])+','+parseFloat(points[1])+'), ';
		if (i==0) first='new GLatLng('+parseFloat(points[0])+','+parseFloat(points[1])+') ';
	}
	
	
	return elements+first;
}

function ShowEarchMap(aMapItems)
{
	if (aMapItems.length>0)
	{
		some = aMapItems[0];
		
		if (some.res==1)
		{
			$('all_maps').style.display='block';
			var map = null;
			function UpdateInfo(e)
			{
				document.getElementById("info").innerHTML ='Latitude = ' +e.view.latlong.latitude +', Longitude = '+ e.view.latlong.longitude +', Zoom=' +e.view.zoomLevel;
			}
				
			map = new VEMap('myMap');
			map.LoadMap(new VELatLong(parseFloat(some.pos1), parseFloat(some.pos2)), 12 ,'r' ,false);
			map.AttachEvent("onendcontinuouspan",UpdateInfo);
			map.AttachEvent("onendzoom",UpdateInfo);
			//map.AttachEvent("onclick",MouseClick);
			for (var i=0; i < aMapItems.length; i++) 
			{
				some = aMapItems[i];
				if (some.type_accessid==1) var im='green_ping_Icon2.png';
				else var im='red_ping_Icon2.png';
				
				var pin = new VEPushpin((i+1),new VELatLong(parseFloat(some.pos1), parseFloat(some.pos2)),SiteURL+'images/'+im,'<a href="'+some.linkss+'">'+some.name+'</a>',some.summary);
				map.AddPushpin(pin);
				//alert(i);
			}
		}
		else 
		{
			$('all_maps').style.display='none';
			$('no_res_div').innerHTML=	some.TAG_NO_RESULTS;
		}
	}
}

function displayR_Cities(aRegions)
{
	var div  = document.getElementById('r_city_container');
	var init = document.getElementById('r_city_init').value;
	
	
	var sel  = '<select name="r_cityid" id="idr_cityid" onchange="getCities(this.value)">';
	sel+='<option value=0>--------------</option>';
	
	for (var i=0; i < aRegions.length; i++) 
	{
		some = aRegions[i];
		sel += '<option value="' + some.id + '"';
		if(some.id == init)
			sel += " selected";
		
		sel += ' onclick="ShowNewVal(1,2)">' + some.name + '</option>';
    }
	if ($('new_r_city_s'))
	{
		some = aRegions[0];
		sel +='<option value="-1" onclick="ShowNewVal(1,1)" style="font-size:13px; font-weight:bold;">'+some.r_name+'</option>';	
	}
	sel += '</select>';
	
	div.innerHTML = sel;
}

function ShowNewVal(par,val)
{
	if (val==1)
	{
		if (par==1) 
		{
			$('new_r_city_s').style.display='block';
			$('new_r_city_s').focus();
		}
		if (par==2) 
		{
			$('new_city_s').style.display='block';
			$('new_city_s').focus();
		}
		if (par==3) 
		{
			$('new_complex_s').style.display='block';
			$('new_complex_s').focus();
		}
	}
	else if (val==2)
	{
		if (par==1) $('new_r_city_s').style.display='none';
		if (par==2) $('new_city_s').style.display='none';
		if (par==3) $('new_complex_s').style.display='none';
	}
}

function displayCities(aRegions)
{
	var div  = document.getElementById('region_container');
	var init = document.getElementById('region_init').value;
	
	
	var sel  = '<select name="cityid" id="idcityid" onchange="getComplex(this.value,1)">';
	sel+='<option value=0>--------------</option>';
	for (var i=0; i < aRegions.length; i++) 
	{
		some = aRegions[i];
		if (some.name)
		{
			sel += '<option value="' + some.id + '"';
			if(some.id == init)
				sel += " selected";
			
			sel += ' onclick="ShowNewVal(2,2)">' + some.name + '</option>';
		}
    }
	
	if ($('new_city_s'))
	{
		some = aRegions[0];
		sel +='<option value="-1" onclick="ShowNewVal(2,1)" style="font-size:13px; font-weight:bold;">'+some.r_name+'</option>';	
	}
	sel += '</select>';
	
	div.innerHTML = sel;
}

function displayComplex(aComplex)
{
	var div  = document.getElementById('complex_container');
	var init = document.getElementById('complex_init').value;
	
	
		var sel  = '<select name="complexid" id="idcomplexid" >';
		sel+='<option value=0>--------------</option>';
		if (aComplex.length)
		{
			for (var i=0; i < aComplex.length; i++) 
			{
				some = aComplex[i];
				if (some.name)
				{
					sel += '<option value="' + some.id + '"';
					if(some.id == init)
						sel += " selected";
					
					sel += ' onclick="ShowNewVal(3,2)">' + some.name + '</option>';
				}
			}
		}
		
		if ($('new_complex_s'))
		{
			some = aComplex[0];
			sel +='<option value="-1" onclick="ShowNewVal(3,1)" style="font-size:13px; font-weight:bold;">'+some.r_name+'</option>';	
		}
		sel += '</select>';
	 
	
	div.innerHTML = sel;
}


function displayComplex2(aComplex)
{
	var div  = document.getElementById('complex_container2');
	var init = document.getElementById('complex_init2').value;
	
	
		var sel  = '<select name="search_complex_id" id="search_complex_id" >';
		sel+='<option value=0>--------------</option>';
		if (aComplex.length)
		{
			for (var i=0; i < aComplex.length; i++) 
			{
				some = aComplex[i];
				sel += '<option value="' + some.id + '"';
				if(some.id == init)
					sel += " selected";
				
				sel += ' onclick = "setComplexid(this.value);">' + some.name + '</option>';
			}
		}
		sel += '</select>';
	 
	
	div.innerHTML = sel;
}

function showReportProblem()
{
	if ($('div_write').style.display=='block')
		$('div_write').style.display='none';
	else $('div_write').style.display='block';
}

function saveForm(lg,par) 
{ 
	if (par==1) //feedback
	{
		var name = $('name').value;
		var phone = '';
		var email = $('email').value;
		var message = $('notes').value;
		var id =0;
		var fr_email='';
		var fr_name='';
		var code='';
		var recaptcha_challenge_field = $('recaptcha_challenge_field').value;
		var recaptcha_response_field = $('recaptcha_response_field').value;
	}
	
	if (par==2) //report a problem
	{
		/*var name = document.forms['write'].elements['name'].value;
		var phone = document.forms['write'].elements['phone'].value;
		var email = document.forms['write'].elements['email'].value;
		var message = document.forms['write'].elements['notes'].value;
		var code=document.forms['write'].elements['code'].value;*/
		var name = $('name').value;
		var phone = $('phone').value;
		var email = $('email').value;
		var message = $('notes').value;
		var code=$('code').value;
		var id =$('spotsid').value;
		var fr_email='';
		var fr_name='';
		var recaptcha_challenge_field = '';
		var recaptcha_response_field = '';
	}
	
	sendGetRequest(SiteURL+'server/save_form.php?name='+name+'&phone='+phone+'&email='+email+'&message='+message+'&id='+id+'&fr_name='+fr_name+'&fr_email='+fr_email+'&par='+par+'&code='+code+'&recaptcha_challenge_field='+recaptcha_challenge_field+'&recaptcha_response_field='+recaptcha_response_field, 'showSaveFormResults','','');	
}

function showSaveFormResults(aSaveInfo)
{
	if (aSaveInfo.length>0)	
	{
		some=aSaveInfo[0];	
		
		document.getElementById(some.div).innerHTML=some.mes;
		if (some.err==0)
		{
			if ($('name'))	$('name').value='';
			if ($('notes'))	$('notes').value='';
			if ($('email'))	$('email').value='';
			if ($('code')) $('code').value='';
		}
	}
}

function MorePictresUpload()
{
	count = parseInt($('count').value);

	if (count != 0) data = '<br>';    
	else data='';
	//inter = "'";


	for (i=0; i < count; i++) 
	{ 
		
		data = data + '<table border="0" cellspacing="0" cellpadding="5">';
		data = data + '	<tr>';
		data = data + '		<td><div class="text2"><input id="tt_'+(i+1)+'" type="text" readonly="readonly" /></div></td>';
		var f="document.getElementById('tt_"+(i+1)+"').value=this.value;";
		data = data + '	<td><div class="file"><input type="file" onChange="'+f+'" name="tt_r_'+(i+1)+'"/></div></td>';
		data = data + '</tr></table>';
	}
	
	if (count != 0) data = data + '<br>';   
	else data='';
	$('show_upload').innerHTML = data;
}

function UploadFiles()
{
	if ($('more_upl_div').style.display=='block')
		$('more_upl_div').style.display='none';
	else $('more_upl_div').style.display='block';
	
	$('show_upload').innerHTML='';
	$('count').value=0;
	if ($('upload_files').style.display=='block')
		$('upload_files').style.display='none';
	else 
	{
		$('upload_files').style.display='block';
		pl();
		MorePictresUpload();
	}
}

function pl()
{
	v = parseInt(document.getElementById('count').value);
	if (v<=3)
		document.getElementById('count').value = v + 1;
	
}//end func

function validate_added_spot(lg)
{
	err=0;
	var mes='';
	if (lg=='_bg')
	{
		var text_adres='Моля, въведете адрес на Wifi точката<br />';
		var text_SSID='Моля, въведете SSID име на мрежата<br />';
		var text_corporate_name='Моля, въведете име на корпоративния потребител<br />';
		var text_corporate_phone='Моля, въведете телефон на корпоративния потребител<br />';
		var text_corporate_mail='Моля, въведете email на корпоративния потребител<br />';
		var text_r_cityid='Моля, изберете област<br />';
		var text_r_cityid2='Моля, въведете нова област<br />';
		var text_cityid='Моля, изберете град<br />';
		var text_cityid2='Моля, въведете нов град<br />';
		var text_complexid='Моля, изберете квартал<br />';
		var text_complexid2='Моля, въведете нов квартал<br />';
	}
	if (lg=='_en')
	{
		var text_adres='Please write Wifi Spot address<br />';
		var text_SSID='Please write Wireless Network name (SSID)<br />';
		var text_corporate_name='Please write corporate user name<br />';
		var text_corporate_phone='Please write corporate user phone<br />';
		var text_corporate_mail='Please write corporate user email<br />';
		var text_r_cityid='Please choose province/state<br />';
		var text_r_cityid2='Please write new province/state<br />';
		var text_cityid='Please choose city<br />';
		var text_cityid2='Please write new city<br />';
		var text_complexid='Please choose complex<br />';
		var text_complexid2='Please write new complex<br />';
	}
	
	if (document.forms['add_sp'].userr[1].checked==true) 
	{
		if (document.forms['add_sp'].elements['company_name'].value=='')
		{
			mes+=text_corporate_name;
			err=1;	
		}
		if (document.forms['add_sp'].elements['company_phone'].value=='')
		{
			mes+=text_corporate_phone;
			err=1;	
		}
		
		if (document.forms['add_sp'].elements['company_email'].value == "" || echeck(document.forms['add_sp'].elements['company_email'].value)==false) 
		{
			mes+=text_corporate_mail;
			err=1;	
		}
	}
	
	if (document.forms['add_sp'].elements['r_cityid'].value==0)
	{
		mes+=text_r_cityid;
		err=1;	
	}
	
	if ((document.forms['add_sp'].elements['r_cityid'].value==-1) && (document.forms['add_sp'].elements['new_r_city_ss'].value==''))
	{
		mes+=text_r_cityid2;
		err=1;	
	}
	
	if (document.forms['add_sp'].elements['cityid'].value==0)
	{
		mes+=text_cityid;
		err=1;	
	}
	
	if ((document.forms['add_sp'].elements['cityid'].value==-1) && (document.forms['add_sp'].elements['new_city_ss'].value==''))
	{
		mes+=text_cityid2;
		err=1;	
	}
	
	if (document.forms['add_sp'].elements['complexid'].value==0)
	{
		mes+=text_complexid;
		err=1;	
	}
	
	if ((document.forms['add_sp'].elements['complexid'].value==-1) && (document.forms['add_sp'].elements['new_complex_ss'].value==''))
	{
		mes+=text_complexid2;
		err=1;	
	}
	
	if (document.forms['add_sp'].elements['address'].value=='')
	{
		mes+=text_adres;
		err=1;	
	}
	
	if (document.forms['add_sp'].elements['SSID'].value=='')
	{
		mes+=text_SSID;
		err=1;	
	}
	
	if (mes!='') mes='<br />'+mes;
	document.getElementById('mess_err').innerHTML=mes;
	
	if (err==1) return false;
	else return true;	
}


function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}
	
function ChangeStarStyle(num)
{
	var stars='';
	 
	for (var i=1;i<=5;i++)
	{
		var myImg = eval("document.getElementById('st_"+i+"')");
		if (i<=num)
			 myImg.src = SiteURL+'images/rating1.gif';
		else 
			myImg.src = SiteURL+'images/rating2.gif';
	}
	

	
}

function UpdateUserVote(v)
{
	
	if ($('user_vote'))
		$('user_vote').value=v;
}
