var myEditor = null;
var retries = 0;
var html = "";
var tblRow = 0;
var frIFrameHidden = true;		
var prx = new PRX();
var ajaxReturn = "";
var WEBSVC_URI = "http://whitleymedia.com/webservices/";
var currentWebsvc = "";
var currentViewerType = "HTML";
var gotoNext = null;
var currentPage;
var savedPage;
var currentStep = 0;
var wait = false;
var stepArray = ["start","contact","release","categories","links","mm","quotes","boilerplate","options"];	
var editorElem = "divEditorXY";	
var fckeditor;					

var paypalWindow;

var prxNS = "http://purl.org/prx/1.0/";       
var mediaNS = "http://search.yahoo.com/mrss/";
var linkNS = "http://search.yahoo.com/mrss/";       
var serviceNS = "http://search.yahoo.com/mrss/";              
var vCardNS = "http://www.w3.org/2001/vcard-rdf/3.0#";  

var ffversion = FFVersion();                   

var iFrames = new Array();

var settings = {
      tl: { radius: 8 },
      tr: { radius: 8 },
      bl: { radius: 8 },
      br: { radius: 8 },
      antiAlias: true,
      autoPad: false
    } 

var url;

//Preload Images
var img1 = new Image();
img1.src="images/pdf.jpg";
var img2 = new Image();
img2.src="images/podcast.jpg";
var img3 = new Image();
img3.src="images/video.gif";
var img4 = new Image();
img4.src="images/audio.jpg";
var img5 = new Image();
img5.src="images/multimedia.gif";


var cleanPRX = 	"<?xml version=\"1.0\" encoding=\"UTF-8\"?><prx version=\"1.0\" xmlns=\"http://purl.org/prx/1.0/\">"
					+"<prxlink />"
					+"<link />"
					+"<contacts />"
					+"<newslines>"
						+"<headline />"
						+"<subheadline />"
						+"<dateline />"
						+"<body />"
						+"<quotes />"
						+"<boilerplate />"
					+"</newslines>"
					+"<categories />"
					+"<tags />"
					+"<links xmlns:link=\"http://search.yahoo.com/mrss/\"/>"
					+"<multimedia xmlns:media=\"http://search.yahoo.com/mrss/\"/>"
					+"<services xmlns:service=\"http://search.yahoo.com/mrss/\"/>"
				+"</prx>";

var save_instr = "<div><ul><li>All information is <u>temporarily</u> saved -- even when moving from&nbsp;"
				+"page to page.&nbsp;&nbsp;However, your data will be lost if you exit the application " 
				+"before clicking on the <b>Save</b> button.<li>Click on the <b>Save</b> button periodically "
				+"to save the data to the server.&nbsp;&nbsp; This will allow " 
				+"us to retrieve your file should you experience a machine or browser crash. "
				+"<li>Click on the <b>Save As</b> button and select <b>PRX</b> to keep a copy of the XML version on your local hard drive. You can open this "
				+"file later in&nbsp;PRX Builder if you need to make any changes.<li>"
				+"Click on the <b>Save As</b> button and select <b>HTML</b> to keep a copy of the " 
				+"HTML version on your local hard drive.</li></ul></div>";
var  prx_what = "<table cellpadding='0' cellspacing='0' border='0' width='90%'><tr><td valign='top'><b>Whats' a PRX File?</b></td><td>A PRX file is the XML representation of your press release and is useful when distributing your release electronically."
				+"<br><br>Software and services that support the PRX format can access your file from the internet.</td></tr></table>";							
var  lnkGroupHelpText = "Links may be grouped using the <b>Link Group ID</b>.<br>"
    					+ "There's nothing special about this number.  It's simply a way to group "
    					+ "several links together.<br><br>Links within a Link Group are all displayed together in a release.<br><br>"
    					+ "The standard release template displays <b>Group Link 1</b> before the <b>Multimedia</b> section.<br><br>"
    					+ "Link Groups with an ID above 1 are displayed following the <b>Boilerplate</b> section."; 				
var prn_webreach = "<b>Web Reach</b> - Your release will be posted to the thousands of Web sites that carry PR Newswire content.  This includes prnewswire.com and PR Newswire's free media-only Web site, PR Newswire for Journalists.  Over 80,000 journalists (including bloggers) are registered for PR Newswire for Journalists.  The site receives over one million news release views per month and was recently named &quot;2006 Best Online News Service&quot; by the SIIA CODiE awards.";				
var prn_reports = "<b>Reporting</b> - You will receive Access Reports detailing accesses to your news release on prnewswire.com and our media-only Web site PR Newswire for Journalists and you will receive a ReleaseWatch report, which includes links to your release as it appears on up to 20 Web sites.";
var prn_seo = "<b>Search Engine Optimization</b> - Your news release will be optimized for search engines so that it may appear higher in the natural search results for up to six months.  It will also be optimized for searches conducted through mobile devices.  You will receive detailed tracking reports that include:<br>"
								+"<ul><li>The keywords used to find product, brand, "
								+"and company information mentioned in your "
								+"release."
								+"<li>The search engines used to find your news "
								+"release."
								+"<li>The number of searchers who followed the "
								+"news release to your company's home page "
								+"or product site.</ul>";
var prn_rss = "<b>RSS Feeds</b> - According to Yahoo, PR Newswire is the most popular RSS source for news releases online.  PR Newswire has more than 500 RSS feeds available to journalists, with over 688 RSS feeds in total.";
var prn_delicious = "<b>del.icio.us</b> - PR Newswire automatically includes links to del.icio.us, the social bookmarking service owned by Yahoo!, to all news releases on prnewswire.com.  del.icio.us (http://del.icio.us/) allows users to create a profile of links to blogs, articles, websites, and other online destinations of personal interest that can be accessed by the individual, or by others who have similar interests, from any web-enabled computer.<br/><br/>The partnership between del.icio.us and PR Newswire will make it easier for news release readers to share releases that are of specific interest to them with del.icio.us users and others who have similar interests, thus extending the reach of your release to audiences most likely to act upon the information.";
var prn_important = "Important PR Newswire Information<br/><br/>"
									+"<ul><li>Processing time between PR Newswire release submission to distribution "  
									+"may take up to 24 business hours." 
									+"<li>The PR Newswire/PRX Builder Web-only package does not include "
									+"disclosure media.  It is not intended for public companies releasing material news. " 
							        +"<li>While all of your release content will be distributed through PR Newswire, "
							        +"due to the limitations of &quot;the wire,&quot; your  release may NOT have "
							        +"the same general format as a PRX Builder release.<br/><br/> "
							        +"For example, within PR Newswire releases, the full URL of all links must "
							        +"be displayed (e.g. http://www.example.com/link.html).  All links will "
							        +"be automatically converted to display the full URL.  They will then be "
							        +"added to the &quot;Related Links&quot; section of the release.</ul>"; 
var blog_address_help = "For Blogger, specify your blog's address<br/>(Example:  http://{blog name}.blogspot.com)<br/><br/>For the metaWeblog API, if your xml-rpc service is not located in the root of your blog, specify the full address to your xml-rpc service.  If you have no idea what an xml-rpc service is -- just try your blog's URL.";							    


function ShowXML(xmlDoc){
    var xml = "";
	try
	{
		if(xmlDoc.xml)
		{
			xml = xmlDoc.xml;
		}
		else
		{
			try{
				var serializer = new XMLSerializer();
				xml = serializer.serializeToString(xmlDoc);
			}
			catch(e)
			{
				xml = xmlDoc.outerHTML;
			}
		}
	}
	catch(e)
	{
		alert("Error:" + e.message);
	}
	return xml;

}



//Custom javascript object
//to retrieve a PRX file.
function PRX() {
    var req;
    this._url = "";
    this._xml = "";
    this.url = urlProp;
    this.xml = getXML;
}

function urlProp(value){
	this._url = value;	
	return this._url;
}

function getXML(){

	try
	{
		xmlDoc = PRX.prototype.xmlDoc;
		if(xmlDoc.xml)
		{
			this._xml = xmlDoc.xml;
		}
		else
		{
			try{
				var serializer = new XMLSerializer();
				var xml = serializer.serializeToString(xmlDoc);
				this._xml = xml;
			}
			catch(e)
			{
				this._xml = xmlDoc.outerHTML;
			}
		}
	}
	catch(e)
	{
		alert("Error:" + e.message);
	}
	return this._xml;

}

PRX.prototype.loadXMLDoc = function() {

    req = false;

    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) {
			req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
		}
    }
    if(req) {
		req.onreadystatechange = this.processReqChange;
		var loc = this._url;
		req.open("GET", loc, true);
		req.send(null);
    }
}

PRX.prototype.processReqChange = function() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
			//ie
			prx = new PRX();
			if(prx.loadXML(req.responseText))
			{
				alert("The document was loaded successfully");
			}
        } else {
            alert("There was a problem retrieving the XML data:\n" +
                req.statusText);
        }
    }
}

PRX.prototype.loadXML = function(xml) {
	var xmlDoc;
	var xmlText;
	var ret = false;

	try
	{	
		xmlText = xml;	

		try
		{
			var parser = new DOMParser();
			xmlDoc = parser.parseFromString(xmlText, "text/xml");			
		}
		catch(e){
			if(window.ActiveXObject) {
				xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
				xmlDoc.async="false";
				xmlDoc.loadXML(xmlText)
			}
		}			
		PRX.prototype.xmlDoc = xmlDoc;
		PRX.prototype.xmlText = xmlText;
		ret = true;
	}
	catch(e)
	{
				alert("There was a problem loading the XML data:\n" + e.message);	
	}
	
	return ret;

}



PRX.prototype.createNode = function(type, name, namespaceURI) {
	
	xmlDoc = PRX.prototype.xmlDoc;
	
	if(window.ActiveXObject)
	{
		node = xmlDoc.createNode(type,name,namespaceURI);
	}
	else
	{
		node = xmlDoc.createElementNS(namespaceURI,"name");
	}


	return node;
}

PRX.prototype.replaceDoc = function(xmlDoc,xmlText) {
	
	PRX.prototype.xmlDoc = xmlDoc;
	PRX.prototype.xmlText = xmlText;

}


PRX.prototype.getElementsByTagName = function(local) {

	var result = null;
	var temp = null;
	
	var xmlDoc = PRX.prototype.xmlDoc;

	result = xmlDoc.getElementsByTagName(local);
	
	if(result.length == 1)
	{
		result = result[0];
	}

	return result;

}

// retrieve XML document element, including
// elements using namespaces
PRX.prototype.getElementsByTagNameNS = function(prefix, local, parentElem, index) {

    var result;
    
    try
    {
		parentElem.childNodes;
    }
    catch(e)
    {
		return result;
    }
    if (window.ActiveXObject || FFVersion() >= 3) {
        result = getElementsByTagNameNSIE(prefix, local, parentElem, index);
    } else {
        // the namespace versions of this method 
        // (getElementsByTagNameNS()) operate
        // differently in Safari and Mozilla, but both
        // return value with just local name, provided 
        // there aren't conflicts with non-namespace element
        // names
        try
        {
			if(index > -1)
			{
				result = parentElem.getElementsByTagName(local)[index];
				if(result[0])
				{
					result = result[0];
				}				
			}
			else
			{
				result = parentElem.getElementsByTagName(local);
			}
		}
		catch(e)
		{
		    try
		    {
                if(!result)
                {
                    result = getElementsByTagNameNSIE(prefix, local, parentElem, index);
                }
            }
            catch(e)
            {
                result = null;
            }
		}
    }

    return result;
}

function getElementsByTagNameNSIE(prefix, local, parentElem, index)
{
        if(prefix.length > 0)
        {
			prefix += ":";
        }
        if(index > -1)
        {
			if(parentElem.getElementsByTagName(prefix + local))
			{
				if(parentElem.getElementsByTagName(prefix + local).length > 1)
				{
					result = parentElem.getElementsByTagName(prefix + local)[index];
				}
				else
				{
					result = parentElem.getElementsByTagName(prefix + local);
				}
			}
			if(result[0])
			{
				result = result[0];
			}
		}
		else
		{
			result = parentElem.getElementsByTagName(prefix + local);
		}
		return result;
}

function FFVersion()
{
    var ffversion = 0;
    if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
         ffversion=new Number(RegExp.$1); // capture x.x portion and store as a number
    }

    return ffversion;
    
}

function ImportNode(childNode)
{
      if(!childNode)
      {
        return;
      }

      var newNode;
      
      newNode = prx.xmlDoc.createElement(childNode.nodeName);

      /* does the node have any attributes to add? */
      if (childNode.attributes && childNode.attributes.length > 0)
      {
        for (var i = 0; i < childNode.attributes.length;i++)
        {
          if(childNode.attributes[i])
          {
            try
            {
                newNode.setAttribute(childNode.attributes[i].nodeName, childNode.getAttribute(childNode.attributes[i].nodeName));
            }
            catch(e)
            {
            }
          }
       }
     }  
      /* are we going after children too, and does the node have any? */
      if (childNode.childNodes && childNode.childNodes.length > 0)
      {
        for (var i = 0; i < childNode.childNodes.length;i++)
        {
            if(childNode.childNodes[i])
            {
                    try
                    {
                        if(childNode.childNodes[i].nodeName == "#cdata-section" || childNode.childNodes[i].nodeName == "#text")
                        {
                            newNode.appendChild(document.createTextNode(childNode.childNodes[i].nodeValue));
                        }
                        else
                        {
                            if(childNode.childNodes[i].nodeName.indexOf("#") < 0)
                            {
                                newNode.appendChild(ImportNode(childNode.childNodes[i]));
                            }
                        }
                    }
                    catch(e)
                    {
                        alert(e.message);
                    }
            }
        }
     } 

     return newNode;
}


function XMLFromText(xmlText, skipImport)
{
			var xmlDoc;

			try
			{
				if(typeof DOMParser != "undefined" )
				{
					var parser = new DOMParser();
				    xmlDoc = parser.parseFromString(xmlText, "text/xml");
			        //Import?
			        if(!skipImport)
			        {
		                xmlDoc = ImportNode(xmlDoc.firstChild);
		            }
				}
				else
				{
					if(window.ActiveXObject) {
						xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
						xmlDoc.async="false";
						xmlDoc.loadXML(xmlText);
						xmlDoc = xmlDoc.firstChild;
					}			
				}
				
			}
			catch(e)
			{
			    alert(e.message);
			}
            
			return xmlDoc;

}		

function GoTo()
{
//    var select = document.forms['Form1'].elements['cboGoTo'];
//    if(select)
//    {
//	    gotoNext = select.selectedIndex;
//	}
	
	switch(document.getElementById("hdnTab").value)
	{
		case "contact":
			ContactSave();
			ContactLoad();
			break;
		case "links":
			LinksSave();
			LinksLoad();
			break;					
		case "mm":
			MMSave();
			MMLoad();
			break;	
	}

}

function StepSelected(step)
{
    var step = "step" + step;

	//Steps
	for(var ctr = 1; ctr < 10; ctr++)
	{
        document.getElementById("step" + ctr).style.backgroundImage = "";
	}

    document.getElementById(step).style.backgroundImage = "url(images/hover_bg.jpg)";
    document.getElementById(step).style.backgroundRepeat="repeat-x";   
}

	
function LoadPageDelayed(obj)
{

//            if(wait)
//            {
//                alert("Editor is still loading.  Please wait.");
//                return;
//            }
			try
			{
				if(!obj.value)
				{
					var page = obj;
					obj = new Image();
					obj.value = page;
				}
			}
			catch(e)
			{
			}
			
			document.getElementById("divMain").style.top = "175px";

			try
			{
				switch(document.getElementById("hdnTab").value)
				{
					case "start":
						break;
					case "contact":
						ContactSave();
						break;
					case "release":
						ReleaseSave();
						break;
					case "categories":
						CategoriesSave();
						break;
					case "links":
						LinksSave();
						break;					
					case "mm":
						MMSave();
						break;	
					case "quotes":
						QuotesSave();
						break;
					case "boilerplate":
						BoilerplateSave();
						break;	
					case "options":
						OptionsSave();
						break;
					case "finish":
						break;							
					
				}		
				EditorHide();
				ViewerHide();
				document.getElementById("btnClose").style.display = "none";									
				document.getElementById("btnWord").style.display = "none";													
				document.getElementById("divFinish").style.display = "none";			
				//document.getElementById("recordNav").style.display = "none";
				document.getElementById("divDistribute").style.display = "none";
				document.getElementById("spnOpt").style.visibility = "hidden";
								
				document.getElementById("hdnTab").value = obj.value;

			
				//Load the Page
				if(document.getElementById(obj.value).contentDocument)
				{
    			    if(document.getElementById("divLayout") && document.getElementById(obj.value))
				    {
				        document.getElementById("divLayout").innerHTML = document.getElementById(obj.value).contentDocument.getElementById("cutPage").innerHTML;										
				    }
				}
				else
				{
				    if(document.getElementById("divLayout") && document.frames[obj.value])
				    {
				        document.getElementById("divLayout").innerHTML = document.frames[obj.value].document.getElementById("cutPage").innerHTML;										
				    }
				}
				
				if(document.getElementById("prname") && document.getElementById("prnameDisplay"))
				{
					if(document.getElementById("prnameDisplay").value != document.getElementById("prname").value)
					{
						document.getElementById("prnameDisplay").value = document.getElementById("prname").value;
					}
				}			

				switch(obj.value)
				{
					case "start":
					    StepSelected(1);
						if(document.getElementById("prnameDisplay"))
						{
							document.getElementById("prnameDisplay").value = document.getElementById("prname").value;
						}
						document.getElementById("lblUserid").innerHTML = document.getElementById("userid").value;
//					    var cornersObj = new curvyCorners(settings, document.getElementById("divFiles"));
//						cornersObj.applyCornersToAll();	
                        FileListDelay();	
                        if(document.getElementById("relThumbs"))
                        {
                        }									    
						break;
					case "contact":
					    StepSelected(2);
						//document.getElementById("step2").style.color = "white";
						//document.getElementById("step2").style.backgroundColor = "black";																					
						//document.getElementById("recordNav").style.display = "block";
						ContactLoad();
					    //var cornersObj = new curvyCorners(settings, document.getElementById("cntct"));
						//cornersObj.applyCornersToAll();						
						break;
					case "release":
					    StepSelected(3);
						//document.getElementById("step3").style.color = "white";
						//document.getElementById("step3").style.backgroundColor = "black";	
//                        myEditor = new YAHOO.widget.Editor('editor', {
//                        height: '300px',
//                        width: '522px',
//                        dompath: true, //Turns on the bar at the bottom
//                        animate: true //Animates the opening, closing and moving of Editor windows
//                        ,focusAtStart: false
//                        });
                          ReleaseLoad();
//                        myEditorPreRender(myEditor);
//                        myEditor.render();																				
					    //var cornersObj = new curvyCorners(settings, document.getElementById("divRelease"));
						//cornersObj.applyCornersToAll();											    						
						break;
					case "categories":
					    StepSelected(4);
						//document.getElementById("step4").style.color = "white";
						//document.getElementById("step4").style.backgroundColor = "black";																					
						CategoriesLoad();
					    //var cornersObj = new curvyCorners(settings, document.getElementById("divKeywords"));
						//cornersObj.applyCornersToAll();											    							
					    //var cornersObj = new curvyCorners(settings, document.getElementById("divCategories"));
						//cornersObj.applyCornersToAll();											    								
						break;
					case "links":
					    StepSelected(5);					
						//document.getElementById("step5").style.color = "white";
						//document.getElementById("step5").style.backgroundColor = "black";																					
						//document.getElementById("recordNav").style.display = "block";				
						LinksLoad();
					    //var cornersObj = new curvyCorners(settings, document.getElementById("divLinks"));
						//cornersObj.applyCornersToAll();											    
						break;					
					case "mm":
					    StepSelected(6);					
						//document.getElementById("step6").style.color = "white";
						//document.getElementById("step6").style.backgroundColor = "black";																					
						//document.getElementById("recordNav").style.display = "block";								
						MMLoad();
					    //var cornersObj = new curvyCorners(settings, document.getElementById("divMM"));
						//cornersObj.applyCornersToAll();											  
						break;	
					case "quotes":
					    StepSelected(7);					
						//document.getElementById("step7").style.color = "white";
						//document.getElementById("step7").style.backgroundColor = "black";	
						QuotesLoad();
					    //var cornersObj = new curvyCorners(settings, document.getElementById("divQuotes"));
						//cornersObj.applyCornersToAll();											    							
						break;
					case "boilerplate":
					    StepSelected(8);					
						//document.getElementById("step8").style.color = "white";
						//document.getElementById("step8").style.backgroundColor = "black";																					
                        BoilerplateLoad();
					    //var cornersObj = new curvyCorners(settings, document.getElementById("divBoilerplate"));
						//cornersObj.applyCornersToAll();											    							
						break;															
					case "finish":
					    StepSelected(9);
						//document.getElementById("step9").style.color = "white";
						//document.getElementById("step9").style.backgroundColor = "black";																					
						//document.getElementById("divFinish").style.display = "block";				
						document.getElementById("btnClose").style.display = "block";											
						document.getElementById("btnWord").style.display = "block";																	
						break;		
					case "options":
					    StepSelected(9);
						//document.getElementById("step9").style.color = "white";
						//document.getElementById("step9").style.backgroundColor = "black";																					
						//document.getElementById("divFinish").style.display = "block";	
						//document.getElementById("spnOpt").style.visibility = "visible";						
						OptionsLoad();
//						if(BrowserDetect.browser != "Opera")
//						{
//							var cornersObj = new curvyCorners(settings, document.getElementById("divTechnorati"));
//							cornersObj.applyCornersToAll();											    								
//							var cornersObj = new curvyCorners(settings, document.getElementById("divServices"));
//							cornersObj.applyCornersToAll();											    	
//							var cornersObj = new curvyCorners(settings, document.getElementById("divLinks"));
//							cornersObj.applyCornersToAll();											    															
//							var cornersObj = new curvyCorners(settings, document.getElementById("divServicesSubmit"));
//							cornersObj.applyCornersToAll();											    								
//						}
						break;
					case "distribute":
					    StepSelected(9);					
						//document.getElementById("step9").style.color = "white";
						//document.getElementById("step9").style.backgroundColor = "black";																					
						//document.getElementById("divFinish").style.display = "block";	
						//document.getElementById("divDistribute").style.display = "block";	
						//document.getElementById("spnOpt").style.visibility = "visible";	
						XMLProcess();
						break;
					case "prn_publish":				
					    StepSelected(9);					
						//document.getElementById("step9").style.color = "white";
						//document.getElementById("step9").style.backgroundColor = "black";																											
						//document.getElementById("divFinish").style.display = "block";	
						//document.getElementById("divDistribute").style.display = "block";												
						//document.getElementById("spnOpt").style.visibility = "visible";	
						break;			
					case "prx_releases":
					    StepSelected(9);
					    $("currTemplate").innerHTML = document.getElementById("xform").options[document.getElementById("xform").selectedIndex].text;					
						//document.getElementById("step9").style.color = "white";
						//document.getElementById("step9").style.backgroundColor = "black";																										
						//document.getElementById("divFinish").style.display = "block";	
						//document.getElementById("divDistribute").style.display = "block";												
						//document.getElementById("spnOpt").style.visibility = "visible";	
//						if(BrowserDetect.browser != "Opera")
//						{						
//							var cornersObj = new curvyCorners(settings, document.getElementById("divFiles"));
//							cornersObj.applyCornersToAll();											    								
//						}
						break;														
					case "ext":
					    StepSelected(9);					
						//document.getElementById("step9").style.color = "white";
						//document.getElementById("step9").style.backgroundColor = "black";																										
//						if(BrowserDetect.browser != "Opera")
//						{
//							var cornersObj = new curvyCorners(settings, document.getElementById("divBlogPost"));
//							cornersObj.applyCornersToAll();											    								
//							var cornersObj = new curvyCorners(settings, document.getElementById("divEmailRelease"));
//							cornersObj.applyCornersToAll();											    	
//						}
						//document.getElementById("divFinish").style.display = "block";	
						//document.getElementById("divDistribute").style.display = "block";												
                        //document.getElementById("spnOpt").style.visibility = "visible";	
                        ExtDefaults();															

						break;															
					
				}
			}
			catch(e)
			{
				alert("Error in LoadPage():  " + e.message);
			}
			EditorLoad($("hdnTab").value + "editor");
			
		}
		
