function addFavorite(a,p,i,x){
    $.ajax({
        type: "GET",
        url: "/func/inc/postcollect.jsp",
        data: { a: a, p: p, i: i },
        contentType: "application/x-www-form-urlencoded;charset=utf-8",
        success: function(response) {
            //alert('This File had been add to your collection!');
            var cnt = $("cnt",response).text();
            $("#dlcnt"+x).text(cnt);
        }
    });
}

function recordMsg( en, label1, label2 ){
    allMsgResponseHide();
    
    var inputtxt1 = $("#playtitle").attr("value");
    var inputtxt2 = $("#playmsg").val();
    if ( inputtxt1 == label1 ){
        $("#playtitle").attr("value","");
    }
    if ( inputtxt2 != label2 ){
        $("#playmsg").attr("value","");
    }
    recordMsgImpl(en, label);
}
function recordMsgImpl( en, label ){
    var pwd = $("#passwd").attr("value");
    $.ajax({
        type: "POST",
        url: "/func/inc/postmsg.jsp",
        data: { e: en, p: pwd },
        contentType: "application/x-www-form-urlencoded;charset=utf-8",
        success: function(response) {
            var responseact = $("passwd",response).text();
            //$("#passwd").attr("value", pwd);
            $("#passwdresponse"+responseact).fadeIn(100).fadeOut(3500);
        }
    });
}

function recordPasswd( en, label ){
    allPasswordResponseHide();
    
    var inputtxt = $("#passwd").attr("value");
    if ( inputtxt != label ){
        recordPasswdImpl(en, label);
    }
}

function clearLabel(field, label){
    var inputtxt = $("#"+field).attr("value");
    //alert("inputtxt:"+inputtxt+",label:"+label);
    if ( inputtxt == label ){
        $("#"+field).attr("value","");
    }
}

function recoverLabel(field, label){
    var inputtxt = $("#"+field).attr("value");
    //alert("inputtxt:"+inputtxt+",label:"+label);
    if ( inputtxt.length == 0 ){
        $("#"+field).attr("value",label);
    }
}



function recordPasswdImpl( en, label ){
    var pwd = $("#passwd").attr("value");
    $.ajax({
        type: "POST",
        url: "http://oeo.la/func/inc/postpasswd.jsp",
        data: { e: en, p: pwd },
        contentType: "application/x-www-form-urlencoded;charset=utf-8",
        success: function(response) {
            var responseact = $("passwd",response).text();
            //$("#passwd").attr("value", pwd);
            $("#passwdresponse"+responseact).fadeIn(100).fadeOut(3500);
        }
    });
}

function addFavorite1(a,p,i){
    $.ajax({
        type: "POST",
        url: "/func/inc/postcollect.jsp",
        data: { a: a, p: p, i: i },
        contentType: "application/x-www-form-urlencoded;charset=utf-8",
        success: function(response) {
            var commenttime = $("time",response).text();
            var commentnickname = $("nickname",response).text();
            var commentmsg = $("msg",response).text();

            var newcomment = "<div class='post respond'><span class='float-right'><strong>"+commenttime+"</strong></span><h4>"
            +commentnickname+": </h4><p>"+commentmsg+"</p></div>";

            $("#commentList").prepend(newcomment);
        }
    });
}
function allPasswordResponseHide(){
    $("#passwdresponse0").hide();
    $("#passwdresponse666").hide();
    $("#passwdresponse999").hide();
}

function copy_to_clipboard(text)
{
    if(window.clipboardData) {
        window.clipboardData.setData('text',text);
    }else{
        //alert('clipboard...'+$("#divclipboardswf").attr("FlashVars"));
        $("#divclipboardswf").attr("FlashVars", "clipboard="+text);
        //alert('clipboard...'+$("#divclipboardswf").attr("FlashVars"));
    }
    //alert('The text is copied to your clipboard...');
}

