// JavaScript Document
var testing = {
		id : [],
		name : [],
		x : [],
		y : [],
		code : [],
		star : []
	};
	
function clearAjaxInstance(queueName, clearAll) {
	$.manageAjax.clear(queueName, clearAll);
}

function getStringData(id, category) {
	var postUrl = "id= " + id;
	postUrl += "&category= " + category;

	var dd = new Date();
	var queueName = 'getCurrenLocation' +
					dd.getDate() + dd.getMonth() + dd.getFullYear() +
					dd.getHours() + dd.getMinutes() + dd.getSeconds() + dd.getMilliseconds() +
					(Math.random() * 5 + 1);
		
	$.manageAjax.create(queueName, {
		queue: true,
		abortOld: false,
		preventDoubbleRequests: false,
		cacheResponse: false
	});
		
	$.manageAjax.add(queueName, {
		type : "POST",
		url :url + "getData.php",
		data : postUrl,
		dataType : "html",
		cache : false,
		error : function() {
			clearAjaxInstance(queueName, false);
			return;
		},
		success : function(html) {
			testing.id = [];
			testing.name = [];
			testing.x = [];
			testing.y = [];
			testing.code = [];
			testing.star = [];
				
			var image, imgs, text, x, y, w, h;
			imgs = '';
			text = ''	
			if (html == null || html == undefined) {
				clearAjaxInstance(queueName, false);
				return;
			}
			
			var display = icon.obj.isDisplayed;
			//alert(display);
			
			if (html == "error") {
				document.getElementById('divResults').innerHTML = html;
			} else {
				if(id > 0){
				   var xy = html.split(",");
				   testing.id.push(xy[0]);
				   testing.name.push(xy[1]);
				   testing.x.push(parseFloat(xy[2]));
				   testing.y.push(parseFloat(xy[3]));
				   testing.code.push(xy[4]);
				   testing.star.push(xy[5]);
					
				   image = parseInt(testing.star[0]);
				   
				   if(category == "Search Location"){
					   image = 1;
				   }
				   
				   if(category == "none" || category == "Search Location" || category == undefined || category == ""){
						document.getElementById('category').style.display = 'none';
				   }else{
						document.getElementById('category').style.display = 'block';
						document.getElementById('category').innerHTML = category;
				   }
				  
					if (icon.img != image || image == 109 || image == 105 || image == 1 || image == 51 || image == 81) {
						MapAPI.mapDraw.panelIcon.deleteIcons();
						//var obj = icon.obj;
						if(id == 56 || id == 25 || id == 48 || id == 196){
							iconno = url + "views/images/ngeeannmap/poi.gif";
							y = testing.y[0];
						}else if(id == 80 || id == 190){
							iconno = url + "views/images/ngeeannmap/star"+image+".cp.gif";
							y = testing.y[0];
						}else if(id == 64 || id == 83 || id == 84 || id == 189 || id == 74 || id == 78 || id == 79 || id == 208){
							iconno = url + "views/images/ngeeannmap/star1.cp.gif";
							y = testing.y[0];
						}else{
							iconno = url + "views/images/ngeeannmap/star"+image+".gif";
							y = testing.y[0];
						}
						
						icon.obj = MapAPI.mapDraw.addIcon(testing.x[0], -testing.y[0], true);
						icon.obj.isDisplayed = true;
						if(image != 1){
							if(id == 56 || id == 25 || id == 48 || id == 196){
								icon.obj.setUrl(iconno,16,16);
							}else if(id == 80 || id == 190){
								icon.obj.setUrl(iconno,130,30);
							}else if(id == 64 || id == 83 || id == 84 || id == 189 || id == 74 || id == 78 || id == 79 || id == 208){
								icon.obj.setUrl(iconno,16,21);
							}else{
								icon.obj.setUrl(iconno,130,100);
							}
						}else{
							icon.obj.setUrl(iconno,16,16);
						}

						icon.img = image;

						if(id == 80 || id == 190 || id == 64 || id == 83 || id == 84 || id == 189 || id == 74 || id == 78 || id == 79){
							document.getElementById('building').innerHTML = testing.name[0];
							MapAPI.setLevelIndex(2);
							MapAPI.setCenterVertex(new Vertex(testing.x[0], -y));
							document.getElementById('Layer4').innerHTML = '<img src="'+host+'xg/img/nav_3.gif" width="17" height="17" border="0">';

							switch(id)
							{
								case "80"	: text = "16 visitor car park lots";break;
								case "190"	: text = "13 visitor car park lots";break;
								case "64"	: text = "6 visitor car park lots";break;
								case "83"	: text = "17 visitor car park lots";break;
								case "84"	: text = "5 visitor car park lots";break;
								case "189"	: text = "16 visitor car park lots";break;
								case "85"	: text = "13 visitor car park lots";break;
								case "74"	: text = "5 visitor car park lots";break;
								case "78"	: text = "5 visitor car park lots";break;
								case "79"	: text = "12 visitor car park lots";break;
							}
							w = 200; h = 100;
							
							var myHtml = '<div id="popup" style="display:block;">';
							myHtml += '<table width="100%" style="padding:5px;" border="0" align="center">';
							myHtml += '<tr><td width="50%" align="left" class="header"><font style="font-size:12px">'+testing.name[0]+'</font></td>';
							myHtml += '<td align="right"><img src="'+url+'views/images/cl_grey.png" style="cursor:pointer" width="14px" height="13px" onclick="document.getElementById(\'poi\').style.display=\'none\'; changeMode('+id+','+testing.x[0]+','+y+');"/></td></tr>';
							if(imgs){								
								 myHtml += '<tr><td colspan="2"><img src='+imgs+' width="320px" height="235px"/></td></tr>';
							}
							 myHtml += '<tr><td align="left" colspan="2">'+text+'</td></tr>';
							 myHtml += '</table></div>';
							document.f.facilities.selectedIndex = 0;							 
							icon.obj.openInfoWindowHtml(200, 100, myHtml);
						}else{
							document.getElementById('building').innerHTML = testing.name[0];
							MapAPI.setLevelIndex(2);
							MapAPI.setCenterVertex(new Vertex(testing.x[0], -y));
							document.getElementById('Layer4').innerHTML = '<img src="'+host+'xg/img/nav_3.gif" width="17" height="17" border="0">';
						}

						iconno2 = url + "views/images/ngeeannmap/poi.gif";
						icon2 = MapAPI.mapDraw.addIcon(1602,-2354, true, [0]);
						icon2.isDisplayed = true;
						icon2.setUrl(iconno2,16 ,16);
						
						
						icon3 = MapAPI.mapDraw.addIcon(1672,-2284, true, [0]);
						icon2.isDisplayed = true;
						icon3.setUrl(iconno2,16 ,16);
						
						icon4 = MapAPI.mapDraw.addIcon(2364,-2202, true, [0]);
						icon2.isDisplayed = true;
						icon4.setUrl(iconno2,16 ,16);
						
						icon5 = MapAPI.mapDraw.addIcon(1435,-2570, true, [0]);
						icon2.isDisplayed = true;
						icon5.setUrl(iconno2,16 ,16);
					
						VEvent.addListener(icon2, 'click', function() {
							 var myHtml = '<div id="popup" style="display:block">';
							 myHtml += '<table width="100%" style="padding:5px;" border="0" align="center">';
							 myHtml += '<tr><td width="50%" align="left" class="header"><font style="font-size:12px">The Atrium</font></td>';
							 myHtml += '<td align="right"><img src="'+url+'views/images/cl_grey.png" style="cursor:pointer" width="14px" height="13px" onclick="document.getElementById(\'poi\').style.display=\'none\';"/></td></tr>';
							 //myHtml += '<tr><td colspan="2"><img src="'+ url +'views/images/atrium.gif" width="320px" height="235px"/></td></tr>';
							 myHtml += '<tr><td align="left" colspan="2">There is no other place better than at the Atrium. One can enjoy the pipe-in music, coffee and sandwiches at the coffee table outside the outlet. It is a good place to get to know each other.</td></tr>';
							 myHtml += '</table></div>';
							 icon2.openInfoWindowHtml(350, 150, myHtml);
						});
		
						VEvent.addListener(icon3, 'click', function() {
							 var myHtml = '<div id="popup" style="display:block">';
							 myHtml += '<table width="100%" style="padding:5px;" border="0" align="center">';
							 myHtml += '<tr><td width="50%" align="left" class="header"><font style="font-size:12px">Library</font></td>';
							 myHtml += '<td align="right"><img src="'+url+'views/images/cl_grey.png" style="cursor:pointer" width="14px" height="13px" onclick="document.getElementById(\'poi\').style.display=\'none\';"/></td></tr>';
							 myHtml += '<tr><td colspan="2"><img src="'+ url +'views/images/library.gif" width="320px" height="235px"/></td></tr>';
							 myHtml += '<tr><td align="left" colspan="2">Print, electronic and multimedia resources -- the Lien Ying Chow Library has it all under one roof to meet your personal, social, recreational and academic needs. There is also a Board Games Room for mental stimulation, Wealth Creation InfoCentre to develop your financial literacy skills and the Lien Ying Chow Gallery to inspire your entrepreneurial spirit. Wireless access to the Internet is available throughout the premises. Come, and be enthralled by what awaits you at the Lifestyle Library !</td></tr>';
							 myHtml += '</table></div>';
							 icon3.openInfoWindowHtml(350, 450, myHtml);
						});
						
						VEvent.addListener(icon4, 'click', function() {
							 var myHtml = '<div id="popup" style="display:block">';
							 myHtml += '<table width="100%" style="padding:5px;" border="0" align="center">';
							 myHtml += '<tr><td width="50%" align="left" class="header"><font style="font-size:12px">Sports Complex</font></td>';
							 myHtml += '<td align="right"><img src="'+url+'views/images/cl_grey.png" style="cursor:pointer" width="14px" height="13px" onclick="document.getElementById(\'poi\').style.display=\'none\';"/></td></tr>';
							 //myHtml += '<tr><td colspan="2"><img src="'+ url +'views/images/sports.gif" width="320px" height="235px"/></td></tr>';
							 myHtml += '<tr><td align="left" colspan="2">Make a splash at the swimming pool? Run around the newly-laid running track? Tone up your muscles in the gymnasium? Game at the Squash Courts? All these are available at the Sports Complex!</td></tr>';
							 myHtml += '</table></div>';
							 icon4.openInfoWindowHtml(350, 150, myHtml);
						});
						
						VEvent.addListener(icon5, 'click', function() {
							 var myHtml = '<div id="popup" style="display:block">';
							 myHtml += '<table width="100%" style="padding:5px;" border="0" align="center">';
							 myHtml += '<tr><td width="50%" align="left" class="header"><font style="font-size:12px">Ngee Ann Poly Entrance</font></td>';
							 myHtml += '<td align="right"><img src="'+url+'views/images/cl_grey.png" style="cursor:pointer" width="14px" height="13px" onclick="document.getElementById(\'poi\').style.display=\'none\';"/></td></tr>';
							 //myHtml += '<tr><td colspan="2"><img src="'+ url +'views/images/entrance.gif" width="320px" height="235px"/></td></tr>';
							 myHtml += '<tr><td align="left" colspan="2">Ngee Ann Polytechnic has offered quality education since 1960s. The campus is spead over 35.4 hectares of suburban land at the fringe of the upmarket Bukit Timah residential district. With its convenient location, transportation is never a problem. The campus is well served by public transport from around the island.</td></tr>';
							 myHtml += '</table></div>';
							 icon5.openInfoWindowHtml(350, 170, myHtml);
						});
				    
				    if(id == 56 || id == 25 || id == 48 || id == 196){
							if(id == 56){
								imgs = url + "views/images/atrium.gif";
								text = "There is no other place better than at the Atrium. One can enjoy the pipe-in music, coffee and sandwiches at the coffee table outside the outlet. It is a good place to get to know each other.";
								w = 350; h = 150;
							}else if(id == 25){
								imgs = url + "views/images/library.gif";
								//text = "Ngee Ann Lifestyle Library has a wide variety of collections to offer to the students, from reference books, past year exam questions, movie tapes, LDs and DVDs, to an Internet Cafe.";
								text = "Print, electronic and multimedia resources -- the Lien Ying Chow Library has it all under one roof to meet your personal, social, recreational and academic needs. There is also a Board Games Room for mental stimulation, Wealth Creation InfoCentre to develop your financial literacy skills and the Lien Ying Chow Gallery to inspire your entrepreneurial spirit. Wireless access to the Internet is available throughout the premises. Come, and be enthralled by what awaits you at the Lifestyle Library !";
								w = 350; h = 450;
							}else if(id == 48){
								imgs = url + "views/images/sports.gif";
								text = "Make a splash at the swimming pool? Run around the newly-laid running track? Tone up your muscles in the gymnasium? Game at the Squash Courts? All these are available at the Sports Complex!";
								w = 350; h = 150;
							}else{
								imgs = url + "views/images/entrance.gif";
								text = "Ngee Ann Polytechnic has offered quality education since 1960s. The campus is spead over 35.4 hectares of suburban land at the fringe of the upmarket Bukit Timah residential district. With its convenient location, transportation is never a problem. The campus is well served by public transport from around the island.";
								w = 350; h = 170;
							}
								 var myHtml = '<div id="popup" style="display:block">';
								 myHtml += '<table width="100%" style="padding:5px;" border="0" align="center">';
								 myHtml += '<tr><td width="50%" align="left" class="header"><font style="font-size:12px">'+testing.name[0]+'</font></td>';
								 myHtml += '<td align="right"><img src="'+url+'views/images/cl_grey.png" style="cursor:pointer" width="14px" height="13px" onclick="document.getElementById(\'poi\').style.display=\'none\'; changeMode('+id+','+testing.x[0]+','+y+');"/></td></tr>';
								 if(id==25){								
									 myHtml += '<tr><td colspan="2"><img src='+imgs+' width="320px" height="235px"/></td></tr>';
							   }
								 myHtml += '<tr><td align="left" colspan="2">'+text+'</td></tr>';
								 myHtml += '</table></div>';
							VEvent.addListener(icon.obj, 'click', function() {
								 //var myHtml = '<div style="border:1px solid red; width:100px"><font style="font-size:12px">'+testing.name[0]+'</font></div>';
								 /*var myHtml = '<div id="popup" style="display:block">';
								 myHtml += '<table width="100%" style="padding:5px;" border="0" align="center">';
								 myHtml += '<tr><td width="50%" align="left" class="header"><font style="font-size:12px">'+testing.name[0]+'</font></td>';
								 myHtml += '<td align="right"><img src="'+url+'views/images/cl_grey.png" style="cursor:pointer" width="14px" height="13px" onclick="document.getElementById(\'poi\').style.display=\'none\'; changeMode('+id+','+testing.x[0]+','+y+');"/></td></tr>';
								 myHtml += '<tr><td colspan="2"><img src='+imgs+' width="320px" height="235px"/></td></tr>';
								 myHtml += '<tr><td align="left" colspan="2">'+text+'</td></tr>';
								 myHtml += '</table></div>';*/
								 icon.obj.openInfoWindowHtml(w, h, myHtml);
							});
							
							icon.obj.openInfoWindowHtml(w, h, myHtml);
						}
						
						//document.location = url +"index.php/main/index/id/"+testing.id[0]+"/x/"+testing.x[0]+"/y/"+testing.y[0]+"/star/"+image+"/name/"+ testing.name[0];
						document.getElementById('print').style.display = 'none';
						var pr = '<a href="javascript:printData('+testing.x[0]+','+testing.y[0]+');" class="link"><img src="'+ url + 'views/images/print.gif" width="24" height="19" border="0"/><span style="vertical-align:top" class="titlered small">&nbsp;Print this map</a></span>';
						document.getElementById('print').style.display = 'block';
						document.getElementById('print').innerHTML = pr;	
					}					   
				  }else if(id=='soe'){
				   document.location.href = "http://www.np.edu.sg/soe/Pages/default.aspx";
				  }else if(id==''){
				   alert("Please choose one");
				  }
					   document.f.school.selectedIndex = 0;						 
					   document.f.office.selectedIndex = 0;						 
					   document.f.facilities.selectedIndex = 0;
					   document.f.lecture.selectedIndex = 0;
					   document.f.building.selectedIndex = 0;
				}
				
				//window.location.hash = "#name="+testing.name[0]+"&category="+category+"&x="+testing.x[0]+"&y="+testing.y[0];
				//window.location.hash = "#id="+id;
				clearAjaxInstance(queueName, false);
			}
		});
 }
 
