/*
 * ht.js
 *
**/

function jLO(exitLoc) {
	new Ajax.Request("/members/member.php?srv=logout", {
		  onSuccess: function() { this.location = exitLoc;}
		});	
}  

function jPop(url, popname, w, h)      
{
    var flags = 'toolbar=no,location=no,directories=no,' +
       'status=no,menubar=no,resizable=yes,copyhistory=no,' +
       'left=50,screenX=50,top=50,screenY=50,scrollbars=yes,' +
       'width=' + w + ',height=' + h;     
    var viewKey = window.open(' ', popname, flags);
    var fullURL = '' + url;
    viewKey.creator = window;
    viewKey.location = fullURL;               
    viewKey.focus();        
} 

function exitIT()                                      
{                                                         
   window.close();                                        
}        
function exitNjump(newloc)
{
   opener.location = newloc ;                              
   window.close();                                        
}                                                 
function exitNclean()                                     
{                                                         
   opener.location.reload();                              
   window.close();                                        
} 





function msgDash() {
  this.document.msglight.src = '$BRITEMSG_IMG';
}                                                        
 


function setHeadNav() {
	// reset the upper navbar
	new Ajax.Updater('headnav', "/pub.php?srv=resetnav", {method: 'get'});
}


function openjoinform(){ 
	joinwin = dhtmlwindow.open("joinbox", "ajax", "pub.php?srv=urequest", "Join HamptonTerrace.org!", 
                                             "width=550px,height=420px,center=1,resize=1,scrolling=1");
}
function joinHT(formId, objId) {
	//alert("joinHT formid:" + formId + " objId:" + objId);
	var comm     = encodeURIComponent($(formId).comments.value);
	var username = encodeURIComponent($(formId).username.value);
    var pass     = encodeURIComponent($(formId).pass.value);
    var pass1    = encodeURIComponent($(formId).pass1.value);
    var email    = encodeURIComponent($(formId).email.value);
    var location = encodeURIComponent($(formId).location.value);
    var token    = encodeURIComponent($(formId).token.value);
    
	var url = "pub.php?srv=uadd&username=" + username + "&pass=" + pass + "&pass1=" + pass1 +
	           "&email=" + email + "&location=" + location + "&token=" + token +
	           "&comments=" + comm ;
	joinwin.load("ajax", url, "Join HamptonTerrace.org!" );
} // end joinHT()


function forumNewPost(token) { 
	forumwin = dhtmlwindow.open("fbox", "ajax", 
			                   "pop.php?srv=faddpost&parent=0&token="+token, 
			                   "New Forum Post", 
                               "width=550px,height=420px,center=1,resize=1,scrolling=1");
} // end forumNewPost()
function forumReply(postid,token) {	
	forumwin = dhtmlwindow.open("fbox", "ajax", 
            "pop.php?srv=faddpost&parent="+postid+"&token="+token, 
            "New Forum Post", 
            "width=550px,height=420px,center=1,resize=1,scrolling=1");	
} // end forumReply()


// SETTINGS
function chooseDefaultPic() {	
	cthumbwin = dhtmlwindow.open("cbox", "ajax", 
            "pop.php?srv=cthumb&twidth=320", 
            "Choose Default Picture", 
            "width=400px,height=420px,center=1,resize=1,scrolling=1");	
} // end chooseDefaultPic()
function saveDefaultPic(formId) {
    var picid;
    var formObj = $(formId);
	for (i = 0; i < formObj.pic_id.length; i++){
		if (formObj.pic_id[i].checked == true){
			picid = formObj.pic_id[i].value;
		}
	}
	var url = "pop.php?srv=sthumb&pic_id=" + picid ;
	new Ajax.Request(url, {
		  method: 'get',
		  onSuccess: function() {window.location.reload();}
		});		
} // end saveDefaultPic()




function tokenSure(formId, checkId) {
	alert("are you sure?");
} // end tokenSure();

function tokenSave(formObj, checkId) {
	//alert("tokenSave  formId:" + formId + " checkId:" + checkId);
	var formObj = $(formObj);
	var token  = $(checkId).checked;
    var value  = "Y";
	if (!token) {value = "N";}
	
	var url = "pop.php?srv=chngtoken&token=" + checkId + "&value=" + value;
	new Ajax.Updater('tokenform', url, {method: 'get'});
} // end tokenSave();
 

function autologSave(objId) {
	//alert("autologSave  formId:" + formId + " checkId:" + checkId);
	var al = $(objId).checked;
    var value  = "Y";
	if (!al) {value = "N";}
	
	var url = "pop.php?srv=chngtoken&token=" + checkId + "&value=" + value;
	new Ajax.Updater('tokenform', url, {method: 'get'});
} // end autoLogSave()


