// JavaScript Document
function doNav(theUrl) {
	document.location.href = theUrl;
}
function changeCursor(tableRow, highLight) {
	if (highLight) {
		tableRow.style.cursor="pointer";
	}
}
function accountHover(tableRow, highLight) {
	if (highLight) {
		tableRow.className = "accounthover";
		tableRow.style.cursor="pointer";
	} else {
		tableRow.className = "account";
	}
}
var loader = new Image();
loader.src = 'images/red_loader.gif';
var left = new Image();
left.src = 'images/left.gif';
var right = new Image();
right.src = 'images/right.gif';
function pleaseWait(table,row,cell) {
	//var button = document.getElementById('submitbutton');
	var x=document.getElementById(table).rows[row].cells;
	x[cell].innerHTML='<img src="images/red_loader.gif" align="absbottom"> Please Wait...';
	//button.style.color="#999999";
	//button.disabled=true;
}
function printPage() {
	window.print();
}
function deleteUser(id) {
	if(confirm('Are you sure you want to delete this user?')) {
		doNav('admin_users.php?action=process&section=delete&id='+id);
	}
}
function deleteParagraph(id,page) {
	if(confirm('Are you sure you want to delete this paragraph?')) {
		doNav('page_info.php?action=process&section=delete&id='+id+'&return='+page);
	}
}
function deleteCategory(id) {
	var remove = confirm('This will delete this gallery as well as all photos and categories within this gallery.  This action is unrecoverable. Are you sure you want to delete this gallery?');
	if(remove == true) {
		doNav('photos.php?action=process&section=deletecat&id='+id);	
	}
}
function deleteGallery(id) {
	var remove = confirm('This will delete this gallery as well as all photos and categories within this gallery.  This action is unrecoverable. Are you sure you want to delete this gallery?');
	if(remove == true) {
		doNav('admin_photos.php?action=process&section=deletecat&catid='+id);	
	}
}
function deletePhoto(catid,id) {
	var remove = confirm('You are about to delete this photo from the database.  This action is unrecoverable. Are you sure you want to delete this photo?');
	if(remove == true) {
		doNav('admin_photos.php?action=process&section=deletephoto&catid='+catid+'&id='+id);	
	}
}
function deleteProduct(id) {
	var remove = confirm('This will delete this product from the database.  This action is unrecoverable. Are you sure you want to delete this product?');
	if(remove == true) {
		doNav('admin_shopping.php?action=process&section=delete&id='+id);	
	}
}
function deleteShipping(id) {
	var remove = confirm('This will delete this shipping option from the database.  This action is unrecoverable. Are you sure you want to delete this shipping option?');
	if(remove == true) {
		doNav('admin_shopping.php?action=process&section=deleteship&id='+id);	
	}
}
function deleteCalendar(id) {
	var remove = confirm('This will delete this calendar from the database.  This action is unrecoverable. Are you sure you want to delete this calendar?');
	if(remove == true) {
		doNav('admin_calendars.php?action=process&section=delete&id='+id);	
	}
}
function addPhoto(table, sub_count) {
	var tbl = document.getElementById(table);
	var lastRow = tbl.rows.length;
	var iteration = lastRow - sub_count;
	var a = tbl.insertRow(iteration)
	a.innerHTML='<td align="left" colspan="2"><table width="100%" border="0" cellpadding="0" cellspacing="0" id="photo'+iteration+'"><tr><td colspan="2"><br></td></tr><tr><td width="100" align="right" valign="top">Add an Image:&nbsp;&nbsp;</td><td align="left" valign="top"><input type="file" class="inputfield" name="image[]" id="image'+iteration+'" size="25">&nbsp;&nbsp;&nbsp;<a href="javascript:removeRow(\'photo'+iteration+'\',\'17\');removeRow(\'photo'+iteration+'\',\'16\');removeRow(\'photo'+iteration+'\',\'15\');removeRow(\'photo'+iteration+'\',\'14\');removeRow(\'photo'+iteration+'\',\'13\');removeRow(\'photo'+iteration+'\',\'12\');removeRow(\'photo'+iteration+'\',\'11\');removeRow(\'photo'+iteration+'\',\'10\');removeRow(\'photo'+iteration+'\',\'9\');removeRow(\'photo'+iteration+'\',\'8\');removeRow(\'photo'+iteration+'\',\'7\');removeRow(\'photo'+iteration+'\',\'6\');removeRow(\'photo'+iteration+'\',\'5\');removeRow(\'photo'+iteration+'\',\'4\');removeRow(\'photo'+iteration+'\',\'3\'); removeRow(\'photo'+iteration+'\',\'2\'); removeRow(\'photo'+iteration+'\',\'1\'); removeRow(\'photo'+iteration+'\',\'0\');" class="adminlink"><img src="images/icons/delete.png" align="absbottom" border="0"></a></td></tr><tr><td colspan="2"><img src="images/spacer.gif" width="100%" height="5"></td></tr><tr><td width="100" align="right" valign="top">Caption:&nbsp;&nbsp;</td><td align="left" valign="top"><input type="text" name="desc[]" id="desc'+iteration+'" size="40" class="inputfield"></td></tr><tr><td colspan="2"><img src="images/spacer.gif" width="100%" height="5"></td></tr><tr><td width="100" align="right" valign="top">Keywords:&nbsp;&nbsp;</td><td align="left" valign="top"><textarea name="keywords[]" id="keywords'+iteration+'" cols="40" class="inputfield" rows="8"></textarea></td></tr><tr><td colspan="2"><img src="images/spacer.gif" width="100%" height="5"></td></tr><tr><td width="100" align="right" valign="top">Homepage?:&nbsp;&nbsp;</td><td align="left" valign="top"><select name="homepage[]" id="homepage'+iteration+'" class="inputfield"><option value="yes">Yes</option><option value="no" selected="selected">No</option></select></td></tr><tr><td colspan="2"><img src="images/spacer.gif" width="100%" height="5"></td></tr><tr><td width="100" align="right" valign="top">Gallery?:&nbsp;&nbsp;</td><td align="left" valign="top"><select name="gallery[]" id="gallery'+iteration+'" class="inputfield"><option value="yes">Yes</option><option value="no" selected="selected">No</option></select></td></tr><tr><td colspan="2"><img src="images/spacer.gif" width="100%" height="5"></td></tr><tr><td width="100" align="right" valign="top">Rates?:&nbsp;&nbsp;</td><td align="left" valign="top"><select name="rates[]" id="rates'+iteration+'" class="inputfield"><option value="yes">Yes</option><option value="no" selected="selected">No</option></select></td></tr><tr><td colspan="2"><img src="images/spacer.gif" width="100%" height="5"></td></tr><tr><td width="100" align="right" valign="top">Links?:&nbsp;&nbsp;</td><td align="left" valign="top"><select name="links[]" id="links'+iteration+'" class="inputfield"><option value="yes">Yes</option><option value="no" selected="selected">No</option></select></td></tr><tr><td colspan="2"><img src="images/spacer.gif" width="100%" height="5"></td></tr><tr><td width="100" align="right" valign="top">Contact?:&nbsp;&nbsp;</td><td align="left" valign="top"><select name="contact[]" id="contact'+iteration+'" class="inputfield"><option value="yes">Yes</option><option value="no" selected="selected">No</option></select></td></tr><tr><td colspan="2"><img src="images/spacer.gif" width="100%" height="5"></td></tr><tr><td width="100" align="right" valign="top">Order:&nbsp;&nbsp;</td><td align="left" valign="top"><input type="text" name="order[]" id="order'+iteration+'" size="10" class="inputfield"></td></tr></table><input type="hidden" name="iteration[]" id="iteration'+iteration+'" value="'+iteration+'"></td>';
}
function removeRow(table,row) {
	var tbl = document.getElementById(table);
	tbl.deleteRow(row);
}
function openGallery(catid,photo) {
	var w = document.viewport.getWidth();
	var h = document.viewport.getHeight();
	$('divGallery').setStyle({width: w+'px',height: h+'px'});
	$('galleryBG').setStyle({width: w+'px',height: h+'px'});
	if(document.getElementById('divGallery').style.display == 'none') {
		new Effect.Appear('divGallery',{duration:.5});
		new Effect.Appear('galleryBG');
	}
	var start = w/2;
	var left = start - 225;
	new Effect.Move('loadingFrame',{x:left,y:220,mode:'absolute',duration:0});
	new Effect.Move('galleryPhotoFrame',{x:left,y:50,mode:'absolute',duration:0});
	new Effect.Appear('galleryPhotoFrame',{duration:.5});
	loadThumbs(catid);
	if(photo == '') {
		new Ajax.Request('ajax_gallery.php?catid='+catid,
			 {
				method:'get',
				onSuccess: function(text){
				  var response = text.responseText || "no response text";
				  loadPhoto(response);
				},
				onFailure: function(){ 
					alert('Something went wrong...')
				}
			  });
	} else {
		loadPhoto(photo);
	}
	return false;
}
function closeGallery() {
	new Effect.Fade('divGallery',{duration:.5});
	new Effect.Fade('galleryBG',{duration:.5});	
}
function loadThumbs(catid) {
	if(document.getElementById('galleryThumbs').style.display != 'none') {
		new Effect.Fade('thumbs');
	}
	new Ajax.Request('ajax_thumbs.php?catid='+catid,
		 {
			method:'get',
			onLoading: function(t) {
			  	if(document.getElementById('galleryThumbs').style.display == 'none') {
					new Effect.BlindDown('galleryThumbs',{duration:1.5});
				}
				document.getElementById('galleryThumbs').innerHTML = '<div id="contentLoading" style="display:none;">Loading...<br /><br /><img src="images/loader_gray.gif" width="24" height="24" /></div>';
			  	new Effect.Appear('contentLoading',{duration:.8});
			},
			onSuccess: function(transport){
				new Effect.Fade('contentLoading',{duration:.3});
			 	var response = transport.responseText || "no response text";
				document.getElementById('galleryThumbs').innerHTML = response;
			  	new Effect.Appear('thumbs', { queue: 'end' });
				document.getElementById('galleryTitle').innerHTML = document.getElementById('galleryTitleHolder').innerHTML;
			},
			onFailure: function(){ alert('Something went wrong...') }
		  });
}
var isLoading = false;
var fadeImage = function() {
	new Effect.Fade('loadingFrame');
	$('galleryPhotoFrame').show();
	new Effect.Appear('fadephotolarge');
}
function loadPhoto(id) {
	if(isLoading) {
		isLoading.transport.abort();
	}
	if(document.getElementById('fadephotolarge').style.display != 'none') {
		new Effect.Fade('fadephotolarge');
	}
	new Ajax.Request('ajax_photolarge.php?photoid='+id,
		 {
			method:'get',
			onCreate:function(request) { isLoading = request; },
			onLoading: function() {
				if(document.getElementById('loadingFrame').style.display == 'none') {
					new Effect.Appear('loadingFrame');
				}
			},
			onSuccess: function(text){
			  var response = text.responseText || "no response text";
				$('galleryPhotoFrame').hide();
			  document.getElementById('galleryPhotoFrame').innerHTML = response;
			  document.getElementById('img'+id).onload = fadeImage;
			  isLoading=false;
			},
			onFailure: function(){ alert('Something went wrong...') }
		  });
}
function updateCart() {
	new Event.observe(document,'keypress',function(event) {
		if(event.keyCode == Event.KEY_RETURN) {
			updateShoppingCart();
		}
	});
}
