RD.Podcast.Base = function(){
	return this;
}

RD.Podcast.Base.REPLACE_CHARS = [
	["&", "&amp;"]
	,["<", "&lt;"]
	,[">", "&gt;"]
	,["'", "&apos;"]
	,["‘", "&apos;"]
	,["’", "&apos;"]
	,["\"", "&quot;"]
	,["“", "&quot;"]
	,["”", "&quot;"]
];

RD.Podcast.Base.getXmlNodeByType = function(aNode, aNodeType){
	aNodeType = (aNodeType != null)?aNodeType:1;
	var vChildNodes = [];
	var vItemNode = null;
	for(var n=0;n<aNode.childNodes.length;n++){
		vItemNode = aNode.childNodes.item(n);
		if(vItemNode.nodeType == aNodeType){
			vChildNodes.push(vItemNode);
		}
	}
	
	return vChildNodes;
}

//please override
RD.Podcast.Base.formInputs = [];

RD.Podcast.Base.renderInput = function(aParentNode, aParams){
	var vDiv = RD.XHTML.NodeHelper.createNode("div", aParentNode, {
			classname:"form"
			,renderedinput:1
		}
	);
	
	var vRequiredClass = String.empty;
	if(aParams.isRequired){
		vRequiredClass = "required";
		RD.XHTML.NodeHelper.createNode("span", vDiv, {
				classname:vRequiredClass
			}
			,"\u2022"
		);
	}
	
	var vLabelId = aParams.id.replace("txt", "lbl");
	vLabelId = vLabelId.replace("sel", "lbl");

	var vLabel = RD.XHTML.NodeHelper.createNode("label", vDiv, {
			classname:"form"
			,title:aParams.title
			,id:vLabelId
		}
		,aParams.label
	);
	//IE doesn't like the for attribute on an object sooooo set it here
	vLabel.setAttribute("for", aParams.id);
	
	RD.XHTML.NodeHelper.createNode("br", vDiv);
	
	if(aParams.isRequired){
		if(aParams.validationNode){
			vDiv.appendChild(aParams.validationNode);
		}
		else{
			RD.XHTML.NodeHelper.createNode("div", vDiv, {
					id:aParams.id.replace("txt", "rfv")
					,classname:"validation hidden"
					,defaultValue:aParams.value
					,inputId:aParams.id
					,validationType:"required"
					,isEnabled:aParams.isEnabled
				}
				,aParams.label + " is required"
			);
		}
	}

	var vHelpStyle = String.empty;
	var vInputClass = aParams.classname?aParams.classname:"form large " + vRequiredClass;
	var vInput = null;
	var vTabIndex = -1;
	switch(aParams.type){
		case "input":
			vInput = RD.XHTML.NodeHelper.createNode(aParams.type, vDiv, {
					name:aParams.id
					,id:aParams.id
					,classname:vInputClass
					,type:"text"
					,value:aParams.value
					,boundNode:aParams.boundNode
					,highlight:"true"
					,maxlength:aParams.maxlength ? aParams.maxlength : 255
					,tabindex:vTabIndex
				}
			);

			break;
		case "textarea":
			vInput = RD.XHTML.NodeHelper.createNode(aParams.type, vDiv, {
					name:aParams.id
					,id:aParams.id
					,classname:vInputClass
					,rows:aParams.rows
					,cols:aParams.cols
					,boundNode:aParams.boundNode
					,highlight:"true"
					,maxlength:aParams.maxlength ? aParams.maxlength : 255
					,tabindex:vTabIndex
				}
			);
			
			vHelpStyle = "position:relative;top:-55px;";
			break;
		case "select":
			vInput = RD.XHTML.NodeHelper.createNode(aParams.type, vDiv, {
					name:aParams.id
					,id:aParams.id
					,classname:"form large " + vRequiredClass
					,style:"width:196px;"
					,value:aParams.value
					,dataFilePath:aParams.dataFilePath
					,onchange:aParams.onchange
					,highlight:"true"
					,tabindex:vTabIndex
				}
			);
			
			RD.XHTML.NodeHelper.createNode("option", vInput, {
					value:"-1"
				}
				,"--Select--"
			);

			break;
	}

	RD.XHTML.NodeHelper.createNode("text", vDiv, {}, "\u00A0");
	
	RD.XHTML.NodeHelper.createNode("img", vDiv, {
			width:"16"
			,height:"16"
			,src:"images/question-out.png"
			,classname:"question"
			,alt:"Question Mark"
			,title:""
			,info:aParams.description
			,style:vHelpStyle
		}
	);
	
	if(vInput){
		//this.formInputs.push(vInput);
	}
};

