//<![CDATA[

var map;
var geocoder;
var myLat;
var myLon;
function load(lat,lon,rad,page) {
zoom = radToZoom(rad);
map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(lat, lon), zoom);
map.setMapType(G_HYBRID_TYPE);
//map.setCenter(new GLatLng(37.4419, -122.1419), 5);
geocoder = new GClientGeocoder();
GEvent.addDomListener(document.getElementById("map"), "dblclick", function(e) {
	document.getElementById('nomove').value = 1;
	setTimeout("showUploadWin()",1000);
});
GEvent.addListener(map, "zoomend", function() {
	if(document.getElementById('nozoom').value == 0){
		setTimeout("returnZlevel()",500);
	}
});
GEvent.addListener(map, "moveend", function() {
		var center = map.getCenter();
		var lat = center.lat();
		var lon = center.lng();
	if(document.getElementById('nomove').value == 0){
		document.getElementById('mapCenterLat').value = lat;
		document.getElementById('mapCenterLon').value = lon;
		addPointToMap(lat,lon);		
	}
	ajaxpage('http://geocaster.com/ajax_geopartner_results.php?lat='+lat+'&lon='+lon+'','ajax_partners');
	
});
GEvent.addListener(map, "drag", function() {
	if(document.getElementById('nomove').value == 0){
		document.getElementById('map_center').style.display = 'block';
	}
});
GEvent.addListener(map, "dragend", function() {
	if(document.getElementById('nomove').value == 0){
		document.getElementById('map_center').style.display = 'none';
	}
});

ajaxpage('http://geocaster.com/ajax_geopartner_results.php?lat='+lat+'&lon='+lon+'','ajax_partners');
//addPointToMap(lat,lon);
addOnlyPointToMap(lat,lon,page);
}

function changeSort(){
	document.getElementById('myPage').value = 0;
	setTimeout("refreshMap()",300);
}
function changeType(){
	setTimeout("refreshMap()",200);
}
function refreshMap(){
	var center = map.getCenter();
	var lat = center.lat();
	var lon = center.lng();
	addPointToMap(lat,lon);
}
function centerPin(lat,lon){
	document.getElementById('nomove').value = 1;
	var zoom = map.getZoom();
	
	document.getElementById('mapCenterLat').value = lat;
	document.getElementById('mapCenterLon').value = lon;
	map.setCenter(new GLatLng(lat, lon), zoom);
	setTimeout("resetNoMove()",500);
}
function showUploadWin(){
	var center = map.getCenter();
	
	var lat = center.lat();
	var lon = center.lng();
	document.getElementById('mapCenterLat').value = lat;
	document.getElementById('mapCenterLon').value = lon;
	var zoom = returnZlevel();
	var myRad = document.getElementById('myRad').value;
	var myCat = document.forms[0].GC_categories.value;
	var myType = getCastType();
	var mySort = getMySort();
	var myUsername = getMyUsername();
	ajaxpage('http://geocaster.com/ajax_options.php?lat='+lat+'&lon='+lon+'&cat='+ myCat +'&type='+ myType +'&sort='+ mySort +'&username='+ myUsername +'&zoom='+zoom+'&radius='+myRad,'ajax_player');
	document.getElementById('map_center').style.display = 'block';

//	addPointToMap(lat,lon);
//	var tabhtml_1 = "<b>Please select:</b><ul><li><a href=\"javascript:void(0);\" onclick=\"addCast("+lat+","+lon+","+ returnZlevel() +");\">Add Cast</a></li><li><a href=\"javascript:void(0);\" onclick=\"zoomStreetlevel("+lat+","+lon+");\">Zoom to Streetlevel</a></li><li><a href=\"javascript:void(0);\" onclick=\"mailPlace("+lat+","+lon+");\">Mail Place</a></li><li><a href=\"javascript:void(0);\" onclick=\"bookmarkPlace("+lat+","+lon+");\">Bookmark Place</a></li></ul>";
//	var tabhtml_2 = "<ul></ul>";
//	var infoTabs = [
//	  new GInfoWindowTab("Infos", tabhtml_1),
//	  new GInfoWindowTab("Options", tabhtml_2)
//	];
	
//	map.openInfoWindowTabsHtml(center,infoTabs);
	
	
	
	setTimeout("resetNoMove()",2000);
}


