function coupon(index)
{	
	var mytime= "&scw="+new Date().getTime();
    var url = "loadCoupon?index=" + escape(index) + mytime;
    
    var callback = {
		success: function(o) {
		
			// Parsing JSON strings can throw a SyntaxError exception, so we wrap the call
			// in a try catch block
			try {
    			var myObject = YAHOO.lang.JSON.parse(o.responseText);
    			if(myObject.error==null)
    			{
   	     			var couponTitle = document.getElementById('couponTitle');
    	    		var couponDescription = document.getElementById('couponDescription');
    	    		var couponIndex = document.getElementById('couponIndex');
        			couponTitle.value=myObject.couponTitle;
        			couponDescription.value=myObject.couponDescription;
        			couponIndex.value=myObject.couponIndex;
       			}
			}
			catch (e) {
    			displayErrorAlert();
			}
		},
		
		failure: function(o) {
			displayErrorAlert();
			}
	}
	 
    var transaction = YAHOO.util.Connect.asyncRequest('GET', url, callback); 
}

function displayErrorAlert()
{
	alert("Unexpected Problem....PLEASE send an email to Service@StoryCreekWeb.com to report this message.  Please refresh this screen so you can see what was saved in the database prior to the error."); //FAILURE
}

function saveCoupon()
{
	alert("in save coupon");
	var url = "saveCoupon"; 

	var callback = {
		success: function(o) {
			// If we got here, the coupon database was already updated.
			// The coupons session object was also updated.
			
			// Update the Coupon Edit buttons. Get these values from the JSON object which was returned.
			var myObject = YAHOO.lang.JSON.parse(o.responseText);
			
			var couponButton0 = document.getElementById("couponButton0");
			var couponButton1 =	document.getElementById("couponButton1");
			var couponButton2 =	document.getElementById("couponButton2");			

			couponButton0.value = myObject.couponButton0;
			couponButton1.value = myObject.couponButton1;
			couponButton2.value = myObject.couponButton2;
		},
		failure: function(o) {
			displayErrorAlert();
		}
	}
	
	var formObject = document.getElementById('submitCouponForm'); 
	YAHOO.util.Connect.setForm(formObject);
	var transaction = YAHOO.util.Connect.asyncRequest('POST', url, callback, null); 
}


