            ///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 1<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
            //Global Variables
			//var ourHomePage="http://localhost/feenfemasr/GoogleMapWork/";
			var h;
			var urlContactUs="";
			//
			var specialCharArr=[];
			specialCharArr[0]=";";
			specialCharArr[1]="<->";
			specialCharArr[2]="/*/";
			specialCharArr[3]="*";
			specialCharArr[4]="<";
			specialCharArr[5]=">";
			specialCharArr[6]="&";
			specialCharArr[7]="@";
			specialCharArr[8]="$";
			specialCharArr[9]="%";
			specialCharArr[10]="^";
			specialCharArr[11]="(";
			specialCharArr[12]=")";
			specialCharArr[13]="!";
			specialCharArr[14]="?";
			specialCharArr[15]="#";
			specialCharArr[16]=" ";
			specialCharArr[17]="~";

			
			//
			var Mansoura = new google.maps.LatLng(31,31.19);
			var EgyptCenter = new google.maps.LatLng(30.12142760422581, 31.69189453125001);
			var map;
			var CityLatLng= new google.maps.LatLng(0,0);
			////
			var txtbox;
			//
			var pointObject=[];
			var pointCount=0;
			var htmlContent='<div id="pointName">Name: </div>';
			var branchPointObject=[];
			var branchPointCount=0;
			//
			var wayPoint=[];
			var wayPointGenrateLink=[];
			var wayPointDivArr=[];	
			var wayPointCount=0;
			var validWayPointCount=0;
			var currentWayPointLocation=new google.maps.LatLng(0,0);
			var currentAnyLocation=new google.maps.LatLng(0,0);
			var startRoute=new google.maps.LatLng(0,0);
			var endRoute=new google.maps.LatLng(0,0);
			//
			//
			var domainName="feen_"+governorate;
			var category='health';
			var subcategoryId;			
			//
			var startPos = new google.maps.Marker();
	        var endPos = new google.maps.Marker();
			//
            var directionsDisplay = new google.maps.DirectionsRenderer();
			var directionsService = new google.maps.DirectionsService();
			//
			var resultDivArr=[];
			var lastResultRecord=0;
			var pageResultNumber=0;
			//
			var contextmenuDiv;
			var directionflag=false;
			//
/////////////////////////////////////////////////////////////////////////////////////////////////////////		
/////////////////////////////////////////////META DATA PART//////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////	
			var ComboOpt="";
			var fieldName=[];
			var values=[]; 
			var required;
			var valid=true;