function showTitleText(defaulttxt){
    if ( $("#titlemsg").length > 0 ){
        if ( "" == $.trim($("#titlemsg").attr("value")) ){
            $("#titletext").html(defaulttxt);
        }
    }
            
    $("#titletext").show();
    $("#titleedit").hide();
    $("#titleloading").hide();
}
function showTitleEdit(defaulttxt){
    if ( $("#titlemsg").length > 0 ){
        if ( defaulttxt == $.trim($("#titlemsg").attr("value")) ){
            $("#titlemsg").attr("value", "");
        }    
    }
    
    $("#titletext").hide();
    $("#titleedit").show();
    $("#titleloading").hide();
    
    $("titlemsg").focus();
}
/*
function editTitle(defaulttxt, enc, origin){
    
	showTitleText(defaulttxt);
    
    var inputtxt1 = $.trim($("#titlemsg").val());
    if ( origin != inputtxt1){
        $("#titletext").hide();
        $("#titleedit").hide();
        $("#titleloading").show();
      
        $.ajax({
            type: "POST",
            url: "/func/inc/posttitle.jsp",
            data: { e: enc, m: inputtxt1 },
            contentType: "application/x-www-form-urlencoded;charset=utf-8",
            success: function(response) {
                inputtxt1 = replaceAll(inputtxt1,"<","&lt;");
                inputtxt1 = replaceAll(inputtxt1,">","&gt;");
                inputtxt1 = replaceAll(inputtxt1,"\r","<br/>");
                if ( inputtxt1.length != 0 ){
                    //inputtxt1 = wrapString( 40, inputtxt1);
                    $("#titletext").html(inputtxt1);
                    $('#titlecontent').attr('value', inputtxt1);
                }else{
                    $("#titletext").html(defaulttxt);
                    $('#titlecontent').attr('value', defaulttxt);
                }
                $("#titleloading").hide();
                $("#titletext").show();
            }
        });
    }
}
*/

function editTitle(enc, origin){
    var inputtxt1 = $.trim($("#playTitle").val());
	if ( $.trim(origin) != inputtxt1 && inputtxt1!=$.trim(emptyTitle)){
        
         $.ajax({
            type: "POST",
            url: "/func/inc/posttitle.jsp",
            data: { e: enc, m: inputtxt1 },
            contentType: "application/x-www-form-urlencoded;charset=utf-8",
            success: function(response) {
                inputtxt1 = replaceAll(inputtxt1,"<","&lt;");
                inputtxt1 = replaceAll(inputtxt1,">","&gt;");
                inputtxt1 = replaceAll(inputtxt1,"\r","<br/>");
                playtitle=inputtxt1;
                if ( inputtxt1.length == 0 ){
                	getPlayTitle(true);
                }
                $("#playTitle").attr("class","inputShareGrayTitle");
            }
        });
    }else{
    	$("#playTitle").attr("class","inputShareGrayTitle");
    }
}

function showDescripText(defaulttxt){
    if ( $("#playmsg").length > 0 ){
        if ( "" == $.trim($("#playmsg").val()) ){
            $("#playmsgtext2").html(defaulttxt);
        }
    }
            
    $("#playmsgtext").show();
    $("#playmsgedit").hide();
    $("#playmsgloading").hide();
}
function showDescripEdit(defaulttxt){
    if ( $("#playmsg").length > 0 ){
        if ( defaulttxt == $.trim($("#playmsg").val()) )
            $("#playmsg").attr("value", "");
    }
    
    $("#playmsgtext").hide();
    $("#playmsgedit").show();
    $("#playmsgloading").hide();
    
    $("#playmsg").focus();
}
/*
function editDescrip(defaulttxt, enc, origin){
    showDescripText(defaulttxt);
    
    var inputtxt1 = $.trim($("#playmsg").val());
    if ( origin != inputtxt1){
        $("#playmsgtext").hide();
        $("#playmsgedit").hide();
        $("#playmsgloading").show();
        
        $.ajax({
            type: "POST",
            url: "/func/inc/postmsg.jsp",
            data: { e: enc, m: inputtxt1 },
            contentType: "application/x-www-form-urlencoded;charset=utf-8",
            success: function(response) {
                inputtxt1 = replaceAll(inputtxt1,"<","&lt;");
                inputtxt1 = replaceAll(inputtxt1,">","&gt;");
                inputtxt1 = replaceAll(inputtxt1,"\r","<br/>");
                if ( inputtxt1.length != 0 ){
                    //inputtxt1 = wrapString( 60, inputtxt1);
                    $("#playmsgtext").html(inputtxt1);
                    $('#msgcontent').attr('value', inputtxt1);
                    $playmsgtext=inputtxt1;
                }else{
                    $("#playmsgtext").html(defaulttxt);
                    $('#msgcontent').attr('value', defaulttxt);
                }
                $("#playmsgloading").hide();
                $("#playmsgtext").show();
            }
        });
    }
}
*/

