// ----------------------------------------------------------------------------- //
// --------------------------- RSVP section :: BOF ----------------------------- //
// ----------------------------------------------------------------------------- //
// function to post RSVP

/*
function postRSVP(pSocialId, rsvpDbStatusOfAttandee, pLoggedInUserId, socialType)
{
	if(socialType == 'usersocial')
	{
		var rsvpVal = get_rsvp_radio_value();
	} else {
		var rsvpVal = jQuery('#idOptThere').value;		
	}

	if(pLoggedInUserId <= 0 || pLoggedInUserId == '')
	{
		jQuery('#errorDivSameStatus').style.display = 'none';
		jQuery('#divPostRSVPMsg').style.display = 'none';			
		jQuery('#errorDivOptions').style.display = 'none';
		jQuery('#errorLoginDivOptions').style.display = 'block';
		return false;
	}

	if(socialType == 'usersocial' && rsvpVal == 0)
	{
		//Please select any one option
		jQuery('#errorDivOptions').style.display = 'block';
		return false;
	}
	
	if(pLoggedInUserId > 0 && rsvpDbStatusOfAttandee == rsvpVal)
	{
		jQuery('#errorDivOptions').style.display = 'none';		
		jQuery('#errorLoginDivOptions').style.display = 'none';		
		jQuery('#errorDivSameStatus').style.display = 'block';
		return false;		
	}

	if(rsvpVal == 1)
	{
		document.frmRSVP.submit();
	}
	else
	{
	var params = "optThere="+rsvpVal+"&socialId="+pSocialId+"&pageOp=postwithoutpayment";
	//alert(params);
	var ajax = new Ajax.Updater('divPostRSVPMsg',
								'ajax/postRSVP.html',
								{
								method: 'post',
								parameters: params,
								onSuccess: showMessage								
								});
	}
}	



function showMessage()
{
	jQuery('#errorDivOptions').style.display = 'none';
	jQuery('#errorDivSameStatus').style.display = 'none';
	jQuery('#errorLoginDivOptions').style.display = 'none';
	jQuery('#divPostRSVPMsg').style.display = 'block';
    // setTimeout("window.location.reload(true);",1000);
}


// validation for radio buttons
function get_rsvp_radio_value()
{
	var cnt = -1;
	for (var i=0; i < document.frmRSVP.optThere.length; i++)
   	{
		if (document.frmRSVP.optThere[i].checked)
      	{
      	var rad_val = document.frmRSVP.optThere[i].value;
		cnt++;
      	}
   	}
	
	if(cnt == -1)
	{
		rad_val = 0;
	}
	return rad_val;
}*/


// ----------------------------------------------------------------------------- //
// ------------------------ Comment section :: BOF ----------------------------- //
// ----------------------------------------------------------------------------- //
//function to post comments

function postComment(pSocialId, pSocialUUID)
{
	jQuery('#divPostCommentMsg').show();
	var comment_page_type = jQuery('#commentPageType').val();
	
	var comment = encodeURIComponent(jQuery('#idComment').val());

	jQuery.ajax({
		url: 'ajax/postComment.html',
		type: "POST",
		data: {
			socialId: pSocialId,
			comment: comment,
			uuid: pSocialUUID,
			comment_page_type: comment_page_type,
			pageOp: 3
		},
		success: showCommentForm()
	});
	
	// var params = "socialId="+pSocialId+"&comment="+comment+"&uuid="+pSocialUUID+"&comment_page_type="+comment_page_type+"&pageOp=3";
	
	// var ajax = new Ajax.Updater('divPostCommentMsg',
	// 							'ajax/postComment.html',
	// 							{
	// 							method: 'post',
	// 							parameters: params,
	// 							evalScripts: true,	
	// 							onSuccess: showCommentForm								
	// 							});	
}



function showCommentForm()
{
  /*The delaytime is entered as milliseconds (1 second=1000 millisecond). */
  setTimeout("commentForm();",3000);
}

function commentForm()
{	
	jQuery('#idComment').val('');
	jQuery('#divPostCommentMsg').hide();
	jQuery('#divCommentForm').show();  
}

// function to display comments on social full view page
function loadSocialComments(pSocialId, pSocialUUID, pSortType)
{
	jQuery.ajax({
		// url: 'ajax/viewSocialComments.html',
		url: 'ajax/viewSocialComments_Dynamic.html',
		type: "POST",
		data: {
			socialId: pSocialId,
			uuid: pSocialUUID,
			sortType: pSortType,
			pageOp: 1
		},
		success: function(data) {
			jQuery("#divSocialComments").html(data);
		}
	});
}


