// *********************************************** //
// ** STRING PROTOTYPES
// ** extends the _JavaScript STRING object with
// ** additional functionality
// ********************************************** //

// string.trim()
    String.prototype.trim = function()
    {   
            return this.replace(/(^\s*)|(\s*$)/g, "");
    }
// string.ltrim()    
    String.prototype.ltrim = function()
    {
            return this.replace(/(^\s*)/g, "");
    }

// string.rtrim()    
    String.prototype.rtrim = function()
    {
            return this.replace(/(\s*$)/g, "");
    }

// string.isEmpty()    
    String.prototype.isEmpty = function()
    {
        if(null == this)
            return(true);      
              
        var sValue = this.trim();
        
        if(sValue.length > 0)
            return(false);
        else
            return(true);
    } 
    
// string.isPhone()
    String.prototype.isPhone = function()
    {
        var pattern = /^(\(?\d\d\d\)?)?( |-|\.)?\d\d\d( |-|\.)?\d{4,4}(( |-|\.)?[ext\.]+ ?\d+)?$/;
        return( this.trim().match(pattern) );
    }  
    
// string.isZipCode()
    String.prototype.isZipCode = function()
    {
        var pattern = /^\d{5}(-\d{4})?$/;
        return( this.trim().match(pattern) );
    }    
    
// string.isEmail()
    String.prototype.isEmail = function()
    {
        var pattern = /^([\w-]+\.)*?[\w-]+@[\w-]+\.([\w-]+\.)*?[\w]+$/;
        return( this.trim().match(pattern) ) ;
    }    
    
// string.isURL()
    String.prototype.isURL = function()
    {
        var pattern = /^[a-zA-Z0-9\-\.]+\.(com|org|net|mil|edu|COM|ORG|NET|MIL|EDU|UK|INFO|US|NAME|BIZ|DE|TV|CC|BZ)$/;
        return( this.trim().match(pattern) );
    }    
    
// string.toHTML
    String.prototype.toHTML = function()
	{
		var result	= null;
		var pattern 	= /\n/g;
		result 		= this.replace(pattern, "<br/>");
		
		pattern		= /\r/g;
		result 		= result.replace(pattern, "<br/>");
		
		return(result);
	}
	
	
// *********************************************** //
// ** XmlHttpResponse & XML Support
// ** declares and initializes an instance of the
// ** XmlHttpResponse object
// ********************************************** //
	  
	var _xmlHttp		= null;

// xml nodeType list 
	var ELEMENT_NODE				= 1;
	var ATTRIBUTE_NODE			= 2;
	var TEXT_NODE					= 3;
	var CDATA_SECTION_NODE			= 4;
	var ENITITY_REFERENCE_NODE		= 5;
	var ENTITY_NODE				= 6;
	var PROCESSING_INSTRUCTION_NODE	= 7;
	var COMMENT_NODE				= 8;
	var DOCUMENT_NODE				= 9;
	var DOCUMENT_TYPE_NODE			= 10;
	var DOCUMENT_FRAGMENT_NODE		= 11;
	var NOTATION_NODE				= 12;
	
// Init_HttpRequest()	
	function Init_HttpRequest()
	{
		if(_xmlHttp == null)
		{
			if(window.XMLHttpRequest)	// init for Mozilla/Safari		
				_xmlHttp = new XMLHttpRequest();
			else if(window.ActiveXObject)	// init for IE
			{
			// earler versions of IE
				try
				{
					_xmlHttp	= new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e)
				{
					try
					{
						_xmlHttp	= new ActiveXObject("Microsoft.XMLHTTP");
					}
					catch(e){}
				}				
			}		
		}
	}
	  

// XML_GetInnerText
/* 	Gets the inner text of an XML node. Attempts to handle 
	variations in browser types. 
	
	Firefox supports the 'textContent' property
	IE supports the 'text' property
*/	
	function XML_GetInnerText( xmlNode )
	{
		if (typeof xmlNode.textContent != 'undefined') 
		{
			return xmlNode.textContent;
		}
		else if (typeof xmlNode.innerText != 'undefined') 
		{
			return xmlNode.innerText;
		}
		else if (typeof xmlNode.text != 'undefined') 
		{
			return xmlNode.text;
		}
		else
		{
			switch(xmlNode.nodeType)
			{
				case CDATA_SECTION_NODE:
					return xmlNode.nodeValue;
					break;
				case DOCUMENT_FRAGMENT_NODE:
					var innerText	= "";
					for(var i=0; xmlNode.childNodes.length; i++)
					{
						innerText += XML_GetInnerText( xmlNode.childNodes[i] );
					}
					return innerText;
					break;
				default:
					return "";
					break;
			}
		}
	}
	  
	  
// *********************************************** //
// ** Browser Information
// ** Methods which extract or derive information 
// ** about the client agent.
// ********************************************** //
	function IsIE()
	{
		return(window.ActiveXObject);
	}
	  
	  
	  
// *********************************************** //
// ** mouseCoords
// ** returns an object which contains the X and Y 
// ** coordinates of the mouse
// *********************************************** //
	function mouseCoords(ev){
		if(ev.pageX || ev.pageY){
			return {x:ev.pageX, y:ev.pageY};
		}
		return {
			x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
			y:ev.clientY + document.body.scrollTop  - document.body.clientTop
		};
	}

	  
	  
	  
	  
	  
	  
	  
	  
	  
	  