/**
 * this is a sample javascript that demonstrates how the Rad UPload Plus
 * applet can interact with a javascript.
 *
 * If you set the jsnotify configuration property, the applet will call 
 * the upload completed method when the file upload has been completed.
 *
 * You can call the getUploadStatus() method to determine whether the
 * upload was successfull. Possible values are 1, for success, 0 when the 
 * user has cancelled the upload and -1 when the upload failed (error).
 * 
 */
/* a usefull variable */
var upload=0;
/**
 * the response returned by the server will be passed as a parameter (s) to this
 * function. However in the case of Netscape the parameter will be empty. When using
 * netscape call the getResponse()method of the applet to access this information.
 *
 */
function fbpublish(_src,_href){

var parseparams = _src.split('|');
/*0 max
		1 max jpg url
    2 rating
    3 title/desc
    4 cat
	5 usr url
	6 jpg*/
//alert('href='+_href+' \nsrc='+_src);
var rooturl = 'http://'+parseparams[0].toString()+'cms';
var mediaref = 'http://'+parseparams[0].toString()+'widerworld' + parseparams[1].toString();
var __href = rooturl+_href;
var maxlogo = rooturl + '/images/maxamundo.jpg';
//var __src = 'http://'+parseparams[0].toString();
var message = 'check out this maxamundo tag';
var cap = '{*actor*} rated this tag '+parseparams[2].toString()+' stars';
var desc = parseparams[3].toString();
var cat = parseparams[4].toString();
var ratings = parseparams[2].toString()+' stars';
var mediatype = parseparams[5].toString();
//alert('media ref = '+mediaref+' ? '+parseparams[5].toString());
//var attachment = { 'name': 'maxamundo', 'href': __href, 'caption': '{*actor*} rated this tag 5 stars', 'description': 'a cool place', 'properties': { 'category': { 'text': 'humor', 'href': 'http://bit.ly/KYbaN'}, 'ratings': '5 stars' }, 'media': [{ 'type': 'image', 'src': __src, 'href': __href}] };

//var attachments_ = { 'name': 'maxamundo', 'href': __href, 'caption': cap, 'description': desc, 'properties': { 'category': { 'text': cat, 'href': __href}, 'ratings': ratings }, 'media': [{ 'type': 'image', 'src': __src, 'href': __href}] };
var attachment = { 'name': 'view on the maxamundo map', 'href': __href, 'caption': cap, 'description': desc, 'properties': { 'category': { 'text': cat, 'href': __href}, 'ratings': ratings }, 'media': [{ 'type': 'image', 'src': mediaref, 'href': __href}] };

if (mediatype == "video") {
	attachment = { 'name': 'view on the maxamundo map', 'href': __href, 'caption': cap, 'description': desc, 'properties': { 'category': { 'text': cat, 'href': __href}, 'ratings': ratings }, 'media': [{'type': 'flash', 'swfsrc': mediaref, 'imgsrc': maxlogo}] };

}
if (mediatype == "mp3") {
	attachment = { 'name': 'view on the maxamundo map', 'href': __href, 'caption': cap, 'description': desc, 'properties': { 'category': { 'text': cat, 'href': __href}, 'ratings': ratings }, 'media': [{ 'type': 'mp3', 'src': mediaref, 'href': __href}] };

}

var action_links = [{'text':'View tag', 'href':__href}]; 
FB.Connect.streamPublish(message, attachment, action_links);
 }
 function alertMe(msg) {
	 alert(msg);
 }
function maxhideaform() {
    var form = 'maxupload';
    var e = document.getElementById(form);
    if (e.style.visibility == "hidden") {
        e.style.visibility = "visible";
        e.style.display = "inline";
    } else {
        e.style.visibility = "hidden";
       e.style.display = "none";
    }
}
function gotoTagId(returnstring){
    //event.itemRenderer.data.guid
    var maxswf = document.getElementById('maxamundoContent');
      var tag = returnstring.toString();
     maxswf.SetVariable("JupGotoTagId",tag);
    // alert ("tagid="+tag);
}
function uploadafileCallback( returnstring ) {
    if (returnstring != "fail") {
        /* return file name to flash rss tag */
        var st = returnstring.toString();
        // alert ("return file name to flash rss tag... "+st);
		 var maxswf = document.getElementById('maxamundoContent');
      // document.maxamundoswf.maxamundoContent.
	  maxswf.SetVariable("JupLoadComm",st);
	  maxhideaform();
       /*   //document.maxamundoContent.SetVariable("JupLoadComm",st);
        //gettags();
       // alert ("uploaded: "+st);
//        hideaform(); */
    }	else {
        alert ("return file name to flash rss tag... "+returnstring);
    }
}
function uploadCompleted()
{
    upload = document.rup.getUploadStatus();
    if(upload==1)
    {
        returnfilen = document.rup.getResponse();
        uploadafileCallback( returnfilen );
    }
    else
    {
        alert("The upload seems to have failed");
    }
	
    return true;
}
function setradData(oldname,image,author,tagid)
{
    // alert ('set url:'+oldname+','+image+','+author+','+tagid);
    //var filepath = document.forms["form"].elements["getpath"].value = args;
    //rename
    //var filepath1 = document.forms["form"].elements["getpath"].value;
    document.forms["form"].elements["tagid"].value = tagid;
    document.forms["form"].elements["author"].value = author;
    //document.forms["form"].elements["username"].value = author+','+tagid;
    document.forms["form"].elements["image"].value = image;
    //document.rup.jsAddTextField('oldname',oldname);
    //var oldname1 = document.forms["form"].elements["oldname"].value;
    //document.rup.jsAddTextField('image',image);
    //var caption1 = document.forms["form"].elements["caption"].value;
    //document.rup.jsAddTextField('author',author);
    //var mediatype1 = document.forms["form"].elements["mediatype"].value;
    //document.rup.jsAddTextField('tagid',tagid);
    r_getFormData();
}
function r_getFormData()
{
    //var filepath = document.forms["form"].elements["getpath"].value = args;
    //rename
    //alert('r_getFormData');
    if(document.forms["form"] == undefined)
    {
        return;
    }
    for(i = 0 ; i < document.forms["form"].elements.length ; i++)
    {
        document.rup.jsAddTextField(document.forms["form"].elements[i].name,
            document.forms["form"].elements[i].value);
    }
/*
var tagid1 = document.forms["form"].elements["tagid"].value;
document.rup.jsAddTextField('tagid',tagid1);
var oldname1 = document.forms["form"].elements["oldname"].value;
document.rup.jsAddTextField('oldname',oldname1);
var author1 = document.forms["form"].elements["author"].value;
document.rup.jsAddTextField('author',author1);
var mediatype1 = document.forms["form"].elements["mediatype"].value;
document.rup.jsAddTextField('mediatype',mediatype1);
*/
}