// ----------------------------------------------------------------------------- //
// ------------------------ Red flg section :: BOF ----------------------------- //
// ----------------------------------------------------------------------------- //
function postRedFlag(cid)
{
	url  = jQuery('#idFlag_'+cid).href;
	GB_showCenter("Report this?", url, /* optional */ 300, 400)
}



// ----------------------------------------------------------------------------- //
// ------------------------ Checklist section :: BOF --------------------------- //
// ----------------------------------------------------------------------------- //
//function to post checklist
/*

function postChecklist(pSocialId)
{
   var varRelatesToEvent 	= 0;
   var varBookingInc 		= 0;
   var varSomewhereMeet 	= 0;
   var varReserveSpace 		= 0;
   var varCsLogo 			= 0;
   var varPrintGuestlist 	= 0;
   var varReviewRate 		= 0;   
	
   var frm = document.checklistfrm;
   
   for (var i=0; i < 2; i++) {
   	  if (frm.relatesToEvent[i].checked) varRelatesToEvent = frm.relatesToEvent[i].value;
   }
   
   for (var i=0; i < 2; i++) {
   	  if (frm.bookingInc[i].checked) varBookingInc = frm.bookingInc[i].value;
   }
   
   for (var i=0; i < 2; i++) {
   	  if (frm.somewhereToMeet[i].checked) varSomewhereMeet = frm.somewhereToMeet[i].value;
   }
    
   for (var i=0; i < 2; i++) {
   	  if (frm.reserveSpace[i].checked) varReserveSpace = frm.reserveSpace[i].value;
   }
    
   for (var i=0; i < 2; i++) {
   	  if (frm.printCsLogo[i].checked) varCsLogo = frm.printCsLogo[i].value;
   }
   
   for (var i=0; i < 2; i++) {
   	  if (frm.printGuestlist[i].checked) varPrintGuestlist = frm.printGuestlist[i].value;
   }
   
   for (var i=0; i < 2; i++) {
   	  if (frm.reviewRate[i].checked) varReviewRate = frm.reviewRate[i].value;
   }	
   
   var hostNotes = encodeURIComponent(jQuery('#hostNotes').value);
   var adminNotes = encodeURIComponent(jQuery('#adminNotes').value);   


	var params = "socialId="+pSocialId+"&rl="+varRelatesToEvent+"&bi="+varBookingInc+"&sm="+varSomewhereMeet+"&rs="+varReserveSpace;
	params += "&cl="+varCsLogo+"&gl="+varPrintGuestlist+"&rr="+varReviewRate;
	params += "&hostnotes="+hostNotes+"&pageOp=1";
	
	//alert(params);
	var ajax = new Ajax.Updater('divPostChecklistMsg',
								'ajax/postChecklist.html',
								{
								method: 'post',
								parameters: params,
								onSuccess: refreshPage									
								});	

}*/




//function to post checklist
function postAdminComments(pSocialId)
{
   var varRelatesToEvent 	= jQuery('#relatesToEvent').val();
   var varBookingInc 		= jQuery('#bookingInc').val();
   var varSomewhereMeet 	= jQuery('#somewhereToMeet').val();
   var varReserveSpace 		= jQuery('#reserveSpace').val();
   var varCsLogo 			= jQuery('#printCsLogo').val();
   var varPrintGuestlist 	= jQuery('#printGuestlist').val();
   var varReviewRate 		= jQuery('#reviewRate').val();  
   var hostNotes 			= jQuery('#hostNotes').val();
   
   var adminNotes = encodeURIComponent(jQuery('#adminNotes').val());   
   //var params = "socialId="+pSocialId+"&adminnotes="+adminNotes;
   
	jQuery.ajax({
		url: 'ajax/postChecklist.html',
		type: "POST",
		data: {
			socialId: pSocialId, rl: varRelatesToEvent,
			bi: varBookingInc,
			sm: varSomewhereMeet,
			rs: varReserveSpace,
			cl: varCsLogo,
			gl: varPrintGuestlist,
			rr: varReviewRate,
			hostnotes: hostNotes,
			adminnotes: adminNotes,
			pageOp: 1
		},
		success: function(data) {
			jQuery("#divPostChecklistMsg").html(data);
		}
	});
}

function refreshPage()
{
	setTimeout("window.location.reload(true);",1000);
}