// Polygon Test
function drawPolyOverlay(overlay, clickedPoint) {
	var polyPoints = Array();

	var mapNormalProj = G_NORMAL_MAP.getProjection();
	var mapZoom = map.getZoom();
        var clickedPixel = mapNormalProj.fromLatLngToPixel(clickedPoint, mapZoom);

	var polySmallRadius = rand(60) + 20;
	var polyLargeRadius = polySmallRadius*2 + rand(40);
	var polyColor = RGB2Color(rand(255),rand(255),rand(255));
	
        polyNumSides = 20;
        polySideLength = 18;
 //       document.getElementById("status").innerHTML = "Drew <strong>circle</strong> with <strong>" + polyNumSides + "</strong> sides, and <strong>" + polyColor + "</strong> fill.";

     	for (var a = 0; a<(polyNumSides+1); a++) {
		var aRad = polySideLength*a*(Math.PI/180);
		var polyRadius = polySmallRadius; 
	       	var pixelX = clickedPixel.x + polyRadius * Math.cos(aRad);
		var pixelY = clickedPixel.y + polyRadius * Math.sin(aRad);
		var polyPixel = new GPoint(pixelX,pixelY);
		var polyPoint = mapNormalProj.fromPixelToLatLng(polyPixel,mapZoom);
		polyPoints.push(polyPoint);
	}	
	var polygon = new GPolygon(polyPoints,"#000000",2,.5,polyColor,.5);
	map.addOverlay(polygon);
}


function resetNoMove(){
	document.getElementById('nomove').value = 0;
}
function hideCenterCross(){
	document.getElementById('map_center').style.display = 'none';
}
function mailPlace(lat,lon){
	alert("This function is not working yet");
	hideCenterCross();
}
function sharePlace(lat,lon){
	alert("This function is not working yet");
	hideCenterCross();
}
function bookmarkPlace(lat,lon){
	var myRad = document.getElementById('myRad').value;
	var url = 'http://geocaster.com/near/lat:'+lat+'/lon:'+lon+'/radius:'+myRad+'/';
	var title = 'GeoCaster.com (Lat:'+lat+' / Lon:'+lon+')';
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,false);
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); 
	} else if(window.opera && window.print) { // Opera Hotlist
		return true; 
	}
	
	hideCenterCross();
}
function bookmarkCast(){
	var myRad = document.getElementById('myRad').value;
	var castID = getCastID();
	var castTitle = getCastTitle();
	var url = 'http://geocaster.com/cast/'+castID+'/radius:'+myRad+'/';
	var title = 'GeoCaster.com - '+castTitle+'';
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url, false);
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); 
	} else if(window.opera && window.print) { // Opera Hotlist
		return true; 
	}
	
	hideCenterCross();
}
function getCastID(){
	try{
		var cID = document.getElementById('player_castID').value;
	} catch(E) {
		var cID = 0;
	}
	return cID;
}
function getCastTitle(){
	try{
		var cT = document.getElementById('player_castTitle').value;
	} catch(E) {
		var cT = '';
	}
	return cT;
}
function getMySort(){
	try{
		var mySort = document.getElementById('sort_select').value;
	} catch(E) {
		try{
			var mySort = document.getElementById('mySort').value;
		} catch(E) {
			var mySort = 'distance';
		}
	}
	document.getElementById('mySort').value = mySort;
	return mySort;
}
function getMyUsername(){
	try{
		var myUname = document.getElementById('myUsername').value;
	} catch(E){
		var myUname = 0;
	}
	return myUname;
}
function setMyUsername(username){
	document.getElementById('myUsername').value = username;
	return true;
}
function showCastsByUsername(username){
	setMyUsername(username);
	var center = map.getCenter();
	var lat = center.lat();
	var lon = center.lng();
	addPointToMap(lat,lon);
}
function showCastDetails(){
	var castID = getCastID();
	if(castID>0){
		var castTitle = getCastTitle();
		
		var lat = document.getElementById('myLat').value;
		var lon = document.getElementById('myLon').value;
		var myRad = document.getElementById('myRad').value;
		var myPage = document.getElementById('myPage').value;
		var mySort = getMySort();
		var myUsername = getMyUsername();
		loadingPleaseWait('ajax_results');
		ajaxpage('http://geocaster.com/ajax_cast_details.php?castID='+ document.getElementById('player_castID').value +'&lat='+ lat +'&lon='+ lon +'&page='+ myPage +'&radius='+ myRad +'&sort='+ mySort +'&username='+ myUsername +'','ajax_results');
	}
}
function closeGeocastDetails(){
	document.getElementById('geocast_details_bg').style.display="none";
	document.getElementById('geocast_details').style.display="none";	
}
function commentCast(objID){
	var obj = document.getElementById(objID);
	var castID = getCastID();
	if(castID > 0){
		var castTitle = getCastTitle();
		loadingPleaseWait(objID);
		ajaxpage('http://geocaster.com/ajax_add_comment.php?castID='+ castID +'',objID);
	}
}
function mailCast(){
	var myRad = document.getElementById('myRad').value;
	var castID = getCastID();
	if(castID>0){
		var castTitle = getCastTitle();
		loadingPleaseWait('ajax_player');
		ajaxpage('http://geocaster.com/ajax_share_cast.php?castID='+ castID +'','ajax_player');
	}
	hideCenterCross();
}
function checkShareCast(){
	//Subject check
	var subjObj=document.getElementById('share_cast_subject');
	if ((subjObj.value==null)||(subjObj.value=="")||(subjObj.value.length < 4)){
		alert("Please Enter a Subject");
		subjObj.focus();
		return false;
	}//Message check
	var messageObj=document.getElementById('share_cast_message');
	if ((messageObj.value==null)||(messageObj.value=="")||(messageObj.value.length < 10)){
		alert("Please Enter a Message");
		messageObj.focus();
		return false;
	}
	//reci Name check
	var nameObj=document.getElementById('reci_name');
	if ((nameObj.value==null)||(nameObj.value=="")||(nameObj.value.length < 2)){
		alert("Please Enter the Recipients Name");
		nameObj.focus();
		return false;
	}
	//reci eMail check
	var emailObj=document.getElementById('reci_mail');
	if ((emailObj.value==null)||(emailObj.value=="")){
		alert("Please Enter the Recipients Email");
		emailObj.focus();
		return false;
	}
	if (checkEmail(emailObj.value)==false){
		emailObj.value="";
		emailObj.focus();
		return false;
	}
	
	
	
	return true;
}
function publishCast(){
	var castID = getCastID();
	if(castID>0){
		var castTitle = getCastTitle();
		loadingPleaseWait('ajax_player');
		ajaxpage('http://geocaster.com/ajax_publish_cast.php?castID='+ castID +'','ajax_player');
	}
}
function reportCast(){
	var castID = getCastID();
	if(castID>0){
		var castTitle = getCastTitle();
		loadingPleaseWait('ajax_player');
		ajaxpage('http://geocaster.com/ajax_report_cast.php?castID='+ castID +'','ajax_player');
	}
}
function checkReportCast(){
	//Subject check
	
	var messageObj=document.getElementById('report_message');
	if ((messageObj.value==null)||(messageObj.value=="")||(messageObj.value.length < 10)){
		alert("Please Enter a Message");
		messageObj.focus();
		return false;
	}	
	
	return true;
}
function contactGeocaster(){
	var castID = getCastID();
	if(castID>0){
		var castTitle = getCastTitle();
		loadingPleaseWait('ajax_player');
		ajaxpage('http://geocaster.com/ajax_contact_geocaster.php?castID='+ castID +'','ajax_player');
	}
}
function checkContactCaster(){
	//Subject check
	var subjObj=document.getElementById('send_caster_subject');
	if ((subjObj.value==null)||(subjObj.value=="")||(subjObj.value.length < 4)){
		alert("Please Enter a Subject");
		subjObj.focus();
		return false;
	}
	//Message check
	var messageObj=document.getElementById('send_caster_message');
	if ((messageObj.value==null)||(messageObj.value=="")||(messageObj.value.length < 10)){
		alert("Please Enter a Message");
		messageObj.focus();
		return false;
	}
	
	
	return true;
}

