function create_gallery(div_id,page)
{
	  
	$.ajax({
		   type: "POST",
		   url: "gallery.php",
		   data:{
				type : "create",
				page : page
		   },
		
				success: function(msg){
					
			   $("#"+div_id).html(msg);
		   }
		 });
	
}

function edit_gallery(div_id,page,id)
{
		
	$.ajax({
		   type: "POST",
		   url: "gallery.php",
		   data:{
				type : "edit",
				gallery_id : id,
				page : page
		   },
		   success: function(msg){
			
			   $("#"+div_id).html(msg);
		   }
		 });
}
function add_artists(galleryid)
{
	
	document.gallery_form.action="artists.php?gallery_id="+galleryid;
	document.gallery_form.submit();
	
}
function add_artwork(galleryid)
{
	
	document.gallery_form.action="art_work.php?gallery_id="+galleryid;
	document.gallery_form.submit();
	
}
function delete_gallery(div_id,page)
{

	var form_obj = eval("document.gallery_form");

	var k = 0;
	var artist_list = new Array();
	var flag = 0;
	
	for(i=0;i<form_obj.elements.length;i++)
	{
		if(form_obj.elements[i].type == "checkbox" && form_obj.elements[i].checked == true)
		{
			artist_list[k++]=form_obj.elements[i].value;
			flag=1;
		}
	}
	
	if(flag == 0)
	{
		alert("Select Gallery to delete");
		return false;
	}
	else
	{
		if((confirmation = confirm("Are you sure to delete the selected item(s)?")) == true)
		{
			document.gallery_form.type.value = "delete";
			document.gallery_form.submit();
		}
	}		
	
}

function delete_images(div_id, section, id, imgname,mode)
{
	var check=confirm("Do you want to delete the selected Image?");
	
	
	
	if(check == true)
	{
		document.getElementById(imgname).src = 'images/loading.gif';
		
		if(mode=="admin"){
		url="gallery.php";
		}
		else{
		url="includes/manage_gallery.php";
		}
		
		$.ajax({
		   type: "POST",
		   url: url,
		   data:{
				type : "delete_image",
				section : section,
				galleryimg_id : id,
				imgname : imgname
				
		   },
		   success: function(msg){
			   $("#"+div_id).html(msg);
		   }
		 });
	}
	
}


function removeFileTab(TblName, ImgCount)
{
	var check=confirm("Are you sure you want to remove this row?");

	if(check == true)
	{
		oTBody = document.getElementById(TblName);
		var lastRow = oTBody.rows.length;

		oTBody.deleteRow(lastRow-1);

		document.getElementById(ImgCount).value = document.getElementById(ImgCount).value - 1;
	}
}

 
 
function addFileTab(TblName, ImgCount, eleName, count_images)
{
	oTBody = document.getElementById(TblName);
	var total = parseInt(document.getElementById(ImgCount).value) + parseInt(document.getElementById(count_images).value);
	
	if(total >= 11)
	{
	return false;
	}
	var lastRow = oTBody.rows.length;     
	
	oTBody.insertRow(lastRow);
	var oinput = document.createElement("input");
	oinput.setAttribute("type", "file");
	oinput.setAttribute("name", eleName+lastRow);
	oinput.setAttribute("id", eleName+lastRow);
	oinput.setAttribute("class", "txtbox");
	oinput.setAttribute("size", "40");
	oTBody.rows[lastRow].insertCell(0);
	oTBody.rows[lastRow].cells[0].align = "left";

	oTBody.rows[lastRow].cells[0].className="darktd";
	oTBody.rows[lastRow].cells[0].appendChild(oinput);

	var oinput = document.createElement("a");
	oinput.setAttribute("href", "javascript:removeFileTab('"+TblName+"', '"+ImgCount+"')");
	oinput.appendChild(document.createTextNode("Delete"));
	oTBody.rows[lastRow].insertCell(1);
	oTBody.rows[lastRow].cells[1].align = "left";
	oTBody.rows[lastRow].cells[1].appendChild(oinput);

	document.getElementById(ImgCount).value = parseInt(document.getElementById(ImgCount).value) + 1;

}
