function IsDate(d) {
    //Author: Matt Loupe - 03/27/2000
    // Returns an error in string format if d is not a valid date in 
    // mm/dd/yyyy or m/d/yyyy format .
    //this function modified by rrobbins on 3/28/2000
   //returns true or false if date is valid/invalid

   //for Saks, this function validates m/d/yy or mm/dd/yy
    
    var mm,dd,yyyy;
    var lastDay;  //last day of the month.
    var sMonth;  //month in string format.
       
    if (d.length < 6 || d.length > 8) //Check length where shortest = m/d/yyyy
       return false;
    
    if (!IsNumeric(d.charAt(1)))  // If the month supplied is only 1 digit prepend a 0.
       d = "0" + d;   
    
    mm = "" + d.substring(0,2);  //Extract month
            
    if (!IsNumeric(d.substring(3,5))) //If day is only one digit insert a 0.
       d =d.substring(0,3) + "0" + d.substring(3,d.length);
      
    dd = d.substring(3,5);  //Extract day

    if (d.length < 8) //Check length again where shortest = mm/dd/yyyy
       return false;

    yyyy= d.substring(6,d.length);  //Extract year
	
	if (yyyy.length != 4 && yyyy.length != 2)
		return false;
	

    if (!IsNumeric(mm) || !IsNumeric(dd) || !IsNumeric(yyyy)) //If any part of the date is not numeric.
       return false;
    
	  mm = mm * 1; dd = dd * 1; yyyy = yyyy * 1; //Convert all parts to integers.
    
	if (yyyy.toString.length <= 2)
	{
		if(yyyy >= 50)
			yyyy+= 1900;
		else
			yyyy+= 2000;
	}
	//alert(yyyy);
    //Routine checks of month,day, and year including number of days in the month and leap year
    if (mm < 1 || mm > 12)  
       return false;    
    switch (mm) { 
       case 1:
         lastDay = 31;
         sMonth = "January";
         break;
       case 2:       
         if (yyyy >= 4 && (yyyy % 4)== 0)  
            lastDay = 29;
         else
            lastDay = 28;
               
         sMonth = "Febuary";
         break;
       case 3:
         lastDay = 31;
         sMonth = "March";
         break;
       case 4:
         lastDay = 30;
         sMonth = "April";
         break;
       case 5:
         lastDay = 31;
         sMonth = "May";
         break;
       case 6:
         lastDay = 30;
         sMonth = "June";
         break;
       case 7:
         lastDay = 31;
         sMonth = "July";
         break;
       case 8:
         lastDay = 31;
         sMonth = "August";
         break;
       case 9:
         lastDay = 30;
         sMonth = "September";
         break;
       case 10:
         lastDay = 31;
         sMonth = "October";
         break;
       case 11:
         lastDay = 30;
         sMonth = "November";
         break;
       default:
         lastDay = 31;
         sMonth = "December";
         break;  
    }     
    if (dd < 1 || dd > lastDay) 
       return false;               
    //if (yyyy < 1) 
     //  return false;               
    
    return true; //Valid date - return an empty string.
  }


function Trim(strString)
	{
		//trim Leading spaces
		while(''+strString.charAt(0)==' ')
			strString=strString.substring(1,strString.length);

		//trim trailing spaces
		while(''+strString.charAt(strString.length - 1) == ' ')
			strString=strString.substring(0,strString.length - 1);

		return strString;
	}
function IsNumeric(field)
	{
		var valid = "0123456789.";
			
		if(field.length < 1) 
		{
			return false;
		}
		else
		{
			for (var i=0; i< field.length;i++)
			{
				temp = "" + field.substring(i, i+1);
				if (valid.indexOf(temp) == "-1")
				{
					return false;
				}
			}
			if (field.indexOf('.') != field.lastIndexOf('.'))
				return false;
		}
		return true;
	}

 function IsEmail(e) {
    // Author: Matthew Loupe - 03/28/2000
    // Returns an error in string format if e is not a valid email in 
    // name@domain.x format where name.length >= 2 , domain.length >=2 
    // and x.length >= 2.
 
    var tmp = "" + e;   

    if (tmp.search(/@/) < 2)
       return false;

    tmp = tmp.substring(tmp.search(/@/) + 1,tmp.length);
    
    if (tmp.search(/@/) > -1)
       return false;
       
    if (tmp.search(/\./) < 2) 
       return false;
      
    tmp = tmp.substring(tmp.search(/\./) + 1,tmp.length);

    //if (tmp.search(/\./) > -1) 
     //  return false;
  
    if (tmp.length < 2)
       return false;                
  
   return true;
  
  }