function editDescrip(enc, origin){
	var inputtxt1 = $.trim($("#playDesc").val());
	if ( $.trim(origin) != inputtxt1 && inputtxt1!=$.trim(emptyDesc)){
        
         $.ajax({
            type: "POST",
            url: "/func/inc/postmsg.jsp",
            data: { e: enc, m: inputtxt1 },
            contentType: "application/x-www-form-urlencoded;charset=utf-8",
            success: function(response) {
                inputtxt1 = replaceAll(inputtxt1,"<","&lt;");
                inputtxt1 = replaceAll(inputtxt1,">","&gt;");
                inputtxt1 = replaceAll(inputtxt1,"\r","<br/>");
                playtitle=inputtxt1;
                
                if ( inputtxt1.length == 0 ){
                	getPlayDesc(true);
                }
                $("#playDesc").attr("class","textareaShareDescUnBorder");
            }
        });
    }else{
    	$("#playDesc").attr("class","textareaShareDescUnBorder");
    }
}

function loadEmptyTitle(defaulttxt){
    var msgvalue = $.trim($('#titlemsg').attr('value'));
    var msgtextvalue = $.trim($('#titletext').html());
    var msgcontentvalue = $.trim($('#titlecontent').attr('value'));
    //alert("1msg:"+msgvalue+",msgtext:"+msgtextvalue+",msgcontent:"+msgcontentvalue)
    if ( msgvalue.length == 0 && msgtextvalue.length == 0 && msgcontentvalue.length == 0 ){
        $('#titlemsg').attr('value', defaulttxt);
        $('#titletext').html(defaulttxt);
        $('#titlecontent').attr('value', defaulttxt);
    }
}

function loadEmptyDescrip(defaulttxt){
    var msgvalue = $.trim($('#playmsg').attr('value'));
    var msgtextvalue = $.trim($('#playmsgtext2').html());
    var msgcontentvalue = $.trim($('#msgcontent').attr('value'));
    //alert("2msg:"+msgvalue+",msgtext:"+msgtextvalue+",msgcontent:"+msgcontentvalue)
    if ( msgvalue.length == 0 && msgtextvalue.length == 0 && msgcontentvalue.length == 0 ){
        $('#playmsg').attr('value', defaulttxt);
        $('#playmsgtext2').html(defaulttxt);
        $('#msgcontent').attr('value', defaulttxt);
    }
}

function wrapTitle(){
    if ( $.trim($("#titletext").html()) != "" ){
        var txt = $("#titletext").html();
        //txt = wrapString(40, txt);
        $("#titletext").html(txt);
    }
}
function wrapString( cnt, s){
    var cnt2 = cnt;
    while ( cnt < s.length ){
        s = s.substr(0,cnt) + "<br>" + s.substr(cnt, s.length);
        cnt = cnt+cnt2;
    }
    return s
}


function bigmodeready(){
	//document.getElementById("FunPlay").callFunPlay();
}

function changeBigMode(){
	bigFunPlay();
	$("#bigone").css("height",getDocumentSize(1)+"px");
    $("#funplayframe").hide();
    $("#logo").hide();
    $("#bigone").show();
    $.scrollTo($("#bigone"),800);
}

function changeSmallMode(){
    //$("#funplayframe").css("width","750px");
    //$("#FunPlay").attr("width",750)
    //$("#FunPlay").attr("height",375)
    $("#funplayframe").show();
    $("#logo").show();
    $("#bigone").hide();
    //go back to logo for scroll page to top
    $.scrollTo($("#logo"),800);
}

function getDocumentSize(a) {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  if ( a == 1 )//Height
    return myHeight;
  else  
    return myWidth;
}

