var DELETE_PHOTO     = 'Are you sure you want to delete this photo?';
  

//! Pagination
function pagination(base_url,keyword,show_from){           
    var sort_by = document.getElementById('sort_by').value;
    if(sort_by == 'popular'){
	    var popular_str = document.getElementById('popular_str').value;
	}
    var postData = 'keyword='+keyword+'&sort_by='+sort_by+'&pagination=y'+'&show_from='+show_from+'&popular_str='+popular_str;    
    if(keyword == ''){

	  jQuery.post(url,postData,callback_pagination_Jquery);	    
    }
    else{
      jQuery.post(url,postData,callback_pagination_Jquery);	    
    }
        if(env_value == 'Online')
	{
	    pageTracker._trackPageview(url);
	}
 
 }
//! Show Photos
function showPhotos(base_url,sort_by,is_gallery){ 
    var url_vars_id = document.getElementById('url_vars_id').value;
    var postData = 'sort_by='+sort_by+'&url_vars_id='+url_vars_id;
    if(is_gallery=='yes'){
      var url = base_url+'ajax/photos/_gallery';
      jQuery.post(url,postData,callback_photos_Jquery);	    
    }
    else{
      var url = base_url+'ajax/photos/_show_all'; 
      jQuery.post(url,postData,callback_photos_Jquery);	    
    }
     
    if(env_value == 'Online')
	{
	    pageTracker._trackPageview(url);
	}
}
//! Pagination
function showMyPhotos(base_url,sort_by,is_gallery){           
  document.getElementById('photo_sort_by').value = sort_by;
  document.frm_photos.submit();
}
//! Show Public Photos
function showPublicPhotos(base_url,sort_by){
  var postData = 'sort_by='+sort_by;
  var url = base_url+'ajax/photos/_public_photos_all' ;
  jQuery.post(url,postData,callback_photos_Jquery);	    
  
    if(env_value == 'Online')
	{
	    pageTracker._trackPageview(url);
	}


}

