function replaceContentWithFade(responseNode, innerCode) {
    var anim = dojo.fadeOut({ node:responseNode });
    dojo.connect(anim,"onEnd",function(){
        dojo.byId(responseNode).innerHTML = innerCode;
        dojo.fadeIn({ node:responseNode }).play();
    });
    anim.play();    
}

function fadeNodeOut(nodeName) {
    var anim = dojo.fadeOut({ node:nodeName });
    dojo.connect(anim,"onEnd",function(){
    	dojo.byId(nodeName).style.display = 'none';
    });
    anim.play();
}

function fadeNodeIn(nodeName) {
	dojo.byId(nodeName).style.display = 'block';
    var anim = dojo.fadeIn({ node:nodeName });
    anim.play();
}

function wipeNodeIn(nodeName) {
	if (dojo.byId(nodeName).style.display == 'none') {
	    var wipeArgs = {
	        node: nodeName,
	        duration: 500
	    };
	    dojo.fx.wipeIn(wipeArgs).play();
	}
}
function wipeNodeOut(nodeName) {
    var wipeArgs = {
        node: nodeName,
        duration: 500
    };
    dojo.fx.wipeOut(wipeArgs).play();
}


function getLoadingTxt() {
    var loadingTxt = '';
    loadingTxt += '<div style="padding:28px;">'+"\n";
    loadingTxt += '  <table width="100%">'+"\n";
    loadingTxt += '    <tr>'+"\n";
    loadingTxt += '      <td align="center"><img src="/images/loading-list.gif"><br />...loading...</td>'+"\n";
    loadingTxt += '    </tr>'+"\n";
    loadingTxt += '  </table>'+"\n";
    loadingTxt += '</div>'+"\n";
    return loadingTxt;
}

function loadJsonList(formname, url, pg, responsediv) {
    dojo.byId(responsediv).innerHTML = getLoadingTxt();
    dojo.byId(formname).pg.value = pg;
    submitAjaxForm(formname, url);
}