akhyar = new Object();
akhyar.addtheevent = function(obj_icon,iconno,size_x,size_y,pos_x,pos_y,w,h,text){
		VEvent.addListener(obj_icon, 'click', function() {
			MapAPI.mapDraw.panelIcon.deleteIcons();
			obj = MapAPI.mapDraw.addIcon(pos_x, -pos_y, true);
			obj.isDisplayed = true;
			obj.setUrl(iconno,size_x,size_y);
			obj.openInfoWindowHtml(w,h,text);
			akhyar.addtheevent(obj,iconno,size_x,size_y,pos_x,pos_y,w,h,text);
		});		
}

function getCarPark(id, category) {
	var postUrl = "id= " + id;
	postUrl += "&category= " + category;

	var dd = new Date();
	var queueName = 'getCurrenLocation' +
					dd.getDate() + dd.getMonth() + dd.getFullYear() +
					dd.getHours() + dd.getMinutes() + dd.getSeconds() + dd.getMilliseconds() +
					(Math.random() * 5 + 1);
		
	$.manageAjax.create(queueName, {
		queue: true,
		abortOld: false,
		preventDoubbleRequests: false,
		cacheResponse: false
	});
		
	$.manageAjax.add(queueName, {
		type : "POST",
		url :url + "getData.php",
		data : postUrl,
		dataType : "html",
		cache : false,
		error : function() {
			clearAjaxInstance(queueName, false);
			return;
		},
		success : function(html) {
			testing.id = [];
			testing.name = [];
			testing.x = [];
			testing.y = [];
			testing.code = [];
			testing.star = [];
				
			var image, imgs, text, x, y, w, h;
			imgs = '';
			text = ''	
			if (html == null || html == undefined) {
				clearAjaxInstance(queueName, false);
				return;
			}
			
			var display = icon.obj.isDisplayed;
			//alert(display);
			
			if (html == "error") {
				document.getElementById('divResults').innerHTML = html;
			} else {
				if(id > 0){
				   var xy = html.split(",");
				   testing.id.push(xy[0]);
				   testing.name.push(xy[1]);
				   testing.x.push(parseFloat(xy[2]));
				   testing.y.push(parseFloat(xy[3]));
				   testing.code.push(xy[4]);
				   testing.star.push(xy[5]);
					
				   image = parseInt(testing.star[0]);
				   
				   if(category == "Search Location"){
					   image = 1;
				   }
						category = 'Visitor Car Park';
						document.getElementById('category').style.display = 'block';
						document.getElementById('category').innerHTML = category;
				   
					if (icon.img != image || image == 1 || image == 81 || image == 190) {
						MapAPI.mapDraw.panelIcon.deleteIcons();
						//var obj = icon.obj;
						if(id == 64 || id == 83 || id == 84 || id == 189 || id == 74 || id == 78 || id == 79){
							iconno = url + "views/images/ngeeannmap/star1.cp.gif";
							y = testing.y[0];
						}else{
							iconno = url + "views/images/ngeeannmap/star"+image+".cp.gif";
							y = testing.y[0];
						}
						icon.obj = MapAPI.mapDraw.addIcon(testing.x[0], -testing.y[0], true);
						icon.obj.isDisplayed = true;
						if(image != 1){
							if(id == 64 || id == 83 || id == 84 || id == 189 || id == 74 || id == 78 || id == 79){
									icon.obj.setUrl(iconno,16,21); size_x = 16; size_y = 21;
							}else if(id == 80 || id == 190 ){
								icon.obj.setUrl(iconno,130,30); size_x = 130 ; size_y = 30;
							}
						}else{
							icon.obj.setUrl(iconno,16,16); size_x = 16; size_y = 16;
						}

						
						document.getElementById('building').innerHTML = testing.name[0];
						MapAPI.setLevelIndex(2);
				   	MapAPI.setCenterVertex(new Vertex(testing.x[0], -y));
				   	document.getElementById('Layer4').innerHTML = '<img src="'+host+'xg/img/nav_3.gif" width="17" height="17" border="0">';
				    
				    iconno2 = url + "views/images/ngeeannmap/poi.gif";
						icon2 = MapAPI.mapDraw.addIcon(1602,-2354, true, [0]);
						icon2.isDisplayed = true;
						icon2.setUrl(iconno2,16 ,16);
						
						
						icon3 = MapAPI.mapDraw.addIcon(1672,-2284, true, [0]);
						icon2.isDisplayed = true;
						icon3.setUrl(iconno2,16 ,16);
						
						icon4 = MapAPI.mapDraw.addIcon(2364,-2202, true, [0]);
						icon2.isDisplayed = true;
						icon4.setUrl(iconno2,16 ,16);
						
						icon5 = MapAPI.mapDraw.addIcon(1435,-2570, true, [0]);
						icon2.isDisplayed = true;
						icon5.setUrl(iconno2,16 ,16);
					
						VEvent.addListener(icon2, 'click', function() {
							 var myHtml = '<div id="popup" style="display:block">';
							 myHtml += '<table width="100%" style="padding:5px;" border="0" align="center">';
							 myHtml += '<tr><td width="50%" align="left" class="header"><font style="font-size:12px">The Atrium</font></td>';
							 myHtml += '<td align="right"><img src="'+url+'views/images/cl_grey.png" style="cursor:pointer" width="14px" height="13px" onclick="document.getElementById(\'poi\').style.display=\'none\';"/></td></tr>';
							 //myHtml += '<tr><td colspan="2"><img src="'+ url +'views/images/atrium.gif" width="320px" height="235px"/></td></tr>';
							 myHtml += '<tr><td align="left" colspan="2">There is no other place better than at the Atrium. One can enjoy the pipe-in music, coffee and sandwiches at the coffee table outside the outlet. It is a good place to get to know each other.</td></tr>';
							 myHtml += '</table></div>';
							 icon2.openInfoWindowHtml(350, 150, myHtml);
						});
		
						VEvent.addListener(icon3, 'click', function() {
							 var myHtml = '<div id="popup" style="display:block">';
							 myHtml += '<table width="100%" style="padding:5px;" border="0" align="center">';
							 myHtml += '<tr><td width="50%" align="left" class="header"><font style="font-size:12px">Library</font></td>';
							 myHtml += '<td align="right"><img src="'+url+'views/images/cl_grey.png" style="cursor:pointer" width="14px" height="13px" onclick="document.getElementById(\'poi\').style.display=\'none\';"/></td></tr>';
							 myHtml += '<tr><td colspan="2"><img src="'+ url +'views/images/library.gif" width="320px" height="235px"/></td></tr>';
							 myHtml += '<tr><td align="left" colspan="2">Print, electronic and multimedia resources -- the Lien Ying Chow Library has it all under one roof to meet your personal, social, recreational and academic needs. There is also a Board Games Room for mental stimulation, Wealth Creation InfoCentre to develop your financial literacy skills and the Lien Ying Chow Gallery to inspire your entrepreneurial spirit. Wireless access to the Internet is available throughout the premises. Come, and be enthralled by what awaits you at the Lifestyle Library !</td></tr>';
							 myHtml += '</table></div>';
							 icon3.openInfoWindowHtml(350, 450, myHtml);
						});
						
						VEvent.addListener(icon4, 'click', function() {
							 var myHtml = '<div id="popup" style="display:block">';
							 myHtml += '<table width="100%" style="padding:5px;" border="0" align="center">';
							 myHtml += '<tr><td width="50%" align="left" class="header"><font style="font-size:12px">Sports Complex</font></td>';
							 myHtml += '<td align="right"><img src="'+url+'views/images/cl_grey.png" style="cursor:pointer" width="14px" height="13px" onclick="document.getElementById(\'poi\').style.display=\'none\';"/></td></tr>';
							 //myHtml += '<tr><td colspan="2"><img src="'+ url +'views/images/sports.gif" width="320px" height="235px"/></td></tr>';
							 myHtml += '<tr><td align="left" colspan="2">Make a splash at the swimming pool? Run around the newly-laid running track? Tone up your muscles in the gymnasium? Game at the Squash Courts? All these are available at the Sports Complex!</td></tr>';
							 myHtml += '</table></div>';
							 icon4.openInfoWindowHtml(350, 150, myHtml);
						});
						
						VEvent.addListener(icon5, 'click', function() {
							 var myHtml = '<div id="popup" style="display:block">';
							 myHtml += '<table width="100%" style="padding:5px;" border="0" align="center">';
							 myHtml += '<tr><td width="50%" align="left" class="header"><font style="font-size:12px">Ngee Ann Poly Entrance</font></td>';
							 myHtml += '<td align="right"><img src="'+url+'views/images/cl_grey.png" style="cursor:pointer" width="14px" height="13px" onclick="document.getElementById(\'poi\').style.display=\'none\';"/></td></tr>';
							 //myHtml += '<tr><td colspan="2"><img src="'+ url +'views/images/entrance.gif" width="320px" height="235px"/></td></tr>';
							 myHtml += '<tr><td align="left" colspan="2">Ngee Ann Polytechnic has offered quality education since 1960s. The campus is spead over 35.4 hectares of suburban land at the fringe of the upmarket Bukit Timah residential district. With its convenient location, transportation is never a problem. The campus is well served by public transport from around the island.</td></tr>';
							 myHtml += '</table></div>';
							 icon5.openInfoWindowHtml(350, 170, myHtml);
						});
				    
						if(id == 80 || id == 64 || id == 83 || id == 84 || id == 189 || id == 190 || id == 74 || id == 78 || id == 79){
							switch(id)
							{
								case 80	: text = "16 visitor car park lots";break;
								case 190: text = "13 visitor car park lots";break;
								case 64	: text = "6 visitor car park lots";break;
								case 83	: text = "17 visitor car park lots";break;
								case 84	: text = "5 visitor car park lots";break;
								case 189: text = "16 visitor car park lots";break;
								case 85	: text = "13 visitor car park lots";break;
								case 74	: text = "5 visitor car park lots";break;
								case 78	: text = "5 visitor car park lots";break;
								case 79	: text = "12 visitor car park lots";break;
							}
							w = 200; h = 100;
								var myHtml = '<div id="popup" style="display:block;">';
								myHtml += '<table width="100%" style="padding:5px;" border="0" align="center">';
								myHtml += '<tr><td width="50%" align="left" class="header"><font style="font-size:12px">'+testing.name[0]+'</font></td>';
								myHtml += '<td align="right"><img src="'+url+'views/images/cl_grey.png" style="cursor:pointer" width="14px" height="13px" onclick="document.getElementById(\'poi\').style.display=\'none\'; changeMode('+id+','+testing.x[0]+','+y+');"/></td></tr>';
								if(id==25){								
									 myHtml += '<tr><td colspan="2"><img src='+imgs+' width="320px" height="235px"/></td></tr>';
								}
								 myHtml += '<tr><td align="left" colspan="2">'+text+'</td></tr>';
								 myHtml += '</table></div>';
								akhyar.addtheevent(icon.obj,iconno,size_x,size_y,testing.x[0],testing.y[0],w,h,myHtml)
							icon.obj.openInfoWindowHtml(w, h, myHtml);
						}
						
						document.getElementById('print').style.display = 'none';
						var pr = '<a href="javascript:printData('+testing.x[0]+','+testing.y[0]+');" class="link"><img src="'+ url + 'views/images/print.gif" width="24" height="19" border="0"/><span style="vertical-align:top" class="titlered small">&nbsp;Print this map</a></span>';
						document.getElementById('print').style.display = 'block';
						document.getElementById('print').innerHTML = pr;	
					}					   
				  }
				   document.f.school.selectedIndex = 0;						 
				   document.f.office.selectedIndex = 0;						 
				   document.f.facilities.selectedIndex = 0;
				   document.f.lecture.selectedIndex = 0;
				   document.f.building.selectedIndex = 0;
				}
				
				//window.location.hash = "#name="+testing.name[0]+"&category="+category+"&x="+testing.x[0]+"&y="+testing.y[0];
				//window.location.hash = "#id="+id;
				clearAjaxInstance(queueName, false);
			}
		});
 }

