/**
 * redirect
 * desc: redirect to another page
 * params: page: url path to page
 */

var resetform = true;
var blockoff = false;

function redirect(page) {
	window.location = page;
}


function record_start(uid, page) {
	st_url = baseurl+'app/ajax/record_times.pjx?point=start&sid='+uid+'&page='+page;
	ajax_do (st_url, 'ajx_start', false);
}

function record_stop(uid, page) {
	st_url = baseurl+'app/ajax/record_times.pjx?point=stop&sid='+uid+'&page='+page;
	ajax_do (st_url, 'ajx_stop', false);
}

function open_details_div(divid) {
	if (div = document.getElementById('div_'+divid)) {
		if (div.style.display == 'block') {
			div.style.display = 'none';
		} else {
			div.style.display = 'block';
		}
	}
}

var newwin = 0;

function open_window(pop, width, height) {
	newwin = 0;
	swidth = self.screen.width;
	sheight = self.screen.height;
	left = (Math.round(swidth / 2)) - (Math.round(width / 2));
	btop = (Math.round(sheight / 2)) - (Math.round(height / 2)); 
	
	try{
		newwindow=window.open(pop,'infobox','width='+width+',height='+height+',left='+left+',top='+btop+',toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,copyhistory=no, resizable=yes');
		window.newwindow.focus();
		setTimeout('newwin = 1;', 500);
		return;
	}
	catch (e){
		//alert(e);
	}
	
}

window.onfocus = closePopup;

function closePopup() {
	try {
		if (window.newwindow && window.newwindow.name != 'infobox' && newwin == 1 && window.newwindow.name != 'uploadStuff') {
			window.newwindow.close();
			newwin = 0;
		}
	}
	catch (e) {
		//alert(e);
		// do nothing
	}
	
}





document.onclick = record;

function record(e) {
	rtn = true;
	if (!e) var e = window.event;
	var tg = (window.event) ? e.srcElement : e.target;
	if (tg.type == 'button' || tg.type == 'image') {		
		if (tg.form) {
			if (tg.form.id) {
				thsform = document.getElementById(tg.form.id);
				form_handler(thsform);
			}
		}
		rtn = false;
	} else if (tg.nodeName=='INPUT' && tg.type != 'checkbox' && tg.type != 'radio') {
		tg.style.border = 'none';
		tg.style.border = '2px inset';
	} else if (tg.nodeName=='SELECT') {
		tg.style.border = 'none';
		tg.style.border = '2px inset';
	} else if (tg.type == 'checkbox' || tg.type == 'radio') {
		if (tg.form) {
			if (tg.form.id == 'callbox') {
				try {
					var thisstr = document.getElementById('txt_'+tg.id).innerHTML;
					var stripped = thisstr.replace(/(<([^>]+)>)/ig,""); 
					try	{
						if (tg.checked == true) {
							document.getElementById('commentbox').value += '\n' + stripped + '\n';
						} else {
							fldval = document.getElementById('commentbox').value;
							document.getElementById('commentbox').value = fldval.replace(stripped, '');
							document.getElementById('commentbox').value = trim_str(document.getElementById('commentbox').value);
						}
					}
					catch (e) {
						alert(e);
					}
				} catch (e) {
					//alert(e);
				}
			}
		}
		rtn = true;
	}
	return rtn;
}

document.onkeypress = determineKey;

function determineKey(e2) {
	if (!e2) var e2 = window.event;
	if (e2.keyCode == 13) {
		var bg = (window.event) ? e2.srcElement : e2.target;
		if (bg.form) {
			var thistag = bg.tagName;
			
			if ('TEXTAREA' != thistag) {
				if (bg.form.id != '') {
					thsform = document.getElementById(bg.form.id);
					
					if (bg.form.method == "" || bg.form.method == "get") {
						form_handler(thsform);
						return false;
					} else {
						thsform.submit();
					}
				}
			} 
		}
		rtn = false;
	}

}