function submitAjaxForm(formname, submitto, buttonid) {
    
    var changeButton = false;

    if (typeof buttonid != 'undefined') {
        changeButton = true;
        origButtonVal = dijit.byId(buttonid).attr('label');
        // dijit.byId(buttonid).setLabel('Processing...');
        dijit.byId(buttonid).setAttribute('disabled', true);
    }

    // submit the form in the background
    dojo.xhrPost({
        url: submitto,
        form: formname,
        handleAs: 'json',
        handle: function(data, args) {
            
            if(typeof data == "error") {
                console.warn("error!",args);
            } else {
                // show our response
                var status = data.status;
                
                // ---------------------------
                // alert(status);
                // ---------------------------

                switch(status) {    
                    case 'OK_UPDATE':
                        if (typeof data.encoding == 'undefined') {
                            responseNode = data.responsediv;
                            dojo.byId(responseNode).innerHTML = data.responsemsg;
                        } else {
                            if (data.encoding == 'base64') {
                                responseNode = data.responsediv;
                                dojo.byId(responseNode).innerHTML = Base64.decode(data.responsemsg);
                            }
                        }
                        break;

                    case 'OK_UPDATE_TRIGGER_SUBMIT':
                        if (typeof data.encoding == 'undefined') {
                            responseNode = data.responsediv;
                            dojo.byId(responseNode).innerHTML = data.responsemsg;
                        } else {
                            if (data.encoding == 'base64') {
                                responseNode = data.responsediv;
                                dojo.byId(responseNode).innerHTML = Base64.decode(data.responsemsg);
                            }
                        }
                        submitAjaxForm(data.formname, data.formposturl);
                        break;

                    case 'OK_UPDATE_TRIGGER_DIALOG':
                        if (typeof data.encoding == 'undefined') {
                            responseNode = data.responsediv;
                            dojo.byId(responseNode).innerHTML = data.responsemsg;
                        } else {
                            if (data.encoding == 'base64') {
                                responseNode = data.responsediv;
                                dojo.byId(responseNode).innerHTML = Base64.decode(data.responsemsg);
                            }
                        }
                        dijit.byId(data.dialogname).show();
                        break;
                        
                    case 'OK_UPDATE_EDITOR':
                        editorId = data.editorname;
                        dijit.byId(editorId).setValue(Base64.decode(data.editorcontent));
                        break;
                        
                    case 'OK_SHOW_DIALOG':
                        dijit.byId(data.dialogname).show();
                        break;

                    case 'OK_CLOSE_DIALOG':
                        dijit.byId(data.dialogname).hide();
                        for (var i in data.updatefield) {
                            dojo.byId(i).innerHTML = data.updatefield[i];
                        }
                        break;

                    case 'OK_CLOSE_POPWIN':
                        window.close();                           
                        break;
                            
                    case 'OK_REFRESH':
                        window.location.reload();
                        break;

                    case 'OK_FWD':
                        jumpToDestination(data.destination);
                        break;

                    case 'OK_TRIGGER_SUBMIT':
                        submitAjaxForm(data.formname, data.formposturl);
                        break;

                    case 'GENERAL_MESSAGE_DIALOG':
                        dispMsg = data.displaymessage;
                        if (dijit.byId('dialog_general_message') == 'undefined') {
                            alert(dispMsg);
                        } else {
                            dojo.byId('dialog_general_message_content').innerHTML = dispMsg;
                            openNamedDialog('dialog_general_message');
                        }                                    
                        break;
                        
                    case 'ERROR_AUTH':
                        jumpToDestination(data.destination);
                        break;
                        
                    case 'ERROR_FIELDS':
                        errorMsgArr = data.errormsgs;
                        dojo.byId('dialog_general_message_box').innerHTML = data.errorheader;
                        for (keyval in errorMsgArr) {                                    
                            dojo.byId('dialog_general_message_box').innerHTML += '<li>'+errorMsgArr[keyval]+'<br />'+"\n";
                        }
                        dojo.byId('dialog_general_message_box').innerHTML += data.errorfooter;
                        openNamedDialog('dialog_general_message');
                        break;

                    case 'ERROR_FIELDS_REGISTER':
                        errorMsgArr = data.errormsgs;
                        dojo.byId('dialog_general_message_box').innerHTML = data.errorheader;
                        for (keyval in errorMsgArr) {                                    
                            dojo.byId('dialog_general_message_box').innerHTML += '<li>'+errorMsgArr[keyval]+'<br />'+"\n";
                        }
                        openNamedDialog('dialog_general_message');
                        Recaptcha.reload();
                        break;

                    case 'OK_UPDATE_SPOTLIST_SPOTMAP':
                        if (typeof data.encoding == 'undefined') {
                            responseNode = data.responsediv;
                            dojo.byId(responseNode).innerHTML = data.responsemsg;
                        } else {
                            if (data.encoding == 'base64') {
                                responseNode = data.responsediv;
                                dojo.byId(responseNode).innerHTML = Base64.decode(data.responsemsg);
                            }
                        }
                        gMap.clearOverlays();
                        
                        var homeIcon = new GIcon();
                        homeIcon.image = '/images/mm_homes.png';
                        homeIcon.shadow = '/images/icn-spot-shadow.png';
                        homeIcon.iconSize = new GSize(20, 34);
                        homeIcon.shadowSize = new GSize(22, 20);
                        homeIcon.iconAnchor = new GPoint(10, 32);
                        homeIcon.infoWindowAnchor = new GPoint(10, 32);

                        // Set up our GMarkerOptions object literal
                        homeMarkerOptions = { icon:homeIcon };
                        
                        gMap.addOverlay(gMarker, homeMarkerOptions);  // add back original location marker

                        var markerImgArr = new Array(12);
                        var markerImgIndex = new Array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
                        for (i=0; i<markerImgIndex.length; i++) {
                            markerImgArr[i] = '/images/mm_pink_'+markerImgIndex[i]+'.png';
                        }
                        
                        i = 0;
                        spotArr = data.mapresult;
                        for (keyval in spotArr) {
                            // Create our "tiny" marker icon
                            var tinyIcon = new GIcon();
                            tinyIcon.image = '/images/mm_pink_00.png';
                            tinyIcon.shadow = '/images/icn-spot-shadow.png';
                            tinyIcon.iconSize = new GSize(15, 26);
                            tinyIcon.shadowSize = new GSize(22, 20);
                            tinyIcon.iconAnchor = new GPoint(7, 24);
                            tinyIcon.infoWindowAnchor = new GPoint(7, 3);

                            // Set up our GMarkerOptions object literal
                            markerOptions = { icon:tinyIcon };
                            
                            var point = new GLatLng(spotArr[keyval]['maplat'], spotArr[keyval]['maplong']);
                            gMap.addOverlay(createSpotMarker(point, markerOptions, spotArr[keyval]['id']));
                            i++;
                        }
                        
                        i = 0;
                        spotArr = data.result;
                        for (keyval in spotArr) {
                            // Create our "tiny" marker icon
                            var tinyIcon = new GIcon();
                            tinyIcon.image = markerImgArr[i];
                            tinyIcon.shadow = '/images/icn-spot-shadow.png';
                            tinyIcon.iconSize = new GSize(15, 26);
                            tinyIcon.shadowSize = new GSize(22, 20);
                            tinyIcon.iconAnchor = new GPoint(7, 24);
                            tinyIcon.infoWindowAnchor = new GPoint(7, 3);

                            // Set up our GMarkerOptions object literal
                            markerOptions = { icon:tinyIcon };
                            
                            var point = new GLatLng(spotArr[keyval]['maplat'], spotArr[keyval]['maplong']);
                            gMap.addOverlay(createSpotMarker(point, markerOptions, spotArr[keyval]['id']));
                            i++;
                        }
                        break;
                        
                    case 'OK_UPDATE_SPOTMAP':
                        // Create our "tiny" marker icon
                        var tinyIcon = new GIcon();
                        tinyIcon.image = '/images/icn-spot.png';
                        tinyIcon.shadow = '/images/icn-spot-shadow.png';
                        tinyIcon.iconSize = new GSize(12, 20);
                        tinyIcon.shadowSize = new GSize(22, 20);
                        tinyIcon.iconAnchor = new GPoint(6, 20);
                        tinyIcon.infoWindowAnchor = new GPoint(5, 1);

                        // Set up our GMarkerOptions object literal
                        markerOptions = { icon:tinyIcon };
                        
                        spotArr = data.spotMsgList;
                        for (keyval in spotArr) {
                            var point = new GLatLng(spotArr[keyval]['maplat'], spotArr[keyval]['maplong']);
                            gMap.addOverlay(createSpotMarker(point, markerOptions, spotArr[keyval]['id']));
                        }
                        break;

                    case 'OK_UPDATE_SPOTINFO':
                        spotMsg = data.result;
                        // dojo.byId('spotmsg').innerHTML = ;
                        var spotPoint = new GLatLng(data.maplat, data.maplong);
                        gMap.openInfoWindowHtml(spotPoint, data.responsemsg, {maxHeight:110,maxWidth:480,autoScroll:true});
                        break;
                        
                    case 'OK_TOGGLE_TALK':
                        if (typeof data.encoding == 'undefined') {
                            responseNode = data.responsediv;
                            dojo.byId(responseNode).innerHTML = data.responsemsg;
                        } else {
                            if (data.encoding == 'base64') {
                                responseNode = data.responsediv;
                                dojo.byId(responseNode).innerHTML = Base64.decode(data.responsemsg);
                            }
                        }
                        spotmsgsection = 'talk_'+data.spotmsg_id;
                        if (dojo.byId(spotmsgsection).style.display == "none") {
                            toggleTalkViewer(spotmsgsection);
                        }
                        break;
                        
                    case 'OK_TOGGLE_REPLIES':
                        if (typeof data.encoding == 'undefined') {
                            responseNode = data.responsediv;
                            dojo.byId(responseNode).innerHTML = data.responsemsg;
                        } else {
                            if (data.encoding == 'base64') {
                                responseNode = data.responsediv;
                                dojo.byId(responseNode).innerHTML = Base64.decode(data.responsemsg);
                            }
                        }
                        msgsection = 'reply_'+data.msg_id;
                        if (dojo.byId(msgsection).style.display == "none") {
                            toggleTalkViewer(msgsection);
                        }
                        break;
                        
                    case 'OK_UPDATE_PLACE_CATEGORIES':
                        if (typeof data.encoding == 'undefined') {
                            responseNode = data.responsediv;
                            dojo.byId(responseNode).innerHTML = data.responsemsg;
                        } else {
                            if (data.encoding == 'base64') {
                                responseNode = data.responsediv;
                                dojo.byId(responseNode).innerHTML = Base64.decode(data.responsemsg);
                            }
                        }
                        if (responseNode == 'dialog_add_place_maincats') {
                        	dojo.fx.slideTo({ node:"dialog_add_place_category_container", left:"0", top:"0", unit:"px", duration:600, easing:dojo.fx.easing.quadOut }).play();
                        } else {
                        	dojo.fx.slideTo({ node:"dialog_add_place_category_container", left:"-436", top:"0", unit:"px", duration:600, easing:dojo.fx.easing.quadOut }).play();
                        }
                    	break;
                    	
                    case 'OK_ADD_PLACE':
                        setTimeout('openNamedDialog(\'dialog_submit_spot\')', 550);
                        resetAddPlaceDialog();
                    	break;

                    	
                    	
                    case 'OK_JSONLIST_DROPIN':
                        innerCode = '';
                        result = data.result;
                        responseNode = data.responsediv;
                        nextLevelImg = '<img border="0" src="/images/icn-morearrow.png" />';
                        for (i=0; i<result.length; i++) {
                            classVal = 'rndinputboxmid';
                            if (i == 0) {
                                classVal = 'rndinputboxtop';
                            }
                            if (i == result.length-1) {
                                classVal = 'rndinputboxbottom';
                            }
                            innerCode += '      <a href="/place/open/id/'+result[i].id+'">'+"\n";
                            innerCode += '      <div id="'+result[i].id+'" class="'+classVal+'">'+"\n";
                            innerCode += '      <table width="100%" cellspacing="0" cellpadding="0">'+"\n";
                            innerCode += '        <tr>'+"\n";
                            innerCode += '          <td width="80%">'+result[i].name+'</td>'+"\n";
                            innerCode += '          <td nowrap style="padding-left:8px; text-align:right;">'+result[i].distancefrom+' km</td>'+"\n";
                            innerCode += '          <td style="padding-left:8px;">'+nextLevelImg+'</td>'+"\n";
                            innerCode += '        </tr>'+"\n";
                            innerCode += '      </table>'+"\n";
                            innerCode += '      </div>'+"\n";
                            innerCode += '      </a>'+"\n";
                        }
                        replaceContentWithFade(responseNode, innerCode);
                        break;                    	
                    	
                    default:
                        break;
                }
            }
        }         
    });

    if (changeButton) {
        dijit.byId(buttonid).setLabel(origButtonVal);
        dijit.byId(buttonid).setAttribute('disabled', false);
    }
    return false;   
}
       


