// JavaScript Document\
function album_detail(opname,album_id,wedid){
	
	var success = function(t){getAjaxAllPublicPhotosByPageCompleted(t);}
	var failure = function(t){loadFailed(t);}
	var url 	= "index.php";
	var pars 	= "op="+opname+".photos.viewalbum&id="+album_id+"&wdid="+wedid;
	
	var myAjax 	= new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});		
}
function getAjaxAllPublicPhotosByPageCompleted(t){ 
   $("ajax_output").innerHTML  = t.responseText;  
   FirstPhotoId =  $("PhotoRight_firstPhoto").value;
   getPublicAllPhotos_PhotoById(FirstPhotoId,'');
}

function add_comments(opname)
  {
	  
	   AlbumId = document.frmphotoleft.AlbumId.value;
	   Weddiingid = document.frmphotoleft.weddiingid.value;
	   Photo_id = document.frmphotoleft.photo_id.value;
	   comments = document.frmphotoleft.comments.value;
	   comments_name = document.frmphotoleft.comments_name.value;
	   comments_email = document.frmphotoleft.comments_email.value;
	  if(comments==""){
		  alert("Comments should not be empty!");
		  document.frmphotoleft.comments.focus();
		  return false;
	  }
	   if(comments_name==""){
		  alert("Name should not be empty!");
		  document.frmphotoleft.comments_name.focus();
		  return false;
	  }
	  if(!isEmailAddr(document.frmphotoleft.comments_email.value,"Email")){	     
		document.frmphotoleft.comments_email.focus();
		 return false;
	   }
	   
	    var success = function(t){getAjaxAllPhotoCommentsCompleted(t);}
		var failure = function(t){loadFailed(t);}
		var url 	= "ajax/photos.php";
		var pars 	= "op=insertcomments&process=postcomments&wedding_id="+Weddiingid+"&album_id="+AlbumId+"&photo_id="+Photo_id+"&comment_name="+comments_name+"&comment_email="+comments_email+"&comments="+comments;
		var myAjax 	= new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});		

	  
 
}
function getAjaxAllPhotoCommentsCompleted(t){ 

   $("comments_output").innerHTML  = t.responseText;  
   	document.frmphotoleft.comments.value="";
	document.frmphotoleft.comments_name.value="";
	document.frmphotoleft.comments_email.value="";

  
}

function delete_comments(deleteid,photoid)
  {
	  
	  
	    var success = function(t){getAjaxdeletePhotoCommentsCompleted(t);}
		var failure = function(t){loadFailed(t);}
		var url 	= "ajax/photos.php";
		var pars 	= "op=deletecomments&process=deletecomments&delid="+deleteid+"&phid="+photoid;
		var myAjax 	= new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});		

	  
  }

function getAjaxdeletePhotoCommentsCompleted(t){ 

   $("comments_output").innerHTML  = t.responseText;  
  
}



function getAllPublicPhotosByPage(page){
	
	sortby = document.frmallphotoslist.SortBy.value;
	
	sortdisplayname = document.frmallphotoslist.sortdisplayname.value;
		
	AlbumId = document.frmphotoleft.AlbumId.value;
	
	authors = document.frmallphotoslist.Authors.value;	
	
	var success = function(t){getAllPublicPhotosByPageCompleted(t);}
	var failure = function(t){loadFailed(t);}
	var url 	= "ajax/photos.php";
	var pars 	= "op=getallphotosright&p="+page+"&sortby="+sortby+"&Authors="+authors+"&WeddingId="+WeddingId+"&AlbumId="+AlbumId+"&sortdisplayname="+sortdisplayname;
	var myAjax 	= new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});		
}
function getAllPublicPhotosByPageCompleted(t){ 
   
   $("AllPhotoBoxId").innerHTML  = t.responseText;  
   FirstPhotoId =  $("PhotoRight_firstPhoto").value;
   getPublicAllPhotos_PhotoById(FirstPhotoId,'');
}






function showsortbylist(){
	$("sortphotolist").style.display  = 'block';
}
function hidesortbylist(){
	$("sortphotolist").style.display  = 'none';
}
function setsortbyvalue(SortByValue,SortByDisplayValue){
     document.frmallphotoslist.SortBy.value = SortByValue;

	 document.frmallphotoslist.sortdisplayname.value = SortByDisplayValue;
	 
	 hidesortbylist()
	 sortallPublicPhotos();
	 
	// document.frmallphotoslist.submit();
}