// display all comments on social comments page
function loadCommentList(pPageNum)
{
	
	var current_page  	= jQuery('#pageNumber').val();
	var social_uuid 	= jQuery('#socialUuid').val();	
	var social_id 		= jQuery('#socialId').val();		
	var allow_omment_flag = jQuery('#allowCommentFlag').val();		

	if(pPageNum == "+")
	{
		pPageNum = ++current_page;
	}
	if(pPageNum == "-")
	{
		pPageNum = current_page - 1;
	}

	jQuery('#pageNumber').val(pPageNum);
	
	jQuery.ajax({
		url: 'ajax/viewAllComments.html',
		type: "POST",
		data: {
			socialId: social_id, 
			pagenum: pPageNum,
			uuid: social_uuid,
			pageOp: 2,
			allow_omment_flag: allow_omment_flag
		},
		success: function(data) {
			jQuery("#divViewComments").html(data);
		}
	})
}


// display all reviews on social reviews page
function loadReviewList(pPageNum)
{
	
	var current_page  	= jQuery('#pageNumber').val();
	var social_uuid 	= jQuery('#socialUuid').val();
	var social_id 		= jQuery('#socialId').val();
	var isAttandeeSaidYes = jQuery('#isAttandeeSaidYes').val();

	if(pPageNum == "+")
	{
		pPageNum = ++current_page;
	}
	if(pPageNum == "-")
	{
		pPageNum = current_page - 1;
	}

	jQuery('#pageNumber').val(pPageNum);

	jQuery.ajax({
		url: 'ajax/viewAllReviews.html',
		type: "POST",
		data: {
			socialId: social_id,
			pagenum: pPageNum,
			uuid: social_uuid,
			pageOp: 1,
			isAttandeeSaidYes: isAttandeeSaidYes
		},
		success: function(data) {
			jQuery("#divViewReviews").html(data);
		}
	});
}


// function to post/update rating/review
function postSocialRating()
{
	var rating_given = "";
	var comments 		= jQuery('#txtComments').val();
	var social_id 	 	= jQuery('#socialId').val();
	
	for(var i = 0; i < 5; i++)
	{
		if(document.frmSocialRating.rdRating[i].checked)
		{
			rating_given = document.frmSocialRating.rdRating[i].value;
			break;
		}
	}

	var params = "socialid="+social_id+"&rating="+rating_given+"&comments="+comments;

	//alert(params);
	if(jQuery('#hRatingKey').val() != '')
	{
		jQuery.ajax({
			url: 'ajax/updateRating.html',
			type: "POST",
			data: {
				socialid: social_id,
				rating: rating_given,
				comments: comments
			},
			success: function(data) {
				jQuery("#divRatingMsg").html(data);
			}
		});
	} else {
		jQuery.ajax({
			url: 'ajax/postRating.html',
			type: "POST",
			data: {
				socialid: social_id,
				rating: rating_given,
				comments: comments
			},
			success: function(data) {
				jQuery("#divRatingMsg").html(data);
                                refreshPage();
			}
		});
	}
}

/*********** Validation of Social video upload form ***************/
function validateSocialVideo(formObj)
{
	var caption = formObj.txtVideoCaption.val();
	var url = formObj.txtVideoUrl.val();
	var validForm = true;
	
	csHide('video_caption_mandatory_error_container');
	csHide('video_url_mandatory_error_container');

	if(!url || trim(url).length == 0)
	{
		csShow('video_url_mandatory_error_container');
		validForm = false;
	}
	
/*	if(!caption || trim(caption).length == 0)
	{
		csShow('video_caption_mandatory_error_container');
		validForm = false;
	}
*/
	if(!validForm) 
	{ 
		return false;
	} 
	else
	{
		return true;
	}
}

/*********** Validation of social photo upload form ***************/
function validateSocialPhotos(formObj)
{
	var validForm = true;
	var fileUploadCnt = 0;
	
	csHide('social_photo_error_header');	
	cnt = jQuery('#hiddenPhotoCnt').val()

	for(i=1; i<cnt; i++)
	{
		idUploadImage = 'txtImages' + i;	
		idCaption = 'txtCaption' + i;
		
		if(jQuery("#" + idUploadImage).val() != '')
		{ 			
			/*if(document.getElementById(idCaption).value == '')
			{
				validForm = false;
			} else {
				fileUploadCnt++;
			}*/
			fileUploadCnt++;
		} else {
				
		}
	}

	if (fileUploadCnt == 0)
	{	
		validForm = false;		
	}
	
	if(!validForm) 
	{ 
		csShow('social_photo_error_header');	
		return false;
	} 
	else 
	{ 
		jQuery('#hiddenPhotoCnt').val(fileUploadCnt);
		return true;
	}
}

