/*
COPYRIGHT ONLINE SINGLES, LLC.
*/

/* GLOBAL VARS */
var ajaxPage = 'ajax.aspx';
var ajaxMsgDiv = 'divAjaxMsg';

function _ajaxProcessMessage() {		
    var myajax = ajaxpack.ajaxobj;
    var myfiletype = ajaxpack.filetype;				
    if (myajax.readyState == 4) { //if request of file completed
	   if (myajax.status==200 || window.location.href.indexOf("http")==-1) { //if request was successful or running script locally
		  if (myfiletype=="txt") {
			 var strResponse = myajax.responseText;
		  } else {
			 var strResponse = myajax.responseXML;
		  }
		   _ajaxDisplayResponse(ajaxMsgDiv,strResponse);		  	  
	   }
    }
}

function _ajaxProcessKudos() {		
    var myajax = ajaxpack.ajaxobj;
    var myfiletype = ajaxpack.filetype;				
    if (myajax.readyState == 4) { //if request of file completed
	   if (myajax.status==200 || window.location.href.indexOf("http")==-1) { //if request was successful or running script locally
		  if (myfiletype=='txt') {
			 var strResponse = myajax.responseText;
		  } else {
			 var strResponse = myajax.responseXML;
		  }
		   _updateKudos(strResponse);		  	  
	   }
    }
}

function _updateKudos(strXML) {
    if (window.ActiveXObject) {
	   var doc = new ActiveXObject("Microsoft.XMLDOM");
		  doc.async = 'false';
		  doc.loadXML(strXML);
    } else {
	   var parser = new DOMParser();
	   var doc = parser.parseFromString(strXML, "text/xml");
    }    
    var root = doc.documentElement;       
    var kLeft = root.childNodes[0].childNodes[0].nodeValue;
    var kCount = root.childNodes[1].childNodes[0].nodeValue;
    var kMsg = root.childNodes[2].childNodes[0].nodeValue;    
    _ajaxDisplayResponse('kudosLeft',kLeft);
    _ajaxDisplayResponse('kudoCount',kCount);    
    alert(kMsg);    
}

function _ajaxDisplayResponse(divName, divContent) {
	var div = document.getElementById(divName);		
	if (div.className == 'hidden') {
		div.className = 'visible';
		div.innerHTML = divContent;
	} else {
		div.innerHTML = divContent;
	}			
}

function _ajaxTagAdd(intTagID, bSubDir) {
    if (bSubDir==null | bSubDir==0) {
	   var postPage = ajaxPage;
    } else {
	   var postPage = '../' + ajaxPage;
    }
    ajaxpack.getAjaxRequest(postPage, 'function=tagAdd&tagID='+intTagID, _ajaxProcessMessage, 'txt');
}
function _ajaxRefreshSession() {
	ajaxpack.getAjaxRequest(ajaxPage, 'function=refreshSession', _ajaxProcessMessage, 'txt');
}
function _ajaxWink(intUserID) {
	ajaxpack.getAjaxRequest(ajaxPage, 'function=wink&userID='+intUserID, _ajaxProcessMessage, 'txt');
}

function _ajaxFavoriteAdd(intUserID) {
	ajaxpack.getAjaxRequest(ajaxPage, 'function=favoriteAdd&userID='+intUserID, _ajaxProcessMessage, 'txt');
}

function _ajaxFriendAdd(intUserID) {
	ajaxpack.getAjaxRequest(ajaxPage, 'function=friendAdd&userID='+intUserID, _ajaxProcessMessage, 'txt');
}

function _ajaxPostAction(intPostID,strFunction) {
	ajaxpack.getAjaxRequest(ajaxPage, 'function='+strFunction+'&postID='+intPostID, _ajaxProcessMessage, 'txt');
}

function _ajaxBlogCommentApprove(intPostID) {
	ajaxpack.getAjaxRequest(ajaxPage, 'function=blogcommentapprove&postID='+intPostID, _ajaxProcessMessage, 'txt');
}

function _ajaxBlogCommentDeny(intPostID) {
	ajaxpack.getAjaxRequest(ajaxPage, 'function=blogcommentdeny&postID='+intPostID, _ajaxProcessMessage, 'txt');
}

function _ajaxPhotoCommentApprove(intPostID) {
	ajaxpack.getAjaxRequest(ajaxPage, 'function=photocommentapprove&postID='+intPostID, _ajaxProcessMessage, 'txt');
}

function _ajaxPhotoCommentDeny(intPostID) {
	ajaxpack.getAjaxRequest(ajaxPage, 'function=photocommentdeny&postID='+intPostID, _ajaxProcessMessage, 'txt');
}
function _ajaxKudos(strType, intID, intVote, bSubDir) {
    if (bSubDir==null | bSubDir==0) {
	   var postPage = ajaxPage;
    } else {
	   var postPage = '../' + ajaxPage;
    }
    ajaxpack.getAjaxRequest(postPage, 'function=kudos&type='+strType+'&id='+intID+'&vote='+intVote, _ajaxProcessKudos, 'txt');
}

function _ajaxMailSpam( msgID, abuserID, bGo) {
	if (bGo==null | bGo==0) {
		if (confirm("Are you sure you want to report this message as spam?")) {
			_ajaxMailSpam(msgID,abuserID,1);
		}
	} else {
		ajaxpack.getAjaxRequest(ajaxPage, 'function=mailspam&msgID='+msgID+ '&abuserID=' +abuserID, _ajaxProcessMessage, 'txt');
	}
}

function _ajaxBlogSpam( blogID, abuserID) {
		if (confirm("Are you sure you want to report this blog as spam or inappropriate?")) {
			ajaxpack.getAjaxRequest('../'+ajaxPage, 'function=blogspam&blogID='+blogID+'&abuserID='+abuserID, _ajaxProcessMessage, 'txt');
		}
}

function _ajaxVideoSpam( videoID, abuserID) {
		if (confirm("Are you sure you want to report this video as spam or inappropriate?")) {
			ajaxpack.getAjaxRequest('../'+ajaxPage, 'function=videospam&videoID='+videoID+'&abuserID='+abuserID, _ajaxProcessMessage, 'txt');
		}
}

function _ajaxPenaltyBox(intUserID, intHours, intStaffUserID) {
			if (confirm("Are you sure you want to put this user in the penalty box?")) {
				ajaxpack.getAjaxRequest( ajaxPage, 'function=penaltybox&userID='+intUserID+'&hours='+intHours+'&staffUserID='+intStaffUserID, _ajaxProcessMessage, 'txt');
			}
}

function _ajaxDeleteBlog( blogID, bSubDir ) {
		if (bSubDir==null | bSubDir==0) {
			var postPage = ajaxPage;
		} else {
			var postPage = '../' + ajaxPage;
		}
		if (confirm("Are you sure you want to delete this blog?")) {
		ajaxpack.getAjaxRequest(postPage, 'function=blogdelete&blogID='+blogID, _ajaxProcessMessage, 'txt');
		}
}

function _ajaxDeleteVideo( videoID, bSubDir ) {
		if (bSubDir==null | bSubDir==0) {
			var postPage = ajaxPage;
		} else {
			var PostPage = '../' + ajaxPage;
		}
		if (confirm("Are you sure you want to delete this video?")) {
			ajaxpack.getAjaxRequest(postPage, 'function=videodelete&videoID='+videoID, _ajaxProcessMessage, 'txt');
		}
}