RD.Podcast.Base.prototype.constructor = RD.Podcast.Base;

//can override
RD.Podcast.Base.prototype.init = function(aFormat, aPodcastGuid){
	this.control = {
		filename:String.empty
		,format:aFormat
	};

	this.title = String.empty;
	this.link = String.empty;
	this.description = String.empty;
	this.language = String.empty;
	this.copyright = String.empty;
	
	this._episodes = new Array();
	this._channelNode = null;
	this._selectedEpisodeNode = null;
	this._channelInputs = [];
	this._inputCount = 0;
	this._guid = (!isNull(aPodcastGuid) && aPodcastGuid.length > 0) ? aPodcastGuid : RD.XHTML.getGuId();
	
	this._callbackObject = null;
	this._callbackFunction = null;
};

RD.Podcast.Base.prototype.getGuId = function(){
	return this._guid;
};

RD.Podcast.Base.prototype.setGuId = function(vGuId){
	this._guid = vGuId;
};

RD.Podcast.Base.prototype.getFilename = function(){
	return this.control.filename;
};

RD.Podcast.Base.prototype.setFilename = function(aFilename){
	this.control.filename = aFilename;
};

RD.Podcast.Base.prototype.getFormat = function(){
	return this.control.format;
};

RD.Podcast.Base.prototype.setFormat = function(aFormat, evt){
	evt = evt?evt:window.event;
	if(!isNull(evt)){
		var vTarget = evt.target ? evt.target : evt.srcElement;
		var vRblFormat = vTarget.form[vTarget.name];
	
		var vSelectedFormat = vTarget.value;
	
		if( this.getFormat() != vSelectedFormat){
			var vSetFormat = confirm("Are you sure you want to change the format of your podcast?\nChanging your podcast format could cause irreversible data loss.");
	
			if(vSetFormat){
				var vPodcastForm = RD.Podcast.Form.getManager();
				vPodcastForm.selectedFormat = RD.Podcast.Config.formats[vSelectedFormat];
				vPodcastForm.loadFormatClass();
			}
			else{
				vRblFormat[this.getFormat()].checked = true;
			}
		}
	}
	else if(!isNull(aFormat)){
		this.control.format = aFormat;
	}
};

RD.Podcast.Base.prototype.getEpisode = function(aIndex){
	return this._episodes[aIndex];
};

RD.Podcast.Base.prototype.setEpisodes = function(aEpisodes){
	this._episodes = aEpisodes;
};

RD.Podcast.Base.prototype.getEpisodes = function(){
	return this._episodes;
};

RD.Podcast.Base.prototype.addEpisode = function(){
	var vEpisode = null;
	
	var vDivEpisodes = $("divEpisodes");
	var vEpisodeTitle = $("txtEpisodeTitle");
	var vMediaFilename = $("txtMediaFilename");
	var vEpisodePublishDate = $("txtEpisodePublishDate");
	var vMediaLength = $("txtMediaLength");
	var vEpisodeDescription = $("txtEpisodeDescription");

	var vIndex = this.getSelectedNodeIndex();

	if(vIndex > -1){
		this._selectedEpisodeNode.firstChild.nodeValue = vEpisodeTitle.value.trim();
		this._selectedEpisodeNode.title = vEpisodeDescription.value.trim();
		
		this.updateEpisode(vIndex, vEpisodeTitle.value.trim(), vEpisodePublishDate.value.trim(), {url:vMediaFilename.value.trim(), length:vMediaLength.value.trim()}, vEpisodeDescription.value.trim());
	}
	else{
		var vDivEpisodes = $("divEpisodes");
		if(this._episodes.length > 8){
			vDivEpisodes.className = "episodes episodes-small";
		}
		else{
			vDivEpisodes.className = "episodes";
		}
		
		var vANode = RD.XHTML.NodeHelper.createNode("a", vDivEpisodes, {
				href:"javascript://"
				,className:"episode"
				,title:vEpisodeDescription.value.trim()
			}
			,vEpisodeTitle.value.trim()
		);
		
		vANode.onclick = function(evt){
			RD.Podcast.Form.getManager().selectEpisode(evt);
		};

		var vEpisode = new RD.Podcast.Episode.Base({parent:this, title:vEpisodeTitle.value.trim(), pubDate: vEpisodePublishDate.value.trim(), enclosure:{url:vMediaFilename.value.trim(), length:vMediaLength.value.trim()}, description:vEpisodeDescription.value.trim()});
		this._episodes.push(vEpisode);
	}
	
	this.deselectEpisode();

	return vEpisode;
};

