//==========================\\
// Created for Randosity \\
// By Negown Productions \\
//================================\\
//// ============== AJAX baby! ================ \\\\\\\
// We're going to test for ajax to make sure the user can support it
var AJAX_TYPE;
try{
// Test for FireFox, Opera, and Safari
AJAX_TYPE = new XMLHttpRequest();
}catch(e){
try{
// Test for Internet Explorer
AJAX_TYPE = new ActiveXObject("Msxm12.XMLHTTP");
}catch(e){
try{
// Another test for IE
AJAX_TYPE = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
// Awe crap! No support for Ajax!!!!
AJAX_TYPE = null;
}
}
}
// Uploads
function getUploader(url){
var TIME_UP = 20; // Seconds until ajax script times out
var ALLGOOD = 'AllGood';
var ERROR = 'Error';
url = '/randosity' + url;
// Ajax function to send acutal data to the server
this.Upload = function(params, success_response, error_response){
if((url == '') || (typeof params != 'object') || (typeof success_response != 'function')){
return false;
}
if(typeof error_response != 'function'){
error_response = null;
}
if(!AJAX_TYPE){
alert("Uh-Oh! It looks like your browser is to old to use the features on this site.\n\nPlease upgrade your browser at:\nhttp://getfirefox.com");
return false;
}
var running_time = setTimeout(function(){
// Remove handler
AJAX_TYPE.onreadystatechange = function() {};
alert("Unable to conntact the server. Please wait a few moments and then try again.");
if(error_response){
error_response();
}
}, TIME_UP * 1000);
AJAX_TYPE.onreadystatechange = function() {
if(AJAX_TYPE.readyState == 4){
if(AJAX_TYPE.status == 200){
clearTimeout(running_time);
var testGrab = new AjaxResponse(AJAX_TYPE);
if(VerifyAjax(testGrab, error_response)){
success_response(testGrab);
}
}
}
}
var query;
var pkey;
if(params){
for(pkey in params){
if(typeof params[pkey] != 'function'){
query += "&" + EncodeURL(pkey) + "=" + EncodeURL(params[pkey]);
}
}
query = query.substring(1);
}
AjaxSend("POST", url, query);
return true;
}
function VerifyAjax(response, error_response){
var state = response.FieldGrab('state');
if(state == null){
alert("Server Error. Please wait a few moments and then try again.");
if(error_response){
error_response();
}
return false;
}
if(state == ERROR){
alert("Error: " + response.FieldGrab('error'));
if(error_response){
error_response();
}
return false;
}
return true;
}
function AjaxResponse(AJAX_TYPE){
var complete;
this.FieldGrab = function(field_name){
var arr_field = this.NodesGrab(field_name);
if((arr_field != null) && (arr_field.length == 1) && (arr_field[0].firstChild != null) && (arr_field[0].firstChild.data != null) && (arr_field[0].firstChild.data != "")){
field = arr_field[0].firstChild.data;
}
return field;
}
this.NodesGrab = function(node_name){
var nodes = new Array();
nodes = AJAX_TYPE.responseXML.documentElement.getElementsByTagName(node_name);
return nodes;
}
function ajaxIsCert(){
if(complete == null){
complete = (AJAX_TYPE) && (AJAX_TYPE.responseXML) && (AJAX_TYPE.responseXML.documentElement);
}
return complete;
}
}
}
function AjaxSend(post_type, url, query){
AJAX_TYPE.open(post_type, url, true);
AJAX_TYPE.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
AJAX_TYPE.overrideMimeType("text/xml");
AJAX_TYPE.send(query);
}
function EncodeURL(url){
url = escape(url);
url = url.replace("/\+/g", "%2B");
return url;
}
function ElemGrab(element){
return document.getElementById(element);
}
//// ~~~~~~~~~~~~~~~ END AJAX ~~~~~~~~~~~~~~ \\\\
//// ================ BUTTONS! ============== \\\\
function Button(id, class, dead_name){
var beg_html;
var beg_class;
this.Create = function(){
var element = GrabButton();
element.innerHTML = beg_html;
element.className = beg_class;
if(ElemGrab('loading')){
ElemGrab('loading').innerHTML = '';
}
}
this.Kill = function(deadtxt){
var element = GrabButton();
if(beg_html == null){
beg_html = element.innerHTML;
}
if(beg_class == null){
beg_class = element.className;
}
if(typeof deadtxt == 'undefined'){
// Oh crap, no name.... I hope no one cares what this is...
var newChild = element.firstChild;
while((newChild.firstChild != '') && (newChild.firstChild.nodeType == 1)){
newChild = newChild.firstChild;
}
deadtxt = newChild.firstChild.data;
}
if(typeof class == 'string'){
deadtxt = '' + deadtxt + '';
}
if(typeof dead_name != 'string'){
element.className = 'button';
}else{
element.className = dead_name;
}
element.innerHTML = '' + deadtxt + '';
if(ElemGrab('loading')){
ElemGrab('loading').innerHTML = '
';
}
}
function GrabButton(){
element = ElemGrab(id);
return element;
}
}
//// ~~~~~~~~~~~~~~ END BUTTONS ~~~~~~~~~~~~~~~ \\\\
//// ============== HELP! Something Happened! ============= \\\\
var helpMeOut = new helpMeOut();
function helpMeOut(){
this.Randary = function(){
var Helper = new Help_popup();
return(Helper);
}
function Help_popup(){
this.PartOfSpeech = function(){
alert("The Part of Speech for a word is the way a word is used in a sentence.");
}
this.Sentence = function(){
alert("The Use of the word in a sentence is your chance to show us how you use the word. Compose an original sentence using the word in it's correct form.");
ElemGrab('sentence').focus();
}
this.WordGrade = function(){
alert("The Word's Grade is the quality or score of the word. The word was voted on by users, and this is their consensus.");
}
}
}
//// ~~~~~~~~~~~~~~ END HELP it's all good now ~~~~~~~~~~~~~ \\\\
//// =============== Random EVERYDAY Functions =================== \\\\
/* Example:
new Effect.Fade(element, {afterFinish: Function});
function Function(){
new Effect.SlideUp(element);
}
Uses:
Appear | BlindDown | Slidedown | Grow
Fade | BlindUp | SlideUp | Shrink | SwitchOff | DropOut | Puff
Shake | Squish | Highlight
Effect.Toggle(element, [appear | blind | slide], [options]);
*/
var RandaryList = new function(){
var list_button = new Button('listbutton');
this.Submit = function(){
var list_type = ElemGrab('list_type').value;
var order_type = ElemGrab('order_type').value;
window.location.href = '/randosity/randary/list/' + list_type + '/' + order_type;
}
}
var Search = new function(){
var search_button = new Button('searchbutton');
this.Send = function(){
var term = ElemGrab('term');
var url = ElemGrab('url');
if(term.value == ''){
alert("You must enter a search term in order to search!");
term.focus();
return false;
}
if(term.value.length < 3){
alert("Your search term must be at least 3 characters in length.");
term.focus();
return false;
}
window.location.href = '' + url.value + term.value;
}
}
var Vote = new function(){
var DURATION = .4;
var params;
var set_vote = 0;
this.CheckAll = function(vote){
if((vote != 0) && (vote != 20) && (vote != 40) && (vote != 60) && (vote != 80) && (vote != 100)){
alert("Required Parameter Invalid.");
return false;
}
if(set_vote == 1){
alert("Your vote is being processed. Please wait.");
return false;
}
return true;
}
this.Cast = function(vote){
var POST_PAGE = ElemGrab('go').value;
ElemGrab('vote_field').value = vote;
if(!(this.CheckAll(vote))){
return;
}
set_vote = 1;
params = new Array();
SetParams();
// Do our nice fading :p
new Effect.Fade('vote', {duration: DURATION});
var AjaxSend = new getUploader(POST_PAGE);
AjaxSend.Upload(params, SuccessResponse, ErrorResponse);
}
function ErrorResponse(){
new Effect.Appear('vote', {duration: DURATION});
}
function SuccessResponse(response){
var new_score = response.FieldGrab('new_score');
var vote_msg = response.FieldGrab('vote_msg');
var score_movement = response.FieldGrab('score_movement');
var new_grade_symbol = response.FieldGrab('new_grade_symbol');
var vote_field = ElemGrab('vote_field').value;
var new_grade;
if(score_movement < 0){
score_movement = '- ' + Math.abs(score_movement);
}else if(score_movement > 0){
score_movement = '+ ' + score_movement;
}else{
score_movement = '+ ' + score_movement;
}
if(new_score <= 100 && new_score > 89){
new_grade = 'a';
}else if(new_score < 90 && new_score > 79){
new_grade = 'b';
}else if(new_score < 80 && new_score > 69){
new_grade = 'c';
}else if(new_score < 70 && new_score > 59){
new_grade = 'd';
}else if(new_score < 60){
new_grade = 'f';
}
new Effect.Fade('prev_grade', {duration: DURATION});
new Effect.Fade('grade', {duration: DURATION, afterFinish: GradeAppear});
new Effect.Fade('vote_msg', {duration: DURATION, afterFinish: VoteMSGAppear});
function GradeAppear(){
ElemGrab('prev_grade').innerHTML = new_score + '% ' + new_grade_symbol;
ElemGrab('prev_grade').className = 'grade_' + new_grade;
ElemGrab('grade').innerHTML = '( ' + score_movement + '% )';
ElemGrab('grade').className = 'grade_' + new_grade;
new Effect.Appear('grade', {duration: DURATION});
new Effect.Appear('prev_grade', {duration: DURATION});
}
function VoteMSGAppear() {
vote_msg.replace('>', '>');
vote_msg.replace('<', '<');
ElemGrab('vote_msg').innerHTML = vote_msg;
new Effect.Appear('vote_msg', {duration: DURATION});
}
}
function SetParams(vote){
params["rvote"] = ElemGrab('vote_field').value;
params["user_id"] = ElemGrab('user_id').value;
params["id"] = ElemGrab('id').value;
}
}
// Forums
function SelectEmCon(id) {
var old = ElemGrab("emcon").value;
ElemGrab("emcon").value = id;
if(id != old){
ElemGrab(id).style.width = "23px";
ElemGrab(id).style.height = "23px";
ElemGrab(id).style.border = "1px solid #000";
ElemGrab(old).style.width = "25px";
ElemGrab(old).style.height = "25px";
ElemGrab(old).style.border = "0";
}
}
var HtmlHelp = new function(){
this.Bold = function(){
var text = prompt('Please enter the text you\'d like to be bolded:', '');
if(text != '' && text != null){
ElemGrab("message").value += '' + text + '';
}
ElemGrab("message").focus();
}
this.Italic = function(){
var text = prompt('Please enter the text you\'d like to be italicized:', '');
if(text != '' && text != null){
ElemGrab("message").value += '' + text + '';
}
ElemGrab("message").focus();
}
this.Underline = function(){
var text = prompt('Please enter the text you\'d like to be underlined:', '');
if(text != '' && text != null){
ElemGrab("message").value += '' + text + '';
}
ElemGrab("message").focus();
}
this.Code = function(){
var code = prompt('Please enter the text you\'d like to be inserted into code format:', '');
if(code != '' && code != null){
ElemGrab("message").value += '' + code + '';
}
ElemGrab("message").focus();
}
this.Link = function(){
var url = prompt('Please enter the URL you wish to link to:', '');
var check = /^(((https?|ftp):\/\/)|aim:goim|skype|\/)/i; // This part was taken from http://newgrounds.com
if(!check.exec(url)){
new_url = 'http://' + url;
}else{
new_url = url;
}
if(url != '' && url != null){
var name = prompt('Please enter the URL Text/Label you wish the link to say (Or leave blank):', '');
if(name != '' && name != null){
ElemGrab("message").value += '' + name + '';
}else{
ElemGrab("message").value += '' + url + '';
}
}
ElemGrab("message").focus();
}
this.Email = function(){
var email = prompt('Please enter the email address you wish to link to:', '');
check = /[^a-z0-9\.\-_]/ig;
split_check = email.split('@');
tlx = split_check[1].split('.');
if(split_check.length < 2){
alert("Invalid Email Address");
return;
}
if(check.exec(split_check[0]) || check.exec(split_check[1])){
alert("Invalid Email Address");
return;
}
if(tlx.length < 2){
alert("Invalid Email Address");
return;
}
if(email != '' && email != null){
var name = prompt('Please enter the Email Text/Label you wish the link to say (Or leave blank):', '');
if(name != '' && name != null){
ElemGrab("message").value += '' + name + '';
}else{
ElemGrab("message").value += '' + email + '';
}
}
ElemGrab("message").focus();
}
}