function setAction(form, action){
    document.getElementById(form).action.value = action;
}

/*Clear field on click*/
function clickclear(field, defval) {
    if (field.value == defval){
        field.value = ''
        field.style.fontStyle="normal"
        field.style.color="#333333"
    }
}

/*Set default value when field is empty*/
function restoredefault(field, defval){
    if(field.value==''){
        field.value=defval;
        field.style.fontStyle="italic"
        field.style.color="#888888"
    }
}

/*Count the number of character and display it in box*/
function charcount(field, maxlimit) {
    var cnt = field.value.length;
    if (cnt > maxlimit) // if too long trim text
        field.value = field.value.substring(0, maxlimit);
    else{
        document.getElementById("count").value = "Count: "+cnt+" out of 140 characters used";
    }
}

function checkmemory(){
    document.getElementById("memory").checked = !document.getElementById("memory").checked;

    if (document.getElementById("memory").checked==true){
        document.getElementById("memoryDiv").style.background = "url('../images/memory.gif') no-repeat 0 -25px";
    }else{
        document.getElementById("memoryDiv").style.background = "url('../images/memory.gif') no-repeat 0 -2px";
        removeCookie();

    }
}

function hoverOnMemory(){
    document.getElementById("memoryDiv").style.background = "url('../images/memory.gif') no-repeat 0 -49px";
}

function hoverOffMemory(){
    if (document.getElementById("memory").checked==true){
        document.getElementById("memoryDiv").style.background = "url('../images/memory.gif') no-repeat 0 -25px";
    }else{
        document.getElementById("memoryDiv").style.background = "url('../images/memory.gif') no-repeat 0 -2px";
    }
}

function tempDisabled(elementId,delay){
    document.getElementById(elementId).disabled=true;
    setTimeout("document.getElementById('"+elementId+"').disabled=false",delay);
}

function checkFacebookConnection(){
    window.fbAsyncInit = function() {
        FB.init({
            appId: '179787062065851',
            status: true,
            cookie: true,
            xfbml: true
        });
        FB.Event.subscribe('auth.sessionChange', function(response) {
            location.reload(true)
        });
    };
    (function() {
        var e = document.createElement('script');
        e.async = true;
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
        document.getElementById('fb-root').appendChild(e);
    }());
}