function check_upload(){
	//Zoom check
	var zoom = map.getZoom();
	if(zoom < 11){
		alert('The specified zoomlevel is not sufficient. Please zoom to Streetlevel');
		document.getElementById('upload_smit').disabled = false;
		return false;
	} else {
		//hideCenterCross();		
	}
	
	//Name check
	var nameObj=document.getElementById('cast_name');
	if ((nameObj.value==null)||(nameObj.value=="")||(nameObj.value.length < 4)){
		alert("Please Enter a Name");
		document.getElementById('upload_smit').disabled = false;
		nameObj.focus();
		return false;
	}
	//Description check
	var nameObj=document.getElementById('cast_desc');
	if ((nameObj.value==null)||(nameObj.value=="")||(nameObj.value.length < 4)){
		alert("Please Enter a Description (at least 20 characters)");
		document.getElementById('upload_smit').disabled = false;
		nameObj.focus();
		return false;
	}
	//Keywords check
	var nameObj=document.getElementById('cast_keywords');
	if ((nameObj.value==null)||(nameObj.value=="")||(nameObj.value.length < 4)){
		alert("Please Enter Keywords separated by comma");
		document.getElementById('upload_smit').disabled = false;
		nameObj.focus();
		return false;
	}
	//Date check
	var nameObj=document.getElementById('cast_date');
	if ((nameObj.value==null)||(nameObj.value=="")||(nameObj.value=="MM-DD-YYYY")||(nameObj.value.length != 10)||(nameObj.value.indexOf('-') == -1)){
		alert("Please Enter a Date. (example: 12-31-2006)");
		document.getElementById('upload_smit').disabled = false;
		nameObj.focus();
		return false;
	}
	//TopCat check
	var nameObj=document.getElementById('cast_topCatID');
	if ((nameObj.value==null)||(nameObj.value=="")||(nameObj.value == 0)){
		alert("Please Select a Main-Category");
		document.getElementById('upload_smit').disabled = false;
		nameObj.focus();
		return false;
	}
	//Cat check
	var nameObj=document.getElementById('cast_catID');
	if ((nameObj.value==null)||(nameObj.value=="")||(nameObj.value == 0)){
		alert("Please Select a Sub-Category");
		document.getElementById('upload_smit').disabled = false;
		nameObj.focus();
		return false;
	}
	//File check
	var nameObj=document.getElementById('cast_file');
	if ((nameObj.value==null)||(nameObj.value=="")||(nameObj.value == 0)){
		alert("Please Select a GeoCast. (Valid filetypes: jpg, png, gif, flv, mp3, avi, 3gp, mpeg, mov, wmv)");
		document.getElementById('upload_smit').disabled = false;
		nameObj.focus();
		return false;
	}
	
	var center = map.getCenter();
	document.getElementById('cast_lat').value = center.lat();
	document.getElementById('cast_lon').value = center.lon();
	return true;
	
}


