//Global Objects
var ie=document.all;
var ns6=document.getElementById && !document.all;

if (ie||ns6) var modaliFrameObj=document.getElementById("modaliFrame");
if (ns6) var modaliFrameDoc = modaliFrameObj.contentDocument.location;
if (ie) var modaliFrameDoc = modaliFrameObj.document.location;

ajaxChangesMade = '';
var adTipEnabled2 = adTipEnabled;
var quantity_g = 0;

/******************************************
**********************galleryEditProperties
******************************************/
function galleryEditProperties(galleryid) {
	OpenPleaseWait();
	hidetip();
	adTipEnabled = false;
	if (ns6) modaliFrameDoc.replace('/includes/gallery/galleryProperties.php?galleryid=' + galleryid);
	if (ie) modaliFrameObj.src = "/includes/gallery/galleryProperties.php?galleryid=" + galleryid;
	return false;
}

/******************************************
******************************galleryCreate
******************************************/
function galleryCreate(parentid) {
	OpenPleaseWait();
	hidetip();
	adTipEnabled = false;
	if (ns6) modaliFrameDoc.replace('/includes/gallery/galleryCreate.php?parentid=' + parentid);
	if (ie) modaliFrameObj.src = "/includes/gallery/galleryCreate.php?parentid=" + parentid;
	return false;
}

/******************************************
*****************************galleryRestore
******************************************/
function galleryRestore(galleryid) {
	OpenPleaseWait();
	hidetip();
	adTipEnabled = false;
	if (ns6) modaliFrameDoc.replace('/includes/gallery/galleryRestore.php?galleryid=' + galleryid);
	if (ie) modaliFrameObj.src = "/includes/gallery/galleryRestore.php?galleryid=" + galleryid;
	return false;
}

/******************************************
*******************************galleryPurge
******************************************/
function galleryPurge(galleryid) {
	OpenPleaseWait();
	hidetip();
	adTipEnabled = false;
	if (ns6) modaliFrameDoc.replace('/includes/gallery/galleryPurge.php?galleryid=' + galleryid);
	if (ie) modaliFrameObj.src = "/includes/gallery/galleryPurge.php?galleryid=" + galleryid;
	return false;
}

/******************************************
********************************photoCreate
******************************************/
function photoCreate(galleryid) {
	OpenPleaseWait();
	hidetip();
	adTipEnabled = false;
	if (ns6) modaliFrameDoc.replace('/includes/gallery/photoCreate.php?galleryid=' + galleryid);
	if (ie) modaliFrameObj.src = "/includes/gallery/photoCreate.php?galleryid=" + galleryid;
	return false;
}

/******************************************
****************************photoProperties
******************************************/
function photoProperties(galleryid) {
	OpenPleaseWait();
	hidetip();
	adTipEnabled = false;
	if (ns6) modaliFrameDoc.replace('/includes/gallery/photoProperties.php?photoid=' + galleryid);
	if (ie) modaliFrameObj.src = "/includes/gallery/photoProperties.php?photoid=" + galleryid;
	return false;
}

/******************************************
****************************photoSetDefault
******************************************/
function photoSetDefault(galleryid) {
	OpenPleaseWait();
	hidetip();
	adTipEnabled = false;
	if (ns6) modaliFrameDoc.replace('/includes/gallery/photoSetDefault.php?photoid=' + galleryid);
	if (ie) modaliFrameObj.src = "/includes/gallery/photoSetDefault.php?photoid=" + galleryid;
	return false;
}

/******************************************
***********************************itemMove
******************************************/
function itemMove(galleryid) {
	OpenPleaseWait();
	hidetip();
	adTipEnabled = false;

	// Check for multiple entries
	var selected=getSelected();
	
	if (selected != "" & selected.indexOf(galleryid) != -1) {
//		alert('Do something with all the selected stuff');
		var url="/includes/gallery/itemMove.php?itemid=" + selected;
	} else {	
		var url="/includes/gallery/itemMove.php?itemid=" + galleryid;
	}

	if (ns6) modaliFrameDoc.replace(url);
	if (ie) modaliFrameObj.src = url;

	return false;
}