function submitEditSpot(doRemove) {
    if (doRemove) {
        dojo.byId('form_standard').docstatus.value = 10;
    }
    dojo.byId('form_standard').categories.value = collectCheckboxValues(dojo.byId('form_standard').selectcategories);
    submitAjaxForm('form_standard', '/spot/submit/format/json');
}

function submitSearch() {
    dojo.byId('embeddedform_search').maplong.value = dojo.byId('embeddedform_current_position').longitude.value;
    dojo.byId('embeddedform_search').maplat.value = dojo.byId('embeddedform_current_position').latitude.value;
    dojo.byId('embeddedform_search').mapaddress.value = dojo.byId('embeddedform_current_position').address.value;
    submitAjaxForm('embeddedform_search', '/spot/search/format/json');
}

function submitProfile() {
    myForm = dojo.byId('form_standard');

    var geocoder = new GClientGeocoder();    
    address = myForm.streetaddress.value+','+myForm.city.value+','+myForm.province.value+','+myForm.country.value+' '+myForm.postalcode.value;
    geocoder.getLatLng(address, function(point) {
        dojo.byId('form_standard').maplat.value = point.lat();
        dojo.byId('form_standard').maplong.value = point.lng();
    });
    submitAjaxForm('form_standard','/profile/submit/format/json');
}


