


// dnn_ctr559_CFD_cfd12
// dnn_ctr559_CFD_lblIntro
// dnn_ctr558_CFD_lblIntro
// dnn_ctr558_CFD_cfd8

// our namspace: EC.Alt
if (EC==undefined) var EC = {};
if (EC.Alt==undefined) EC.Alt = {};

EC.Alt.SwapFeedbackIntroTextIntoMessageBody = function () {

	// Finds a Feedback module, and then takes the text from the 'Intro' span
	// and puts it in the main message body.

	// Intro span will have an ID of something like 'dnn_ctr28_CFD_lblIntro' or 'dnn_ctr559_CFD_lblIntro'
	// It's only the number in the middle that changes, and that is the module number - so we search for that first.
	
	// The message body could be 'dnn_ctr28_CFD_cfd12' or 'dnn_ctr559_CFD_cfd8' 
	// where the middle number is the module number, and the end one is anything

	// The module will have an empty <a> tag with an id of just  a plain number...
	var allAnchorTags = dnn.dom.getByTagName("a");
	
	var agt=navigator.userAgent.toLowerCase();
	
	var ie = dnn.dom.browser.isType(dnn.dom.browser.InternetExplorer); 
	var chrome = (agt.indexOf('chrome') != -1)
	
	var ctlId, introId, foundId;
	
	for (var a in allAnchorTags) {

		if (ie) {
			ctlId = a;
		} else {
			var tag = allAnchorTags[a];
			ctlId = tag.name;
		}
		
		if (isFinite(ctlId)) {
			// look for an intro span element
			introId = 'dnn_ctr' + ctlId + '_CFD_lblIntro';
			if ($(introId)) {
				foundId = ctlId;
				break;
			}
		}
	}

	
	if (foundId) {

		// get the intro span's contents
		var intro = $(introId);
		var msg = intro.innerHTML;
		// and tidy line breaks
		msg = msg.replace(/<br>/gi,'\n');
		// and remove the span now we've got what we want
		dnn.dom.removeChild(intro);

		// find message body textarea - by regexing the name of all textareas in page
		var msgBodyNameLike = 'dnn.ctr' + foundId + '.CFD.cfd\\d*';
		var allTextAreas = dnn.dom.getByTagName("textarea");
		var tagName;
		for (var ta in allTextAreas) {
			if (ie) {
				tagName = ta;
			} else {
				tag = allTextAreas[ta];
				tagName = tag.name;
			}
			if (tagName != undefined && tagName.match(msgBodyNameLike)) {
				// got it
				var textarea = allTextAreas[ta];
				textarea.value = msg;
				break;
			}
		}
			
	}
}();
