function FlagFile(){
	document.getElementById('flag_rspnse').innerHTML='Please select a reason';
	if (document.getElementById('flag_reason').selectedIndex > 0){
		document.getElementById('flag_rspnse').innerHTML='<div align="center" style="padding-right:130px;"><img height="18px" width="18px" border="0" align="middle" src="images/imgloader.gif"></div>';
		//userFileAction("flag", document.getElementById('flag_reason').options[document.getElementById('flag_reason').selectedIndex].value, flagNote);
		userFileAction("flag", document.getElementById('flag_reason').options[document.getElementById('flag_reason').selectedIndex].value);
	}
}


function userPostAction(postid, action, value, valueReason){
    mySWF.callSWF("userPostAction", ["JS", postid,action, value, valueReason]); 
     document.getElementById('dv_cmntsloader'+postid).style.display="block";
}

function fillPostState_UserPostProbarties(obj){

//alert('i am here .............' +obj.post_state.id );
//alert('comment_okay_'+obj.post_state.id);
//document.getElementById('comment_okay_'+obj.post_state.id).style.display="none";

//alert(document.getElementById('comment_group_'+ obj.post_state.id).innerHTML)
//alert(document.getElementById('comment_group_'+ obj.post_state.id).length)



//alert("from inner : " + document.getElementById('comment_okay_'+obj.post_state.id).innerHTML);

//alert('id: '+obj.post_state.id);
//alert('okay: '+obj.post_state.okay);
//alert('bad: '+obj.post_state.bad);
//alert('userpostid: '+obj.postuserProparties.id);
//alert('mark: '+obj.postuserProparties.mark);
//alert('flag: '+obj.postuserProparties.flag);

    document.getElementById('dv_cmntsloader'+obj.post_state.id).style.display="none";
    document.getElementById('comment_okay_'+obj.post_state.id).innerHTML=obj.post_state.okay;
    document.getElementById('comment_bad_'+obj.post_state.id).innerHTML=obj.post_state.bad;


//postinfo.id
//postinfo.mark //1  user alreadh fot okay; if 2 post is bad // if 0  user did not valute
//postinfo.flag
//postinfo.posted
//id="cmnts_'+name+'_'+id+'"
}


function userFileAction(action, value, valueReason){

	switch(action){
		case 'rate':
			rating.notifytext.innerHTML = 'تقييم '+value+' ..Saving';
			//1st parameter is to position the msg, second parameter is the message.
			//hangUserRspnce("ratingdiv","'Rated' this");
		break;
		case 'mark':
			if(value==1){hrf_id='hrf_likethis';msg="'Liked this'";
			}else{hrf_id='hrf_dlike';msg="'Disliked this'";}
			if(document.getElementById("userid").value=="0")
				{dLoginBox(hrf_id,'below_left');return false;}
			document.getElementById('likedislike_bar').innerHTML= '..Saving'; 
			//1st parameter is to position the msg, second parameter is the message.likedislike_bar
			//hangUserRspnce(hrf_id,msg);
			
		break;
		default:
	}
//alert(document.getElementById("f").value +" "+action+" "+value+" "+valueReason);
    mySWF.callSWF("userFileAction", ["JS", document.getElementById("f").value, action, value, valueReason]); 
}


function hangUserRspnce(divid,msg){
	document.getElementById('PopDiv').innerHTML= '<div id="div_loginbx" style="background-color:#FFF;border:1px solid #CCC;"><div align="center" style="margin:6px;padding:1px 3px;font-size:11px;font-weight:bold;border:1px solid #CCC;background-color:#000;color:#CC0000;"> You alredy '+msg+' file.</div></div>'; 
	Popup.show('PopDiv',divid,"below left",{'constrainToScreen':true});
	timedMsg('PopDiv');
}


function fillFileState_UserFileProbarties(infoObj){
//alert(infoObj.file_state.like+" "+infoObj.file_state.dislike+" "+infoObj.file_state.ratings+" "+infoObj.file_state.raters);
    likeDislikes(infoObj.file_state.like, infoObj.file_state.dislike);
    setRating(infoObj.file_state.ratings,infoObj.file_state.raters);

//alert('doen ' + infoObj.actionField);
//alert(infoObj.file_state.raters);
/*alert(infoObj.fileuserProparties.rate);
//alert(infoObj.fileuserProparties.mark);
//alert(infoObj.fileuserProparties.flag);
//alert(infoObj.fileuserProparties.favorite);*/
}


function fillOwnerInfo(user){

//alert('filling owner info 1');
	if (document.getElementById("userid").value==user.userid)
	var userblock='<div align="right" id="ownerprofile"><a href="#" class="blue">Edit Profile</a></div>';
	else
	userblock="";
//alert('filling owner info 2');

	userblock=userblock+'<img id="ownerpicture" src="http://www.yabdoo.com/board/image.php?place=gallery&u='+user.userid +'" width="90" height="93" border="1"/><br/><br/>'+
			   '<img src="images/'+user.onlinestatus+'.gif" width="16" height="16" border="0" align="absmiddle" style="background-image:none">'+
	'<b>'+user.username+'</b><br/>'+
		'الانضمام: '+user.joindate+'<br/>'+
		'مشاركات:'+ user.posts +'<br/>';

	document.getElementById("ownerProfiles_D").innerHTML=userblock;
//alert('filling owner info 3 ' + document.getElementById("UserProfile_D").innerHTML);

//alert('filling owner info 4');
}



