﻿/* Alfi CMS Global Javascript Functions
-------------------------------------------------------------
*/

function deleteConfirm(file,title) { //v2.0
  test = confirm("Are You Sure you want to delete this item?");
  if (test==true) {
  	  location = file;
  }
}

function optionConfirm(file,option) { //v2.0
  test = confirm("Are You Sure you want "+option+"?");
  if (test==true) {
  	  location = file;
  }
}

function openHijakDialogue (lid, title, width, height, after_function_name) {
	var widthval = width; 
	var heightval = height; 
	if (typeof width === 'undefined') widthval = 500;
	if (typeof height === 'undefined') heightval = 300;
	
	$("#dialog").load($('#'+lid).attr('rel'), function() { // load remote content from its 'rel' attribute into hidden div
            $(this)
              .dialog('destroy') // destroy dialog widget (if exists)
              .dialog({ // and recreate it with following options
                title: title,
				height: heightval, 
				width: widthval, 
				zIndex: 10000, 
                open: function() { $(this).hijack() }, 
				close: function() {
					if (typeof after_function_name !== 'undefined') {
		   				eval(after_function_name); 
					} else { 
						// show_loading(); location.reload(); 
					}
				}
              });
	});
}

function ajaxDeleteItem(resulterid, datetype, id, after_function_name) {
	var resultMsg = "";
	
	var userConfirm = confirm("Are you sure you want to delete this item?");
	if (userConfirm==true) {
	
		$.ajax({
		   type: "GET",
		   url: "deleteRecord.php",
		   data: "type="+datetype+"&id="+id,
		   beforeSend: function() {
			$('#'+resulterid).after('<div id="tmp-'+resulterid+'" class="quick_info"><img src="img/ajax-loader.gif" align="absmiddle"> Loading... please wait.<div>');
			//alert("type="+datetype+"&id="+id);
		   }, 
		   success: function(msg){
			 $('#tmp-'+resulterid).html(msg);
			 resultMsg = msg;
		   }, 
		   error: function (XMLHttpRequest, textStatus, errorThrown) {
			 $('#tmp-'+resulterid).html("An error has occured while processing your request! <br>Type: " + errorThrown);
		   },
		   complete: function () { 
				$('#tmp-'+resulterid).fadeOut(20000);
	
				if (resultMsg.indexOf('Delete Successul!') != -1)  {
					// delete was a success
					if (typeof after_function_name !== 'undefined') {
						eval(after_function_name); 
					}
				}
		   }
		   
		});

	}
	
}

function ajaxUpdatePubStatus(switch_id, datetype, id, status) {
	var resultMsg = "";
	
		$.ajax({
		   type: "GET",
		   url: "ajax_publish_status.php",
		   data: "type="+datetype+"&id="+id+"&status="+status,
		   success: function(msg){
			 resultMsg = msg;
		   }, 
		   complete: function () { 
				if (resultMsg.indexOf('Update Successul!') == -1)  {
					// update was a not success
					$('#'+switch_id).trigger('resize');
					$('#'+switch_id).after('<div id="tmp-'+switch_id+'" class="quick_info" style="width: 80px;">Could not update status<div>'+ resultMsg);
					$('#tmp-'+switch_id).fadeOut(10000);
				} 
		   }
		});
}

