
//   	    function butstart() {
//         document.getElementById("buttons").innerHTML="<input type=\"submit\" value=\" SAVE MAP VIEW\" onClick=\"smv();\"><input type=\"submit\" value=\" SAVE MARKERS \" onClick=\"sm();\"><input type=\"submit\" id=\"adm\" value=\" ADD NEW MARKER \" onClick=\"addpmark();\"></span> &nbsp; &nbsp;<b id=\"blurb\"></b> ";
//        }; 
 


function loginstart() {

 //setCookie('ml',fbuser+'OFBO'+rnumpass,1000,'/','www.massivemap.com')	
			
 setCookie('ml','LIOMPO'+mapsid+'O'+rnumpass+'OMP',null,'/','www.massivemap.com') ///// ////  //////   here
	
	
//document.getElementById("vm3").innerHTML="<a href=\"javascript:placel()\" onfocus=\"if (this.blur) this.blur();\">List Your Registered Markers</a>"	  
//  document.getElementById("mm1").innerHTML=""	          
    yourmap()                                         	                                 
    var center = map.getCenter();                    //  jgh();	       // want to loose this
            lng =  center.lng() ;
            lat =  center.lat() ;  
            zm = map.getZoom();                                  /// var definition here? also set mtp on start so new markers are correct..
            
//document.getElementById("mm2").innerHTML= "<a href=\"javascript:addpmarkn()\" onfocus=\"if (this.blur) this.blur();\">Add a place to the map!</a></span>"      
    
     butstart();     
 //   if (cvwmd=='pub'){ placel();} //mainly to clear public markers on logging in...
    placel();
    
 //  setCookie('lgst','DL'+clem+hmmmmm,1000)      ////   sort encrypt password....
    
    
     }



        function addpmarkn(){inmap=-1;addpmark()}     
        
        function addpmarkd(){inmap=0;addpmark()}    
                 
        function addpmark() {  /// inmap=0
	        svalert = 1;  	                      
	        newmarks++;
	        mkst++;
	        highid++;
	        uidn[mkst]=highid; 
	        pmstat[mkst]="n"; 
	        mkid[mkst]="new"; 
	        mklnm[mkst]= "(Enter Place Name)";          
	        mkhtm[mkst]= ""; 
	        mksha[mkst]= 1; 
	        mktag[mkst]= ""; 	
	        lck[mkst]=0;
	        mkrnd[mkst]= Math.floor(Math.random()*999999999+1)
	                	        
	        mkzm[mkst] = zm   // document.getElementById("hzm").value;       //mk sure not empty
	        mktyp[mkst] = mtp   /// document.getElementById("htyp").value;
	        mkpica[mkst] = "<img id=\"idpic\" src=\"logo.jpg\" height=\"120\">"; 	  /// dont think I need mkpic anymore        	         
	        var newinf = "New Marker "+mkst;
//            lngc =  document.getElementById("hlng").value ; 
//            latc =  document.getElementById("hlat").value ;          
 //           zmonqm = document.getElementById("hzm").value;  
      	 var point = new GPoint(lng,lat);
      	 
      	 mklat[mkst]=lat; mklng[mkst]=lng;
      	 
      	 adding=1; mover=1;                            //// inmap confusing name just about dragging
         markerp = cLPMarker(point,newinf,mkst);         
      //   pmarker[i] = markerp; 
         map.closeInfoWindow() ;  
         map.addOverlay(markerp);
         markerp.enableDragging();	
         
         GEvent.addListener(map, "mousemove", function(mousept){   if(inmap==0){inmap=1}   ///mover not back to 1 so no infwin open on zoom click
         markerp.setPoint(mousept);
        mklat[mkst] = mousept.lat()
 	    mklng[mkst] = mousept.lng()
     })
 
          
     
     
      GEvent.addListener(map, "click", function(mousept){ 
	     dropmark()    
	      })
	      	      
// 	      GEvent.addListener(map, "click", function(overlay, point) {     
//           if (point) { //  alert('drop')
//           dropmark() 
//           }
//         });
         
  
         GEvent.addListener(map, "mouseout", function(){   inmap=-1 // so only straight drag works
	     if (mover==1){ 
		 var gpnt = new GLatLng(lat,lng);        
	     markerp.setPoint(gpnt)
	     mklat[mkst] = gpnt.lat()
 	     mklng[mkst] = gpnt.lng()
	        }   
                   })	
        // updatemlist()                        try checking this out for now
        
         butstore = document.getElementById("buttons").innerHTML;  
         document.getElementById("buttons").innerHTML="<b>Click the Map to Add your place or</b> <input type=\"submit\" value=\" CANCEL \" onClick=\"cancelmark("+mkst+");\"> &nbsp; &nbsp;<b id=\"blurb\">  </b>   ";  
             
   //      document.getElementById("buttons").innerHTML="<b>Click the Map to Add your place, then...</b> <input type=\"submit\" value=\" ADD MARKER INFO\" onClick=\"opinfwin();\">&nbsp; &nbsp; <input type=\"submit\" value=\" DONE \" onClick=\"butback();\"><input type=\"submit\" value=\" CANCEL \" onClick=\"cancelmark("+mkst+");\"> &nbsp; &nbsp;<b id=\"blurb\">  </b>   ";  
         
//          document.getElementById("mm2").innerHTML="<span id=\"mm2\"><a href=\"javascript:opinfwin()\" onfocus=\"if (this.blur) this.blur();\">Add marker info</a></span>"
     }
     
     
     function butback(){ 
// 	      GEvent.clearListeners(map, "mousemove");

	 document.getElementById("buttons").innerHTML= butstore;  // dont think I need anymore
	 
     }  // updatemlist(); 

          
     function cancelmark(i){      adding=0; mover=0; 
  	     butback()
	     deletemark(i);	
	     } 
     
     function opinfwin(){  GEvent.clearListeners(map, "mousemove");
	     medit(mkst)
	     butback()     /// was checked out pre fb, put back in for fb
	     }
                   

        function logout() {

	 setCookie('ml','NLOOOO',1000,'/','www.massivemap.com')			                
	    
//  	     if(svalert == 1){     
//          var name=confirm("Save your map before quitting?")
//          if (name==true)
//           { sm(); }
//           }
			mkst=0;
 
	     cmapname="";  highid=0;  ntryl=''; ptryl='';  lgst="nl";  marklist="No markers added"; clem='n'; clp='n';
   //    document.getElementById("buttons").innerHTML="<span id=\"blurb\"></span> ";
         butstart();
             document.getElementById("contbut").innerHTML = "<br>";
             map.clearOverlays();
             map.panTo(new GLatLng (16.171875,20.96143961409684));
             map.setZoom(2);
           document.getElementById("tleft").innerHTML = "";
           document.getElementById("tright").innerHTML = "";
   //      document.getElementById("mail").innerHTML = "";          
           document.getElementById("sidebar").innerHTML="";
           document.getElementById("trpic").innerHTML = "<img id=\"idpic\" src=\"logo.jpg\" height=\"120\">" ; 
   //        document.getElementById("options").innerHTML = "";
   //        document.getElementById("listmenu").innerHTML = "";   
   //        document.getElementById("addedme").innerHTML = "";  
   //        document.getElementById("places").innerHTML = "";
   //        document.getElementById("mkvw").innerHTML = "";                          
   //        document.getElementById("vm3").innerHTML="<a href=\"javascript:placel()\" onfocus=\"if (this.blur) this.blur();\">List Your New Markers</a>"
           	
                  logbox();
                  logreg();
        };     
        
        
        
        function smvd(){
	        smvfb = 1;
	        sm()
	        smvfb = 0;
           homelat=lat; homelng=lng;   homezm=zm;  hometp=mtp;	        
	        }
	        