//! Show Edit Photos
function showEditPhoto(base_url,photo_id,sort_by,show_from,page_from){           
  var postData = 'photo_id='+photo_id+'&sort_by='+sort_by+'&show_from='+show_from+'&page_from='+page_from;
  var url = base_url+'ajax/photos/_show_edit_photo' ;
  jQuery.post(url,postData,callback_show_edit_photo_Jquery);	    
   if(env_value == 'Online')
	{
	    pageTracker._trackPageview(url);
	}
  

}
//! cancel Edit Photos
function cancelEditPhoto(base_url,photo_id,sort_by,show_from,page_from){           
  var postData = 'photo_id='+photo_id+'&sort_by='+sort_by+'&show_from='+show_from+'&pagination=y'+'&cancel_edit=y';
  if(page_from == '_landing_photo'){
    var url = base_url+'ajax/photos/_landing_photo';
    jQuery.post(url,postData,callback_cancel_show_edit_photo_Jquery);	    
  }
  else{
    var url = base_url+'ajax/photos/_show_all';
    jQuery.post(url,postData,callback_cancel_show_edit_photo_Jquery);
  }
  
 if(env_value == 'Online')
	{
	    pageTracker._trackPageview(url);
	}
  
  
}
//! Show Add to Album
function showAddToAlbumPhoto(base_url,photo_id,sort_by,show_from,page_from){           
  var postData = 'photo_id='+photo_id+'&sort_by='+sort_by+'&show_from='+show_from+'&page_from='+page_from;
  var url = base_url+'ajax/photos/_show_add_to_album_photo' ;
  jQuery.post(url,postData,callback_show_add_to_album_photo_Jquery);	    
 if(env_value == 'Online')
	{
	    pageTracker._trackPageview(url);
	}
 

}
//! cancel show Add to Album Photos
function cancelAddToAlbumPhoto(base_url,photo_id,sort_by,show_from,page_from){           
  var postData = 'photo_id='+photo_id+'&sort_by='+sort_by+'&show_from='+show_from+'&pagination=y';
  var url = base_url+'ajax/photos/_landing_photo';
  jQuery.post(url,postData,callback_cancel_show_add_to_album_photo_Jquery);	    

 if(env_value == 'Online')
	{
	    pageTracker._trackPageview(url);
	}

}
//! Edit Photos
function editPhoto(base_url,photo_id,sort_by,show_from){     
  var title = document.getElementById('title').value;
  var desc = document.getElementById('desc').value;
  var check = document.getElementById('check').checked;
  var checked_val = '';
  if(trim(title) == ''){
    alert("Please enter valid title.");
  }
  if(check){
    checked_val = '1';
  }
  var tags = document.getElementById('tags').value;
  var prev_tags = document.getElementById('prev_tags').value;
  var photo_gallery = document.getElementById('photo_gallery').value;
  var select_photo_gallery = document.getElementById('select_photo_gallery').value;
  var prev_gallery = document.getElementById('prev_gallery').value;
  var postData = 'photo_id='+photo_id+'&sort_by='+sort_by+'&show_from='+show_from+'&title='+title+'&desc='+desc+'&tags='+tags+'&check='+checked_val+'&pagination=y&photo_gallery='+photo_gallery+'&select_photo_gallery='+select_photo_gallery+'&prev_gallery='+prev_gallery+'&prev_tags='+prev_tags;
  var url = base_url+'ajax/photos/_edit_photo';
  jQuery.post(url,postData,callback_edit_photo_Jquery);	    
  pageTracker._trackPageview(url);
  if(trim(title) != '' && strip_tags(title)){
    var t = setTimeout("editPhotoToshowAll()",1000);
  }
}
function editPhotoToshowAll(){
  window.location = system_base_url + "photos/_show_all";
}
//! Add Album from photo landing 
function addToAlbumPhoto(base_url,photo_id,sort_by,show_from){           
  var select_photo_gallery = document.getElementById('select_photo_gallery').value;
  var prev_gallery = document.getElementById('prev_gallery').value;
  var postData = 'photo_id='+photo_id+'&sort_by='+sort_by+'&show_from='+show_from+'&pagination=y&select_photo_gallery='+select_photo_gallery+'&prev_gallery='+prev_gallery;
  var url = base_url+'ajax/photos/_add_to_album_photo';
  jQuery.post(url,postData,callback_add_to_album_photo_Jquery);	    
 
   if(env_value == 'Online')
	{
	    pageTracker._trackPageview(url);
	}


}
//! Delete Photos
function deletePhoto(base_url,photo_id,sort_by,show_from){           
  if(confirm(DELETE_PHOTO)){	   
    var postData = 'photo_id='+photo_id+'&sort_by='+sort_by+'&show_from='+show_from+'&pagination=y'+'&delete_photo=y';
    var url = base_url+'ajax/photos/_delete_photo';
    jQuery.post(url,postData,callback_delete_photo_Jquery);	    
    
       if(env_value == 'Online')
	{
	    pageTracker._trackPageview(url);
	}


  }
}
//! Delete Photos
function deletePhotoFromAlbum(base_url,photo_id,photo_type,show_from){           
  if(confirm(DELETE_PHOTO)){	   
    var postData = 'photo_id='+photo_id+'&photo_type='+photo_type+'&show_from='+show_from+'&pagination=y'+'&delete_photo=y';
    var url = base_url+'ajax/photos/_delete_photo_album';
    jQuery.post(url,postData,callback_delete_photo_album_Jquery);	    

    if(env_value == 'Online')
	{
	    pageTracker._trackPageview(url);
	}
    
    
  }
}
//! Method to check presence of an element inside array
/*!
 * \param array arr and value
 * \ checks presence of value in array arr
 * \return true on success else false 
 */
 function inArray_photo(arr, value){
   var i;
   for (i=0; i < arr.length; i++){
     if (arr[i] === value){
       return true;
     }
   }
   return false;
 }
