var docRoot = "";
//var docRoot = "/_dev";
var main_feedback = "<span>There is an error. Please try again.</span>";
var main_confirm = "<span>Are you sure?</span>";
var main_loading = "<span>Processing please wait.<br/><br/><div style='text-align:center;'><img src='"+docRoot+"/images/loading.gif' border='0' /></div></span>";
/*******************Main Feedback *****************/
function dialog_main_feedback(msg){
	if(msg)
		$('#mainFeedback').html(msg);
	else
		$('#mainFeedback').html(main_feedback);
	$('#dialog_main_feedback').dialog('open');
}
function dialog_main_feedback_close(){
	$('#dialog_main_feedback').dialog('close');
}
/************* End Main Feedback ******************/

/*******************Main Loadpage *****************/
function dialog_main_loadpage(pageurl,pagetitle){
	if(pageurl){
		$("#dialog_main_loadpage").dialog( "option", "title", pagetitle);
		showLoading('mainLoadpage');
		$('#dialog_main_loadpage').dialog('open');
		$('#mainLoadpage').load(pageurl,function() {
			$("#dialog_main_loadpage").dialog('close');
			$("#dialog_main_loadpage").dialog("option", "position", 'center');
			$("#dialog_main_loadpage").dialog('open');
		});
	}
}
function dialog_main_loadpage_close(){
	$('#dialog_main_loadpage').dialog('close');
}
/************* End Main Loadpage ******************/

/*******************Main Confirm *****************/
function dialog_confirm(msg,callback){
	$('#mainConfirmCallback').val(callback);
	if(msg)
		$('#mainConfirm').html(msg);
	else
		$('#mainConfirm').html(main_confirm);
	$('#dialog_confirm').dialog('open');
}
/************* End Main Confirm ******************/

/******************* Profiles *********************/
// Delete Profile Message Dialog
function dialog_profile_deleteMessage(mid){
	// Update the cid value in the hidden field
	$('#messageID').val(mid);
	$('#dialog_profile_deleteMessage').dialog('open');
}

// Delete Profile Post Dialog
function dialog_profile_deletePost(cid,pid){
	// Update the cid value in the hidden field
	$('#catID').val(cid);
	$('#postID').val(pid);
	$('#dialog_profile_deletePost').dialog('open');
}

// Delete Profile Post Dialog
function dialog_profile_deleteComment(cid){
	// Update the cid value in the hidden field
	$('#commentID').val(cid);
	$('#dialog_profile_deleteComment').dialog('open');
}

// Delete Profile Message Dialog
function dialog_profile_deletePic(pid){
	// Update the cid value in the hidden field
	$('#picID').val(pid);
	$('#dialog_profile_deletePic').dialog('open');
}

// Upload Profile Photo
function dialog_profile_uploadPhoto(){
	$('#Profile_upload_photo').val('');
	$('#dialog_profile_uploadPhoto').dialog('open');
}

// Upload Profile Emotion Photo
function dialog_profile_uploadEmotionPhoto(emotionName, eid){
	$('#Profile_upload_emotion_photo').val('');
	$('#emotionID').val(eid);
	$('#emotionName').text(emotionName);
	$('#dialog_profile_uploadEmotionPhoto').dialog('open');
}

// Add Style Dialog
function dialog_profile_addStyle(){
	// Update the cid value in the hidden field
	$('#dialog_profile_addStyle').dialog('open');
}

// Delete Style Dialog
function dialog_profile_deleteStyle(sid){
	// Update the cid value in the hidden field
	$('#styleID').val(sid);
	$('#dialog_profile_deleteStyle').dialog('open');
}

// Unjoin School
function dialog_profile_unjoinSchool(sid){
	$('#schoolID').val(sid);
	$('#dialog_profile_unjoinSchool').dialog('open');
}

// Delete Event Dialog
function dialog_profile_deleteEvent(eid){
	// Update the cid value in the hidden field
	$('#eventID').val(eid);
	$('#dialog_profile_deleteEvent').dialog('open');
}

// Delete Icon Dialog
function dialog_profile_deleteIcon(iid){
	// Update the cid value in the hidden field
	$('#iconID').val(iid);
	$('#dialog_profile_deleteIcon').dialog('open');
}
/**************** End Profiles ********************/

/**************** Schools *************************/

// Delete Album Comment Dialog
function dialog_deleteSchoolComment(cid){
	// Update the cid value in the hidden field
	$('#commentID').val(cid);
	$('#dialog_school_deleteComment').dialog('open');
}

// Upload Profile Photo
function dialog_school_uploadPhoto(sid,act,callmode){
	$('#School_id').val(sid);
	$('#School_action').val(act);
	$('#School_mode').val(callmode);
	$('#dialog_school_uploadPhoto').val('');
	$('#dialog_school_uploadPhoto').dialog('open');
}

function dialog_school_addPeople(sid){
	$('#SchoolId').val(sid);
	$('#dialog_school_addPeople').dialog('open');
}

function dialog_school_deletePhoto(sid, pid, order){
	// Update the cid value in the hidden field
	$('#photoID').val(pid);
	$('#schoolID').val(sid);
	$('#order').val(order);
	$('#dialog_school_deletePhoto').dialog('open');
}

function dialog_school_verification(){
	$('#dialog_school_verification').dialog('open');
}

