// JavaScript Document
var cityglob;
function chkfor(form)
{
	var validat="";
	var validtxt="";
	var txtval="";
	var id=0;
	cityglob="";
	switch(form)
	{
		case "funplotter":
		 validat=document.funplotter.selectfunsite.value;
		 txtval=document.funplotter.txtpinterestdiv.value;
		 cityglob=document.funplotter.city.value;
		break;
		case "funplottertrip":
		 validat=document.funplottertrip.selectfunsitetrip.value;
		// id=document.funplottertrip.selectfunsitetrip.selectedIndex;
		// validtxt=document.funplottertrip.selectfunsitetrip.options[id].text;
		 txtval=document.funplottertrip.txtpinterestdivtrip.value;
		 cityglob=document.funplottertrip.citytrip.value;
		break;
		case "specialevent":
		 validat=document.specialevent.selectfunsite_event.value;
		 txtval=document.specialevent.txtpinterestdiv_event.value;
		 cityglob=document.specialevent.city_event.value;
		break;
		case "specialhtml":
		 validat=document.specialhtml.selectfunsite_html.value;
		 txtval=document.specialhtml.txtpinterestdiv_html.value;
		 cityglob=document.specialhtml.city_html.value;
		break;
		case "party":
		 validat=document.party.selectfunsite_party.value;
		 txtval=document.party.txtpinterestdiv_party.value;
		 cityglob=document.party.city_party.value;
		break;
		case "partyhtml":
		 validat=document.partyhtml.selectfunsite_party_html.value;
		 txtval=document.partyhtml.txtpinterestdiv_party_html.value;
		 cityglob=document.partyhtml.city_party_html.value;
		break;
	}
	
	if(validat=="N")
	{
		if(txtval=="")
		{
			alert("Please Specify Funspot Name !");
		}
		else
		{
			spotlat(form,txtval,"1");
		}
	}
	else
	{
		if(validat=="")
		{
			alert("Please Specify Funspot Name !");
		}
		else
		{
		    spotlat(form,validat,"2");
		}
	}
}
var globalform
function spotlat(form,txtvals,from)
{
	WaitOn();
	switch(form)
	{
		case "funplotter":
		document.partyhtml.repeatd.value="no";
		break;
		case "funplottertrip":
		document.partyhtml.repeatd.value="no";
		break;
		case "specialevent":
		document.partyhtml.repeatd.value="no";
		break;
		case "specialhtml":
		document.partyhtml.repeatd.value="no";
		break;
		case "party":
		document.partyhtml.repeatd.value="no";
		break;
		case "partyhtml":
		document.partyhtml.repeatd.value="no";
		break;
	}
	globalform=form;
	//alert(txtvals+cityglob);
	var url="includes/plantrip.helper.php?sid=" + Math.random() + "&funspotname="+txtvals+"&selectcity="+cityglob+"&sel="+from
	xmlspot=GetXmlHttpObject(spotresult)
	xmlspot.open("GET", url , true)
	xmlspot.send(null)	
}

function spotresult()
{ 
		if (xmlspot.readyState==4 || xmlspot.readyState=="complete")
		{ 
			var xmlresp=xmlspot.responseText;
			var arrxml = xmlresp.split("<delim>");
			form=globalform;
			//alert(globalform+cityglob);
			var states=arrxml[0];
			var arrStates=states.split("|");
			var setval="";
			//alert(arrStates);
			for (i=0;i<arrStates.length-1;i++)
			{
				if (arrStates[i].length>0)
				{
					var arrState_split = arrStates[i].split("/");
					if(arrState_split[2]!="" && arrState_split[3]!="" && arrState_split[2]!=0 && arrState_split[3]!=0)
					{
					switch(form)
					{
						case "funplotter":
						document.funplotter.lat_long.value= arrState_split[2]+"/"+arrState_split[3];
						setval=document.funplotter.lat_long.value;
						document.funplotter.repeatd.value="yes";
						break;
						case "funplottertrip":
						document.funplottertrip.lat_long.value= arrState_split[2]+"/"+arrState_split[3];
						setval=document.funplottertrip.lat_long.value;
						document.funplottertrip.repeatd.value="yes";
						break;
						case "specialevent":
						document.specialevent.lat_long.value= arrState_split[2]+"/"+arrState_split[3];
						setval=document.specialevent.lat_long.value;
						document.specialevent.repeatd.value="yes";
						break;
						case "specialhtml":
						document.specialhtml.lat_long.value= arrState_split[2]+"/"+arrState_split[3];
						setval=document.specialhtml.lat_long.value;
						document.specialhtml.repeatd.value="yes";
						break;
						case "party":
						document.party.lat_long.value= arrState_split[2]+"/"+arrState_split[3];
						setval=document.party.lat_long.value;
						document.party.repeatd.value="yes";
						break;
						case "partyhtml":
						document.partyhtml.lat_long.value= arrState_split[2]+"/"+arrState_split[3];
						setval=document.partyhtml.lat_long.value;
						document.partyhtml.repeatd.value="yes";
						break;
					}
						alert("Latittude n longitude retrieved");
						WaitOff();	
					}
					else
					{
						alert("Funspot you provided could not be located on the map\nPlease enter address in the address box below, if available.");
						WaitOff();	
					}
					
				}
			}
			
		}
		
}