// JavaScript Document
function getProfileBox(profileURL,containerId,callbackName)
{
	
	if (containerId == null)
	{
		containerId ='spanProfile';
	}
	if (callbackName == null)
	{
		callbackName ='callback';
	}
	$.ajax({
			  url: profileURL,
			  cache: false,
			  dataType: "jsonp",
			  jsonp:callbackName,
			  success: function(data) {
				showBoxProfile(data,containerId)
			}});
}

function showBoxProfile(data,containerId)
{
	if (data.result)
	{
		$('#'+containerId).html(data.result);
	}
}

$("#optPhotoMemberHome").change(function ()
	{						
	intPhotoBoxOrderBy=$('#optPhotoMemberHome option:selected').attr("value");
	$('#span_pto_photo').nt_loadPhotoBox(strOwnerUsername,intPhotoBoxOrderBy);
	});

function registerPhotoBoxSelectOrder()
{
	$("#optPhotoMemberHome").change(function ()
			{						
			intPhotoBoxOrderBy=$('#optPhotoMemberHome option:selected').attr("value");			
			$('#span_pto_photo').nt_loadPhotoBox(strOwnerUsername,intPhotoBoxOrderBy);
			});
}
///
$("#optAlbumMemberHome").change(function ()
	{						
	intAlbumBoxOrderBy = $('#optAlbumMemberHome option:selected').attr('value');			
	$('#span_pto_album').nt_loadAlbumsBox(strOwnerUsername,intAlbumBoxOrderBy);
	});
function registerAlbumBoxSelectOrder()
{
	$("#optAlbumMemberHome").change(function ()
			{						
			intAlbumBoxOrderBy = $('#optAlbumMemberHome option:selected').attr('value');			
			$('#span_pto_album').nt_loadAlbumsBox(strOwnerUsername,intAlbumBoxOrderBy);
			});
}
//
$("#opt_photo_favourite_member_home").change(function ()
	{						
	intFavPhotoBoxOrderBy = $("select[@name='opt_photo_favourite_member_home'] option:selected").attr("value");			
	$('#span_pto_ptyt').nt_loadFavouritePictureBox(strOwnerUsername,intFavPhotoBoxOrderBy);
	});
function registerFavouritePhotoBoxSelectOrder()
{
	$("#opt_photo_favourite_member_home").change(function ()
			{						
			intFavPhotoBoxOrderBy = $("select[@name='opt_photo_favourite_member_home'] option:selected").attr("value");			
			$('#span_pto_ptyt').nt_loadFavouritePictureBox(strOwnerUsername,intFavPhotoBoxOrderBy);
			});
}
//
$("#optAlbumFavouriteMemberHome").change(function ()
	{						
	intFavAlbumBoxOrderBy = $("select[@name='optAlbumFavouriteMemberHome'] option:selected").attr("value");				
	$('#span_pto_albumyt').nt_loadFavouriteAlbumsBox(strOwnerUsername,intFavAlbumBoxOrderBy);
	});
function registerFavouriteAlbumBoxSelectOrder()
{
	$("#optAlbumFavouriteMemberHome").change(function ()
			{						
			intFavAlbumBoxOrderBy = $("select[@name='optAlbumFavouriteMemberHome'] option:selected").attr("value");				
			$('#span_pto_albumyt').nt_loadFavouriteAlbumsBox(strOwnerUsername,intFavAlbumBoxOrderBy);
			});
}
///////////////
// load list photo
$("#optlistPhoto").change(function () {						
	//intOptListPhoto =$("select[@name='optlistPhoto'] option:selected").attr("value");	
	$('#listphoto_id').nt_loadListPicture(strOwnerUsername);         
});
$("#optListPhotoPaging").change(function () {						
//	intOptListPhoto =$("select[@name='optlistPhoto'] option:selected").attr("value");	
	$('#listphoto_id').nt_loadListPicture(strOwnerUsername);         
});

// load list album
$("#optListAlbum").change(function () {	 			
//	intOptListAlbum =$("select[@name='optListAlbum'] option:selected").attr("value");	
	$('#listAlbum_content_id').nt_loadListAlbum(strOwnerUsername);         
			
});

$("#optListAlbum_Paging").change(function () {						
	//intOptListAlbum =$("select[@name='optListAlbum'] option:selected").attr("value");	
	$('#listAlbum_content_id').nt_loadListAlbum(strOwnerUsername);         
});

