Useful AJAX Functions

Leave a comment Standard
/**************
* Purpose: initalize ajax
* Precondition: none
* Postcondition: ajax xmlhttp object running
**************/

//global variables
var xmlhttp = false; //initalize ajax
var queryString;

//check if we're using IE
try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
if (!xmlhttp && typeof XMLHttpRequest != "undefined")
    xmlhttp = new XMLHttpRequest();

    /**************
    * Purpose: make an ajax get request
    **************/
    function getrequest(page, objID)
    {

        //change cursor
        document.body.style.cursor = 'wait';

        //find object
        var obj = document.getElementById(objID);

        //remove tinyMCE editors
        //removeTiny();

        //get information
        xmlhttp.open("GET", page);
        xmlhttp.onreadystatechange = function() {

            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {

                //change the page
                obj.innerHTML = xmlhttp.responseText;

                //restore the tinyMCE editors
                //loadTiny();

                //change the cursor back
                document.body.style.cursor = 'default';
            }
        }

        //send information
        xmlhttp.send(null);
    }

    /**************
    * Purpose: make an ajax post request
    **************/
    function postrequest(page, objID)
    {

        //change cursor
        document.body.style.cursor = 'wait';

        //remove tinyMCE editors
        //removeTiny();

        //open the page
        xmlhttp.open("POST", page);

        //send the querystring headers
        //set the querystring variable before you call this...
        xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        xmlhttp.send(queryString);   

        xmlhttp.onreadystatechange = function() {

            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
            {

                //change the page
                obj.innerHTML = xmlhttp.responseText;

                //restore the tinyMCE editors
                //loadTiny();

                //put back the cursor
                document.body.style.cursor = 'default';
            }
        }

        if (queryString) //reset query string
            queryString = "";

    }

    /**************
    * Purpose: initialize the top-level variable; also reset the variable to cover when 
    *          the user clicks multiple times   
    **************/
    function setQueryString(num)
    {
        if (num == null)
            num = 0;

        queryString="";
        var frm, numberElements;
        frm = document.forms[num];
        numberElements = frm.elements.length;

        for(var i = 0; i < numberElements; i++) {
            if (i < numberElements-1) {
                queryString += frm.elements[i].name+"="+frm.elements[i].value+"&";
            } else {
                queryString += frm.elements[i].name+"="+frm.elements[i].value;
            }
        }

        //if youre using tinyMCE editors
        //for(id in tinyMCE.editors)
        //        if (id != "rshStorageField" && id != "toJSONString" && id != "mce_0")
        //            queryString += "&" + id + "=" + tinyMCE.get(id).getContent();
    }

    /**************
    * Purpose: load tiny MCE editors 
    * Requires tinyMCE from Moxiecode 
    **************/
    function loadTiny()
    {

        tinyMCE.init({
            // General options
            mode : "textareas",
            theme : "advanced",
            skin : "o2k7",
            skin_variant : "black",
            plugins : "save,safari,pagebreak,style,layer,table,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

            // Theme options
            theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,fontselect,fontsizeselect, |,forecolor,backcolor",
            theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,code,|,insertdate,inserttime,preview",
            theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
            theme_advanced_toolbar_location : "top",
            theme_advanced_toolbar_align : "left",
            theme_advanced_statusbar_location : "bottom",
            theme_advanced_resizing : true

            // Example content CSS (should be your site CSS)
            //content_css : "css/content.css",

            // Drop lists for link/image/media/template dialogs
            //template_external_list_url : "../javascript/tiny_mce/lists/template_list.js",
            //external_link_list_url : "../javascript/tiny_mce/lists/link_list.js",
            //external_image_list_url : "../javascript/tiny_mce/lists/image_list.js",
            //media_external_list_url : "../javascript/tiny_mce/lists/media_list.js"
        });

        return true;
    }

    /**************
    * Purpose: remove tiny MCE editors 
    * Requires tinyMCE from Moxiecode 
    **************/
    function removeTiny()
    {
         if (typeof tinyMCE != "undefined") 
         {
            for(id in tinyMCE.editors)
                if (id != "rshStorageField" && id != "toJSONString")
                tinyMCE.execCommand('mceRemoveControl', false, id);
        }
    }