function dialog_school_verification_feedback(pin){
	$('#PIN').html(pin);
	$('#dialog_school_verification_feedback').dialog('open');
}

/**************** End Schools *********************/

/******************* Albums ***********************/

// Delete Album Photo Dialog
function dialog_album_deletePhoto(pid, aid, order,ref){
	// Update the cid value in the hidden field
	$('#photoID').val(pid);
	$('#albumID').val(aid);
	$('#order').val(order);
	$('#ref').val(ref);
	$('#dialog_album_deletePhoto').dialog('open');	
}

// Delete Album Comment Dialog
function dialog_deleteAlbumComment(cid){
	// Update the cid value in the hidden field
	$('#commentID').val(cid);
	$('#dialog_album_deleteComment').dialog('open');
}

// Report Photo Dialog
function dialog_album_reportPhoto(pid){
	// Update the cid value in the hidden field
	$('#reportPhotoID').val(pid);
	$('#dialog_album_reportPhoto').dialog('open');
}

// Delete Album Dialog
function dialog_album_deleteAlbum(aid,nav){
	// Update the cid value in the hidden field
	$('#albumID').val(aid);
	$('#albumNav').val(nav);
	$('#dialog_album_deleteAlbum').dialog('open');
}

// Help Album Open To PublicDialog
function dialog_album_help_openToPublic(){
	$('#dialog_album_help_openToPublic').dialog('open');
}

// Tag Photo to an event
function dialog_album_tagPhoto(pid,ref){
	$('#tagPhotoID').val(pid);
	$('#tagRef').val(ref);
	$('#dialog_album_tagPhoto').dialog('open');
}

// Tag Photo to an event
function dialog_album_addTags(pid){
	$('#addTagsPhotoID').val(pid);
	$('#dialog_album_addTags').dialog('open');
}
/******************* End Albums ********************/

/******************* Videos ***********************/

// Delete Video Dialog
function dialog_video_deleteVideo(vid){
	// Update the vid value in the hidden field
	$('#videoID').val(vid);
	$('#dialog_video_deleteVideo').dialog('open');
}

// Delete Video Comment Dialog
function dialog_deleteVideoComment(cid){
	// Update the cid value in the hidden field
	$('#commentID').val(cid);
	$('#dialog_video_deleteComment').dialog('open');
}
// Report Video Dialog
function dialog_video_reportVideo(vid){
	// Update the cid value in the hidden field
	$('#videoID').val(vid);
	$('#dialog_video_reportVideo').dialog('open');
}

/******************* End Videos ********************/

/******************* Inbox ***********************/

// Delete Video Dialog
function dialog_inbox_to_field(){
	showLoading('dialog_inbox_to_field_content');
	$('#dialog_inbox_to_field').dialog('open');
	//$('#SelectedFriend').html('&nbsp;');
	$('#SearchFriendField').val('');
	$('#dialog_inbox_to_field_content').load(docRoot+'/inbox/dialog_to_field.php');
}

function dialog_inbox_deleteMail(inbox_id, act){
	$('#inboxID').val(inbox_id);
	$('#inboxAction').val(act);
	$('#dialog_inbox_deleteMail').dialog('open');
}

function dialog_inbox_deleteSentMail(inbox_id, act){
	$('#inboxID').val(inbox_id);
	$('#inboxAction').val(act);
	$('#dialog_inbox_deleteSentMail').dialog('open');
}
/******************* End Inbox ********************/