// load photo in album
$("#optPhotoInAlbum").change(function(){
	intOptPhoto = $("select[@name='optPhotoInAlbum'] option:selected").attr("value");
	$('#photo_in_album_id').nt_loadPhotoInAlbum(strOwnerUsername,intAlbum_id);	
	
});
$("#optPhotoInAlbumPaging").change(function(){
	intOptPhoto = $("select[@name='optPhotoInAlbum'] option:selected").attr("value");
	$('#photo_in_album_id').nt_loadPhotoInAlbum(strOwnerUsername,intAlbum_id);											  
});
// load favourite photo of homepage
$("#opt_photo_favourite_member_home").change(function () {			
	intOptFavPic =$("select[@name='opt_photo_favourite_member_home'] option:selected").attr("value");			
	$('#ym_pto_ptyt').nt_loadFavouritePicture(strOwnerUsername,intOptFavPic);         
});


//function registerFavouriteAlbumSelect()
//{
	$("#opt_list_favourite_album").change(function(){
	
		intOptFavAlbum = $("select[@name='opt_list_favourite_album'] option:selected").attr("value");
		$('#list_favourite_album_id').nt_loadFavouriteAlbums(strOwnerUsername,intOptFavAlbum);											  
	});
	$("#opt_paging_opt_list_favourite_album").change(function(){
		
		intOptFavAlbum = $("select[@name='opt_list_favourite_album'] option:selected").attr("value");
		$('#list_favourite_album_id').nt_loadFavouriteAlbums(strOwnerUsername,intOptFavAlbum);										  
	});
//}

$("#opt_list_favourite_photo").change(function(){
	intOptFavPhoto = $("select[@name='opt_list_favourite_photo'] option:selected").attr("value");
	$('#list_favourite_photo_id').nt_loadFavouritePictures(strOwnerUsername,intOptFavPhoto);										  
});
$("#opt_list_favourite_photo_paging").change(function(){
	intOptFavPhoto = $("select[@name='opt_list_favourite_photo'] option:selected").attr("value");
	$('#list_favourite_photo_id').nt_loadFavouritePictures(strOwnerUsername,intOptFavPhoto);										  
});



function pagingListPhoto(intPage)
{
	//intOptListPhoto =$("select[@name='optlistPhoto'] option:selected").attr("value");	
	$('#listphoto_id').nt_loadListPicture(strOwnerUsername,intPage); 	
}
function pagingListAlbum(intPage)
{
	//intOptListAlbum =$("select[@name='optListAlbum'] option:selected").attr("value");	
	$('#listAlbum_content_id').nt_loadListAlbum(strOwnerUsername,intPage); 
}

function pagingPhotoInAlbum(p_intAlbum_id, intPage)
{
	//intOptPhoto = $("select[@name='optPhotoInAlbum'] option:selected").attr("value");
	$('#photo_in_album_id').nt_loadPhotoInAlbum(strOwnerUsername,p_intAlbum_id,intPage);	
}

function pagingListFavouritePhoto(strOwnerUsername,intPage)
{
	//intOptFavPhoto = $("select[@name='opt_list_favourite_photo'] option:selected").attr("value");
	$('#list_favourite_photo_id').nt_loadFavouritePictures(strOwnerUsername,intPage);
}

function pagingListFavouriteAlbum(strOwnerUsername,intPage)
{
	//intOptFavAlbum = $("select[@name='opt_list_favourite_album'] option:selected").attr("value");
	
	$('#list_favourite_album_id').nt_loadFavouriteAlbums(strOwnerUsername,intPage);	
}

function showPopup(id,albumId,strOwnerUsername,strAlbumName)
{
	$('#'+id).nt_showPopup(id,albumId,strOwnerUsername,strAlbumName);
}
function showAlbumPasswordPopup(albumId)
{	

	$('#ym_popup_xacnhanpass1').nt_showPopupRegisterPassword(albumId);	
}