function PRXLoad()
{
	if(document.getElementById("prname").value.length > 0)
	{
		Open();
	}
	else
	{
	    prx = new PRX();
		prx.loadXML(cleanPRX);
		XMLProcess();
	}
	
}
		
function DemoCopy()
{
    if($("hdnTab").value != "start")
    {
        LoadPage("start");
        setTimeout("DemoCopy()",1000);
    }
    
    if(document.getElementById("prnameDisplay"))
    {
	    document.getElementById("prname").value = "demo.xml";
	    document.getElementById("prnameDisplay").value = "demo.xml";	
	    FileOpen();
	}
}		
		
function FileOpen()
{
    if(document.getElementById("hdnContactIndex"))
    {
        document.getElementById("hdnContactIndex").value = 0;
        document.getElementById("hdnLinkIndex").value = 0;
        document.getElementById("hdnMMIndex").value = 0;
    }
	Open();
}

function ContactAdd(index)
{

       var parent = prx.getElementsByTagName("prx");
	   var contacts = prx.getElementsByTagNameNS("", "contacts", parent, 0);       

		var node = XMLFromText("<contact xmlns:vCard=\"" + vCardNS + "\"><vCard:CATEGORIES>"
				+ "</vCard:CATEGORIES><vCard:FN></vCard:FN>"
				+"<vCard:ORG><vCard:Orgname></vCard:Orgname></vCard:ORG>"
				+"<vCard:TITLE></vCard:TITLE>"
				+"<vCard:LABEL vCard:TYPE=\"http://www.w3.org/2001/vcard-rdf/3.0#postal\"></vCard:LABEL>"
				+"<vCard:NOTE></vCard:NOTE>"
				+"</contact>");

		try
		{
			contacts.appendChild(node);
		    var pos = contacts.childNodes.length - 1;
		    while(pos > index)
		    {
		        MoveThis("down");
		        pos--;
		    }
		    ItemListLoad();							
		}
		catch(e)
		{
			alert("Error in blank ContactAdd():  " + e.message);
		}


}

function ContactNew()
{
		document.getElementById("contact_type").selectedIndex = 0;			
		document.getElementById("fullname").value = "";
		document.getElementById("company").value = "";
		document.getElementById("title").value = "";	    
		document.getElementById("address").value = "";
		document.getElementById("contact_phones").value = "999.999.9999 (office)\n"
															+"999.999.9999 (fax)\n"
															+"999.999.9999 (cell)\n"
															+"xxxxxxxx (im)";
		document.getElementById("contact_links").value = "Email:xxx@xxx.com\n"
															+"Web site:http://\n"
															+"Blog:http://\n"
															+"Financial Data:http://finance.yahoo.com/q?s=[STOCK SYMBOL]";	   

}
		
function ContactLoad()
{

	try
	{

       var parent = prx.getElementsByTagName("prx");
       
       if(gotoNext != null)
       {
			document.getElementById("hdnContactIndex").value = gotoNext;
			gotoNext = null;
       }
       
	   //Contacts
	   var index = parseInt(document.getElementById("hdnContactIndex").value);

	   var contacts = prx.getElementsByTagNameNS("", "contacts", parent, 0);
	   
	    contacts_length = 0;
		if(contacts.childNodes.length)
		{
			contacts_length = contacts.childNodes.length;
		}
		
		
	   //New Release
	   if(contacts_length == 0)
	   {
			//Blank Record
			ContactNew();
			GoToReset();			
	   }	
		
	   if(contacts_length > 0)
	   {
		    //document.getElementById("contactTotal").innerHTML = contacts_length;					    
			if(index > (contacts_length - 1))
			{
//				var option = new Option();
//				option.value = index + 1;
//				option.text = index + 1;
//                var select = document.forms['Form1'].elements['cboGoTo'];				
//				if(select)
//				{
//				    select.options.add(option);				
//				}
				//Blank Record
				ContactNew();
				ContactSave();
				ContactLoad();
//				if(select)
//				{
//				    select.options[index].selected = true;																
//				}
//    		    document.getElementById("contactTotal").innerHTML = contacts_length + 1;					    
				//Nothing to load.																
				return;
			}
			var contact_type = NodeValue("vCard","CATEGORIES",contacts,index);
			ctr = document.getElementById("contact_type").options.length;
			while(ctr--)
			{
				if(document.getElementById("contact_type").options[ctr].text == contact_type)
				{
					document.getElementById("contact_type").options[ctr].selected = true;
				}
			}

			document.getElementById("fullname").value = NodeValue("vCard","FN",contacts, index);
			document.getElementById("company").value = NodeValue("vCard","Orgname",contacts, index);
			document.getElementById("title").value = NodeValue("vCard","TITLE",contacts, index);	    
			var address =  NodeValue("vCard","LABEL",contacts, index);	    
			var contact_phones= NodeValue("vCard","NOTE",contacts, index);	    	    

			var rx =  new RegExp(/<br\/>/g);
			document.getElementById("address").value = address.replace(rx,'\n');
			document.getElementById("contact_phones").value = contact_phones.replace(rx,'\n');		
			
			
			var contact = prx.getElementsByTagNameNS("", "contact", contacts, index);

			var links = prx.getElementsByTagNameNS("vCard", "EMAIL", contact, -1);
			var linkList = "";
            
           
			if(links)
			{
				if(links[0])
				{
					for(var ctr2=0;ctr2 < links.length;ctr2++)
					{
						label = "";
						link = "";			
						url = links[ctr2];
						if(url[0])
						{
							url = url[0];
						}
						var label = "";
						link = "";
						label = NodeValue("","label",url, ctr2)
						label = url.getElementsByTagName("label");
						if(label[0])
						{
							label = label[0];
						}
						label = label.firstChild.nodeValue;				
						if(url.firstChild)
						{
							link = url.firstChild.nodeValue;
						}
						link = link.replace(new RegExp(/ /g),'');
						link = link.replace(new RegExp(/\n/g),'');			
						if(label.length > 0 && link.length > 0)
						{
							linkList += label + ":" + link + "\n";
						}
					}	        	    
				}	    
				else
				{
					if(links)
					{
						url = links;
						label = "";
						link = "";
						label = NodeValue("","label",url, 0)
						if(url.firstChild)
						{
							link = url.firstChild.nodeValue;
						}
						link = link.replace(new RegExp(/ /g),'');
						link = link.replace(new RegExp(/\n/g),'');			
						if(label.length > 0 && link.length > 0)
						{
							linkList += label + ":" + link + "\n";
						}		
					}
				}
			}

            
			links = prx.getElementsByTagNameNS("vCard", "URL", contact, -1);

			if(links)
			{
				if(links[0])
				{
					for(var ctr2=0;ctr2 < links.length;ctr2++)
					{
						label = "";
						link = "";			
						url = links[ctr2];
						if(url[0])
						{
							url = url[0];
						}
						var label = "";
						link = "";
						label = NodeValue("","label",url, ctr2)
						label = url.getElementsByTagName("label");
						if(label[0])
						{
							label = label[0];
						}
						label = label.firstChild.nodeValue;				
						if(url.firstChild)
						{
							link = url.firstChild.nodeValue;
						}
						link = link.replace(new RegExp(/ /g),'');
						link = link.replace(new RegExp(/\n/g),'');			
						if(label.length > 0 && link.length > 0)
						{
							linkList += label + ":" + link + "\n";
						}
					}	        	    
				}	    
				else
				{
					if(links)
					{
						url = links;
						label = "";
						link = "";
						label = NodeValue("","label",url, 0)
						if(url.firstChild)
						{
							link = url.firstChild.nodeValue;
						}
						link = link.replace(new RegExp(/ /g),'');
						link = link.replace(new RegExp(/\n/g),'');			
						if(label.length > 0 && link.length > 0)
						{
							linkList += label + ":" + link + "\n";
						}		
					}
				}
			}
			document.getElementById("contact_links").value = linkList;        		


//            var select = document.forms['Form1'].elements['cboGoTo'];
//			if(select)
//			{
//			    if(select.options.length != contacts.childNodes.length)
//			    {
//				    select.options.length = 0;
//				    for(var ctr=0;ctr<contacts.childNodes.length;ctr++)
//				    {
//					    var option = new Option(ctr+1,ctr+1);
//					    //option.value = ctr + 1;
//					    //option.text = ctr + 1;
//                        //select.options[ctr] = option;					    
//					    select.options[ctr] = option;
//				    }
//			    }		
//			    select.options[index].selected = true;
//			}
		}
        ItemListLoad();		
	}
	catch(e)
	{
		alert("Error loading contacts:  " + e.message);
	}
}		

function ContactSave()
{

	try
	{
	    if(!document.getElementById("hdnContactIndex") || !document.getElementById("fullname"))
	    {
	        return;
	    }
	   //Contacts
	   var index = parseInt(document.getElementById("hdnContactIndex").value);
	   //Blank record.
	   if(index == 0 && document.getElementById("fullname").value.length == 0)
	   {
			return;
	   }	   

       var parent = prx.getElementsByTagName("prx");	  
	   var contacts = prx.getElementsByTagNameNS("", "contacts", parent, 0);	
	   var contact;
	   

	   
	   if(contacts)
	   {
	   
			if(index > (contacts.childNodes.length - 1))
			{
				ContactAdd(index);
				contacts = prx.getElementsByTagNameNS("", "contacts", parent, 0);					
			}
	   }

	   contact = prx.getElementsByTagNameNS("", "contact", contacts, index);
	   

	   if(contact)
	   {
			//Contacts
			var rx =  new RegExp(/\n/g);
			var address = document.getElementById("address").value.replace(rx,"<br/>");
			var contact_phones = document.getElementById("contact_phones").value.replace(rx,"<br/>");					
			rx =  new RegExp(/\r/g);
			address = address.replace(rx,"");
			contact_phones = contact_phones.replace(rx,"");								
			if(address.length > 5)
			{
				if(address.substring(address.length - 5) == "<br/>")
				{
					address = address.substring(0,address.length - 5);
				}
			}
			if(contact_phones.length > 5)
			{
				if(contact_phones.substring(contact_phones.length - 5) == "<br/>")
				{
					contact_phones = contact_phones.substring(0,contact_phones.length - 5);
				}
			}			
			var node = XMLFromText("<contact xmlns:vCard=\"" + vCardNS + "\"><vCard:CATEGORIES><![CDATA[" + document.getElementById("contact_type").options[document.getElementById("contact_type").selectedIndex].text
						+ "]]></vCard:CATEGORIES><vCard:FN><![CDATA[" + document.getElementById("fullname").value + "]]></vCard:FN>"
			       		+"<vCard:ORG><vCard:Orgname><![CDATA[" + document.getElementById("company").value + "]]></vCard:Orgname></vCard:ORG>"
			       		+"<vCard:TITLE><![CDATA[" + document.getElementById("title").value + "]]></vCard:TITLE>"
			       		+"<vCard:LABEL vCard:TYPE=\"http://www.w3.org/2001/vcard-rdf/3.0#postal\"><![CDATA[" + address + "]]></vCard:LABEL>"
			       		+"<vCard:NOTE><![CDATA[" + contact_phones + "]]></vCard:NOTE>"
			       		+"</contact>");

				try
				{
					//contacts = contact.parentNode;
					contacts.replaceChild(node, contact);
             	    contact = prx.getElementsByTagNameNS("", "contact", contacts, index);
				}
				catch(e)
				{
					alert("Error during Save1:  " + e.message);
				}

				var contact_links = document.getElementById("contact_links").value.split("\n");

				if(contact_links[0].length > 0)
				{
					for(var ctr = 0;ctr < contact_links.length;ctr++)
					{
						var link_parts = contact_links[ctr].split(":");

						if(link_parts.length > 1)
						{
							//Email
							if(contact_links[ctr].indexOf("@") > 0)
							{
								link_parts[1] = link_parts[1].replace(new RegExp(/\n/g),"");
								link_parts[1] = link_parts[1].replace(new RegExp(/ /g),"");							 		
								var nodeEmail = XMLFromText("<vCard:EMAIL xmlns:vCard=\"http://www.w3.org/2001/vcard-rdf/3.0#\" "
										+ "vCard:TYPE=\"http://www.w3.org/2001/vcard-rdf/3.0#internet\"><![CDATA["
										+ link_parts[1] + "]]><label><![CDATA[" + link_parts[0] + "]]></label></vCard:EMAIL>");								
								contact.appendChild(nodeEmail);							 		
			    			}
							else
							{

								if(link_parts.length > 2)
								{
									link_parts[1] = link_parts[1] + ":" + link_parts[2];
								}
								else
								{
									if(link_parts[1].indexOf("www.") == 0)
									{
										link_parts[1] = "http://" + link_parts[1];
									}
								}
								link_parts[1] = link_parts[1].replace(new RegExp(/\n/g),"");
								link_parts[1] = link_parts[1].replace(new RegExp(/ /g),"");							 		
								var nodeURL = XMLFromText("<vCard:URL xmlns:vCard=\"http://www.w3.org/2001/vcard-rdf/3.0#\"><![CDATA["
										+ link_parts[1] + "]]><label><![CDATA[" + link_parts[0] + "]]></label></vCard:URL>");								
								contact.appendChild(nodeURL);							 																		
							}
						}
					}
				}
	
			}
		}
		catch(e)
		{
			alert("Error during Save2: " + e.message);
		}				
 	  


}		

function ReleaseLoad()
{

    var parent = prx.getElementsByTagName("prx");
    var newslines = prx.getElementsByTagNameNS("","newslines",parent,0);       
	   
	document.getElementById("headline").value = NodeValue("","headline",newslines, 0);
	document.getElementById("dateline").value = NodeValue("","dateline",newslines, 0);
	document.getElementById("subheadline").value = NodeValue("","subheadline",newslines, 0);
	//var x = document.getElementById("divMain").style.left.replace(RegExp(/px/),"");
	//var y = document.getElementById("divMain").style.top.replace(RegExp(/px/),"");
	//x = parseInt(x) + 120;
	//y = parseInt(y) + 350;
	//var xy = Position.positionedOffset(document.getElementById("divEditorXY"));
	//var x = xy[0];
	//var y = xy[1];
	//moveIFrame("editorDiv" +  "\t" + x + "\t" + y + "\t80%\t900");
	var body = NodeValue("","body",newslines, 0);
    $("editor").value = body;
}

function ReleaseSave()
{

	try
	{
	   var parent = prx.getElementsByTagName("prx");
	   var newslines = prx.getElementsByTagNameNS("","newslines",parent,0);	   
       var headline = prx.getElementsByTagNameNS("","headline",newslines,0);
       var dateline = prx.getElementsByTagNameNS("","dateline",newslines,0);       
       var subhead = prx.getElementsByTagNameNS("","subheadline",newslines,0);              
       var body = prx.getElementsByTagNameNS("","body",newslines,0);                     
       
       var newNode;

	    newNode = XMLFromText("<headline><![CDATA[" + document.getElementById("headline").value + "]]></headline>");
		newslines.replaceChild(newNode,headline);

	    newNode = XMLFromText("<dateline><![CDATA[" + document.getElementById("dateline").value + "]]></dateline>");
		newslines.replaceChild(newNode,dateline);

	    newNode = XMLFromText("<subheadline><![CDATA[" + document.getElementById("subheadline").value + "]]></subheadline>");
		newslines.replaceChild(newNode,subhead);

        var html = EditorGet();
        if(html != null && html != "undefined")
        {
	        newNode = XMLFromText("<body><![CDATA[" + html + "]]></body>");
		    newslines.replaceChild(newNode,body);
		}
	   		
	 }
	 catch(e)
	 {
		alert("Error in ReleaseSave:  " + e.message);
	 }
}

function QuotesLoad()
{

        var parent = prx.getElementsByTagName("prx");
        var newslines = prx.getElementsByTagNameNS("","newslines",parent,0);        
	    //var x = document.getElementById("divMain").style.left.replace(RegExp(/px/),"");
	    //var y = document.getElementById("divMain").style.top.replace(RegExp(/px/),"");        
	    //x = parseInt(x) + 120;
	    //y = parseInt(y) + 175;
	    //var xy = Position.cumulativeOffset(document.getElementById("divEditorXY"));
		//moveIFrame("editorDiv" +  "\t" + x + "\t" + y + "\t80%\t900");
		var quotes = NodeValue("","quotes",newslines, 0);
	    $("editor").value = quotes;
}