function form_handler(frm) {
	if (!frm) {
		return;
	}
	if (blockoff === true) {
		//alert("No");
		return;
	}
	fid = frm.id;
	if (fid == ''){
		alert('NO FORM ID!!!');
	}
	if (fid == 'test'){
		frm.setAttribute("name", "test");
		frm.setAttribute("method", "POST");
	} else if (fid == 'contact') {
		frm.setAttribute("name", "contact");
		frm.setAttribute("method", "POST");
		resetform = false;
	} else if (fid == 'join') {
		frm.setAttribute("name", "join");
		frm.setAttribute("method", "POST");
		resetform = false;
	} else if (fid == 'login') {
		frm.setAttribute("name", "login");
		frm.setAttribute("method", "POST");
		resetform = false;
	} else if (fid == 'editPhotoForm2') {
		frm.setAttribute("name", "editPhotoForm2");
		frm.setAttribute("method", "POST");
		resetform = false;
	} else if (fid == 'photos_refresh') {
		frm.setAttribute("name", "photos_refresh");
		frm.setAttribute("method", "POST");
		resetform = false;
	} else if (fid == 'myProfileEdit') {
		frm.setAttribute("name", "myProfileEdit");
		frm.setAttribute("method", "POST");
		resetform = false;
	} else if (fid == 'myaccount_changeUsername') {
		frm.setAttribute("name", "myaccount_changeUsername");
		frm.setAttribute("method", "POST");
		resetform = false;
	} else if (fid == 'myaccount_changePassword') {
		frm.setAttribute("name", "myaccount_changePassword");
		frm.setAttribute("method", "POST");
		resetform = false;
	} else if (fid == 'myaccount_changeEmail') {
		frm.setAttribute("name", "myaccount_changeEmail");
		frm.setAttribute("method", "POST");
		resetform = false;
	} else if (fid == 'myaccount_joinComm') {
		frm.setAttribute("name", "myaccount_joinComm");
		frm.setAttribute("method", "POST");
		resetform = false;
	} else if (fid == 'myaccount_suggestComm') {
		frm.setAttribute("name", "myaccount_suggestComm");
		frm.setAttribute("method", "POST");
		resetform = true;
	} else if (fid == 'myinbox_compose') {
		frm.setAttribute("name", "myinbox_compose");
		frm.setAttribute("method", "POST");
		resetform = true;
	} else if (fid == 'myinbox_membersSearch') {
		frm.setAttribute("name", "myinbox_membersSearch");
		frm.setAttribute("method", "POST");
		resetform = true;
	} else if (fid == 'widget_datingTips') {
		frm.setAttribute("name", "widget_datingTips");
		frm.setAttribute("method", "POST");
		resetform = true;
	} else if (fid == 'search_optForm') {
		frm.setAttribute("name", "search_optForm");
		frm.setAttribute("method", "POST");
		resetform = true;
	} else if (fid == 'ajax_send_smile') {
		frm.setAttribute("name", "ajax_send_smile");
		frm.setAttribute("method", "POST");
		resetform = true;
	} else if (fid == 'myinbox_compose_voicemail') {
		frm.setAttribute("name", "myinbox_compose_voicemail");
		frm.setAttribute("method", "POST");
		resetform = false;
	} else if (fid == 'myinbox_smiles_markread') {
		frm.setAttribute("name", "myinbox_smiles_markread");
		frm.setAttribute("method", "POST");
		resetform = false;
	} else if (fid == 'myinbox_compose_videomail') {
		frm.setAttribute("name", "myinbox_compose_videomail");
		frm.setAttribute("method", "POST");
		resetform = false;
	} else if (fid == 'widget_recordPoll') {
		frm.setAttribute("name", "widget_recordPoll");
		frm.setAttribute("method", "POST");
		resetform = false;
	} else if (fid == 'poll_suggest') {
		frm.setAttribute("name", "poll_suggest");
		frm.setAttribute("method", "POST");
		resetform = false;
	} else if (fid == 'events_sendToFriend') {
		frm.setAttribute("name", "events_sendToFriend");
		frm.setAttribute("method", "POST");
		resetform = false;
	} else if (fid == 'events_suggestEvent') {
		frm.setAttribute("name", "events_suggestEvent");
		frm.setAttribute("method", "POST");
		resetform = false;
	} else if (fid == 'events_addReminder') {
		frm.setAttribute("name", "events_addReminder");
		frm.setAttribute("method", "POST");
		resetform = false;
	} else if (fid == 'getchatreq') {
		frm.setAttribute("name", "getchatreq");
		frm.setAttribute("method", "POST");
		resetform = false;
	} else if (fid == 'chat_accept_decline_request') {
		frm.setAttribute("name", "chat_accept_decline_request");
		frm.setAttribute("method", "POST");
		resetform = false;
	} else if (fid == 'chat_request') {
		frm.setAttribute("name", "chat_request");
		frm.setAttribute("method", "POST");
		resetform = false;
	} else if (fid == 'profile_addRec') {
		frm.setAttribute("name", "profile_addRec");
		frm.setAttribute("method", "POST");
		resetform = false;
	} else if (fid == 'profile_approveReject_recc') {
		frm.setAttribute("name", "profile_approveReject_recc");
		frm.setAttribute("method", "POST");
		resetform = false;
	} else if (fid == 'myhome_suggform') {
		frm.setAttribute("name", "myhome_suggform");
		frm.setAttribute("method", "POST");
		resetform = false;
	} else if (fid == 'my_video_saveComments') {
		frm.setAttribute("name", "my_video_saveComments");
		frm.setAttribute("method", "POST");
		resetform = false;
	} else if (fid == 'my_video_view_comments') {
		frm.setAttribute("name", "my_video_view_comments");
		frm.setAttribute("method", "POST");
		resetform = false;
	} else if (fid == 'my_videoprofile_view_comments') {
		frm.setAttribute("name", "my_videoprofile_view_comments");
		frm.setAttribute("method", "POST");
		resetform = false;
	} else if (fid == 'my_audio_update') {
		frm.setAttribute("name", "my_audio_update");
		frm.setAttribute("method", "POST");
		resetform = false;
	} else if (fid == 'forgotpassword') {
		frm.setAttribute("name", "forgotpassword");
		frm.setAttribute("method", "POST");
		resetform = false;
	} else if (fid == 'my_home_toggleOnline') {
		frm.setAttribute("name", "my_home_toggleOnline");
		frm.setAttribute("method", "POST");
		resetform = false;
	}

	if (frm.name && frm.method ) {
		if (validate(frm)) {
			place1 = 'insert1';
			place2 = 'insert2';
			if (frm.place1) {
				place1 = frm.place1.value;
			} 
			if (frm.place2) {
				place2 = frm.place2.value;
			} 
			submitFormCustom(frm, place1, place2, true);
		} 
	} else {
		alert('UPDATE form_handler METHOD in misc_site.js');
	}
}