function checkAlbumPassword()
{
	strAlbumPass= $('#txtAlbumPassword').val();	
	intAlbumId = $('#AlbumId').val();	
	$('#ym_popup_xacnhanpass1').nt_checkAlbumPassword(strOwnerUsername,strAlbumPass,intAlbumId);
}
function refeshCaptcha()
{
	var e = document.getElementById("img_security");
	if(e)
	{
		intNumRand = parseInt(Math.random()*999999999999999);
		e.src = PHOTO+"/captcha.php?t=" + intNumRand;
	}
}
function checkEmail(strEmail,isArray)
{
	if(isArray==true)
	{
		arrEmail=strEmail.split(',');
		for(i=0;i<arrEmail.length;i++)
		{
			arrEmail[i]=arrEmail[i].replace(/^\s+|\s+$/g,"");
			if (arrEmail[i].search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1 && arrEmail[i]!="")
			{
				return false;
			}	
			else
			return true;
		}	
	}
	else
	{
		if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1)
		{
			return false;
		}
		else
		return true
	}
}
function checkFieldLength(element,limit)
{
	if(element.val().length >=limit)
	{
		strNew = element.val().substr(0,limit);
		element.val(strNew);
	}	
}
function errorSecurity(id)
{
		if(!$('div#security_error').is('#security_error'))
		{
			$('div#'+id).removeClass('normal_form');
			$('div#'+id).addClass('error_form');
			$('div#'+id).prepend('<div class="txt_error" id="security_error">Mã xác nhận không chính xác! </div>');
		}
		else
		{
			$('div#'+id).addClass('error_form');
		}
}
function send2Friend(itemId,ownerUsername,bolType)
{
	strReceiverEmail = $("#txt_receiver_email");
	strSendedContent = $("#txt_content_sendmail");
	intSecurity = $("#txt_security_sendmail");
	if($("div#id_sender_email").length!=0)
	{
		strSenderEmail = $("#txt_sender_email");
		if($.trim(strSenderEmail.val())=='' || !checkEmail(strSenderEmail.val(),false))
		{
			if(!$('div#id_sender_email').is('.error_form'))
			{
				$('div#id_sender_email').removeClass('normal_form');
				$('div#id_sender_email').addClass('error_form');
				$('div#id_sender_email').prepend('<div class="txt_error">Email người Gửi không hợp lệ </div>');
			}
			strSenderEmail.focus();
			return false;
		}
		else
		{
			$('div#id_sender_email').removeClass('error_form');
			$('div#id_sender_email').addClass('normal_form');
		}
		strSenderEmail = strSenderEmail.val();
	}
	else
	{
		strSenderEmail='';
	}
	if($.trim(strReceiverEmail.val())=='' || !checkEmail(strReceiverEmail.val(),true))
	{
		if(!$('div#id_receiver_email').is('.error_form'))
		{
			$('div#id_receiver_email').removeClass('normal_form');
			$('div#id_receiver_email').addClass('error_form');
			$('div#id_receiver_email').prepend('<div class="txt_error">Email người Nhận không hợp lệ </div>');
		}
		strReceiverEmail.focus();
		return false;
	}
	else
	{
		$('div#id_receiver_email').removeClass('error_form');
		$('div#id_receiver_email').addClass('normal_form');
	}
	if($.trim(intSecurity.val())=='')
	{
		if(!$('div#id_security_sendmail').is('.error_form'))
		{
			$('div#id_security_sendmail').removeClass('normal_form');
			$('div#id_security_sendmail').addClass('error_form');
			$('div#id_security_sendmail').prepend('<div class="txt_error id=security_error">Bạn chưa nhập mã xác nhận!</div>');
		}
		intSecurity.focus();
		return false;
	}
	else
	{
		$('div#id_security_sendmail').removeClass('error_form');
		$('div#id_security_sendmail').addClass('normal_form');
	}
	$('#ym_2cr').nt_sendToFriend(strSenderEmail,strReceiverEmail.val(),strSendedContent.val(),intSecurity.val(),itemId,ownerUsername,bolType);
}
function sendBadNote(albumId)
{
	strOptionBadNoteContent=$(".rad:checked").attr('id');
	strBadNoteContent = $("#txt_content_badnote");
	intSecurity = $("#txt_security_badnote");
	if($.trim(intSecurity.val())=='')
	{
		if(!$('div#id_security_badnote').is('.error_form'))
		{
			$('div#id_security_badnote').removeClass('normal_form');
			$('div#id_security_badnote').addClass('error_form');
			$('div#id_security_badnote').prepend('<div class="txt_error" id="security_error">Bạn chưa nhập mã xác nhận!</div>');
		}
		intSecurity.focus();
		return false;
	}
	else
	{
		$('div#id_security_badnote').removeClass('error_form');
		$('div#id_security_badnote').addClass('normal_form');
	}
	$('#ym_2cr').nt_sendBadNote(strOptionBadNoteContent,strBadNoteContent.val(),intSecurity.val(),albumId);
}
function setFavouriteAlbum(intAlbumId,albumName)
{
	$('#ym_2cr').nt_setFavouriteAlbum(intAlbumId,albumName);
}
function setHotAlbum(strAlbumId,strAlbumIdHot,strAlbumName)
{
	isHot=confirm('Bạn muốn chọn slideshow này làm slideshow nổi bật?');
	if(isHot)
	{
		$('#ym_2cr').nt_setHotAlbum(strAlbumId,strAlbumIdHot,strAlbumName);
	}
}
function autoPlay(effect,memberUsername,albumId)
{
	
	if($('#autoplay').attr('checked')==true)
	{
		$('#blog').val('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,40,0" align="middle" width="348" height="289"><param name="movie" value="'+STATIC +'images/flash/slideshow/20080703/slideshow.swf?xmlPath='+PHOTO+'/slideshow/' + memberUsername + '/' + albumId + '/' + effect +'.xml"/><param name="wmode" value="transparent" /><param name="allowscriptaccess" value="always" /><param name="allowfullscreen" value="true" /><param name="mAuto" value="true" /><embed width="348" height="289" wmode="transparent" allowscriptaccess="always" allowfullscreen="true" mAuto="true" quality="high" src="'+STATIC+'images/flash/slideshow/20080703/slideshow.swf?xmlPath=' + PHOTO + '/slideshow/' + memberUsername + '/' + albumId + '/' + effect + '.xml" type="application/x-shockwave-flash"/></object>');
	}
	else
	{
		$('#blog').val('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,40,0" align="middle" width="348" height="289"><param name="movie" value="'+STATIC +'images/flash/slideshow/20080703/slideshow.swf?xmlPath='+PHOTO+'/slideshow/' + memberUsername + '/' + albumId + '/' + effect +'.xml"/><param name="wmode" value="transparent" /><param name="allowscriptaccess" value="always" /><param name="allowfullscreen" value="true" /><param name="mAuto" value="false" /><embed width="348" height="289" wmode="transparent" allowscriptaccess="always" allowfullscreen="true" mAuto="false" quality="high" src="'+STATIC+'images/flash/slideshow/20080703/slideshow.swf?xmlPath=' + PHOTO + '/slideshow/' + memberUsername + '/' + albumId + '/' + effect + '.xml" type="application/x-shockwave-flash"/></object>');
	}
}
function goToTop()
{
	jQuery(function( $ ){
	$('#gototop').click(function(){
		$.scrollTo( 0, 700);					
		return false;
	});
	$('#gotocm').click(function(){
	$.scrollTo('#ym_writebl_inner', 700);					
		return false;
	});
})
}

