//Utility function to trim out spaces
function TrimSpaces(sText)
{
	//alert(sText);
	return sText.replace(/(^\s+)|(\s+$)/g,"");
}

function EmailValid2(str) 
{
	alert(str);
//	if (window.RegExp) 
//	{
//		var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
//		var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";
//		var reg1 = new RegExp(reg1str);
//		var reg2 = new RegExp(reg2str);
//		
//		if (!reg1.test(str) && reg2.test(str))
//		{
//			return true;
//		}
//		else
//		{
//			return false;
//		}
//    } 
//    else 
//    {
//		if(str.indexOf("@") > 0)
//		return true;
//    }
}

function PasswordValid(str) 
{
	//alert(txtBox.value);
	if (window.RegExp) 
	{
		var reg1str = "^[a-zA-Z0-9]{3,8}$";
		//"(?=.{3,8})[a-zA-Z]+";
		var reg1 = new RegExp(reg1str);
		
		if (reg1.test(str))
		{
			return true;
		}
		else
		{
			return false;
		}
	} 
	else 
	{
		if(str.length > 3)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}

function ZipValid(str)
{
	var patt = /(\d{5})/;
		
	if (str.match(patt))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function validateUSDate( strValue ) 
{
    
  var patt = "/^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/";
 
  if(!strValue.match(patt))
    return false; 
  else
  {
    var strSeparator = strValue.substring(2,3) //find date separator
    var arrayDate = strValue.split(strSeparator); //split date into month, day, year
    //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; 
}


function  validateNumeric( strValue ) 
{
  var patt = "/(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/";
  return strValue.match(patt);
}


function ssn_mask(t)
{
	// IE
	if( window.event )
	{
		keycode = window.event.keyCode;
	}
	// Mozilla
	else if( e ) 
	{
		keycode = e.which;
	}
	
	var patt = /(\d{3}).*(\d{2}).*(\d{4})/;
	var donepatt = /^(\d{3})-(\d{2})-(\d{4})$/;
	var str = t.value;
	var result;
	if (!str.match(donepatt))
	{
		result = str.match(patt);
		if (result!= null)
		{
			t.value = t.value.replace(/[^\d]/gi,'');
			str = result[1] + '-' + result[2] + '-' + result[3];
			t.value = str;
		}
		if (t.value.length==3)
		{
			t.value = t.value + "-";
		}
		if (t.value.length==6)
		{
			t.value = t.value + "-";
		}
		
		// Check to see if the backspace key was pressed, and the - is the last character
		if( keycode == 8 && t.value.substring(t.value.length-1) == "-" )
		{
			// Remove the dash, so that the backspace can function properly
			t.value = t.value.substring(0, t.value.lastIndexOf("-"));
		}
	}
}

function phone_mask(t)
{
	var keycode;
				
	// IE
	if( window.event )
	{
		keycode = window.event.keyCode;
	}
	// Mozilla
	else if( e ) 
	{
		keycode = e.which;
	}
				
	var patt = /(\d{3}).*(\d{3}).*(\d{4})/;
	var donepatt = /^(\d{3})-(\d{3})-(\d{4})$/;
	var str = t.value;
	var result;
	if (!str.match(donepatt))
	{
		result = str.match(patt);
		if (result!= null)
		{
			t.value = t.value.replace(/[^\d]/gi,'');
			str = result[1] + '-' + result[2] + '-' + result[3];
			t.value = str;
		}
		if (t.value.length==3)
		{
			t.value = t.value + "-";
		}
		if (t.value.length==7)
		{
			t.value = t.value + "-";
		}
		
		// Check to see if the backspace key was pressed, and the - is the last character
		if( keycode == 8 && t.value.substring(t.value.length-1) == "-" )
		{
			// Remove the dash, so that the backspace can function properly
			t.value = t.value.substring(0, t.value.lastIndexOf("-"));
		}
	}
	
	// The phoner number is completely filled out, but it does not match the proper format (###-###-####)
	if( t.value.length == 12 && ! str.match(donepatt) )
	{
		// Split the string at the dashes, since we don't know where they are, but we know there are two of,
		// and create a string array with 3 parts (before first dash, middle, after second dash)
		var strArray = str.split("-");
		
		// Put the string back together without the dashes
		str = strArray[0] + strArray[1] + strArray[2];
		
		// Get the pattern we want to match with the current value
		var finalPhoneNumber = str.match(patt);
		
		if( finalPhoneNumber != null )
		{
			// Put the string back together, so long as it matches the desired pattern
			finalPhoneNumber = finalPhoneNumber[1] + "-" + finalPhoneNumber[2] + "-" + finalPhoneNumber[3];
			
			// Set the value of the textbox to the new phone number
			t.value = finalPhoneNumber;
		}
	}
}
