// JavaScript Document

//********************* Written by **********************************//
//*********************Adnan Siddiqi********************************//
//******************** URL: http://adnansiddiqi.com*************************//
	//Global Variable
	var req;
	var SResponse;
	var returnRecords=0;
	var returnData="";
	var arrId;



function putValue(myval,id,str)
	{
		if(str=='searchresult')	
		{
			document.getElementById('cities').value=myval;
			document.getElementById('city_name').value=myval;
			document.getElementById('txtcityname').value=myval.replace(/ /g,'_');
			//searchcityid(myval);
			FindCityId();
		}
		else
		{
			document.getElementById('citylist').selectedIndex=0;
			document.getElementById('cities').value=myval;
			document.getElementById('city_name').value=myval;
			document.getElementById('txttest_new').value=id;
			document.getElementById('CiTy').value=id;
		}
		//document.getElementById("suggest").style.display="none";
		//document.frmSearch.cityLonLat.value=lon+","+lat;
		
	}

function getHigh(objId)
{
	document.getElementById(objId).style.background= "#3366cc";
	document.getElementById(objId).style.cursor="default";
	document.getElementById(objId).style.color="White";
	document.getElementById(objId).style.border=2;
	
}

function getLow(objId)
{
	
	document.getElementById(objId).style.background= "#EFEFEF";
	document.getElementById(objId).style.color="black";

}


function getMap()
{
	var imgName=document.getElementById('proptype1').options[document.getElementById('proptype1').selectedIndex].text;
	var selectedImage="";
	switch (imgName){
		case "Gran Canaria": 
		selectedImage="grancanaria.jpg";
		break;
		case "La Gomera":
		selectedImage="lagomera.jpg";
		break;
		case "La Palma":
		selectedImage="lapalma.jpg";
		break;
		case "Lanzarote":
		selectedImage="lanzarote.jpg";
		break;
		case "Fuerteventura":
		selectedImage="fuerteventura.jpg";
		break;
		case "El Hierro":
		selectedImage="elhierro.jpg";
		break;
		default :
		selectedImage="tenerife.jpg";
}

	document.getElementById("imgMap").src="map/"+selectedImage;
	/* AJAX Function to Get Map Cordinates */
	var ind=eval(document.getElementById('proptype1').selectedIndex+1);
	var url="fetchCordinates.php?elem=" + escape(ind);
	//for non-IE browsers
		if(window.XMLHttpRequest)
			{
				req=new XMLHttpRequest();
			} else
			//IF  IE browsers
		if(window.ActiveXObject)
			{
				req=new ActiveXObject("Microsoft.XMLHTTP");
			}
		req.open("GET",url,true);
		req.onreadystatechange=parseMapCord;//call Back function
		req.send(null);
}
	

function parseMapCord()
	{
		if(req.readyState==4)
		{
			if(req.status==200) //for OK
				{
					SResponse=req.responseText;
					document.getElementById("divMapCord").innerHTML=SResponse;
				}
		}
	}
	
	
/************************* METHODS TO GET NEAR BY CITIES***********************************
/																						   
/******************************************************************************************/



//to fetch near by cities on Click
function getNearByCity()
{
	var cityName=document.frmSearch.cityName.value;
	var longLat=document.frmSearch.cityLonLat.value;
	var island=document.frmSearch.proptype1.value;
	cityName=cityName.replace(/^\s*|\s*$/g,"");//trim all spaces

	document.getElementById("divtitleCity").innerHTML=cityName;
	document.getElementById("divCitiesBullet").style.display="block";
		
	var url="fetchCities.php?elem=" + escape(longLat)+"&dist="+document.frmSearch.distance_required.value+"&island="+island;
	if(eval(document.frmSearch.cityName.value.length) > 0)
	{
		//for non-IE browsers
		if(window.XMLHttpRequest)
			{
				req=new XMLHttpRequest();
			} else
			//IF  IE browsers
		if(window.ActiveXObject)
			{
				req=new ActiveXObject("Microsoft.XMLHTTP");
			}
		req.open("GET",url,true);
		req.onreadystatechange=parseCities;//call Back function
		req.send(null);
	}
	
	
}

function parseCities()
	{
		if(req.readyState==4)
		{
			if(req.status==200) //for OK
				{
					SResponse=req.responseText;
					
					document.getElementById("divCities").innerHTML=SResponse;

				}
		}
	}

/******************************* MAP RELATED AJAX FUNCTIONS *******************************/
//fetch Cities via Map
/*
function map(city)
{
	alert(city);
	var cityName=city;
	var longLat=document.frmSearch.cityLonLat.value;
	var island=document.frmSearch.proptype1.value;
	//document.frmSearch.thisImage.src="maps/" + cityName + "tenerife.jpg";
	//alert(document.frmSearch.thisImage.src);
	cityName=cityName.replace(/^\s*|\s*$/g,"");//trim all spaces

	document.getElementById("divtitleCity").innerHTML=cityName;
	document.getElementById("divCitiesBullet").style.display="block";
	
	
	
	var url="fetchCities.php?elem=" + escape(longLat)+"&dist="+document.frmSearch.distance_required.value+"&island="+island;
	if(eval(document.frmSearch.cityName.value.length) > 0)
	{
		//for non-IE browsers
		if(window.XMLHttpRequest)
			{
				req=new XMLHttpRequest();
			} else
			//IF  IE browsers
		if(window.ActiveXObject)
			{
				req=new ActiveXObject("Microsoft.XMLHTTP");
			}
		req.open("GET",url,true);
		req.onreadystatechange=parseCities;//call Back function
		req.send(null);
	}
	
}
*/
function viewCities(city)
{
	//document.getElementById("dcity").innerHTML=city;
	document.getElementById("cities").value=city;
	document.getElementById('citylist').selectedIndex=0;	
}
 


function selectCity()
{
	document.getElementById("cities").value = document.getElementById('city_name').value;
}