function savePhotoReportAbuse1(){
  var selected_types = '';
  var comma = '';   
  var select_action = false;
  var abuse_types = document.photo_abuse_form.abuse_type;
  for(var i=0;i<6;i++){
    if(abuse_types[i].value != ''){
      if(abuse_types[i].checked){
	selected_types = selected_types + comma + abuse_types[i].value;			    
	comma = ',';	
	select_action = true;
      }
    }
  }
  if(select_action == false){
    document.getElementById('abuse_error_msg').innerHTML = 'Please select the reason for your complaint.';
  }
  else{	
    var photo_abuse_id = document.getElementById('photo_abuse_id_main').value;
    var photo_user_id = document.getElementById('photo_user_id_main').value;
    var postData ='abuse_types='+selected_types+'&photo_abuse_id='+photo_abuse_id+'&photo_user_id='+photo_user_id;
    var url = system_base_url+'ajax/photos/_abuse_photo/' ;
    jQuery.post(url,postData,callback_photo_abuse_Jquery);	    
   
    if(env_value == 'Online')
	{
	    pageTracker._trackPageview(url);
	}
   

  }
}
function deletePhotoComments(comment_id){
  var photo_id = document.getElementById('photo_post_id').value;
  var photo_comment_id = comment_id;
  var postData ='comment_id='+photo_comment_id+'&photo_post_id='+photo_id;
  var url =  system_base_url+'ajax/photos/_delete_photo_comment/' ;
  jQuery.post(url,postData,callback_delete_photo_comment_Jquery);	    

  if(env_value == 'Online')
      {
	  pageTracker._trackPageview(url);
      }
  
}
function savePhotoCommentsReportAbuse(){
  var selected_types = '';
  var comma = '';   
  var select_action = false;
  var abuse_types = document.photos_comments_abuse_form.abuse_type;
  var login_user_id = document.getElementById('login_user_id').value;
  
  for(var i=0;i<6;i++){
    if(abuse_types[i].value != ''){
      if(abuse_types[i].checked){
	selected_types = selected_types + comma + abuse_types[i].value;			    
	comma = ',';	
	select_action = true;
      }
    }
  }
  
  if(login_user_id == '' || isNaN(login_user_id)){
    document.getElementById('abuse_comments_error_msg').innerHTML = ERROR_LOGIN_REQUIRED;
  }
  else if(select_action == false){
    document.getElementById('abuse_comments_error_msg').innerHTML = 'Please select the reason for your complaint.';
  }
  else {	 
    var abuse_id = document.getElementById('abuse_id').value;
    var abuse_user_id = document.getElementById('abuse_user_id').value;
    var login_user_id = document.getElementById('login_user_id').value;
    var postData ='abuse_types='+selected_types+'&abuse_id='+abuse_id+'&abuse_user_id='+abuse_user_id+'&login_user_id='+login_user_id;
    var url =  system_base_url+'ajax/photos/_abuse_photo_comments/' ;
    jQuery.post(url,postData,callback_photos_comments_abuse_Jquery);	    
    
     if(env_value == 'Online')
      {
	  pageTracker._trackPageview(url);
      }
  
  }
}
function deleteFavPhoto(id,profileid){
  if(confirm(ERROR_DELETE_FAVS_PHOTO)){
    var show_from = document.getElementById('favs_from').value;
    var postData = 'photo_id='+id+'&pagination=y&favs_delete=yes'+'&show_from='+show_from;    
    var url = system_base_url+'photos/_delete_fav_photo/' ;
    jQuery.post(url,postData,callback_delete_fav_photo_Jquery);	    
 
    if(env_value == 'Online')
      {
	  pageTracker._trackPageview(url);
      }
    
 
  }
}

// Function to remove HTML entities from String
function strip_tags(text){
  return text.replace(/<\/?[^>]+>/gi, '');
}

//CALLBACK
function callback_photos_comments_abuse_Jquery(data){
  if(data == 701){
    var abuse_id = document.getElementById('abuse_id').value;
    document.getElementById('abusecommentpopup_'+abuse_id).innerHTML = 'Under Review';
  }else if(data != ''){
    displayErrorCommon('error_photo_comments',data,'error');
  }
  hidePhotoCommentsPopup1();
  var success_message = 'This photo comment has been reported as abusive. It is currently under review.'
    document.getElementById('photo_success_message').innerHTML = success_message;
  $(function() {
      $("#photo_dialog4").dialog({
	bgiframe: true,
	    title:'Report Abuse',
	    width:600,
	    modal: true,
	    draggable: true,
	    resizable:false
	    });
    });
}
function hidePhotoCommentsPopup1(){
  $("#photo_dialog2").dialog('destroy');
}

