
var replaceObject = {
	
	init: function(){
		
		
		var metaDescription = document.getElementById("metadata_field_text_1552_value");
		var metaTitle = document.getElementById("page_standard_0_140");
		
		if(metaDescription){
		
			metaDescription.onblur = function(){
			
				replaceObject.clearQuotes(this);
			
			}
		
		}
		
		else if(metaTitle){
			
			metaTitle.onblur = function(){
			
				replaceObject.clearQuotes(this);
				replaceObject.clearDollar(this);
			
			}
			
		}
				
	},
	
	str_replace: function(haystack, needle, replacement) {
				var temp = haystack.split(needle);
				return temp.join(replacement);
				
	},
	
	clearQuotes: function(whichForm){        
					
			var smartQuoteRight = String.fromCharCode(8217);
			var smartQuoteLeft = String.fromCharCode(8216);
			var smartDoubleRQuote = String.fromCharCode(8221);
			var smartDoubleLQuote = String.fromCharCode(8220);
			var enDash = String.fromCharCode(8211);
			
			
			
			// Place new replace characters in the below array
			
		    var changeArray = [];
			  
			changeArray[smartQuoteRight] = "'";
			changeArray[smartQuoteLeft] = "'";
			changeArray[smartDoubleRQuote] = '"';
			changeArray[smartDoubleLQuote] = '"';
			changeArray[enDash] = '-';

			 
			  
			for (var key in changeArray)
			
			  {
				  var value = changeArray[key];		

				  whichForm.value = replaceObject.str_replace(whichForm.value, key, value);   
			  }
			  
     },
	 
	 clearDollar: function(whichForm){
		 
		var dollar = "$";
		
		if(whichForm.value.indexOf(dollar) != -1){
										
						whichForm.value = replaceObject.str_replace(whichForm.value, dollar, "");
						
							alert('The use of dollar signs in this initial stage of page creation is not allowed as it breaks the URL. They have been automatically removed from the page title, you may reinsert them by selecting the "Page Name" and "Page Short Name" fields located on the next screen. For further clarification please contact the Web team'); 
							
		}
		 
	 }
	
};

replaceObject.init();