RD.Podcast.Base.prototype.getSelectedNodeIndex = function(){
	var vIndex = -1;
	var vEpisodes = this.getEpisodes();
	if(vEpisodes.length){
		if(this._selectedEpisodeNode){
			var vEpisodeNodes = $$($("divEpisodes"), "a");
			for(var n=0;n<vEpisodeNodes.length;n++){
				if(vEpisodeNodes.item(n) == this._selectedEpisodeNode){
					vIndex = n;
					break;
				}
			}
		}
	}

	return vIndex;
};

RD.Podcast.Base.prototype.shiftEpisode = function(aTarget){
	var vEpisodeNodes =  $$($("divEpisodes"), "a");
	var vSelectedIndex = 0;
	for(var n=0;n<vEpisodeNodes.length;n++){
		if(vEpisodeNodes.item(n) == this._selectedEpisodeNode){
			vSelectedIndex = n;
		}
	}
	if(aTarget.id == "btnShiftEpisodeUp"){
		this._selectedEpisodeNode.parentNode.insertBefore(this._selectedEpisodeNode, vEpisodeNodes.item(vSelectedIndex-1));
		
		this.shiftEpisodeValues(true, vSelectedIndex);
	}
	else if(aTarget.id == "btnShiftEpisodeDown"){
		this._selectedEpisodeNode.parentNode.insertBefore(this._selectedEpisodeNode, vEpisodeNodes.item(vSelectedIndex+2));
		this.shiftEpisodeValues(false, vSelectedIndex);
	}
	
	this.selectEpisode(this._selectedEpisodeNode);
};

RD.Podcast.Base.prototype.shiftEpisodeValues = function(aShiftUp, aIndex){
	var vParentNode = this._episodes[aIndex]._episodeXmlNode.parentNode;
	
	if(aShiftUp){
		//shift the node values
		vParentNode.insertBefore(this._episodes[aIndex]._episodeXmlNode, this._episodes[aIndex-1]._episodeXmlNode);
	
		//swap the array values
		this._episodes.swapValues(aIndex, aIndex - 1);
	}
	else{
		//shift the node values
		//alert(printNode(this._episodes[aIndex]._episodeXmlNode));
		//alert(printNode(this._episodes[aIndex+2]._episodeXmlNode));
		if(this._episodes[aIndex+2]){
			vParentNode.insertBefore(this._episodes[aIndex]._episodeXmlNode, this._episodes[aIndex+2]._episodeXmlNode);
		}
		else{
			vParentNode.appendChild(this._episodes[aIndex]._episodeXmlNode);
		}
		
		//swap the array values
		this._episodes.swapValues(aIndex, aIndex + 1);
	}

	this.update(null, true);
};

RD.Podcast.Base.prototype.addEpisodeNode = function(aEpisodeNode){
	var vEpisode = new RD.Podcast.Episode.Base({parent:this, episodeNode:aEpisodeNode});
	this._episodes.push(vEpisode);
	
	return vEpisode;
};

RD.Podcast.Base.prototype.updateEpisode = function(aIndex, aTitle, aEpisodePublishDate, aEnclosure, aDescription){
	this._episodes[aIndex].update(aTitle, aEpisodePublishDate, aEnclosure, aDescription);
	
	this.update();
};