function addCast(lat,lon,radius){
	ajaxpage('http://geocaster.com/ajax_upload.php?lat='+lat+'&lon='+lon+'&radius='+radius,'ajax_player');
}
function zoomStreetlevel(lat,lon){
	point = new GLatLng(lat,lon);
	map.setCenter(point, 15);
//	map.setZoom(15);
}

function zoomTo(zoom){
//	var center = map.getCenter();
	var lat = document.getElementById('mapCenterLat').value;
	var lon = document.getElementById('mapCenterLon').value;
	var center = new GLatLng(lat,lon);
	map.setCenter(center, zoom);
	returnZlevel()
}

function loadingPleaseWait(obj){
	document.getElementById(obj).innerHTML = '<'+'div'+' style="text-align:center;text-decoration:blink;color:#f00;font-weight:bold;">Loading ... Please wait ...<'+'/div>';
}


// Create geopin icon
var icon = new GIcon();
icon.image = "http://geocaster.com/images/geopin.gif";
icon.shadow = "http://geocaster.com/images/geopin_shadow.png";
icon.iconSize = new GSize(25, 38);
icon.shadowSize = new GSize(45, 28);
icon.iconAnchor = new GPoint(12, 38);
icon.infoWindowAnchor = new GPoint(5, 1);




// Create geopin image icon
var image_icon = new GIcon();
image_icon.image = "http://geocaster.com/images/geopin_icon_image.gif";
image_icon.iconSize = new GSize(16, 24);
image_icon.shadowSize = new GSize(16, 24);
image_icon.iconAnchor = new GPoint(1, 24);
image_icon.infoWindowAnchor = new GPoint(5, 1);
// Create geopin video icon
var video_icon = new GIcon();
video_icon.image = "http://geocaster.com/images/geopin_icon_video.gif";
video_icon.iconSize = new GSize(16, 24);
video_icon.shadowSize = new GSize(16, 24);
video_icon.iconAnchor = new GPoint(1, 24);
video_icon.infoWindowAnchor = new GPoint(5, 1);


// addAddressToMap() is called when the geocoder returns an
// answer.  It adds a marker to the map with an open info window
// showing the nicely formatted version of the address and the country code.
function addAddressToMap(response) {
	map.clearOverlays();
	if (!response || response.Status.code != 200) {
		alert("Sorry, we were unable to geocode that address. Please spell check your input or be more specific. (Example: \"Miami, FL\" or \"Berlin, Germany\")");
	} else {
		/*
		var city = [
		  {
		    name: "Washington, DC",
		    Status: {
		      code: 200,
		      request: "geocode"
		    },
		    Placemark: [
		      {
		        address: "Washington, DC, USA",
		        population: "0.563M",
		        AddressDetails: {
		          Country: {
		            CountryNameCode: "US",
		            AdministrativeArea: {
		              AdministrativeAreaName: "DC",
		              Locality: {
		                LocalityName: "Washington"
		              }
		            }
		          },
		          Accuracy: 4          
		        },
		        Point: {
		          coordinates: [-77.036667, 38.895000, 0]
		        }
		      }
		    ]
		  },
		  ... // etc., and so on for other cities
		];
		*/
		place = response.Placemark[0];
		point = new GLatLng(place.Point.coordinates[1],
		                    place.Point.coordinates[0]);
		var myZoom = document.getElementById('myZoom').value;
		map.setCenter(point, myZoom);
		myLat = place.Point.coordinates[1];
		myLon = place.Point.coordinates[0];
		document.getElementById('myLat').value = myLat;
		document.getElementById('myLon').value = myLon;
		var myRad = document.getElementById('myRad').value;
		
		var myCat = document.forms[0].GC_categories.value;
		var myType = getCastType();
		var mySort = "distance";
		var myUsername = 0;
		setMyUsername(0);
		document.getElementById('mySort').value = mySort;
		
		loadingPleaseWait('ajax_results');
		ajaxpage('http://geocaster.com/ajax_results.php?lat='+ myLat +'&lon='+ myLon +'&cat='+ myCat +'&type='+ myType +'&sort='+ mySort +'&username='+ myUsername +'&city='+ place.address +'&country='+ place.AddressDetails.Country.CountryNameCode +'&population='+ place.population +'&radius='+ myRad +'','ajax_results');   //&locality='+ place.AddressDetails.Country.AdministrativeArea.Locality.LocalityName +'&administrativearea='+ place.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName +'
		
		GDownloadUrl('http://geocaster.com/ajax_results.php?xml_markers=1&lat='+ myLat +'&lon='+ myLon +'&cat='+ myCat +'&type='+ myType +'&sort='+ mySort +'&username='+ myUsername +'&radius='+ myRad +'', function(data, responseCode) {
		  var xml = GXml.parse(data);
		  var markers = xml.documentElement.getElementsByTagName("marker");
		  for (var i = 0; i < markers.length; i++) {
		    var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
		                            parseFloat(markers[i].getAttribute("lng")));
		    var markerID = markers[i].getAttribute("id");
		    
		    map.addOverlay(createMarker(point, i+1, markerID,parseFloat(markers[i].getAttribute("lat")),parseFloat(markers[i].getAttribute("lng")),markers[i].getAttribute("name"),markers[i].getAttribute("desc"),markers[i].getAttribute("type")));
		  }
		});
		
		hideCenterCross();
		
	}
}

