﻿	getShowBagID = function(){return ShowbagID};
	setShowBagID = function(val){ShowbagID = val};

	var actionAdd = '<a href="javascript:addItem(this)"><img src="/images/buttons/btn-add.gif" width="77px" height="31px" alt="Add" class="addButton"></a>'
	var actionUpdate = '<a href="javascript:updateItem()"><img src="/images/buttons/btn-update.gif" alt="Update" class="addButton"></a>'


	//We must extract the information from the form	
	var ItemID
	var Quantity;
	var ItemDescription;
	var Value;
	var processURL;
		
	var myTable;
	var myTableBody;
	var row;
	var cell;
	var j;
	var textVal;
	var textNode
	
	function getItem(ItemID){
		var processURL = "/admin/ajax/getItem-xml.asp?ItemID="+ItemID
		new Ajax.Request(processURL, {
			method: 'GET',
			requestHeaders: {accept: 'text/html'},
			onSuccess: function(trans) {
				if (trans.responseText) {
					var itemArray = eval(trans.responseText)
					
					//Lets populate form fields
					setFieldText("ItemID",itemArray[0])
					setFieldText("Quantity",itemArray[1])
					setFieldText("ItemDescription",itemArray[2])
					//alert(document.getElementById("ItemDescription").length)
					setFieldText("Value",itemArray[3])
					
					//Lets change the action to update
					document.getElementById("ItemAction").innerHTML=actionUpdate
					setFocus("Quantity")
					
				}else{
					alert("Unable to Get item")
				}
			},
			onFailure: function(){ 
				alert("unable to get item.")
			}
		}); 	
	}

	function addItem(){		
		
		Quantity = getFieldText("Quantity")
		ItemDescription =getFieldText("ItemDescription")
		Value = getFieldText("Value")
		
		if (!checkField(ItemDescription,"Please enter a description")) {return}
		
		var processURL = "/admin/ajax/addItem.asp?Quantity="+encodeURIComponent(Quantity)+"&ItemDescription="+encodeURIComponent(ItemDescription)+"&Value="+encodeURIComponent(Value)+"&ShowbagID="+getShowBagID()
		new Ajax.Request(processURL, {
			method: 'GET',
			requestHeaders: {accept: 'text/html'},
			onSuccess: function(trans) {
				if (trans.responseText > 0) {
					RefreshShowbagList()
				}else{
					alert("Unable to add item")
				}
			},
			onFailure: function(){ 
				alert("unable to update item list")
			}
		}); 
	
		clearForm("formAddItem")
		setFocus("Quantity")
		
			
	}
	
	function addShowbag(){		
			var processURL = "/admin/ajax/updateShowbagHeader.asp?Name="+encodeURIComponent(Name)+"&Price="+encodeURIComponent(Price)+"&Promotion="+encodeURIComponent(Promotion)+"&ShowbagID="+getShowBagID()			
			new Ajax.Request(processURL, {
			method: 'GET',
			requestHeaders: {accept: 'text/html'},
			onSuccess: function(trans) {
				if (trans.responseText.length > 0) {
					setShowBagID(trans.responseText)
				}else{
					alert("Unable to add showbag")
				}
			},
			onFailure: function(){ 
				alert("unable to update item list")
			}
		}); 
			
			
			loadHTTP(processURL,"setShowBagID")
	}
		
	function addLocation(){		
		
		LocationID = getFieldText("LocationID")
		
		if (!checkField("LocationID","Please enter a description")) {return}
		
			var processURL = "/admin/ajax/addLocation.asp?LocationID="+LocationID+"&ShowbagID="+getShowBagID()	
			new Ajax.Request(processURL, {
				method: 'GET',
				requestHeaders: {accept: 'text/html'},
				onSuccess: function(trans) {
					if (trans.responseText == '') {
						RefreshLocationList()
					}else{
						alert(trans.responseText)
					}
				},
				onFailure: function(){ alert("unable to update location list")}
			}); 			
		//clearForm("formAddItem")
		setFocus("LocationID")
			
		}
	  
	
	function updateItem(){
	//We must extract the information from the form	
			
		ItemID = getFieldText("ItemID")
		Quantity = getFieldText("Quantity")
		ItemDescription =getFieldText("ItemDescription")
		Value = getFieldText("Value")
		
		checkField(ItemDescription,"Please enter a description")
			
		var processURL = "/admin/ajax/updateItem.asp?ItemID="+ItemID+"&Quantity="+encodeURIComponent(Quantity)+"&ItemDescription="+encodeURIComponent(ItemDescription)+"&Value="+encodeURIComponent(Value)+"&ShowbagID="+getShowBagID()
		new Ajax.Request(processURL, {
			method: 'GET',
			requestHeaders: {accept: 'text/html'},
			onSuccess: function(trans) {
				if (trans.responseText > 0) {
					RefreshShowbagList()
				}else{
					alert("Unable to add item")
				}
			},
			onFailure: function(){ 
				alert("unable to update Item")
			}
		}); 
		document.getElementById("ItemAction").innerHTML=actionAdd
		clearForm("formAddItem")
		setFocus("Quantity")
	}  
	
	
	function deleteItem(id){
		if(confirm("Are you sure you want to delete this item?")){

			var processURL = "/admin/ajax/deleteItem.asp?ItemID="+id+"&ShowbagID="+getShowBagID()
			new Ajax.Request(processURL, {
				method: 'GET',
				requestHeaders: {accept: 'text/html'},
				onSuccess: function(trans) {
					if (trans.responseText == 1) {
						RefreshShowbagList()
					}else{
						alert("Unable to delete item")
					}
				},
				onFailure: function(){ alert("unable to update item list")}
			}); 
		}
	}  
	function deleteLocation(id){
		if(confirm("Are you sure you want to delete this location?")){
			
			var processURL = "/admin/ajax/deleteLocation.asp?LocationID="+id+"&ShowbagID="+getShowBagID()
			new Ajax.Request(processURL, {
				method: 'GET',
				requestHeaders: {accept: 'text/html'},
				onSuccess: function(trans) {
					if (trans.responseText == 1) {
						RefreshLocationList()
					}else{
						alert("Unable to delete item")
					}
				},
				onFailure: function(){ alert("unable to update location list")}
			}); 
		}
	} 
	 