RD.Podcast.Base.prototype.deleteEpisode = function(){
	if(this._selectedEpisodeNode){
		var vDivEpisodes = $("divEpisodes");
		if(this._episodes.length > 10){
			vDivEpisodes.className = "episodes episodes-small";
		}
		else{
			vDivEpisodes.className = "episodes";
		}

		var vIndex = RD.XHTML.NodeHelper.getNodeIndexByNodeType(this._selectedEpisodeNode);
		this._selectedEpisodeNode.parentNode.removeChild(this._selectedEpisodeNode);
				
		var vEpisodes = $$(this._channelNode, "item");
		this._channelNode.removeChild(vEpisodes[vIndex]);
		this._episodes.removeAt(vIndex);
	
		new RD.XHTML.TextExporter({
			chunkSize:RD.XHTML.TextExporter.MaxChunkSize
			,callback:this.updateComplete
			,text:String.encodeURI(printNode(this._podcastXmlDoc))
			,exportTextScript:"php_scripts/rd_io_export_file.php?filename=" + this._guid + ".xml"
		});
		
		this.deselectEpisode();
	}
};

//can override
RD.Podcast.Base.prototype.bindForm = function(){

};

//can override
RD.Podcast.Base.prototype.initValidate = function(){
	$("rfvEpisodes").setAttribute("isEnabled", "disabled");
	$("rfvEpisodeTitle").setAttribute("isEnabled", String.empty);
	$("rfvMediaFilename").setAttribute("isEnabled", String.empty);
	$("rfvMediaLength").setAttribute("isEnabled", String.empty);
};

RD.Podcast.Base.prototype.setTabIndex = function(aCurrentStep){
	var vStepInputs;
	for(var n=0;n<this._channelInputs.length;n++){
		vStepInputs = this._channelInputs[n];
		for(var z=0;z<vStepInputs.length;z++){
			if((n + 1) == aCurrentStep){
				vStepInputs[z].tabIndex = (z + 1);
			}
			else{
				vStepInputs[z].tabIndex = -1;
			}
		}
	}
};

RD.Podcast.Base.prototype.setFocusToFirstInput = function(aCurrentStep){
	if(this._channelInputs[aCurrentStep-1]){
		//alert(aCurrentStep);
		//alert(this._channelInputs[aCurrentStep-1][0].id);
		this._channelInputs[aCurrentStep-1][0].focus();
	}
}

//can override
RD.Podcast.Base.prototype.initPreviousStep = function(aCurrentStep){

};

//can override
RD.Podcast.Base.prototype.initNextStep = function(aCurrentStep){

};

//can override
RD.Podcast.Base.prototype.showStep = function(aNextStep, aTotalSteps){

};

//can override
RD.Podcast.Base.prototype.selectEpisode = function(aTarget){
	
};

RD.Podcast.Base.prototype.deselectEpisode = function(){
	
};

//can override
RD.Podcast.Base.prototype.getDefaultPodcastXmlDocument = function(){
	return null;
};

//can override
RD.Podcast.Base.prototype.setPodcastXmlDocumentFromTemplate = function(aDocPath){
	RD.Podcast.Form.getManager().setContentLoading(true);
	RD.XHTML.XMLHttpRequestHandler(aDocPath + "?" + (new Date().getTime()), "GET", this, "setPodcastXmlDocumentFromTemplate_Callback", null, null, true);
};

RD.Podcast.Base.prototype.setPodcastXmlDocumentFromTemplate_Callback = function(aStatus){
	//alert(printNode(aStatus.responseXML));
	if(aStatus.responseXML && aStatus.responseXML.childNodes.length > 0){
		this._podcastXmlDoc = parseXML(printNode(aStatus.responseXML), false);
	}
	else{
		this._podcastXmlDoc = this.getDefaultPodcastXmlDocument();
	}

	this._channelNode = $$(this._podcastXmlDoc, "channel").item(0);
	RD.Podcast.Form.getManager().setContentLoading(false);
};

//please override
RD.Podcast.Base.prototype.copyStandardToPodcast = function(aPodcast){

};

//please override
RD.Podcast.Base.prototype.copyPodcastToStandard = function(aPodcast){

};