/////////////////////////////////////////////////////////////////////////////////////////////////////////		
/////////////////////////////////////////////META DATA PART//////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////	
			function cityMap(city)
			{
				//alert(city);
				var cityInfo = city.split("<->");
				CityLatLng=new google.maps.LatLng(cityInfo[1],cityInfo[2]);
				//
				showSearchPart();
				//
				getControlsFromMetaData();
				//
				//initializeMap();
				//Navigation
				//showSearchPart();
				//
			}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            ///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 2<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
            //Startup Function
			function initializeMap() 
			{
				//alert("1");
				//var mTCO=("ROADMAP","HYBRID","SATELLITE")
				//
			
				if(document.getElementById("ss") !=null)
				{
				document.getElementById("ss").style.display='none';
				}
				if(document.getElementById("map_canvas") !=null)
				{
				document.getElementById("map_canvas").style.display='block';
				//
				var mapTypes = [];
				mapTypes.push(google.maps.MapTypeId.ROADMAP);
				mapTypes.push(google.maps.MapTypeId.SATELLITE);
				mapTypes.push(google.maps.MapTypeId.HYBRID);
				//
				var myOptions = 
				{
					zoom: 6,
					center: EgyptCenter,
					mapTypeId: google.maps.MapTypeId.ROADMAP,
					//mapTypeControl: true,
					mapTypeControlOptions: 
					{
    					//style: google.maps.MapTypeControlStyle.DROPDOWN_MENU,
						mapTypeIds: mapTypes
  					} 
				}
				//
				map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
				//
				var EgyptSouthWest=new google.maps.LatLng(21.313629689561335, 24.61669921875001);
				var EgyptNorthEast=new google.maps.LatLng(32.67979121469283, 35.822753906250014);
				var EgyptBounds = new google.maps.LatLngBounds(EgyptSouthWest,EgyptNorthEast);
                //map.fitBounds(EgyptBounds);
				//
				directionsDisplay.setMap(map);
				google.maps.event.addListener(map, 'rightclick', function(event)
				{
					currentWayPointLocation = new google.maps.LatLng(event.latLng.lat(),event.latLng.lng());
					currentAnyLocation = new google.maps.LatLng(event.latLng.lat(),event.latLng.lng());
					showAddContextMenu(event.latLng);
				});
				//
				google.maps.event.addListener(startPos, 'rightclick', function()
				{
					showDeleteAnypointContextMenu(startPos);
				});
				//
				google.maps.event.addListener(endPos, 'rightclick', function()
				{
					showDeleteAnypointContextMenu(endPos);
				});
				//
				google.maps.event.addListener(map, 'click', function()
				{
					if(contextmenuDiv != null)
					{
						contextmenuDiv.style.visibility = "hidden";
					}
					//
					for(ipranch=0;ipranch<branchPointCount;ipranch++)
					{
						branchPointObject[ipranch].infowindow.close();	
					}
					//
					for(ipoint=0;ipoint<pointCount;ipoint++)
					{
						pointObject[ipoint].infowindow.close();	
					}
				});
				//
				document.getElementById("toRoute").value="";
				document.getElementById("fromRoute").value="";
				//document.getElementById("txtSearch").value="";
                // Create the DIV to hold the control and
                // call the HomeControl() constructor passing
                // in this DIV.
                var WaterMarkControlDiv = document.createElement('DIV');
                var waterMarkControl = new WaterMark(WaterMarkControlDiv, map);

                WaterMarkControlDiv.index = 1;
                map.controls[google.maps.ControlPosition.TOP].push(WaterMarkControlDiv); 
				//
				//applyLink();	
				//
				}
			}
            ///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 3<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
            function WaterMark(controlDiv, map)
            {

                // Set CSS styles for the DIV containing the control
                // Setting padding to 5 px will offset the control
                // from the edge of the map
                controlDiv.style.padding = '5px';
                // Set CSS for the control border
                var controlUI = document.createElement('DIV');
                controlUI.style.cursor = 'pointer';
                controlUI.style.textAlign = 'center';
                controlUI.title = 'This is FeenFeMasr';
                //controlUI.innerHTML = '<img src="'+ourHomePage+'Logo/1.png"></img>';
                controlDiv.appendChild(controlUI);
                // Setup the click event listeners: simply set the map to

                google.maps.event.addDomListener(controlUI, 'click', function()
                {
                  //  map.setCenter(chicago)
						//alert("hi");
                });

            }			
            ///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 4<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
			function removeStart_EndPoint(markerIndex)
			{
				if(markerIndex==0)
				{
				    startPos.setMap(null);
                	startPos.setPosition(null);
					//
					//document.getElementById("fromRoute").value="";
					//
					if(contextmenuDiv!=null)
					{
						contextmenuDiv.style.visibility = "hidden";	
					}
				}
				else if(markerIndex==1)
				{
					endPos.setMap(null);
					endPos.setPosition(null);
					//
					//document.getElementById("toRoute").value="";
					//
					if(contextmenuDiv!=null)
					{
						contextmenuDiv.style.visibility = "hidden";	
					}	
				}		
			}
			////////////////////////////////////////////////////////////////////
			///////////for deleting the textbox according to the delete on the context menu//////////////////////////////////////
			////////////////////////////////////////////////////////////////////
			function removeStart_EndPoint2(markerIndex)
			{
				if(markerIndex==0)
				{
				    startPos.setMap(null);
                	startPos.setPosition(null);
					//
					document.getElementById("fromRoute").value="";
					//
					if(contextmenuDiv!=null)
					{
						contextmenuDiv.style.visibility = "hidden";	
					}
				}
				else if(markerIndex==1)
				{
					endPos.setMap(null);
					endPos.setPosition(null);
					//
					document.getElementById("toRoute").value="";
					//
					if(contextmenuDiv!=null)
					{
						contextmenuDiv.style.visibility = "hidden";	
					}	
				}		
			}
			////////////////////////////////////////////////////////////////////
		    ///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 5<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
			
			//delete way point
			function removeWayPointDiv(i)
			{
				
				 
				
				var fromvar = document.getElementById('fromRoute').value;
				var tovar = document.getElementById('toRoute').value;
				
				//alert(i);
				var tbl = document.getElementById('table1').innerHTML;
				//alert(tbl);
				var rowstart = tbl.indexOf('<tr id="waypoint'+i+'">');
				//alert(rowstart);
				var beforrow = tbl.substring(0,rowstart);
				//alert(beforrow);
				var fromrow = tbl.substring(rowstart,tbl.length);
				//alert(fromrow);
				var endrow = fromrow.indexOf('</tr>');
				//alert(endrow);
				var afterrow = fromrow.substring(endrow+5,fromrow.length);
				//alert(afterrow);
				
				document.getElementById('table1').innerHTML = beforrow + afterrow;
				
				document.getElementById('fromRoute').value = fromvar;
				document.getElementById('toRoute').value = tovar;
				wayPointDivArr[i]="";
				//alert('0000000000000000');
				
				validWayPointCount--;
					//remove from array way point
					wayPointCount--;
					//alert(wayPointCount);
					//
					wayPoint[i].marker.setMap(null);
					wayPoint[i].marker.setPosition(null)

					wayPoint[i].stopover=false;
					//
					contextmenuDiv.style.visibility = "hidden";
					calcRoute(startPos,endPos);
					//renderWayPoint();
					//----------------if(contextmenuDiv != null)
					//{
						//contextmenuDiv.style.visibility = "hidden";
					//}
					//
					
					//validWayPointCount--;
					//remove from array way point
					//wayPointCount--;
					//alert("way point is");
					//alert("validWayPointCount"+validWayPointCount);
					//
					//alert('koko');
				if((endPos.getPosition()!=null) && (startPos.getPosition()!=null) && !(endPos.getPosition().equals(startPos.getPosition()) ) )
				{
					//
					//alert("kkkkk");
					calcRoute(startPos,endPos);
					
				}
				
				
			}
			///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 6<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
            //Function responsible for getting point in runtime in db using ajax
			function getAllPoint(str)
			{
				//Ajax Part
				//Create a boolean variable to check for a valid Internet Explorer instance.
				var xmlhttp = false;
				//Check if we are using IE.
				try 
				{
					//If the Javascript version is greater than 5.
					xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		
				} 
				catch (e) 
				{
					//If not, then use the older active x object.
					try 
					{
						//If we are using Internet Explorer.
						xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		
					} 
					catch (E) 
					{
						//Else we must be using a non-IE browser.
						xmlhttp = false;
					}
				}
				//If we are using a non-IE browser, create a javascript instance of the object.
				if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
				{
					xmlhttp = new XMLHttpRequest();
				}
				//
				//preparing request url	
				
				var url1=ourHomePage+"php/select_from_server.php";
				var dom="feen_"+governorate+"_"+subCategory;
				url1=url1+'?tableName='+dom;
				url1=url1+'&subCategory='+subCategory;
				url1=url1+'&Name='+str;
				url1=url1+'&sid='+Math.random();
				//sending reques
				//
				document.getElementById("searchResultCount").innerHTML="";
				document.getElementById("searchResultCount").innerHTML="<Center><img src='"+ourHomePage+"loading/ajax-loader1.gif'/></Center>";
				//
				xmlhttp.open("GET",url1);
				//getting result as string of data
				xmlhttp.onreadystatechange = function()
				{
					if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
					{
						//spliting result string to be rendered on the map
						if (xmlhttp.responseText== "")
						{
							//alert("There is no Result for your search");
							//
							document.getElementById('SearchResultDiv').innerHTML="";
							//
							document.getElementById("searchResultCount").innerHTML="";
							document.getElementById("searchResultCount").innerHTML="<label>نتائج البحث :( "+0+" )</label>";
							//ذ
							//document.getElementById("showDirectionPartLink").style.visibility = "visible";
						}
						else
						{
						//
							splitAllPointsQuerry(xmlhttp.responseText);
							//
							document.getElementById("searchResultCount").innerHTML="";
							//
							document.getElementById('SearchResultDiv').innerHTML="";
							ResultsDiv=document.getElementById('SearchResultDiv');
							drawSearchResultDiv(pointObject,ResultsDiv);
							//
							focusMap();
							//
							//document.getElementById("toRoute").value="";
							//document.getElementById("fromRoute").value="";
							//
						}
					}
					else if (xmlhttp.readyState != 4)
					{
						document.getElementById("searchResultCount").innerHTML="";
						document.getElementById("searchResultCount").innerHTML="<Center><img src='"+ourHomePage+"loading/ajax-loader1.gif'/></Center>";
					}
				}
				xmlhttp.send(null);
				//end of Ajax 
			}
			///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 7<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
            //Function responsible for splitting reult string and draw marker
			function splitAllPointsQuerry(QuerryResult)
			{
				var points = QuerryResult.split("/*/");
				pointCount=points.length-1;
				
				for(p=0;p<points.length-1;p++)
				{
					var pointAttr = points[p].split("<->");
					pointObject[p]=new Object();
					var location = new google.maps.LatLng(pointAttr[2],pointAttr[3]);
					var image=ourHomePage+"markerIcons/"+(p+1)+".png";
					var marker = new google.maps.Marker(
					{
						position: location,
						title: pointAttr[1],
						map: map,
						icon: image,
						zIndex: 1000
					});
					//
					var startLink="<a id='infowindw' href='javascript:void(0);' onClick='setStartRoute("+p+")'>مـن</a>";
					var endLink="<a id='infowindw' href='javascript:void(0);' onClick='setEndRoute("+p+")'>الي</a>";
					infowindow = new google.maps.InfoWindow(
					{
						//<center><label id='infolabelTitle'>"+ pointAttr[1]+
						content:pointAttr[4]+"<center><div>"+startLink+"	"+endLink+"</div></center>",
						size: new google.maps.Size(50,50),
						position: location 
					});
					//
					pointObject[p].id=pointAttr[0];
					pointObject[p].title=pointAttr[1];
					pointObject[p].marker=marker;
					pointObject[p].infowindow=infowindow;
					pointObject[p].listener = makeClosure(p, pointObject[p].marker) ;
					pointObject[p].details=pointAttr[4];
					pointObject[p].noOfBranchs=0;
					pointObject[p].branches="";
					//					
				}
				//
				for(iget=0;iget<pointCount;iget++)
				{
						getBranch(pointObject[iget].id,iget);
				}							
			}
			///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 8<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
            //Function responsible for adding event to each point
			function makeClosure( i, marker )
			{
				var listener = google.maps.event.addListener(marker, 'click', function()
				{
					for(countInfo=0;countInfo<pointObject.length;countInfo++)
					{
					pointObject[countInfo].infowindow.close();	
					}
					pointObject[i].infowindow.open(map,pointObject[i].marker) ; 	// <-- this is the key to making it work
					//
					if(contextmenuDiv!=null)
					{
						contextmenuDiv.style.visibility = "hidden";	
					}
				});
				//				
				return listener ;
			}
			///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 9<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
            //Function responsible for resetting map			
			function clearPoints()
			{
				for(ipointcount=0;ipointcount<pointCount;ipointcount++)
				{
					pointObject[ipointcount].location="";
					pointObject[ipointcount].marker.setMap(null);
					pointObject[ipointcount].infowindow.close();	
					pointObject[ipointcount].marker="";
					
					pointObject[ipointcount].infowindow="";
					
					pointObject[ipointcount].id="";
					pointObject[ipointcount].title="";
					pointObject[ipointcount].details="";
					
					resultDivArr[ipointcount]="";
				}
				//
				lastResultRecord=0;
				resultDivArr=[];
				pointCount=0;
				validWayPointCount=0;
				//document.getElementById('SearchResultDiv').innerHTML="";
			}
			
			//////////////////////////////////////////////////////////////////////////////
			///////////////////////////////////////////////function to clear blue flag?/////////////////////
			function clearFlags()
			{
				for(iflag=0;iflag<pointCount;iflag++)
				{
					//pointObject[iflag].location="";
					pointObject[iflag].marker.setMap(null);
					//pointObject[iflag].infowindow.close();	
					//pointObject[iflag].marker="";
					
					//pointObject[iflag].infowindow="";
					
					//pointObject[iflag].id="";
					//pointObject[iflag].title="";
					//pointObject[iflag].details="";
					
					//resultDivArr[iflag]="";
				}
				//
				lastResultRecord=0;
				resultDivArr=[];
				//pointCount=0;
				validWayPointCount=0;
				//document.getElementById('SearchResultDiv').innerHTML="";
			}
			///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 10<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
            //Function responsible for searching of text	
			function search()
			{
				if(txtbox==null)
				{
					txtbox='';
				}
				document.getElementById('SearchResultDiv').innerHTML="";
				if(document.getElementById("controlsDiv").style.display=="inline")
				{
					directionsDisplay.setMap(null);
					directionsDisplay.setPanel(null);
					//
					clearPoints();
					clearBranchPoints();
					//					
					getDataFromControls();
					//
					showSearchResultPart();
				}
			}
			///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 11<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
            //Function responsible for Filtering searching of text
			function filterSearchTxt(txt)
			{
				var txtAfterFilter=txt;
				for(i=0;i<specialCharArr.length;i++)
				{
					var letter=specialCharArr[i];
					//
					if(txtAfterFilter.indexOf(letter)>0)
					{
						txtAfterFilter=txtAfterFilter.replace(letter,"");
					}
				}
				//
				return txtAfterFilter;
			}
			///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 12<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
            //Function responsible for checking if searching of text contain special character
			function containSpecialChar(txt)
			{
				var result = false;
				for(ispecial=0;ispecial<specialCharArr.length;ispecial++)
				{
					var letter=specialCharArr[ispecial];
					//
					if(txt.indexOf(letter)>0)
					{
						result=true;
					}
				}
				//
				return result;
			}
            ///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 13<-------------------------------
            ///////////////////////////////////////////////////////////////////////////
			function drawSearchResultDiv(pointObject,ResultsDiv)
			{
				//pointCount=7;
				ResultsDiv.innerHTML="";
				//
				document.getElementById("searchResultCount").innerHTML="";
				document.getElementById("searchResultCount").innerHTML="<label> نتائج البحث ( "+pointCount+" )</label>";
				//
				for(icount=0;icount<pointCount;icount++)
				{
					resultDivArr[icount]="";
					//<li>
					divStr="<Left><div id='divId"+icount+"'";
					divStr+="onmouseover='addEffect(this.id)' "; 
					divStr+="onmouseout='removeEffect(this.id)'";
					divStr+=">";
					//tilte link
					divStr+="<a href='javascript:void(0);'"; 
					divStr+="id='pointDiv"+pointObject[icount].id+"'"; 
					divStr+="onClick='focusPoint(this.id)'>";
					divStr+=(icount+1)+"- "+pointObject[icount].title +"</a>";
					//details
					divStr+="<br>";//pointObject[i].details;
					//start & end links
					var startLink="<a href='javascript:void(0);' onClick='setStartRoute("+icount+")'>مـن</a>";
					var endLink="<a href='javascript:void(0);' onClick='setEndRoute("+icount+")'>الي</a>";
					divStr+="<br>";
					divStr+="<img id='imageflagsmall' onClick='setStartRoute("+icount+")' src='"+ourHomePage+"markerIcons/Start.png'/> &nbsp;"+startLink+"			"+"<img id='imageflagsmall' onClick='setEndRoute("+icount+")' src='"+ourHomePage+"markerIcons/End.png'/>&nbsp;"+endLink;
					//alert(pointObject[i].noOfBranchs);
					//
					divStr+="			";
					divStr+="<img id='pointDiv"+pointObject[icount].id+"' class='moreinfo' onClick='focusPoint(this.id)' src='"+ourHomePage+"markerIcons/moreinfo.png'/> &nbsp;";
					divStr+="<a id='pointDiv"+pointObject[icount].id+"'  href='javascript:void(0);'  onClick='focusPoint(this.id)'>معلومات اضافيه</a>";					
					//		
					divStr+="</div><br></Left>";
					//</li>
					resultDivArr[icount]=divStr;
				}
				pageResultNumber=1;	
				renderSearchResultDiv(ResultsDiv,4);
				//
			}
            ///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 14<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
			function renderSearchResultDiv(ResultsDiv,shiftMove)
			{
				if(resultDivArr.length>0)
				{
					ResultsDiv.innerHTML="";
					var txt="";
					//in case of back mode
					if(shiftMove<0)
					{
						lastResultRecord+=(2*shiftMove);
						shiftMove*=-1;
					}
					//
					var finalResultRecord=lastResultRecord+shiftMove;
					if(finalResultRecord>resultDivArr.length)
					{
						finalResultRecord=resultDivArr.length;
					}
					//
					//
					for(imarker=0;imarker<pointCount;imarker++)
					{
						pointObject[imarker].marker.setMap(null);
					}
					//
					txt+="<ul>";
					for(ilastresult=lastResultRecord;ilastresult<finalResultRecord;ilastresult++)
					{
						txt+=resultDivArr[ilastresult];
						//
						pointObject[ilastresult].marker.setMap(map);
					}
					txt+="</ul>";
					//
					var nextResult="<a href='javascript:void(0);' onclick='moveNext()'>التالى</a>";
					var prevResult="<a href='javascript:void(0);' onclick='moveBack()'>السابق</a>";
					//case of first render
					if((lastResultRecord==0) && (finalResultRecord<resultDivArr.length))
					{
						txt+="<br>"+nextResult;
					}
					//case of Last render
					else if((lastResultRecord>0) && ((lastResultRecord+shiftMove)>=resultDivArr.length))
					{
						txt+="<br>"+prevResult;
					}
					//case of middle render
					else if((lastResultRecord>0) && ((lastResultRecord+shiftMove)<resultDivArr.length))
					{
						txt+="<br>"+prevResult+"			"+nextResult;
					}
					txt+="</Left>";
					// الصفحات مـن 1 الى 2 postion
					txt+="<br><center><label id='pages'>الصفحات مـن  "+pageResultNumber+" الى "+(Math.ceil(resultDivArr.length/4))+"</label></center>";
					//
					ResultsDiv.innerHTML=txt;
					lastResultRecord+=shiftMove;
				}
			}
//****************************************************************************************************************************

			function getBranch(mainBranchId,i)
			{
				
				//Create a boolean variable to check for a valid Internet Explorer instance.
				var xmlhttp = false;
				//Check if we are using IE.
				try 
				{
					//If the Javascript version is greater than 5.
					xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		
				} 
				catch (e) 
				{
					//If not, then use the older active x object.
					try 
					{
						//If we are using Internet Explorer.
						xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		
					} 
					catch (E) 
					{
						//Else we must be using a non-IE browser.
						xmlhttp = false;
					}
				}
				//If we are using a non-IE browser, create a javascript instance of the object.
				if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
				{
					xmlhttp = new XMLHttpRequest();
				}
				//
				//preparing request url
				//tableName
				var url1=ourHomePage+"php/SelectBranch.php";
				var dom="feen_"+governorate+"_"+subCategory;
				url1=url1+'?tableName='+dom;
				url1=url1+'&mainBranchId='+mainBranchId;
				url1=url1+'&subCategory='+subCategory;
								
				url1=url1+'&subCategoryId='+subcategoryId;
				url1=url1+'&sid='+Math.random();
				//sending request
				xmlhttp.open("GET",url1);
				//getting result as string of data
				xmlhttp.onreadystatechange = function()
				{
					if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
					{
						//spliting result string to be rendered on the map
						//alert(xmlhttp.responseText);
						if (xmlhttp.responseText!="")
						{
							//
							pointObject[i].noOfBranchs=1;
							pointObject[i].branches=xmlhttp.responseText;
							//alert(i+" --> "+pointObject[i].noOfBranchs);
						} 
					}
				}
				xmlhttp.send(null);
				//end of Ajax	
			}
