var boxpesan=(function(){
	var boxwin=new Object;
	var parrent=null;
	var tanda=null;
	var map=null;
	var tandalokasi=null;
	var marker=null;
	var defzoom= 5;
	var masterbox=[];
	var bgbox=[];
	
	return{
		load:function(){
			var htm="<style type=\"text/css\">";
			htm+="@-webkit-keyframes masuk2 {";
			htm+="0%   {top: -1500px;}";
			htm+="100%  {top: "+(50+boxpesan.yscrol())+"px;}";
			htm+="}";
			
			htm+="@keyframes masuk2 {";
			htm+="0%   {top: -1500px;}";
			htm+="100%  {top: "+(50+boxpesan.yscrol())+"px;}";
			htm+="}";
			
			htm+="@-webkit-keyframes keluar2 {";
			htm+="0%   {top: "+(50+boxpesan.yscrol())+"px;}";
			htm+="100%  {top: -1500px;}";
			htm+="}";
			
			htm+="@keyframes keluar2 {";
			htm+="0%   {top: "+(50+boxpesan.yscrol())+"px;}";
			htm+="100%  {top: -1500px;}";
			htm+="}";
			
			htm+=".animmasuk2 {";
			htm+="top:"+(50+boxpesan.yscrol())+"px;";
			htm+="-webkit-animation: masuk2 0.5s;";
			htm+="animation: masuk2 0.5s;";
			htm+="}";
			
			htm+=".animkeluar2 {";
			htm+="top:-1500px;";
			htm+="display:none;";
			htm+="-webkit-animation: keluar2 0.5s;";
			htm+="animation: keluar2 0.5s;";
			htm+="}";
				
			htm+="</style>";
			$("#boxcss_boxpesan").html(htm);
		},
		yesno:function(a){
			boxpesan.load();
			var boxw=document.createElement("div");
			var boxbg=document.createElement("div");
			masterbox.push(boxw);
			bgbox.push(boxbg);
			var nourut=(masterbox.length-1);
			
			var ttl=a['title'];
			var ps=a['pesan'];
			var htm="";
			htm="<div style='padding:5px 10px;background:#d9d9d9;font-size:15px;font-weight:bold;'>"+ttl;
			htm+="<span class='box_pesan_tutup' onclick='boxpesan.tutupobj("+nourut+")'></span>";
			htm+="</div>"
			htm+="<p align='center' style='padding:10px'>"+ps+"</p>";
			htm+="<div align='center' style='width:100%;margin-top:10px;margin-bottom:20px;'>";
			htm+="<div id='box_loader_yes_no' class='error'></div>";
			htm+="<span id='bt_yesno_no_"+nourut+"' class='btmerah' onclick='boxpesan.tutupobj("+nourut+")'>Batal</span>&nbsp;&nbsp;<span id='bt_yesno_ya_"+nourut+"' class='bthijau'>Proses</span>"
			htm+="</div>";
			boxw.innerHTML=htm;
			
			document.body.appendChild(boxw);
			boxw.className="box_wpesan topawal animmasuk2";
			
			boxbg.className="bg_box_wpesan";
			document.body.appendChild(boxbg);
			var obj=new Object;
			obj.no=nourut;
			obj.batal=document.getElementById("bt_yesno_no_"+nourut);
			obj.proses=document.getElementById("bt_yesno_ya_"+nourut);
			obj.tutup=function(){
				document.body.removeChild(boxbg);
				bgbox.splice(nourut,1);
				
				boxw.className="box_wpesan topawal animkeluar2";
				document.body.removeChild(boxw);
				masterbox.splice(nourut,1);
			};
			return obj;
		},
		peringatan:function(a){
			boxpesan.load();
			
			var boxw=document.createElement("div");
			var boxbg=document.createElement("div");
			masterbox.push(boxw);
			bgbox.push(boxbg);
			var nourut=(masterbox.length-1);
			
			var ttl=a['title'];
			var ps=a['pesan'];
			
			var htm="";
			htm="<div style='padding:5px 10px;background:#d9d9d9;font-size:15px;font-weight:bold;'>"+ttl;
			htm+="<span class='box_pesan_tutup' onclick='boxpesan.tutupobj("+nourut+")'></span>";
			htm+="</div>"
			htm+="<p align='center' style='padding:10px;color:red;'>"+ps+"</p>";
			htm+="<div align='center' style='width:100%;margin-top:10px;margin-bottom:20px;'>";
			htm+="<span class='btmerah' onclick='boxpesan.tutupobj("+nourut+")'>Tutup</span>"
			htm+="</div>";
			
			boxw.innerHTML=htm;
			document.body.appendChild(boxw);
			boxw.className="box_wpesan topawal animmasuk2";
			
			boxbg.className="bg_box_wpesan";
			document.body.appendChild(boxbg);
		},
		err:function(a){
			boxpesan.load();
			
			var boxw=document.createElement("div");
			var boxbg=document.createElement("div");
			masterbox.push(boxw);
			bgbox.push(boxbg);
			var nourut=(masterbox.length-1);
			var err="ERROR DATA";
			
			switch(a)
			{
				case 0:
					err="ERROR INPUT/EDIT DATA !";
					break;
				case 23000:
					err="DATA INPUTAN SUDAH ADA (GANDA) !";
					break;
			}
			
			var htm="";
			htm="<div style='padding:5px 10px;background:#d9d9d9;font-size:15px;font-weight:bold;'>TERJADI KESALAHAN";
			htm+="<span class='box_pesan_tutup' onclick='boxpesan.tutupobj("+nourut+")'></span>";
			htm+="</div>"
			htm+="<p align='center' style='padding:10px;color:red;'>"+err+"</p>";
			htm+="<div align='center' style='width:100%;margin-top:10px;margin-bottom:20px;'>";
			htm+="<span class='btmerah btnclose' onclick='boxpesan.tutupobj("+nourut+")'>Tutup</span>"
			htm+="</div>";
			
			boxw.innerHTML=htm;
			document.body.appendChild(boxw);
			boxw.className="box_wpesan topawal animmasuk2";
			
			boxbg.className="bg_box_wpesan";
			document.body.appendChild(boxbg);
		},
		win:function(a){
			
			boxpesan.load();
			var obj=new Object;
			
			//$("#box_wpesan").html("");
			var boxw=document.createElement("div");
			boxw.style.maxWidth="100%";
			var boxbg=document.createElement("div");
			masterbox.push(boxw);
			bgbox.push(boxbg);
			var nourut=(masterbox.length-1);
			
			var ttl=a['title'];
			var ps=a['box'];
			var tutup=a['close'] || "ya";
			var lebar=a['lebar'] || null;
			var tinggimax=a['tinggimax'] || null;
			var tinggi=a['tinggi'] || null;
			var layar=a['layar'] || "YA";
			var padding=a['padding'] || null;
			
			boxwin["box_main_win_"+nourut]=document.getElementById(ps);
			boxwin["box_main_par_"+nourut]=document.getElementById(ps).parentElement;
			document.getElementById(ps).style.display="block";
			
			htm="<div class='title_window'>"+ttl;
			
			if(tutup!=null && tutup=="ya"){
				htm+="<span class='box_pesan_tutup' onclick='boxpesan.tutupwin("+nourut+")'></span>";
			}
			htm+="</div>"
			htm+="<div id='box_main_win_"+nourut+"' align='left' style='width:100%;margin-top:10px;margin-bottom:20px;'>";
			
			htm+="</div>";
			if(lebar!=null){
				boxw.style.width=lebar;
				
			}
			boxw.innerHTML=htm;
			document.body.appendChild(boxw);
			boxw.className="box_wpesan topawal animmasuk2";
			/*if(tinggimax!=null){
				if(tinggimax=="fit"){
					//boxw.style.maxHeight=$(window).height()-(($(window).height()*15)/100)+"px";
				}
			}*/
			if(layar=="YA") boxbg.className="bg_box_wpesan";
			document.body.appendChild(boxbg);
			
			//$("#box_wpesan").html(htm);
			var mainwin=document.getElementById('box_main_win_'+nourut);
			mainwin.appendChild(boxwin["box_main_win_"+nourut]);
			document.body.className="stopscroll";
			/*if(tinggimax!=null){
				if(tinggimax=="fit"){
					mainwin.style.maxHeight=($(window).height()-(($(window).height()*15)/100)-90)+"px";
					mainwin.className="box_winscroll";
				}
			}*/
			mainwin.style.maxHeight=($(window).height()-(($(window).height()*15)/100)-90)+"px";
			mainwin.className="box_winscroll";
			
			if(tinggi!=null){
				mainwin.style.height=tinggi;
				
			}
			
			if(padding!=null){
				mainwin.style.padding=padding;
			}
			obj.tutup=function(){
				boxpesan.tutupwin(nourut);
				document.body.className="";
			};
			obj.hide=function(){
				boxw.style.display="none";
				boxbg.style.display="none";
				document.body.className="";
			};
			obj.show=function(){
				boxw.style.display="block";
				boxbg.style.display="block";
			};
			obj.buka=function(a){
				document.body.appendChild(boxw);
				boxw.className="box_wpesan topawal animmasuk2";
				
				boxbg.className="bg_box_wpesan";
				document.body.appendChild(boxbg);
				
				//$("#box_wpesan").html(htm);
				var mainwin=document.getElementById('box_main_win_'+nourut);
				
				mainwin.appendChild(boxwin["box_main_win_"+nourut]);
			};
			return obj;
			
		},
		peta:function(a){
			boxpesan.load();
			var obj=new Object;
			
			var ttl=a['title'];
			var ps=a['box'];
			var lokasi=a['lokasi'] || "-4.477856485570586,138.09814453125";
			var lebar=a['lebar'] || null;
			var edit=a['edit'] || false;
			var tinggi=a['tinggi'] || null;
			var proses=a['proses'] || null;
			var modepeta=a['mode'] || "buat";
			var ezoom=a['zoom'] || defzoom;
			
			var mwin=document.createElement("div");
			if(lebar!=null){
				mwin.style.width=lebar;
			}
			
			var boxbg=document.createElement("div");
			
			masterbox.push(mwin);
			bgbox.push(boxbg);
			var nourut=(masterbox.length-1);
			
			var boxpeta=document.createElement("div");
			boxpeta.style.width="100%";
			if(tinggi!=null){
				boxpeta.style.height=tinggi;
			}
			
			htm="<div style='padding:5px 10px;background:#d9d9d9;font-size:15px;font-weight:bold;'>"+ttl;
			htm+="<span class='box_pesan_tutup' onclick='boxpesan.tutupobj("+nourut+")'></span>";
			htm+="</div>"
			htm+="<div id='box_main_win_"+nourut+"' align='left' style='width:100%;margin-top:10px;margin-bottom:0px;'>";
			
			htm+="</div>";
			
			mwin.innerHTML=htm;
			document.body.appendChild(mwin);
			mwin.className="box_wpesan topawal animmasuk2";
			
			boxbg.className="bg_box_wpesan";
			document.body.appendChild(boxbg);
			
			var mainwin=document.getElementById('box_main_win_'+nourut);
			mainwin.appendChild(boxpeta);
			if(modepeta=="buat"){
				var boxbt=document.createElement("div");
				boxbt.className="ps_btbawah";
				mainwin.appendChild(boxbt);
				
				var bttutup=document.createElement("span");
				var btproses=document.createElement("span");
				bttutup.className="btnone btbox_bawah";
				btproses.className="bthijau btbox_bawah";
				bttutup.innerHTML="TUTUP";btproses.innerHTML="PROSES";
				boxbt.appendChild(bttutup);
				boxbt.appendChild(btproses);
				
				bttutup.onclick=function(){
					boxpesan.tutupobj(nourut);
				};
				
				obj.proses=btproses;
				obj.tutup=function(){
					boxpesan.tutupobj(nourut);
				};
			}
			
			//tanda=new google.maps.LatLng(-4.477856485570586,138.09814453125);
			
			if(lokasi!=null){
				var lok=lokasi.split(",");
				if(lok.length==2){
					tanda=new google.maps.LatLng(lok[0],lok[1]);
					obj.tanda=lokasi;
				}
			}
			
			obj.tanda=tanda.lat()+","+tanda.lng();
			var myStyle = [
			   {
				 featureType: "administrative",
				 elementType: "labels",
				 stylers: [
				   { visibility: "on" }
				 ]
			   },{
				 featureType: "poi",
				 elementType: "labels",
				 stylers: [
				   { visibility: "on" }
				 ]
			   }
			 ];
			var mapOptions = {
			    zoom: ezoom,
			    center: tanda,
			    scrollwheel:true,
			    mapTypeId: google.maps.MapTypeId.ROADMAP
			};
			map = new google.maps.Map(boxpeta, mapOptions);
			if(edit && modepeta=="buat"){
				marker = new google.maps.Marker({
				      position: tanda,
				      map: map,
				      draggable:true,
				      title: 'Lokasi'
				});
				
				google.maps.event.addListener(marker, 'dragend', function() 
				{
					
				    var geolok=marker.getPosition();
				    obj.tanda=geolok.lat()+","+geolok.lng();
				    
				});
			}else{
				marker = new google.maps.Marker({
				      position: tanda,
				      map: map,
				      draggable:false,
				      title: 'Lokasi'
				});
			}
			map.setOptions({styles: myStyle});
			return obj;
		},
		tutupwin:function(a){
			if(boxwin["box_main_win_"+a]!=null){
				boxwin["box_main_par_"+a].appendChild(boxwin["box_main_win_"+a]);
			}
			boxwin["box_main_win_"+a].style.display="none";
			boxwin["box_main_win_"+a]=null;
			boxwin["box_main_par_"+a]=null;
			
			var mbox=masterbox[a];
			var bgb=bgbox[a];
			document.body.removeChild(bgb);
			bgbox.splice(a,1);
			mbox.className="box_wpesan topawal animkeluar2";
			document.body.removeChild(mbox);
			masterbox.splice(a,1);
			document.body.className="";
		},
		tutup:function(a){
			
			if(boxwin!=null){
				boxwin.style.display="none";
				parrent.appendChild(boxwin);
				boxwin=null;
				parrent=null;
			}
			$("#box_wpesan").attr("class","animkeluar2");
			$("#bg_box_wpesan").hide();
			document.body.className="";
		},
		tutupobj:function(a){
			var mbox=masterbox[a];
			var bgb=bgbox[a];
			document.body.removeChild(bgb);
			bgbox.splice(a,1);
			mbox.className="box_wpesan topawal animkeluar2";
			document.body.removeChild(mbox);
			masterbox.splice(a,1);
			document.body.className="";
		},
		yscrol:function(){
			var top  = window.pageYOffset || document.documentElement.scrollTop;
			return top;
		},
		getlokasi(){
			return tandalokasi;
		}
	}
})();