//please override
RD.Podcast.Base.prototype.renderSteps = function(aParentNode){
	var vDivStep1 = $("divStep_1");
	                                       
	if(!vDivStep1){
		vDivStep1 = RD.XHTML.NodeHelper.createNode("div", null, {
				id:"divStep_1"
				,classname:"podcast-step"
			}
		);
		
		RD.XHTML.NodeHelper.insertFirstChild($("divSteps"), vDivStep1);
		
		RD.XHTML.NodeHelper.createNode("div", vDivStep1, {
				style:"margin:0px 0px 10px 0px;padding:0px 14px 0px 0px;"
			}
			,"In the first few steps of the podcast creation process you will enter the information that is needed to create the podcast feed channel."
		);

	}

	vDiv = RD.XHTML.NodeHelper.createNode("div", vDivStep1, {
			classname:"form"
		}
	);
	
	var vNode;
	var vDiv2;
	var vStyle;
	var vFormats = RD.Podcast.Config.formats;
	
	for(var n=0;n<vFormats.length;n++){
		vStyle = "width:164px;float:left;";
		if(n % 2 == 0){
			vStyle += "text-align:left;";
		}
		else{
			vStyle += "text-align:right;";
		}
		vDiv2 = RD.XHTML.NodeHelper.createNode("div", vDiv, {
				style:vStyle
			}
		);
		vDiv2 = RD.XHTML.NodeHelper.createNode("div", vDiv2, {
				style:"margin:auto;"
			}
		);
		vNode = RD.XHTML.NodeHelper.createNode("label", vDiv2, {
				classname:"form"
				,title:"Format of your feed"
			}
			,"Format (" + vFormats[n].title + ")"
		);

		//IE doesn't like the for attribute on an object sooooo set it here
		vNode.setAttribute("for", "rbl" + vFormats[n].title);
	
		vNode = RD.XHTML.NodeHelper.createNode("span", vDiv2, {
				style:"margin:0px 2px 0px 6px;"
			}
		);
		
		vNode = RD.XHTML.NodeHelper.createNode("input", vNode, {
				type:"radio"
				,name:"rblFormat"
				,id:"rbl" + vFormats[n].title
				,value:n
				,title:"Format of your feed"
				,classname:"form radio"
				,onclick:"RD.Podcast.Form.getManager().setFormat(event);"
				,disabled:vFormats[n].disabled
				,tabIndex:-1
			}
		);

		if(this.getFormat() == vFormats[n].format){
			vNode.checked = true;
		}

		if(n == 1){
			RD.XHTML.NodeHelper.createNode("img", vDiv2, {
					width:"16"
					,height:"16"
					,src:"images/question-out.png"
					,classname:"question"
					,alt:"Question Mark"
					,title:""
					,info:"The \u0022Format\u0022 field is used to determine the format of your feed."
					,style:"top:6px;"
				}
			);
		}

		if(n % 2 == 1){
			if(n > 1){
				vDiv2.style.cssText += "clear:both;margin-right:16px;";
			}

			RD.XHTML.NodeHelper.createNode("div", vDiv, {
					classname:"clear"
				}
			);
		}
	}
};

//can override
RD.Podcast.Base.prototype.clearSteps = function(aParentNode){
	var vDivStep;
	var vDivNodes;
	var vLength;
	for(var n = 1;n<=this._totalSteps;n++){
		vDivStep = $("divStep_" + n);
		if(!isNull(vDivStep)){
			aParentNode.removeChild(vDivStep);
		}
	}
};

RD.Podcast.Base.prototype.toString = function(){
	return printNode(this._podcastXmlDoc);
};

//can override
RD.Podcast.Base.prototype.updateXmlDocument = function(){
	this.updateXmlDocumentForObject(this, this._channelNode);

	for(var n=0;n<this._episodes.length;n++){
		this._episodes[n].updateXmlNode();
	}
};