//
//branchPointCount
//branchPointObject
//
			function splitAllBranchPointsQuerry(i)
			{
				var QuerryResult=pointObject[i].branches;
				//
				clearBranchPoints();
				//
				var points = QuerryResult.split("/*/");
				branchPointCount=points.length-1;
				
				for(p=0;p<points.length-1;p++)
				{
					var pointAttr = points[p].split("<->");
					branchPointObject[p]=new Object();
					var location = new google.maps.LatLng(pointAttr[2],pointAttr[3]);
					var image=ourHomePage+"markerIcons/Branch.png";
					var markerTitle=pointObject[i].title;
					
					//alert(markerTitle);
					var marker = new google.maps.Marker(
					{
						position: location,
						title:  pointAttr[1],
						map: map,
						icon: image,
						zIndex: 1000
					});
					//
					var startLink="<a id='infowindw' href='javascript:void(0);' onClick='setStartRouteForBranch("+p+")'>مـن</a>";
					var endLink="<a id='infowindw' href='javascript:void(0);' onClick='setEndRouteForBranch("+p+")'>الي</a>";
					infowindow = new google.maps.InfoWindow(
					{
						content: markerTitle+"<center><div>"+startLink+"	"+endLink+"</div></center>",
						size: new google.maps.Size(50,50),
						position: location 
						//setOptions({maxWidth:500;});
						
					});
					
					//
					branchPointObject[p].id=pointAttr[0];
					branchPointObject[p].title=pointAttr[1];
					branchPointObject[p].marker=marker;
					branchPointObject[p].infowindow=infowindow;
					branchPointObject[p].listener = makeBranchClosure(p, branchPointObject[p].marker) ;
					branchPointObject[p].details=pointAttr[4];
				}
				
			}

			function makeBranchClosure( i, marker )
			{
				var listener = google.maps.event.addListener(marker, 'click', function()
				{
					branchPointObject[i].infowindow.open(map,branchPointObject[i].marker) ; 	
					//
					if(contextmenuDiv!=null)
					{
						contextmenuDiv.style.visibility = "hidden";	
					}
				});
				//				
				return listener ;
			}
			
			
			function clearBranchPoints()
			{
				for(ibranchpoint=0;ibranchpoint<branchPointCount;ibranchpoint++)
				{
					
					branchPointObject[ibranchpoint].marker.setMap(null);
					branchPointObject[ibranchpoint].infowindow.close();	
					branchPointObject[ibranchpoint].marker="";
					
					branchPointObject[ibranchpoint].infowindow="";
					
					branchPointObject[ibranchpoint].id="";
					branchPointObject[ibranchpoint].title="";
					branchPointObject[ibranchpoint].details="";
					

				}
				//
				branchPointCount=0;
			}


			function setStartRouteForBranch(num)
			{
				startLocationX=branchPointObject[num].marker.getPosition().lat();
				startLocationY=branchPointObject[num].marker.getPosition().lng();
				//
				startPos.setPosition(new google.maps.LatLng(startLocationX,startLocationY));	
				startPos.setMap(map);
				//
				var image=ourHomePage+"markerIcons/"+"Start.png";
				startPos.setIcon(image);
				//
				for(i=0;i<branchPointCount;i++)
				{
					branchPointObject[i].infowindow.close();
					//
					if((branchPointObject[i].marker.getPosition().lat()==startLocationX)&&(branchPointObject[i].marker.getPosition().lng()==startLocationY))
					{
						document.getElementById("fromRoute").value=branchPointObject[i].title;
						//document.getElementById("toRoute").value="";
					}
				}
				//
				if((endPos.getPosition()!=null) && (startPos.getPosition()!=null) && !(endPos.getPosition().equals(startPos.getPosition()) ) )
				{
					showDirectionPart();
					//
					calcRoute(startPos,endPos);
				}
				else
				{
					removeStart_EndPoint(1);
				}				
				
			}	
			///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 21<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
            //setting start point
			function setEndRouteForBranch(num)
			{
				endLocationX=branchPointObject[num].marker.getPosition().lat();
				endLocationY=branchPointObject[num].marker.getPosition().lng();
				//
				endPos.setPosition(new google.maps.LatLng(endLocationX,endLocationY));
				endPos.setMap(map);				
				//
				var image=ourHomePage+"markerIcons/"+"End.png";
				endPos.setIcon(image);
				//				
				for(ibranchPoint2=0;ibranchPoint2<branchPointCount;ibranchPoint2++)
				{
					branchPointObject[ibranchPoint2].infowindow.close();
					//
					if((branchPointObject[ibranchPoint2].marker.getPosition().lat()==endLocationX)&&(branchPointObject[ibranchPoint2].marker.getPosition().lng()==endLocationY))
					{
						document.getElementById("toRoute").value=branchPointObject[ibranchPoint2].title;
					}
				}
				//
				if((endPos.getPosition()!=null) && (startPos.getPosition()!=null) && !(endPos.getPosition().equals(startPos.getPosition()) ) )
				{
					showDirectionPart();
					//
					calcRoute(startPos,endPos);
				}
				else
				{
					removeStart_EndPoint(0);				
				}
			}



			function showBranchsLink()
			{
				for(ipointCount3=0;ipointCount3<pointCount;ipointCount3++)
				{	
					var branchLink="branchLink_"+ipointCount3;
					//
					if(document.getElementById(branchLink) != null)
					{
						if(pointObject[ipointCount3].noOfBranchs>0)
						{	
							document.getElementById(branchLink).style.visibility="visible";			
						}
					}
					//
					//alert(i+" --> "+pointObject[i].noOfBranchs);	
				}	
			}