function loadSocialPhoto(pagenum, pages, socialid)
{

	var current_page  = jQuery('#pageNumber').val();
	var uuid = jQuery('#idUuid').val();
	
	if(pagenum == "+")
	{
		if( current_page == pages ) return 1;		
		pagenum = ++current_page;
	}
	
	if(pagenum == "-")
	{
		if( current_page == 1 ) return 1;
		pagenum = current_page - 1;
	}
	
	jQuery('#pageNumber').value = pagenum;
	
	jQuery.ajax({
		url: 'ajax/view_photos.html',
		type: "POST",
		data: {
			pagenum: pagenum,
			pages: pages,
			socialid: socialid,
			uuid: uuid
		},
		success: function(data) {
			jQuery("#SocialPhotoContainer").html(data);
		}
	});
}

function loadSocialVideo(pagenum, pages, socialid)
{

	var current_page  = jQuery('#pageNumber').val();
	var uuid = jQuery('#idUuid').val();
	
	if(pagenum == "+")
	{
		if( current_page == pages ) return 1;		
		pagenum = ++current_page;
	}
	
	if(pagenum == "-")
	{
		if( current_page == 1 ) return 1;
		pagenum = current_page - 1;
	}
	
	jQuery('#pageNumber').val(pagenum);
	
	jQuery.ajax({
		url: 'ajax/view_videos.html',
		type: "POST",
		data: {
			pagenum: pagenum,
			pages: pages,
			socialid: socialid,
			uuid: uuid
		},
		success: function(data) {
			jQuery("#SocialVideoContainer").html(data)
		}
	});

}
function showPhoto(frmName)
{
	frmName.submit();
}

function closegreybox()
{	
    GB_hide();
	top.location.reload();	
}

function loadPhotoComments(pagenum, pages, photovideoid)
{
	var current_page  = jQuery('#pageNumber').val();
	
	if(pagenum == "+")
	{
		if( current_page == pages ) return 1;		
		pagenum = ++current_page;
	}
	
	if(pagenum == "-")
	{
		if( current_page == 1 ) return 1;
		pagenum = current_page - 1;
	}
	
	jQuery('#pageNumber').val(pagenum);
	
	jQuery.ajax({
		url: 'ajax/view_photo_video_comments.html',
		type: "POST",
		data: {
			pagenum: pagenum,
			pages: pages,
			photovideoid: photovideoid
		},
		success: function(data) {
			jQuery("#social_photo_comments").html(data);
		}
	});
}

//function to post photo /video comments
function postSocialPhotoComment()
{
	jQuery('#commentFormPostResult').show();
										
	jQuery.ajax({
		url: 'ajax/post_comment.html',
		type: "POST",
		data: {
			photoid: jQuery('#idPhotoId').val(),
			socialid: jQuery('#idSocialId').val(),
			comment: jQuery('#idComment').val(),
			isHost: jQuery('#hiddenIsHost').val()
		},
		success: function(data) {
			jQuery("#commentFormPostResult").html(data);
		}
	});
	//window.location.reload();
}

function refreshform()
{
  /*The delaytime is entered as milliseconds (1 second=1000 millisecond). */
  setTimeout("window.location.reload(true);",2000);
}

//function to social booking close
function closeBooking(bookingStatus, socialUuid)
{
	
	if(bookingStatus == 1)
		var msg = 'Are you sure you want to close the booking for this social?';
	else
		var msg = 'Are you sure you want to open the booking for this social?';
	
	if(confirm(msg)) 
	{
		jQuery.ajax({
			url: 'ajax/postBookingClosed.html',
			type: "POST",
			data: {
				uuid: socialUuid,
				bc: bookingStatus
			},
			success: function(data) {
				jQuery("#divCloseBookingMsg").html(data);
			}
		});
	}
}

//function to social booking close
function fullyBooked(bookingStatus, socialUuid)
{
	
	if(bookingStatus == 1)
		var msg = 'Are you sure you want to close the booking for this social?';
	else
		var msg = 'Are you sure you want to open the booking for this social?';
	
	if(confirm(msg)) 
	{
		jQuery.ajax({
			url: 'ajax/postFullyBooked.html',
			type: "POST",
			data: {
				uuid: socialUuid,
				bc: bookingStatus
			},
			success: function(data) {
				jQuery("#divCloseBookingMsg").html(data);
			}
		});
	}
}