RD.Podcast.Base.prototype.updateXmlDocumentForObject = function(aObject, aParentNode){
	var vItemNode = null;

	for(var vKey in aObject){
		if(!vKey.startsWith("_")){
			switch(typeof(aObject[vKey])){
				case "string":
				case "number":
					//alert(vKey + ":" + aObject[vKey]);
					this.updateXmlDocumentForString(aParentNode, vKey.replace(/_/gi, ":"), aObject[vKey], true);
					break;
				case "object":
					vItemNode = this.updateXmlDocumentForString(aParentNode, vKey.replace(/_/gi, ":"), aObject[vKey], false);
					this.updateXmlDocumentForObject(aObject[vKey], vItemNode);
					break;
			}
		}
	}
};

RD.Podcast.Base.prototype.updateXmlDocumentForString = function(aParentNode, aNodeName, aNodeValue, aHasChildren){
	var vItemNode = $$(aParentNode, aNodeName).item(0);

	if(!isNull(aNodeValue)){
		aNodeValue = aNodeValue.toString().trim();
		var vReplaceChars = RD.Podcast.Base.REPLACE_CHARS;
		for(var n=0;n<vReplaceChars.length;n++){
			aNodeValue = aNodeValue.replace(vReplaceChars[n][0], vReplaceChars[n][1]);
		}
	}
	
	if(!vItemNode){
		vItemNode = RD.XHTML.NodeHelper.createNode(aNodeName, aParentNode, {}
			,aNodeValue
			,this._podcastXmlDoc
		);
	}
	else if(aHasChildren){
		if(!vItemNode.firstChild && aHasChildren){
			RD.XHTML.NodeHelper.createNode("text", vItemNode, {}
				,aNodeValue
				,this._podcastXmlDoc
			);
		}
		else{
			vItemNode.firstChild.nodeValue = aNodeValue;
		}
	}
	
	return vItemNode;
};

RD.Podcast.Base.prototype.loadFromGuiId = function(aPodcastGuid, aCallbackObject, aCallbackFunction){
	this._callbackObject = aCallbackObject;
	this._callbackFunction = aCallbackFunction;
	this._guid = aPodcastGuid;
	
	RD.Podcast.Form.getManager().setContentLoading(true);
	
	RD.XHTML.XMLHttpRequestHandler("temp_files/" + this._guid + ".xml?" + (new Date().getTime()), "GET", this, "loadFromGuiId_Callback", null, null, true);
};

RD.Podcast.Base.prototype.loadFromGuiId_Callback = function(aStatus){
	if(aStatus.responseXML && aStatus.responseXML.childNodes.length > 0){
		this._podcastXmlDoc = parseXML(printNode(aStatus.responseXML), false);

		this._channelNode = $$(this._podcastXmlDoc, "channel");
		if(this._channelNode.length){
			this._channelNode = this._channelNode.item(0);

			this.loadPodcastFromXml(this._channelNode, this, ",item,");

			var vItemNodes = $$(this._channelNode, "item");
	
			for(var n=0;n<vItemNodes.length;n++){
				this.addEpisodeNode(vItemNodes.item(n));
			}
		}
		else{
			this._channelNode = null;
		}
	}

	if(!this._podcastXmlDoc || !this._channelNode){
		this._podcastXmlDoc = this.getDefaultPodcastXmlDocument();
		this._channelNode = $$(this._podcastXmlDoc, "channel").item(0);
	}
	
	
	if(typeof(this._callbackObject) == "string"){
		eval(this._callbackObject)(aStatus);
	}
	else{
		if(this._callbackObject.operationComplete){
			this._callbackObject.operationComplete(aStatus);
		}
		else if(this._callbackFunction){
			this._callbackObject[this._callbackFunction](aStatus);
		}
		else if(this._callbackObject != window){
			this._callbackObject(aStatus);
		}
	}
};

RD.Podcast.Base.prototype.loadPodcastFromXml = function(aXmlNode, aJsObject, aExcludeNodes){
	aExcludeNodes = aExcludeNodes?aExcludeNodes:String.empty;
	
	var vChildNode = null;
	var vElementNodes = null;
	var vNodeName = null;
	for(var n=0;n<aXmlNode.childNodes.length;n++){
		vChildNode = aXmlNode.childNodes.item(n);
		if(aExcludeNodes.indexOf("," + vChildNode.nodeName + ",") < 0){
			if(vChildNode.childNodes.length > 0){
				vNodeName = vChildNode.nodeName.replace(/:/gi, "_");
				vElementNodes = RD.XHTML.NodeHelper.getElementsByNodeType(vChildNode, 1, false);
				if(vElementNodes.length > 0){
					aJsObject[vNodeName] = {};
					this.loadPodcastFromXml(vChildNode, aJsObject[vNodeName], aExcludeNodes);
				}
				else if(vChildNode.firstChild && vChildNode.firstChild.nodeName == "#text"){
					aJsObject[vNodeName] = vChildNode.firstChild.nodeValue;
				}
			}
		}
	}
};