//********************************************************************************************************************************			
			///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 15<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
			//
			function moveNext()
			{
				ResultsDiv=document.getElementById('SearchResultDiv');
				//
				pageResultNumber++;
				//
				renderSearchResultDiv(ResultsDiv,4);
				//
				clearBranchPoints();
				//
				showBranchsLink();	
			}
			///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 16<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
			//
			function moveBack()
			{
				ResultsDiv=document.getElementById('SearchResultDiv');
				//
				pageResultNumber--;
				//
				renderSearchResultDiv(ResultsDiv,-4);
				//
				clearBranchPoints();
				//
				showBranchsLink();					
			}
			///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 17<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
			//
			function addEffect(divId)
			{
				myDiv=document.getElementById(divId);
				//AliceBlue.
				//myDiv.style.backgroundColor="Gainsboro";
				//myDiv.className = 'menu14';
				
			}
			///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 18<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
			//
			function removeEffect(divId)
			{
				myDiv=document.getElementById(divId);
				//
				//myDiv.style.backgroundColor="WHITE";
				
			}
			///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 19<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
            //Function responsible focusing of search result
			function focusPoint(pointId)
			{
				pointId=pointId.replace("pointDiv","");
				//
				for(ipointCount4=0;ipointCount4<pointCount;ipointCount4++)
				{
					//pointObject[i].marker.setMap(null);
					pointObject[ipointCount4].infowindow.close();
				}
				//
				for(ipointCount5=0;ipointCount5<pointCount;ipointCount5++)
				{
					if(pointObject[ipointCount5].id==pointId)
					{
						prevPoint=new google.maps.LatLng(pointObject[ipointCount5].marker.getPosition().lat()-.005,pointObject[ipointCount5].marker.getPosition().lng()-.005);
						nextPoint=new google.maps.LatLng(pointObject[ipointCount5].marker.getPosition().lat()+.005,pointObject[ipointCount5].marker.getPosition().lng()+.005);
						mapBounds = new google.maps.LatLngBounds(prevPoint,nextPoint);
                		map.fitBounds(mapBounds);
						//
						pointObject[ipointCount5].marker.setMap(map);
						map.setCenter(pointObject[ipointCount5].marker.getPosition());
						pointObject[ipointCount5].infowindow.open(map,pointObject[ipointCount5].marker);
					}
				}
			}
			///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 20<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
			function setStartRoute(num)
			{
				startLocationX=pointObject[num].marker.getPosition().lat();
				startLocationY=pointObject[num].marker.getPosition().lng();
				//
				startPos.setPosition(new google.maps.LatLng(startLocationX,startLocationY));	
				startPos.setMap(map);
				startPos.setTitle("1");
				//
				var image=ourHomePage+"markerIcons/"+"Start.png";
				startPos.setIcon(image);
				//
				for(i=0;i<pointCount;i++)
				{
					pointObject[i].infowindow.close();
					//
					if((pointObject[i].marker.getPosition().lat()==startLocationX)&&(pointObject[i].marker.getPosition().lng()==startLocationY))
					{
						document.getElementById("fromRoute").value=pointObject[i].title;
						if(document.getElementById("fromRoute").value==document.getElementById("toRoute").value)
						{
						document.getElementById("toRoute").value="";
						}
						//document.getElementById("toRoute").value="";
					}
				}
				//
				if((endPos.getPosition()!=null) && (startPos.getPosition()!=null) && !(endPos.getPosition().equals(startPos.getPosition()) ) )
				{
					showDirectionPart();
					//
					calcRoute(startPos,endPos);
				}
				else
				{
					removeStart_EndPoint(1);
				}				
				
			}	
			///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 21<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
            //setting start point
			function setEndRoute(num)
			{
				endLocationX=pointObject[num].marker.getPosition().lat();
				endLocationY=pointObject[num].marker.getPosition().lng();
				//
				endPos.setPosition(new google.maps.LatLng(endLocationX,endLocationY));
				endPos.setMap(map);				
				endPos.setTitle("2");
				//
				var image=ourHomePage+"markerIcons/"+"End.png";
				endPos.setIcon(image);
				//				
				for(ipointCount6=0;ipointCount6<pointCount;ipointCount6++)
				{
					pointObject[ipointCount6].infowindow.close();
					//
					if((pointObject[ipointCount6].marker.getPosition().lat()==endLocationX)&&(pointObject[ipointCount6].marker.getPosition().lng()==endLocationY))
					{
						document.getElementById("toRoute").value=pointObject[ipointCount6].title;
						if(document.getElementById("toRoute").value==document.getElementById("fromRoute").value)
						{
						document.getElementById("fromRoute").value="";
						}
					}
				}
				//
				if((endPos.getPosition()!=null) && (startPos.getPosition()!=null) && !(endPos.getPosition().equals(startPos.getPosition()) ) )
				{
					showDirectionPart();
					//
					calcRoute(startPos,endPos);
				}
				else
				{
					removeStart_EndPoint(0);				
				}
			}
			
			
			
			///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 22<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
			function setStartRouteAnyPoint()
			{
				startLocationX=currentAnyLocation.lat();
				startLocationY=currentAnyLocation.lng();
				//
				startPos.setPosition(new google.maps.LatLng(startLocationX,startLocationY));
				startPos.setMap(map);
				startPos.setTitle("1");
				//
				var image=ourHomePage+"markerIcons/"+"Start.png";
				startPos.setIcon(image);
				//
				document.getElementById("fromRoute").value=startPos.getPosition();		
				//alert(document.getElementById("fromRoute").value);
				//
				if(contextmenuDiv!=null)
				{
					contextmenuDiv.style.visibility = "hidden";	
				}	
				//
				if((endPos.getPosition()!=null) && (startPos.getPosition()!=null) && !(endPos.getPosition().equals(startPos.getPosition()) ) )
				{
					showDirectionPart();
					//
					calcRoute(startPos,endPos);
					//document.getElementById("showDirectionPartLink").style.visibility = "visible";
				}					
			}	
			///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 23<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
            //setting start point
			function setEndRouteAnyPoint()
			{
				endLocationX=currentAnyLocation.lat();
				endLocationY=currentAnyLocation.lng();
				//
				endPos.setPosition(new google.maps.LatLng(endLocationX,endLocationY));
				endPos.setMap(map);
				endPos.setTitle("2");
				//
				var image=ourHomePage+"markerIcons/"+"End.png";
				endPos.setIcon(image);
				//
				document.getElementById("toRoute").value=endPos.getPosition();
				//
				if(contextmenuDiv!=null)
				{
					contextmenuDiv.style.visibility = "hidden";	
				}
				//
				if((endPos.getPosition()!=null) && (startPos.getPosition()!=null) && !(endPos.getPosition().equals(startPos.getPosition()) ) )
				{
					showDirectionPart();
					//
					calcRoute(startPos,endPos);
					//document.getElementById("showDirectionPartLink").style.visibility = "visible";
				}				
			}			
			
			
			///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 24<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
            //Calculating Direction
			function calcRoute(startPos,endPos)
            {
				
				//clearPoints();
				clearFlags();
				//
				if(startPos.getPosition()!=null && endPos.getPosition()!=null)
				{		
					var waypts = [];
					var wPC=0;
					for (var iwayPointCount = 0; iwayPointCount < wayPointCount; iwayPointCount++)
					{
						if(wayPoint[iwayPointCount].marker.getPosition()!=null)
						{							
							wayPointGenrateLink[wPC]=new Object();
							wayPointGenrateLink[wPC].marker= new google.maps.Marker(
							{
								position: wayPoint[iwayPointCount].marker.getPosition()
							});	
							//	
							wPC++;
							//
							waypts.push(
							{
								location:wayPoint[iwayPointCount].marker.getPosition(),
								stopover:wayPoint[iwayPointCount].stopover
							});	
						}
					}
					//Getting positions
					var request = 
					{
						origin:startPos.getPosition(), 
						destination:endPos.getPosition(),
						waypoints: waypts,
						travelMode: google.maps.DirectionsTravelMode.DRIVING,
						unitSystem: google.maps.DirectionsUnitSystem.METRIC
					};
					//

					document.getElementById("DirectionPanel").innerHTML="";
					document.getElementById("DirectionPanel").style.display="inline";
					document.getElementById("DirectionPanel").innerHTML="<Center><img src='"+ourHomePage+"loading/ajax-loader1.gif'/></Center>";
					//
					document.getElementById("generation_link").style.display="none";
					document.getElementById("link_to_new_page").style.display="none";
					//
					startRoute=new google.maps.LatLng(startPos.getPosition().lat(),startPos.getPosition().lng());
					endRoute=new google.maps.LatLng(endPos.getPosition().lat(),endPos.getPosition().lng());
					//Displaying Rout
					directionsService.route(request, function(response, status) 
					{
						if (status == google.maps.DirectionsStatus.OK) 
						{
							directionsDisplay.setMap(map);
							directionsDisplay.setDirections(response);
							document.getElementById("DirectionPanel").innerHTML="";
							document.getElementById("DirectionPanel").style.display="inline";
							directionsDisplay.setPanel(document.getElementById("DirectionPanel"));
							//
							//document.getElementById("generation_link").innerHTML="";
							document.getElementById("generation_link").style.display="inline";
							//
							startPos.setMap(null);
							endPos.setMap(null);
							//alert("ee");
                             for (var iwayPointCount2 = 0; iwayPointCount2 < wayPointCount; iwayPointCount2++)
							{
			//---------------------------hide red marker---------------------------------------------
							wayPoint[iwayPointCount2].marker.setMap(null);
							//pointObject[i].marker.setMap(null);
							}			
						}
						else
						{
							document.getElementById("DirectionPanel").innerHTML="";
							document.getElementById("DirectionPanel").style.display="inline";
							alert("لا يمكن اتمام المسار");
						}
					});
					//Reseting start&end point
					//startPos.setMap(null);
					//startPos.setPosition(null);
					//endPos.setMap(null);
					//endPos.setPosition(null);
					////
//					for (var i = 0; i < wayPointCount; i++)
//					{
//						wayPoint[i].marker.setMap(null);
//						wayPoint[i].marker.setPosition(null);
//						wayPoint[i].stopover=false;
//						//
//						wayPoint[i].marker="";
//						wayPoint[i].stopover="";
//						//
//						
//						wayPointDivArr[i]="";
//					}
//					wayPointCount=0;
//					renderWayPoint();
					//
					//document.getElementById("toRoute").value="";
					//document.getElementById("fromRoute").value="";
				}
				else
				{
					alert("فضلا إختر نقطه بدايه ونقطه نهايه");
				}				
            }
			///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 25<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
            //focusing on map result
			function focusMap()
			{
				if(pointCount>0)
				{
					var maxLat=pointObject[0].marker.getPosition().lat();
					var maxLng=pointObject[0].marker.getPosition().lng();
					var minLat=pointObject[0].marker.getPosition().lat();
					var minLng=pointObject[0].marker.getPosition().lng();
					//
					for(ipointCount8=0;ipointCount8<pointCount;ipointCount8++)
					{
						if(maxLat<pointObject[ipointCount8].marker.getPosition().lat())
						{
							maxLat=pointObject[ipointCount8].marker.getPosition().lat()
						}
						//
						if(maxLng<pointObject[ipointCount8].marker.getPosition().lng())
						{
							maxLng=pointObject[ipointCount8].marker.getPosition().lng()
						}
					}
					//
					for(ipointCount9=0;ipointCount9<pointCount;ipointCount9++)
					{
						if(minLat>pointObject[ipointCount9].marker.getPosition().lat())
						{
							minLat=pointObject[ipointCount9].marker.getPosition().lat()
						}
						//
						if(minLng>pointObject[ipointCount9].marker.getPosition().lng())
						{
							minLng=pointObject[ipointCount9].marker.getPosition().lng()
						}
					}
					//
					var minLimit=new google.maps.LatLng(minLat -.0005,minLng -.0005);
					var maxLimit=new google.maps.LatLng(maxLat +.0005,maxLng +.0005);
					var mapLimit = new google.maps.LatLngBounds(minLimit,maxLimit);
					map.fitBounds(mapLimit);
					//
				}
				//
				setTimeout('showBranchsLink()',2000);	
			}
			///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 26<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
			function renderWayPoint()
			{
				var wayPointDiv=document.getElementById("wayPointDiv");
				//
				wayPointDiv.innerHTML="";
				wayPointDiv.style.display="inline";
				//
				//alert(wayPointCount);
				for(iway=0;iway<wayPointCount;iway++)
				{
					wayPointDiv.innerHTML+=wayPointDivArr[iway];
					//alert(wayPointDivArr[wayPointCount]);
				}
			}
			///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 27<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
			//	
			function getCanvasXY(caurrentLatLng)
			{
				//alert(" iam in getCanvasXY");
				var scale = Math.pow(2, map.getZoom());
				var nw = new google.maps.LatLng
				(
					map.getBounds().getNorthEast().lat(),
					map.getBounds().getSouthWest().lng()
				);
				var worldCoordinateNW = map.getProjection().fromLatLngToPoint(nw);
				var worldCoordinate = map.getProjection().fromLatLngToPoint(caurrentLatLng);
				var caurrentLatLngOffset = new google.maps.Point
				(
					Math.floor((worldCoordinate.x - worldCoordinateNW.x) * scale),
					Math.floor((worldCoordinate.y - worldCoordinateNW.y) * scale)
				);
				return caurrentLatLngOffset;
			}
			///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 28<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
			//
			function setMenuXY(caurrentLatLng)
			{
				//alert(" iam in set menue xy");
				var mapWidth = document.getElementById("map_canvas").style.width;
				var mapHeight = document.getElementById("map_canvas").style.height;
				var menuWidth = document.getElementById("contextmenuDiv").style.width;
				var menuHeight = document.getElementById("contextmenuDiv").style.height;
				document.getElementById("contextmenuDiv").style.left=0;
				//var menuWidth = $('.contextmenu').width();
				//var menuHeight = $('.contextmenu').height();
				var clickedPosition = getCanvasXY(caurrentLatLng);
				var x = clickedPosition.x ;
				var y = clickedPosition.y ;
				//alert("x is  "+x);
				//alert("y is  "+y);
				//alert("mapwidth" + mapWidth);
				//alert("mapwidth" + menuHeight);
				
				if((mapWidth - x ) < menuWidth)
				{
					
					x = x - menuWidth;
				
				}
				
				if((mapHeight - y ) < menuHeight)
				{
					y = y - menuHeight;
				}
				
				document.getElementById("contextmenuDiv").style.position="relative";
				if(x>500||y>283)
				{
					//x=x - menuWidth;
					document.getElementById("contextmenuDiv").style.left=x-100+"px";
					//y = y - menuHeight;
					document.getElementById("contextmenuDiv").style.top=y-15+"px";
					//alert(" in if");
				}
				else if(y>268)
				{
					//x=x - menuWidth;
					document.getElementById("contextmenuDiv").style.left=x+"px";
					//y = y - menuHeight;
					document.getElementById("contextmenuDiv").style.top=y-15+"px";
					//alert(" in if");
				}
				else
				{
					document.getElementById("contextmenuDiv").style.left=x+"px";
					document.getElementById("contextmenuDiv").style.top=y+"px";
					
				}
				//document.getElementById("contextmenuDiv").style.position="relative";
				//document.getElementById("contextmenuDiv").style.left=x+"px";
				//document.getElementById("contextmenuDiv").style.right=x+"px";
				//document.getElementById("contextmenuDiv").style.top=y+"px";
				
			};
			///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 29<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
			function showDeleteWaypointContextMenu(marker)
			{
        		var projection;
        		// contextmenuDiv;
        		projection = map.getProjection() ;
				if(contextmenuDiv !=null)
				{
					map.getDiv().removeChild(contextmenuDiv);
					contextmenuDiv.innerHTML="";
				}
        		contextmenuDiv = document.createElement("div");
        		contextmenuDiv.className  =  'contextmenu';
				contextmenuDiv.id="contextmenuDiv";
				//"<a href='javascript:void(0);' onClick='setEndRoute("+i+")'>End</a>";
				var deletelink="<a href='javascript:void(0);' onClick='removeWayPointDiv("+(marker.getTitle()-1)+")'>حذف&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>";
        		contextmenuDiv.innerHTML = deletelink;
        		map.getDiv().appendChild(contextmenuDiv);         
        		setMenuXY(marker.getPosition());
        		contextmenuDiv.style.visibility = "visible";
        	}
			///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 30<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
			function showDeleteAnypointContextMenu(marker)
			{
        		var projection;
        		// contextmenuDiv;
        		projection = map.getProjection() ;
				if(contextmenuDiv !=null)
				{
					map.getDiv().removeChild(contextmenuDiv);
					contextmenuDiv.innerHTML="";
				}
        		contextmenuDiv = document.createElement("div");
        		contextmenuDiv.className  = 'contextmenu';
				contextmenuDiv.id="contextmenuDiv";
				//"<a href='javascript:void(0);' onClick='setEndRoute("+i+")'>End</a>";
				var deletelink="<a href='javascript:void(0);' onClick='removeStart_EndPoint2("+(marker.getTitle()-1)+")'>حذف&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>";
        		contextmenuDiv.innerHTML = deletelink;
        		map.getDiv().appendChild(contextmenuDiv);         
        		setMenuXY(marker.getPosition());
        		contextmenuDiv.style.visibility = "visible";
        	}
			///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 31<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
			function showAddContextMenu(caurrentLatLng)
			{	

        		var projection;
        		// contextmenuDiv;
        		projection = map.getProjection() ;
        		//$('.contextmenu').remove();
				if(contextmenuDiv !=null)
				{
					map.getDiv().removeChild(contextmenuDiv);
					contextmenuDiv.innerHTML="";
				}
        		contextmenuDiv = document.createElement("div");
        		contextmenuDiv.className  = 'contextmenu';
				contextmenuDiv.id="contextmenuDiv";
				//"<a href='javascript:void(0);' onClick='setEndRoute("+i+")'>End</a>";
				//placeWayPoint(event.latLng);
				//
				/*var addWayPointlink="<a href='javascript:void(0);' onClick='placeWayPoint()'>نقطة وسيطه&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>";*/
				var addStartPointlink="<a href='javascript:void(0);' onClick='setStartRouteAnyPoint()'>نقطة بداية&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;</a>";
				var addEndPointlink="<a href='javascript:void(0);' onClick='setEndRouteAnyPoint()'>نقطة نهاية&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;</a>";
				//
        		//contextmenuDiv.innerHTML = addStartPointlink+"<br>"+addWayPointlink+"<br>"+addEndPointlink;
				//
        		contextmenuDiv.innerHTML = addStartPointlink+"<br>"+addEndPointlink;
        		//$(map.getDiv()).append(contextmenuDiv); 
				map.getDiv().appendChild(contextmenuDiv);   
        		setMenuXY(caurrentLatLng);
				contextmenuDiv.style.visibility = "visible";

        	}

			///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 32<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
			
			// function to add way point in run time
			function placeWayPoint()
			{
				
				if(validWayPointCount<3)
				{
					wayPoint[wayPointCount]=new Object();
					var location = new google.maps.LatLng(currentWayPointLocation.lat(),currentWayPointLocation.lng());
					var marker = new google.maps.Marker(
					{
						position: location,
						//draggable: true,
						title: (wayPointCount+1).toString(),
						map: map
					});	
					
					var fromvar = document.getElementById('fromRoute').value;
					var tovar = document.getElementById('toRoute').value;
					
					//wayPointDiv
					var tbl = document.getElementById('table1').innerHTML;
					//alert(tbl);
					var ltr = tbl.lastIndexOf("<tr>");
					var toptxt = tbl.substring(0,ltr);
					//alert(tbl);
					var remaintxt = tbl.substring(ltr,tbl.length);
					//alert(remaintxt);
					var newtbl = '<table>';
					row ='<tr id="waypoint'+wayPointCount+'"><td><label>نقطة وسيطة</label></td>';
					row += '<td><input  id="waypoint" style="direction:rtl" type="text" readonly="true"   value="'+currentWayPointLocation +'"/></td>';
					row += "<td><a href='javascript:void(0);' onClick='removeWayPointDiv("+wayPointCount+")'> حذف </a></td>";
					row += '</tr>';
					//
					document.getElementById('table1').innerHTML = toptxt + row + remaintxt;
					document.getElementById('fromRoute').value = fromvar;
					document.getElementById('toRoute').value = tovar;
					//
					contextmenuDiv.style.visibility = "hidden";
					//
					wayPointDivArr[wayPointCount]= "<div id='wayPointDiv"+wayPointCount+"'><br/>نقطة وسيطة" + " " + "<input style='direction:rtl' type='text' id='point' readonly='true'   value='"+currentWayPointLocation +"'/><a href='javascript:void(0);' onClick='removeWayPointDiv("+wayPointCount+")'> حذف </a></div>";
					//
					google.maps.event.addListener(marker, 'rightclick', function(event)
					{
						showDeleteWaypointContextMenu(marker);
					});
					//
					wayPoint[wayPointCount].marker=marker;
					wayPoint[wayPointCount].stopover=true;
					//
					wayPointCount++;
					validWayPointCount++;					
					//
					if(contextmenuDiv != null)
					{
						contextmenuDiv.style.visibility = "hidden";
					}
					calcRoute(startPos,endPos);
					//
				}
				else
				{
					alert("لايمكن إضافه اكثر مـن 3 نقط وسيطة");
					//
					if(contextmenuDiv != null)
					{
						contextmenuDiv.style.visibility = "hidden";
					}
				}
				if((endPos.getPosition()!=null) && (startPos.getPosition()!=null) && !(endPos.getPosition().equals(startPos.getPosition()) ) )
				{
					//
					calcRoute(startPos,endPos);	
				}				
			}
			///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 33<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
			function showSearchPart()
			{
			    //
				//alert(document.getElementById("SearchResultPart").innerHTML);
				//document.getElementById("SearchResultPart").innerHTML='';
				document.getElementById("governorateMenu").disabled=false;
				document.getElementById("governorateMenu").value=selectedgov;
				document.getElementById("citiesMenu").disabled=false;
				document.getElementById("citiesMenu").value=selectedcityy;
				document.getElementById("categoryMenu").disabled=false;
				document.getElementById("categoryMenu").value=selectedcatt;
				document.getElementById("subcategoryMenu").disabled=false;
				document.getElementById("subcategoryMenu").value=selectedsubcatt;
				map.setZoom(zoomLevelCity);
				//removeStart_EndPoint(0);
				//removeStart_EndPoint(1);
				document.getElementById("category_search_JoomlaTab").focus();
			    //
                var JoomlaTab= new Array();
				var inputs = document.getElementsByTagName( 'div' );
                for(var iinput=0;iinput<inputs.length;iinput++)
                {
                    if(inputs.item(iinput).getAttribute( 'name' ) == 'JoomlaTabNo' )
                    {
                        JoomlaTab.push( inputs.item(iinput) );
                    }
                }
				//
				if(JoomlaTab.length>0)
				{
						JoomlaTab[0].style.visibility="visible";
						JoomlaTab[1].style.visibility="hidden";
						//
						JoomlaTab[0].style.display="inline";
						JoomlaTab[1].style.display="none";
						//
				}
				//
				if((document.getElementById("DirectionPart").style.display != "none")&&(pointCount>0))
				{
					showSearchResultPart();
				}
				else
				{
					document.getElementById("DirectionPart").style.display = "none";
					//document.getElementById("SearchResultPart").innerHTML='';
					document.getElementById("SearchResultPart").style.display = "none";
					//
					document.getElementById("CategoryPart").style.display = "inline";
					document.getElementById("SearchPart").style.display = "inline";
					//
					directionsDisplay.setMap(null);
					directionsDisplay.setPanel(null);
					//
					//clearPoints();
					clearFlags();
					clearBranchPoints();
					//
					showAdvancedSearchPart();
				}
					//
					for(ibranchpoint2=0;ibranchpoint2<branchPointCount;ibranchpoint2++)
					{
						branchPointObject[ibranchpoint2].infowindow.close();	
					}
					//
					for(ibc=0;ibc<pointCount;ibc++)
					{
						pointObject[ibc].infowindow.close();	
					}
					//document.getElementById("SearchResultPart").innerHTML='';
			}
			///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 34<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
			function showSearchResultPart()
			{
//				alert(txtbox.value);
					//if(txtbox.value !=''&& txtbox.value !=null)
//					{
//						txtbox.value='';
//						//alert(txtbox.value );
//					}
					var JoomlaTab= new Array();
					var inputs = document.getElementsByTagName( 'div' );
					for(var iiputss=0;iiputss<inputs.length;iiputss++)
					{
						if(inputs.item(iiputss).getAttribute( 'name' ) == 'JoomlaTabNo' )
						{
							JoomlaTab.push( inputs.item(iiputss) );
						}
					}
					//
					if(JoomlaTab.length>0)
					{
							JoomlaTab[0].style.visibility="visible";
							JoomlaTab[1].style.visibility="hidden";
							//
							JoomlaTab[0].style.display="inline";
							JoomlaTab[1].style.display="none";
							//
					}
					//
					if(document.getElementById("SearchResultPart").style.display != "inline")
					{
						document.getElementById("DirectionPart").style.display = "none";
						document.getElementById("SearchPart").style.display = "none";		
						document.getElementById("CategoryPart").style.display = "none";
						//
						document.getElementById("SearchResultPart").style.display = "inline";
						//
						focusMap();
						//
						directionsDisplay.setMap(null);
						directionsDisplay.setPanel(null);
						//
					}
					//
	//				for(i=0;i<branchPointCount;i++)
	//				{
	//					branchPointObject[i].infowindow.close();	
	//				}
					//
					for(ittt=0;ittt<pointCount;ittt++)
					{
						pointObject[ittt].infowindow.close();	
					}
			}
			///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 35<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
			function showDirectionPart()
			{
				//document.getElementById("category_search_JoomlaTab").style.backgroundColor='red';
				//var imgURL="../../templates/gk_icki_sports/images/style1/gk_stuff/tab_active_right.png";
				//document.getElementById("directionJoomlaTab").style.backgroundImage= 'url(' + imgURL + ')';
				//alert(document.getElementById('generation_link').style);
				if(contextmenuDiv != null)
					{
						contextmenuDiv.style.visibility = "hidden";
					}

			    var JoomlaTab= new Array();
				//show the direction tab
		        var inputs = document.getElementsByTagName( 'div' );
                for(var tttt=0;tttt<inputs.length;tttt++)
                {
                    if(inputs.item(tttt).getAttribute( 'name' ) == 'JoomlaTabNo' )
                    {
                        JoomlaTab.push( inputs.item(tttt) );
                    }
                }
				//
				if(JoomlaTab.length>0)
				{
						JoomlaTab[1].style.visibility="visible";
						JoomlaTab[0].style.visibility="hidden";
						//
						JoomlaTab[1].style.display="inline";
						JoomlaTab[0].style.display="none";
						//
				}
				//
				document.getElementById("SearchPart").style.display = "none";
				document.getElementById("SearchResultPart").style.display = "none";	
				document.getElementById("CategoryPart").style.display = "none";
				//
				document.getElementById("DirectionPart").style.display = "inline";
				document.getElementById("DirectionPart").style.overflow = "scroll";
				//
				//if(document.getElementById("toRoute").value == "" || document.getElementById("fromRoute").value == "")
				//{
				//test if the direction route is visible or not
				//if the  direction route is not found generatelink and link to new page links will not displayed
				if(directionsDisplay.getMap()==null)
				{
					document.getElementById("generation_link").style.display="none";
					document.getElementById("link_to_new_page").style.display="none";
				}
				//}
				//if the  direction route is  found generatelink and link to new page links will  display
				else
				{
				document.getElementById("generation_link").style.display="inline";
				document.getElementById("link_to_new_page").style.display="inline";	
				}
				
				//
				if(pointCount>0)
				{
					var backLink="<a id='backtoserchreslt' href='javascript:void(0);' onClick='newfun()'>العوده الى نتائج البحث</a>";
					document.getElementById("backLink").innerHTML="";
					document.getElementById("backLink").innerHTML=backLink;
					document.getElementById("backLink").style.display="inline";
					
				}
				else
				{
					var backLink="<a id='newBckToSearch' href='javascript:void(0);' onClick='showCategoryPart();'>العودة الى البحث</a>";
					document.getElementById("backLink").innerHTML="";
					document.getElementById("backLink").innerHTML=backLink;
					document.getElementById("backLink").style.display="inline";				
				}
				//
					//
//					for(i=0;i<branchPointCount;i++)
//					{
//						branchPointObject[i].infowindow.close();	
//					}
					//
					for(yyy=0;yyy<pointCount;yyy++)
					{
						pointObject[yyy].infowindow.close();	
					}
					//lastResultRecord=0;
					//clearPoints();
					clearFlags();
			}		
			///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 36<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
			function newfun()
			{
				
			    var JoomlaTab= new Array();
                var inputs = document.getElementsByTagName( 'div' );
                for(var irrr=0;irrr<inputs.length;irrr++)
                {
                    if(inputs.item(irrr).getAttribute( 'name' ) == 'JoomlaTabNo' )
                    {
                        JoomlaTab.push( inputs.item(irrr) );
                    }
                }
				//
				if(JoomlaTab.length>0)
				{
						JoomlaTab[0].style.visibility="visible";
						JoomlaTab[1].style.visibility="hidden";
						//
						JoomlaTab[0].style.display="inline";
						JoomlaTab[1].style.display="none";
						//
				}
				//
				if(document.getElementById("SearchResultPart").style.display != "inline")
				{
					document.getElementById("DirectionPart").style.display = "none";
					document.getElementById("SearchPart").style.display = "none";		
					document.getElementById("CategoryPart").style.display = "none";
					//
					document.getElementById("SearchResultPart").style.display = "inline";
					//
					
					//
					directionsDisplay.setMap(null);
					directionsDisplay.setPanel(null);
					//
					//document.getElementById("myTD").height="472";
					//document.getElementById("toRoute").value="";
					//document.getElementById("fromRoute").value="";
					//
					//removeStart_EndPoint(0);
					//removeStart_EndPoint(1);
					//
				}
					//
					for(kkk=0;kkk<branchPointCount;kkk++)
					{
						branchPointObject[kkk].infowindow.close();	
					}
					//
					for(lll=0;lll<pointCount;lll++)
					{
						pointObject[lll].infowindow.close();	
					}	
					//pointObject[i].id.setMap(map);
			        // runSearch();	
					focusMap();
					drawSearchResultDiv(pointObject,ResultsDiv);
			}
            function generateLink()
            {   
			
                var generatedLink;
				//
				var wayPointLink="";
				//
    			for (var iGenrate = 0; iGenrate < wayPointGenrateLink.length; iGenrate++)
				{
					if(wayPointGenrateLink[iGenrate].marker.getPosition()!=null)
					{
						wayPointLink = wayPointLink
						+"&GeneratedWayPointLat["+iGenrate+"]=" + wayPointGenrateLink[iGenrate].marker.getPosition().lat()
						+"&GeneratedWayPointLng["+iGenrate+"]=" + wayPointGenrateLink[iGenrate].marker.getPosition().lng();
					}
				}
				if(wayPointLink != "")
				{
					wayPointLink = "&GeneratedWayPointCount=" + wayPointGenrateLink.length + wayPointLink;
				}				
				//
                if(document.URL.indexOf("?")>0)
                {
                    generatedLink = document.URL.substr(0,document.URL.indexOf("?"));
                }
                else
                {
                    generatedLink = document.URL;
                }
				//
                generatedLink = generatedLink
				+"?City=" + governorate
                +"&Lat=" + map.getCenter().lat()
                + "&Lng=" + map.getCenter().lng()
                + "&Zoom=" + map.getZoom()
                + "&Type=" + map.getMapTypeId();
				if(directionsDisplay.getMap()!=null)
				{
					generatedLink=generatedLink
					+ "&Mark1_lat=" + startRoute.lat()
					+ "&Mark1_lng=" + startRoute.lng()
					+ wayPointLink
					+ "&Mark2_lat=" + endRoute.lat()
					+ "&Mark2_lng=" + endRoute.lng();
				}
				if(document.getElementById("link_to_new_page").style.display!="inline")
				{
				if(document.getElementById("toRoute").value!="" && document.getElementById("fromRoute").value !="")
				{
				document.getElementById("link_to_new_page").innerHTML="";
				//var generatedLinkTxtBox="<input type='text' readonly='true' size='300' rows='3' width='50' value='"+generatedLink+"' />";
				var generatedLinkTxtBox="<TEXTAREA readonly='readonly' NAME=name ROWS=5 COLS=30>"+generatedLink+"</TEXTAREA>";
                document.getElementById("link_to_new_page").innerHTML = '<a target="_blank" href="' + generatedLink + '">الرابط الى هذه الصفحة<\/a>'+"<br>"+generatedLinkTxtBox;
				document.getElementById("link_to_new_page").style.display="inline";
                //document.getElementById("generation_link").href = generatedLink;
                //
				//alert(generatedLink);
				}
				}
				else
				{
				document.getElementById("link_to_new_page").style.display="none";	
				}
				
            }
            ///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 37<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
            function applyLink()
            {
				var query;
                if(document.URL.indexOf("?")>0)
                {
					initializeMap();
					//
					if(map!=null)
					{
					var JoomlaTab= new Array();
					var inputs = document.getElementsByTagName( 'div' );
                    for(var ipp=0;ipp<inputs.length;ipp++)
                    {
                        if(inputs.item(ipp).getAttribute( 'name' ) == 'JoomlaTabNo' )
                        {
                            JoomlaTab.push( inputs.item(ipp) );
                        }
                    }
				    //
					if(JoomlaTab.length>0)
					{	
						JoomlaTab[1].style.visibility="visible";
						JoomlaTab[0].style.visibility="hidden";
						//
						JoomlaTab[1].style.display="inline";
						JoomlaTab[0].style.display="none";
						//
					}
					//
					//
                    query = document.URL.split("?");
                    // split the rest at each "&" character to give a list of  "argname=value"  pairs
                    var pairs = query[1].split("&");
                    //
                    var city,lat,lng,zoom,maptype,Mark1_lat,Mark1_lng,Mark2_lat,Mark2_lng,GeneratedWayPointCount=0;
					var GeneratedWayPointLat=[];
					var GeneratedWayPointLng=[];
					//
					var countTest=0;
                    for (var ipairs = 0; ipairs < pairs.length; ipairs++)
                    {
                        // break each pair at the first "=" to obtain the argname and value
                        var pos = pairs[ipairs].indexOf("=");
                        var argname = pairs[ipairs].substring(0, pos);
                        var value = pairs[ipairs].substring(pos + 1);
                        // process each possible argname
						if (argname == "City") { city = parseFloat(value); }
                        if (argname == "Lat") { lat = parseFloat(value); }
                        if (argname == "Lng") { lng = parseFloat(value); }
                        if (argname == "Zoom") { zoom = parseInt(value); }
                        if (argname == "Type") {maptype = value;}
                        if (argname == "Mark1_lat") { Mark1_lat = parseFloat(value); }
                        if (argname == "Mark1_lng") { Mark1_lng = parseFloat(value); }
						//
						if (argname == "GeneratedWayPointCount"){GeneratedWayPointCount = parseInt(value);} 
						if (argname == "GeneratedWayPointLat["+countTest+"]")
						{ 
							GeneratedWayPointLat[countTest] = parseFloat(value); 
						}
						if (argname == "GeneratedWayPointLng["+countTest+"]")
						{
							GeneratedWayPointLng[countTest] = parseFloat(value);
							//
							countTest++
						}	
						//
						if (argname == "Mark2_lat") { Mark2_lat = parseFloat(value); }
                        if (argname == "Mark2_lng") { Mark2_lng = parseFloat(value); }	
                    }
                    if(city !="")
					{
						governorate=city;
					}
                    if(lat!= 0 && lng!= 0)
                    {
                        map.setCenter(new google.maps.LatLng(lat, lng));
                        //alert(lat+lng);
                    }
                    if(zoom != 0)
                    {
                        map.setZoom(zoom);
                        
                    }
                    if(maptype!="")
                    {
                        map.setMapTypeId(maptype);
                        //alert(maptype);
                    }
                    if ((Mark1_lat!=0) && (Mark1_lng!=0) && (Mark2_lat!=0) && (Mark2_lng!=0))
                    {
						showDirectionPart();
						//
                        currentAnyLocation=new google.maps.LatLng(Mark1_lat,Mark1_lng);
						//document.getElementById("toRoute").value='kkkkkhhhgggggguuuuiiiirrrree';	
						setStartRouteAnyPoint();
						//
						if(GeneratedWayPointCount!=0)
						{
							for(iGenerated=0;iGenerated<GeneratedWayPointCount;iGenerated++)
							{							
								currentWayPointLocation=new google.maps.LatLng(GeneratedWayPointLat[iGenerated],GeneratedWayPointLng[iGenerated]);
								placeWayPoint();
							}
						}	
						//
                        currentAnyLocation=new google.maps.LatLng(Mark2_lat,Mark2_lng);
				//document.getElementById("fromRoute").value='lolololololololy';	
				
						setEndRouteAnyPoint();
                        //
						
                        calcRoute(startPos,endPos);
						
                    }
					//
					document.url=query[0];
					//
					}

                }
            }
			function resetSite()
			{
				
			}