function addPointToMap(lat,lon) {
	map.clearOverlays();
	
	point = new GLatLng(lat,lon);
	myLat = lat;
	myLon = lon;
	document.getElementById('myLat').value = myLat;
	document.getElementById('myLon').value = myLon;
	var myRad = document.getElementById('myRad').value;
	var myZoom = document.getElementById('myZoom').value;
	var myCat = document.forms[0].GC_categories.value;
	var myType = getCastType();
	var mySort = getMySort();
	var myUsername = getMyUsername();
	loadingPleaseWait('ajax_results');
	ajaxpage('http://geocaster.com/ajax_results.php?lat='+ myLat +'&lon='+ myLon +'&cat='+ myCat +'&type='+ myType +'&sort='+ mySort +'&username='+ myUsername +'&radius='+ myRad +'','ajax_results');
	
	GDownloadUrl('http://geocaster.com/ajax_results.php?xml_markers=1&lat='+ myLat +'&lon='+ myLon +'&cat='+ myCat +'&type='+ myType +'&sort='+ mySort +'&username='+ myUsername +'&radius='+ myRad +'', function(data, responseCode) {
	  var xml = GXml.parse(data);
	  var markers = xml.documentElement.getElementsByTagName("marker");
	  for (var i = 0; i < markers.length; i++) {
	    var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
	                            parseFloat(markers[i].getAttribute("lng")));
	    var markerID = markers[i].getAttribute("id");
	    
	    map.addOverlay(createMarker(point, i+1, markerID,parseFloat(markers[i].getAttribute("lat")),parseFloat(markers[i].getAttribute("lng")),markers[i].getAttribute("name"),markers[i].getAttribute("desc"),markers[i].getAttribute("type")));
	  }
	});
	hideCenterCross();
}


function addOnlyPointToMap(lat,lon,page) {
	map.clearOverlays();
	
	point = new GLatLng(lat,lon);
	myLat = lat;
	myLon = lon;
	document.getElementById('myLat').value = myLat;
	document.getElementById('myLon').value = myLon;
	var myRad = document.getElementById('myRad').value;
	var myZoom = document.getElementById('myZoom').value;
	var myCat = document.forms[0].GC_categories.value;
	var myType = getCastType();
	var mySort = getMySort();
	var myUsername = getMyUsername();
	GDownloadUrl('http://geocaster.com/ajax_results.php?xml_markers=1&lat='+ myLat +'&lon='+ myLon +'&cat='+ myCat +'&type='+ myType +'&sort='+ mySort +'&username='+ myUsername +'&radius='+ myRad +'&page='+page, function(data, responseCode) {
	  var xml = GXml.parse(data);
	  var markers = xml.documentElement.getElementsByTagName("marker");
	  for (var i = 0; i < markers.length; i++) {
	    var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
	                            parseFloat(markers[i].getAttribute("lng")));
	    var markerID = markers[i].getAttribute("id");
	    
	    map.addOverlay(createMarker(point, i+1, markerID,parseFloat(markers[i].getAttribute("lat")),parseFloat(markers[i].getAttribute("lng")),markers[i].getAttribute("name"),markers[i].getAttribute("desc"),markers[i].getAttribute("type")));
	  }
	});
	hideCenterCross();
}


function showPage(lat,lon,page){
	var myRad = document.getElementById('myRad').value;
	var myCat = document.forms[0].GC_categories.value;
	var myType = getCastType();
	var mySort = getMySort();
	var myUsername = getMyUsername();
	document.getElementById('myPage').value = page;
	loadingPleaseWait('ajax_results');
	ajaxpage('http://geocaster.com/ajax_results.php?lat='+lat+'&lon='+lon+'&cat='+ myCat +'&type='+ myType +'&sort='+ mySort +'&username='+ myUsername +'&radius='+myRad+'&page='+page+'','ajax_results');
	addOnlyPointToMap(lat,lon,page);
	hideCenterCross();
}