function viewEvent(eventid){
	eventwin = dhtmlwindow.open("eventbox", "ajax", 
			"pop.php?srv=vevent&event_id="+ eventid , 
			"Event:",  "width=550px,height=420px,center=1,resize=1,scrolling=1");	
}
function formEvent(eventid){ 
	eventwin = dhtmlwindow.open("eventbox", "ajax", 
			"pop.php?srv=fevent&event_id="+ eventid , 
			"Event:",  "width=550px,height=420px,center=1,resize=1,scrolling=1");
}
function saveEvent(formId, objId) {
	//alert("saveEvent formid:" + formId + " objId:" + objId);
	var srv      = $(formId).srv.value;
	var eventid  = $(formId).event_id.value;
	var sd       = $(formId).event_start.value;
	var ed       = $(formId).event_end.value;
	var title    = encodeURIComponent($(formId).event_title.value);
	var desc     = encodeURIComponent($(formId).event_description.value);
    var location = encodeURIComponent($(formId).location.value);
    var email    = encodeURIComponent($(formId).event_email.value);
    var web      = encodeURIComponent($(formId).event_web.value);
    var tokenlist = "";
    var tcount    = $(formId).token.length; 
    for (var x=0; x < $(formId).token.length; x++) {
    	if ($(formId).token[x].checked) {
    		tokenlist += "&token[]=" + $(formId).token[x].value;
    	}
    }	    
	var url = "pop.php?srv="  + srv      + "&event_id="    + eventid + 
	          "&event_start=" + sd       + "&event_end="   + ed    + 
	          "&event_title=" + title    + "&event_description="   + desc + 
	          "&location="    + location + "&event_email=" + email + "&event_web="  + web +
	          tokenlist ;
	new Ajax.Request(url, {
		  method: 'get',
		  onSuccess: function(transport) {
		    if (transport.responseText == 1) { // good
		    	window.location.reload();
		    } else {  // error
		    	eventwin.load("inline", transport.responseText, "Event: Errors Found")
		    }
		  }
		});	
} // end saveEvent()
function delEvent(formId, objId) {
	var eventid  = $(formId).event_id.value;	
	var url = "pop.php?srv=delevent&event_id=" + eventid + "&objid=" + objId ;
	new Ajax.Request(url, {
		  method: 'get',
		  onSuccess: function() {window.location.reload();}
		});		
} // end delEvent()
  
 
function daychooser(yearmonth, objId){ 
	var dateXY = Position.page($(objId));
	var leftxy = dateXY[0];
	var topxy  = dateXY[1];
	var url = "pop.php?srv=calchooser&yearmonth=" + yearmonth + "&objid=" + objId;
	cpwin = dhtmlwindow.open("calpopbox", "ajax", url, "Calendar:", 
                             "width=250px,height=180px,left="+leftxy+",top="+topxy+",center=0,resize=0,scrolling=0");
}
function changedate(yearmonth, objId){
	var url = "pop.php?srv=calchooser&yearmonth=" + yearmonth + "&objid=" + objId;
	cpwin.load("ajax", url, "Calendar:" );	
}
function setdate(newdate, objId){
	$(objId).value = newdate;
	cpwin.close();
}



function viewHelp(title, srv) { 
	var helpwin = dhtmlwindow.open("helpwin", "ajax", 
			                   "pop.php?srv="+srv, "Help: " + title,
                               "width=550px,height=420px,center=1,resize=1,scrolling=1");
} // end viewHelp()




function setLaston() {
	var url = "pop.php?srv=setlaston" ;
	new Ajax.Request(url, {method: 'get'});	
} // end setLaston()



function convsManager() {
	convswin = dhtmlwindow.open("msgbox", "ajax", 
			"pop.php?srv=mngconvs" , 
			"My Chats:",  "width=450px,height=300px,center=1,resize=1,scrolling=1");
} // end convsManager()
function convsView(convs_id) { 
	var url = "pop.php?srv=viewmsg&conversation_id=" + convs_id ;
	convswin.load("ajax", url, "View Message" );
}
function convsSave(formId) {
	//alert("convsSave formid:" + formId );
	var text     = encodeURIComponent($(formId).convs_text.value);
	var convs_id = $(formId).conversation_id.value;
	var url = "pop.php?srv=replymsg&conversation_id=" + convs_id + "&convs_text=" + text ;
	convswin.load("ajax", url, "My Chats:" );
} // end convsSave()
function convsNew(userid) {
	convswin = dhtmlwindow.open("msgbox", "ajax", 
			"pop.php?srv=msgcomp&to_userid=" + userid , 
			"My Chats: Compose Message",  "width=450px,height=300px,center=1,resize=1,scrolling=1");
} // end convsNew()
function convsSaveNew(formId) {
	//alert("convsSaveNew formid:" + formId );
	var text   = encodeURIComponent($(formId).convs_text.value);
	var users  = $(formId).userlist.value;
	var url = "pop.php?srv=sendmsg&userlist=" + users + "&convs_text=" + text ;
	convswin.load("ajax", url, "My Chats:" );
} // end convsSaveNew()
function convsDelMany(formId) {
	//alert("ConvsDelMany formid: "+ formId);
	var convslist = "";
	var delcount  = 0 ;
	var ccount    = $(formId).dconvs.length; 
	for (var x=0; x < $(formId).dconvs.length; x++) {
		if ($(formId).dconvs[x].checked) {
			convslist += "&dconvs[]=" + $(formId).dconvs[x].value;
			delcount++;
		}
	}
	var url = "pop.php?srv=msgDelMany" + convslist ;
	//alert("URL:"+url);
	if (delcount > 0) {
		convswin.load("ajax", url, "My Chats:" );
	}
} // end convsDelMany()
function convsDelete(dconvs) {
	var url = "pop.php?srv=msgDelete&dconvs=" + dconvs ;
	convswin.load("ajax", url, "My Chats:" );
} // end convsDelete()



function viewMember(userid){
	//alert("viewMember:"+ userid);
	memwin = dhtmlwindow.open("memberbox", "ajax", 
			"pop.php?srv=uview&user_id="+userid , 
			"Member:",  "width=550px,height=420px,center=1,resize=1,scrolling=1");	
} // end viewMember()



function viewPic(pic_id) {
	picwin = dhtmlwindow.open("picbox", "ajax", 
			"pop.php?srv=vpic&pic_id="+pic_id , 
			"Picture:",  "width=700px,height=600px,center=0,resize=1,scrolling=1");	
} // end viewPic()