function BuildFileItem2(file_,i){
//alert("Loading..."+ file_);
         var title;
		var link='#!section=watch&f='+file_.code;

        if(file_.title)
        {
//alert("TITLE: " + file_.title);
//alert("splitString: " + splitString(file_.title, 10));
        //title = splitString(file_.title, 10);
      title = file_.title;

        }
        else 
        {
        title="no title";
        }

//document.getElementById("loaderHome").innerHTML=document.getElementById("player").innerHTML;


if(i==0)
{
 // BuildFileItem(file_,i)
  document.getElementById("mostViewedFile_D").innerHTML=BuildFileItem(file_,i);
}

var uid=uniqId();

		var dv_content = '<div id="thumb'+i+'" class="vidthumb3" style="position:relative;height:73px;">';
	 dv_content += '<a href="'+link+'" class="blue" id="'+file_.code+'"  onMouseOver=JAVASCRIPT:thumbOverNew("'+uid+'aC_'+file_.code+'");';

	 dv_content += ' onMouseOut=document.getElementById("'+uid+'aC_'+file_.code+'").style.display="none"; >';
	 dv_content += '<img src="http://www.yabdoo.com/gallery/watch.php?showType=Capture&showSize=thumb&f='+file_.code+'" style="margin-right:3px;" width="80" height="70" border="1" align="left"/>'+title+'</a><br/>';
	 dv_content += file_.views+' المشاهدات<br/>'+file_.owner;
	 dv_content += '<div id="duration" align="left" ';
	 dv_content += ' class="durationtxt">'+file_.duration+'</div>';
	 dv_content += '<div onMouseOver=JAVASCRIPT:thumbOverNew("'+uid+'aC_'+file_.code+'"); id="'+uid+'aC_'+file_.code+'" align="left" class="addCart " style="position:absolute;z-index:3;">';
	 dv_content += ' <span style="cursor:pointer;" onMouseOver="Tip(' +"'إضافة إلى السرة'"+ ',BGCOLOR,\'#666666\',ABOVE, true,CENTERMOUSE,true);" onClick=JAVASCRIPT:alert("'+uid+'aC_'+file_.code+'");dLoginBox("'+uid+'aC_'+file_.code+'","below_left");>';
	 dv_content += '<img src="images/add.gif" width="17" height="17" border="0" /></span></div>';
	 dv_content += '<div id="addTC'+file_.code+'" class="addedToCart" align="left">';
	 dv_content += '<a href="#" onMouseOver=thumbOverNew("aC_'+file_.code+uid+'");><img src="images/added_cart.gif" width="17" height="17" border="0" /></a> </div>';
	 dv_content += '<div id="addTF'+file_.code+'" class="addedToFav" align="left"> <a href="#" onMouseOver=JAVASCRIPT:thumbOverNew("aC_'+file_.code+'");>';
	 dv_content += '<img src="images/added_fav.gif" width="17" height="17" border="0" /></a> </div>  ';
	 dv_content += '<div id="addTQ'+file_.code+'" class="addedToQ" align="left"> ';
	 dv_content += '<a href="#"><img src="images/added_q.gif" width="17" height="17" border="0" /></a> </div></div>';

return dv_content;
}


function BuildFileItem(file_,i){
//alert("BuildFileItem.....");
//alert("Loading..."+ file_);
//alert("file: " + file_.code);
//alert('fileType'+file_.fileType);
document.getElementById("filetype_loading").style.display='none';

	var link='#!section=watch&f='+file_.code;

//        title = splitString(file_.title,10);

        if(file_.title)
        title = file_.title;

else 
title="no title";
	var uid=uniqId();
		var dv_content = '<div id="thumb'+i+'" class="vidthumb2" style="position:relative;height:73px;">';
	 dv_content += '<a href="'+link+'" class="blue" id="'+file_.code+'"  onMouseOver=JAVASCRIPT:thumbOverNew("'+uid+'0aC_'+file_.code+'");';
	 dv_content += ' onMouseOut=document.getElementById("'+uid+'0aC_'+file_.code+'").style.display="none"; >';
	 dv_content += '<img src="http://www.yabdoo.com/gallery/watch.php?showType=Capture&showSize=thumb&f='+file_.code+'" style="margin-right:3px;" width="80" height="70" border="1" align="left"/>'+title+'</a><br/>';
	 dv_content += file_.views+' المشاهدات<br/>'+file_.owner;
	 //dv_content += '<br/>'+fileType(file_.fileType)+':Type ';
	 dv_content += '<div id="duration" align="left" class="durationtxt">'+file_.duration+'</div>';

	 dv_content += '<div onMouseOver=JAVASCRIPT:thumbOverNew("'+uid+'0aC_'+file_.code+'"); id="'+uid+'0aC_'+file_.code+'" align="left" class="addCart " style="position:absolute;z-index:3;">';

	 dv_content += ' <span style="cursor:pointer;" onMouseOver="Tip(' +"'إضافة إلى السرة'"+ ',BGCOLOR,\'#666666\',ABOVE,true,CENTERMOUSE,true);" onClick=JAVASCRIPT:fileAddClick("'+file_.code+'");dLoginBox("'+uid+'0aC_'+file_.code+'","below_left");document.getElementById("'+uid+'0aC_'+file_.code+'").style.display="none"; >';
	 dv_content += '<img src="images/add.gif" width="17" height="17" border="0" /></span></div>';
	 dv_content += '<div id="addTC'+file_.code+'" class="addedToCart" align="left">';
	 dv_content += '<a href="#" onMouseOver=thumbOverNew("0aC_'+file_.code+uid+'");><img src="images/added_cart.gif" width="17" height="17" border="0" /></a> </div>';
	 dv_content += '<div id="addTF'+file_.code+'" class="addedToFav" align="left"> <a href="#" onMouseOver=JAVASCRIPT:thumbOverNew("0aC_'+file_.code+uid+'");>';
	 dv_content += '<img src="images/added_fav.gif" width="17" height="17" border="0" /></a> </div>  ';
	 dv_content += '<div id="addTQ'+file_.code+'" class="addedToQ" align="left"> ';
	 dv_content += '<a href="#"><img src="images/added_q.gif" width="17" height="17" border="0" /></a> </div></div>';

return dv_content;
}
		

