YAHOO.namespace("example.container");
YAHOO.util.Event.onDOMReady(initialise);

function initialise() {

	YAHOO.example.container.panel1 = new YAHOO.widget.Panel("panel1", { width:"400px", visible:false, constraintoviewport:false, zIndex:99, modal:true, close:true, fixedcenter:true } );
	YAHOO.example.container.panel1.render(document.body);
	YAHOO.util.Event.addListener("show1", "click", YAHOO.example.container.panel1.show, YAHOO.example.container.panel1, true);
}


function addEvent(elm, evType, fn, useCapture) {
		if (elm.addEventListener) {
			elm.addEventListener(evType, fn, useCapture);
			return true;
		}
		else if (elm.attachEvent) {
			var r = elm.attachEvent('on' + evType, fn);
			return r;
		}
		else {
			elm['on' + evType] = fn;
		}
	}


function getSelectValue(iSelectObj) {
		if (iSelectObj) {
			for (var i = 0; i < iSelectObj.options.length; i=i+1) {
				var opt = iSelectObj.options[i];
				if (opt.selected) {
					return opt.value;
				}
			}
		}
		
		return "";
}

function processTellFriend() {
	//var name = document.getElementById("FirstName");
	//var email = document.getElementById("EmailAddress");
	handleTellFriendSubmission('TELLFRIEND')
}
function clearField(iField) {
	var theField = document.getElementById(iField);
	if (theField.value.length > 4 && theField.value.substring(0,4) == "Type")		{
		theField.value = "";
	}
}

function handleTellFriendSubmission(iCode, iElementIds) {
	var invalidElId = validateTellFriendInfo(['EmailAddress']);
	if (invalidElId) {
		showErrorMessage(invalidElId);
	} else {
		handleSubmission("TELLFRIEND", ['EmailAddress','ShopId','SendName'], handleCallBack);
	}
}
	
function validateTellFriendInfo(iElementIds) {
	for (var i = 0; i < iElementIds.length; i=i+1) {
		var elId = iElementIds[i];
		if (elId) {
			var el = document.getElementById(elId);
			if (el) {
				if (!el.value || "Type email address here" == el.value || "Type your name here" == el.value) {
					return elId;
				}
			}
		}
	}
	return null;
}
	
function showErrorMessage(iElementId) {
	var elLbl = document.getElementById(iElementId + "Lbl");
	alert("Please supply a value for '" + elLbl.innerText + "'");
}
	 
function handleCallBack(iActionStatus) {
	alert(iActionStatus.actionMessage);
	
	if (iActionStatus.actionSuccessful) {
		document.forms['TellFriend'].reset();
	}

}

