Element.extend( {        
	show: function() {            
		this.setStyle('display','');        
	},        
	hide: function() {            
		this.setStyle('display','none');         
	}, 	
	getSiblings: function(match,nocash) {
		return this.getParent().getChildren(match,nocache).erase(this);
	},	
	'click': function(fn) {
		return this.addEvent('click',fn);
	},
	
	visible: function() {
		return this.style.display != 'none';
	},
	
	toggle: function() {
		this[this.visible() ? 'hide' : 'show']();
		return this;
	},
	
	setHTML: function() {
		alert("here");
		debug;
	}
}); 


String.extend( {
			  
	ReplaceAll : function(replace_str, with_str)
	{
		return this.replace( new RegExp(replace_str,"g"), with_str );		
	},

	isEmpty : function() {
			if ((this.length==0) || (this==null)) {
				return true;
			}
			else
			{
				return false;
			} 
	},

	isNull : function() {
			return ( (this.length==0) || (this==null) );
	},
	
	/************************************************
	DESCRIPTION: Validates that a string contains valid
	  US phone pattern.
	  Ex. (999) 999-9999 or (999)999-9999
	
	RETURNS:
	   True if valid, otherwise false.
	*************************************************/	
	IsUSNumber : function() {
			var objRegExp  = /^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/;
  			//check for valid us phone with or without space between
  			//area code
  			return objRegExp.test(this);
	  },
	  
	/************************************************
	DESCRIPTION: Returns all the numbers in a string
	
	RETURNS:
	   String with Numbers Only (0-9)
	
	*************************************************/		  
	 GetNumbers : function() {
			var temp = this;
			var index = 0;
			var LimitCheck;
			var FmtStr = "";
			LimitCheck = this.length;
			while (index != LimitCheck)
			{
				if (isNaN(parseInt(temp.charAt(index))))
				{ }
				else
				{ 
					FmtStr = FmtStr + temp.charAt(index); 
				}
				index = index + 1;
			}
			return FmtStr;	 
	 },
	/************************************************
		DESCRIPTION: Validates that a string contains a
		  valid email pattern.
		
		RETURNS:
		   True if valid, otherwise false.
		
		REMARKS: Accounts for email with country appended
		  does not validate that email contains valid URL
		  type (.com, .gov, etc.) or valid country suffix.
	**************************************************/
	IsEmail : function() {
		var str = this;
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true
	},
	
	/************************************************
	DESCRIPTION: Validates that a string contains only
		valid dates with 2 digit month, 2 digit day,
		4 digit year. Date separator can be ., -, or /.
		Uses combination of regular expressions and
		string parsing to validate date.
		Ex. mm/dd/yyyy or mm-dd-yyyy or mm.dd.yyyy
	
	RETURNS:
	   True if valid, otherwise false.
	
	REMARKS:
	   Avoids some of the limitations of the Date.parse()
	   method such as the date separator character.
	*************************************************/
	IsDate : function() {

		  var strValue = this;
		  var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
		 
		  //check to see if in correct format
		  if(!objRegExp.test(strValue))
				return false; //doesn't match pattern, bad date
		  else
		  {
				var strSeparator = strValue.substring(2,3) 
				var arrayDate = strValue.split(strSeparator); 
				//create a lookup for months not equal to Feb.
				var arrayLookup = { '01' : 31,'03' : 31, 
								'04' : 30,'05' : 31,
								'06' : 30,'07' : 31,
								'08' : 31,'09' : 30,
								'10' : 31,'11' : 30,'12' : 31}
				var intDay = parseInt(arrayDate[1],10); 
		
				//check if month value and day value agree
				if(arrayLookup[arrayDate[0]] != null) 
				{
			  		if(intDay <= arrayLookup[arrayDate[0]] && intDay != 0)
						return true; //found in lookup table, good date
				}
			
				//check for February (bugfix 20050322)
				//bugfix  for parseInt kevin
				//bugfix  biss year  O.Jp Voutat
				var intMonth = parseInt(arrayDate[0],10);
				if (intMonth == 2) 
				{ 
					var intYear = parseInt(arrayDate[2]);
				   	if (intDay > 0 && intDay < 29) 
					{
						return true;
				   	}
				   	else if (intDay == 29) 
				   	{
						 if ((intYear % 4 == 0) && (intYear % 100 != 0) || 
							 (intYear % 400 == 0)) 
						{
							  // year div by 4 and ((not div by 100) or div by 400) ->ok
							 return true;
						}   
			   		}
				}
		  }  
		  return false; //any other values, bad date
	},
	
	
	/************************************************
	DESCRIPTION: Validates that a string a United
	  States zip code in 5 digit format or zip+4
	  format. 99999 or 99999-9999
	
	PARAMETERS:
	   format: 5, 10: 5 format (11111) 10 format(11111-1111)
	
	RETURNS:
	   True if valid, otherwise false.
	
	*************************************************/
	IsUSZip : function(format) {
		var objRegExp;
		if(format == 5)
		{
			objRegExp  = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
		}
		else
		{
			objRegExp  = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
		}

  		//check for valid US Zipcode
		return objRegExp.test(this);
	},
	
	/************************************************
	DESCRIPTION: Is the String Empty or Null
	
	RETURNS:
	   True if valid, otherwise false.
	
	*************************************************/	
	IsEmpty : function()
	{
		return ((this == null) || (this.length == 0));
	},
	
	/************************************************
	DESCRIPTION: Is the String a Double Number
	
	RETURNS:
	   True if valid, otherwise false.
	
	*************************************************/	
	IsDouble : function() {
		var i;
		var bDecimalFound = false;
		var check = this;
		if (this.IsEmpty()) 
		{
			return false;
		}
	
		// Search through string's characters one by one
		// until we find a non-numeric character, excluding decimal point.
		// When we do, return false; if we don't, return true.  If more than
		// one decimal point is found, return false.	
		for (i = 0; i < check.length; i++)
		{   
			// Check that current character is number.
			var c = check .charAt(i);
	
			// If current character is a decimal point and a previous decimal point has NOT been found yet
			if ( ( c == "." ) && ( !bDecimalFound ) )
			{
				// Indicate that the one allowed decimal point has been found; continue searching value
				bDecimalFound = true;
			}
			else if ( !isDigit(c) )
			{
				return false;
			}
		}

		// All characters are numbers or the decimal point.
		return true;
	}
});