function QuotesSave()
{

	try
	{
	   var parent = prx.getElementsByTagName("prx");
	   var newslines = prx.getElementsByTagNameNS("","newslines",parent,0);	   
       var node = prx.getElementsByTagNameNS("","quotes",newslines,0);

       if(!node)
       {
            var html = EditorGet();
            if(html != null && html != "undefined")
            {
    			node = XMLFromText("<quotes><![CDATA[" + html + "]]></quotes>");
			    newslines.appendChild(node);
			}
	   }
	   else
	   {
            var html = EditorGet();
            if(html != null && html != "undefined")
            {
    		    newNode = XMLFromText("<quotes><![CDATA[" + html + "]]></quotes>");
			    newslines.replaceChild(newNode,node);
			}
	   }		
	 }
	 catch(e)
	 {
		alert("Error in QuotesSave():  " + e.message);
	 }
}


function BoilerplateLoad()
{

        var parent = prx.getElementsByTagName("prx");
        var newslines = prx.getElementsByTagNameNS("","newslines",parent,0);        
	    //var x = document.getElementById("divMain").style.left.replace(RegExp(/px/),"");
	    //var y = document.getElementById("divMain").style.top.replace(RegExp(/px/),"");        
	    //x = parseInt(x) + 150;
	    //y = parseInt(y) + 200;
	    //var xy = Position.cumulativeOffset(document.getElementById("divEditorXY"));
		//moveIFrame("editorDiv" +  "\t" + x + "\t" + y + "\t80%\t900");
		var bp = NodeValue("","boilerplate",newslines, 0);
		$("editor").value = bp;
}

function BoilerplateSave()
{

	try
	{
	   var parent = prx.getElementsByTagName("prx");
	   var newslines = prx.getElementsByTagNameNS("","newslines",parent,0);	   
       var node = prx.getElementsByTagNameNS("","boilerplate",newslines,0);
       if(!node)
       {
            var html = EditorGet();
            if(html != null && html != "undefined")
            {
			    node = XMLFromText("<boilerplate><![CDATA[" + html + "]]></boilerplate>");
			    newslines.appendChild(node);
			}
	   }
	   else
       {
	        var html = EditorGet();
            if(html != null && html != "undefined")
            {
		        newNode = XMLFromText("<boilerplate><![CDATA[" + html + "]]></boilerplate>");
			    newslines.replaceChild(newNode,node);
			}
	   }		
	 }
	 catch(e)
	 {
		alert("Error in BoilerplateSave():  " + e.message);
	 }
}

function OptionsLoad()
{

	try
	{
	  var parent = prx.getElementsByTagName("prx");
	  document.getElementById("permalinkHTML").value = NodeValue("","link",parent, 0);        
	  document.getElementById("permalinkPRX").value = NodeValue("","prxlink",parent, 0);      
	  
	  	
      parent = prx.getElementsByTagName("services");
  		
		
       //List of tags
       var tags = "";
	   service = prx.getElementsByTagNameNS("service", "content", parent, -1);       

       for(var ctr=0;ctr < service.length;ctr++)
       {
			type = NodeValue("","type",service[ctr], 0);
			if(type == "digg")
			{
				document.getElementById("digg").checked = true;
			}
			if(type == "del.icio.us")
			{
				document.getElementById("delicious").checked = true;
			}			
			if(type == "technorati")
			{
				if(tags.length == 0)
				{
					tags = NodeValue("service","title",service[ctr], 0);
				}
				else
				{
					tags += "," + NodeValue("service","title",service[ctr], 0);
				}
			}			
       }
       document.getElementById("technorati_tags").value = tags;
       if(tags.length > 0)
       {
			document.getElementById("technorati").checked = true;
       }
       TechnoratiTagsDefault();
      }
      catch(e)
      {
		alert("Error in OptionsLoad():  " + e.message);
      }		

}

function OptionsSave()
{

	try
	{
       var parent = prx.getElementsByTagName("prx");
	  
	   var link = prx.getElementsByTagNameNS("","link",parent,0);
	   if(link)
	   {
			node = XMLFromText("<link><![CDATA[" + document.getElementById("permalinkHTML").value + "]]></link>");
			parent.replaceChild(node,link);
	   }
	   var prxlink = prx.getElementsByTagNameNS("","prxlink",parent,0);
	   if(prxlink)
	   {
			node = XMLFromText("<prxlink><![CDATA[" + document.getElementById("permalinkPRX").value + "]]></prxlink>");
			parent.replaceChild(node,prxlink);
	   }	   
       
       var services = prx.getElementsByTagNameNS("","services",parent,0);
       
       var node = XMLFromText("<services xmlns:service=\"http://search.yahoo.com/mrss/\" />");
       parent.replaceChild(node,services);	
       
       services = prx.getElementsByTagNameNS("","services",parent,0);              
       
       
		if(document.getElementById("technorati_tags").value.length > 0)
		{

			var ti_tags = document.getElementById("technorati_tags").value.replace(new RegExp(/, /g),",");					
			ti_tags = ti_tags.replace("\r","");
			ti_tags = ti_tags.replace("\n","");			
			var ti_tagArray = ti_tags.split(",");
			for(var ctr=0;ctr < ti_tagArray.length;ctr++)
			{
					var tURL = "http://www.technorati.com/tag/" + escape(ti_tagArray[ctr].replace(new RegExp(/ /g),"+"));					
					node = XMLFromText("<service:content xmlns:service=\"http://search.yahoo.com/mrss/\" url=\"" + AttribClean(tURL) + "\"><service:title><![CDATA[" + ti_tagArray[ctr] + "]]></service:title><type domain=\"http://purl.org/prx/1.0/\">technorati</type></service:content>");
	   				services.appendChild(node);
	   				
			}
		}
		if(document.getElementById("digg").checked == true)
		{		
			node = XMLFromText("<service:content xmlns:service=\"http://search.yahoo.com/mrss/\" url=\"http://www.digg.com/submit/?phase=3&amp;url=\"><service:title>Digg this</service:title><type domain=\"http://purl.org/prx/1.0/\">digg</type></service:content>");
			services.appendChild(node);
		}		
		if(document.getElementById("delicious").checked == true)
		{
			node = XMLFromText("<service:content xmlns:service=\"http://search.yahoo.com/mrss/\" url=\"http://del.icio.us/post?url=\"><service:title>Add to del.icio.us</service:title><type domain=\"http://purl.org/prx/1.0/\">del.icio.us</type></service:content>");				
			services.appendChild(node);
		}		
	 }
	 catch(e)
	 {
		alert("Error in OptionsSave()  " + e.message);
	 }

}

function CategoriesLoad()
{

	try
	{

       var parent = prx.getElementsByTagName("prx");
       parent = prx.getElementsByTagNameNS("","categories",parent,0);       
       
       //Categories
       //industry
       //document.getElementById("industry").options.selected = -1;
       industries = prx.getElementsByTagNameNS("", "industry", parent, -1);
       for(var ctr=0;ctr < industries.length;ctr++)
       {
			for(ctr2=0;ctr2<document.getElementById("industry").options.length;ctr2++)
			{
				if(document.getElementById("industry").options[ctr2].text == industries[ctr].firstChild.nodeValue)
				{
					document.getElementById("industry").options[ctr2].selected = true;
				}
			}
       }       
       //MSA
       msas = prx.getElementsByTagNameNS("", "msa", parent, -1);
       for(var ctr=0;ctr < msas.length;ctr++)
       {
			for(ctr2=0;ctr2<document.getElementById("msa").options.length;ctr2++)
			{
				if(document.getElementById("msa").options[ctr2].text == msas[ctr].firstChild.nodeValue)
				{
					document.getElementById("msa").options[ctr2].selected = true;
				}
			}
       }       

       //Country
       countries = prx.getElementsByTagNameNS("", "country", parent, -1);
       for(var ctr=0;ctr < countries.length;ctr++)
       {
			for(ctr2=0;ctr2<document.getElementById("country").options.length;ctr2++)
			{
				if(document.getElementById("country").options[ctr2].text == countries[ctr].firstChild.nodeValue)
				{
					document.getElementById("country").options[ctr2].selected = true;
				}
			}
       }       


       //List of tags
	   parent = prx.getElementsByTagName("prx");       
       parent = prx.getElementsByTagNameNS("","tags",parent,0);              
       var tags = "";
       for(var ctr=0;ctr < prx.getElementsByTagNameNS("", "tag", parent, -1).length;ctr++)
       {
			if(tags.length == 0)
			{
				tags = NodeValue("","tag",parent, ctr);
				}
				else
				{
				tags += "," + NodeValue("","tag",parent, ctr);
			}
       }
       document.getElementById("tags").value = tags;
      }
      catch(e)
      {
		alert(e.message);
      }
}

function TechnoratiTagsDefault()
{
	if(document.getElementById("technorati").checked == true && document.getElementById("technorati_tags").value.length == 0)
	{
	   var parent = prx.getElementsByTagName("prx");       
       parent = prx.getElementsByTagNameNS("","tags",parent,0);              
       var tags = "";
       for(var ctr=0;ctr < prx.getElementsByTagNameNS("", "tag", parent, -1).length;ctr++)
       {
			if(tags.length == 0)
			{
				tags = NodeValue("","tag",parent, ctr);
				}
				else
				{
				tags += "," + NodeValue("","tag",parent, ctr);
			}
       }
       document.getElementById("technorati_tags").value = tags;	
	}
}

function CategoriesSave()
{

	try
	{
       var parent = prx.xmlDoc.getElementsByTagName("prx");
       var categories = prx.getElementsByTagNameNS("","categories",parent[0],-1);
       
       node = XMLFromText("<categories/>");
       
       parent[0].replaceChild(node,categories[0]);
       
       categories = prx.getElementsByTagNameNS("","categories",parent[0],0);       
       
       //Categories
       //industry
       for(var ctr=0;ctr < document.getElementById("industry").options.length;ctr++)
       {
			if(document.getElementById("industry").options[ctr].selected)
			{
				node = XMLFromText("<industry domain=\"http://purl.org/prx/1.0/\"><![CDATA[" + document.getElementById("industry").options[ctr].text + "]]></industry>");
				categories.appendChild(node);
			} 
       }       
       //MSA
       for(var ctr=0;ctr < document.getElementById("msa").options.length;ctr++)
       {
			if(document.getElementById("msa").options[ctr].selected)
			{
				node = XMLFromText("<msa domain=\"http://www.whitehouse.gov/omb/inforeg/statpolicy.html#ms\"><![CDATA[" + document.getElementById("msa").options[ctr].text + "]]></msa>");
				categories.appendChild(node);
			} 
       }       
       //Country
       for(var ctr=0;ctr < document.getElementById("country").options.length;ctr++)
       {
			if(document.getElementById("country").options[ctr].selected)
			{
				node = XMLFromText("<country domain=\"http://www.iso.org/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/index.html\"><![CDATA[" + document.getElementById("country").options[ctr].text + "]]></country>");
				categories.appendChild(node);
			} 
       }              

       //List of tags
       var tags = prx.getElementsByTagNameNS("","tags",parent[0],-1);
       node = XMLFromText("<tags/>");     
       parent[0].replaceChild(node,tags[0]);       
       tags = prx.getElementsByTagNameNS("","tags",parent[0],0);                
   	   var tagText = document.getElementById("tags").value;
   	   tagText = tagText.replace("\r","");
   	   tagText = tagText.replace("\n","");
	   var tagArray = tagText.split(",");
	   for(var ctr=0;ctr < tagArray.length;ctr++)
	   {
	     	node = XMLFromText("<tag><![CDATA[" + tagArray[ctr] + "]]></tag>");
	   		tags.appendChild(node);
	   }       		       		       		 
	  }
	  catch(e)
	  {
		alert(e.message);
	  }
}

function LinksSample()
{
	try
	{
		document.getElementById("linkSample1").innerHTML = "<a href=\"" + document.getElementById("linkurl").value + "\" target='_blank'>" + document.getElementById("linktext").value + "</a>";	
		document.getElementById("linkSample2").innerHTML = document.getElementById("linkdescr").value;	
		if(document.getElementById("linkimage_url").value.length == 0)
		{
			document.getElementById("linkImage").style.display = "none";
		}
		else
		{
			document.getElementById("linkImage").src = document.getElementById("linkimage_url").value;		
			document.getElementById("linkImage").style.display = "block";	
		}
	}
	catch(e)
	{
		alert("Error in LinksSample():  " + e.message);
	}
	
}

function LinksAdd(index)
{

			var parent = prx.getElementsByTagName("prx");
			var links = prx.getElementsByTagNameNS("", "links", parent, 0);			
			node = XMLFromText("<link:content xmlns:link=\"http://search.yahoo.com/mrss/\" url=\"\">"
					+"<link:title></link:title>"
					+"<link:description></link:description>"
					+"<group>2</group>"
					+"<link:thumbnail url=\"\"></link:thumbnail></link:content>");
   			try
			{
				links.appendChild(node);
			    var pos = links.childNodes.length - 1;
			    while(pos > index)
			    {
			        MoveThis("down");
			        pos--;
			    }
			    ItemListLoad();				
			}
			catch(e)
			{
				alert("Error in LinksAdd():  " + e.message);
			}
}

function LinksNew()
{
	document.getElementById("linkurl").value = "";
	document.getElementById("linktext").value = "";
	document.getElementById("linkdescr").value = "";
	document.getElementById("linkgroup").selectedIndex = 1;
	document.getElementById("linkimage_url").value = "";
	LinksSample();
}

function LinksLoad()
{
   
	   //Contacts
	   try
	   {
			var parent = prx.getElementsByTagName("prx");
			var links = prx.getElementsByTagNameNS("", "links", parent, 0);			
			
			if(gotoNext != null)
			{
					document.getElementById("hdnLinkIndex").value = gotoNext;
					gotoNext = null;
			}			
		
			var index = parseInt(document.getElementById("hdnLinkIndex").value);
	    	var links_length = 0;
		
			if(links)
			{
				if(links.childNodes)
				{
					links_length = links.childNodes.length;
				}
			}
			
			if(links_length == 0)
			{
				LinksNew();
				GoToReset();											
			}

			if(links_length > 0)
			{ 	
			    //document.getElementById("linkTotal").innerHTML = links_length;					    
				if(index > (links_length - 1))
				{
//					var option = new Option();
//					option.value = index + 1;
//					option.text = index + 1;
//					var select = document.forms['Form1'].elements['cboGoTo'];
//					if(select)
//					{
//					    select.options.add(option);
//					    select.options[index].selected = true;								
//					}
					LinksNew();
    			    //document.getElementById("mmTotal").innerHTML = items_length + 1;
    			    LinksSave();
    			    LinksLoad();							
    			    //document.getElementById("linkTotal").innerHTML = links_length + 1;					    
					return;
				}

				var link = prx.getElementsByTagNameNS("link", "content", links, index);
				
				if(link)
				{
					document.getElementById("linkurl").value = link.getAttribute("url");		
					document.getElementById("linktext").value = NodeValue("link","title",link, 0);
					document.getElementById("linkdescr").value = NodeValue("link","description",link, 0);
				
					var group = NodeValue("","group",link,0);
					ctr = document.getElementById("linkgroup").options.length;
					while(ctr--)
					{
						if(document.getElementById("linkgroup").options[ctr].text == group)
						{
							document.getElementById("linkgroup").options[ctr].selected = true;
						}
					}					
					elem2 = prx.getElementsByTagNameNS("link", "thumbnail", link, 0);	
					if(elem2)
					{    
						document.getElementById("linkimage_url").value = elem2.getAttribute("url");
					}
				}
//				var select = document.forms['Form1'].elements['cboGoTo'];
//				if(select)
//				{
//				    if(select.options.length != links.childNodes.length)
//				    {
//					    select.options.length = 0;
//					    for(var ctr=0;ctr<links.childNodes.length;ctr++)
//					    {
//						    var option = new Option();
//						    option.value = ctr + 1;
//						    option.text = ctr + 1;
//						    select.options.add(option);
//					    }
//				    }		
//				    select.options[index].selected = true;				
//				}
			}
			LinksSample();	
			ItemListLoad();    					
		}
		catch(e)
		{
			alert("Error loading links:  " + e.message);
		}


}		

function LinksSave()
{

	try
	{
	    if(!document.getElementById("linktext") || !document.getElementById("linkurl"))
	    {
	        return;
	    }
	   
	   index = parseInt(document.getElementById("hdnLinkIndex").value);       
       //Blank record.
       if(index == 0 && document.getElementById("linktext").value.length == 0 && document.getElementById("linkurl").value.length == 0)
       {
			return;
       }	   
	   
       var parent = prx.getElementsByTagName("prx");
       var links = prx.getElementsByTagNameNS("","links",parent,0);       
       var link;
   
	   if(links)
	   {
			if(index > (links.childNodes.length - 1))
			{
				LinksAdd(index);
				links = prx.getElementsByTagNameNS("", "links", parent, 0);					
			}
            try {
                link = prx.getElementsByTagNameNS("link", "content", links, index);				
            }
            catch(e)
            {
            }

	   }	   

	   
	   
	   if(link)
	   {
		   //Links
 		    var link_url = AttribClean(document.getElementById("linkurl").value);
//			if(link_url.indexOf("<") >= 0)
//			{
//			    alert("'<' is not allowed.  Please begin your url with 'http://'.  Do not use HTML code.");
//			    return;
//			} 		    
		    if(link_url.length > 0 && link_url.indexOf("http") < 0)
		    {
		        link_url = "http://" + link_url;
		    }		    
		    var linkThumb_url = AttribClean(document.getElementById("linkimage_url").value);
//			if(linkThumb_url.indexOf("<") >= 0)
//			{
//			    alert("'<' is not allowed.  Please begin your url with 'http://'.  Do not use HTML code.");
//			    return;
//			} 		    		    
		    if(linkThumb_url.length > 0 && linkThumb_url.indexOf("http") < 0)
		    {
		        linkThumb_url = "http://" + linkThumb_url;
		    }
		    
		    

			node = XMLFromText("<link:content xmlns:link=\"http://search.yahoo.com/mrss/\" url=\"" + link_url + "\">"
					+"<link:title><![CDATA[" + document.getElementById("linktext").value + "]]></link:title>"
					+"<link:description><![CDATA[" + document.getElementById("linkdescr").value + "]]></link:description>"
					+"<group>" + document.getElementById("linkgroup").options[document.getElementById("linkgroup").selectedIndex].value + "</group>"
					+"<link:thumbnail url=\"" + linkThumb_url + "\"></link:thumbnail></link:content>");

			links = link.parentNode;
			links.replaceChild(node,link);			
	   }
	}
	catch(e)
	{
		alert("Error in LinksSave():  " + e.message);
	}
		   
	
}		

function MMSample()
{
    setTimeout('MMSampleDelay()',500);
}