function build_dvContent(files, style_){
	var dv_content = "";
	if(files.length==0)dv_content='No files found';

	for (var i=0; i<files.length; i++)
	{            
		var file_=files[i];
                  if (style_==2)
                  {               
		dv_content += BuildFileItem2(file_, i);
                  }
                  else
                  {
		dv_content += BuildFileItem(file_, i);
                  }

	}
					

/*manually added advertisement*/
document.getElementById("Advertisement_D").innerHTML='<div align="center"><img src="images/add.jpg" width="192" height="218" align="middle"></div>';

return dv_content;
}			



function fillTypeClick() {
$(document).ready( function(){ 
	$(".cb-enable").click(function(){
//alert("click");
		var parent = $(this).parents('.switch');
		$('.cb-disable',parent).removeClass('selected');
		$(this).addClass('selected');
		$('.checkbox',parent).attr('checked', true);
sendFileTypeQuery();

//alert(parent.name);
//var galleryTypeArray=new Array();
//galleryTypestring=galleryTypeArray.join(',');

//alert(galleryTypestring);
		//alert($('.checkbox',parent).attr('name')+' checked: '+ $('.checkbox',parent).attr('checked'));
	});
	$(".cb-disable").click(function(){
		var parent = $(this).parents('.switch');
		$('.cb-enable',parent).removeClass('selected');
		$(this).addClass('selected');
		$('.checkbox',parent).attr('checked', false);
		//alert($('.checkbox',parent).attr('name')+' checked: false');
sendFileTypeQuery();

	});
});
}

//Modified by Asik for image and video off/on (The above function "fillTypeClick()" deprecated)
$(document).ready( function(){ 
	$("body").delegate("div#dv_advanceSearch", "myCustomEvent", function(e, myName, myValue){
		$(".cb-enable").click(function(){
			var parent = $(this).parents('.switch');
			$('.cb-disable',parent).removeClass('selected');
			$(this).addClass('selected');
			$('.checkbox',parent).attr('checked', true);
			sendFileTypeQuery();
		});
		$(".cb-disable").click(function(){
			var parent = $(this).parents('.switch');
			$('.cb-enable',parent).removeClass('selected');
			$(this).addClass('selected');
			$('.checkbox',parent).attr('checked', false);
			sendFileTypeQuery();
		});
	});	
});



function sendFileTypeQuery(){
//alert("photo: " + document.getElementById('photoBtn').className +", video: "+ document.getElementById('videoBtn').className+", Others: "+ document.getElementById('othersBtn').className);

var galleryTypeArray=new Array();

if (document.getElementById('photoBtn').className=="cb-enable selected")
galleryTypeArray.push(1);
if (document.getElementById('videoBtn').className=="cb-enable selected")
galleryTypeArray.push(2);
if (document.getElementById('othersBtn').className=="cb-enable selected")
galleryTypeArray.push(3);
/*
if (document.getElementById('srh_photo').checked==true)
galleryTypeArray.push(1);
if (document.getElementById('srh_video').checked==true)
galleryTypeArray.push(2);
if (document.getElementById('srh_others').checked==true)
galleryTypeArray.push(3);
*/
galleryType=galleryTypeArray.join(',');

document.getElementById("filetype_loading").style.display="block";
document.getElementById("filetype_loading").innerHTML='<b>&nbsp; جاري تحديث الصفحة، فضلا الانتظار...</b>';
mySWF.callSWF("updateUserSettings", ["JS", "galleryType", galleryType]); 

updatedGalleryType=galleryType;
//alert("updatedGalleryType: " + updatedGalleryType);
}