//view photo
function sendComment()
{			
	//contentComment = $('#txtCommentPicture').val();
	contentComment = $.trim(tinyMCE.get('txt_write_comment').getContent());
	pictureId = $("#txtPictureId").val();
	commentReceiverId = $("#txtCommentReceiverId").val();
	
	if($.trim(contentComment)=="" || contentComment==lagStatusComment)
	{
		alert(lagStatusComment);
		$("#txt_write_comment").focus();
	}
	else
	{
		$("#commentContentPicture").nt_insertCommentPicture(contentComment,pictureId,commentReceiverId);
		tinyMCE.get('txt_write_comment').setContent('');
		//$("#txt_write_comment").val('');
		//alert(lagAddComment);
	}
}
function delPictureComment(id)
{
	$question = confirm(lagDelPicture);
	if($question==1)
	{
		$("#comment_"+id).nt_deleteCommentPicture(id);
		$("#comment_"+id).remove();
	}
}
function showPopupPicture(divId,pictureId,owner_username,strPictureTitle)
{
	$("#"+divId).nt_showPopupPicture(strPictureTitle,divId,pictureId,0,owner_username);	
}
function showPopupAddAlbum(divId,ownerId,pictureId,picturepath)
{
	$("#"+divId).nt_showPopupAddAlbum(divId,ownerId,pictureId,picturepath);	
}