//can override
RD.Podcast.Base.prototype.update = function(aCurrentStep, aForceUpdate){
	var vOldDocument = printNode(this._podcastXmlDoc);

	this.updateXmlDocument();

	var vNewDocument = printNode(this._podcastXmlDoc);

	if(aForceUpdate || vOldDocument != vNewDocument){
		vNewDocument = printNode(this.formatXmlDocument(this._podcastXmlDoc));

		new RD.XHTML.TextExporter({
			chunkSize:RD.XHTML.TextExporter.MaxChunkSize
			,callback:this.updateComplete
			,text:String.encodeURI(vNewDocument)
			,exportTextScript:"php_scripts/rd_io_export_file.php?filename=" + this._guid + ".xml"
		});
	}
};

RD.Podcast.Base.prototype.publish = function(){
	var vExportFilename = this._guid + ".rss";
	
	if(!isNull(this.control.filename) && this.control.filename.trim().length > 0){
		vExportFilename = this.control.filename;
	}
	if(!vExportFilename.endsWith(".rss")){
		vExportFilename += ".rss";
	}

	var vReplaceExp = String.encodeURI("\t\t<\s*?control.*?>(.*?)<\s*?/control\s*?>\r\n");
	window.location = "php_scripts/rd_io_export_file.php?export=1&replace_exp=" + vReplaceExp + "&filename=" + this._guid + ".xml&exportFilename=" + vExportFilename;
};

RD.Podcast.Base.prototype.formatXmlDocument = function(aXmlDocument){
	var vXmlContent = printNode(aXmlDocument);
	var vXmlDocument = parseXML(this.formatXmlContent(vXmlContent), false);

	RD.XHTML.NodeHelper.appendWhiteSpaceToElementNodes(vXmlDocument, 0, vXmlDocument);

	return vXmlDocument;
};

RD.Podcast.Base.prototype.formatXmlContent = function(aXmlContent){
	var vMyRE = new RegExp("[\r\n\t]", "gi");
	
	aXmlContent = aXmlContent.replace(vMyRE, 
		function(){
				return RegExp.$1;
		}
	);

	return aXmlContent;
};

//	start episode base class
RD.Podcast.Episode = {};
RD.Podcast.Episode.Base = function(aArgs){
	aArgs = aArgs?aArgs:{};

	this.init(aArgs);

	return this;
}

RD.Podcast.Episode.Base.MEDIA_TYPE = {
	MP3:"audio/mpeg"
	,M4A:"audio/x-m4a"
	,MP4:"video/mp4"
	,M4V:"video/x-m4v"
	,MOV:"video/quicktime"
	,PDF:"application/pdf"
};

RD.Podcast.Episode.Base.prototype.constructor = RD.Podcast.Episode.Base;

