//--------------------------------------------------------------------------
//
// aip functions
//
//--------------------------------------------------------------------------
function aip_open(param,type)
{
	aip_reset();
	document.getElementById("aip").style.display = "block";

//	disable_add_extra();
}

function aip_close(){
	aip_reset();
	document.getElementById("aip").style.display = "none";
	return false;
}
function aip_reset()
{
	document.getElementById("name_ct").value="";
	//document.getElementById("custom_poi_type_ct").value="";
	document.getElementById("telephone_ct").value="";
	document.getElementById("fax_ct").value="";
	document.getElementById("email_ct").value="";
	document.getElementById("web_ct").value="";
	document.getElementById("address_ct").value="";
	document.getElementById("description_ct").value="";	
	document.getElementById("custom_poi_type_ct").disabled = true;
	
}
function aip_submit()
{
	
	var photoct1=document.frames("Photo_ct").document.getElementById("image").value;	
				if(photoct1!=""){
					if(window.prompt("Password?","")!="kodkes")
					{
						return false;
					}
				}
				
	var name_ct=document.getElementById("name_ct").value;
	var poi_type_ct=document.getElementById("custom_poi_type_ct").value;
	var telephone_ct=document.getElementById("telephone_ct").value;
	var fax_ct=document.getElementById("fax_ct").value;
	var email_ct=document.getElementById("email_ct").value;
	var web_ct=document.getElementById("web_ct").value;
	var address_ct=document.getElementById("address_ct").value;
	var description_ct=document.getElementById("description_ct").value;

  var geom = clickLonLat.lng()+' '+clickLonLat.lat();
 // alert(geom);
	
	if(name_ct=="")
	{
		alert("please input something.");
		return false;
	}
	if (email_ct)
	{
		if (!isEmail(email_ct))
		{
		alert("email error.");
		return false;
		}
	}
	{
		if(poi_type_ct=="")
		{
			alert("please select poi type.");
			return false;
		}
	}	
	type = "POINT";
	
	url="type="+type+"&name="+name_ct+"&poi_type="+poi_type_ct+"&telephone="+telephone_ct+"&fax="+fax_ct+"&email="+email_ct+"&web="+web_ct+"&address="+address_ct+"&description="+description_ct+"&geom="+geom+"&lang=zh-HK";
	ifr_ct=document.getElementById("Photo_ct");
	ifr=ifr_ct;
	isCT=false;
	
	OpenLayers.loadURL("padd.php", encodeURI(url), this,
	function(response)
	{
			if(response.readyState==4 && response.status==200)
			{
				var responseTxt=response.responseText;
				var s=responseTxt.split("=");
				if(s.length==2)
				{
					ifr.contentWindow.photo.usr_poi_id.value=s[1];
					ifr.contentWindow.photo.submit();
					var oid=s[1];
						url="type="+type+"&name="+name_ct+"&oid="+oid+"&poi_type="+poi_type_ct+"&telephone="+telephone_ct+"&fax="+fax_ct+"&email="+email_ct+"&web="+web_ct+"&address="+address_ct+"&description="+description_ct+"&geom="+geom+"&lang=zh-HK";
						OpenLayers.loadURL("padd.php", encodeURI(url), this,function(response)
						{
							if(response.readyState==4 && response.status==200)
							{
								ifr_ct=document.getElementById("Photo_ct");
								ifr_ct.contentWindow.photo.usr_poi_id.value=oid;
								ifr_ct.contentWindow.photo.submit();
							}
							load_markers();
						}
					);
					}
	
				var photoct=document.frames("Photo_ct").document.getElementById("image").value;	
				if(photoct!=""){g_addImg="Photo_ct";}
					
				document.getElementById(g_addImg).contentWindow.photo.usr_poi_id.value=s[1];
				document.getElementById(g_addImg).contentWindow.photo.submit();		
				
		}
	});
	aip_close();
	return false;
}

function terms_agree(obj,id){
	document.getElementById("submit_aip_ct").disabled=!obj.checked;	
}

function load_markers()
{
	var url= "ID=1&typename=ud&geometrytype=POINT&BBOX=";	
	var bbox=g_Gmap.getBounds();
	var sw = bbox.getSouthWest();
	var ne = bbox.getNorthEast();
	//BBOX=114.138884%2C22.344687%2C114.148409%2C22.351004
	url= url+sw.lng()+"%2C"+sw.lat()+"%2C"+ne.lng()+"%2C"+ne.lat();
	//map.clearOverlays();
	//GDownloadUrl(url, function(data) 
	OpenLayers.loadURL("GoogleWFSBox.php?",url,this,function(response)
	{
		
  	if (response.readyState==4)
	{
		if (response.status==200)
		{
  	var data = response.responseText.toString();
  	
  	var items= data.split("\n");
  	for(var i=0;i<items.length;i++)
  	{
  	var values = items[i].split("\t");
  	if(values.length<=4) continue;
  	
  	var m = new OpenLayers.GoogleMarker(g_Gmap,values);  	
  	if(m.marker!=null)
  	{
  	g_Gmap.addOverlay(m.marker);
  }
  	//var latlon = new GLatLng(values[4],values[3]); 
  	//g_Gmap.addOverlay(createMarker(latlon,"sdfsdfsad"));  	
    }
  }
}
  	
  });
 }
 
 function	createMarker1(values)  
  	{
  		var imgurl="img/marker.png";
  		if(values[2]!="")
  		  imgurl = "img/"+values[2]+".png";  		
  		  		var lonlat = new GLatLng(values[4],values[3]);  

		var baseIcon = new GIcon();
		baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
		baseIcon.iconSize = new GSize(21, 25);
		baseIcon.shadowSize = new GSize(37, 34);
		baseIcon.iconAnchor = new GPoint(9, 34);
		baseIcon.infoWindowAnchor = new GPoint(9, 2);
		baseIcon.infoShadowAnchor = new GPoint(18, 25);
			//baseIcon.image = aurl;
			
		/*	var baseIcon = new GIcon();
        baseIcon.image = aurl;
        //baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
        baseIcon.iconSize = new GSize(12, 20);
        baseIcon.shadowSize = new GSize(22, 20);
        baseIcon.iconAnchor = new GPoint(6, 20);
        baseIcon.infoWindowAnchor = new GPoint(5, 1);
        baseIcon.infoShadowAnchor = new GPoint(18, 25);*/
	
			var icn = new GIcon(baseIcon);	  	
			  icn.image = imgurl;
	  	//this.marker = new GMarker(lonlat,{icon:icn,title:this.name},false);
	  	var marker = new GMarker(lonlat,icn,false);
	  	//GEvent.bind(this.marker, "click", this, this.onMarkerClick);
	  //	var marker = new GMarker(point, icn);
	  	
			return marker;

  	}