function callback_delete_photo_comment_Jquery(data){
  document.getElementById("photo_landing_comments").innerHTML = data;        
}
function callback_photo_abuse_Jquery(data){
  if(data == 701){
    document.getElementById('report_abuse_photo').innerHTML = '<a href="#" class="vertmiddle"><img src="/storage/image/default/icon/ico-under-review.gif" width="25" height="25" border="0" alt="" class="vertmiddle zero"> <b>Under Review</b></a><br class="spacer3">';
  }
  hidePhotoPopup();
  var success_message = 'This photo has been reported as abusive. It is currently under review.';
  document.getElementById('photo_success_message').innerHTML = success_message;
  $(function() {
      $("#photo_dialog4").dialog({
	bgiframe: true,
	    title:'Report Abuse',
	    width:600,
	    modal: true,
	    draggable: true,
	    resizable:false
	    });
    });
}
function hidePhotoPopup()
{
 $("#photo_dialog1").dialog('destroy');
}
function hidePhotoPopup4()
{
 $("#photo_dialog4").dialog('destroy');
}
function callback_delete_photo_Jquery(data){
  document.getElementById('photos_loading').style.display = 'none';
  document.getElementById("photos_loading").innerHTML = '';
  document.getElementById("photos").innerHTML = data;    		
}
function callback_delete_photo_album_Jquery(data){
    var album_id = document.getElementById('selected_album_id').value;
    var profile_id = document.getElementById('album_profile_id').value;
    window.location.href = system_base_url+'photos/'+profile_id+'/_albums_view/'+album_id;
}

function callback_add_to_album_photo_Jquery(data){
  document.getElementById('photos_loading').style.display = 'none';
  document.getElementById("photos_loading").innerHTML = '';
  document.getElementById("photos").innerHTML = data;  
}
function callback_edit_photo_Jquery(data){
  document.getElementById('photos_loading').style.display = 'none';
  document.getElementById("photos_loading").innerHTML = '';
  document.getElementById("photos").innerHTML = data;  
}
function callback_cancel_show_add_to_album_photo_Jquery(data){
  document.getElementById("photos").innerHTML = data;  
}
function callback_show_add_to_album_photo_Jquery(data){
  document.getElementById("photos").innerHTML = data;  
}
function callback_cancel_show_edit_photo_Jquery(data){
  document.getElementById("photos").innerHTML = data;  
}
function callback_show_edit_photo_Jquery(data){
  document.getElementById("photos").innerHTML = data;  
}
function callback_photos_Jquery(data){
  document.getElementById('photos_loading').style.display = 'none';
  document.getElementById("photos_loading").innerHTML = '';
  document.getElementById("photos").innerHTML = data;    		
}
function callback_pagination_Jquery(data){
  document.getElementById('photos_loading').style.display = 'none';
  document.getElementById("photos_loading").innerHTML = '';
  document.getElementById("photos").innerHTML = data;    		
}
function callback_delete_fav_photo_Jquery(data){
  document.getElementById("photos").innerHTML = data;    		
}
function callback_all_sizes_photo_Jquery(data){
  document.getElementById('photos_loading').style.display = 'none';
  document.getElementById("photos_loading").innerHTML = '';
  document.getElementById("photos").innerHTML = data;    		
}
//OLD FUNCTION