function MMSampleDelay()
{
	try
	{
		var img = new Image();
		var wRation = 0;
		var hRatio = 0;
		var wChange = false;
		var hChange = false;
		var defaultImage = true;
		
		//Thumbnail or Image
		if(document.getElementById("mmthumb").value.length > 0)
		{
		    img.src = document.getElementById("mmthumb").value;
		    defaultImage = false;	
		}
		else
		{
		    if(document.getElementById("mmtype").options[document.getElementById("mmtype").selectedIndex].value == "Image")
		    {
			    img.src = document.getElementById("mmurl").value;	
			    defaultImage = false;
		    }
		}

		if(!defaultImage)
		{
			if(document.getElementById("mmwidth").value != document.getElementById("mmSample1").width)
			{
				wChange = true;
			}
			if(document.getElementById("mmheight").value != document.getElementById("mmSample1").height)
			{
				hChange = true;
			}			

			if(document.getElementById("mmwidth").value == "" || document.getElementById("mmwidth").value == "null" || document.getElementById("mmwidth").value == "0" || document.getElementById("mmwidth").value == "NaN")
			{
				if(img.width)
				{
					document.getElementById("mmwidth").value = img.width;
					document.getElementById("mmSample1").width = img.width;	
				}
			}			

			document.getElementById("mmSample1").width = document.getElementById("mmwidth").value;

			if(document.getElementById("mmheight").value == "" || document.getElementById("mmheight").value == "null" || document.getElementById("mmheight").value == "0" || document.getElementById("mmheight").value == "NaN")
			{
				if(img.height)
				{
					document.getElementById("mmheight").value = img.height;	
					document.getElementById("mmSample1").height = img.height;				
				}
			}
			document.getElementById("mmSample1").height = document.getElementById("mmheight").value;	
			
			//Maintain Aspect Ration
			if(img.height && img.width)
			{
				wRatio = img.width / img.height;
				//wRatio = Math.round(wRatio*100)/100;  
				hRatio = img.height / img.width;
				//hRatio = Math.round(hRatio*100)/100;  			
				if(wChange)
				{
					document.getElementById("mmheight").value = Math.round(document.getElementById("mmwidth").value * hRatio);	
					document.getElementById("mmSample1").height = document.getElementById("mmheight").value;	
				}
				if(hChange)
				{
					document.getElementById("mmwidth").value = Math.round(document.getElementById("mmheight").value * wRatio);	
					document.getElementById("mmSample1").width = document.getElementById("mmwidth").value;				
				}				
			}
		}
		else
		{
			document.getElementById("mmwidth").value = "";
			document.getElementById("mmheight").value = "";
			img.src = document.getElementById("mmSample1").src;	
			if(img.height)
			{
				document.getElementById("mmSample1").height = img.height;							
			}
			if(img.width)
			{
				document.getElementById("mmSample1").width = img.width;					
			}
		}

		document.getElementById("mmSample1").src = img.src;	
		document.getElementById("mmSample2").innerHTML = "<a href=\"" + document.getElementById("mmurl").value + "\" target='_blank'>" + document.getElementById("mmtext").value + "</a>";		
	}
	catch(e)
	{
		alert("Error in MMSample():  " + e.message);
	}
}

function MMAdd(index)
{

       var parent = prx.getElementsByTagName("prx");
       var items = prx.getElementsByTagNameNS("","multimedia",parent,0);
	   var node = XMLFromText("<media:content xmlns:media=\"http://search.yahoo.com/mrss/\" url='' "
							+"height='' width=''><media:title></media:title>"
							+"<type domain=\"http://purl.org/prx/1.0/\">Image</type></media:content>"); 
   		try
		{
			items.appendChild(node);
			var pos = items.childNodes.length - 1;
			while(pos > index)
			{
			    MoveThis("down");
			    pos--;
			}
			ItemListLoad();
			
		}
		catch(e)
		{
			alert("Error in MMAdd():  " + e.message);
		}

}

function MMNew()
{
		document.getElementById("mmurl").value = "";
		document.getElementById("mmheight").value = "";
		document.getElementById("mmwidth").value = "";
		document.getElementById("mmtext").value = "";
		document.getElementById("mmthumb").value = "";
		document.getElementById("mmtype").selectedIndex = 2;
		MMTypeChange();
}

function MMLoad()
{
	try
	{
			document.getElementById("mmheight").value = "";
			document.getElementById("mmwidth").value = "";
			var parent = prx.getElementsByTagName("prx");
			var items = prx.getElementsByTagNameNS("", "multimedia", parent, 0);			
			var elem2;
			
			if(gotoNext != null)
			{
					document.getElementById("hdnMMIndex").value = gotoNext;
					gotoNext = null;
			}			
		
			var index = parseInt(document.getElementById("hdnMMIndex").value);
	    	var items_length = 0;
		
			if(items)
			{
				if(items.childNodes)
				{
					items_length = items.childNodes.length;
				}
			}
			
			if(items_length == 0)
			{
				GoToReset();			
				MMNew();
			}

			if(items_length > 0)
			{
			    //document.getElementById("mmTotal").innerHTML = items_length;					    
				if(index > (items_length - 1))
				{
//					var option = new Option();
//					option.value = index + 1;
//					option.text = index + 1;
//                    var select = document.forms['Form1'].elements['cboGoTo'];					
//					if(select)
//					{
//					    select.options.add(option);
//					    select.options[index].selected = true;								
//					}
					MMNew();
    			    //document.getElementById("mmTotal").innerHTML = items_length + 1;
    			    MMSave();
    			    MMLoad();				    
					return;
				}
		   
				var item = prx.getElementsByTagNameNS("media", "content", items, index);

				if(item)
				{
					var ctr = document.getElementById("mmtype").options.length;
					var type = NodeValue("","type",item, 0);
					while(ctr--)
					{
						if(document.getElementById("mmtype").options[ctr].text == type)
						{
							document.getElementById("mmtype").options[ctr].selected = true;
						}
					}								
					document.getElementById("mmurl").value = item.getAttribute("url");		
					document.getElementById("mmheight").value = item.getAttribute("height");
					document.getElementById("mmwidth").value = item.getAttribute("width");			
					document.getElementById("mmtext").value = NodeValue("media","title",item, 0);
					try {
					   elem2 = prx.getElementsByTagNameNS("media", "thumbnail", item, 0);	
					   if(elem2)
					   {    
					   	   document.getElementById("mmthumb").value = elem2.getAttribute("url");
					   }
					}
					catch(e)
					{
					}
					
				}
//                var select = document.forms['Form1'].elements['cboGoTo'];				
//				if(select)
//				{
//				    if(select.options.length != items.childNodes.length)
//				    {
//					    select.options.length = 0;
//					    for(var ctr=0;ctr<items.childNodes.length;ctr++)
//					    {
//						    var option = new Option();
//						    option.value = ctr + 1;
//						    option.text = ctr + 1;
//						    select.options.add(option);
//					    }
//				    }		
//				    select.options[index].selected = true;				
//				}
			}
			MMTypeChange();
			ItemListLoad();			
		}
		catch(e)
		{
			alert("Error in MMLoad():  " + e.message);
		}

}		

function MMListLoad()
{
		var parent = prx.getElementsByTagName("prx");
		var items = prx.getElementsByTagNameNS("", "multimedia", parent, 0);
		
		var mmList = document.getElementById("mmList");
		
		mmList.innerHTML = ''; 			

        if(items.childNodes.length > 0)
        {
            var daList = '<table width="95%" border="0" align="center" cellpadding="5" cellspacing="0" class="heading" style="border:solid 1px #CCCCCC">';
            var selected = '';
            var even = '';
            
            for(index=0;index < items.childNodes.length;index++)
            {
                if(index % 2 == 0)
                {
                    even = 'even';
                }
                else
                {
                    even = 'odd';
                }
                if(index == document.getElementById("hdnMMIndex").value)
                {
                    selected = 'checked="checked"';
                }
                else
                {
                    selected = '';
                }
                var item = prx.getElementsByTagNameNS("media", "content", items, index);        
                daList += '<tr class="' + even + '">';
                daList += '<td><a href="javascript:void(0)" onclick="gotoNext=' + index + ';MMSave();MMLoad();MMEdit();">edit</a></td><td colspan="3"><a href="' + item.getAttribute("url") + '" target="_blank" >' +  NodeValue("media","title",item, 0) + '</a></td>';
                daList += '<td style="background-color:#FFFFFF"><a href="javascript:void(0)" onclick="gotoNext=' + index + ';MMSave();MMLoad();Delete();MMLoad();" title="Delete Item"><img src="images/del_bt.gif" width="100" height="20" border="0" alt="Delete Item" /></a></td>';
                daList += '<td style="background-color:#FFFFFF"><a href="javascript:void(0)" onclick="gotoNext=' + index + ';MMSave();MMLoad();MoveThis(\'down\');MMSave();MMLoad();" title="Move this item\'s position up."><img src="images/arrow_up.gif" width="20" height="20" border="0" /></a><a href="javascript:void(0)" onclick="gotoNext=' + index + ';MMSave();MMLoad();MoveThis(\'up\');MMSave();MMLoad();" title="Move this item\'s position down."><img src="images/arrow_dn.gif" width="20" height="20" border="0" /></a></td>';            
                daList += '<td></td>';                        
                daList += '</tr>';
            }
            daList += '</table>';
            mmList.innerHTML = daList;
        }
        else
        {
            MMEdit();
        }
}

function ItemEdit()
{
    if(document.getElementById("itemEdit").style.display == "none")
    {
        document.getElementById("btnShowAll").style.visibility = "visible";    
        document.getElementById("btnShowAll2").style.visibility = "visible";    
        document.getElementById("itemEdit").style.display = "block";
        document.getElementById("itemList").style.display = "none";
    }
    else
    {
        document.getElementById("btnShowAll").style.visibility = "hidden";    
        document.getElementById("btnShowAll2").style.visibility = "hidden";    
        document.getElementById("itemEdit").style.display = "none";
        document.getElementById("itemList").style.display = "block";
        //IE6 Bug -- Images aren't showing.
        if(!window.XMLHttpRequest)
        {
            LoadPage(document.getElementById("hdnTab").value);
        }
    }
}

function MMSave()
{

	try
	{
	   if(!document.getElementById("hdnMMIndex") || !document.getElementById("mmtext") || !document.getElementById("mmurl"))
	   {
	        return;
	   }
	   
	   var index = parseInt(document.getElementById("hdnMMIndex").value);       
       //Blank record.
       if(index == 0 && document.getElementById("mmtext").value.length == 0 && document.getElementById("mmurl").value.length == 0)
       {
			return;
       }
	   
       var parent = prx.getElementsByTagName("prx");
       var items = prx.getElementsByTagNameNS("","multimedia",parent,0);

	   if(items)
	   {
			if(index > (items.childNodes.length -1))
			{
				MMAdd(index);
				items = prx.getElementsByTagNameNS("", "multimedia", parent, 0);					
			}
	   }	          
       
	   var item = prx.getElementsByTagNameNS("media", "content", items, index);
	   
	   if(item)
	   {
			//Multimedia
			var mm_url = AttribClean(document.getElementById("mmurl").value);
//			if(mm_url.indexOf("<") >= 0)
//			{
//			    alert("'<' is not allowed.  If this is a YouTube video, please use the 'Import From YouTube' feature.");
//			    return;
//			}
		    if(mm_url.length > 0 && mm_url.indexOf("http") < 0)
		    {
		        mm_url = "http://" + mm_url;
		    }
			var mm_thumb = AttribClean(document.getElementById("mmthumb").value);
//			if(mm_thumb.indexOf("<") >= 0)
//			{
//			    alert("'<' is not allowed.  If this is a YouTube video, please use the 'Import From YouTube' feature.");
//			    return;
//			}			
		    if(mm_thumb.length > 0 && mm_thumb.indexOf("http") < 0)
		    {
		        mm_thumb = "http://" + mm_thumb;
		    }		    			
			var node = XMLFromText("<media:content xmlns:media=\"http://search.yahoo.com/mrss/\" url='" + mm_url
							   +"' height='" + document.getElementById("mmheight").value + "' width='" + document.getElementById("mmwidth").value 
							   +"'><media:title><![CDATA[" + document.getElementById("mmtext").value + "]]></media:title>"
							   +"<type domain=\"http://purl.org/prx/1.0/\"><![CDATA[" + document.getElementById("mmtype").options[document.getElementById("mmtype").selectedIndex].value + "]]></type>"
							   +"<media:thumbnail url='" + mm_thumb + "'></media:thumbnail></media:content>"); 

			items.replaceChild(node,item);						
	   }
	}
	catch(e)
	{
		alert("Error in MMSave():  " + e.message);
	}	   
	
}		

function MMTypeChange()
{
	try
	{
		document.getElementById("mmWidthHeight").style.display = "none";
				
		switch(document.getElementById("mmtype").options[document.getElementById("mmtype").selectedIndex].value)
		{
				case "Image":
					document.getElementById("mmWidthHeight").style.display = "block";
					break;
				case "PDF":
					document.getElementById("mmSample1").src=img1.src;
					break;
				case "PodCast":
					document.getElementById("mmSample1").src=img2.src;
					break;			
				case "Video":
				    document.getElementById("mmSample1").src=img3.src;
					break;						
				case "Audio":
					document.getElementById("mmSample1").src=img4.src;
					break;										
				default:
					document.getElementById("mmtype").value = "Other";
					document.getElementById("mmSample1").src =img5.src;
					break;				
		}
		MMSample();
	}
	catch(e)
	{
		alert("Error in MMTypeChange():  " + e.message);
	}

}


function ItemListLoad()
{
    var itemType = "";
    var itemIndex = "";
        
    try
    {
        switch(document.getElementById("hdnTab").value)
        {
            case "contact":
                itemType = "contacts";
                itemIndex = "hdnContactIndex";
                break;           
            case "links":
                itemType = "links";
                itemIndex = "hdnLinkIndex";
                break;        
            case "mm":
                itemType = "multimedia";
                itemIndex = "hdnMMIndex";
                break;
        }
		var parent = prx.getElementsByTagName("prx");
		var items = prx.getElementsByTagNameNS("", itemType, parent, 0);
		
		var itemList = document.getElementById("itemList");
		
		itemList.innerHTML = ''; 			

        if(items.childNodes.length > 0)
        {
            var daList = '<table width="95%" border="0" align="center" cellpadding="5" cellspacing="0" class="heading" style="border:solid 1px #CCCCCC">';
            var selected = '';
            var even = '';
            
            var loadFunc = "";
            var saveFunc = "";
            var editFunc = "";
            var href = "";
            var title = "";
            var item = "";
            
            
            for(index=0;index < items.childNodes.length;index++)
            {
                switch(document.getElementById("hdnTab").value)
                {
                    case "contact":
                        item = prx.getElementsByTagNameNS("", "contact", items, index);        
                        saveFunc = "ContactSave();";
                        loadFunc = "ContactLoad();";
                        editFunc = "ItemEdit();";
                        title = NodeValue("vCard","FN",item, 0);
                        href = "#";
                        break;     
                    case "links":
                        item = prx.getElementsByTagNameNS("link", "content", items, index);        
                        saveFunc = "LinksSave();";
                        loadFunc = "LinksLoad();";
                        editFunc = "ItemEdit();";
                        title = NodeValue("link","title",item, 0);
                        href = item.getAttribute("url");
                        break;                
                    case "mm":
                        item = prx.getElementsByTagNameNS("media", "content", items, index);        
                        saveFunc = "MMSave();";
                        loadFunc = "MMLoad();";
                        editFunc = "ItemEdit();";
                        title = NodeValue("media","title",item, 0);
                        href = item.getAttribute("url");
                        break;
                }
           
                if(index % 2 == 0)
                {
                    even = 'even';
                }
                else
                {
                    even = 'odd';
                }
                
                daList += '<tr class="' + even + '">';
                daList += '<td><span style="color:#3b5998">' + (index + 1) + '</span></td><td><a href="javascript:void(0)" onclick="gotoNext=' + index + ';' + saveFunc + loadFunc + editFunc + '"><img src="images/edit.gif" border="0" width="16" height="16" alt="Edit Item" /></a> <a href="javascript:void(0)" onclick="gotoNext=' + index + ';' + saveFunc + loadFunc + editFunc + '">Edit</a></td>';
                if(href != "#")
                {
                    target = 'target="_blank"';
                }
                else
                {
                    target = '';                
                }
                daList += '<td colspan="3"><a href="' + href + '" ' + target + ' >' +  title + '</a></td>';
                daList += '<td><a href="javascript:void(0)" onclick="gotoNext=' + index + ';' + saveFunc + loadFunc + 'Delete();' + loadFunc + '" title="Delete Item"><img src="images/delete_x_16.gif" border="0" height="16" width="16" alt="Delete Item" /></a></td>';
                daList += '<td><a href="javascript:void(0)" onclick="gotoNext=' + index + ';' + saveFunc + loadFunc + 'MoveThis(\'down\');' + saveFunc + loadFunc + '" title="Move this item\'s position up."><img src="images/upbutton.gif" border="0" width="21" height="21" /></a><a href="javascript:void(0)" onclick="gotoNext=' + index + ';' + saveFunc + loadFunc + 'MoveThis(\'up\');' + saveFunc + loadFunc + '" title="Move this item\'s position down."><img src="images/downbutton.gif" border="0" width="21" height="21" /></a></td>';            
                daList += '<td></td>';                        
                daList += '</tr>';
            }
            daList += '</table>';
            itemList.innerHTML = daList;
            if(document.getElementById("itemEdit").style.display == "none")
            {
                document.getElementById("btnShowAll").style.visibility = "hidden";             
                document.getElementById("btnShowAll2").style.visibility = "hidden";             
            }
            else
            {
                document.getElementById("btnShowAll").style.visibility = "visible";             
                document.getElementById("btnShowAll2").style.visibility = "visible";             
            }
        }
        else
        {
            if(document.getElementById("itemEdit").style.display == "none")
			{
			    ItemEdit();
			}
            document.getElementById("btnShowAll").style.visibility = "hidden";             
            document.getElementById("btnShowAll2").style.visibility = "hidden";             
        }
    }
	catch(e)
	{
		alert("Error in ItemListLoad():  " + e.message);
	}
    
}







function MoveThis(direction)
{
	try
	{
			var change = false;
			var parent = prx.getElementsByTagName("prx");	
			switch(document.getElementById("hdnTab").value)
			{
				case "contact":
					ContactSave();
					var contacts = prx.getElementsByTagNameNS("","contacts",parent,0);
					if(contacts.childNodes.length > 0)
					{
						var index = document.getElementById("hdnContactIndex").value;
						var moveIndex = index;
						if(direction == "up")
						{
							if(index < contacts.childNodes.length - 1)
							{
								
								index++;
								change = true;
							}
						}
						else
						{
							if(index > 0)
							{
								index--;
								change = true;								
							}
						}
						if(change)
						{
							var contact = prx.getElementsByTagNameNS("","contact",contacts,index);						
							var moveContact = prx.getElementsByTagNameNS("","contact",contacts,moveIndex);						
							contacts.replaceChild(contact.cloneNode(true), moveContact);
							document.getElementById("hdnContactIndex").value = index;
//                            var select = document.forms['Form1'].elements['cboGoTo'];							
//							select.selectedIndex = index;
							ContactSave();
						}
					}
					break;
				case "links":
					LinksSave();					
					var links = prx.getElementsByTagNameNS("","links",parent,0);
					if(links.childNodes.length > 0)
					{
						var index = document.getElementById("hdnLinkIndex").value;
						var moveIndex = index;
						if(direction == "up")
						{
							if(index < links.childNodes.length - 1)
							{
								
								index++;
								change = true;
							}
						}
						else
						{
							if(index > 0)
							{
								index--;
								change = true;								
							}
						}
						if(change)
						{
							var link = prx.getElementsByTagNameNS("link","content",links,index);						
							var moveLink = prx.getElementsByTagNameNS("link","content",links,moveIndex);						
							links.replaceChild(link.cloneNode(true), moveLink);
							document.getElementById("hdnLinkIndex").value = index;
//                            var select = document.forms['Form1'].elements['cboGoTo'];							
//							select.selectedIndex = index;
							LinksSave();
						}

					}
					break;
				case "mm":
					MMSave();							
					var items = prx.getElementsByTagNameNS("","multimedia",parent,0);
					if(items.childNodes.length > 0)
					{
						var index = document.getElementById("hdnMMIndex").value;
						var moveIndex = index;
						if(direction == "up")
						{
							if(index < items.childNodes.length - 1)
							{
								
								index++;
								change = true;
							}
						}
						else
						{
							if(index > 0)
							{
								index--;
								change = true;								
							}
						}
						if(change)
						{
							var item = prx.getElementsByTagNameNS("media","content",items,index);						
							var moveItem = prx.getElementsByTagNameNS("media","content",items,moveIndex);						
							items.replaceChild(item.cloneNode(true), moveItem);
							document.getElementById("hdnMMIndex").value = index;
//                            var select = document.forms['Form1'].elements['cboGoTo'];							
//							select.selectedIndex = index;
							MMSave();
						}

					}
					break;										
			}
		}
		catch(e)
		{
			alert(e.message);
		}
}

function GoToReset()
{

//    var select = document.forms['Form1'].elements['cboGoTo'];
//    if(select)
//    {
//	    select.options.length = 0;
//	    var option = new Option();
//	    option.value = 1;
//	    option.text = 1;
//	    select.options.add(option);
//	}

}