function updateFCK(inst) {
	var oEditor = FCKeditorAPI.GetInstance(inst);
	if (document.getElementById('storediv')){
		oEditor.InsertHtml(document.getElementById('storediv').innerHTML);
	} else {
		alert('div with id "storediv" must exist on page');
	}
}

function getFCK(inst, dest) {
	var oEditor = FCKeditorAPI.GetInstance(inst);
	htmval = oEditor.GetXHTML();
	
	if (document.getElementById(dest)) {
		document.getElementById(dest).value = htmval;
	}
	//alert(document.getElementById(dest).value);
	return true;
}

function selectAll(dparentid, selbx) {
	dparent = document.getElementById(dparentid);
	inptlst = dparent.getElementsByTagName('INPUT');
	if (inptlst.length > 0) {
		for (i=0; i < inptlst.length; i++) {
			if (inptlst[i].type=='checkbox'){
				if (selbx.checked == false) {
					inptlst[i].checked = false;
				} else {
					inptlst[i].checked = true;
				}
			}
		}
	}
}




function closeD() {
	document.getElementById('d').style.width='450px';
	document.getElementById('d').style.display = 'none';
	document.getElementById('d').innerHTML = '';
}

function getMouseXY(e) {
	try {
		if (IE) { // grab the x-y pos.s if browser is IE
			tempX = event.clientX + document.body.scrollLeft;
			tempY = event.clientY + document.body.scrollTop;
		} else {  // grab the x-y pos.s if browser is NS
			tempX = e.pageX;
			tempY = e.pageY;
		}  
		// catch possible negative values in NS4
		if (tempX < 0){tempX = 0;}
		if (tempY < 0){tempY = 0;}  
		// show the position values in the form named Show
		// in the text fields named MouseX and MouseY
		//if (open) {
			//if (tempX > wd || tempX < b || tempY < a || tempY > ht) {
				//open = false;
				//test2();
			//}
		//}
		//document.getElementById('MouseX').value = tempX
		//document.getElementById('MouseY').value = tempY
		return true
	}
	catch (e) {
	}
	
}