function jumpToDestination(dest) {
    window.location = dest;
}

function openNamedDialog(name) {
    dijit.byId(name).show();
    window.blur();
}

function cancelNamedDialog(name) {
    dijit.byId(name).hide();
}




function deleteAttachment(id, parentid, attuse, responsediv) {
    Ext.Msg.confirm('Delete Attachment', 'Are you sure?',
        function(btn) {
            if (btn == 'yes') {
                dojo.byId('standardupload_docaction').value = 'delete';
                dojo.byId('standardupload_id').value = id;
                dojo.byId('standardupload_parentid').value = parentid;
                dojo.byId('standardupload_attuse').value = attuse;
                dojo.byId('standardupload_updatediv').value = responsediv;
                sendStandardForm('form_attachmentaction', responsediv);
            }
        });
}


var myUploadTimer = null;

function checkUploadStatus(numFrames) {
    myCurrentUploads = new Array();
    i = 1;
    while (i <= numFrames) {
        framedWindow = window.frames['hidden_upload_iframe_'+i];
        framedDocument = framedWindow.document;
        framedResponse = framedDocument.getElementById('responsediv');
        
        if (framedResponse.innerHTML == '') {
            // myCurrentUploads.push('Queue '+i+ ' is free.');           
        } else {
            if (framedResponse.innerHTML == 'RESERVED') {
                // still uploading
                myCurrentUploads.push('File is being transferred... (Queue:'+i+')');
            } else {
                window.clearInterval(myUploadTimer);
                returnString = framedResponse.innerHTML;
                if (returnString.indexOf('SUCCESS') == 0) {
                    dijit.byId('button_refresh_ATTACHMENTS').onClick();
                    myCurrentUploads.push('File successfully transferred! (Queue:'+i+')');
                    framedResponse.innerHTML = '';
                } else {
                    myCurrentUploads.push('Error in transfer. (Queue:'+i+')');
                    framedResponse.innerHTML = '';
                }
            }
        }
        i++;
    }
    while (myCurrentUploads.length > 0) {
        dojo.byId("upload_status_messages").innerHTML += myCurrentUploads.pop()+'<br />';
    }
}