function XMLProcess()
{

	try
	{

       if(!prx.xmlDoc)
       {
			if(retries < 5)
			{
	   				setTimeout("XMLProcess()",1000);
			}
			else
			{
				alert("Error:  Could not retrieve the document.");
			}
			retries++;
				
			return;
	   }
	   
		document.getElementById("lblPRX").value = prx.xmlText;	   
	}
	catch(e)
	{
		alert("Error in XMLProcess():" + e.message);
	}
  }			
			

		
function NodeUpdate(prefix, name, parent, index, value) {

    var result = "";
    var node = null;

    if(prx.getElementsByTagNameNS(prefix, name, parent, index))
    {
       if(prx.getElementsByTagNameNS(prefix, name, parent, index).firstChild) {
           node = prx.getElementsByTagNameNS(prefix, name, parent, index).firstChild;
       }	
    }
    else
    {
		if(parent)
		{
			try
			{
				switch(document.getElementById("tabPage").value)
				{
					case "contact":
						node = prx.createNode(3, name,vCardNS);
						break;
					case "links":
						node = prx.createNode(3, name,linkNS);					
						break;
				}
				if(node)
				{
					//node.data = value;
					//parent.appendChild(node)
					//node = prx.getElementsByTagNameNS(prefix, name, parent, index).firstChild;
					//alert(node.data);
				}
			}
			catch(e)
			{
				alert(e.message);
			}
		}
    }
    
    if(node)
    {
		node.data = value;
	}

    return node;
}
		
function NodeValue(prefix, name, parent, index) {

	try
	{
		var result = "";

		var node = prx.getElementsByTagNameNS(prefix, name, parent, index);
		
		if(node[0])
		{
			node = node[0];
		}

		if(node)
		{
		    if(node.firstChild) {
			    result = node.firstChild.nodeValue;
		    }	
		}
	    
		if(!result)
		{
			result = "";
		}
    }
    catch(e)
    {
		
    }
    
    return result;
}

function New(type)
{

	try
	{
	        if(type == "file")
	        {
	            if($("hdnTab").value != "start")
	            {
	                LoadPage("start");
	                setTimeout("New('file')",1000);
	                return;
	            }
	        }    

	        if(document.getElementById("itemEdit"))
	        {
			    if(document.getElementById("itemEdit").style.display == "none")
			    {
			        ItemEdit();
			    }
			}

			var parent = prx.getElementsByTagName("prx");
			switch(type)
			{
				case "file":
				    if(document.getElementById("hdnContactIndex"))
                    {
                        document.getElementById("hdnContactIndex").value = 0;
                        document.getElementById("hdnLinkIndex").value = 0;
                        document.getElementById("hdnMMIndex").value = 0;
                    }
                    if(document.getElementById("prnameDisplay"))
                    {
					    if(document.getElementById("prnameDisplay").value.length == 0)
					    {
						    alert("Please enter a file name.");
					    }
					    else
					    {
						    if(confirm("Warning:  A BLANK release is about to be created with the following name:\n\n" + document.getElementById("prnameDisplay").value
							    +" \n\nYour current release data will be cleared.\n\nClick OK to create a new file or Cancel to continue working with your current release."))
						    {	 
							    document.getElementById("prname").value = document.getElementById("prnameDisplay").value;
							    prx = new PRX(); 
							    prx.loadXML(cleanPRX);
							    currentWebsvc = "NewFile";
							    Save();
						    }
					    }
					}
					break;
				case "contact":
 		            if(document.getElementById("fullname").value.length > 0)
                    {
					    ContactSave();
    					var contacts = prx.getElementsByTagNameNS("","contacts",parent,0);
	    				var count = contacts.childNodes.length;
					    document.getElementById("hdnContactIndex").value = count;
					    ContactLoad();
					}
					break;
				case "link":
				    if(document.getElementById("linktext").value.length > 0)
				    {
					    LinksSave();							
					    var links = prx.getElementsByTagNameNS("","links",parent,0);
					    var count = links.childNodes.length;
					    document.getElementById("hdnLinkIndex").value = count;
					    LinksLoad();
					}
					break;
				case "mm":
				    if(document.getElementById("mmtext").value.length > 0)
					{
					    MMSave();							
					    var mm = prx.getElementsByTagNameNS("","multimedia",parent,0);
					    var count = mm.childNodes.length;					
					    document.getElementById("hdnMMIndex").value = count;
					    MMLoad();
					}
					break;										
				
			}
		}
		catch(e)
		{
			alert("Error in New(): " + e.message);
		}
}

function Delete()
{
	try
	{
			var parent = prx.getElementsByTagName("prx");	
			switch(document.getElementById("hdnTab").value)
			{
				case "contact":
					ContactSave();
					var contacts = prx.getElementsByTagNameNS("","contacts",parent,0);
					if(contacts.childNodes.length > 0)
					{
						var index = document.getElementById("hdnContactIndex").value;
						var contact = prx.getElementsByTagNameNS("","contact",contacts,index);
						contacts.removeChild(contact);
						if(index > 0)
						{
							index--;
						}
						document.getElementById("hdnContactIndex").value = index;
					}
					ContactLoad();
					break;
				case "links":
					LinksSave();					
					var links = prx.getElementsByTagNameNS("","links",parent,0);
					if(links.childNodes.length > 0)
					{
						var index = document.getElementById("hdnLinkIndex").value;
						var link = prx.getElementsByTagNameNS("link","content",links,index);
						links.removeChild(link);
						if(index > 0)
						{
							index--;
						}
						document.getElementById("hdnLinkIndex").value = index;					
					}
					LinksLoad();
					break;
				case "mm":
					MMSave();							
					var items = prx.getElementsByTagNameNS("","multimedia",parent,0);
					if(items.childNodes.length > 0)
					{
						var index = document.getElementById("hdnMMIndex").value;
						var item = prx.getElementsByTagNameNS("media","content",items,index);
						items.removeChild(item);
						if(index > 0)
						{
							index--;
						}
						document.getElementById("hdnMMIndex").value = index;					
					}
					MMLoad();
					break;										
			}
		}
		catch(e)
		{
			alert(e.message);
		}
}
		
function Previous()
{
			switch(document.getElementById("hdnTab").value)
			{
				case "contact":
					ContactSave();
					if(document.getElementById("hdnContactIndex").value != "0")
					{
						document.getElementById("hdnContactIndex").value = parseInt(document.getElementById("hdnContactIndex").value) - 1;
					}
					else
					{
					    alert("You are viewing the first contact.");
					}					
					ContactLoad();
					break;
				case "links":
					LinksSave();							
					if(document.getElementById("hdnLinkIndex").value != "0")
					{
						document.getElementById("hdnLinkIndex").value = parseInt(document.getElementById("hdnLinkIndex").value) - 1;					
					}
					else
					{
					    alert("You are viewing the first link.");
					}						
					LinksLoad();
					break;
				case "mm":
					MMSave();							
					if(document.getElementById("hdnMMIndex").value != "0")
					{
						document.getElementById("hdnMMIndex").value = parseInt(document.getElementById("hdnMMIndex").value) - 1;					
					}
					else
					{
					    alert("You are viewing the first item.");
					}						
					MMLoad();
					break;										
				
			}
}
function Next()
{
	try
	{
			var parent = prx.getElementsByTagName("prx");

			switch(document.getElementById("hdnTab").value)
			{
				case "contact":
					ContactSave();							
				    //Contacts
				    var contacts = prx.getElementsByTagNameNS("", "contacts", parent, 0);
					var count = contacts.childNodes.length;
					if((count - 1) > parseInt(document.getElementById("hdnContactIndex").value))
					{ 					
						document.getElementById("hdnContactIndex").value = parseInt(document.getElementById("hdnContactIndex").value) + 1;
					}
					else
					{
					    alert("No more contacts to view.");
					}
					ContactLoad();
					break;
				case "links":
					LinksSave();							
				    var links = prx.getElementsByTagNameNS("", "links", parent, 0);					
					count = links.childNodes.length;			
					if((count - 1) > document.getElementById("hdnLinkIndex").value)
					{		
						document.getElementById("hdnLinkIndex").value = parseInt(document.getElementById("hdnLinkIndex").value) + 1;					
					}
					else
					{
					    alert("No more links to view.");
					}					
					LinksLoad();
					break;
				case "mm":
					MMSave();							
					var items = prx.getElementsByTagNameNS("","multimedia",parent,0);
					count = items.childNodes.length;				
					if((count - 1) > document.getElementById("hdnMMIndex").value)
					{					
						document.getElementById("hdnMMIndex").value = parseInt(document.getElementById("hdnMMIndex").value) + 1;					
					}
					else
					{
					    alert("No more items to view.");
					}					
					MMLoad();
					break;					
				
			}
		}
		catch(e)
		{
			alert("Error during next: " + e.message);
		}
}

function moveIFrame(parms) 
{

	parmArray = parms.split("\t");
	var frameId = parmArray[0];
	var x = parmArray[1];
	var y = parmArray[2];
	var w = parmArray[3];
	var h = parmArray[4];
	
	x = x.replace(RegExp(/px/),"");
	y = y.replace(RegExp(/px/),"");	

	try
	{
		if(frameId == "frIFrame" && frIFrameHidden)
		{
			return;
		}

	    var frameRef=document.getElementById(frameId);
	    
	    frameRef.style.left=x + "px";
	    frameRef.style.top=y + "px";
	    frameRef.style.width=w;
	    frameRef.style.height=h + "px";    
	    frameRef.width="90%";
	    frameRef.height=h + "px";
    }
    catch(e)
    {
		alert("Error in moveIFrame():  " + e.message);
    }

}



function OpenViewer(type)
{
	currentWebsvc = "OpenViewer";
	currentViewerType = type;	
	if(currentViewerType == "DOC")
	{
		SaveAs()
	}	
	else
	{
		Save();
	}
}

function SaveAs()
{
	currentWebsvc = "SaveAs";
	Save();
	return document.getElementById("hdnMsg").innerHTML;
}


function SaveAsReturn()
{
	
	var url = document.getElementById("viewerAddress").value + "&download=true";
	var html = url + "&xform=" + document.getElementById("xform").options[document.getElementById("xform").selectedIndex].value;	
	var prx = url;
	var msg = "";
	if(currentViewerType == "DOC")
	{
		html += "&doc=true";
		msg = 'Click on the link below to open this release in MS Word.'
				+'<br><br><ul><a href=' + html + ' target=\'_blank\'>Export to MS Word</a></ul>'
				+'<br><br><br>';
				//<input type='button' class='btnStyle' value='Close' onclick='PopOverHide()' onmouseover='goLite(this)' onmouseout='goDim(this)'>";	
	    PopOverShow(msg,200,200,400,175);
	}
	else
	{
		msg = 'You are about to save a file to your machine.<br><br>Please select a file type by clicking on one of the links below.<ul>'
				+'<li><a href=' + prx + ' target=\'_blank\'>PRX File</a>'
				+'<li><a href=' + html + ' target=\'_blank\'>HTML File</a></ul><br><br>'
				+ prx_what
				+'<br><br><br>';
				//<input type='button' class='btnStyle' value='Close' onclick='PopOverHide()' onmouseover='goLite(this)' onmouseout='goDim(this)'>";
		//PopOverShow(msg,200,200,400,300);				
	    PopOverShow(msg,200,200,400,300);	
	}
									
	currentViewerType = "";	

}

function OpenViewerReturn()
{
	document.getElementById("btnClose").style.display = "block";
	document.getElementById("btnWord").style.display = "block";	
	savedPage = $("hdnTab").value;
	LoadPage("finish");
	setTimeout('OpenViewerReturnDelay()',700);
}

function OpenViewerReturnDelay()
{
	
	var url = document.getElementById("viewerAddress").value;
	
	var x = document.getElementById("divMain").style.left.replace(RegExp(/px/),"");
	var y = document.getElementById("divMain").style.top.replace(RegExp(/px/),"");        
	x = parseInt(x) + 50;
	y = parseInt(y) + 150;	
	
	
	if(currentViewerType.indexOf("HTML") == 0)
	{
		url += "&xform=" + document.getElementById("xform").options[document.getElementById("xform").selectedIndex].value;
	}
	else
	{
		if(currentViewerType.indexOf("WIRE") == 0)
		{
			url += "&xform=xslt/trad.xslt";
		}		
		else
		{
			url += "&xform=false";
		}
	}

	frIFrameHidden = false;		
	moveIFrame("frIFrame" +  "\t" + x + "\t" + y + "\t750\t2000");	

	ViewerShow(url);
}

function Open()
{
		var ret = false;
		var request = 0;
		action = "Open";
		action_uri = WEBSVC_URI + action;	

		currentWebsvc = "Open";
		
		try
		{
			prname = document.getElementById("prname");
			if(prname.value.length == 0)
			{
				alert("Please enter a file name on the 'Start' page.");
				return false;
			}
			if(prname.value.toLowerCase().indexOf(".xml") < 0)
			{
				prname.value += ".xml";
			}

			var userid = document.getElementById("userid").value;
								
			soapBody = SoapOpen(userid, prname.value, "<same domain>");
			envelope = SoapRequestBuild(soapBody);	
			//Post the Soap message.
			request = "Open";
			websvc_url = WEBSVC_URL;
			RequestSend(request, websvc_url, action, action_uri, envelope);									
					

			ret = true;
		}
		catch(e)
		{
			alert("Error during open:  " + e.message);
		}
		
		return ret;

}

function Save()
{
		var ret = false;
		var request = 0;
		var template = document.getElementById("xform").options[document.getElementById("xform").selectedIndex].value;
		action = "SaveDocXform";
		action_uri = WEBSVC_URI + action;	
		
		LoadPage(document.getElementById("hdnTab").value);				
		
		switch(currentWebsvc)
		{
			case "OpenViewer":
				break;
			case "SaveAs":
				break;				
			case "NewFile":
				break;
			default:
				currentWebsvc = "Save";
				break;
		}

	
		try
		{
			prname = document.getElementById("prname");
			if(prname.value.length == 0)
			{
				alert("Please enter a file name on the 'Start' page.");
				return false;
			}
			if(prname.value.toLowerCase().indexOf(".xml") < 0)
			{
				prname.value += ".xml";
			}
			if(prname.value == "demo.xml")
			{
				prname.value = "smpr_sample.xml";
			}			

			var userid = document.getElementById("userid").value;
			
			soapBody = SoapSave(userid, prname.value, prx.xml(),"<same domain>",true, template);
			envelope = SoapRequestBuild(soapBody);	
			//Post the Soap message.
			request = "SaveDoc";
			websvc_url = WEBSVC_URL;
			RequestSend(request, websvc_url, action, action_uri, envelope);									
					

			ret = true;
		}
		catch(e)
		{
			alert("Error during save:  " + e.message);
		}
		
		
		return ret;

}

function NewswireSend()
{
		var ret = false;
		var request = 0;
		action = "NewswirePublish";
		action_uri = WEBSVC_URI + action;
		var pub_list = "";
		var parms = "";	

   		if(!confirm("Are you ready to publish your release?"))
   		{
   			return;
   		}

		try
		{
	   	    document.getElementById("prxProcessing").style.display = "block";
            setTimeout("document.getElementById('prxProcessing').style.display = 'none'",5000);
//			var prn_name = document.getElementById("prn_name").value;
//			var prn_org = document.getElementById("prn_org").value;			
//			var prn_email = document.getElementById("prn_email").value;			
//			var prn_phone = document.getElementById("prn_phone").value;			
//			var prn_member = document.getElementById("prn_member").checked;															
//			var prn_acct = document.getElementById("prn_acct").value;	
//			var prn_nonus = document.getElementById("prn_nonus").checked;															
			var ret = true;
//			if(prn_name.length == 0)
//			{
//				alert("Please enter your name in the PR Newswire form.");
//				ret = false;
//			}
//			if(prn_org.length == 0 && ret)
//			{
//				alert("Please enter the name of your organization in the PR Newswire form.");
//				ret = false;				
//			}			
//			if(prn_member == true && prn_acct.length == 0 && ret)
//			{
//				alert("Please enter your PR Newswire Account Number in the PR Newswire form.");
//				ret = false;				
//			}			
//			if(prn_phone.length == 0 && ret)
//			{
//				alert("Please enter your phone number in the PR Newswire form.");
//				ret = false;				
//			}									
//			if((prn_email.length == 0 || prn_email.indexOf("@") < 0) && ret)
//			{
//				alert("Please enter your email address in the PR Newswire form.");
//				ret = false;				
//			}												
//			if(prn_nonus == true)
//			{
//				prn_nonus = "true";
//			}
            if(document.getElementById('pub_options'))
            {
                pub_list = document.getElementById('pub_options').value.split("\t");
                for(ctr=0;ctr<pub_list.length;ctr++)
                {
                    if(document.getElementById(pub_list[ctr]))
                    {
                        if(document.getElementById(pub_list[ctr]).checked)
                        {
                            if(parms.length > 0)
                            {
                                parms += "\t";
                            }
                            parms += pub_list[ctr];
                        }
                    }
                }
            }


			if(ret)
			{
				//Save();
				currentWebsvc = "NewswirePublish";				
				userid = document.getElementById("userid").value;
				prname = document.getElementById("prname").value;
				template = document.getElementById("xform").options[document.getElementById("xform").selectedIndex].value;
				prn_prxreleases = "true";
				soapBody = SoapNewswirePublish(userid, prname,template,parms,prn_prxreleases,"<same domain>");
				envelope = SoapRequestBuild(soapBody);	
				//Post the Soap message.
				request = "NewswirePublish";
				websvc_url = WEBSVC_URL;
				RequestSend(request, websvc_url, action, action_uri, envelope);									
			}		
		
			ret = true;
		}
		catch(e)
		{
			alert("Error during publish:  " + e.message);
		}
   	    
	
		return ret;

}

function ExtDefaults()
{
try
{
    var xmlrpc = getQueryVariable("xmlrpc");
    var wp_user = getQueryVariable("wp_user");
    var wp_password = getQueryVariable("wp_password");    
    if(xmlrpc)
    {
        document.getElementById("xmlrpc_url").value = unescape(xmlrpc);
    }

    if(wp_user)
    {
        document.getElementById("blog_username").value = unescape(wp_user);
    }
    
    if(wp_user)
    {
        document.getElementById("blog_password").value = unescape(wp_password);
    }    
}
catch(e)
{
}
}

function getQueryVariable(variable) {
try
{
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0;i<vars.length;i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) {
            return pair[1];
        }
     } 
}
catch(e)
{
}
}


function BlogPost()
{
		var ret = false;
		var request = 0;
		action = "BlogPost";
		action_uri = WEBSVC_URI + action;	
	
		try
		{
			currentWebsvc = action;		
		
			var xmlrpc_url = document.getElementById("xmlrpc_url").value;
			var username = document.getElementById("blog_username").value;			
			var password = document.getElementById("blog_password").value;						
			var parent = prx.getElementsByTagName("prx");
			var newslines = prx.getElementsByTagNameNS("","newslines",parent,0);		
			var title = NodeValue("","headline",newslines,0);			
			var pr_url = document.getElementById("viewerAddress").value;
			if(pr_url.length == "")
			{
				alert("Please preview this release first.");
				return;
			}			
			pr_url += "&xform=" + document.getElementById("xform").options[document.getElementById("xform").selectedIndex].value;
			
			soapBody = SoapBlogPost(xmlrpc_url, username, password, title, pr_url,"<same domain>");
			envelope = SoapRequestBuild(soapBody);	
			//Post the Soap message.
			request = "BlogPost";
			websvc_url = WEBSVC_URL;
			RequestSend(request, websvc_url, action, action_uri, envelope);									
					

			ret = true;
		}
		catch(e)
		{
			alert("Error during BlogPost():  " + e.message);
		}
		
		return ret;

}