function sortallPublicPhotos(){
   if(document.frmallphotoslist.PhotoRight_currentpage){
		Page = document.frmallphotoslist.PhotoRight_currentpage.value;
	}
	else{
		Page = 1;
	}
   getAllPublicPhotosByPage(Page);
}


function openAuthorList(){
   $("authorlist").style.display ='block';
}
function closeAuthorList(){
   $("authorlist").style.display ='none';
}
cntAll=0;			
var CheckAllAuthor = function (ChkId)		{
		Total  =	document.frmallphotoslist.TotalAuthors.value;
		cntAll++;
		cntAll=cntAll%2;	
		if (cntAll == 1)	{
		document.getElementById(ChkId.id).src = "images/albumview/checked.gif";
		document.frmallphotoslist.AllAuthor.value = 'Yes';
		for (var i=0;i<Total;i++)	
			document.getElementById("authch"+i).src = "images/albumview/checked.gif"
		}
		else	{
		document.frmallphotoslist.AllAuthor.value = 'No';	
		document.getElementById(ChkId.id).src = "images/albumview/notchecked.gif";
		for (var i=0;i<Total;i++)	
			document.getElementById("authch"+i).src = "images/albumview/notchecked.gif"
	}
}

function setthisauth(ChkId){
	    Total  =	document.frmallphotoslist.TotalAuthors.value;
		ChkID=ChkId.id;
		chkSrc=ChkId.src;
		
		if (chkSrc.length > 0)	{
			chkSrc=chkSrc.substring(parseInt(chkSrc.lastIndexOf("/"))+parseInt(1),chkSrc.length);
		}	

		if (chkSrc=="checked.gif")		{
			document.getElementById(ChkID).src = "images/albumview/notchecked.gif";
		}
		else {
			document.getElementById(ChkID).src = "images/albumview/checked.gif";
		}
		ckcount =0;
		for (var i=0;i<Total;i++){	
			chkSrc=$("authch"+i).src;
			chkSrc=chkSrc.substring(parseInt(chkSrc.lastIndexOf("/"))+parseInt(1),chkSrc.length);
			if (chkSrc=="notchecked.gif"){
			   document.frmallphotoslist.AllAuthor.value = 'No';	
			   document.getElementById("allauthch").src = "images/albumview/notchecked.gif";
			   break;
			}
			else{
			   ckcount++;
			}
				
		}
		/*if(ckcount == Total){
			document.frmallphotoslist.AllAuthor.value = 'Yes';	
			document.getElementById("allauthch").src = "images/photos/checked.gif";
		}*/
}
function setauthsearch(){
   Total  =	document.frmallphotoslist.TotalAuthors.value;
   StrIds =  '';
   for (var i=0;i<Total;i++){	
		chkSrc=$("authch"+i).src;
		chkSrc=chkSrc.substring(parseInt(chkSrc.lastIndexOf("/"))+parseInt(1),chkSrc.length);
		if (chkSrc=="checked.gif"){
		   StrIds += $("authvalue"+i).value +',';
		}
			
	}
	if(StrIds == ""){
	     alert("Select atleast one author");
		 return false;
	}
	
	if(document.frmallphotoslist.AllAuthor.value == "Yes"){
		document.frmallphotoslist.Authors.value = 'all';
	}
	else{
		document.frmallphotoslist.Authors.value = StrIds;
	}	
    closeAuthorList();
	
	Page = 1;	
	getAllPublicPhotosByPage(Page);
	//document.frmallphotoslist.submit();	
}
function getAllPhotos_PhotoById(Id,action){
	if(action == 'next'){
		CurrIdent = document.frmphotoleft.CurrentPreviewId.value;
		LastPhotoId =  $("PhotoRight_lastPhoto").value;
		if(CurrIdent == LastPhotoId){
		    Page =1;
			if(document.frmallphotoslist.PhotoRight_currentpage){
				Page = parseInt(document.frmallphotoslist.PhotoRight_currentpage.value)+1;
			}
			url = PREVNEXTURL+"PhotoId="+Id+"&p="+Page;
		    window.location.href = url;
		}
		else{
		   url = PHOTOURL+"PhotoId="+Id;
		   window.location.href = url;
 		}
	}
	if(action == 'pre'){
		CurrIdent = document.frmphotoleft.CurrentPreviewId.value;
		FirstPhotoId =  $("PhotoRight_firstPhoto").value;
		if(CurrIdent == FirstPhotoId){
		    Page =1;
			if(document.frmallphotoslist.PhotoRight_currentpage){
				Page = parseInt(document.frmallphotoslist.PhotoRight_currentpage.value)-1;
			}
			url = PREVNEXTURL+"PhotoId="+Id+"&p="+Page;
		    window.location.href = url;
		}
		else{
		   url = PHOTOURL+"PhotoId="+Id;
		   window.location.href = url;
 		}
	}	
}
var ThumbLst;
function CngClass(obj){
	 obj=document.getElementById(obj);
	 if (ThumbLst) ThumbLst.className='photo-all-thumb-normal';
	 obj.className='photo-all-thumb-over';
	 ThumbLst=obj;
}
function downloadphoto(){
	CurrIdent = document.frmphotoleft.CurrentPreviewId.value;
	window.location.href = 'downphoto.php?op='+WebUrl+'&id='+CurrIdent;
}
function showratingoption(){
		$("OverImgDiv").style.display = 'block';
		$("ratecontent").style.display = 'block';
}
function hideratingoption(){
		$("OverImgDiv").style.display = 'none';
		$("ratecontent").style.display = 'none';
}
/*function ratethispicture(){
	document.frmphotoleft.fAction.value = 'ratethis';
	document.frmphotoleft.submit();
}
*/
function getAllphotosForSlideshow(){
    
	AlbumId  = document.frmphotoleft.AlbumId.value;	
	
	sortby = document.frmallphotoslist.SortBy.value;
	
	authors = document.frmallphotoslist.Authors.value;
			
    var success = function(t){getAllphotosForSlideshowCompleted(t);}	
	var failure = function(t){loadFailed(t);}
	var url 	=  SITEGLOBALPATH+"public/ajax/photos.php";
	var pars 	= "op=getalbumviewxmlforslideshow"+"&SortBy="+sortby+"&Authors="+authors+"&AlbumId="+AlbumId+"&WeddingId="+WeddingId;
	var myAjax 	= new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});
}
var AllPhotos_SlidePath = new Array();
var AllPhotos_SlidePathCompleted = '';
function getAllphotosForSlideshowCompleted(t){
	var objXML 			= t.responseXML;
	objElements = objXML.getElementsByTagName("Photo");
	objNode     = objElements.length;
	
	for (var iNode = 0; iNode < objNode; iNode++) {
         AllPhotos_SlidePath[iNode]     		= objXML.getElementsByTagName("NormalPath")[iNode].childNodes[0].nodeValue;
	}
	AllPhotos_SlidePathCompleted = 'yes'; 
	//alert(objLigt.start());
	objLigt.start();
	StartSlideSession = 0;
	CurrPos = document.frmphotoleft.CurrentLeftPhotoCount.value - 1;
	objLigt.changeImage(CurrPos);
}
function downloadalbum(id){
	window.location.href = 'zipdownload.php?op=album&id='+id;
}