//! Function to show / hide div - active / inactive div
function showHideLink(sort_by){
  if(sort_by == 'recent')
    {
      var show_div = 'recently_added_active,most_popular_inactive,most_viewed_inactive,most_commented_inactive';
      var hide_div = 'recently_added_inactive,most_popular_active,most_viewed_active,most_commented_active';		
    }
  else if(sort_by == 'popular')
    {
      var show_div = 'recently_added_inactive,most_popular_active,most_viewed_inactive,most_commented_inactive';
      var hide_div = 'recently_added_active,most_popular_inactive,most_viewed_active,most_commented_active';		
    }
  else if(sort_by == 'viewed')
    {
      var show_div = 'recently_added_inactive,most_popular_inactive,most_viewed_active,most_commented_inactive';
      var hide_div = 'recently_added_active,most_popular_active,most_viewed_inactive,most_commented_active';		
    }
  else if(sort_by == 'comment')
    {
      var show_div = 'recently_added_inactive,most_popular_inactive,most_viewed_inactive,most_commented_active';
      var hide_div = 'recently_added_active,most_popular_active,most_viewed_active,most_commented_inactive';		
    }
  else 
    {
      var show_div = 'recently_added_active,most_popular_inactive,most_viewed_inactive,most_commented_inactive';
      var hide_div = 'recently_added_inactive,most_popular_active,most_viewed_active,most_commented_active';
    }
  
  var show_arr = new Array();    
  show_ids = show_div.split(',');       
  var len = show_ids.length; 
  var hide_arr = new Array();    
  hide_ids = hide_div.split(',');           
  
  for(var i=0;i<len;i++)	
    {
      var s = show_ids[i];
      var h = hide_ids[i];
      document.getElementById(s).style.display = 'block';
      document.getElementById(h).style.display = 'none';
    }
}
//! Function to show various sizes images
function showImage(image_path,image_name)
{
  if(image_name == 'thumb')
    {
      var show_div = 'inactive_thumb,active_gallery,active_medium,active_original';
      var hide_div = 'active_thumb,inactive_gallery,inactive_medium,inactive_original';		
    }
  else if(image_name == 'gallery')
    {
      var show_div = 'active_thumb,inactive_gallery,active_medium,active_original';
      var hide_div = 'inactive_thumb,active_gallery,inactive_medium,inactive_original';		
    }
    else if(image_name == 'medium')
      {
	var show_div = 'active_thumb,active_gallery,inactive_medium,active_original';
	var hide_div = 'inactive_thumb,inactive_gallery,active_medium,inactive_original';		
      }    
    else if(image_name == 'original')
      {
	var show_div = 'active_thumb,active_gallery,active_medium,inactive_original';
	var hide_div = 'inactive_thumb,inactive_gallery,inactive_medium,active_original';		
	}    
    else 
      {
	var show_div = 'active_thumb,active_gallery,active_medium,inactive_original';
	var hide_div = 'inactive_thumb,inactive_gallery,inactive_medium,active_original';		
	}
  document.getElementById('img_path').src = image_path;
  var show_arr = new Array();    
  show_ids = show_div.split(',');       
  var len = show_ids.length; 
  var hide_arr = new Array();    
    hide_ids = hide_div.split(',');           
    
    for(var i=0;i<len;i++)	
      {
	var s = show_ids[i];
	var h = hide_ids[i];
	document.getElementById(s).style.display = 'block';
	document.getElementById(h).style.display = 'none';
      }
}
//! Function to show selected left link
function showLeftLink(selected_link)
{
  if(selected_link == 'my_photo')
	{
	  var show_div = 'my_photos_inactive,public_photos_active';
	  var hide_div = 'my_photos_active,public_photos_inactive';		
	}
  else if(selected_link == 'public_photo')
    {
      var show_div = 'my_photos_active,public_photos_inactive';
      var hide_div = 'my_photos_inactive,public_photos_active';		
    }    
  else 
    {
      var show_div = 'my_photos_inactive,public_photos_active';
      var hide_div = 'my_photos_active,public_photos_inactive';			    
    }
  
  var show_arr = new Array();    
  show_ids = show_div.split(',');       
  var len = show_ids.length; 
  var hide_arr = new Array();    
  hide_ids = hide_div.split(',');           
  
  for(var i=0;i<len;i++)	
    {
      var s = show_ids[i];
      var h = hide_ids[i];
      document.getElementById(s).style.display = 'block';
      document.getElementById(h).style.display = 'none';
    }
}
//! Function to show various sizes images
function showImage(image_path,image_name)
{
  if(image_name == 'thumb')
    {
      var show_div = 'inactive_thumb,active_gallery,active_medium,active_original';
      var hide_div = 'active_thumb,inactive_gallery,inactive_medium,inactive_original';		
    }
  else if(image_name == 'gallery')
    {
      var show_div = 'active_thumb,inactive_gallery,active_medium,active_original';
      var hide_div = 'inactive_thumb,active_gallery,inactive_medium,inactive_original';		
    }
  else if(image_name == 'medium')
    {
      var show_div = 'active_thumb,active_gallery,inactive_medium,active_original';
      var hide_div = 'inactive_thumb,inactive_gallery,active_medium,inactive_original';		
    } 
  else if(image_name == 'original')
    {
      var show_div = 'active_thumb,active_gallery,active_medium,inactive_original';
      var hide_div = 'inactive_thumb,inactive_gallery,inactive_medium,active_original';		
    }    
  else 
    {
      var show_div = 'active_thumb,active_gallery,active_medium,inactive_original';
      var hide_div = 'inactive_thumb,inactive_gallery,inactive_medium,active_original';		
    }
  document.getElementById('img_path').src = image_path;
  alert(image_path);    
  var show_arr = new Array();    
  show_ids = show_div.split(',');       
  var len = show_ids.length; 
  var hide_arr = new Array();    
  hide_ids = hide_div.split(',');           
  
  for(var i=0;i<len;i++)	
    {
      var s = show_ids[i];
      var h = hide_ids[i];
      document.getElementById(s).style.display = 'block';
      document.getElementById(h).style.display = 'none';
    }
}

