﻿var map;
function Initialise(z)
{
    if(document.getElementById && document.createElement)
    {        
        var strLocation = $('ddlCountry').options[$('ddlCountry').selectedIndex].value;
		if(strLocation == "UAE")
		{
			alert("Coming soon");
			location.href = "/";
		}

/*         var intZoom = 13;
        var intDist = 0;
 */  
		var intZoom = 13;
        var intDist = 0;
        
        map = new GMapCreator("map",strLocation,intDist,intZoom,true);


           $('btnFindStores').onclick = function() 
		   {
			var strLocation;
			var strLandmark ;
//			alert($('chkstation').checked)
			if($('chkstation').checked)
			{
 			    strLandmark = $('landmarktxt').value + " station";
				if(strLandmark.indexOf('Landmark or Station')>0)
				{
					strLandmark = '';
				}
			}
			else
			{
				
				strLandmark = $('landmarktxt').value
				if(strLandmark.indexOf('Landmark or Station') > 0)
				{
					strLandmark = '';
				}
		    }
//			alert(strLandmark);
			if (strLandmark!="")
			{
				var strCountry = $('ddlCountry').options[$('ddlCountry').selectedIndex].value;
				var intDist = $('ddlRadius').options[$('ddlRadius').selectedIndex].value;
				if (strCountry!=0)
				{
					strLocation = strLandmark +','+strCountry;
				}
				else
				{
					strLocation = strLandmark;
				}
				
				map.findStores(strLocation,strCountry,intDist,17);return false;
			}
			else
			{
				test(z)
			}
		}



		var condTube = z.length;

		if(typeof condTube!='undefined')
		{
				var strLocation;	
				var tmpValues = z.split("|")				
			    var strCountry = tmpValues[1]
//				var intDist = 1
				var intDist = 0.5
				if (strCountry!=0)
				{
					strLocation = tmpValues[0] +','+strCountry;
				}
				else
				{
					strLocation = tmpValues[0] ;
				}

//				alert('inside the ')
				map.findStores(strLocation,strCountry,intDist,17);return false;
		}
 
    }
test(z);
}


	function test(zoom)
	{
			
	
			var strCountry = $('ddlCountry').options[$('ddlCountry').selectedIndex].value;
            var strRegion = $('ddlRegion').options[$('ddlRegion').selectedIndex].value;
            var strLoc = $('ddlLocation').options[$('ddlLocation').selectedIndex].value;
            var strStore = $('ddlOffices').options[$('ddlOffices').selectedIndex].value;
            
         	
			if (strCountry!=0)
			{
		 		if(strCountry != undefined){strCountry = strCountry}
			}
			else
			{
				strCountry = '';
			}

			if (strRegion!=0)
			{
		 		if(strRegion != undefined){strRegion = strRegion + ","}
			}
			else
			{
				strRegion = '';
			}
			
			if (strLoc!=0)
			{
		 		 if(strLoc != undefined){strLoc = strLoc + ","}
			}
			else
			{
				strLoc = '';
			}
			if (strStore!=0)
			{
		 		 if(strStore != undefined){strStore = strStore + ","}
			}
			else
			{
				strStore = '';
			}
			
//           alert('coutry=' + strCountry +'region='+ strRegion +'location'+ strLoc + 'store' +strStore)
           
						

//            var strLocation = strStore + strRegion + strLoc + strCountry ;
			var strLocation = strStore + strLoc + strRegion + strCountry ;
	        var intDist = $('ddlRadius').options[$('ddlRadius').selectedIndex].value;
			var intDist = '';
            map.findStores(strLocation,strCountry,intDist,zoom);return false;
		}


function tt(z)
{
	Initialise(z);

}