//accepts a string value to check if it's a phone no
	//phone can be either ###-#### or ###-###-#### or (###)###-####
	//returns true if valid number
	function IsPhone(strPhone)
	{
		strPhone = Trim(strPhone);

		//Allow for 10 digit nbrs
		if (strPhone.length == 10 && IsNumeric(strPhone))
			return true;

		//if(strPhone.length !=13)
		if(strPhone.length != 8 && strPhone.length != 12 && strPhone.length !=13)
			return false;
		
		//decimals and spaces are valid delimiters, replace with
		//hyphen to simplify further parsing
		strPhone = strPhone.replace(/\./g,"-");
		strPhone = strPhone.replace(/ /g,"-");
		
		//
		if (strPhone.length == 8) //###-####
		{
			if(strPhone.charAt(3) != '-')
				return false;
				
			strPhone = strPhone.replace(/-/,'');
		}
		else //###-###-####
		{
			if (strPhone.length == 12)
			{
				if(strPhone.charAt(3) != '-' || strPhone.charAt(7) != '-')
				return false;
				
				//replace the - twice
				for(var i=1;i<=2;i++)
					strPhone = strPhone.replace(/-/,'');
			}
			else
			{
				if(strPhone.charAt(0) != '(' || strPhone.charAt(4) != ')' || strPhone.charAt(8) != '-')
					return false;

				//replace hyphens and parentheses
				strPhone = strPhone.replace(/-/,'');
				strPhone = strPhone.replace('(','');
				strPhone = strPhone.replace(')','');
			}
			
		}
		
		//if they're are more - or (), phone number is invalid
		if(strPhone.indexOf('-') != -1 || strPhone.indexOf('(') != -1 || strPhone.indexOf(')') != -1)
			return false;	
			
		if(!IsNumeric(strPhone) || (strPhone.length != 7 && strPhone.length != 10))
			return false;
			
			
		
		return true;
	}
	
function IsZip(field) //string object
		{
			var valid = "0123456789-";
			var hyphencount = 0;

			if (field.length!=5 && field.length!=10) 
			{
				
				return false;
			}
			for (var i=0; i < field.length; i++) 
			{
				temp = "" + field.substring(i, i+1);
				if (temp == "-") hyphencount++;
				if (valid.indexOf(temp) == "-1") 
				{
					
					return false;
				}
				if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) 
				{
					
					return false;
				}
			}
			return true;
		}

function IsSSN(field)
{
	
	if (field.length != 11)
	{
		return false;
	}
	if (field.charAt(3)!="-" || field.charAt(6)!="-")
	{
		return false;
	}

	//replace the - twice
	for(var i=1;i<=2;i++)
		field = field.replace(/-/,'');

	if (field.indexOf('-') != -1 || field.indexOf('.') != -1)
	{
		return false;
	}
	
	if (!IsNumeric(field))
	{
		return false;
	}

	return true;
}

function getRadioValue(radioName,frmName) 
{
	var frm = document.forms[frmName];
	var rdo = frm.elements[radioName];
	for(var i=0;i< rdo.length;i++)
	{
		if(rdo[i].checked == true)
			return rdo[i].value;  
	}
	
	return '';
}

function moveSelected(lstFromName,lstToName,frmName) 
	{
		var frm = document.forms[frmName];
		var lstFrom = frm.elements[lstFromName];
		var lstTo = frm.elements[lstToName];
		var arrFromVal = new Array();
		var arrFromText = new Array();
		var nFrom = 0;
		var lenTo = lstTo.length;	
		var lenFrom = lstFrom.length;
		
		for(var i=0;i < lstFrom.length;i++)
		{
			
			if(lstFrom.options[i].selected == true)
			{
				
				lstTo.length = lenTo + 1;
				lstTo.options[lenTo] = new Option(lstFrom.options[i].text,lstFrom.options[i].value);
				
				//lstFrom.options[i].selected = false;
				//lstFrom.options[i] = null;
				//i--;
				lenTo++;
				

			} 
			else
			{
				arrFromVal.length = nFrom + 1;
				arrFromText.length = nFrom + 1;
				arrFromVal[nFrom] = lstFrom.options[i].value;
				arrFromText[nFrom] = lstFrom.options[i].text;
				nFrom++;
			}
			
		}
		
		if (navigator.userAgent.indexOf('MSIE 5')>0)
		{
			//the next few lines are to accomodate a bug in IE 5.0
			//moving over more options then the size of the <select> 
			//throws an exception.  setting the .innerHTML to "" clears the select entirely
			//and then it is rebuilt from the array
			lstFrom.innerHTML = "";
		}
		
		lstFrom.length = 0;
		for (i=0;i <arrFromVal.length ;i++)
		{
			lstFrom.length = i + 1;
			lstFrom.options[i] = new Option(arrFromText[i],arrFromVal[i]);
		}
		
	}

function SelectAll(lstName,frmName)
{
	var frm = document.forms[frmName];
	var lst = frm.elements[lstName];

	for(var i=0;i<lst.length;i++)
	{
		lst.options[i].selected = true;
	}
}