// 	    function sm(){
// 	     placel()
//          smncl()     /// I dont want to close the window on every save I think...
// 		    }    
                
        function sm(){  
	    if (lgst=='nl'){ document.getElementById("blurb").innerHTML='You need to log in...';
	    alert('You need to log in to save your markers...')
	    return;
	    }
	        	        
	          if(mkst>0){                 /// now adapt for fb....  ////
    
	       svalert = 0;   /// possibly obsolete now
           
           if (cloci!=-1){latc=pmarker[cloci].getPoint().lat() ; lngc=pmarker[cloci].getPoint().lng() ; 
           latlngc=latc+','+lngc          
           var qumsg = "<b>"+mklnm[cloci]+"</b><br>"+mkhtm[cloci]  
           qumsg = qumsg.replace(/\"/g, "");	
	       qumsg = qumsg.replace(/\'/g, "");
	       qumsg = qumsg.replace(/&/g, " and ");            
           }else{latlngc="n";var qumsg="";}
                     
 //var sendat = clem+'&fbuser='+fbuser+'&fbname='+fbname+'&zm='+zm+'&lat='+lat+'&lng='+lng+'&tp='+mtp+'&latlngc='+latlngc+'&zmonqm='+zmonqm; 
 
 var sendat = clem+'&ptrys='+clp+'&zm='+zm+'&lat='+lat+'&lng='+lng+'&tp='+mtp+'&latlngc='+latlngc+'&zmonqm='+zmonqm; 
 
 
        sendat +='&newmarks='+newmarks+'&mkst='+mkst+'&lastsvmk='+lastsvmk+'&clocuidn='+clocuidn+'&highid='+highid+'&qumsg='+qumsg+'&smvfb='+smvfb;	     
	       
        var mkdata="";               ///dont put ~ start
        for (var i=1;i<=mkst;i++) {
	    
	    var cllnm =mklnm[i].replace(/~/g, "_") 
	    var clhtm =mkhtm[i].replace(/~/g, "_")     

	    var cmksha =mksha[i]                             //// .replace(/~/g, "_")    /// not a string anymore
	    var cmktag =mktag[i].replace(/~/g, "_")      

        if (cmktag=='(add a tag e.g. hotel, hostel)'){cmktag=''}	    
	//  if (mkwww=='(add www link here)'){mkwww=''} 
	    	    	    	         
	    mkdata += mkid[i] +"~";  
	    mkdata += uidn[i] +"~";   
	    mkdata += pmstat[i] +"~";      
	    mkdata += cllnm +"~";    
	    mkdata += clhtm +"~"; 
	    mkdata += mkzm[i] +"~"; 
	    mkdata += mktyp[i] +"~";  	    
	    
// 	    mkdata += pmarker[i].getPoint().lat() +"~"; 
// 	    mkdata += pmarker[i].getPoint().lng() +"~"; 

        mkdata += mklat[i] +"~"; 
        mkdata += mklng[i] +"~"; 	    
	    
	//  mkdata += lck[i] +"~";    	     //// if zoom>threshold, set to lock in database? 
	    mkdata += "1~";    	     //// or lock everything in database for now
	    
	    mkdata += cmksha +"~";
	    mkdata += mkrnd[i] +"~";    
    
	    mkdata += cmktag +"~~~x~~~";   
	    
// 	    mkdata = mkdata.replace(/\'/g, "&#39;");
// 	    mkdata = mkdata.replace(/\"/g, "&#34;");	

	    mkdata = mkdata.replace(/&/g, " and ");	///    &'s seem to fuck it up better check for other chars...

	    mkdata = mkdata.replace(/\"/g, "");	
	    mkdata = mkdata.replace(/\'/g, "");
	    
//	    mkdata = mkdata.replace(/\'/g, "*bqt*");  /// this would work but need to decode for every map view and fb main page etc..
	    
	    if((pmstat[i]=="n")&&(cllnm!="(Enter Place Name)")){                 /// ; alert(mkhtm[i])
	    pmstat[i]="tr";  //transitional   
          }
	    }
	      var bigvar="bv="+mkdata;
	      
		//       if (lgst!="nl"){    
         
          ca('sm.php?ntrys='+sendat,'blurb', 'Saving Markers...',bigvar)		 
  //  }else{
    //      ca('smnl.php?ntrys='+sendat,'blurb', 'Saving Markers...',bigvar)		 
// document.getElementById("blurb").innerHTML = "You need to register to save your map... <a href=\"javascript:lnu()\">Go</a>"   	    
//	    };  /// alert(sendat)

	cvwmd="umk";
	          
    }}
         
  
        
        function trylogin()  {  svalert = 0;
           ntryl =  document.getElementById("ntryl").value ; 
           ptryl =  document.getElementById("ptryl").value ; 
          ntryl = ntryl.toLowerCase();    ptryl = ptryl.toLowerCase();      /// strip spaces at some point  //  logblb        
	 	    evalAHAH('li.php?ntryl='+ntryl+'&ptryl='+ptryl+'&mkstprelog='+mkst+'&clocuidnpre='+clocuidn,'blurb','Connecting...')	// logblb 
	 	 // document.getElementById("options").innerHTML = ""  
	    
        }; 
        
        
        /// gonna call different trylogin version when map is already being viewed basically       
       /// also write routine for viewing other pages while logged in.. buttons just home and leave message     
        //first do quick message properly ....
        
                   
        
	function getwidth() {    /// for fb version hmm not entirely sure... scale probs between firefox and explorer
	
 screenH = 480; scrW = 600;
if (parseInt(navigator.appVersion)>3) {
// screenH = screen.height;
 scrW = screen.width;
}
else if (navigator.appName == "Netscape" 
    && parseInt(navigator.appVersion)==3
    && navigator.javaEnabled() ) 
{
 var jToolkit = java.awt.Toolkit.getDefaultToolkit();
 var jScreenSize = jToolkit.getScreenSize();
// screenH = jScreenSize.height;
 scrW = jScreenSize.width;
}
return scrW
}



function boxtext(){	                    conts = conts.replace(/,/g, " ") ;  	      
conts = conts.replace(/  /g, " ") ; 	   // sorting old prob with IE    		
lodconts = conts.replace(/ /g, "\n") ;
if (lodconts =='none'){lodconts=''}	      	
 document.getElementById("rlist").innerHTML="<div id=\"boxtext\"><TEXTAREA id=\"frl\" ROWS=\"17\" COLS=\"34\" WRAP>"+lodconts+"</TEXTAREA></div> ";	
  document.getElementById("contbut").innerHTML="<br><input type=\"submit\" value=\"SAVE FRIEND LIST\" onClick=\"updatef()\"><input type=\"submit\" value=\"CANCEL\" onClick=\"contal()\">";
	}

	
	
	
function updatef(){                                                           /// change to post I think!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
var updf = document.getElementById("frl").value;

updf = updf.replace(/\r\n/g, " ") ; updf = updf.replace(/\r/g, " ") ;
updf = updf.replace(/\n/g, " ") ;   /// get rid of nls before ahah
ca('updatecont.php?ntryl='+ntryl+'&ptryl='+ptryl,'blurb','Connecting....','contactlist='+updf)		 //     
	
conts = updf;    ///keep this as text

 contht = updf.replace(/ /g, "<br>") ;   	  //  contht = conts.replace(/ /g, "<br>") ;   
//document.getElementById("rlist").innerHTML="<div id=\"sidebar\" style=\"overflow:auto; height:100px;\"></div> ";
document.getElementById("contbut").innerHTML="<br><br><input type=\"submit\"  value=\"EDIT LIST\" onClick=\"boxtext();\"><input type=\"submit\"  value=\"SEND MAIL\" onClick=\"sndml();\"> ";                  /// change this button replace thingy...
document.getElementById("sidebar").innerHTML = contht ; 
	adding=0; 
 // document.getElementById("sidebar").innerHTML = conts ;
 map.clearOverlays();
 ca('contanddrop.php?ntryl='+ntryl+'&ptryl='+ptryl,'blurb','Searching for friends...','contactlist='+conts)		//      +'&contactlist='+frch 
	    }


		

		function qmupd(){
	qumessage = document.getElementById("quickm").value;
    qumessage =qumessage.replace(/\n/g, "<br>") ;
	evalAHAH('qmupd.php?ntryl='+ntryl+'&ptryl='+ptryl+'&quickm='+qumessage,'blurb','Updating Quick Marker text...')	
		map.closeInfoWindow() ;
		placel();      	       	
}

				
		function nameupdate(){
   nameupd = document.getElementById("ufname").value;
	evalAHAH('nameupd.php?ntryl='+ntryl+'&ptryl='+ptryl+'&nameupd='+nameupd,'namebl','Updating your name...')		       		
			}

					
function showopts(){ document.getElementById("options").innerHTML = "<br><br><br><br><br> "
document.getElementById("mkvw").innerHTML = "<table border=\"0\" cellpadding=\"7\" width=\"90%\" align=\"center\"><td><h3>Name/Map Title:</h3><p id=\"namebl\">The title for your map, and also the name appearing on your friends contact list</p><input type=\"text\" id=\"ufname\"  value=\""+fname+"\"  size=\"100\"><input align=\"right\" type=\"button\"  value=\"UPDATE NAME\" onClick=\"nameupdate();\"><h3>Profile Picture:</h3><p id=\"picbl\">Put up a picture to appear on your main map page. You can add pictures to individual markers by clicking the marker after you have saved its location. If you already have a picture of yourself on the web you can enter a link to it here to show it on your map page...</p><p><input type=\"text\"   id=\"piclink\"  value=\""+uplpic+"\"  size=\"100\"><input align=\"right\" type=\"button\" id=\"picup\" value=\"SUBMIT PICTURE\" onClick=\"piclinku();\"><br><p>Alternatively upload your picture...</p><form action=\"pictureupload.php\" target=\"_blank\" method=\"post\"><input type=\"hidden\" name=\"ntryl\" value=\""+ntryl+"\"><input type=\"hidden\" name=\"ptryl\" value=\""+ptryl+"\"><input type=\"submit\" value=\"UPLOAD A PICTURE\"></form> </p><br><h3>Add Map Information</h3><span id=\"blgwin\"></span><p id=\"blgblb\">Add information to your main map... Add a commment to appear below your map. (You can use HTML tags)</p><span id=blgbt1><input type=\"submit\" value=\"ADD MAP INFO\" onClick=\"blogwin();\"></span><p>This is the link to view your personal map:<br><br><b><a href=\"http://www.massivemap.com/u.php?i="+rndlink+"\" target=\"_blank\">http://www.massivemap.com/u.php?i="+rndlink+"</a></b></p><input type=\"text\" id=\"qulink\"  value=\"www.massivemap.com/u.php?i="+rndlink+"\"  size=\"100\" onfocus=\"this.select();\" onblur=\"embck()\"><br><br>&nbsp;&nbsp;<a href=\"javascript:clsopt()\">Return to main map (close options)</a> </td></table>";
	     window.location.hash="mkvw";   	
	} 
function embck(){document.getElementById("qulink").value= "www.massivemap.com/u.php?i="+rndlink;}
function blogwin(){
		    var detailsnl = details.replace(/<br>/g, "\n") ;  
        document.getElementById("blgwin").innerHTML="<textarea id=\"blg\" rows=\"15\" cols=\"80\" wrap>"+detailsnl+"</textarea><br><input type=\"submit\" value=\"ADD TEXT\" onClick=\"goblog();\"><input type=\"submit\" value=\"CANCEL\" onClick=\"clblog();\"> ";
   document.getElementById("blgbt1").innerHTML= "";     	        	
	}
function goblog(){
    details = document.getElementById("blg").value;   // change to ca post
    details = details.replace(/\n/g, "<br>") ;  
	evalAHAH('blogup.php?ntryl='+ntryl+'&ptryl='+ptryl+'&details='+details,'blgblb','Updating Information...')		       		
	clblog();}	
function clblog(){
 document.getElementById("blgwin").innerHTML="";
 document.getElementById("blgbt1").innerHTML= "<input type=\"submit\" value=\"ADD INFO\" onClick=\"blogwin();\">";    	        	 	
	}	
			
function piclinku(){
 piclink = document.getElementById("piclink").value;    ///keep this as text	
evalAHAH('piclink.php?ntryl='+ntryl+'&ptryl='+ptryl+'&piclink='+piclink,'picbl','Setting your picture...')
// document.getElementById("trpic").innerHTML = "<img id=\"idpic\" src=\""+piclink+"\" height=\"180\">" ; 		       		
}
	
function picupl() {
var upupic = document.getElementById("upupic").value;    ///keep this as text	
evalAHAH('picupload.php?ntryl='+ntryl+'&ptryl='+ptryl+'&upupic='+upupic,'blurb','Starting Upload')	
	}
		
		
function panzmt(lt,lg,z,t,n){
map.setZoom(z)
map.setMapType(t);
map.panTo(new GLatLng(lt,lg));	
//document.getElementById("blurb").innerHTML=n+" <input type=\"submit\" value=\"DELETE MAP VIEW\" onClick=\"dmv('"+n+"');\"> ";
}

function panzm(lt,lg,z,t,n){map.setZoom(z);map.setMapType(t);map.panTo(new GLatLng(lt,lg));}  /// hmmmm dont need i think


    function zoomin(lt,lg,z,t){  //  alert('z='+z+'  zm='+zm)
	if (zm>=z){z=zm+1}    
	map.closeInfoWindow()            
   if (t=="Satellite"){
	     map.setCenter(new GLatLng(lt,lg),z,G_SATELLITE_MAP );   
	   } else {
		    if (t=="Hybrid")  {
			  map.setCenter(new GLatLng(lt,lg),z,G_HYBRID_MAP); 
			      }  else  {				      
		        map.setCenter(new GLatLng(lt,lg),z,G_NORMAL_MAP );  			      
     }} 
 //    alert('z='+z+'  zm='+zm) 
    }




function dmv(n){
evalAHAH('dmv.php?ntryl='+ntryl+'&ptryl='+ptryl+'&dmv='+n,'blurb','Deleting...')
}


function setCookie(c_name,value,expiredays,path,domain,secure)      //  set path as "/"
{var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays)   //// think this function does not make the cookie global on domain...
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
//alert('test  '+value)
} 

// function setCookie(c_name,value,expiredays)
// {var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays) // think this function does not make the cookie global on domain...
// document.cookie=c_name+ "=" +escape(value)+
// ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
// } 