function getFile(){

	alert(document.getElementById("image").value)
}

function hidePanel(pName, mode){

	if (mode == 'hide'){
		document.getElementById(pName).className = 'hidePanel';
	}
	if (mode == 'show'){
		document.getElementById(pName).className = 'showPanel';
	}
}
function showbagPanel(mode){

	if (mode == 'hide'){
		document.getElementById("showbagMain").className = 'hidePanel';
	}
	if (mode == 'show'){
		document.getElementById("showbagMain").className = 'showPanel';
	}
}
		
	
function  validateShowbagHeader(val){

	Name = getFieldText("Name")
	Price =getFieldText("Price")
	Promotion = getFieldText("Promotion")

	if(Name == "" || Price == ""){
		alert("Please enter a Name and Price")
		return false;
	}else{
		return true;
	}
}	

function RefreshShowbagList(){
 //URL + queryString to process adding items
	var processURL = "/admin/ajax/getItemList-html.asp?ShowbagID="+getShowBagID()
	new Ajax.Request(processURL, {
		method: 'GET',
		requestHeaders: {accept: 'text/html'},

		onSuccess: function(trans) {
			$('itemTBody').update(trans.responseText);
			if (trans.responseText) {
				$('itemNoRecords').hide();
			}else{
			$('itemNoRecords').show();
			}
		},
		onFailure: function(){ alert("unable to update item list")}
	}); 
}
function RefreshLocationList(){
 //URL + queryString to process adding items
	var processURL = "/admin/ajax/getLocationList-html.asp?ShowbagID="+getShowBagID()
	new Ajax.Request(processURL, {
		method: 'GET',
		requestHeaders: {accept: 'text/html'},

		onSuccess: function(trans) {
			$('locationTBody').update(trans.responseText)
			if (trans.responseText) {
				$('locationNoRecords').hide();
			}
			else{
				$('locationNoRecords').show();
			}
		},
		onFailure: function(){ alert("unable to update item list")}
	}); 
}

//============================  submit newsletter subscriber ==========================================================
function ajaxSubscriber(subscriberName, subscriberEmail)
{
	var url;
	url = '/register.asp?ajax-submitted=true&subscriberName=' + escape(subscriberName) + '&subscriberEmail=' + escape(subscriberEmail)
	new Ajax.Updater('container', url,{onCreate:function(){ajaxOnStart()},
										onComplete:function(){ajaxOnComplete()}, evalScripts:false,method:'post'});   	
}

function ajaxKidSubscriber(subscriberName, subscriberEmail, agree1, agree2)
{
	var url;
	url = '/kidspot/default.asp?ajax-submitted=true&subscriberName=' + escape(subscriberName) + '&subscriberEmail=' + escape(subscriberEmail) + '&agree1=' + escape(agree1) + '&agree2=' + escape(agree2)
	new Ajax.Updater('container', url,{onCreate:function(){ajaxOnStart()},
										onComplete:function(){ajaxOnComplete()}, evalScripts:false,method:'post'});   	
}

function ajaxOnStart()
{	
	document.getElementById('container').className			= 'setOpacityOn';
	document.getElementById('AjaxLoading').style.display	= 'block';
}
function ajaxOnComplete()
{
	document.getElementById('AjaxLoading').style.display	= 'none';
	document.getElementById('container').className			= 'setOpacityOff';
}