function EmailRelease()
{
		var ret = false;
		var request = 0;
		action = "EmailRelease";
		action_uri = WEBSVC_URI + action;	
	
		try
		{
		
			currentWebsvc = action;
		
			var email = "self:" + document.getElementById("userid").value;
			var subject = "[PRX Builder] Email Release";
			var body = "";
			var pr_url = document.getElementById("viewerAddress").value;
			if(pr_url.length == "")
			{
				alert("Please preview this release first.");
				return;
			}
			pr_url += "&xform=" + document.getElementById("xform").options[document.getElementById("xform").selectedIndex].value;
			var template = document.getElementById("xform").options[document.getElementById("xform").selectedIndex].value;
			var parms = null;
			
			soapBody = SoapEmailRelease(email, subject, body, pr_url, template, parms);
			envelope = SoapRequestBuild(soapBody);	
			//Post the Soap message.
			request = "EmailRelease";
			websvc_url = WEBSVC_URL;
			RequestSend(request, websvc_url, action, action_uri, envelope);									

			ret = true;
		}
		catch(e)
		{
			alert("Error during EmailRelease():  " + e.message);
		}
		
		return ret;

}

function FileList()
{
		var obj = new Image();
		obj.value = "fileselect";
		LoadPage(obj);
		setTimeout('FileListDelay()',700);
}

function FileListDelay()
{
		var ret = false;
		var request = 0;


		action = "FileListGet";
		action_uri = WEBSVC_URI + action;	
		currentWebsvc = "FileListGet";
			
		try
		{
			userid = document.getElementById("userid").value;
			soapBody = SoapFileListGet(userid, "<same domain>");
			envelope = SoapRequestBuild(soapBody);	
			//Post the Soap message.
			request = "FileListGet";
			websvc_url = WEBSVC_URL;
			RequestSend(request, websvc_url, action, action_uri, envelope);									
					

			ret = true;
		}
		catch(e)
		{
			alert("Error during file listing:  " + e.message);
		}
		
		return ret;

}

function TechnoratiTagAdd(tag)
{
	if(document.getElementById("technorati_tags").value.length == 0)
	{
		document.getElementById("technorati_tags").value = tag;
	}
	else
	{
		document.getElementById("technorati_tags").value += ", " + tag;
	}

}