function replaceAll(strOrg,strFind,strReplace){
 var index = 0;
 while(strOrg.indexOf(strFind,index) != -1){
  strOrg = strOrg.replace(strFind,strReplace);
  index = strOrg.indexOf(strFind,index);
 }
 return strOrg
} 

function clearComment(s){
    if ( $.trim(s) == $.trim($("#p_msg").attr("value")) )
        $("#p_msg").attr("value","");
}

function checkCommentLength(){
    var leng = 200;
    if ( $("#p_msg").attr("value").length > leng )
        $("#p_msg").attr("value", $("#p_msg").attr("value").substring(0,leng))
}

function checkDescripLength(){
    var leng = 100;
    if ( $("#playmsg").attr("value").length > leng )
        $("#playmsg").attr("value", $("#playmsg").attr("value").substring(0,leng))
}
var folderPath=folderPath || {
	scrip:"",
	root:"",
	path:[],
	/*
	path = [
		{
			foldername: "foldername",
			folderid: "123456",
			folderuri: "http://oeo.la/doijwefwe",
		},
	];
		path.push({
	        foldername: true,
	        ready: false,
			filename: ''
		});
		var lastpath = path.pop();

	 */
	browsefolders:[],
	browsefiles:[],
	folderBrowse:function(p, fn, a, t, s, u, i, n, callbackfunc){
	//alert(s+"   "+folderPath.scrip);
		$.ajax({
	        type: "POST",
	        url: "/func/inc/folderlist.jsp",
	        data: { fn: fn, p: p, t: t, s: folderPath.scrip, u: u, i: i, a: a, r:folderPath.root, n: n },
	        contentType: "application/x-www-form-urlencoded;charset=utf-8",
	        success: function(response) {
	        	//alert(response);
	        	//$("#fblist").html(response);
	        	/*
	        	browsefolders=[];
	        	$(response).find("folder").each(function()
	        	{
	        		browsefolders.push({
	        			id:$(this).find("id").text(),
	        			display:$(this).find("display").text()
	        		});
	        	});
	        	
				browsefiles=[];
				$(response).find("file").each(function()
			    {
					browsefiles.push({
						id:$(this).find("id").text(),
						display:$(this).find("display").text(),
						display:$(this).find("isimg").text(),
						display:$(this).find("fcode").text(),
			        });
			    });
			    */
				if(typeof(callbackfunc)=="function")
					callbackfunc(response);
				
	        }
	    });
	}

};
//folderPath.folderBrowse(321534, "testfolder", "", function(){
//	alert(browsefolders.length+"    "+browsefiles.length);
//});

function writeinfo(date, size, cnt){
	if(date.length>0){
		$("#infodate").html(date);
	}
	$("#infosize").html(size);
	$("#infocnt").html(cnt);
	$("#filecount").html(cnt);
}

function writecommentcount(cnt){
	$("#commentcount").html(cnt);
}

function lockshare(sw){
	if(sw==1)
		$("#lockshareimg").attr('src',"/images/lock.jpg");
	else
		$("#lockshareimg").attr('src',"/images/unlock.jpg");
}
function getLocked(){
	if($("#lockshareimg").attr('src')=="/images/lock.jpg"){return true;}
	else{ return false;}
}

function showCommentDiv(){

	$("#fblist").hide();
	$("#commentDiv").show();
//	$("#commentDiv").next().slideDown('slow',function(){
//		$("#fblist").slideUp('slow');
//	});
}

function showFblistDiv(){
	$("#fblist").show();
	$("#commentDiv").hide();
}

var playtitle = "";
var playdesc = "";

function getPlayTitle(Ownerflg){
	if($.trim($("#playTitle").val()).length>0)
		playtitle=$.trim($("#playTitle").val());
	else if(Ownerflg)
		$("#playTitle").val(emptyTitle);
	else
		$("#playTitle").hide();
}

function getPlayDesc(Ownerflg){
	if($.trim($("#playDesc").val()).length>0)
		playdesc=$.trim($("#playDesc").val());
	else if(Ownerflg)
		$("#playDesc").val(emptyDesc);
	else
		$("#playDesc").hide();

}