//-----------------------------------------------------------------------//
function formatPhone(sPhone,sDel1,sDel2,sDel3)                           //
//-----------------------------------------------------------------------//
//          function name: formatPhone()                                 //
//             created by: Dustin Brown                                  //
//             created on: 2/20/2001                                     //
//                purpose: format a given phone number to                //
//                         sDel1+999+sDel2+999+sDel3+9999                //
//                         example: sPhone = "9998887777"                //
//                                  sDel1  = "("                         //
//                                  sDel2  = ")"                         //
//                                  sDel3  = "-"                         //
//                                  return "(999)888-7777"               //
//             parameters: sPhone - the date to be formatted.            //
//                         sDel1  - (optional) the first delimiter to be //
//                                  used; defaults to "(".               //
//                         sDel2  - (optional) the second delimiter to   //
//                                  be used; defaults to ")".            //
//                         sDel3  - (optional) the third delimiter to be //
//                                  used; defaults to "-".               //
//                returns: the newly formatted phone if 'sPhone' is      //
//                         valid; a zero length string if it is not.     //
// include files required: validPhone.js, stripChars.js                  //
//-----------------------------------------------------------------------//
{
	//verify 'sPhone' is a valid phone number
	if(!validPhone(sPhone))return "";
	
	//check for delimeters; if omitted, set to default
	if((sDel1==null)||(sDel2==null)){
		sDel1="(";
		sDel2=")";
	}
	if(sDel3==null)sDel3="-";
	
	sPhone=stripChars(sPhone);
	
	//concatenate delimiters and substrings
	var temp=sPhone;
	sPhone=sDel1+temp.substring(0,3)+sDel2;
	sPhone+=temp.substring(3,6)+sDel3;
	sPhone+=temp.substring(6,10);
	
	//return formatted phone number
	return sPhone;
}
//End function formatPhone()---------------------------------------------//