function getAvailableUploadFrame(numFrames) {
    availableIndex = 0;
    i = 1;
    while (i <= numFrames) {
        framedUploadWindow = window.frames['hidden_upload_iframe_'+i];
        framedDocument = framedUploadWindow.document;
        framedResponse = framedDocument.getElementById('responsediv');
        if (framedResponse.innerHTML == '') {
            availableIndex = i;
            framedResponse.innerHTML = 'RESERVED';
            i = numFrames; // exit out of loop
        }
        i++;        
    }
    return availableIndex;
}

function sendStandardUpload(dialogname) {
    if (dojo.byId('form_dialog_add_attachment').elements['dialog_add_attachment__filename'].value == '') {
        alert('Please click the Browse button to select a file to upload.');
    } else {
        dijit.byId('dialog_add_attachment').hide();
        
        // routine to find an unused iframe
        numFrames = parseInt(dojo.byId('form_dialog_add_attachment').elements['dialog_add_attachment__docnumuploaders'].value);
        useFrame = getAvailableUploadFrame(numFrames);
        
        if (useFrame == 0) {
            alert('Please wait for one of your current uploads to finish.');
        } else {
            dojo.byId('form_dialog_add_attachment').target = 'hidden_upload_iframe_'+useFrame;
            dojo.byId('form_dialog_add_attachment').submit();
            myUploadTimer = window.setInterval("checkUploadStatus("+numFrames+");",800);
        }
    }
}