function returnZlevel(){
	var zoom = map.getZoom();
	var newRad;
	//alert(zoom.toString());
	if(zoom==0)newRad=10000;
	if(zoom==1)newRad=6000;
	if(zoom==2)newRad=3000;
	if(zoom==3)newRad=1500;
	if(zoom==4)newRad=700;
	if(zoom==5)newRad=320;
	if(zoom==6)newRad=160;
	if(zoom==7)newRad=80;
	if(zoom==8)newRad=40;
	if(zoom==9)newRad=20;
	if(zoom==10)newRad=10;
	if(zoom==11)newRad=5;
	if(zoom==12)newRad=2.5;
	if(zoom==13)newRad=1.2;
	if(zoom==14)newRad=0.6;
	if(zoom==15)newRad=0.3;
	if(zoom==16)newRad=0.15;
	if(zoom==17)newRad=0.075;
	if(zoom==18)newRad=0.075;
	if(zoom==19)newRad=0.075;
	if(zoom==20)newRad=0.075;
	if(zoom==21)newRad=0.075;
	if(zoom==22)newRad=0.075;
	if(zoom==23)newRad=0.075;
	if(zoom==24)newRad=0.075;
	if(zoom==25)newRad=0.075;
	
	document.getElementById('myZoom').value = zoom;
	document.getElementById('myRad').value = newRad;
	var center = map.getCenter();
	var lat = center.lat();
	var lon = center.lng();
	addPointToMap(lat,lon);
}


function radToZoom(rad){
	var zoom;
	if(rad==10000)zoom=0;
	if(rad==6000)zoom=1;
	if(rad==3000)zoom=2;
	if(rad==1500)zoom=3;
	if(rad==700)zoom=4;
	if(rad==320)zoom=5;
	if(rad==160)zoom=6;
	if(rad==80)zoom=7;
	if(rad==40)zoom=8;
	if(rad==20)zoom=9;
	if(rad==10)zoom=10;
	if(rad==5)zoom=11;
	if(rad==2.5)zoom=12;
	if(rad==1.2)zoom=13;
	if(rad==0.6)zoom=14;
	if(rad==0.3)zoom=15;
	if(rad==0.15)zoom=16;
	if(rad==0.075)zoom=17;
	return zoom;
}

function removeSortSelector() {
	var cont = true;
	try{
		var d = document.getElementById('sort_select_wrapper');
	} catch(E){
		cont = false;
	}
	if(cont){
		try{
			var o = document.getElementById('inner_sort_select_wrapper');
		} catch(E){
			cont = false;
		}
	}
  	if(cont){
		try{
 			d.removeChild(o);
  		} catch(E){
  			cont = false;
  		}
  	}
  	return cont;
}

var allMarkers = new Array();
function createMarker(point, number, id, myLat, myLon, myName, myDesc, theType) {
	if(theType=="image"){
		var mmarker = new GMarker(point,image_icon);
	} else if(theType=="video"){
		var mmarker = new GMarker(point,video_icon);
	} else if(theType=="audio"){
		var mmarker = new GMarker(point,audio_icon);
	} else {
		var mmarker = new GMarker(point,icon);
	}
	GEvent.addListener(mmarker, "mouseover", function() {
//		document.getElementById('geocast_'+id).style.background='#ffffdd';
		showD("<div style='display:block;overflow:hidden;width:80px;height:80px;float:left;margin:0;margin-right:3px;'><img src='http://geocaster.com/cast_thumbs/"+ id +".jpg' /></div><p>"+myDesc+"</p>",myName);
	});
	GEvent.addListener(mmarker, "mouseout", function() {
//		document.getElementById('geocast_'+id).style.background='';
		hideD();
	});
	GEvent.addListener(mmarker, "click", function() {
		hideD();
		mySort = 'distance';
	//	
		try{
			document.getElementById('sort_select').onchange = '';
		} catch(E){
			
		}
		try{	
			document.getElementById('sort_select').value = 'distance';
		} catch(E){
			
		}
		try{
			document.getElementById('mySort').value = 'distance';
		} catch(E){
			
		}
		
		var myUsername = getMyUsername();
		
		var myZoom = document.getElementById('myZoom').value;
		map.setCenter(point, myZoom);
    
		for (var i = 0; i < allMarkers.length; i++) {
			map.removeOverlay(allMarkers[i]);
		}
		
		var myRad = document.getElementById('myRad').value;
		var myCat = document.forms[0].GC_categories.value;
		var myType = getCastType();
		var mySort = 'distance';
		
		removeSortSelector();
		
		loadingPleaseWait('ajax_results');
		ajaxpage('http://geocaster.com/ajax_results.php?lat='+ myLat +'&lon='+ myLon +'&cat='+ myCat +'&type='+ myType +'&sort='+ mySort +'&username='+ myUsername +'&radius='+ myRad +'','ajax_results');
		
		loadingPleaseWait('ajax_player');
		ajaxpage('http://geocaster.com/ajax_player.php?lat='+ myLat +'&lon='+ myLon +'&cat='+ myCat +'&type='+ myType +'&sort='+ mySort +'&username='+ myUsername +'&castID='+id,'ajax_player');
		
		GDownloadUrl('http://geocaster.com/ajax_results.php?xml_markers=1&lat='+ myLat +'&lon='+ myLon +'&cat='+ myCat +'&type='+ myType +'&sort='+ mySort +'&username='+ myUsername +'&radius='+ myRad +'&castID='+id, function(data, responseCode) {
			var xml = GXml.parse(data);
			var markers = xml.documentElement.getElementsByTagName("marker");
			for (var i = 0; i < markers.length; i++) {
				var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
			                            parseFloat(markers[i].getAttribute("lng")));
				var markerID = markers[i].getAttribute("id");
				map.addOverlay(createMarker(point, i+1, markerID,parseFloat(markers[i].getAttribute("lat")),parseFloat(markers[i].getAttribute("lng")),markers[i].getAttribute("name"),markers[i].getAttribute("desc"),markers[i].getAttribute("type")));
			}
		});
	});
	allMarkers.push(mmarker);
	return mmarker;
}