function showPopupDowload(divId,picturepath)
{
	$("#"+divId).nt_showPopupDowload(divId,picturepath);	
}
function sendPictureBadNote(pictureId)
{
	strOptionBadNoteContent=$(".rad:checked").attr('id');
	strBadNoteContent = $("#txt_content_badnote");
	intSecurity = $("#txt_security_badnote");
	
	if($.trim(intSecurity.val())=='')
	{
		if(!$('div#id_security_badnote').is('.error_form'))
		{
			$('div#id_security_badnote').removeClass('normal_form');
			$('div#id_security_badnote').addClass('error_form');
			$('div#id_security_badnote').prepend('<div class="txt_error"  id="security">'+lagCapcha+'!</div>');
		}
		intSecurity.focus();
		return false;
	}
	else
	{
		$('div#security').empty();
		$('div#id_security_badnote').removeClass('error_form');
		$('div#id_security_badnote').addClass('normal_form');
	}
	$('#ym_2cr').nt_sendPictureBadNote(strOptionBadNoteContent,strBadNoteContent.val(),intSecurity.val(),pictureId);
}
function checkSecurityBadnote()
{
		if($('div#security2').length<=0)
		{
			$('div#id_security_badnote').removeClass('normal_form');
			$('div#id_security_badnote').addClass('error_form');
			$('div#id_security_badnote').prepend('<div class="txt_error" id="security2">'+lagReCapcha+'!</div>');
			intSecurity.focus();
			return false;
		}
		else
		{
			$('div#id_security_badnote').removeClass('error_form');
			$('div#id_security_badnote').addClass('normal_form');
		}
}
function dowloadPicture()
{
	intSecurity = $("#txtSecurityBadnote");
	picturPath = $("#picturePath");
	if($.trim(intSecurity.val())=='')
	{
		if(!$('div#id_security').is('.error_form'))
		{
			$('div#id_security').removeClass('normal_form');
			$('div#id_security').addClass('error_form');
			$('div#id_security').prepend('<div class="txt_error" id="security">Bạn chưa nhập mã xác nhận!</div>');
		}
		intSecurity.focus();
		return false;
	}
	else
	{	
		$('div#security').empty();
		$('div#id_security').removeClass('error_form');
		$('div#id_security').addClass('normal_form');
	}
	$('#ym_popup_download').nt_dowloadPicture(intSecurity.val(),picturPath.val());
}
function checkSecurityPicture()
{
		if($('div#security2').length<=0)
		{
			$('div#id_security').removeClass('normal_form');
			$('div#id_security').addClass('error_form');
			$('div#id_security').prepend('<div class="txt_error" id="security2">Mã xác nhận chưa hợp lệ!</div>');
			intSecurity.focus();
			return false;
		}
		else
		{
			$('div#id_security').removeClass('error_form');
			$('div#id_security').addClass('normal_form');
		}
}
function setHotPicture(pictureId,pictureName)
{
	$("#hotpicture").nt_setHotPicture(pictureId,pictureName);
}
function setFavoritePicture(pictureId,pictureName)
{
	$("#favoritePicture").nt_setFavoritePicture(pictureId,pictureName);
	$("#favoritePicture").empty();
	$("#favoritePicture").prepend('<a href="javascript:void(0);" class="ym_link">Yêu thích</a>');
}
function HighlightAllMsg(theField,msg) {
 var tempval=eval("document."+theField).select();
 var text = '';
	text = eval("document."+theField).value;
	$.copy(text);
	//alert(msg);
}
/************************/
function getEditor()
{
	tinyMCE.init({
		mode : "exact",
		elements : "txt_write_comment",
		theme : "advanced",
		entities : "",
		plugins : "inlinepopups,emotions,eBizImage,eBizIcon",
		theme_advanced_buttons1 : "mybutton,bold,italic,underline,justifyleft,justifycenter,justifyright,justifyfull,forecolor,emotions,eBizIcon,eBizImage,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "",	    
		theme_advanced_buttons3 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "none",
		theme_advanced_resizing : false,		
		content_css : "/js/tinymce/css/content.css",
		setup: function(ed) {        			
			ed.addButton('mybutton', {
				label : 'Viết bình luận',
				onclick : function() {
					
				}
			});
		}
	});
	
	
}
/************************/