function collectCheckboxValues(srcCheckboxField){
    var returnString = '';
    for(var i=0; i < srcCheckboxField.length; i++){
        if(srcCheckboxField[i].checked) {
            returnString += srcCheckboxField[i].value + ';';
        }
    }
    return returnString;
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function createSpotMarker(point, markerOptions, id) {
    var marker = new GMarker(point, markerOptions);
    GEvent.addListener(marker, 'click', function() {
        var spotPoint = marker.getLatLng();
        // changeSpotMarker(spotPoint, id);
        
        dojo.byId('embeddedform_spot_info').id.value = id;
        dojo.byId('embeddedform_spot_info').maplat.value = spotPoint.lat();
        dojo.byId('embeddedform_spot_info').maplong.value = spotPoint.lng();
        submitAjaxForm('embeddedform_spot_info', '/spot/info/format/json');
    });
    return marker;   
}

function changeSpotMarker(point, id) {
    // Create our "tiny" marker icon
    var tinyIcon = new GIcon();
    tinyIcon.image = '/images/icn-spot-hilite.png';
    tinyIcon.shadow = '/images/icn-spot-shadow.png';
    tinyIcon.iconSize = new GSize(12, 20);
    tinyIcon.shadowSize = new GSize(22, 20);
    tinyIcon.iconAnchor = new GPoint(6, 20);
    tinyIcon.infoWindowAnchor = new GPoint(5, 1);
    
    // Set up our GMarkerOptions object literal
    markerOptions = { icon:tinyIcon };

    if (!empty(gMarkerHighlight)) {
        gMap.removeOverlay(gMarkerHighlight);
    }
    gMarkerHighlight = new GMarker(point, markerOptions);
    gMap.addOverlay(gMarkerHighlight);
}

function setAutoLocation(location) {
    switch (location) {
        case 'CABBAGETOWN':
            // 43.66382,-79.367552
            var lat = 43.66382;
            var lng = -79.367552;
            var point = new GLatLng(lat,lng);
            gMarker.setLatLng(point);
            gMap.panTo(point);
            dispAddress = 'Cabbagetown, Toronto, ON';
            break;
        case 'ENTDISTRICT':
            // 43.647721,-79.390887
            var lat = 43.647721;
            var lng = -79.390887;
            var point = new GLatLng(lat,lng);
            gMarker.setLatLng(point);
            gMap.panTo(point);
            dispAddress = 'Entertainment District, Toronto';
            break;            
    }
    dojo.byId('googlemapaddress').innerHTML = dispAddress;
    dojo.byId('embeddedform_current_position').latitude.value = lat;
    dojo.byId('embeddedform_current_position').longitude.value = lng;
    dojo.byId('embeddedform_current_position').address.value = dispAddress;
    submitAjaxForm('embeddedform_current_position', '/spot/setcurrent/format/json');    
}

function submitVote(spotmsg, voteval) {
    dojo.byId('embeddedform_vote').spotmsgid.value = spotmsg;
    dojo.byId('embeddedform_vote').votevalue.value = voteval;
    submitAjaxForm('embeddedform_vote', '/my/dovote/format/json');
}

function togglePicsViewer(spotmsgsection) {
    var fadeOut = dojo.fadeOut({node: spotmsgsection+"_frame", duration: 888});
    var fadeIn = dojo.fadeIn({node: spotmsgsection+"_frame", duration: 888});
    var wipeOut = dojo.fx.wipeOut({node: spotmsgsection+"_frame", duration: 888});
    var wipeIn = dojo.fx.wipeIn({node: spotmsgsection+"_frame", duration: 888});
    var slideRight = dojo.fx.slideTo({node: spotmsgsection+"_frame", duration: 888, left: 300, top: 0});
    var slideLeft = dojo.fx.slideTo({node: spotmsgsection+"_frame", duration: 888, left: 0, top: 0});

    var animOut = dojo.fx.combine([fadeOut, wipeOut, slideRight]);
    var animIn = dojo.fx.combine([fadeIn, wipeIn, slideLeft]);
    
    var animOpen = dojo.fx.wipeIn({node: spotmsgsection, duration: 222});
    var animClose = dojo.fx.wipeOut({node: spotmsgsection, duration: 222});
        
    if (dojo.byId(spotmsgsection).style.display == "none") {
        animOpen.play();
        setTimeout(function() {
            animIn.play();
        }, 222);
    } else {
        animOut.play();
        setTimeout(function() {            
            animClose.play();
        }, 888);
    }
    dojo.parser.parse(spotmsgsection+"_frame");
}

function toggleTalkViewer(spotmsgsection) {
    var fadeOut = dojo.fadeOut({node: spotmsgsection+"_frame", duration: 888});
    var fadeIn = dojo.fadeIn({node: spotmsgsection+"_frame", duration: 888});
    var wipeOut = dojo.fx.wipeOut({node: spotmsgsection+"_frame", duration: 888});
    var wipeIn = dojo.fx.wipeIn({node: spotmsgsection+"_frame", duration: 888});
    var slideRight = dojo.fx.slideTo({node: spotmsgsection+"_frame", duration: 888, left: 300, top: 0});
    var slideLeft = dojo.fx.slideTo({node: spotmsgsection+"_frame", duration: 888, left: 0, top: 0});

    var animOut = dojo.fx.combine([fadeOut, wipeOut, slideRight]);
    var animIn = dojo.fx.combine([fadeIn, wipeIn, slideLeft]);
    
    var animOpen = dojo.fx.wipeIn({node: spotmsgsection, duration: 222});
    var animClose = dojo.fx.wipeOut({node: spotmsgsection, duration: 222});
        
    if (dojo.byId(spotmsgsection).style.display == "none") {
        animOpen.play();
        setTimeout(function() {
            animIn.play();
        }, 222);
    } else {
        animOut.play();
        setTimeout(function() {            
            animClose.play();
        }, 888);
    }
    dojo.parser.parse(spotmsgsection+"_frame");
}

function empty(mixed_var) {
    var key;
    if (mixed_var === "" ||
        mixed_var === 0 ||
        mixed_var === "0" ||
        mixed_var === null ||
        mixed_var === false ||
        mixed_var === undefined
    ){
        return true;
    }
    if (typeof mixed_var == 'object') {
        for (key in mixed_var) {
            return false;
        }
        return true;
    } 
    return false;
}

function getHomeMarkerOptions() {
    var homeIcon = new GIcon(G_DEFAULT_ICON);
    homeIcon.image = '/images/mm_home.png';
    homeIcon.shadow = '/images/mm_home_shadow.png';
    homeIcon.iconSize = new GSize(20, 34);
    homeIcon.shadowSize = new GSize(37, 34);
    homeIcon.iconAnchor = new GPoint(10, 32);
    homeIcon.infoWindowAnchor = new GPoint(10, 32);

    // Set up our GMarkerOptions object literal
    homeMarkerOptions = { icon:homeIcon, draggable:true };
    return homeMarkerOptions;
}

function getAddPlaceMarkerOptions() {
    var homeIcon = new GIcon(G_DEFAULT_ICON);
    homeIcon.image = '/images/mm_home.png';
    homeIcon.shadow = '/images/mm_home_shadow.png';
    homeIcon.iconSize = new GSize(20, 34);
    homeIcon.shadowSize = new GSize(37, 34);
    homeIcon.iconAnchor = new GPoint(10, 32);
    homeIcon.infoWindowAnchor = new GPoint(10, 32);

    // Set up our GMarkerOptions object literal
    homeMarkerOptions = { icon:homeIcon, draggable:false };
    return homeMarkerOptions;
}

function switchToTab(tabcontainer, pane) {
   var tabs = dijit.byId(tabcontainer);
   var newpane = dijit.byId(pane);
   tabs.selectChild(newpane);
}

function scrollToContentStart() {
    var animNode = dojo.byId('content_start');
    var anim0 = dojox.fx.smoothScroll({node:animNode,win:window,duration:750,easing:dojo.fx.easing.quadInOut});
    anim0.play();
}

function toProperCase(s) {
  return s.toLowerCase().replace(/^(.)|\s(.)/g, 
          function($1) { return $1.toUpperCase(); });
}



function openComments(fieldId) {
	commentNode = dojo.byId('comment_form_'+fieldId);
	if (commentNode.style.display == 'none') {
	    wipeNodeIn('comment_form_'+fieldId);
	} else {
		var anim = dojox.fx.smoothScroll({
            node: commentNode,
            win:window,
            duration:300,
            easing:dojo.fx.easing.easeOut
        }).play();		
	}
}

function renderCommentBlock(arrComment, fieldId, parentId, threadId, myAuthId, myUserIcon) {
    var innerCode = '';
    var commentBoxDisplay = '';
    if (arrComment.length == 0) {
        commentBoxDisplay = 'display:none;';
    }
    
    innerCode += '<div id="comment_history_'+fieldId+'" style="padding-left:43px; '+commentBoxDisplay+'">'+"\n";
    for (j=0; j<arrComment.length; j++) {
        innerCode += '<div style="padding-bottom:5px;">'+"\n";
        innerCode += '  <div class="rndboxstream">'+"\n";
        innerCode += '    <table cellspacing="0" cellpadding="0" border="0"><tr><td valign="top">'+"\n";
        innerCode += '      <img class="user_icon" src="'+arrComment[j].render_icon+'" />'+"\n";
        innerCode += '    </td><td style="padding-left:8px; valign="top">'+"\n";
        innerCode += '      <div>'+arrComment[j].msg+'</div>'+"\n";
        innerCode += '      <div><span class=\"stream_date\">'+arrComment[j].render_date+' ('+arrComment[j].render_dateago+')'+'<\/span></div>'+"\n";
        innerCode += '    </td></tr></table>'+"\n";
        innerCode += '  </div>'+"\n";
        innerCode += '</div>'+"\n";
    }
    innerCode += '</div>'+"\n";

    innerCode += '<div id="comment_form_'+fieldId+'" style="padding-left:43px; padding-bottom:5px; '+commentBoxDisplay+'">'+"\n";
    innerCode += '  <div class="rndboxstream">'+"\n";
    innerCode += '    <table cellspacing="0" cellpadding="0" border="0"><tr><td valign="top">'+"\n";
    innerCode += '      <img class="user_icon" src="'+myUserIcon+'" />'+"\n";
    innerCode += '    </td><td style="padding-left:8px; valign="top">'+"\n";
    innerCode += '    <form id="embeddedform_comment_'+fieldId+'" name="embeddedform_comment_'+parentId+'" action="" method="post" target="">'+"\n";
    innerCode += '      <input type="hidden" name="fid" value="'+fieldId+'" />'+"\n";
    innerCode += '      <input type="hidden" name="uid" value="'+parentId+'" />'+"\n";
    innerCode += '      <input type="hidden" name="user_id" value="'+myAuthId+'" />'+"\n";
    innerCode += '      <input type="hidden" name="parent_id" value="'+parentId+'" />'+"\n";
    innerCode += '      <input type="hidden" name="thread_id" value="'+threadId+'" />'+"\n";
    innerCode += '      <textarea id="embeddedform_comment_msg_'+fieldId+'" name="msg" dojoType="dijit.form.Textarea" style="min-height:49px; width:388px; padding:5px;"></textarea>'+"\n";
    innerCode += '    </form>'+"\n";
    innerCode += '    </td><td valign="bottom" style="padding-left:8px;">'+"\n";
    innerCode += '    <a href="javascript:void(0);" onclick="submitAction(\'embeddedform_comment_'+fieldId+'\', \'/rest/api/v1/comment.save/format/json\');">'+"\n";    
    innerCode += '    <div class="buttonouter" style="width:60px; background-color:#a84324; padding:3px;">'+"\n";
    innerCode += '      <div class="buttoninner" style="background-repeat:repeat-x; background-color:#f1592a; border:1px solid #fab390;">'+"\n";
    innerCode += '        <div class="buttoninner" style="background-repeat:no-repeat; padding:3px;">'+"\n";
    innerCode += '          <div class="buttontext">'+"\n";
    innerCode += '          Post'+"\n";
    innerCode += '          </div>'+"\n";
    innerCode += '        </div>'+"\n";
    innerCode += '      </div>'+"\n";
    innerCode += '    </div>'+"\n";
    innerCode += '    </a>'+"\n";
    innerCode += '    </td></tr></table>'+"\n";
    innerCode += '  </div>'+"\n";
    innerCode += '</div>'+"\n";
    
    return innerCode;
}