function getY( oElement ) {
	var iReturnValue = 0;
	while( oElement != null ) {
		iReturnValue += oElement.offsetTop;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}

function getX( oElement ) {
	var iReturnValue = 0;
	while( oElement != null ) {
		iReturnValue += oElement.offsetLeft;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}

var addelems = 1;
function addAttach() {
	abox = document.getElementById('attchbox');
	if (addelems <= 6) {
		addelems ++;
		var aelem = document.createElement('span');
		aelem.id = 'span'+addelems;
		aelem.innerHTML = '<input type="file" name="attach[]" id="attach'+addelems+'" class="style9" size="40">&nbsp;&nbsp;<span class="link" onclick="removeAttch('+addelems+')">[-]</a><br/>';
		abox.appendChild(aelem);
	}
}

function removeAttch(remid) {
	abox = document.getElementById('attchbox');
	if (remspan = document.getElementById('span'+remid)) {
		abox.removeChild(remspan);
		addelems --;
	}
	return;
}



// CUSTOM FORM SUBMITS 
// SPECIAL CASES -> WITHOUT BUTTONS OR IMAGE INPUT TYPES
/*********************************************************************************************************/

/**
 * sub_contact
 * desc: submit the contact us form
 * params: NA
 * used-by: contact.htm
 */
function sub_contact() {
	myfrm = document.getElementById('contact');
	form_handler(myfrm);
}

/**
 * sub_join
 * desc: submit the join datingonline form
 * params: NA
 * used-by: join.htm
 */
function sub_join() {
	myfrm = document.getElementById('join');
	form_handler(myfrm);
}

/**
 * sub_login
 * desc: submit the log into datingonline form
 * params: NA
 * used-by: login.htm
 */
function sub_login() {
	myfrm = document.getElementById('login');
	form_handler(myfrm);
}

/**
 * photos_refreshPhotos
 * desc: refresh the uploaded photos section
 * params: NA
 * used-by: my-Photos.htm
 */
function photos_refreshPhotos() {
	myfrm = document.getElementById('photos_refresh');
	form_handler(myfrm);
}

/**
 * profile_subEdit
 * desc: submit edit profile form
 * params: NA
 * used-by: my-ProfileEdit.htm
 */
function profile_subEdit() {
	myfrm = document.getElementById('myProfileEdit');
	form_handler(myfrm);
}

/**
 * myaccount_updateUsername
 * desc: submit chnage username form
 * params: NA
 * used-by: my-account.htm
 */
function myaccount_updateUsername() {
	myfrm = document.getElementById('myaccount_changeUsername');
	form_handler(myfrm);
}

/**
 * myaccount_joinCommunity
 * desc: submit join a community form
 * params: NA
 * used-by: my-account.htm
 */
function myaccount_joinCommunity() {
	myfrm = document.getElementById('myaccount_joinComm');
	form_handler(myfrm);
}

/**
 * myaccount_updatePassword
 * desc: submit chnage password form
 * params: NA
 * used-by: my-account.htm
 */
function myaccount_updatePassword() {
	myfrm = document.getElementById('myaccount_changePassword');
	form_handler(myfrm);
}

/**
 * myaccount_updateEmail
 * desc: submit chnage email form
 * params: NA
 * used-by: my-account.htm
 */
function myaccount_updateEmail() {
	myfrm = document.getElementById('myaccount_changeEmail');
	form_handler(myfrm);
}

/**
 * myaccount_suggestCommunity
 * desc: submit suggest a community form
 * params: NA
 * used-by: my-account.htm
 */
function myaccount_suggestCommunity() {
	myfrm = document.getElementById('myaccount_suggestComm');
	form_handler(myfrm);
}

/**
 * myinbox_composeMessage()
 * desc: submit compose a message and send
 * params: NA
 * used-by: my-inbox-Compose.htm
 */
function myinbox_composeMessage() {
	// get FCK contents for form submission
	document.getElementById('emailArea2').value = FCKeditorAPI.GetInstance('emailArea').GetXHTML();
	myfrm = document.getElementById('myinbox_compose');
	form_handler(myfrm);
}

/**
 * myinbox_composeVoicemail()
 * desc: submit compose a message and send
 * params: NA
 * used-by: my-inbox-Compose-Voicemail.htm
 */
function myinbox_composeVoicemail() {
	myfrm = document.getElementById('myinbox_compose_voicemail');
	form_handler(myfrm);
}


/**
 * myinbox_composeVideomail()
 * desc: submit compose a message and send
 * params: NA
 * used-by: my-inbox-Compose-Videomail.htm
 */
function myinbox_composeVideomail() {
	myfrm = document.getElementById('myinbox_compose_videomail');
	form_handler(myfrm);
}


/**
 * myinbox_searchMembers
 * desc: do a basic search for members for send message
 * params: NA
 * used-by: my-inbox-Compose.htm
 */
function myinbox_searchMembers(fldObj) {
	// get FCK contents for form submission
	document.getElementById('search_str').value = fldObj.value;
	document.getElementById('schBox').style.display = "block";
	myfrm = document.getElementById('myinbox_membersSearch');
	form_handler(myfrm);
}

/**
 * widget_datingTips_nextPrev
 * desc: get the next / previous dating tips (sidebar)
 * params: nextprev (int)
 * used-by: (multiple - widget class)
 */
function widget_datingTips_nextPrev(nextprev) {
	// get FCK contents for form submission
	document.getElementById('dtip_direction').value = nextprev;
	myfrm = document.getElementById('widget_datingTips');
	form_handler(myfrm);
}

/**
 * search_subForm
 * desc: submit the search form
 * params: frmRef (int)
 * used-by: search.htm
 */
function search_subForm(frmRef) {
	document.getElementById('sFrmRef').value = frmRef;
	document.getElementById('searchForm').submit();
}


/**
 * search_sendOption
 * desc: Send items from search results
 * params: userid (int) opt (int)
 * notes: NA
 * used-by: searchResults-List.htm
 */
function search_sendOption(userid, opt) {
	document.getElementById('sch_userid').value = userid;
	document.getElementById('sch_option').value = opt;
	myfrm = document.getElementById('search_optForm');
	form_handler(myfrm);
}

/**
 * ajax_sendSmile
 * desc: Send a smile
 * params: NA
 * notes: NA
 * used-by: search_smallOptions.pjx
 */
function ajax_sendSmile() {
	myfrm = document.getElementById('ajax_send_smile');
	form_handler(myfrm);
}

/**
 * myinbox_smiles_viewSmile
 * desc: View smiles
 * params: smileId (int)
 * notes: NA
 * used-by: my-inbox-Smiles.htm
 */
function myinbox_smiles_viewSmile(smileId) {
	document.getElementById("divSmile_1_" + smileId).style.display = "none";
	document.getElementById("divSmile_2_" + smileId).style.display = "block";
	document.getElementById("smileId").value = smileId;
	myfrm = document.getElementById('myinbox_smiles_markread');
	form_handler(myfrm);
}

/**
 * widget_submitPoll()
 * desc: Submit the poll
 * params: NA
 * notes: NA
 * used-by: (multiple - widget class)
 */
function widget_submitPoll() {
	var pollArr = document.getElementById('poll_answer').getElementsByTagName('input');
	var ahead = false;
	if (pollArr.length > 0) {
		for (i=0; i < pollArr.length; i++) {
			if (pollArr[i].checked == true) {
				ahead = true;
			}
		}
	} 
	
	if (ahead) {
		myfrm = document.getElementById('widget_recordPoll');
		form_handler(myfrm);
	} else {
		alert("Please select a poll option");
	}
	
}

/**
 * poll_suggestQuestion
 * desc: Submit suggest poll question form
 * params: NA
 * notes: NA
 * used-by: pollResults.htm
 */
function poll_suggestQuestion() {
	myfrm = document.getElementById('poll_suggest');
	form_handler(myfrm);
}

/**
 * sub_mailEvent
 * desc: Sumit a send to friend event request
 * params: NA
 * notes: NA
 * used-by: events_browse.htm
 */
function sub_mailEvent() {
	myfrm = document.getElementById('events_sendToFriend');
	form_handler(myfrm);
}

/**
 * events_suggestEventSubmit
 * desc: Submit a suggest event request
 * params: NA
 * notes: NA
 * used-by: events_suggest.htm
 */
function events_suggestEventSubmit() {
	myfrm = document.getElementById('events_suggestEvent');
	form_handler(myfrm);
}

/**
 * sub_saveEventReminder
 * desc: Submit a event reminder request
 * params: NA
 * notes: NA
 * used-by: events_browse.htm
 */
function sub_saveEventReminder() {
	myfrm = document.getElementById('events_addReminder');
	form_handler(myfrm);
}
/**
 * getChatRequest
 * desc: find out if there is any chat requests
 * params: NA
 * notes: NA
 * used-by: additional_html.inc
 */
function getChatRequest() {
	myfrm = document.getElementById('getchatreq');
	form_handler(myfrm);
	setTimeout("getChatRequest()", 5000);
}

/**
 * chat_acceptDecline
 * desc: Submit accept / decline chat request form
 * params: requestee (int), session (str), ref (enum 1 | 2)
 * notes: NA
 * used-by: my-ChatRequest.htm
 */
function chat_acceptDecline(requestee, session, ref) {
	document.getElementById('ch_requestee').value = requestee;
	document.getElementById('ch_session').value = session;
	document.getElementById('ch_ref').value = ref;
	myfrm = document.getElementById('chat_accept_decline_request');
	form_handler(myfrm);

}

/**
 * chat_requestChat
 * desc: submit request chat form
 * params: ch_targetid (int)
 * notes: NA
 * used-by: searchResultsList.htm
 */
function chat_requestChat(ch_targetid) {
	document.getElementById('targetid').value = ch_targetid;
	myfrm = document.getElementById('chat_request');
	form_handler(myfrm);
	
}

/**
 * profile_subRecForm
 * desc: Submit reccomendations form
 * params: NA
 * notes: NA 
 * used-by: profile.htm
 */
function profile_subRecForm() {
	myfrm = document.getElementById('profile_addRec');
	form_handler(myfrm);
}

/**
 * profile_subAppForm
 * desc: Submit the approve / reject reccomendation form
 * params: appRej (int), recVal (int)
 * notes: NA
 * used-by: profile.htm
 */
function profile_subAppForm(appReg, recVal) {
	document.getElementById('apprej').value = appReg;
	document.getElementById('reccid').value = recVal;
	myfrm = document.getElementById('profile_approveReject_recc');
	form_handler(myfrm);
}

/**
 * myhome_suggformSubmit
 * desc: Submit the main suggestions form
 * params: NA
 * notes: NA
 * used-by: my-home.htm
 */
function myhome_suggformSubmit() {
	myfrm = document.getElementById('myhome_suggform');
	form_handler(myfrm);
}

/**
 * my_video_saveComments_submit
 * desc: submit update video form
 * params: NA
 * notees: NA
 * used-by: my-Video.htm
 */
function my_video_saveComments_submit() {
	myfrm = document.getElementById("my_video_saveComments");
	form_handler(myfrm);
}

/**
 * my_video_view_comments_submit
 * desc: submit the add vm comments form
 * params: NA
 * notes: NA
 * used-by: my-Video-View.htm
 */
function my_video_view_comments_submit() {
	myfrm = document.getElementById("my_video_view_comments");
	form_handler(myfrm);
}

/**
 * my_videoprofile_view_comments_submit
 * desc: Sumit video comments form
 * params: NA
 * notes: NA
 * used-by: my-VideoProfile-View.htm
 */
function my_videoprofile_view_comments_submit() {
	myfrm = document.getElementById("my_videoprofile_view_comments");
	form_handler(myfrm);
}

/**
 * my_audio_update_submit
 * desc: Submit audio comment / delete form 
 * params: NA
 * notes: NA
 * used-by: my-Audio.htm
 */
function my_audio_update_submit() {
	myfrm = document.getElementById("my_audio_update");
	form_handler(myfrm);
}

/**
 * forgotpassword_submit
 * desc: Sumits forgot password form
 * params: NA
 * notes: NA
 * used-by: forgotpassword.htm
 */
function forgotpassword_submit() {
	myfrm = document.getElementById("forgotpassword");
	form_handler(myfrm);
}

/**
 * my_home_toggleOnline_submit
 * desc: toggle online status
 * params: NA
 * notes: NA
 * used-by: my-home.htm
 */
function my_home_toggleOnline_submit() {
	myfrm = document.getElementById("my_home_toggleOnline");
	form_handler(myfrm);
}

/********************************************************************************************************/



/**********************************
**
** VALIDATE STUFF
**
**
**********************************/
/**
 * validateForumTopic
 * desc: validate req fields on add forum topic page
 * params: vfrmid (form id)
 * used-by: my-forum-addtopic.htm 
 */
function validateForumTopic(vfrmid) {
	vfrm = document.getElementById(vfrmid);
	var fck_content = trim_str(FCKeditorAPI.GetInstance('addTopic').GetXHTML());
	var title = trim_str(document.getElementById('addTopic_title').value);
	if (title == "" || fck_content == "") {
		alert("Please enter a title and some topic text");
	} else {
		vfrm.submit();
	}
}


// 
// Random Things
//
function forum_goToForum(slval) {
	if (slval != "") {
		window.location="my-forum-topic?fid="+slval;
	}
}

//
// FCK stuff
//

function RTE(taname){
	// Automatically calculates the editor base path based on the _samples directory.
	// This is usefull only for these samples. A real application should use something like this:
	// oFCKeditor.BasePath = '/fckeditor/' ;        // '/fckeditor/' is the default value.
	var sBasePath = '/~FCK/';
	var oFCKeditor = new FCKeditor(taname) ;
	oFCKeditor.BasePath     = sBasePath ;
	oFCKeditor.Height       = 300 ;
	oFCKeditor.ToolbarSet   = 'Basic';
	oFCKeditor.Config['SkinPath'] = sBasePath + 'editor/skins/silver/';
	oFCKeditor.ReplaceTextarea() ;
}

//
// DOB STUFF
//

function getMonthDaySelect(isYear) {
	var mnth = document.getElementById('month').value;
	var sel_year = document.getElementById('year').value;
	if (sel_year == '') sel_year = 0;

	var selval = 1;
	if (document.getElementById('daysel')) {
		var sel_elems = document.getElementById('daysel').getElementsByTagName('option');
		if (sel_elems.length > 0) {
			for (i = 0; i < sel_elems.length; i++) {
				if (sel_elems[i].selected) {
					selval = sel_elems[i].value;
				}
			}
		}
	}

	document.getElementById('daybks').innerHTML = '';
	if (mnth == '') return;
	var lim = 31;
	// clear box 
	
	
	if (mnth == 6 || mnth == 8 || mnth == 11 || mnth == 13) {
		lim = 30;
	} else if (mnth == 4) {
		if (sel_year % 4 == 0 && sel_year > 0) {
			lim = 29;
		} else {
			lim = 28;
		}
	}
	var mySel = document.createElement('select');
	mySel.setAttribute("name", "nu_dob_day");
	mySel.setAttribute("id", "daysel");
	mySel.style.width = "40px";
	mySel.style.font = "11px arial";

	for (i=1; i <= lim; i++) {
		var fval = document.createElement('option');
		fval.setAttribute("value", i);
		if (i == selval) {
			fval.setAttribute("selected", "selected");
		}
		fval.appendChild(document.createTextNode(i));
		mySel.appendChild(fval);
	}
	
	document.getElementById('daybks').appendChild(mySel);
}

//
// Toggle stuff
//

/**
 * toggleAccountSettings
 * desc: Toggle the display of the account settings
 * params: showid (str)
 * notes: NA
 * used-by: my-account.htm
 */
function toggleAccountSettings(showid) {
	var tobj = document.getElementById('tr_'+showid);
	var taobj = document.getElementById('a_'+showid);
	if (tobj.style.display == "none") {
		tobj.style.display = "block";
		taobj.innerHTML = '[hide]';
	} else {
		tobj.style.display = "none";
		taobj.innerHTML = '[change]';
	}
}

/**
 * close_myinboxMsgBox
 * desc: Closes the search box on the my-inbox-Compose form
 * params: NA
 * notes: NA
 * used-by: myinbox_searchMembers.pjx
 */
function close_myinboxMsgBox() {
	document.getElementById('schBox').style.display = 'none';
	return;
}

/**
 * myinbox_recordToField
 * desc: Record the to users details to the form
 * params: mi_username (str), mi_id (int)
 * notes: NA
 * used-by: myinbox_searchMembers.pjx
 */
function myinbox_recordToField(mi_username, mi_id) {
	document.getElementById('msg_to').value = mi_username;
	document.getElementById('toId').value = mi_id;
	close_myinboxMsgBox();
}

/**
 * myinbox_selectMail
 * desc: Toggle mail chacked status
 * params: ml_selObj (obj)
 * notes: NA
 * used-by: my-inbox-Email.htm
 */
function myinbox_selectMail(ml_selObj) {
	ml_status = ml_selObj.value;
	targetObj = document.getElementById('mailTable').getElementsByTagName('input');

	if (targetObj.length > 0) {
		for (i = 0; i < targetObj.length; i++) {
			targetObj[i].checked = false;
			if (targetObj[i].type == "checkbox") {
				if (ml_status == 4) {
					targetObj[i].checked = true;
				} else if (ml_status == 2) {
					if (document.getElementById("readStatus_" + targetObj[i].value).value > 0) {
						targetObj[i].checked = true;
					}
				} else if (ml_status == 3) {
					if (document.getElementById("readStatus_" + targetObj[i].value).value < 1) {
						targetObj[i].checked = true;
					}
				} 
			} 
		}
	}
}

/**
 * myinbox_toggleMailStatus
 * desc: toggle mail read status
 * params: ml_status (int)
 * notes: NA
 * used-by: my-inbox-Emails.htm
 */
function myinbox_toggleMailStatus(ml_status) {
	targetObj = document.getElementById('mailTable').getElementsByTagName('input');
	var ml_cnt = 0;
	if (targetObj.length > 0) {
		for (i = 0; i < targetObj.length; i++) {
			if (targetObj[i].checked) ml_cnt ++;
		}
	}
	if (ml_cnt > 0) {
		
		conf = false;

		if (ml_status == "1") {
			conf = confirm("Are you sure you want to mark these " + ml_cnt + " messages as read?");
		} else if (ml_status == 2) {
			conf = confirm("Are you sure you want to mark these " + ml_cnt + " messages as unread?");
		} else if (ml_status == 3) {
			conf = confirm("Are you sure you want to delete these " + ml_cnt + " messages");
		}
		
		if (conf) {
			document.getElementById('mailStatus').value = ml_status;
			document.getElementById('mailStatusForm').submit();
		}
	} else {
		alert("You must select some email messages");
	}
}

/**
 * myinbox_toggleVoiceMailStatus
 * desc: toggle voicemail mail view / delete status
 * params: ml_status (int)
 * notes: NA
 * used-by: my-inbox-Voicemail.htm
 */
function myinbox_toggleVoiceMailStatus(ml_status) {
	targetObj = document.getElementById('mailTable').getElementsByTagName('input');
	var ml_cnt = 0;
	if (targetObj.length > 0) {
		for (i = 0; i < targetObj.length; i++) {
			if (targetObj[i].checked) ml_cnt ++;
		}
	}
	if (ml_cnt > 0) {
		
		conf = false;

		if (ml_status == "1") {
			conf = confirm("Are you sure you want to mark these " + ml_cnt + " voicemail messages as read?");
		} else if (ml_status == 2) {
			conf = confirm("Are you sure you want to mark these " + ml_cnt + " voicemail messages as unread?");
		} else if (ml_status == 3) {
			conf = confirm("Are you sure you want to delete these " + ml_cnt + " voicemail messages");
		}
		
		if (conf) {
			document.getElementById('mailStatus').value = ml_status;
			document.getElementById('mailStatusForm').submit();
		}
	} else {
		alert("You must select some voicemail messages");
	}
}

/**
 * myinbox_toggleSmileStatus
 * desc: toggle smiles mail view / delete status
 * params: ml_status (int)
 * notes: NA
 * used-by: my-inbox-Smiles.htm
 */
function myinbox_toggleSmileStatus(ml_status) {
	targetObj = document.getElementById('mailTable').getElementsByTagName('input');
	var ml_cnt = 0;
	if (targetObj.length > 0) {
		for (i = 0; i < targetObj.length; i++) {
			if (targetObj[i].checked) ml_cnt ++;
		}
	}
	if (ml_cnt > 0) {
		
		conf = false;

		if (ml_status == "1") {
			conf = confirm("Are you sure you want to mark these " + ml_cnt + " smiles as read?");
		} else if (ml_status == 2) {
			conf = confirm("Are you sure you want to mark these " + ml_cnt + " smiles as unread?");
		} else if (ml_status == 3) {
			conf = confirm("Are you sure you want to delete these " + ml_cnt + " smiles");
		}
		
		if (conf) {
			document.getElementById('mailStatus').value = ml_status;
			document.getElementById('mailStatusForm').submit();
		}
	} else {
		alert("You must select some smiles");
	}
}


/**
 * search_searchOrder
 * desc: Get the search ordering
 * params: sselObj (obj)
 * notes: NA
 * used-by: searchResults-List.htm; searchResultsGallery.htm
 */
function search_searchOrder(sselObj) {
	if (sselObj.value != "") {
		locn = window.location.toString().substring('?');
		window.location=locn + "?search_order=" + sselObj.value;
	}
}