//can override
RD.Podcast.Episode.Base.prototype.init = function(aArgs){
	if(aArgs.episodeNode){
		aArgs.title = String.empty;
		aArgs.pubDate = String.empty;
		aArgs.enclosure = {};
		aArgs.description = String.empty;
		
		var vTitle = $$(aArgs.episodeNode, "title").item(0).firstChild;
		if(vTitle){
			aArgs.title = vTitle.nodeValue;
		}
		var vPublishDate = $$(aArgs.episodeNode, "pubDate").item(0).firstChild;
		if(vPublishDate){
			aArgs.pubDate = vPublishDate.nodeValue;
		}
		
		var vEnclosure = $$(aArgs.episodeNode, "enclosure").item(0);
		
		if(vEnclosure){
			aArgs.enclosure = {
				url:vEnclosure.getAttribute("url")
				,length:vEnclosure.getAttribute("length")
				,type:vEnclosure.getAttribute("type")
			};
		}
		var vDescription = $$(aArgs.episodeNode, "description").item(0).firstChild;
		if(vDescription){
			aArgs.description = vDescription.nodeValue;
		}
	}
	
	this._parent = aArgs.parent;
	this.title = aArgs.title?aArgs.title:String.empty;
	this.pubDate = aArgs.pubDate?aArgs.pubDate:String.empty;
	this._enclosure = aArgs.enclosure?aArgs.enclosure:{};
	this.description = aArgs.description?aArgs.description:String.empty;
	this.guid = RD.XHTML.getGuId();
	
	this._enclosure.url = this._enclosure.url?this._enclosure.url:String.empty;
	this._enclosure.length = this._enclosure.length?this._enclosure.length:String.empty;
	this._enclosure.type = this._enclosure.type?this._enclosure.type:String.empty;
	
	if(aArgs.episodeNode){
		this._episodeXmlNode = aArgs.episodeNode;
	}
	else if(this._parent){
		this._episodeXmlNode = RD.XHTML.NodeHelper.createNode("item", this._parent._channelNode, {}, null, this._parent._podcastXmlDoc);
	}
};

RD.Podcast.Episode.Base.prototype.toString = function(){
	return printNode(this._episodeXmlNode);
};

RD.Podcast.Episode.Base.prototype.getXmlNode = function(){
	return this._episodeXmlNode;
};

//can override
RD.Podcast.Episode.Base.prototype.update = function(aTitle, aPublishDate, aEnclosure, aDescription){
	this.title = aTitle?aTitle:String.empty;
	this.pubDate = aPublishDate?aPublishDate:String.empty;
	this._enclosure = aEnclosure?aEnclosure:{};
	this.description = aDescription?aDescription:String.empty;
	
	this._enclosure.url = this._enclosure.url?this._enclosure.url:String.empty;
	this._enclosure.length = this._enclosure.length?this._enclosure.length:String.empty;
	this._enclosure.type = this._enclosure.type?this._enclosure.type:String.empty;
};

//can override
RD.Podcast.Episode.Base.prototype.updateXmlNode = function(){
	var vItemNode = null;
	var vChildNodes = null;
	var vValue = null;
	var vNodeArray = null;
	var vXmlDoc = null;
	var vNewNode = null;
	var vNodeString = null;
	for(var vKey in this){
		if(!vKey.startsWith("_") && typeof(this[vKey]) != "function"){
			vValue = this[vKey];
			vKey = vKey.replace(/_/gi, ":");
			vNodeArray = $$(this._episodeXmlNode, vKey);
			if(!vNodeArray.length){
				vItemNode = RD.XHTML.NodeHelper.createNode(vKey, this._episodeXmlNode, {}
					,vValue
					,this._parent._podcastXmlDoc
				);
				
				if(vKey != vItemNode.nodeName){
					vNodeString = printNode(vItemNode).replace(vItemNode.nodeName, vKey);
					vNodeString = vNodeString.replace("/" + vItemNode.nodeName, "/" + vKey);
					vNewNode = parseXML(vNodeString, false).firstChild;
					vItemNode.parentNode.replaceChild(vNewNode, vItemNode);
				}
				
			}
			else if(!vNodeArray.item(0).firstChild){
				RD.XHTML.NodeHelper.createNode("text", vNodeArray.item(0), {}
					,vValue
					,this._parent._podcastXmlDoc
				);
			}
			else{
				vNodeArray.item(0).firstChild.nodeValue = this[vKey];
			}
		}
		else if(vKey.startsWith("_")){
			switch(vKey){
				case "_enclosure":
					vItemNode = $$(this._episodeXmlNode, vKey.substr(1)).item(0);
					
					if(!vItemNode){
						vItemNode = RD.XHTML.NodeHelper.createNode(vKey.substr(1), this._episodeXmlNode, {}
							,null
							,this._parent._podcastXmlDoc
						);
					}

					vItemNode.setAttribute("url", this[vKey].url);
					vItemNode.setAttribute("length", this[vKey].length);
					vItemNode.setAttribute("type", this[vKey].type);

					break;
			}
		}
	}
};