/******************************************
***********************************itemCopy
******************************************/
function itemCopy(galleryid) {
	OpenPleaseWait();
	hidetip();
	adTipEnabled = false;

	// Check for multiple entries
	var selected=getSelected();
	
	if (selected != "" & selected.indexOf(galleryid) != -1) {
		var url="/includes/gallery/itemCopy.php?itemid=" + selected;
	} else {	
		var url='/includes/gallery/itemCopy.php?itemid=' + galleryid;
	}

	if (ns6) modaliFrameDoc.replace(url);
	if (ie) modaliFrameObj.src = url;

	return false;
}

/******************************************
***********************************itemSort
******************************************/
function itemSort(galleryid,how) {
	OpenPleaseWait();
	hidetip();
	adTipEnabled = false;
	if (ns6) modaliFrameDoc.replace('/includes/gallery/itemSort.php?itemid=' + galleryid + "&how=" + how);
	if (ie) modaliFrameObj.src = "/includes/gallery/itemSort.php?itemid=" + galleryid + "&how=" + how;
	return false;
}

/******************************************
******************************itemRemove
******************************************/
function itemRemove(itemid) {
	OpenPleaseWait();
	hidetip();
	adTipEnabled = false;
	
	// Check for multiple entries
	var selected=getSelected();
	
	if (selected != "" & selected.indexOf(itemid) != -1) {
		var url='/includes/gallery/itemRemove.php?itemid=' + selected;
	} else {	
		var url='/includes/gallery/itemRemove.php?itemid=' + itemid;
	}
	if (ns6) modaliFrameDoc.replace(url);
	if (ie) modaliFrameObj.src = url;
	return false;
}

/******************************************
**********************************addToCart
******************************************/
function addToCartResp(http_request) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			if (http_request.responseText == 'true') {
				document.getElementById('infoDialogBody').innerHTML = "Item added to your purchase list.";
				dialogActivate('info','Information',300,1);
				document.getElementById('cart_item_count').value = parseInt(document.getElementById('cart_item_count').value) + parseInt(quantity_g);
				var cartitems = document.getElementById('cart_item_count').value;
				document.getElementById('order1').innerHTML = "Confirm Order (" + cartitems + (cartitems == 1?" item)":" items)");
				document.getElementById('order2').innerHTML = "Confirm Order (" + cartitems + (cartitems == 1?" item)":" items)");
			} else {
				document.getElementById('errorDialogBody').innerHTML = "There was a problem adding your item to the purchase list.  Response from server:<br><pre>" + http_request.responseText + "</pre>";
				dialogActivate('error','Error',400,1);
			}
		} else {
			document.getElementById('errorDialogBody').innerHTML = "There was a communication error with the server.  Please try again later.<br>If the problem still persists please contact us at: <a href=\"mailto:bugs@photo-genesis.net\" class=\"errorDialogLink\">bugs@photo-genesis.net</a> Error Code: " + http_request.status;
			dialogActivate('error','Internal Error',500,1);
		}
		ClosePleaseWait();
		adTipEnabled = adTipEnabled2;
	}
}

function addToCart(itemid,varient,quantity) {
	OpenPleaseWait();
	hidetip();
	adTipEnabled = false;
	quantity_g = quantity;
	var serverRequest = makeRequest("/includes/ecommerce/addtocart.php?itemid=" + itemid + "&varid=" + varient + "&quantity=" + quantity);
	serverRequest.onreadystatechange = function() { addToCartResp(serverRequest,quantity); };
	return false;
}

/******************************************
*****************************setFeaturedArtist
******************************************/
function setFeaturedArtistResp(http_request) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			if (http_request.responseText == '<xml><ok></ok></xml>') {
				document.getElementById('infoDialogBody').innerHTML = "This gallery has been set as the Featured Artist gallery.";
				dialogActivate('info','Information',400,1);
			} else {
				document.getElementById('errorDialogBody').innerHTML = "There was a problem.  Response from server:<br><pre>" + http_request.responseText + "</pre>";
				dialogActivate('error','Error',400,1);
			}
		} else {
			document.getElementById('errorDialogBody').innerHTML = "There was a communication error with the server.  Please try again later.<br>If the problem still persists please contact us at: <a href=\"mailto:bugs@photo-genesis.net\" class=\"errorDialogLink\">bugs@photo-genesis.net</a> Error Code: " + http_request.status;
			dialogActivate('error','Internal Error',500,1);
		}
		ClosePleaseWait();
		adTipEnabled = adTipEnabled2;
	}
}