// showLocation() is called when you click on the Search button
// in the form.  It geocodes the address entered into the form
// and adds a marker to the map at that location.
function showLocation() {
var address = document.forms[0].q.value;
geocoder.getLocations(address, addAddressToMap);
}

// findLocation() is used to enter the sample addresses into the form.
function findLocation(address) {
document.forms[0].q.value = address;
showLocation();
}

function getCastType(){
	return checkradio('cast_type');
}
function checkradio(feld){
	var feldO = document.getElementsByName(feld)
	for (i=0; i<feldO.length; i++){
			if(feldO[i].checked == true){
				return feldO[i].value;
			}
	}
}

function setFlurl(url,title)
{
	var movie = findFl('_nexMP3bigPlay');
	if (movie) {		   
		movie.SetVariable('nexFile', url.toString());
		movie.SetVariable('nexTitle', title.toString());
		movie.SetVariable('nexNewPlayCheck', 'gogogo');
	}
}
function setFst(st)
{
	var movie = findFl('_nexMP3bigPlay');
	if (movie) {
		movie.SetVariable('st', st.toString());
	}
}
            
function findFl (flash) {
	    if (document.all) {
	      if (document.all[flash]) {
	        return document.all[flash];
	      }
	      if (window.opera) {
	        var movie = eval(window.document + flash);
	        if (movie.SetVariable) {
	          return movie;
	        }
	      }
	      return;
	    }
	    if(document.layers) {
	      if(document.embeds) {
	        var movie = document.embeds[flash];
	        if (movie.SetVariable) {
	          return movie;
	        }
	      }
	      return;
	    }
	    if (!document.getElementById) {
	      return;
	    }
	    var movie = document.getElementById(flash);
	    if (movie.SetVariable) {
	      return movie;
	    }
	    var movies = movie.getElementsByTagName('embed');
	    if (!movies || !movies.length) {
	      return;
	    }
	    movie = movies[0];
	    if (movie.SetVariable) {
	      return movie;
	    }
	    return;
}

var apClickCount = 0;
function prevCast(){
	var casterCount = document.getElementById('geocaster_player_container_count').value;
	if(apClickCount>0){
		
//		var ap=document.getElementById('ajax_player_slide');
		document.getElementById('geocaster_player_container_'+apClickCount).style.display = 'none';
		apClickCount--;
		document.getElementById('geocaster_player_container_'+apClickCount).style.display = 'block';
//		ap.style.top = (0 - (apClickCount*400)) +'px';
	}
	
}
function nextCast(){
	
	var casterCount = document.getElementById('geocaster_player_container_count').value;
	if(apClickCount<(casterCount-1)){
		document.getElementById('geocaster_player_container_'+apClickCount).style.display = 'none';
		apClickCount++;
		document.getElementById('geocaster_player_container_'+apClickCount).style.display = 'block';
	}
//	var ap=document.getElementById('ajax_player_slide');
//	ap.style.top = (0 - (apClickCount*400)) +'px';
}