/*Downloading in  Album in Split done by sudhakar  */
function downloadpublicalbumsplit(objForm){
	 id = objForm.SeletedPublicAlbumId.value;
	 curobj = "albumdown_id";
	 	
     var divPos = new ElementPosition(curobj); 
	 xpos = divPos.x;
	 ypos = divPos.y;
	 xpos = xpos -500;
	 ypos = ypos -50;
	 
	 document.getElementById(TransLayerId).style.left  = xpos+'px';
	 document.getElementById(TransLayerId).style.top  = ypos+'px';
	 strContent  = '<div class="transparent-layer-loading" style="width:250px"><img src="images/spinner_grey.gif" align="absmiddle" > please wait a moment to get it..</div>'; 
	 document.getElementById(TransLayerId).innerHTML= strContent ;	 
	 document.getElementById(TransLayerId).style.display="block";
	 
	 var success = function(t){downloadpublicalbumsplitCompleted(t,curobj);}
	 var failure = function(t){loadFailed(t);}
	 var url 	= "ajax/form.php";
	 var pars 	= "op=downloadalbumsplit&album_id="+id;
	 var myAjax 	= new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});
}
function downloadpublicalbumsplitCompleted(t,curobj){
	strContent = t.responseText
	document.getElementById(TransLayerId).innerHTML= strContent ;	 
	document.getElementById(TransLayerId).style.display="block";
}
function downloadsplitphotos(Ids,index){
	window.location.href = 'zipdownload.php?op=splitalbum&ids='+Ids+"&index="+index;
}


function isEmailAddr(email,Label) {
	
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)){
return (true)
}
alert("Invalid "+Label+" Address! Please re-enter.")
return (false)
}
function isEmailAddr1(email) {
	
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)){
return (true)
}

return (false)
}

/*End*/