//! Show Photo By Size
function bigSizesPhoto(base_url,photo_id,sort_by,show_from,size)
{           
  var url_vars_id = document.getElementById('url_vars_id').value;
  var post_data = 'photo_id='+photo_id+'&sort_by='+sort_by+'&show_from='+show_from+'&pagination=y'+'&url_vars_id='+url_vars_id+'&size='+size;
  if(url_vars_id != '')
    {
      var url =  base_url+'ajax/photos/'+url_vars_id+'/_big_sizes_photo';
      jQuery.post(url,postData,callback_big_sizes_photo_Jquery);	    
    }
  else
    {
      var url =base_url+'ajax/photos/_big_sizes_photo' ;
      jQuery.post(url,postData,callback_big_sizes_photo_Jquery);	    
    }

     if(env_value == 'Online')
      {
	  pageTracker._trackPageview(url);
      }
 
 
  
}


//! Show Photo By Size
function allSizesPhoto(base_url,photo_id,sort_by,show_from)
{           
  var url_vars_id = document.getElementById('url_vars_id').value;
  var post_data = 'photo_id='+photo_id+'&sort_by='+sort_by+'&show_from='+show_from+'&pagination=y'+'&url_vars_id='+url_vars_id;
  if(url_vars_id != '')
    {
      var url = base_url+'ajax/photos/'+url_vars_id+'/_all_sizes_photo' ;
      jQuery.post(url,postData,callback_all_sizes_photo_Jquery);	    
    }
  else
    {
      var url = base_url+'ajax/photos/_all_sizes_photo' ;
      jQuery.post(url,postData,callback_all_sizes_photo_Jquery);	    
    }
 
      if(env_value == 'Online')
      {
	  pageTracker._trackPageview(url);
      }
 
 
  
}
//! Pagination New
function paginationNew(base_url,keyword,show_from){           
    document.getElementById('keyword').value = keyword;
    document.getElementById('pagination').value = 'y';
    document.getElementById('show_from').value = show_from;
    document.frm_pagination.submit();
}
//! Show Edit Photos
function showEditPhotoJquery(photo_id, param_module){
  if(param_module == "album"){
      var url = system_base_url+'photos/_show_edit_photo/album';
    }
  else{
     var url = system_base_url+'photos/_show_edit_photo/';
    }           
  document.getElementById('selected_edit_id').value = photo_id;
  document.getElementById('frmGallery').action = url;
  document.frmGallery.submit();
}
//! Pagination New
function editPhotos(base_url,photo_id,sort_by,show_from){           
    var title = document.getElementById('title').value;
    var desc = document.getElementById('desc').value;
    var check = document.getElementById('check').checked;
    var checked_val = '';
    if(trim(title) == '')
	{
	    alert("Please enter valid title.");
	}
    if(check)
	{
	    document.getElementById('check').value = 1;
	}
    document.frm_edit_photo.submit();
}
function deleteAlbum(album_id){
    var profile_id = document.getElementById('album_profile_id').value;           
    if(confirm(ERROR_DELETE_ALBUM))
	{
	    window.location.href = system_base_url+'photos/'+profile_id+'/_album_delete/'+album_id;
	    return;
	}
}