function getSearchData(name) {
	var postUrl = "name= " + name;

	var dd = new Date();
	var queueName = 'getCurrenLocation' +
					dd.getDate() + dd.getMonth() + dd.getFullYear() +
					dd.getHours() + dd.getMinutes() + dd.getSeconds() + dd.getMilliseconds() +
					(Math.random() * 5 + 1);
		
	$.manageAjax.create(queueName, {
		queue: true,
		abortOld: false,
		preventDoubbleRequests: false,
		cacheResponse: false
	});
		
	$.manageAjax.add(queueName, {
		type : "POST",
		url : url + "getData.php",
		data : postUrl,
		dataType : "html",
		cache : false,
		error : function() {
			clearAjaxInstance(queueName, false);
			return;
		},
		success : function(html) {
			testing.id = [];
			testing.name = [];
			testing.x = [];
			testing.y = [];
			testing.code = [];
			testing.star = [];
				
			var image, bgcol, t, rt, err;
			t = '';
			rt = '';
			if (html == null || html == undefined) {
				clearAjaxInstance(queueName, false);
				return;
			}

			if (html == "error") {
				document.getElementById('divResults').innerHTML = html;
			} else {
				if(name != ''){
				   var result = html.split("=>");
				   for(var i=0; i<result.length;i++){
					   var xy = result[i].split(",");
					   testing.id.push(xy[0]);
					   testing.name.push(xy[1]);
					   testing.x.push(parseFloat(xy[2]));
					   testing.y.push(parseFloat(xy[3]));
					   testing.code.push(xy[4]);
					   testing.star.push(xy[5]);
				   }
				
				    document.getElementById('Map').style.display = 'none';
				    document.getElementById('the_div').style.display = 'none';
				    document.getElementById('leg').style.display = 'none';
				    //document.getElementById('Map').style.display = 'none';
					//alert(testing.name.length +";"+testing.name[0]);
				    if(testing.name.length > 0 && testing.name[0] != undefined){
					rt = "<table border='0' width='100%' cellpadding='5' cellspacing='0'><tr><td align='center'>";
					rt += "<span class='header'>Search Result of '"+ name + "'</span>";
					rt += "</td></tr></table>";
				
					t = "<table border='0' width='100%' cellpadding='5' cellspacing='0'>";
					t +="<tr><td width='90%'><font class='header'>Building</font></td><td align='center'><font class='header'>Location</font></td></tr>";
					for(var j=0; j < (testing.name.length)-1; j++){
						bgcol = "";
						var mod = j % 2;
						//alert(mod)
						if(mod != 0){
							bgcol = "style='background-color:#eaeaea'";
						}else{
							bcgol = "";
						}
						t +="<tr "+bgcol+"><td>"+testing.name[j]+"</td><td align='center'><a href='"+ url +"index.php/main/index/id/"+testing.id[j]+"/x/"+testing.x[j]+"/y/"+testing.y[j]+"/star/"+testing.star[j]+"/name/"+testing.name[j]+"' class='link'>Map</a></td></tr>";
					}
					t+= "</table>";

					
					//alert(testing.name[0]+ " , " + testing.x[0]+ " , " +testing.y[0]);
				    }else{
					rt = "<table border='0' width='100%' cellpadding='5' cellspacing='0'><tr><td align='center'>";
					rt += "<span class='header'><font color='red'>No matching result for '"+ name + "'</font></span>";
					rt += "</td></tr></table>";

					t = "";
				    }
					document.getElementById('resultTitle').innerHTML = rt;
					document.getElementById('resultTitle').style.display = 'block';
					document.getElementById('result').innerHTML = t;
					document.getElementById('result').style.display = 'block';
				}else{
					alert("Please choose one");
				}
				clearAjaxInstance(queueName, false);
			}
		 }
	});
}
function printData(x, y, levelIndex) {
		var postUrl = "x=dddd ";// + x;
		postUrl += "&y=yyyyyyyy&level=jjjjj";
		var dd = new Date();
		var queueName = 'getCurrenLocation' +
						dd.getDate() + dd.getMonth() + dd.getFullYear() +
						dd.getHours() + dd.getMinutes() + dd.getSeconds() + dd.getMilliseconds() +
						(Math.random() * 5 + 1);
		
		$.manageAjax.create(queueName, {
			queue: true,
			abortOld: false,
			preventDoubbleRequests: false,
			cacheResponse: false
		});
		
		$.manageAjax.add(queueName, {
			type : "POST",
			url : "getData.php",
			data : postUrl,
			dataType : "html",
			cache : false,
			error : function() {
				clearAjaxInstance(queueName, false);
				return;
			},
			success : function(html) {
				var star = 1;
				var display = icon.obj.isDisplayed;
				
				if(display == true){
					star = 1;
				}else{
					star = 0;
				}

				levelIndex = levelIndex+1;
				y = parseInt(y);
				y = Math.abs(y);
				document.getElementById('rail').style.display = 'none';
				document.getElementById('leg').style.display = 'none';
				document.getElementById('the_div').style.display = 'none';
				document.getElementById('Map').style.display = 'none';
				document.getElementById('building').style.display = 'none';
				document.getElementById('content').style.display = 'none';
				document.getElementById('printDiv').style.display = 'block';
				var p = '<table width="954" border="0" style="padding:10px;"><tr><td align="center"><font face="Verdana" size="2">Click to </font><a href="javascript:print()"><font face="Verdana" size="2">Print</font></a><font face=Verdana size=2>&nbsp;this map</font></td></tr>';
				p += '<tr><td><img src="'+url+'views/images/spacer.gif" height="3px" /></td></tr>';
				//p += '<tr><td align="center">'+name+'</td></tr>';
				//p += '<tr><td><img src="'+url+'views/images/spacer.gif" height="3px" /></td></tr>';
				if(levelIndex != 1){
					p += '<tr><td align="center"><img width="900px" height="800px" src="http://test2.street-directory.com/ngeeann/ngeeann_genmap_new.cgi?x='+x+'&y='+y+'&level='+levelIndex+'&star='+star+'&sizex=900&sizey=800"/></td></tr>';
				}else{
					p += '<tr style="background-color:#f3f3cd"><td align="center" width="900px" height="800px"><img width="600px" height="600px" src="http://www.street-directory.com/ngeeann/ngeeann_genmap_new.cgi?x='+x+'&y='+y+'&level='+levelIndex+'&star='+star+'&sizex=600&sizey=600"/></td></tr>';
				}
				p += '<tr><td align="center"><a href="'+url+'" class="link">Home</a></td></tr></table><br>';

				document.getElementById('printDiv').innerHTML = p;
			}
		});
}