Advertisements

BioShock: Graphic Violence in Video Games

Comments 5 Standard

Since when have playing games become all about how much blood sprays your screen when you bash someone over the head with a tire iron? Just this weekend I was over at my Cousin’s house and we were swapping video game favorites. His gift to me was Fable II (which I’m very interested in playing if it weren’t on XBOX) and BioShock. In fact, he put BioShock in and let me have at it.

Now I won’t disregard some of the really interesting concepts presented in this game. Everything from the underwater atmosphere, graphic detail and cool new powers that give you a pretty flexible play style. But I can honestly say I was a bit put off by the blood and guts violence. Do video games really need to be so graphically violent? You arrive at an underwater city and before you can even control your character’s actions you watch a maniac guy spill someone’s intestines. This is shortly followed by finding a nice heavy wrench and beating crazy people over the head until their brains are all over the floor.

Would this game be nearly as scary with the creepy upbeat music and crazy inhabitants? No, of course not. Would this game loose all playability if it weren’t nearly as bloody? My answer — no. There are perfectly good ways to make a scary video game, even a suspenseful video game without all the blood and guts. Take three examples:

Silent Hill. This is probably one of the scariest games I’ve ever played, and most of it was the atmosphere. Running around a deserted, foggy town with only the sound of your footsteps and distant cawing of crows. Sure, there was a disembodied corpse here or there and ugly monsters, but the blood is nearly non-existent during fight scenes.

Resident Evil. This game has a huge following. I think RE’s biggest selling point is that killing things isn’t the biggest aspect of game play. The monsters have enough arms and legs and tentacles to make you shiver but the blood and guts factor is pretty much non-existent. Most of the time you’re walking around deserted houses or streets, not looking at disemboweled corpses with knives sticking out of them like you do in BioShock.

Eternal Darkness. This game is a scary is a psychological way. Half the time you’re not sure if you’re really being killed or if the main character is having a hallucination. Eternal darkness plays with the psyche in a way I’ve never seen any other game do. It’ll give you goosebumps every time — without the blood.

Does the increasing violence in our video games mirror the changing attitude of the public? Of course all game companies are out to “give the consumer what they want.” Does that mean we’re all secretly aching to run around taking a chain-saw to people? I’m certainly not the only one who feels this way.

Legendary Nintendo designer Shigeru Miyamoto expressed his dissatisfaction with the industry’s growing predisposition toward violent software. Emphasizing the social responsibilities of game developers, Miyamoto told British television station Channel 4 (via Develop), “I don’t want to curb freedom of expression, but I am concerned many developers focus on excessive violence in order to stimulate people’s minds,” adding, “I believe that there are more ways of grabbing players’ attention than violence alone.” (source: http://www.1up.com/do/newsStory?cId=3170809)

Now I’m not saying there shouldn’t be violence in video games. Violence is a part of life we live with day to day, year after year. In fact according to the ESA, BioShock was the #19 best selling video game of 2007 in sales per units. #1 and #2 positions are dominated by World of Warcraft and it’s expansion pack, followed by Call of Duty4 in fourth place, and Command and Conquer in seventh. In all, twelve of the top twenty best selling games in 2007 had some kind of simulated violence. These games are selling well right now. But aren’t our video games supposed to be for entertainment? Isn’t that why we really play, to have fun? Does that mean every time we hear about a murder on TV we should jump up and think, +10 head shot I wonder how much blood got on the wall? Games are becoming more and more of an art form and in that case I would compare BioShock to skinning the family dog and hanging the corpse on the wall–crude, but well loved.

If we’re going to incorporate violence into video games I think we need to set some basic ground rules. The hyper realism really isn’t doing games any justice as far as violence goes. I’d rather see more realistic characters, shadows, shaders, and clothing then blood pools that ripple when I walk on by. Maybe that’s just me….