function checkEmail(email) {

	var at="@";
	var dot=".";
	var lat=email.indexOf(at);
	var lstr=email.length;
	var ldot=email.indexOf(dot);
	if (email.indexOf(at)==-1){
	   alert("The E-mail you entered is invalid.\nPlease correct your input to proceed.");
	   return false;
	}
	if (email.indexOf(at)==-1 || email.indexOf(at)==0 || email.indexOf(at)==lstr){
	   alert("The E-mail you entered is invalid.\nPlease correct your input to proceed.");
	   return false;
	}
	if (email.indexOf(dot)==-1 || email.indexOf(dot)==0 || email.indexOf(dot)==lstr){
	    alert("The E-mail you entered is invalid.\nPlease correct your input to proceed.");
	    return false;
	}
	if (email.indexOf(at,(lat+1))!=-1){
	    alert("The E-mail you entered is invalid.\nPlease correct your input to proceed.");
	    return false;
	}
	if (email.substring(lat-1,lat)==dot || email.substring(lat+1,lat+2)==dot){
	    alert("The E-mail you entered is invalid.\nPlease correct your input to proceed.");
	    return false;
	}
	if (email.indexOf(dot,(lat+2))==-1){
	    alert("The E-mail you entered is invalid.\nPlease correct your input to proceed.");
	    return false;
	}
	if (email.indexOf(" ")!=-1){
	    alert("The E-mail you entered is invalid.\nPlease correct your input to proceed.");
	    return false;
	}
	return true;				
}
function disable_form(theform) {
	if (document.all || document.getElementById) {
		for (i = 0; i < theform.length; i++) {
			var tempobj = theform.elements[i];
			if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset")
				tempobj.disabled = true;
		}
		return true;
	} else {
		return true;
		//return false;
	}
}
function validate_regform(){
	//Firstname check
	var fnameObj=document.getElementById('regform_userVorname');
	if ((fnameObj.value==null)||(fnameObj.value=="")||(fnameObj.value.length < 2)){
		alert("Please Enter your Firstname");
		fnameObj.focus();
		return false;
	}
	
	//Lastname check
	var lnameObj=document.getElementById('regform_userNachname');
	if ((lnameObj.value==null)||(lnameObj.value=="")||(lnameObj.value.length < 2)){
		alert("Please Enter your Lastname");
		lnameObj.focus();
		return false;
	}
	
	//Username check
	var userObj=document.getElementById('regform_userUser');
	if ((userObj.value==null)||(userObj.value=="")||(userObj.value.length < 2)){
		alert("Please Enter your Username");
		userObj.focus();
		return false;
	}
	var userFreeObj=document.getElementById('regform_userchecked_checker');
	if ((userFreeObj.value==0)){
		alert("Please Check Availability of your Username");
		userObj.focus();
		return false;
	}
	
	//Password check
	var pwObj=document.getElementById('regform_userPass');
	var pw2Obj=document.getElementById('regform_userPass2');
	if ((pwObj.value==null)||(pwObj.value=="")||(pwObj.value.length < 6)){
		alert("Please Enter your Password (at least 6 characters)");
		pwObj.focus();
		return false;
	}
	if ((pw2Obj.value==null)||(pw2Obj.value=="")||(pw2Obj.value.length < 6)){
		alert("Please Enter the same Password a second time");
		pw2Obj.focus();
		return false;
	}
	if (pwObj.value!=pw2Obj.value){
		alert("Your Passwords don't match");
		pwObj.value="";
		pw2Obj.value="";
		pwObj.focus();
		return false;
	}
	
	//eMail check
	var emailObj=document.getElementById('regform_userMail');
	if ((emailObj.value==null)||(emailObj.value=="")){
		alert("Please Enter your Email");
		emailObj.focus();
		return false;
	}
	if (checkEmail(emailObj.value)==false){
		emailObj.value="";
		emailObj.focus();
		return false;
	}
	
	//terms check
	if(document.getElementById('regform_accept_all_terms').checked!=true && document.getElementById('regform_accept_all_terms').checked!='checked'){
		alert("You must read and accept all terms and agrements by checking the appropriate box to proceed");
		return false;
	}
	
	
	return true;
 }


function become_geopartner(){
	var center = map.getCenter();
	var lat = center.lat();
	var lon = center.lng();
	var myRad = document.getElementById('myRad').value;
	
	ajaxpage('http://geocaster.com/ajax_become_geopartner.php?lat='+ lat +'&lon='+ lon +'&radius='+ myRad +'','ajax_player');
}
function check_geopartner_form(){
	var zoom = map.getZoom();
	if(zoom < 11){
		alert('The specified zoomlevel is not sufficient. Please zoom to Streetlevel');
		document.getElementById('upload_smit').disabled = false;
	} else {
		hideCenterCross();
		document.getElementById('become_geopartner').submit();
	}
	
}

function update_monthly_fee(){
	if(parseFloat(document.getElementById('miles').value)<1){document.getElementById('miles').value = 1;}
	if(parseFloat(document.getElementById('bid').value)<1){document.getElementById('bid').value = 1;}
	var theFee = parseFloat(document.getElementById('miles').value) * parseFloat(document.getElementById('bid').value);
	
	document.getElementById('geopartner_fee').innerHTML = theFee;
	document.getElementById('monthly_fee').value = theFee;
}

function check_position_maxbid(){
	var center = map.getCenter();
	var lat = center.lat();
	var lon = center.lng();
	ajaxpage('http://geocaster.com/ajax_check_geopartner_position.php?lat='+ lat +'&lon='+ lon +'','geopartner_maxbid');
}


//]]>