$(function() {
	
	/****** Main Feedback ************************/
	$("#dialog_main_feedback").dialog({
		bgiframe: true,
		autoOpen: false,
		width: 380,
		resizable: false,
		draggable: false,
		modal: true,
		buttons: {
			OK: function() {
				$(this).dialog('close');
			},
		},
		close: function() {
			//clear the feedback
			$('#mainFeedback').val(main_feedback);
		}
	});
	
	/****** Main Loadpage ************************/
	$("#dialog_main_loadpage").dialog({
		modal: true,
		autoOpen: false,
    resizable: false,
    draggable: false,
    width: 'auto',
		close: function() {
			//$('#mainLoadpage').html("");
		}
	});
	
	/****** Main confirm ************************/
	$("#dialog_confirm").dialog({
		bgiframe: true,
		autoOpen: false,
		width: 420,
		resizable: false,
		draggable: false,
		modal: true,
		buttons: {
			Cancel: function() {
				$(this).dialog('close');
			},
			OK: function() {
				eval($('#mainConfirmCallback').val());
				$(this).dialog('close');
			},
		},
		close: function() {
			//clear the feedback
			$('#mainConfirm').val(main_confirm);
		}
	});
	
	/****** Profile ******************************/
	/* Delete Profile Post*/
	$("#dialog_profile_deletePost").dialog({
		bgiframe: true,
		autoOpen: false,
		width: 380,
		resizable: false,
		draggable: false,
		modal: true,
		buttons: {
			Cancel: function() {
				$(this).dialog('close');
			},
			'Delete Post': function() {
				var str = $('#deletePostForm').serialize();
				var cid = $('#catID').val();
				var pid = $('#postID').val();
				$.ajax({
			  	type: "POST",
			   	url: docRoot+"/profile/dialog_deletePost.php",
			   	data: str,
			   	success: function(msg){
			    	//alert( "Data Saved: " + msg );
			    	// If error
			    	if(msg == '0'){
			    		//$('#deletePostFeedback').html('<span class="err">There is an error. Please try again.</span>');
			    		dialog_main_feedback();
			    		$("#dialog_profile_deletePost").dialog('close');
			    	}
			    	else{
			    		
			    		//remove the comment from DOM
			    		$('[id=Profile_feed_block_'+pid+']').remove();
			    		//remove the message container from DOM if it is empty.
        			//var checkBlockExisted = $('#Message_'+pid).text();
        			var checkBlockExisted = $('#Message_container_'+pid).text();
        			if(checkBlockExisted.length < 20)
        				$('#Message_container_'+pid).remove();
        			
        			//alert(msg);
			    		$("#dialog_profile_deletePost").dialog('close');
			    	}
			   	}
			 });

			}
		},
		close: function() {
			//clear the feedback
			$('#deletePostFeedback').val("");
		}
	});	

	/* Delete Profile Comment*/
	$("#dialog_profile_deleteComment").dialog({
		bgiframe: true,
		autoOpen: false,
		width: 400,
		resizable: false,
		draggable: false,
		modal: true,
		buttons: {
			Cancel: function() {
				$(this).dialog('close');
			},
			'Delete Comment': function() {
				var str = $('#deleteCommentForm').serialize();
				var cid = $('#commentID').val();
				$.ajax({
			  	type: "POST",
			   	url: docRoot+"/profile/dialog_deleteComment.php",
			   	data: str,
			   	success: function(msg){
			    	//alert( "Data Saved: " + msg );
			    	// If error
			    	if(msg == '0'){
			    		//$('#deletePostFeedback').html('<span class="err">There is an error. Please try again.</span>');
			    		dialog_main_feedback();
			    		$("#dialog_profile_deleteComment").dialog('close');
			    	}
			    	else{
			    		//remove the comment from DOM
			    		$('[id=Comment_'+cid+']').remove();
			    		$("#dialog_profile_deleteComment").dialog('close');
			    	}
			   	}
			 });

			}
		},
		close: function() {
			//clear the feedback
			//$('#deletePostFeedback').val("");
		}
	});	
	
	/* Delete Profile Message*/
	$("#dialog_profile_deleteMessage").dialog({
		bgiframe: true,
		autoOpen: false,
		width: 380,
		resizable: false,
		draggable: false,
		modal: true,
		buttons: {
			Cancel: function() {
				$(this).dialog('close');
			},
			'Delete Message': function() {
				var str = $('#deleteMessageForm').serialize();
				var mid = $('#messageID').val();
				$.ajax({
			  	type: "POST",
			   	url: docRoot+"/profile/dialog_deleteMessage.php",
			   	data: str,
			   	success: function(msg){
			    	//alert( "Data Saved: " + msg );
			    	// If error
			    	if(msg == '0'){
			    		$('#deleteMessageFeedback').html('<span class="err">There is an error. Please try again.</span>');
			    	}
			    	else{
			    		//remove the comment from DOM
			    		$('[id=Profile_message_block_'+mid+']').remove();
			    		//remove the message container from DOM if it is empty.
			    		var d = new Date();
            	var str = (d.getMonth()+1)+"-"+d.getDate()+"-"+d.getFullYear();
        			var checkBlockExisted = $('#Message_'+str).text();
        			if(checkBlockExisted.length < 20)
        				$('#Message_container_'+str).remove();
			    		$("#dialog_profile_deleteMessage").dialog('close');
			    	}
			   	}
			 });

			}
		},
		close: function() {
			//clear the feedback
			$('#deleteMessageFeedback').val("");
		}
	});

	/* Delete Profile picID'*/
	$("#dialog_profile_deletePic").dialog({
		bgiframe: true,
		autoOpen: false,
		width: 380,
		resizable: false,
		draggable: false,
		modal: true,
		buttons: {
			Cancel: function() {
				hideLoading('Profile_upload_response');
				$(this).dialog('close');
			},
			'Delete Picture': function() {
				showLoading('Profile_upload_response');
				var str = $('#deletePicForm').serialize();
				var pid = $('#picID').val();
				$.ajax({
			  	type: "POST",
			   	url: docRoot+"/profile/dialog_deletePic.php",
			   	data: str,
			   	success: function(msg){
			    	//alert( "Data Saved: " + msg );
			    	// If error
			    	if(msg == '0'){
			    		$('#deletePicFeedback').html('<span class="err">There is an error. Please try again.</span>');
			    	}
			    	else{
			    		$('#Profile_pic_'+pid).remove();
			    		$('#Profile').load('changeProfilePic.php');	
			    		hideLoading('Profile_upload_response');
			    		$("#dialog_profile_deletePic").dialog('close');
			    	}
			   	}
			 });

			}
		},
		close: function() {
			//clear the feedback
			hideLoading('Profile_upload_response');
			$('#deletePicFeedback').val("");
		}
	});
	
	/* Upload Profile photo'*/
	$("#dialog_profile_uploadPhoto").dialog({
		bgiframe: true,
		autoOpen: false,
		width: 450,
		resizable: false,
		draggable: false,
		modal: true,
		close: function() {

		}
	});
	
	/* Upload Profile Emotion photo'*/
	$("#dialog_profile_uploadEmotionPhoto").dialog({
		bgiframe: true,
		autoOpen: false,
		width: 450,
		resizable: false,
		draggable: false,
		modal: true,
		close: function() {

		}
	});
	
	/* Add Style*/
	$("#dialog_profile_addStyle").dialog({
		bgiframe: true,
		autoOpen: false,
		width: 380,
		resizable: false,
		draggable: false,
		modal: true,
		buttons: {
			Cancel: function() {
				$(this).dialog('close');
			},
			'Add Style': function() {
				var str = $('#addStyleForm').serialize();
				$.ajax({
			  	type: "POST",
			   	url: docRoot+"/profile/dialog_addStyle.php",
			   	data: str,
			   	success: function(msg){
			    	//alert( "Data Saved: " + msg );
			    	// If error
			    	if(msg == '3'){
			    		dialog_main_feedback('This style is already on your list.');
			    		$("#dialog_profile_addStyle").dialog('close');
			    	}
			    	else if(msg == '0'){
			    		dialog_main_feedback(msg);
			    		$("#dialog_profile_addStyle").dialog('close');
			    	}
			    	else{
			    		style_array = msg.split(":");
			    		//alert(style_array[0]+":"+style_array[1]+"-"+msg)
			    		//$('[id=Style_list]').append('<tr><td>'+style_array[1]+'</td><td><span class="ui-icon ui-icon-closethick link" style="float:left;" onclick="dialog_profile_deleteStyle(\''+style_array[0]+'\')"></span></td></tr>');
			    		$('[id=Style_list]').append('<div style="clear:both;" id="Style_'+style_array[0]+'"><span style="float:left;margin-right: 5px;margin-bottom:5px;">'+style_array[1]+'</span><span class="ui-icon ui-icon-closethick link" style="float:left;" onclick="dialog_profile_deleteStyle(\''+style_array[0]+'\')"></span></div>');
			    		$("#dialog_profile_addStyle").dialog('close');
			    	}
			   	}
			 });

			}
		},
		close: function() {
			//clear the feedback
			//$('#deletePostFeedback').val("");
		}
	});	
	
	/* Delete Style*/
	$("#dialog_profile_deleteStyle").dialog({
		bgiframe: true,
		autoOpen: false,
		width: 380,
		resizable: false,
		draggable: false,
		modal: true,
		buttons: {
			Cancel: function() {
				$(this).dialog('close');
			},
			'Delete Style': function() {
				var str = $('#deleteStyleForm').serialize();
				var sid = $('#styleID').val();
				$.ajax({
			  	type: "POST",
			   	url: docRoot+"/profile/dialog_deleteStyle.php",
			   	data: str,
			   	success: function(msg){
			    	//alert( "Data Saved: " + msg );
			    	// If error
			    	if(msg == '0'){
			    		//$('#deletePostFeedback').html('<span class="err">There is an error. Please try again.</span>');
			    		dialog_main_feedback();
			    		$("#dialog_profile_deleteStyle").dialog('close');
			    	}
			    	else{
			    		//remove the comment from DOM
			    		$('[id=Style_'+sid+']').remove();
			    		$("#dialog_profile_deleteStyle").dialog('close');
			    	}
			   	}
			 });

			}
		},
		close: function() {
			//clear the feedback
			//$('#deletePostFeedback').val("");
		}
	});
	
	/* Unjoin School*/
	$("#dialog_profile_unjoinSchool").dialog({
		bgiframe: true,
		autoOpen: false,
		width: 380,
		resizable: false,
		draggable: false,
		modal: true,
		buttons: {
			Cancel: function() {
				$(this).dialog('close');
			},
			'Unjoin': function() {
				var str = $('#unjoinSchoolForm').serialize();
				var sid = $('#schoolID').val();
				$.ajax({
			  	type: "POST",
			   	url: docRoot+"/profile/dialog_unjoinSchool.php",
			   	data: str,
			   	success: function(msg){
			    	//alert( "Data Saved: " + msg );
			    	// If error
			    	if(msg == '0'){
			    		//$('#deletePostFeedback').html('<span class="err">There is an error. Please try again.</span>');
			    		dialog_main_feedback();
			    		$("#dialog_profile_unjoinSchool").dialog('close');
			    	}
			    	else{
			    		//remove the comment from DOM
			    		$('[id=School_'+sid+']').remove();
			    		$("#dialog_profile_unjoinSchool").dialog('close');
			    	}
			   	}
			 });

			}
		},
		close: function() {
			//clear the feedback
			//$('#deletePostFeedback').val("");
		}
	});
	
	/* Delete Event*/
	$("#dialog_profile_deleteEvent").dialog({
		bgiframe: true,
		autoOpen: false,
		width: 380,
		resizable: false,
		draggable: false,
		modal: true,
		buttons: {
			Cancel: function() {
				$(this).dialog('close');
			},
			'Delete': function() {
				var str = $('#deleteEventForm').serialize();
				var eid = $('#eventID').val();
				$.ajax({
			  	type: "POST",
			   	url: docRoot+"/profile/dialog_deleteEvent.php",
			   	data: str,
			   	success: function(msg){
			    	//alert( "Data Saved: " + msg );
			    	// If error
			    	if(msg != '1'){
			    		//$('#deletePostFeedback').html('<span class="err">There is an error. Please try again.</span>');
			    		dialog_main_feedback(msg);
			    		$("#dialog_profile_deleteEvent").dialog('close');
			    	}
			    	else{
			    		//remove the comment from DOM
			    		$('[id=Event_'+eid+']').remove();
			    		$("#dialog_profile_deleteEvent").dialog('close');
			    	}
			   	}
			 });

			}
		},
		close: function() {
			//clear the feedback
			//$('#deletePostFeedback').val("");
		}
	});

	/* Delete Icon*/
	$("#dialog_profile_deleteIcon").dialog({
		bgiframe: true,
		autoOpen: false,
		width: 380,
		resizable: false,
		draggable: false,
		modal: true,
		buttons: {
			Cancel: function() {
				$(this).dialog('close');
			},
			'Delete': function() {
				var str = $('#deleteIconForm').serialize();
				var iid = $('#iconID').val();
				$.ajax({
			  	type: "POST",
			   	url: docRoot+"/profile/dialog_deleteIcon.php",
			   	data: str,
			   	success: function(msg){
			    	//alert( "Data Saved: " + msg );
			    	// If error
			    	if(msg != '1'){
			    		//$('#deletePostFeedback').html('<span class="err">There is an error. Please try again.</span>');
			    		dialog_main_feedback(msg);
			    		$("#dialog_profile_deleteIcon").dialog('close');
			    	}
			    	else{
			    		//remove the comment from DOM
			    		$('[id=Icon_'+iid+']').remove();
			    		$("#dialog_profile_deleteIcon").dialog('close');
			    	}
			   	}
			 });

			}
		},
		close: function() {
			//clear the feedback
			//$('#deletePostFeedback').val("");
		}
	});
	
	/**************End  Profile ********************************/

	/**************Schools ************************************/
	/* Upload School photo'*/
	$("#dialog_school_uploadPhoto").dialog({
		bgiframe: true,
		autoOpen: false,
		width: 450,
		resizable: false,
		draggable: false,
		modal: true,
		close: function() {
			
		}
	});

	/* Add People*/
	$("#dialog_school_addPeople").dialog({
		bgiframe: true,
		autoOpen: false,
		width: 380,
		resizable: false,
		draggable: false,
		modal: true,
		buttons: {
			Cancel: function() {
				$(this).dialog('close');
			},
			'Submit': function() {
				var str = $('#addPeopleForm').serialize();
				var sid = $('#SchoolId').val();
				$.ajax({
			  	type: "POST",
			   	url: docRoot+"/schools/addPeople.php",
			   	data: str,
			   	success: function(msg){
			    	//alert( "Data Saved: " + msg );
			    	// If error
			    	if(msg == '1'){
			    		$('#tab_school_people').load(docRoot+"/schools/tab_people.php?id="+sid);
			    		$("#dialog_school_addPeople").dialog('close');
			    	}
			    	else{
			    		dialog_main_feedback();
			    		$("#dialog_school_addPeople").dialog('close');
			    	}
			   	}
			 	});
			}
		},
		close: function() {
			//clear the feedback
			$('#addPeopleFeedback').val("");
		}
	});

	$('#dialog_school_deletePhoto').dialog({
		bgiframe: true,
		autoOpen: false,
		width: 380,
		resizable: false,
		draggable: false,
		modal: true,
		buttons: {
			Cancel: function() {
				$(this).dialog('close');
			},
			'Delete Photo': function() {
				var str = $('#deletePhotoForm').serialize();
				var sid = $('#schoolID').val();
				var pid = $('#photoID').val();
				$.ajax({
			  	type: "POST",
			   	url: docRoot+"/schools/dialog_deletePhoto.php",
			   	data: str,
			   	success: function(msg){
			    	//alert( "Data Saved: " + msg );
			    	// If error
			    	if(msg == '0'){
			    		dialog_main_feedback();
			    		$('#dialog_school_deletePhoto').dialog('close');
			    	}
			    	else{
			    		//$("#dialog_album_deletePhoto").dialog('close');
			    		//window.location = docRoot+"/schools/view.php?id="+sid+"&pid="+pid;
			    		window.location = docRoot+"/schools/view.php?id="+sid;
			    	}
			   	}
			 });

			}
		},
		close: function() {
			//clear the feedback
			$('#deleteCommentFeedback').val("");
		}
	});
	
	/* Verification*/
	$("#dialog_school_verification").dialog({
		bgiframe: true,
		autoOpen: false,
		width: 550,
		resizable: false,
		draggable: false,
		modal: true,
		buttons: {
			Cancel: function() {
				$(this).dialog('close');
			},
			'OK Call Now': function() {
				showLoading('verificationFeedback');
				var str = $('#verificationForm').serialize();
				var sid = $('#schoolID').val();
				var pin = $('#schoolPin').val();
				$.ajax({
			  	type: "POST",
			   	url: docRoot+"/schools/claim/call/proc.php",
			   	data: str,
			   	success: function(msg){
			   		/*if(msg.length > 0){
			    		dialog_main_feedback(msg);
			    		$("#dialog_school_verification").dialog('close');
			    	}*/
			    	$('#School_msg').html(msg);
			   	}
			 	});
			 	$('#verificationFeedback').html("");
			  dialog_school_verification_feedback(pin);
			  $("#dialog_school_verification").dialog('close');
			}
		},
		close: function() {
			//clear the feedback
			$('#verificationFeedback').html("");
		}
	});

	$("#dialog_school_verification_feedback").dialog({
		bgiframe: true,
		autoOpen: false,
		width: 550,
		resizable: false,
		draggable: false,
		modal: true,
		buttons: {
			OK: function() {
				$('#verificationFeedback').html("");
				$('#School_msg').html('Please wait<br/><img src="'+docRoot+'/images/loading.gif" border="0" />');
				$(this).dialog('close');
			}
		},
		close: function() {
			//clear the feedback
			$('#verificationFeedback').html("");
			$('#School_msg').html('Please wait<br/><img src="'+docRoot+'/images/loading.gif" border="0" />');
		}
	});

	/**************End  School ********************************/

	/* Delete Album Photo*/
	$("#dialog_album_deletePhoto").dialog({
		bgiframe: true,
		autoOpen: false,
		width: 380,
		resizable: false,
		draggable: false,
		modal: true,
		buttons: {
			Cancel: function() {
				$(this).dialog('close');
			},
			'Delete Photo': function() {
				var str = $('#deletePhotoForm').serialize();
				var aid = $('#albumID').val();
				var ref = $('#ref').val();
				$.ajax({
			  	type: "POST",
			   	url: docRoot+"/albums/dialog_deletePhoto.php",
			   	data: str,
			   	success: function(msg){
			    	//alert( "Data Saved: " + msg );
			    	// If error
			    	if(msg == '0'){
			    		$('#deletePhotoFeedback').html('<span class="err">There is an error. Please try again.</span>');
			    	}
			    	else{
			    		//$("#dialog_album_deletePhoto").dialog('close');
			    		if(ref=="calendar")
			    			window.location = docRoot+"/calendar/detail.php?id="+aid;
			    		else if(ref=="photo")
			    			window.location = docRoot+"/photos/view.php?id="+aid;
			    		else if(ref=="profile")
			    			window.location = docRoot+"/albums/view.php?id="+aid+"&nav=profile";
			    		else
			    			window.location = docRoot+"/albums/view.php?id="+aid;
			    	}
			   	}
			 });

			}
		},
		close: function() {
			//clear the feedback
			$('#deleteCommentFeedback').val("");
		}
	});
	
	/* Delete Album Comment*/
	$("#dialog_album_deleteComment").dialog({
		bgiframe: true,
		autoOpen: false,
		width: 400,
		resizable: false,
		draggable: false,
		modal: true,
		buttons: {
			Cancel: function() {
				$(this).dialog('close');
			},
			'Delete Comment': function() {
				var str = $('#deleteCommentForm').serialize();
				var cid = $('#commentID').val();
				$.ajax({
			  	type: "POST",
			   	url: docRoot+"/albums/dialog_deleteComment.php",
			   	data: str,
			   	success: function(msg){
			    	//alert( "Data Saved: " + msg );
			    	// If error
			    	if(msg == '0'){
			    		$('#deleteCommentFeedback').html('<span class="err">There is an error. Please try again.</span>');
			    	}
			    	else{
			    		//remove the comment from DOM
			    		$('[id=Message_container_'+cid+']').remove();
			    		// Clear the add comment feedback
			    		$('#Album_tempFeedback').remove();
			    		$("#dialog_album_deleteComment").dialog('close');
			    	}
			   	}
			 });

			}
		},
		close: function() {
			//clear the feedback
			$('#deleteCommentFeedback').val("");
		}
	});
	
	/* Report Photo*/
	$("#dialog_album_reportPhoto").dialog({
		bgiframe: true,
		autoOpen: false,
		width: 350,
		resizable: false,
		draggable: false,
		modal: true,
		buttons: {
			Cancel: function() {
				$(this).dialog('close');
			},
			'Report Photo': function() {
				var str = $('#reportPhotoForm').serialize();
				$.ajax({
			  	type: "POST",
			   	url: docRoot+"/albums/dialog_reportPhoto.php",
			   	data: str,
			   	success: function(msg){
			    	//alert( "Data Saved: " + msg );
			    	// If error
			    	if(msg == '0'){
			    		$('#reportPhotoFeedback').html('<span class="err">There is an error. Please try again.</span>');
			    	}
			    	else{
			    		$("#dialog_album_reportPhoto").dialog('close');
			    	}
			   	}
			 });

			}
		},
		close: function() {
			//clear the feedback
			$('#reportPhotoFeedback').val("");
		}
	});
	
	/* Delete Whole Album*/
	$("#dialog_album_deleteAlbum").dialog({
		bgiframe: true,
		autoOpen: false,
		width: 380,
		resizable: false,
		draggable: false,
		modal: true,
		buttons: {
			Cancel: function() {
				$(this).dialog('close');
			},
			'Delete Photo': function() {
				var str = $('#deleteAlbumForm').serialize();
				var aid = $('#albumID').val();
				var nav = $('#albumNav').val();
				$.ajax({
			  	type: "POST",
			   	url: docRoot+"/albums/dialog_deleteAlbum.php",
			   	data: str,
			   	success: function(msg){
			    	//alert( "Data Saved: " + msg );
			    	// If error
			    	if(msg == '0'){
			    		$('#deleteAlbumFeedback').html('<span class="err">There is an error. Please try again.</span>');
			    	}
			    	else{
			    		//$("#dialog_album_deletePhoto").dialog('close');
			    		if(nav == 'profile')
			    			nav_str = "?nav=profile";
			    		window.location = docRoot+"/albums/index.php"+nav_str;
			    	}
			   	}
			 });

			}
		},
		close: function() {
			//clear the feedback
			$('#deleteAlbumFeedback').val("");
		}
	});
	
	/* Help Album Open To Public*/
	$("#dialog_album_help_openToPublic").dialog({
		bgiframe: true,
		autoOpen: false,
		width: 380,
		resizable: false,
		draggable: false,
		modal: true,
		buttons: {
			Close: function() {
				$(this).dialog('close');
			}
		},
		close: function() {
			
		}
	});

	/* Tag Photo*/
	$("#dialog_album_tagPhoto").dialog({
		bgiframe: true,
		autoOpen: false,
		width: 400,
		resizable: false,
		draggable: false,
		modal: true,
		buttons: {
			Cancel: function() {
				$(this).dialog('close');
			},
			'Tag Photo': function() {
				var str = $('#tagPhotoForm').serialize();
				var pid = $('#tagPhotoID').val();
				var ref = $('#tagRef').val();
				$.ajax({
			  	type: "POST",
			   	url: docRoot+"/albums/dialog_tagPhoto.php",
			   	data: str,
			   	success: function(msg){
			    	//alert( "Data Saved: " + msg );
			    	// If error
			    	if(msg == '0'){
			    		dialog_main_feedback();
			    		$('#dialog_album_tagPhoto').dialog('close');
			    	}
			    	else{
			    		if(ref=="photo"){
			    			window.location = docRoot+"/photos/view.php?id="+pid;
			    		}
			    		else{
			    			window.location = docRoot+"/albums/viewPhoto.php?id="+pid+"&nav=profile";
			    			$("#dialog_album_tagPhoto").dialog('close');
			    		}
			    	}
			   	}
			 });

			}
		},
		close: function() {
			//clear the feedback
			$('#tagPhotoFeedback').html("");
		}
	});

	/* Add Tags*/
	$("#dialog_album_addTags").dialog({
		bgiframe: true,
		autoOpen: false,
		width: 400,
		resizable: false,
		draggable: false,
		modal: true,
		buttons: {
			Cancel: function() {
				$(this).dialog('close');
			},
			'Add': function() {
				showLoading("addTagsFeedback");
				var str = $('#addTagsForm').serialize();
				var pid = $('#addTagsPhotoID').val();
				$.ajax({
			  	type: "POST",
			   	url: docRoot+"/albums/dialog_addTags.php",
			   	data: str,
			   	success: function(msg){
			    	//alert( "Data Saved: " + msg );
			    	// If error
			    	if(msg == '0'){
			    		dialog_main_feedback();
			    		$('#dialog_album_addTags').dialog('close');
			    	}
			    	else{
			    		$('[id=Photo_tag_'+pid+']').append(msg);
			    		$('#dialog_album_addTags').dialog('close');
			    	}			    	
			    	$('#addTagsForm')[0].reset();
			   	}
			 });

			}
		},
		close: function() {
			//clear the feedback
			$('#addTagsFeedback').html("");
		}
	});
	
	/***********************Videos***************************/
	
	/* Delete Video */
	$("#dialog_video_deleteVideo").dialog({
		bgiframe: true,
		autoOpen: false,
		width: 380,
		resizable: false,
		draggable: false,
		modal: true,
		buttons: {
			Cancel: function() {
				$(this).dialog('close');
			},
			'Delete Video': function() {
				var str = $('#deleteVideoForm').serialize();
				$.ajax({
			  	type: "POST",
			   	url: docRoot+"/videos/dialog_deleteVideo.php",
			   	data: str,
			   	success: function(msg){
			    	//alert( "Data Saved: " + msg );
			    	// If error
			    	if(msg == '0'){
			    		$('#deleteVideoFeedback').html('<span class="err">There is an error. Please try again.</span>');
			    	}
			    	else{
			    		window.location = docRoot+"/videos/index.php";
			    	}
			   	}
			 });

			}
		},
		close: function() {
			//clear the feedback
			$('#deleteCommentFeedback').html("");
		}
	});

	// Delete Video Comment
	$("#dialog_video_deleteComment").dialog({
		bgiframe: true,
		autoOpen: false,
		width: 380,
		resizable: false,
		draggable: false,
		modal: true,
		buttons: {
			Cancel: function() {
				$(this).dialog('close');
			},
			'Delete Comment': function() {
				var str = $('#deleteCommentForm').serialize();
				var cid = $('#commentID').val();
				$.ajax({
			  	type: "POST",
			   	url: docRoot+"/videos/dialog_deleteComment.php",
			   	data: str,
			   	success: function(msg){
			    	//alert( "Data Saved: " + msg );
			    	// If error
			    	if(msg == '0'){
			    		$('#deleteCommentFeedback').html('<span class="err">There is an error. Please try again.</span>');
			    	}
			    	else{
			    		//remove the comment from DOM
			    		$('[id=Message_container_'+cid+']').remove();
			    		// Clear the add comment feedback
			    		$('#Video_tempFeedback').remove();
			    		$("#dialog_video_deleteComment").dialog('close');
			    	}
			   	}
			 });

			}
		},
		close: function() {
			//clear the feedback
			$('#deleteCommentFeedback').val("");
		}
	});
	
	// Report Video
	$("#dialog_video_reportVideo").dialog({
		bgiframe: true,
		autoOpen: false,
		width: 330,
		resizable: false,
		draggable: false,
		modal: true,
		buttons: {
			Cancel: function() {
				$(this).dialog('close');
			},
			'Report Video': function() {
				var str = $('#reportVideoForm').serialize();
				$.ajax({
			  	type: "POST",
			   	url: docRoot+"/videos/dialog_reportVideo.php",
			   	data: str,
			   	success: function(msg){
			    	//alert( "Data Saved: " + msg );
			    	// If error
			    	if(msg == '0'){
			    		$('#reportVideoFeedback').html('<span class="err">There is an error. Please try again.</span>');
			    	}
			    	else{
			    		$("#dialog_video_reportVideo").dialog('close');
			    	}
			   	}
			 });

			}
		},
		close: function() {
			//clear the feedback
			$('#reportVideoFeedback').val("");
		}
	});
	/***********************End Videos***********************/
	
	
	/***********************Schools**************************/
	/* Delete School Comment*/
	$("#dialog_school_deleteComment").dialog({
		bgiframe: true,
		autoOpen: false,
		width: 380,
		resizable: false,
		draggable: false,
		modal: true,
		buttons: {
			Cancel: function() {
				$(this).dialog('close');
			},
			'Delete Comment': function() {
				var str = $('#deleteCommentForm').serialize();
				var cid = $('#commentID').val();
				$.ajax({
			  	type: "POST",
			   	url: docRoot+"/schools/dialog_deleteComment.php",
			   	data: str,
			   	success: function(msg){
			    	//alert( "Data Saved: " + msg );
			    	// If error
			    	if(msg == '0'){
			    		$('#deleteCommentFeedback').html('<span class="err">There is an error. Please try again.</span>');
			    	}
			    	else{
			    		//remove the comment from DOM
			    		$('[id=Message_container_'+cid+']').remove();
			    		// Clear the add comment feedback
			    		$('#School_tempFeedback').remove();
			    		$("#dialog_school_deleteComment").dialog('close');
			    	}
			   	}
			 });

			}
		},
		close: function() {
			//clear the feedback
			$('#deleteCommentFeedback').val("");
		}
	});
	/***********************End Schools**********************/
	
	
	/***********************Inbox***************************/
	
	/* Search Friend */
	$("#dialog_inbox_to_field").dialog({
		bgiframe: true,
		autoOpen: false,
		width: 550,
		resizable: false,
		draggable: false,
		modal: true,
		buttons: {
			/*Cancel: function() {
				//$('#To_field').html('<i>Select Your Friend</i>');
				//$('#SelectedFriend').html('&nbsp;');
				$(this).dialog('close');
			},
			'Select': function() {
				var str = $('#InboxToForm').serialize();
				$('#To_field').html($('#SelectedFriend').html());
				$("#dialog_inbox_to_field").dialog('close');
			}*/
			Close: function() {
				$(this).dialog('close');
			}
		},
		close: function() {
			//clear the feedback
			$('#deleteInboxFeedback').val("");
		}
	});
	
	//delete mail
	$("#dialog_inbox_deleteMail").dialog({
		bgiframe: true,
		autoOpen: false,
		width: 380,
		resizable: false,
		draggable: false,
		modal: true,
		buttons: {
			Cancel: function() {
				$(this).dialog('close');
			},
			'Delete Mail': function() {
				var str = $('#deleteMailForm').serialize();
				var inbox_id = $('#inboxID').val();
				var act = $('#inboxAction').val();
				
				$.ajax({
			  	type: "POST",
			   	url: docRoot+"/inbox/dialog_deleteMail.php",
			   	data: str,
			   	success: function(msg){
			    	//alert( "Data Saved: " + msg );
			    	// If error
			    	if(msg == '0'){
			    		$('#deleteMailFeedback').html('<span class="err">There is an error. Please try again.</span>');
			    	}
			    	else{
			    		if(act=='redirect')
			    			window.location = docRoot+"/inbox/index.php";
			    		else{
        				$('[id=inboxBox_'+inbox_id+']').remove();
			    			$("#dialog_inbox_deleteMail").dialog('close');
			    		}
			    	}
			   	}
				});
			}
		},
		close: function() {
			//clear the feedback
			$('#deleteMailFeedback').val("");
		}
	});
	
		//delete mail
	$("#dialog_inbox_deleteSentMail").dialog({
		bgiframe: true,
		autoOpen: false,
		width: 380,
		resizable: false,
		draggable: false,
		modal: true,
		buttons: {
			Cancel: function() {
				$(this).dialog('close');
			},
			'Delete Mail': function() {
				var str = $('#deleteSentMailForm').serialize();
				var inbox_id = $('#inboxID').val();
				var act = $('#inboxAction').val();
				
				$.ajax({
			  	type: "POST",
			   	url: docRoot+"/inbox/dialog_deleteSentMail.php",
			   	data: str,
			   	success: function(msg){
			    	//alert( "Data Saved: " + msg );
			    	// If error
			    	if(msg == '0'){
			    		$('#deleteMailFeedback').html('<span class="err">There is an error. Please try again.</span>');
			    	}
			    	else{
        			$('[id=inboxBox_'+inbox_id+']').remove();
			    		$("#dialog_inbox_deleteSentMail").dialog('close');
			    	}
			   	}
				});
			}
		},
		close: function() {
			//clear the feedback
			$('#deleteSentMailFeedback').val("");
		}
	});
	/*******************End Inbox*****************************/
	
});