function TechnoratiCloud()
{
		var ret = false;
		var request = 0;
		var fromHeadline = false;
		
		action = "TechnoratiCloud";
		action_uri = WEBSVC_URI + action;	
		currentWebsvc = "TechnoratiCloud";
		
		document.getElementById("divTechnoratiTags").innerHTML = "Processing...";
			
		try
		{
			var searchString = document.getElementById("technorati_search").value;
			
			if(searchString == "" || searchString.indexOf("[Enter search text") == 0)
			{
				fromHeadline = true;
				var headline = prx.getElementsByTagName("headline").firstChild.nodeValue;			
				if(headline != null)
				{
					if(headline.length > 0)
					{
						searchString = headline;
					}
				}
			}			
	
			searchString = searchString.replace(new RegExp(/\"/g),"%22");
			searchString = searchString.replace(new RegExp(/\'/g),"%27");
			
			if(fromHeadline)
			{
				searchString = searchString.replace(new RegExp(/\u0020a\u0020+|^A\u0020/g)," ");						
				searchString = searchString.replace(new RegExp(/\u0020the\u0020+|^The\u0020/g)," ");									
				searchString = searchString.replace(new RegExp(/\u0020an\u0020+|^An\u0020/g)," ");									
				searchString = searchString.replace(new RegExp(/\u0020is\u0020+|^Is\u0020/g)," ");												
				searchString = searchString.replace(new RegExp(/\u0020this\u0020/g)," ");												
				searchString = searchString.replace(new RegExp(/\u0020that\u0020/g)," ");												
				searchString = searchString.replace(new RegExp(/\u0020these\u0020/g)," ");												
				searchString = searchString.replace(new RegExp(/\u0020those\u0020/g)," ");												
				searchString = searchString.replace(new RegExp(/\u0020which\u0020/g)," ");																											
				searchString = searchString.replace(new RegExp(/\u0020my\u0020/g)," ");
				searchString = searchString.replace(new RegExp(/\u0020our\u0020/g)," ");
				searchString = searchString.replace(new RegExp(/\u0020your\u0020/g)," ");
				searchString = searchString.replace(new RegExp(/\u0020her\u0020/g)," ");			
				searchString = searchString.replace(new RegExp(/\u0020his\u0020/g)," ");
				searchString = searchString.replace(new RegExp(/\u0020its\u0020/g)," ");
				searchString = searchString.replace(new RegExp(/\u0020their\u0020/g)," ");
				searchString = searchString.replace(new RegExp(/\u0020all\u0020/g)," ");
				searchString = searchString.replace(new RegExp(/\u0020few\u0020/g)," ");
				searchString = searchString.replace(new RegExp(/\u0020many\u0020/g)," ");
				searchString = searchString.replace(new RegExp(/\u0020several\u0020/g)," ");									
				searchString = searchString.replace(new RegExp(/\u0020some\u0020/g)," ");
				searchString = searchString.replace(new RegExp(/\u0020every\u0020/g)," ");
				searchString = searchString.replace(new RegExp(/\u0020each\u0020/g)," ");						
				searchString = searchString.replace(new RegExp(/\u0020any\u0020/g)," ");
				searchString = searchString.replace(new RegExp(/^\u0020/g),"");												
				searchString = searchString.replace(new RegExp(/\u0020/g),"+or+");									
			}									
			
			
			document.getElementById("technorati_search").value = searchString;			
			
			soapBody = SoapTCloud(searchString, "<same domain>");
			envelope = SoapRequestBuild(soapBody);	
			//Post the Soap message.
			request = "TechnoratiCloud";
			websvc_url = WEBSVC_URL;
			RequestSend(request, websvc_url, action, action_uri, envelope);									
					

			ret = true;
		}
		catch(e)
		{
			alert("Error during TechnoratiCloud():  " + e.message);
		}
		
		return ret;

}

function hideIFrame(){

	try
	{
		document.getElementById("frIFrame").style.left="-999999px";
		frIFrameHidden = true;
	}
	catch(e)
	{
	}
}


function ViewerClose()
{
	try
	{
		document.getElementById("frIFrame").style.left = "-999999px";
	    LoadPage($("hdnTab"));
	}
	catch(e)
	{
	}
}

function EditorSet(value)
{
	try
	{
        if(value)
        {
//            var fck = FCKeditorAPI.GetInstance(editorElem);
//	        if(fck)
//	        {
//	            fck.SetHTML(value);
//	        }
	    }
	}
	catch(e)
	{
		//alert("Error in EditorSet():  " + e.message);
	}

}

function FCKeditor_OnComplete( editorInstance ) {
        wait = false;
        if($("editor"))
        {
            EditorSet($("editor").value);
        }
}

function EditorRemove()
{

	try
	{
        fckeditor = null;
	}
	catch(e)
	{
	}


}

function EditorLoad(type)
{
    try
    {
        editorElem = type;
        if($(editorElem))
        {
            wait = true;
            EditorRemove();
//            fckeditor = new FCKeditor(editorElem, '525','500');
//            var div = $(editorElem);
//            fckeditor.BasePath = "/fckeditor/";
//            div.innerHTML = fckeditor.CreateHtml();
            //fckeditor.ReplaceTextarea();
            if(BrowserDetect.browser == "Safari")
            {
                $(editor).setAttribute("cols","75");
            }
            xinha_editors = ["editor"];
            xinha_plugins = 
              [
               'CharacterMap',
               'ContextMenu',
               'ListType',
               'Stylist',
               'SuperClean',
               'Linker',
               'TableOperations'
              ];

            xinha_editors = Xinha.makeEditors(xinha_editors, xinha_config, xinha_plugins);
            xinha_config = new Xinha.Config();
            xinha_config.pageStyleSheets = [ _editor_url + "examples/full_example.css" ];

            Xinha.startEditors(xinha_editors);

        }
    }
    catch(e)
    {
        alert("Error in EditorLoad: " + e.message);
    }
}


function EditorGet()
{
    var fck;
    var html = " ";

	try
	{
        //fck = FCKeditorAPI.GetInstance(editorElem);

//	    if(fck)
//	    {
//	        html = fck.GetHTML(true);
//	    }
	    if(html.length == 0 && $("editor").value.length != 0)
	    {
	        if(!confirm("Please confirm:  Remove all text from the editor and leave it blank?\n\nClick OK to remove your text.  Click Cancel to keep your text."))
	        {
	            throw new Error("Editor error.  Please try again.");
	        }
	    }
	    if(html == null || html == "undefined")
	    {
	        throw new Error("Error in editor.");
	    }
	}
	catch(e)
	{
		throw new Error("Error in EditorGet():  " + e.message);
	}
	html = xinha_editors.editor.getEditorContent();

	return html
}

function thisSWF(name) 
{
	try
	{
		if (navigator.appName.indexOf("Microsoft") != -1) 
		{
			return window[name];
		} 
		else
		{
			return document[name];
		}
    }
    catch(e)
    {
    }
}


function EditorShow(html)
{
	try
	{
        var fck;
        
//        if (typeof(FCKeditorAPI)!=='undefined')
//        {
//            fck = FCKeditorAPI.GetInstance(editorElem);
//		}	
		
//		if(fck)
//		{
//			fck.SetHTML(html,true);
//		}
//		else
//		{
			document.getElementById("editor").value = html;
//		}
//	
	}
	catch(e)
	{
		alert("Error in EditorShow():  " + e.message);
	}

}

function EditorFocusOut()
{
	try
	{
		if(isIE == true)
		{
			document.getElementById("pos").focus();
		}
		document.getElementById("socialmediapressrelease").focus();
	}
	catch(e)
	{
	}
}


function EditorHide()
{
	try
	{
//        var fck;

//        if (typeof(FCKeditorAPI)!=='undefined')
//        {
//            fck = FCKeditorAPI.GetInstance(editorElem);
//        }

//	    if(fck)
//	    {
//	        fck.EditorDocument = null;
//	    }
		//document.getElementById("editorDiv").style.left = "-99999px";
		//document.getElementById("editorFrame").style.left = "-99999px";
		
	}
	catch(e)
	{
	}
}

function ViewerHide()
{
	try
	{
        document.getElementById("spnView").style.visibility = "hidden";
		document.getElementById("frIFrame").style.left = "-99999px";
	}
	catch(e)
	{
	}
}

function ViewerShow(url) 
{
	try
	{
	    document.getElementById("spnView").style.visibility = "visible";
		document.getElementById("frIFrame").src = url;
		return true;
	}
	catch(e)
	{
		return false;
	}
}

function LoadInit()
{
	//try
	//{
		document.getElementById("start").style.left = "-99999px";
		document.getElementById("contact").style.left = "-99999px";
		document.getElementById("release").style.left = "-99999px";
		document.getElementById("categories").style.left = "-99999px";
		document.getElementById("links").style.left = "-99999px";
		document.getElementById("delicious_window").style.left = "-99999px";		
		document.getElementById("delicious_window").src = "delicious.aspx?ver=" + prxver;
		document.getElementById("twitter_window").style.left = "-99999px";		
		document.getElementById("twitter_window").src = "twitter.aspx?ver=" + prxver;				
        document.getElementById("tracer_window").style.left = "-99999px";			
		document.getElementById("tracer_window").src = "tracer_rpt.aspx?ver=" + prxver;				        			
		document.getElementById("flickr_window").style.left = "-99999px";		
		document.getElementById("flickr_window").src = "flickr.aspx?ver=" + prxver;					
		document.getElementById("youtube_window").style.left = "-99999px";		
		document.getElementById("youtube_window").src = "youtube.aspx?ver=" + prxver;					
		document.getElementById("fileimport_window").style.left = "-99999px";		
		document.getElementById("fileimport_window").src = "fileimport.aspx?ver=" + prxver;		
		document.getElementById("prxuploader_window").style.left = "-99999px";		
		document.getElementById("prxuploader_window").src = "prxuploader.aspx?ver=" + prxver;					
		document.getElementById("mm").style.left = "-99999px";
		document.getElementById("quotes").style.left = "-99999px";
		document.getElementById("boilerplate").style.left = "-99999px";
		document.getElementById("finish").style.left = "-99999px";
		document.getElementById("options").style.left = "-99999px";
		document.getElementById("fileselect").style.left = "-99999px";		
		//document.getElementById("recordNav").style.display = "none";
		document.getElementById("divFinish").style.display = "none";
		document.getElementById("prn_publish").style.left = "-99999px";		
		document.getElementById("prx_releases").style.left = "-99999px";				
		document.getElementById("distribute").style.left = "-99999px";				
		document.getElementById("ext").style.left = "-99999px";						
		setTimeout("RemoveLoading()",1000);										
	//}
	//catch(e)
	//{
		//alert("An error occurred during initialization:  " + e.message);	
	//}
}
function RemoveLoading()
{
		try
		{
			//fck = FCKeditorAPI.GetInstance("editorBox");	
		}
		catch(e)
		{
			//continue with textarea.
		}
		//try
		//{
			PRXLoad();				
			LoadPage('start');	
			document.getElementById("divLoading").style.height = "1px";				
			document.getElementById("divLoading").style.width = "1px";								
			document.getElementById("divLoading").width = "1px";								
			document.getElementById("divLoading").height = "1px";												
			document.getElementById("ifmLoading").style.width = "1px";								
			document.getElementById("ifmLoading").style.height = "1px";			
			document.getElementById('divLoading').style.left = '-99999px';		
		//}
		//catch(e)
		//{
			//alert("An error occurred during initialization:  " + e.message);
		//}
}

/*****************************************
**	RequestSend(url, action, action_uri, envelope)
**	Post the SOAP request.
*****************************************/
function RequestSend(request, url, action, action_uri, envelope)
{
	var oHTTP;
	ajaxReturn = "";
	
    try
    {
	    // code for Mozilla, etc.
		if (window.XMLHttpRequest)
		{
			oHTTP = new XMLHttpRequest();
		}
		// code for IE
		else if (window.ActiveXObject)
		{
			oHTTP=new ActiveXObject("Microsoft.XMLHTTP");
		}

		//Begin the connection and generate the Soap Header.
		oHTTP.open("POST", "builder.asmx", true);
		oHTTP.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
		oHTTP.setRequestHeader("SOAPAction", action_uri);  
		oHTTP.setRequestHeader("XmlHttpSvc_Url",url);		

		oHTTP.onreadystatechange = 
			function(){if(oHTTP.readyState == 4){oHTTPChange(oHTTP, request, action)}};
			
		
		//Send the Soap Request.
	    oHTTP.send(envelope);
	
	}
    catch (e)
    {
	    alert(e);
    }	  
	    
}

function oHTTPChange(oHTTP, request, action)
{
    var tag;
    var nodes;
    var node;

	try
	{	  
		if (oHTTP.responseXML)
		{
			responseXML = oHTTP.responseXML;
		}
		if(oHTTP.responseText)
		{
			responseText = oHTTP.responseText;
		}

		//Success.  
		if (oHTTP.status == 200)
		{
			tag = action + "Result";
			//Firefox -- Go beyond 4096!
			if(!window.ActiveXObject)
			{
				responseXML.normalize();
			}
			nodes = responseXML.getElementsByTagName(tag);		
			
			if (nodes)
			{
				node = nodes[0];
				if(node)
				{
				    if(!node.firstChild)
				    {
				        alert("An error prevented this process from completing.\rPlease try again or report this issue to support.");
				    }
					if(node.firstChild)
					{
						ajaxReturn = node.firstChild.nodeValue;
						switch(currentWebsvc)
						{
							case "Login":
								currentWebsvc = "";							
								if(ajaxReturn == "Success")
								{
									Login(document.getElementById("login_userid").value + "\tajax")								
								}
								else
								{
									alert(ajaxReturn);
								}
								break;
							case "NewFile":
							case "Save":
								document.getElementById("viewerAddress").value = ajaxReturn;
								if(document.getElementById("prnameDisplay"))
								{
									document.getElementById("prnameDisplay").value = document.getElementById("prname").value;
								}
								alert("File saved successfully.");
								if(currentWebsvc == "NewFile")
								{
									LoadPage('contact');								
								}
								currentWebsvc = "";																						
								break;
							case "Open":
								currentWebsvc = "";
								prx = new PRX();														
								prx.loadXML(ajaxReturn);
								if(document.getElementById("hdnTab").value == "start")
								{
								    alert("File opened successfully.");
								}
    							LoadPage('contact');								
								break;								
							case "OpenViewer":
								currentWebsvc = "";														
								document.getElementById("viewerAddress").value = ajaxReturn;
								if(ajaxReturn.length == 0)
								{
								    alert("The document could not be saved and previewed.  Please try again or contact support.");
								}							
								OpenViewerReturn();
								break;
							case "SaveAs":
								currentWebsvc = "";														
								document.getElementById("viewerAddress").value = ajaxReturn;							
								SaveAsReturn();
								break;								
							case "FileListGet":
								currentWebsvc = "";														
								var nodes = XMLFromText(ajaxReturn,true);
								nodes = nodes.getElementsByTagName("file");
								var relList = document.createElement("ul");
								relList.id = "relList";
								
								for(var ctr=0;ctr < nodes.length;ctr++)
								{
									var node = nodes[ctr];
									var opt = new Option();
									opt.text = node.firstChild.nodeValue + " - " + node.getAttribute("fileDate");
									opt.value = node.firstChild.nodeValue;
									if(opt.value.indexOf(".png") < 0 && opt.value.indexOf("demo.xml") < 0)
									{
									    document.getElementById("fileListBox").options.add(opt);
									    var li = document.createElement("li");
									    
									    li.innerHTML = '<p><img src="thumb.aspx?id=' + userid + '&name=' + node.firstChild.nodeValue + '&cache=' + datetimestamp() + '" width="200" height="140" align="left" /></p>';
									    li.innerHTML += '<p class="caption"><a href="javascript:void(0)" onclick=\'FileSelected("' + node.firstChild.nodeValue + '")\'>' + node.firstChild.nodeValue + '</a><br/>' + node.getAttribute("fileDate") + '</p>';									    
									    relList.appendChild(li);
									}
									
								}
								
                                 document.getElementById("relThumbs").appendChild(relList);	
                                
								//fileList.innerHTML = node
								break;
							case "TechnoratiCloud":
								document.getElementById("divTechnoratiTags").innerHTML = ajaxReturn;
								break;
							case "NewswirePublish":
								currentWebsvc = "";														
								result = ajaxReturn;
								ret = false;
								if(result != null)
								{
									if(result == "true")
									{
										FileOpen();								
										alert("Your release has been published.\nYou will receive additional instructions via email.");
										ret = true;

									}
								}
								if(!ret)
								{
									alert("Error during publish.\n\nPlease try again or contact PRX Builder Support.");	
								}
								document.getElementById("prxProcessing").style.display = "none";
								break;
							case "BlogPost":
								if(ajaxReturn == "true")
								{
									alert("Blog posting complete.");
								}
								else
								{
									alert("An error occurred during the blog posting.\n\n" + ajaxReturn);								
								}
								break;
							case "EmailRelease":
								if(ajaxReturn == "true")
								{
									alert("Email sent.");
								}
								else
								{
									alert("An error occurred while attempting to send the email.");
								}
								break;								
						}
					}
				}
				else
				{
					throw "An error occurred during the send process.";
				}				
			}			
			else
			{
				throw "An error occurred during the send process.";
			}
		}
		else
		{
			//Process the error.
			if (responseXML != null)
			{
				//Set the error message returned by the web service.
				tag = "faultstring";
				nodes = responseXML.getElementsByTagName(tag);
				if (nodes)
				{
					node = nodes[0];
					if(node)
					{
						if(node.firstChild)
						{
							message = node.firstChild.nodeValue;
						}
					}
					
				}
				else
				{
					//Standard web service error not found.
					//Reply with the full text of the status and statusText.
					//Error text could not be found.
					message="Status:  " + oHTTP.status + " - " + oHTTP.statusText;						  
				}
			}
			else
			{
				if (responseText.length > 0)
				{
					message = responseText;
				}
				else
				{			
					message="Status:  " + oHTTP.status + " - " + oHTTP.statusText;						  
				}
			}
			throw message;                                    
		}

	}
	catch (e)
	{
	    alert(e);
	}
}


/*****************************************
**	SoapRequestBuild(soapBody)
**	Create the SOAP envelope.
*****************************************/
function SoapRequestBuild(soapBody)
{
    //Soap Request For Web Service.
    envelope = "<?xml version='1.0' encoding='utf-8'?>";
    envelope += "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>";
    envelope += "<soap:Body>";
    envelope += soapBody;
    envelope += "</soap:Body>";
    envelope += "</soap:Envelope>";

    return envelope;
}

/*****************************************
**	SoapBody(headerOnly, uri_path)
**	Create the Soap Body.
*****************************************/
function SoapOpen(userid, name, code)
{

	soapBody = "<Open xmlns='http://whitleymedia.com/webservices/'>";
	soapBody += "<userid><![CDATA[" + userid + "]]></userid>";	
	soapBody += "<name><![CDATA[" + name + "]]></name>";
	soapBody += "<code><![CDATA[" + code + "]]></code>";	
	soapBody += "</Open>";	
	
    return soapBody;
}

/*****************************************
**	SoapBody(headerOnly, uri_path)
**	Create the Soap Body.
*****************************************/
function SoapSave(userid, name, xmlString, code, decode, template)
{

	soapBody = "<SaveDocXform xmlns='http://whitleymedia.com/webservices/'>";
	soapBody += "<userid><![CDATA[" + userid + "]]></userid>";	
	soapBody += "<name><![CDATA[" + name + "]]></name>";
	soapBody += "<xmlString><![CDATA[" + EncodeXml(xmlString) + "]]></xmlString>";				
	soapBody += "<code><![CDATA[" + code + "]]></code>";	
	soapBody += "<decodeXML><![CDATA[" + true + "]]></decodeXML>";	
    soapBody += "<template><![CDATA[" + template + "]]></template>";				
	soapBody += "</SaveDocXform>";	
	
	
	
    return soapBody;
}


/*****************************************
**	SoapBody(headerOnly, uri_path)
**	Create the Soap Body.
*****************************************/
function SoapLogin(userid, password, code)
{

	soapBody = "<Login xmlns='http://whitleymedia.com/webservices/'>";
	soapBody += "<username><![CDATA[" + userid + "]]></username>";	
	soapBody += "<password><![CDATA[" + password + "]]></password>";
	soapBody += "<code><![CDATA[" + code + "]]></code>";	
	soapBody += "</Login>";	
	
	
	
    return soapBody;
}

/*****************************************
**	SoapBody(headerOnly, uri_path)
**	Create the Soap Body.
*****************************************/
function SoapFileListGet(userid, code)
{

	soapBody = "<FileListGet xmlns='http://whitleymedia.com/webservices/'>";
	soapBody += "<userid><![CDATA[" + userid + "]]></userid>";	
	soapBody += "<code><![CDATA[" + code; 
	soapBody += "]]></code>";	
	soapBody += "</FileListGet>";	
	
	
	
    return soapBody;
}


/*****************************************
**	SoapBody(headerOnly, uri_path)
**	Create the Soap Body.
*****************************************/
function SoapTCloud(searchString, code)
{

	soapBody = "<TechnoratiCloud xmlns='http://whitleymedia.com/webservices/'>";
	soapBody += "<searchString><![CDATA[" + searchString + "]]></searchString>";	
	soapBody += "<code><![CDATA[" + code + "]]></code>";	
	soapBody += "</TechnoratiCloud>";	
	
	
	
    return soapBody;
}


/*****************************************
**	SoapBody(headerOnly, uri_path)
**	Create the Soap Body.
*****************************************/
function SoapNewswirePublish(userid, name, template, parms, sendToPRXReleases,code)
{

	soapBody = "<NewswirePublish xmlns='http://whitleymedia.com/webservices/'>";
	soapBody += "<userid><![CDATA[" + userid + "]]></userid>";	
	soapBody += "<name><![CDATA[" + name + "]]></name>";
	soapBody += "<template><![CDATA[" + template + "]]></template>";				
	soapBody += "<parms><![CDATA[" + parms + "]]></parms>";				
	soapBody += "<sendToPRXReleases><![CDATA[" + sendToPRXReleases + "]]></sendToPRXReleases>";				
	soapBody += "<code><![CDATA[" + code; 
	soapBody += "]]></code>";	
	soapBody += "</NewswirePublish>";	
	
	
	
    return soapBody;
}

/*****************************************
**	SoapBody(headerOnly, uri_path)
**	Create the Soap Body.
*****************************************/
function SoapBlogPost(xmlrpc_url, username, password, title, pr_url,code)
{

	soapBody = "<BlogPost xmlns='http://whitleymedia.com/webservices/'>";
	soapBody += "<xmlrpc_url><![CDATA[" + xmlrpc_url + "]]></xmlrpc_url>";	        
	soapBody += "<username><![CDATA[" + username + "]]></username>";	
	soapBody += "<password><![CDATA[" + password + "]]></password>";
	soapBody += "<title><![CDATA[" + title + "]]></title>";				
	soapBody += "<pr_url><![CDATA[" + pr_url + "]]></pr_url>";				
	soapBody += "<code><![CDATA[" + code + "]]></code>";	
	soapBody += "</BlogPost>";	
	
    return soapBody;
}

/*****************************************
**	SoapBody(headerOnly, uri_path)
**	Create the Soap Body.
*****************************************/
function SoapEmailRelease(email, subject, body, pr_url, template, parms, code)
{

	soapBody = "<EmailRelease xmlns='http://whitleymedia.com/webservices/'>";
	soapBody += "<email><![CDATA[" + email + "]]></email>";	
	soapBody += "<subject><![CDATA[" + subject + "]]></subject>";
	soapBody += "<body><![CDATA[" + body + "]]></body>";				
	soapBody += "<pr_url><![CDATA[" + pr_url + "]]></pr_url>";					
	soapBody += "<template><![CDATA[" + template + "]]></template>";				
	soapBody += "<parms><![CDATA[" + parms + "]]></parms>";				
	soapBody += "<code><![CDATA[" + code; 
	soapBody += "]]></code>";	
	soapBody += "</EmailRelease>";	

	
    return soapBody;
}


/*****************************************
**	EncodeXml(value)
**	Replace invalid Xml characters.
*****************************************/
function EncodeXml(inbound)
{
	var strRepl = "";
	strRepl = inbound;

	strRepl = strRepl.replace(new RegExp(/&/g), "&amp;");	
	strRepl = strRepl.replace(new RegExp(/<!\[CDATA\[/g), "<cdata>");	
	strRepl = strRepl.replace(new RegExp(/\]\]>/g), "</cdata>");
	strRepl = strRepl.replace(new RegExp(/</g), "&lt;");
	strRepl = strRepl.replace(new RegExp(/>/g), "&gt;");			
	strRepl = strRepl.replace(new RegExp(/'/g), "&apos;");
	strRepl = strRepl.replace(new RegExp(/\"/g), "&quot;");	

	
	return strRepl;
}

/*****************************************
**	AttribClean(value)
*****************************************/
function AttribClean(inbound)
{
	var strRepl = "";
	strRepl = inbound;

	strRepl = strRepl.replace(new RegExp(/&/g), "&amp;");	
	strRepl = strRepl.replace(new RegExp(/<!\[CDATA\[/g), "");	
	strRepl = strRepl.replace(new RegExp(/\]\]>/g), "");
	strRepl = strRepl.replace(new RegExp(/</g), "");
	strRepl = strRepl.replace(new RegExp(/>/g), "");			
	strRepl = strRepl.replace(new RegExp(/'/g), "&apos;");
	strRepl = strRepl.replace(new RegExp(/\"/g), "");	

	
	return strRepl;
}


/*****************************************
**	DecodeXml(strRepl)
**	Replace Xml characters that were previously encoded.
*****************************************/
function DecodeXml(inbound)
{
	var strRepl = "";
	strRepl = inbound;
	strRepl = strRepl.replace(new RegExp(/&lt;/g), "<");
	strRepl = strRepl.replace(new RegExp(/&gt;/g), ">");			
	strRepl = strRepl.replace(new RegExp(/&apos;/g), "'");
	strRepl = strRepl.replace(new RegExp(/&quot;/g), "\"");	
	strRepl = strRepl.replace(new RegExp(/<cdata>/g),"<![CDATA[");	
	strRepl = strRepl.replace(new RegExp(/<\/cdata>/g),"]]>");			
	strRepl = strRepl.replace(new RegExp(/&amp;/g), "&");		
	
	return strRepl;
}


function LoginAjax(userid,password)
{
		var ret = false;
		var request = 0;
		action = "Login";
		action_uri = WEBSVC_URI + action;	
		
		currentWebsvc = "Login";
		
		try
		{
			soapBody = SoapLogin(userid, password,"<same domain>");
			envelope = SoapRequestBuild(soapBody);	
			//Post the Soap message.
			request = "Login";
			websvc_url = SECURE_WEBSVC_URL;
			RequestSend(request, websvc_url, action, action_uri, envelope);	
					
			ret = true;
		}
		catch(e)
		{
			alert("Error during Login():  " + e.message);
		}

		return ret;
		

}

function goLite(obj)
{
   obj.style.color = "#6666AA";
   obj.style.backgroundColor = "#EEEEF4";
   obj.style.borderColor = "#9999DD";
}

function goDim(obj)
{
   obj.style.color = "#444444";
   obj.style.backgroundColor = "#EEEEEE";
   obj.style.borderColor = "#BBBBBB";
}

function PopOverShow(msg,x,y,width,height)
{
	var pOver = document.getElementById("divPopOver");
	
	pOver.innerHTML = msg;
	pOver.style.top = y + "px";
	pOver.style.left = x + "px";
	pOver.style.width = width + "px";
	pOver.style.height = height + "px";
	var a = document.createElement("a");
	a.innerHTML = "Close";
	a.setAttribute("href","javascript:void(0)");
    if(window.ActiveXObject)
    {
        a.setAttribute("onclick",PopOverHide);
    }
    else
    {
        a.setAttribute("onclick","PopOverHide()");
    }
	pOver.appendChild(a);

}
function PopOverHide()
{
	var pOver = document.getElementById("divPopOver");
	pOver.innerHTML = "";
	pOver.style.top = "0px";
	pOver.style.left = "-99999px";
	pOver.style.width = "0px";
	pOver.style.height = "0px";	

}

function DeliciousImport()
{

	//var delWindow = window.open(SECURE_URI + "delicious.aspx");
	var delWindow = document.getElementById("delicious_window");
	delWindow.style.left="0px";
	delWindow.style.top="0px";
	delWindow.style.width="100%";		
	delWindow.style.height="2500px";	

}


function TwitterStatusUpdate()
{

	//document.getElementById("divDistribute").style.display = "none";				
	//document.getElementById("spnOpt").style.visibility = "visible";	
	var delWindow = document.getElementById("twitter_window");
	delWindow.style.left="0px";
	delWindow.style.top="0px";
	delWindow.style.width="100%";		
	delWindow.style.height="2500px";
	location.href = "#";	

}

function Tracer()
{
   var parent = prx.getElementsByTagName("prx");
   var location = NodeValue("","link",parent, 0);

   if(location.length == 0)
   {
        alert("Please publish your release first.\nClick on the Distribute button.");
        return;
   }
	var delWindow = document.getElementById("tracer_window");
	var headline = "";
	delWindow.src = "tracer_rpt.aspx?id=" + escape(document.getElementById('userid').value + document.getElementById('prname').value) + "&headline=" + escape(document.getElementById('prname').value);
	delWindow.style.left="0px";
	delWindow.style.top="0px";
	delWindow.style.width="100%";		
	delWindow.style.height="2500px";
	location.href = "#";	

}

function FlickrImport()
{

	//var delWindow = window.open(SECURE_URI + "delicious.aspx");
	var flickrWindow = document.getElementById("flickr_window");
	flickrWindow.style.left="0px";
	flickrWindow.style.top="0px";
	flickrWindow.style.width="100%";		
	flickrWindow.style.height="2500px";	

}

function YouTubeImport()
{

	//var delWindow = window.open(SECURE_URI + "delicious.aspx");
	var youTubeWindow = document.getElementById("youtube_window");
	youTubeWindow.style.left="0px";
	youTubeWindow.style.top="0px";
	youTubeWindow.style.width="100%";		
	youTubeWindow.style.height="2500px";	

}


function PRXUploader()
{
	var prxUploaderWindow = document.getElementById("prxuploader_window");
	prxUploaderWindow.style.left="0px";
	prxUploaderWindow.style.top="0px";
	prxUploaderWindow.style.width="100%";		
	prxUploaderWindow.style.height="2500px";	

}

function FileImport()
{

	var fileWindow = document.getElementById("fileimport_window");
	fileWindow.style.left="0px";
	fileWindow.style.top="0px";
	fileWindow.style.width="100%";		
	fileWindow.style.height="2500px";	

}

function FileImportOKCancel(name,xml)
{

	try
	{
		if(xml.length > 0)
		{
			var node = XMLFromText(xml);
			prx.replaceDoc(node,xml);
			alert("File loaded successfully.");
			document.getElementById("prname").value = name;
			document.getElementById("prnameDisplay").value = name;			
		}
		var fileWindow = document.getElementById("fileimport_window");
		fileWindow.style.left="-99999px";
		fileWindow.style.top="0px";
		fileWindow.style.width="1px";		
		fileWindow.style.height="1px";	
	}
	catch(e)
	{
		alert("The file could not be loaded.\n\n" + e.message);
	}
	LoadPage('start');
}

function twitterCharCount()
{
    obj = document.getElementById("txtStatus");
    if(obj.value.length == 0)
    {
		prx = parent.PRXGet();    
		var parent1 = prx.getElementsByTagName("prx");
		var newslines = prx.getElementsByTagNameNS("","newslines",parent1,0);		
        var title = NodeValue("","headline",newslines,0);
		var url = NodeValue("","link",parent1, 0);        
        obj.value = "#news " + url + " - " + title;
    }
    if(140 - obj.value.length < 0)
    {
        obj.value = obj.value.substring(0,140);
    }
    document.getElementById("divChars").innerHTML = 140 - obj.value.length;
}


function LinksUpdate()
{
	try
	{
		var inputList = document.getElementsByTagName("input");
		var chk;
		var link;
		var node;
		prx = parent.PRXGet();    
		var parent1 = prx.getElementsByTagName("prx");
		var links = prx.getElementsByTagNameNS("", "links", parent1, 0);	
		
		count = inputList.length;

		for(var ctr = 0;ctr < count;ctr++)
		{
			if(document.getElementById("chk" + ctr))
			{
				chk = document.getElementById("chk" + ctr);
				if(chk.checked)
				{
					link = document.getElementById("link" + ctr);
					node = XMLFromText("<link:content xmlns:link=\"http://search.yahoo.com/mrss/\" url=\"" + link.href + "\">"
							+"<link:title><![CDATA[" + link.title + "]]></link:title>"
							+"<link:description></link:description>"
							+"<group>2</group>"
							+"<link:thumbnail url=\"\"></link:thumbnail></link:content>");
					try
					{
						links.appendChild(node);
					}
					catch(e)
					{
						alert(e.message);
					}
				}
			}
		}
		Close();
	}
	catch(e)
	{
		alert("An error occurred:  " + e.message);
	}
}

function MMUpdate()
{
	try
	{
		var inputList = document.getElementsByTagName("input");
		var chk;
		var item;
		var img;
		var node;
		var mmType = "Image";
		prx = parent.PRXGet();    		
		var parent1 = prx.getElementsByTagName("prx");
		var items = prx.getElementsByTagNameNS("", "multimedia", parent1, 0);			
		
		count = inputList.length;

		for(var ctr = 0;ctr < count;ctr++)
		{
			if(document.getElementById("chk" + ctr))
			{
				chk = document.getElementById("chk" + ctr);
				if(chk.checked)
				{
					item = document.getElementById("link" + ctr);
					img = document.getElementById("img" + ctr);					
					if(item.href.indexOf("youtube.com") > 0)
					{
					    mmType = "Video";
					}
					if(img.title)
					{
					    mmType = img.title;
					    img = new Image();
					}
					var mmurl = item.href;
					mmurl = AttribClean(mmurl);
					var mmThumbUrl = img.src;
					mmThumbUrl = AttribClean(mmThumbUrl);
					
					node = XMLFromText("<media:content xmlns:media=\"http://search.yahoo.com/mrss/\" url='" + mmurl
							   +"' height='' width=''><media:title><![CDATA[" + item.title + "]]></media:title>"
							   +"<type domain=\"http://purl.org/prx/1.0/\"><![CDATA[" + mmType + "]]></type>"
							   +"<media:thumbnail url='" + mmThumbUrl + "'></media:thumbnail>"
							   +"</media:content>"); 							
						
					try
					{
						items.appendChild(node);
					}
					catch(e)
					{
						alert(e.message);
					}
				}
			}
		}
		Close();
	}
	catch(e)
	{
		alert("An error occurred:  " + e.message);
	}
}

function Set_Cookie( name, value, expires, path, domain, secure ) 
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct 
expires time, the current script below will set 
it for x number of days, to make it for hours, 
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

// this function gets the cookie, if it exists
function Get_Cookie( name ) {
	
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) &&
( name != document.cookie.substring( 0, name.length ) ) )
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function ServiceSubmit(type)
{
   		
	try
	{
	   	var tempURL;
		if(document.getElementById("permalinkHTML").value != "")
		{
	   		tempURL = document.getElementById("permalinkHTML").value;
	  	}
		var url = "";
		var parent = prx.getElementsByTagName("prx");
		var newslines = prx.getElementsByTagNameNS("","newslines",parent,0);		
		var title = NodeValue("","headline",newslines,0);
		tempURL = escape(tempURL);
		title = escape(title);
								
	   	switch(type)
	   	{
	   		case "digg":
	   			url = "http://www.digg.com/submit/?phase=3&url=" + tempURL + "&title=" + title;
	   			break;
	   		case "del.icio.us":
	   			url = "http://del.icio.us/post/?url=" + tempURL + "&title=" + title;
	   			break;
	   		case "reddit":
	   			url = "http://reddit.com/submit?url=" + tempURL + "&title=" + title;
	   			break;
	   		case "markaboo":
	   			url = "http://www.markaboo.com/resources/new/?url=" + tempURL + "&title=" + title;
	   			break;
	   		case "furl":
	   			url = "http://www.furl.net/storeIt.jsp?u=" + tempURL + "&t=" + title;
	   			break;
	   		
	   	}
	   	
	   	if(title.length > 0 && tempURL.length > 0)
	   	{
			var mywindow = window.open(url);   		   		
			if(!mywindow)
			{
				alert("A popup blocker may be stopping this action.\nPlease disable your popup blocker.");
			}
	   	}
	   	else
	   	{
	   		alert("A headline and HTML internet link are required.");
	   	}
	}
	catch(e)
	{
   		alert("An error occurred in ServiceSubmit():  " + e.message);	   		
	}
   		
}

function PRXReleases()
{
   	var item_name = "PRX Releases";
   	var item_number = "1001";
   	var amount = "40.00";
   	var ret = false;
   	var coupon;
   	
   	try
   	{
   	    document.getElementById("prxProcessing").innerHTML = "<h3>Processing...</h3>";
//   	    if(document.getElementById("prxcoupon"))
//   	    {
//   	        var coupon = document.getElementById("prxcoupon").value;
//   	        if(coupon.length > 0)
//   	        {
//	   	        item_number = coupon;	   	    
//	   	    }
//   	    }
//	   	var custom =  document.getElementById("userid").value + "," +  "permastore" + "," + document.getElementById("prname").value + "," + document.getElementById("xform").options[document.getElementById("xform").selectedIndex].value;
//	   	
//   	
//	   	paypalWindow = window.open("paypal.htm?custom=" + custom + "&item_name=" + item_name
//	   		+ "&item_number=" + item_number + "&amount=" + amount);	  
//	    if(paypalWindow)
//	    {
//  	        paypalWindow.focus();
//  	        var msg = "<div style='padding:10px'>A new browser window has been opened to process your release.<br/><br/>"
//	   		    + "Click the <strong>Complete</strong> button after you complete the process successfully."
//                +"<br><br><br><input type='button' class='btnStyle' value='Complete' onclick='FileOpen();PopOverHide();' onmouseover='goLite(this)' onmouseout='goDim(this)'>"		   		    	   		    
//                +"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='button' class='btnStyle' value='Cancel' onclick='PopOverHide()' onmouseover='goLite(this)' onmouseout='goDim(this)'></div>";		   		    
//            PopOverShow(msg,200,200,400,150);									        
//	    }
//	    else
//	    {
//	        alert("The Paypal window could not be opened.\nPlease make sure that you have disabled your popup blocker.");
//	    }
   	    document.getElementById("prxProcessing").innerHTML = "";

   	}
   	catch(e)
   	{
   	}
}

function FileSelected(name)
{
    document.getElementById('prname').value = name;
    FileOpen();
}

function FileOpenDelay()
{
		if(confirm("A new browser window has been opened to process your payment.\n\n"
	   		    + "Click OK after you complete the payment process successfully."))
		{
			FileOpen();											
		}

}

//********************************************
// ContactParse
//********************************************
function ContactParse(contact) {

	contact = contact.replace(new RegExp(/\r/g),"");	
	var lines = contact.split('\n');
	var name = "";
	var note = "";
	var category = "Spokesperson";
	var links = "";
    document.getElementById('contact_phones').value = "";
    document.getElementById('contact_links').value = "";    
                         		

	//Name and Contact Category
	if(lines.length > 0)
	{
		name = lines[0];
		lines[0] = '';
	}
	else
	{
		name = contact;
	}
	if(name.indexOf('(Agency)') > 0)
	{
		category = 'Agency';
	}	
	if(name.indexOf('(Client)') > 0)
	{
		category = 'Client';
	}
	//Remove the category from the name line.
	if(name.indexOf('(') > 0)
	{
		name = name.substring(0,name.indexOf('('));
	}

	//Email & Web Sites
	links = '';
	for(var ctr=0;ctr < lines.length;ctr++)
	{
        lines[ctr] = lines[ctr].replace('mailto:','');
		var link_parts = lines[ctr].split(':');
		//Email
		if(lines[ctr].indexOf('@') > 0)
		{
			if(lines[ctr].indexOf('.') > 0)
			{
				var email = '';
				var label = '';
				if(link_parts.length > 1)
				{
					if(link_parts[1].indexOf('@') > 0)
					{
						label = link_parts[0];
                        email = link_parts[1];
					}
				}
				else
				{
					email = link_parts[0];
					label = 'Email';
				}
				email = email.replace(new RegExp(/\n/g),'');
				email = email.replace(new RegExp(/\r/g),'');				
				email = email.replace(new RegExp(/ /g),'');
				//links += '<vCard:EMAIL xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#" '
                //       +'vCard:TYPE="http://www.w3.org/2001/vcard-rdf/3.0#internet">'
                //       +'<![CDATA['+email+']]><label><![CDATA['+label+']]></label></vCard:EMAIL>';	
                document.getElementById('contact_links').value += label + ":" + email + "\n";
				lines[ctr] = '';				
			}
		}
		//Website
		if(lines[ctr].indexOf('http') > 0)
		{
			if(lines[ctr].indexOf('//') > 0)
			{
				var url = '';
				var label = '';
				if(link_parts.length > 2)
				{
					label = link_parts[0];
                    url = link_parts[1] + link_parts[2];
				}
				else
				{
					if(link_parts.length > 1)
					{
						label = link_parts[0];
						url = link_parts[1];
					}				
					else
					{
					    url = link_parts[0];
					    label = 'Website';
					}
				}
				url = url.replace(new RegExp(/\n/g),'');
				url = url.replace(new RegExp(/\r/g),'');				
				url = url.replace(new RegExp(/ /g),'');
				//links += '<vCard:URL xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#"> '
                //       +'<![CDATA['+url+']]><label><![CDATA['+label+']]></label></vCard:URL>';                       
                document.getElementById('contact_links').value += label + ":" + url + "\n";                
				lines[ctr] = '';				
			}
		}		
	}

	//Place the remaining lines in the Notes section.
	if(lines.length > 1)
	{
		var note = lines.join('\n');
		note = note.replace(new RegExp(/\n\n\n/g),'\n');
		note = note.replace(new RegExp(/\n\n/g),'\n');		
		if(note.substring(0,1) == '\n')
		{
			note = note.substring(1,note.length - 1);
		}
		if(note.length > 1)
		{
			if(note.substring(note.length - 1,1) == '\n')
			{
				note = note.substring(0,note.length - 1);
			}
		}
	}

	//var xml = '<contact xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#"><vCard:CATEGORIES>'
	//    +category+'</vCard:CATEGORIES><vCard:FN><![CDATA['+name+']]></vCard:FN>'
	//	+'<vCard:ORG><vCard:Orgname></vCard:Orgname></vCard:ORG>'
	//	+'<vCard:TITLE></vCard:TITLE>'
	//	+'<vCard:LABEL vCard:TYPE="http://www.w3.org/2001/vcard-rdf/3.0#postal"></vCard:LABEL>'
	//	+'<vCard:NOTE><![CDATA['+note+']]></vCard:NOTE>'
	//	+links
	//	+'</contact>';
	
	for(var i=0;i < document.getElementById('contact_type').options.length;i++)
	{
		if(document.getElementById('contact_type').options[i].text == category)
		{
		    document.getElementById('contact_type').options[i].selected = true;
		}
	}
    document.getElementById('fullname').value = name;    
    document.getElementById('contact_phones').value = note;        
    ContactSave();
    ContactLoad();
	//return xml;

}

function SaveReminder()
{
    var div = document.createElement("div");
    div.id="saveReminder";
    div.style.position = "absolute";
    div.style.width = "250px";
    div.style.height = "100px";
    div.style.left="20px";
    div.style.top="20px";
    div.style.backgroundColor = "#efeded";
    div.style.padding = "20px";
    div.style.color = "black";
    div.style.border = "solid 1px #CCCCCC";
    div.innerHTML = "<h3>Please remember to save your release.</h3>";
    document.body.appendChild(div)
    setTimeout("document.body.removeChild(document.getElementById('saveReminder'))",3000);
}

//DogpileUpdate

function DogpileUpdate(search)
{
      var dogpileURL = "http://www.dogpile.com/info.dogpl/search/web/";
      dogpileURL += search;
      try
      {
        document.getElementById("lnkDogpile").setAttribute("href",dogpileURL);
        document.getElementById("lnkDogpile").href = dogpileURL;
      }
      catch(e)
      {
      }
}

function datetimestamp()
{
    var today = new Date();
    var sToday = (today.getMonth()+1).toString();
    sToday += today.getDate().toString();
    sToday += today.getYear().toString();
    sToday += today.getHours().toString();
    sToday += today.getMinutes().toString();
    sToday += today.getSeconds().toString();
    return sToday;
}

//PRXBuilder Page Code
function gears() {
  if (!window.google || !google.gears) {
    //Every Ten Minutes.
    setInterval('SaveReminder()',600000);
    return;
  }

  try {
    db = google.gears.factory.create('beta.database','1.0');
  } catch (ex) {
    alert('Could not create database: ' + ex.message);
  }

  if (db) {
    db.open();
    db.execute('create table if not exists prx_backup' +
               ' (prname varchar(255), prx text, timestamp int)');
  }

  var gears_succeeded = !!db;
  if(gears_succeeded)
  {
     //Save every 10 minutes;
     var ourInterval = setInterval('AutoSave()',600000);
  }
}

function AutoSave()
{
  if (!google.gears.factory || !db) {
    return;
  }

  XMLProcess();
  var prname = document.getElementById("prname").value;
  var xml = document.getElementById("lblPRX").value;
  var currTime = new Date().getTime();

  if(prname.length > 0)
  {
    db.execute('delete from prx_backup where timestamp not in (select timestamp from prx_backup order by timestamp desc limit 3)');    
    db.execute('insert into prx_backup values (?, ?, ?)', [prname, xml, currTime]);
   }
}

function GearsGet(version) {

   if (!window.google || !google.gears) {
    alert("Google Gears must be installed.");
    return;
  }

  var recentSaves = ['', '', ''];
  var recentNames = ['', '', ''];

  try {

    // Get the 3 most recent entries.
    var rs = db.execute('select * from prx_backup order by timestamp desc');
    var index = 0;
    while (rs.isValidRow()) {
      if (index < 3) {
        recentSaves[index] = rs.field(1);
        recentNames[index] = rs.field(0);
      }
      ++index;
      rs.next();
    }
    rs.close();

    } catch (e) {
    alert(e);
    }
    if(recentNames[version])
    {
        try {
            if(document.getElementById("prnameDisplay"))
            {
                document.getElementById("prnameDisplay").value = recentNames[version];        
            }
            document.getElementById("prname").value = recentNames[version];
            prx.loadXML(recentSaves[version]);
            alert("Backup loaded successfully!");
        }
        catch(e)
        {
            alert("Backup #" + (version + 1) + " failed to load.");
        }
    }
    else
    {
        alert("Backup #" + (version + 1) + " could not be found.");
    }
    
}

function StepSelected(step)
{
    currentStep = step - 1;
    if(appMenu)
    {
        appMenu.getItem(currentStep).focus();
    }
    if(oNext)
    {
        oNext.set('disabled',false);
    }
    if(oPrev)
    {
        oPrev.set('disabled',false);
    }
    if(currentStep > stepArray.length - 2)
    {
        if(oNext)
        {
            oNext.set('disabled',true);
        }
    }
    if(currentStep == 0)
    {
        if(oPrev)
        {
            oPrev.set('disabled',true);
        }
    }
    
    var step = "step" + step;
	
	//Steps
	for(var ctr = 1; ctr < 10; ctr++)
	{
        document.getElementById("step" + ctr).style.fontWeight = "normal";
	}

    document.getElementById(step).style.fontWeight = "bold";
}

function moveIFrame(parms) 
{

	parmArray = parms.split("\t");
	var frameId = parmArray[0];
	var x = parmArray[1];
	var y = parmArray[2];
	var w = parmArray[3];
	var h = parmArray[4];
	
	if(currentPage == "finish")
	{
	    x = "0px";
	    y = "200px";
	    w = "98%";
	}
	
	if(currentPage == "release")
	{
	    y = "595px";
	}
	if(currentPage == "quotes" || currentPage == "boilerplate")
	{
	    y = "315px";
	}	
		
	
	x = x.replace(RegExp(/px/),"");
	y = y.replace(RegExp(/px/),"");	

	try
	{
		if(frameId == "frIFrame" && frIFrameHidden)
		{
			return;
		}

	    var frameRef=document.getElementById(frameId);
	    
	    frameRef.style.left=x + "px";
	    frameRef.style.top=y + "px";
	    frameRef.style.width=w;
	    frameRef.style.height=h + "px";    
	    frameRef.width="90%";
	    frameRef.height=h + "px";
    }
    catch(e)
    {
		alert("Error in moveIFrame():  " + e.message);
    }

}

function LoadPage(obj)
{
   currentPage = obj;
   setTimeout('LoadPageDelayed(currentPage)',500);
   setTimeout('AdjustPage()',500);   
}

function AdjustPage()
{
    document.getElementById("divMain").style.position = "relative";
    document.getElementById("divMain").style.top = "-55px";
}

function fbShare()
{
   var parent = prx.getElementsByTagName("prx");
   var location = NodeValue("","link",parent, 0);
   if(location.length == 0)
   {
        alert("Please publish your release first.\nClick on the Distribute button.");
        return;
   }
    var newslines = prx.getElementsByTagNameNS("","newslines",parent,0);	   
    var title = NodeValue("","headline",newslines, 0);
    
    var d=document,
    f='http://www.facebook.com/share',
    l=d.location,
    e=encodeURIComponent,
    p='.php?src=bm&v=4&i=1191014899&u='+e(location)+'&t='+e(title);
    1;
    try{
    if(!/^(.*\.)?facebook\.[^.]*$/.test(l.host))
    throw(0);share_internal_bookmarklet(p)}
    catch(z){
    a=function(){
    if(!window.open(f+'r'+p,'sharer','toolbar=0,status=0,resizable=0,width=626,height=436'))l.href=f+p};
    if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else{a()}}void(0);	
}

function DeliciousPost()
{

   var parent = prx.getElementsByTagName("prx");
   var location = NodeValue("","link",parent, 0);
   if(location.length == 0)
   {
        alert("Please publish your release first.\nClick on the Distribute button.");
        return;
   }
    var newslines = prx.getElementsByTagNameNS("","newslines",parent,0);	   
    var title = NodeValue("","headline",newslines, 0);
    
    document.getElementById("deliciousPost").setAttribute("href","http://del.icio.us/post?url=" + escape(location) + "&title=" + escape(title));

    return true;
}

function NewshoundPublish()
{
   var parent = prx.getElementsByTagName("prx");
   var location = NodeValue("","link",parent, 0);
   if(location.length == 0)
   {
        alert("Please publish your release first.\nClick on the Distribute button.");
        return;
   }

   var newslines = prx.getElementsByTagNameNS("","newslines",parent,0);	   
   var title = NodeValue("","headline",newslines, 0);
   var custom = document.getElementById("userid").value + "\t" + "newshound";
   
   document.getElementById("newshoundPublishLink").setAttribute("href","prcsorder.aspx?custom=" + escape(custom)
   + "&app_topic_id=" + escape("PRX" + document.getElementById("userid").value + document.getElementById("prname").value)
   + "&title=" + escape(title)
   + "&url=" + escape(location));


}

/////////////////////
//////////


///////////




/*
     "beforeshow" event handler for each submenu of the MenuBar
     instance, used to setup certain style properties before
     the menu is animated.
*/

function onSubmenuBeforeShow(p_sType, p_sArgs) {

    ViewerHide();
    
    var oBody,
        oElement,
        oShadow,
        oUL;

    if (this.parent) {

        oElement = this.element;

        /*
             Get a reference to the Menu's shadow element and 
             set its "height" property to "0px" to syncronize 
             it with the height of the Menu instance.
        */
       
        oElement.style.zIndex = 999;

        oShadow = oElement.lastChild;
        oShadow.style.height = "0px";

        
        /*
            Stop the Animation instance if it is currently 
            animating a Menu.
        */ 
    
        if (oAnim && oAnim.isAnimated()) {
        
            oAnim.stop();
            oAnim = null;
        
        }


        /*
            Set the body element's "overflow" property to 
            "hidden" to clip the display of its negatively 
            positioned <ul> element.
        */ 

        oBody = this.body;


        //  Check if the menu is a submenu of a submenu.

        if (this.parent && 
            !(this.parent instanceof YAHOO.widget.MenuBarItem)) {
        

            /*
                There is a bug in gecko-based browsers where 
                an element whose "position" property is set to 
                "absolute" and "overflow" property is set to 
                "hidden" will not render at the correct width when
                its offsetParent's "position" property is also 
                set to "absolute."  It is possible to work around 
                this bug by specifying a value for the width 
                property in addition to overflow.
            */

            if (ua.gecko) {
            
                oBody.style.width = oBody.clientWidth + "px";
            
            }
            
            
            /*
                Set a width on the submenu to prevent its 
                width from growing when the animation 
                is complete.
            */
            
            if (ua.ie == 7) {

                oElement.style.width = oElement.clientWidth + "px";

            }
        
        }


        oBody.style.overflow = "hidden";


        /*
            Set the <ul> element's "marginTop" property 
            to a negative value so that the Menu's height
            collapses.
        */ 

        oUL = oBody.getElementsByTagName("ul")[0];

        oUL.style.marginTop = ("-" + oUL.offsetHeight + "px");
    
    }

}


/*
    "tween" event handler for the Anim instance, used to 
    syncronize the size and position of the Menu instance's 
    shadow and iframe shim (if it exists) with its 
    changing height.
*/

function onTween(p_sType, p_aArgs, p_oShadow) {

    if (this.cfg.getProperty("iframe")) {
    
        this.syncIframe();

    }

    if (p_oShadow) {

        p_oShadow.style.height = this.element.offsetHeight + "px";
    
    }

}


/*
    "complete" event handler for the Anim instance, used to 
    remove style properties that were animated so that the 
    Menu instance can be displayed at its final height.
*/

function onAnimationComplete(p_sType, p_aArgs, p_oShadow) {

    var oBody = this.body,
        oUL = oBody.getElementsByTagName("ul")[0];

    if (p_oShadow) {
    
        p_oShadow.style.height = this.element.offsetHeight + "px";
    
    }


    oUL.style.marginTop = "";
    oBody.style.overflow = "";
    

    //  Check if the menu is a submenu of a submenu.

    if (this.parent && 
        !(this.parent instanceof YAHOO.widget.MenuBarItem)) {


        // Clear widths set by the "beforeshow" event handler

        if (ua.gecko) {
        
            oBody.style.width = "";
        
        }
        
        if (ua.ie == 7) {

            this.element.style.width = "";

        }
    
    }
    
}


/*
     "show" event handler for each submenu of the MenuBar 
     instance - used to kick off the animation of the 
     <ul> element.
*/

function onSubmenuShow(p_sType, p_sArgs) {

    var oElement,
        oShadow,
        oUL;

    if (this.parent) {

        oElement = this.element;
        oShadow = oElement.lastChild;
        oUL = this.body.getElementsByTagName("ul")[0];
    

        /*
             Animate the <ul> element's "marginTop" style 
             property to a value of 0.
        */

        oAnim = new YAHOO.util.Anim(oUL, 
            { marginTop: { to: 0 } },
            .5, YAHOO.util.Easing.easeOut);


        oAnim.onStart.subscribe(function () {

            oShadow.style.height = "100%";
        
        });


        oAnim.animate();


        /*
            Subscribe to the Anim instance's "tween" event for 
            IE to syncronize the size and position of a 
            submenu's shadow and iframe shim (if it exists)  
            with its changing height.
        */

        if (YAHOO.env.ua.ie) {
            
            oShadow.style.height = oElement.offsetHeight + "px";


            /*
                Subscribe to the Anim instance's "tween"
                event, passing a reference Menu's shadow 
                element and making the scope of the event 
                listener the Menu instance.
            */

            oAnim.onTween.subscribe(onTween, oShadow, this);

        }


        /*
            Subscribe to the Anim instance's "complete" event,
            passing a reference Menu's shadow element and making 
            the scope of the event listener the Menu instance.
        */

        oAnim.onComplete.subscribe(onAnimationComplete, oShadow, this);
    
    }

}


//function myEditorPreRender(myEditor) {
//    var Dom = YAHOO.util.Dom,
//        Event = YAHOO.util.Event;
//    var state = 'off';
//    myEditor.on('toolbarLoaded', function() {
//        var codeConfig = {
//            type: 'push', label: 'Edit HTML Code', value: 'editcode'
//        };
//        this.toolbar.addButtonToGroup(codeConfig, 'insertitem');
//        this.toolbar.on('editcodeClick', function() {
//            var ta = this.get('element'),
//                iframe = this.get('iframe').get('element');
//            if (state == 'on') {
//                state = 'off';
//                this.toolbar.set('disabled', false);
//                this.setEditorHTML(ta.value);
//                if (!this.browser.ie) {
//                    this._setDesignMode('on');
//                }
//                Dom.removeClass(iframe, 'editor-hidden');
//                Dom.addClass(ta, 'editor-hidden');
//                this.show();
//                this._focusWindow();
//            } else {
//                state = 'on';
//                this.cleanHTML();
//                Dom.addClass(iframe, 'editor-hidden');
//                Dom.removeClass(ta, 'editor-hidden');
//                this.toolbar.set('disabled', true);
//                this.toolbar.getButtonByValue('editcode').set('disabled', false);
//                this.toolbar.selectButton('editcode');
//                this.dompath.innerHTML = 'Editing HTML Code';
//                this.hide();
//            }
//            return false;
//        }, this, true);

//        this.on('cleanHTML', function(ev) {
//            this.get('element').value = ev.html;
//        }, this, true);
//        
//        this.on('afterRender', function() {
//            var wrapper = this.get('editor_wrapper');
//            wrapper.appendChild(this.get('element'));
//            this.setStyle('width', '95%');
//            this.setStyle('height', '95%');
//            this.setStyle('visibility', '');
//            this.setStyle('top', '');
//            this.setStyle('left', '');
//            this.setStyle('position', '');
//            this.addClass('editor-hidden');
//        }, this, true);
//    }, myEditor, true);
//}

function $(elem)
{
    return document.getElementById(elem);
}

function ToggleDiv(a,elem)
{
    
    if($(elem).style.display == "none")
    {
        $(elem).style.display = "block";
        a.innerHTML = a.innerHTML.replace("+","-");
    }
    else
    {
        $(elem).style.display = "none";    
        a.innerHTML = a.innerHTML.replace("-","+");        
    }
}

function Exit()
{
    location.href = "exit.aspx";    
}






   	