function setFeaturedArtist(galleryid) {
	OpenPleaseWait();
	hidetip();
	adTipEnabled = false;
	var serverRequest = makeRequest("/includes/gallery/setfeaturedartist.php?galleryid=" + galleryid);
	serverRequest.onreadystatechange = function() { setFeaturedArtistResp(serverRequest); };
	return false;
}

/******************************************
*****************************setFeaturedSeries
******************************************/
function setFeaturedSeriesResp(http_request) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			if (http_request.responseText == '<xml><ok></ok></xml>') {
				document.getElementById('infoDialogBody').innerHTML = "This gallery has been set as the Featured Series gallery.";
				dialogActivate('info','Information',400,1);
			} else {
				document.getElementById('errorDialogBody').innerHTML = "There was a problem.  Response from server:<br><pre>" + http_request.responseText + "</pre>";
				dialogActivate('error','Error',400,1);
			}
		} else {
			document.getElementById('errorDialogBody').innerHTML = "There was a communication error with the server.  Please try again later.<br>If the problem still persists please contact us at: <a href=\"mailto:bugs@photo-genesis.net\" class=\"errorDialogLink\">bugs@photo-genesis.net</a> Error Code: " + http_request.status;
			dialogActivate('error','Internal Error',500,1);
		}
		ClosePleaseWait();
		adTipEnabled = adTipEnabled2;
	}
}

function setFeaturedSeries(galleryid) {
	OpenPleaseWait();
	hidetip();
	adTipEnabled = false;
	var serverRequest = makeRequest("/includes/gallery/setfeaturedseries.php?galleryid=" + galleryid);
	serverRequest.onreadystatechange = function() { setFeaturedSeriesResp(serverRequest); };
	return false;
}

/******************************************
**************************userCreateGallery
******************************************/
/*
function userCreateGalleryResp(http_request) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			if (http_request.responseText == 'true') {
				document.getElementById('infoDialogBody').innerHTML = "Gallery successfully created.";
				dialogActivate('info','Information',300,1);
			} else {
				document.getElementById('errorDialogBody').innerHTML = "There was a problem creating the gallery.  Response from server:<br><pre>" + http_request.responseText + "</pre>";
				dialogActivate('error','Error',400,1);
			}
		} else {
			document.getElementById('errorDialogBody').innerHTML = "There was a communication error with the server.  Please try again later.<br>If the problem still persists please contact us at: <a href=\"mailto:bugs@photo-genesis.net\" class=\"errorDialogLink\">bugs@photo-genesis.net</a>";
			dialogActivate('error','Internal Error',500,1);
		}
		ClosePleaseWait();
		adTipEnabled = adTipEnabled2;
		callUserAdmin();
	}
}

function userCreateGallery(userid) {
	OpenPleaseWait();
	hidetip();
	adTipEnabled = false;
	var serverRequest = makeRequest("/userCreateGallery.php?userid=" + userid);
	serverRequest.onreadystatechange = function() { userCreateGalleryResp(serverRequest); };
	return false;
}
*/



/******************************************
************************************Generic
******************************************/
/*
function callMainPageResp(http_request) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			document.getElementById("admin_div").innerHTML = http_request.responseText;
		} else {
			document.getElementById('errorDialogBody').innerHTML = "There was a communication error with the server.  Please try again later.<br>If the problem still persists please contact us at: <a href=\"mailto:bugs@photo-genesis.net\" class=\"errorDialogLink\">bugs@photo-genesis.net</a>";
			dialogActivate('error','Internal Error',500,1);
		}
	}
}

function callMainPage() {
	if (ajaxChangesMade == '') {
		var serverRequest = makeRequest("admin/admin_main.php");
		serverRequest.onreadystatechange = function() { callMainPageResp(serverRequest); };
	} else {
		document.getElementById('infoDialogBody').innerHTML = "You've made changes to this screen which will be lost if you continue.<br>Continue anyway?<br><center><input type=\"submit\" value=\"Yes\" onclick=\"ajaxChangesMade=''; dialogClose('info'); callMainPage();\">&nbsp;&nbsp;&nbsp;<input type=\"submit\" value=\"No\" onclick=\"dialogClose('info');\"></center>";
		dialogActivate('info','Alert!',500,0);
	}
	return false;
}
*/