/////////////////////////////////////////////////////////////////////////////////////////////////////////		
/////////////////////////////////////////////META DATA PART//////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////		

			////////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 2<--------------------------------
            /////////////////to get the category controooools//////////////////////////	
			function getControlsFromMetaData()
			{
				//Create a boolean variable to check for a valid Internet Explorer instance.
				var xmlhttp = false;
				//Check if we are using IE.
				try 
				{
					//If the Javascript version is greater than 5.
					xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		
				} 
				catch (e) 
				{
					//If not, then use the older active x object.
					try 
					{
						//If we are using Internet Explorer.
						xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		
					} 
					catch (E) 
					{
						//Else we must be using a non-IE browser.
						xmlhttp = false;
					}
				}
				//If we are using a non-IE browser, create a javascript instance of the object.
				if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
				{
					xmlhttp = new XMLHttpRequest();
				}
				//
				//preparing request url
					//tableName
				var url1=ourHomePage+"php/GetControls_MetaData.php";
				url1=url1+'?subcategoryId='+subcategoryId;
				url1=url1+'&sid='+Math.random();
				//sending request
				xmlhttp.open("GET",url1);
				//getting result as string of data
				xmlhttp.onreadystatechange = function()
				{
					if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
					{
						//spliting result string to be rendered on the map
						if (xmlhttp.responseText== "")
						{
							//alert("There is no Result for this sub category");
						}
						else
						{
							renderControls(xmlhttp.responseText);
						}
					}
				}
				xmlhttp.send(null);
				//end of Ajax		   
		   		//showcategory();
			}			
			// Shemy 
			// Cancel form Submit
			function cancel(e)
            {
                if (e && e.preventDefault)
                    e.preventDefault(); // DOM style
                return false; // IE style
            }
			// Check If enter Pressed
			function handleEnter(inField, e) 
			{
                var charCode;
                //
                if(e && e.which)
                {
                    charCode = e.which;
                }
                else if(window.event)
                {
                    e = window.event;
                    charCode = e.keyCode;
                }
                // Enter Preesed
                if(charCode == 13) 
                {
                    search();
                }
            }
            function TranslateArabicQueryString(str)
            {
                ret="";
                //
                for(istr=0; istr<str.length; istr++) 
                {
                    ch=str.charAt(istr);
                    //
                    if (ch =="آ" || ch =="أ" || ch =="إ"|| ch == "ا" || ch =="ٱ")
                    {
                        ret = ret + "%C7";    
                    }
                    else if (ch =="ب")
                    {
                        ret = ret + "%C8";    
                    }
                    else if (ch =="ت")
                    {
                        ret = ret + "%CA";    
                    }
                    else if (ch =="ث")
                    {
                        ret = ret + "%CB";    
                    }
                    //
                    else if (ch =="ج")
                    {
                        ret = ret + "%CC";    
                    }
                    else if (ch =="ح")
                    {
                        ret = ret + "%CD";    
                    }
                    else if (ch =="خ")
                    {
                        ret = ret + "%CE";    
                    }
                    //
                    else if (ch =="د")
                    {
                        ret = ret + "%CF";    
                    }
                    else if (ch =="ذ")
                    {
                        ret = ret + "%D0";    
                    }
                    else if (ch =="ر")
                    {
                        ret = ret + "%D1";    
                    }
                    else if (ch =="ز")
                    {
                        ret = ret + "%D2";    
                    }
                    //
                    else if (ch =="س")
                    {
                        ret = ret + "%D3";    
                    }
                    else if (ch =="ش")
                    {
                        ret = ret + "%D4";    
                    }
                    //
                    else if (ch =="ص")
                    {
                        ret = ret + "%D5";    
                    }
                    else if (ch =="ض")
                    {
                        ret = ret + "%D6";    
                    }
                    //
                    else if (ch =="ط")
                    {
                        ret = ret + "%D8";    
                    }
                    else if (ch =="ظ")
                    {
                        ret = ret + "%D9";    
                    }
                    //
                    else if (ch =="ع")
                    {
                        ret = ret + "%DA";    
                    }
                    else if (ch =="غ")
                    {
                        ret = ret + "%DB";    
                    }
                    //
                    else if (ch =="ف")
                    {
                        ret = ret + "%DD";    
                    }
                    else if (ch =="ق")
                    {
                        ret = ret + "%DE";    
                    }
                    //
                    else if (ch =="ك")
                    {
                        ret = ret + "%DF";    
                    }
                    else if (ch =="ل")
                    {
                        ret = ret + "%E1";    
                    }
                    else if (ch =="م")
                    {
                        ret = ret + "%E3";    
                    }
                    else if (ch =="ن")
                    {
                        ret = ret + "%E4";    
                    }
                    else if (ch =="ه")
                    {
                        ret = ret + "%E5"; 
						//str=str.replace("ه","ة");
                    }
                    else if (ch =="ة")
                    {
                       ret = ret + "%C9";
						 //ret = ret + "%E5";
						//str=str.replace("ة","ه");
                    }
                    else if (ch =="و")
                    {
                        ret = ret + "%E6";    
                    }
                    else if (ch =="ى")
                    {
                        ret = ret + "%EC";    
                    }
                    else if (ch =="ي")
                    {
                        ret = ret + "%ED";    
						//ret = ret + "%EC";    
                    }
					else if (ch =="ء")
                    {
                        ret = ret + "%C1";    
                    }
                    else
                    {
                        ret = ret + ch;    
                    }
				
                } 
                //
                return ret;       
            }
			////////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 2<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
            //Function responsible for splitting reult string and draw controls
			function renderControls(QuerryResult)
			{
				//controlsDivs
				var divcont=document.getElementById('controlsDiv');
				divcont.innerHTML="";
				divcont.style.direction="rtl";
				//
				var tbl  = document.createElement("table");
        		var tblBody = document.createElement("tbody");
			    //
				var bigForm= document.createElement('form');
				bigForm.id="formControls";
				//shemy
				bigForm.setAttribute("method","post");
				bigForm.setAttribute("onSubmit","return cancel(event)");
				var controls = QuerryResult.split("/*/");
				//
				divcont.appendChild(bigForm);
				// Shemy
				if(controls.length>0)
				{
				    var rowLbl = document.createElement("tr");
					var cell2Lbl = document.createElement("td");
					cell2Lbl.setAttribute("colspan","2");
					//
					var lbldiv= document.createElement('div');
					lbldiv.innerHTML="خيارات البحث";
					lbldiv.className='labelRed';
					cell2Lbl.appendChild(lbldiv);
					//
					rowLbl.appendChild(cell2Lbl);
               		//
					tblBody.appendChild(rowLbl);	
				}
				//
				for(p=0;p<controls.length;p++)
				{
					var pointAttr = controls[p].split("<->");					
					////////////////////////////////////////////////////////////////////////
					///____________________________this is text box_________________________
					///////////////////////////////////////////////////////////////////////				
					if(pointAttr[3]==1)
					{
						var row = document.createElement("tr");
						var cell = document.createElement("td");
						var cell2 = document.createElement("td");
						//
						txtbox= document.createElement('input');
						txtbox.type= 'text';
						txtbox.setAttribute("onkeypress","handleEnter(this, event)");
						//
						var txtdiv= document.createElement('div');
						txtdiv.innerHTML=pointAttr[1];
						txtdiv.className='txtdiv';
						//
						required=pointAttr[13];
						// Shemy
						txtbox.name=pointAttr[12];
						txtbox.id= pointAttr[4];                          //set the id for all controls the field name
						txtdiv.style.display="inline";
						txtdiv.style.marginLeft='40px';
						//
						cell.appendChild(txtbox);
						cell2.appendChild(txtdiv);
						row.appendChild(cell2);
               			row.appendChild(cell);
						//
						tblBody.appendChild(row);
					}		
					////////////////////////////////////////////////////////////////////////
					///____________________________this is fixed check box__________________
					///////////////////////////////////////////////////////////////////////	
					if(pointAttr[3]==2)
					{
						var row = document.createElement("tr");
						var cell = document.createElement("td");
						var cell2 = document.createElement("td");
						//
						var checkbox = document.createElement('input');
						var checkboxdiv = document.createElement('label');
						//
						checkboxdiv.className='checkboxdiv';
						checkbox.type = 'checkbox';
						checkbox.defaultChecked = false;					
						checkboxdiv.innerHTML=pointAttr[1];
						//
						checkbox.id= pointAttr[4];
						checkbox.style.textAlign = 'right';
						//
						cell.appendChild(checkbox);
						cell.appendChild(checkboxdiv);
						row.appendChild(cell2);
               			row.appendChild(cell);
						tblBody.appendChild(row);
					}
					////////////////////////////////////////////////////////////////////////
					///____________________________this is dynamic check box________________
					/////////////////////////////////////////////////////////////////////////	
					if(pointAttr[3]==3)
					{
						var row = document.createElement("tr");
						var cell = document.createElement("td");
						var cell2 = document.createElement("td");
						//
						var checkbox = document.createElement('input');
						var checkboxdiv = document.createElement('label');
						checkbox.type = 'checkbox';
						checkbox.defaultChecked = false;
						checkboxdiv.innerHTML=pointAttr[1];
						//
						checkbox.id= pointAttr[4];
						checkbox.style.textAlign = 'right';
                        //
						bigForm.innerHTML+="<br>";						
					}
					
					////////////////////////////////////////////////////////////////////////
					///____________________________this is fixed combo box__________________
					/////////////////////////////////////////////////////////////////////////	
					if(pointAttr[3]==4)
					{
						var row = document.createElement("tr");
						var cell = document.createElement("td");
						var cell2 = document.createElement("td");	
						//alert("this is combobox");							
						var oSelect= document.createElement('select');
						oSelect.className='oSelect';
						//oSelect.style.paddingLeft='30px';
						oSelect.id=pointAttr[4];
						var fixoption=pointAttr[11];
						//
						var optD= document.createElement('option');
						optD.innerHTML='الكل';
						oSelect.appendChild(optD);
						//
						var opt = fixoption.split("%");
						for(m=0;m<opt.length-1;m++)
						{
							var arropt = opt[m].split("~");	
									
							var oOption= document.createElement('option');	//From this your stuff to place the value in combo here */
							oOption.value=arropt[0];
							//
							oOption.innerHTML=arropt[1];
							oSelect.appendChild(oOption);
						}
						//
						var oSelectdiv= document.createElement('div');
						oSelectdiv.style.display="inline";
						oSelectdiv.innerHTML=pointAttr[1];
						oSelectdiv.className='oSelectdiv';
                        //
						bigForm.innerHTML+="<br>";
						//
						cell.appendChild(oSelect);
						cell2.appendChild(oSelectdiv);
						row.appendChild(cell2);
               			row.appendChild(cell);
						//
						tblBody.appendChild(row);
					}
					////////////////////////////////////////////////////////////////////////
					///____________________________this is dynamic combo box_________________
					/////////////////////////////////////////////////////////////////////////	
					if(pointAttr[3]==5)
					{
						var row = document.createElement("tr");
						var cell = document.createElement("td");
						var cell2 = document.createElement("td");	
						//alert("this is combobox");								
						var oSelect2= document.createElement('select');
						oSelect2.id=pointAttr[4];
						oSelect2.className='oSelect2';
						//
						var opts= document.createElement('option');
						opts.innerHTML='الكل';
						oSelect2.appendChild(opts);
						//
						var sqlStatment=pointAttr[7];
						var selectedvalue=pointAttr[8];
						var selectedtext=pointAttr[9];                                                       
						//
						var oSelectd2iv= document.createElement('div');
						oSelectd2iv.style.display="inline";
						oSelectd2iv.innerHTML=pointAttr[1];
						oSelectd2iv.className='oSelectd2iv';
						////-----ajax part--------//
						var xmlhttp = false;
						//Check if we are using IE.
						try 
						{//If the Javascript version is greater than 5.
							xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");} 
						catch (e) 
						{
							//If not, then use the older active x object.
							try 
							{//If we are using Internet Explorer.
								xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
							} 
							catch (E) 
							{//Else we must be using a non-IE browser.
								xmlhttp = false;
							}
						}
						//If we are using a non-IE browser, create a javascript instance of the object.
						if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
						{
							xmlhttp = new XMLHttpRequest();
						}
							//tableName
						var url1=ourHomePage+"php/SelectFields_DynamicControls.php";
						url1=url1+'?sqlStatment='+sqlStatment;
						url1=url1+'&selectedvalue='+selectedvalue;
						url1=url1+'&selectedtext='+selectedtext;
						url1=url1+'&sid='+Math.random();
						//alert(url1);
						//sending request
						xmlhttp.open("GET",url1);
				
						//getting result as string of data
						xmlhttp.onreadystatechange = function()
						{
							if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
							{
								//spliting result string to be rendered on the map
								if (xmlhttp.responseText== "")
								{
									alert("لا يوجد نتيجه لهذا النشاط");
								}
								else
								{
									ComboOpt=xmlhttp.responseText;
									
									var opt = ComboOpt.split("/*/");
									for(m2=0;m2<opt.length-1;m2++)
									{
										var arropt = opt[m2].split("<->");
										//From this your stuff to place the value in combo here */										
										var oOption= document.createElement('option');
										oOption.value=arropt[0];
										
										oOption.innerHTML=arropt[1];
										oSelect2.appendChild(oOption);							
										//alert(arropt[0]);
										//alert(arropt[1]);
									}
									//
//									bigForm.appendChild(oSelectd2iv);
//									//
//									bigForm.appendChild(oSelect2);
									bigForm.innerHTML+="<br>";
								}
							}
						}
						xmlhttp.send(null);
						//
						cell.appendChild(oSelect2);
						cell2.appendChild(oSelectd2iv);
						row.appendChild(cell2);
               			row.appendChild(cell);
						
						tblBody.appendChild(row);
					}
				//end of Ajax 	 
				}
						//
						tbl.appendChild(tblBody);
						bigForm.appendChild(tbl);
			}
			///////////////////////////////////////////////////////////////////////////
            //--------------------------------->PART 3<--------------------------------
            ///////////////////////////////////////////////////////////////////////////
            function getDataFromControls()
			{
				var myfrm=document.getElementById('formControls');
				////alert(myfrm.elements.length);
				if(myfrm!=null)
				{
					for(i=0;i<myfrm.elements.length;i++)
					{
						
						/////alert(i);
						//////////////////////////////////////////////////////
						///__________________________check box________________
						/////////////////////////////////////////////////////	
						
						if (myfrm.elements[i].type=='checkbox')
						{
							var v=false;
							fieldName[i]='';
							values[i]=-1;
							var check=myfrm.elements[i];
							v=check.checked;
							//alert(v);
							if(v==true)
							 {
								values[i]=1;
								fieldName[i]=check.id;
							 }
							 else if(v==false) 
							 {
								 fieldName[i]='';
								 values[i]=-1;
							 }
								//alert(fieldName[i]);
								// alert(values[i]);
						
						}
			
						/////////////////////////////////////////////////////////////
						///_____________________________text box______________________
						///////////////////////////////////////////////////////////////						
						else if(myfrm.elements[i].type=='text')
						{
							fieldName[i]='';
							values[i]=-1;
							var text1=myfrm.elements[i].value;
							/////////////////////////////////////////////////
							//---------------validation ------------------s
							/////////////////////////////////////////////////
							if(text1=='')
							{
								fieldName[i]='';
								values[i]=-1;
								if(required==-1)
								{
									valid=false;
								}
							}
							////////////////////////////////////////
							//--------------Digit-----------------//
							////////////////////////////////////////				
							else if(myfrm.elements[i].name==1)
							{
								var flag = checkDigit(text1);
								if(flag==true)
								{
									fieldName[i]=myfrm.elements[i].id;
									values[i]=text1;
										if(required==-1)
										{
											valid=false;
										}
								}
							}
							////////////////////////////////////////
							//----------------INT-----------------//
							////////////////////////////////////////
							else if(myfrm.elements[i].name==2)
							{
								var flag = checkInt(text1);
								if(flag==true)
								{
									fieldName[i]=myfrm.elements[i].id;
									values[i]=text1;
									if(required==-1)
									{
										valid=false;
									}
								}
							}
							////////////////////////////////////////
							//--------------Text-----------------//
							////////////////////////////////////////
							else if(myfrm.elements[i].name==3)
							{
								var flag = checkText(text1);
								if(flag==true)
								{
									fieldName[i]=myfrm.elements[i].id;
									values[i]=TranslateArabicQueryString(text1);
									//
									if(required==-1)
									{
										valid=false;
									}
								}
							}
							////////////////////////////////////////
							//--------------Email-----------------//
							////////////////////////////////////////
							else if(myfrm.elements[i].name==4)
							{
								var flag = checkEmail(text1);
								if(flag==true)
								{
									fieldName[i]=myfrm.elements[i].id;
									values[i]=text1;
									if(required==-1)
									{
										valid=false;
									}
								}
							}
							////////////////////////////////////////
							//--------------Website-----------------//
							////////////////////////////////////////
							else if(myfrm.elements[i].name==5)
							{
								var flag = checkWebsite(text1);
								if(flag==true)
								{
									fieldName[i]=myfrm.elements[i].id;
									values[i]=text1;
									if(required==-1)
									{
										valid=false;
									}
								}
							}
						}
						/////////////////////////////////////////////////////////
						//________________________combo box______________________
						/////////////////////////////////////////////////////////
						else if(myfrm.elements[i].type=='select-one')
						{
							//alert('this is is selection');
							var combo=myfrm.elements[i];
							//controlType[i]='textbox';
							fieldName[i]=myfrm.elements[i].id;
							var value = combo.options[combo.selectedIndex].value;
							if(value=='الكل')
							{
							   fieldName[i]='';
								values[i]=-1;
							}
							var combovalue = document.getElementById(myfrm.elements[i].id).value;
							values[i]=combo.value;
						}		
						//////////////////////////////////////////////////////////////////////
				 }
				}
				////////////////////////////////////////////////				
				if(valid==true)
				{	
					runSearch();
				
				}
				else
				{
					alert('فضلا قم بملئ كل البيانات المطلوبه');
				}
			}
			///////////////////////////////////////////////////////////////////
			/////-----------------getting values from data base----------------
			/////////////////////////////////////////////////////////////////////
			function runSearch()
			{
					//alert(governorate);
				//Create a boolean variable to check for a valid Internet Explorer instance.
				var xmlhttp = false;
				//Check if we are using IE.
				try 
				{
					//If the Javascript version is greater than 5.
					xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		
				} 
				catch (e) 
				{
					//If not, then use the older active x object.
					try 
					{
						//If we are using Internet Explorer.
						xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		
					} 
					catch (E) 
					{
						//Else we must be using a non-IE browser.
						xmlhttp = false;
					}
				}
				//If we are using a non-IE browser, create a javascript instance of the object.
				if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
				{
					xmlhttp = new XMLHttpRequest();
				}
				
				//preparing request url
				var count=values.length; 
				//tableName
				var url1=ourHomePage+"php/SelectFromServer.php";
				//alert(governorate);
				var dom="feen_"+governorate+"_"+subCategory;
				//alert(dom);
				url1=url1+'?tableName='+dom;
				url1=url1+'&subCategory='+subCategory;
				//alert(url1);
				var vars='';
				for(x=0;x<values.length;x++)
				{
					if((fieldName[x].length!=0) && (values[x]!=-1))
					{
						
						vars=vars+fieldName[x];
						vars=vars+','+values[x];		 
						if(x<values.length-1)
						{
							 vars=vars+',';
						}
					}
					else
					{
						count--;
					}
				}
				url1=url1+'&count='+count;
				url1=url1+'&vars='+vars;
				url1=url1+'&sid='+Math.random();
				//alert(url1);
				//sending request
				//////alert(url1);
				//alert(governorate);
				xmlhttp.open("GET",url1);
				document.getElementById("searchResultCount").innerHTML="";
				document.getElementById("searchResultCount").innerHTML="<Center><img src='"+ourHomePage+"loading/ajax-loader1.gif'/></Center>";				
				//getting result as string of data
				xmlhttp.onreadystatechange = function()
				{
					if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
					{
						//spliting result string to be rendered on the map
						if (xmlhttp.responseText== "")
						{
							//alert("There is no Result for your search");
							//
							document.getElementById('SearchResultDiv').innerHTML="";
							//
							document.getElementById("searchResultCount").innerHTML="";
							document.getElementById("searchResultCount").innerHTML="<label>نتائج البحث :( "+0+" )</label>";
							//
							//document.getElementById("showDirectionPartLink").style.visibility = "visible";
						}
						else
						{
						//
							//alert(xmlhttp.responseText);
							splitAllPointsQuerry(xmlhttp.responseText);
							//
							document.getElementById("searchResultCount").innerHTML="";
							//
							document.getElementById('SearchResultDiv').innerHTML="";
							ResultsDiv=document.getElementById('SearchResultDiv');
							drawSearchResultDiv(pointObject,ResultsDiv);
							//
							focusMap();
							//
							//document.getElementById("toRoute").value="";
							//document.getElementById("fromRoute").value="";
							//
						}
					}
					else if (xmlhttp.readyState != 4)
					{
						document.getElementById("searchResultCount").innerHTML="";
						document.getElementById("searchResultCount").innerHTML="<Center><img src='"+ourHomePage+"loading/ajax-loader1.gif'/></Center>";
					}
				}
				xmlhttp.send(null);
				//end of Ajax   
		    }
		
			////////////////////////////////////////////////////////////////////////////////////////
			////________________________________validation functions________________________________
			////////////////////////////////////////////////////////////////////////////////////////
			/////////////////////
			//___this is digit__
			////////////////////
			function checkDigit(text1)
			{
				if(text1.toString().search(/^-?[0-9]+$/)!= 0)
				{
					return false;
				} 
				else 
				{
					return true;
				}
			}
			////////////////////////
			//___this is integer__
			///////////////////////
			function checkInt(text1)
			{	
				if(isNaN(text1))
				{
				 	 return false;
				}
				else 
				{
					return true;
				}	
			}
			////////////////////////
			//___this is text__
			///////////////////////	
			function checkText(text1)
			{						
				var iChars = "!@#$%^&*()+=-[]\';,./{}|\":<>?";
				for (var t = 0; t < text1.length; t++)
				{  	
					if (iChars.indexOf(text1.charAt(t))!= -1)   
					{  
						return false;	
					}
					else 
					{
						return true;
					}	
				}	
			}
			///////////////////////
			//___this is Email__
			///////////////////////	
			function checkEmail(text1)
			{
				if (!(text1.indexOf(".") > 2) && (text1.indexOf("@") > 0))
				{
					return false;
				}
				else 
				{
					return true;
				}											
			}
			///////////////////////
			//___this is website__
			///////////////////////	
			function checkWebsite(text1)
			{
				var v = new RegExp(); 
				v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$"); 
				if (!v.test(text1))
				{
					return false; 
				} 
				else 
				{
					return true;
				}
											
			}
			//
			function showAdvancedSearchPart()
			{
					document.getElementById("controlsDiv").style.display="inline";
			}
/////////////////////////////////////////////////////////////////////////////////////////////////////////		
/////////////////////////////////////////////META DATA PART//////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////				
			function swapDirection()
			{
				tmp=startPos;
				startPos=endPos;
				endPos=tmp;
				//
				
				//
				tmp=document.getElementById("fromRoute").value;
				document.getElementById("fromRoute").value=document.getElementById("toRoute").value;
				document.getElementById("toRoute").value=tmp;
				//
				/*if(directionflag == true)
				{
					var image=ourHomePage+"markerIcons/"+"End.png";
					startPos.setIcon(image);
					//
					image=ourHomePage+"markerIcons/"+"Start.png";
					endPos.setIcon(image);
					//
					directionflag = false;
				}
				else
				{
					var image=ourHomePage+"markerIcons/"+"End.png";
					endPos.setIcon(image);
					//
					image=ourHomePage+"markerIcons/"+"Start.png";
					startPos.setIcon(image);
					//
					directionflag = true;
				}*/
				calcRoute(startPos,endPos);
			
			}
//

			function sponsorAds(imageId)
			//{
				{
							//Create a boolean variable to check for a valid Internet Explorer instance.
							var xmlhttp = false;
							//Check if we are using IE.
							try 
							{
								//If the Javascript version is greater than 5.
								xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
					
							} 
							catch (e) 
							{
								//If not, then use the older active x object.
								try 
								{
									//If we are using Internet Explorer.
									xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
					
								} 
								catch (E) 
								{
									//Else we must be using a non-IE browser.
									xmlhttp = false;
								}
							}
							//If we are using a non-IE browser, create a javascript instance of the object.
							if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
							{
								xmlhttp = new XMLHttpRequest();
							}
							//
							//preparing request url
								//tableName
							var url1=ourHomePage+"php/getimage.php";
							url1=url1+'?imageId='+imageId;
							url1=url1+'&sid='+Math.random();
							//sending request
							//alert(url1);
							xmlhttp.open("GET",url1);
							//getting result as string of data
							xmlhttp.onreadystatechange = function()
							{
								if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
								{
									//spliting result string to be rendered on the map
									if (xmlhttp.responseText== "")
									{
										alert("لا يوجد نتيجه");
									}
									else
									{
										
										var imgInfo=xmlhttp.responseText;
										var arrInfo = imgInfo.split("/-/");
										if(arrInfo[1]=='')
										{
										}
										else
										{
										window.open("http://" + arrInfo[1]);	
											//
											//document.open("http://" + arrInfo[1]);
											//document.write('<a href="http://" + arrInfo[1]" target="_blank"> </a>');
											//alert("jjj");

										}
									}
								}
							}
							xmlhttp.send(null);
							//end of Ajax		   
					   
					}		


/////////////////////////////////////////////////////////////////////////////////////////////////////////		
					function resetStartDirection()
					{
						//Reseting Start point
						startPos.setMap(null);
						startPos.setPosition(null);
						//
						document.getElementById("fromRoute").value="";
						/////
						if(document.getElementById("toRoute").value !="")
						{
							endPos.setMap(map);
							endPos.setTitle("1");
							var image=ourHomePage+"markerIcons/"+"End.png";
							endPos.setIcon(image);
						}
						else
						{
									
						}
				//
			
				//
						if(contextmenuDiv!=null)
						{
							contextmenuDiv.style.visibility = "hidden";	
						}
						//
						directionsDisplay.setPanel(null);
						directionsDisplay.setMap(null);
						document.getElementById("link_to_new_page").style.display="none";
						document.getElementById("generation_link").style.display="none";
						document.getElementById("link_to_new_page").value="";
						
					}
					//
					function resetEndDirection()
					{
						//Reseting End point
						endPos.setMap(null);
						endPos.setPosition(null);
						//
						document.getElementById("toRoute").value="";
						//
						if(document.getElementById("fromRoute").value !="")
						{
							startPos.setMap(map);
							startPos.setTitle("1");
							var image=ourHomePage+"markerIcons/"+"Start.png";
							endPos.setIcon(image);
						}
						else
						{
									
						}
						directionsDisplay.setPanel(null);
						directionsDisplay.setMap(null);
						document.getElementById("link_to_new_page").style.display="none";
						document.getElementById("generation_link").style.display="none";
						document.getElementById("link_to_new_page").value="";
						
					}
