/************************************************************
function : MatchString(strText)
usage    : for matching one string with another
inputs   : string,string.
output   : boolean(True/False)
e.g      : MatchString("abc","abc") = True
************************************************************/
function MatchString(s1,s2)
{
	if(s1==s2)
		return true;
	else
		return false;
}
/************************************************************
function : LTrim(strText)
usage    : for removing blank spaces from left of a string
inputs   : string.
output   : string without spaces on its left
e.g      : LTrim("  abc  ") = "abc  "
************************************************************/
function LTrim(strText)
{
	while (strText.substring(0,1) == ' ')
			strText = strText.substring(1, strText.length);
	return strText;
} 


/************************************************************
function : RTrim(strText)
usage    : for removing blank spaces from right of a string
inputs   : string.
output   : string without spaces on its right
e.g      : RTrim("  abc  ") = "  abc"
************************************************************/
function RTrim(strText)
{
	while (strText.substring(strText.length-1,strText.length) == ' ')
			strText = strText.substring(0, strText.length-1);
	return strText;
}
	

/************************************************************
function : Trim(strText)
usage    : for removing blank spaces from right and left of a string
inputs   : string.
output   : string without spaces on its right and left
e.g      : Trim("  abc  ") = "abc"
**************************************************************/
function Trim(strText)
{
	return RTrim(LTrim(strText));
}



/************************************************************
function : IsNumeric(strNum)
usage    : to determine whether given string is integer
inputs   : string.
output   : true if it is integer, false otherwise.
e.g      : "123" returns true, "abc44" returns false, "12.34" returns false, "-12" returns true
************************************************************/
function IsNumeric(strNum)
{
	
	if(strNum.indexOf(".")!=-1)
	{
		return false;
	}
	if(strNum.indexOf("e")!=-1)
	{
		return false;
	}
	if(strNum.indexOf("E")!=-1)
	{
		return false;
	}
	if(isNaN(strNum))
	{
		return false;
	}
	return true;
} 

/************************************************************
function : IsDigit(strNum)
usage    : to determine whether given string is integer
inputs   : string.
output   : true if it is integer, false otherwise.
e.g      : "123" returns true, "abc44" returns false, "12.34" returns false, "-12" returns false
************************************************************/
function IsDigit(strNum)
{
	
	if(strNum.indexOf(".")!=-1)
	{
		return false;
	}
	if(strNum.indexOf("-")!=-1)
	{
		return false;
	}
	if(strNum.indexOf("e")!=-1)
	{
		return false;
	}
	if(strNum.indexOf("E")!=-1)
	{
		return false;
	}
	if(isNaN(strNum))
	{
		return false;
	}
	return true;
} 


/************************************************************
function : IsDigit(strNum)
usage    : to determine whether given string is integer
inputs   : string.
output   : true if it is integer, false otherwise.
e.g      : "123" returns true, "abc44" returns false, "12.34" returns true, "-12" returns false
************************************************************/
function IsMoney(strNum)
{
	
	//if(strNum.indexOf(".")!=-1)
	//{
	//	return false;
	//}
	var blnFlag=0
	var intLen=strNum.length
	if ( strNum.charAt(0)==".")
	{		
		return false
	}
	if (strNum.charAt(intLen-1)==".")
	{		
		return false
	}
	for (var i=0;i<intLen;i++)
	{
		if (strNum.charAt(i)==".")
		{
			blnFlag=blnFlag+1
		}
	}
	if (blnFlag>1)
	{		
		return false
	}
	if(strNum.indexOf("-")!=-1)
	{
		return false;
	}
	if(strNum.indexOf("e")!=-1)
	{
		return false;
	}
	if(strNum.indexOf("E")!=-1)
	{
		return false;
	}
	if(isNaN(strNum))
	{
		return false;
	}
	return true;
} 


/************************************************************
function : IsDecimal(strNum)
usage    : to determine whether given string is decimal
inputs   : string.
output   : true if it is decimal, false otherwise.
e.g      : "123" returns true, "abc" returns false, "12.34" returns true,"-12.34" returns true
************************************************************/
function IsDecimal(strNum)
{
	if(strNum.indexOf("e")!=-1)
	{
		return false;
	}
	if(strNum.indexOf("E")!=-1)
	{
		return false;
	}
	if(isNaN(strNum))
	{
		return false;
	}
	return true;
} 




/**************************************************************
function : CheckPhone(p1,p2,p3)
usage    : To check phone number of the form ###-###-####
inputs   : three textbox fields used as input to phone number, str is message to be displayed
output   : returns true if phone number is valid; otherwise returns false
e.g      : 123-345-6789 is valid phone number
**************************************************************/
function CheckPhone(p1,p2,p3,str)
{
	if (p1.value=="" & p2.value=="" & p3.value=="")
	{
	   // str="Enter Primary Phone";
	    alert(str);
	    p1.focus();
		return false;
	}
	if(p1.value.length!=3)
	{
		alert(str);
		p1.select();
		p1.focus();		
		return false;
	}	
	if(!IsDigit(p1.value))
	{
		alert(str);
		p1.select();
		p1.focus();
		return false;
	}
	if(p2.value.length!=3)
	{
		alert(str);
		p2.select();
		p2.focus();		
		return false;
	}	
	if(!IsDigit(p2.value))
	{
		alert(str);
		p2.select();
		p2.focus();
		return false;
	}
	if(p3.value.length!=4)
	{
		alert(str);
		p3.select();
		p3.focus();		
		return false;
	}
	if(!IsDigit(p3.value))
	{
		alert(str);
		p3.select();
		p3.focus();
		return false;
	}
	
	return true;
}


/************************************************************
function : CheckZip(p1,p2,str)
usage    : To check Zip number of the form #####-####
inputs   : two textbox fields used as input to zip number, str is message to be displayed
output   : returns true if zip number is valid; otherwise returns false
e.g      : 12334-6789 is valid Zip Number
************************************************************/

function CheckZip(p1,p2,str)
{
	if (p1.value=="" & p2.value=="")
	{
		return true;
	}
	if(p1.value.length!=5)
	{
		alert(str);
		p1.select();
		p1.focus();		
		return false;
	}
	if(!IsDigit(p1.value))
	{
		alert(str);
		p1.select();
		p1.focus();
		return false;
	}
	if(p2.value.length!=4)
	{
		alert(str);
		p2.select();
		p2.focus();		
		return false;
	}	
	if(!IsDigit(p2.value))
	{
		alert(str);
		p2.select();
		p2.focus();
		return false;
	}
	
	return true;
}


/************************************************************
function : CheckEmail(strMail)
usage    : To check Validity Of Email
inputs   : string containing mail address
output   : returns true if email is valid; otherwise returns false
e.g      : abc@xyz.com is valid Email Address.

************************************************************/
/*
function CheckEmail(strMail)
{
	var strMessage;
	strMessage="Please Enter Valid Email"
	if (Trim(strMail.value)=="")
	{
		return true;
	}
	var intLen=strMail.value.length
	var blnFlag=0
	if (strMail.value.charAt(0)=="@" || strMail.value.charAt(0)==".")
	{
		alert(strMessage)
		strMail.select()
		strMail.focus()
		return false
	}
	if (strMail.value.charAt(intLen-1)=="@" || strMail.value.charAt(intLen-1)==".")
	{
		alert(strMessage)
		strMail.select()
		strMail.focus()
		return false
	}
	for (var i=0;i<intLen;i++)
	{
		if (strMail.value.charAt(i)=="@")
		{
			blnFlag=blnFlag+1
		}
	}
	if (blnFlag>=0 && blnFlag<1 || blnFlag>1)
	{
		alert(strMessage)
		strMail.select()
		strMail.focus()
		return false
	}
	strSplit=(strMail.value).split("@")
	intSptLen=strSplit[1].length
	var intCnt=0
	for(var j=0;j<intSptLen;j++)
	{
		if (strSplit[1].charAt(j)==".")
		{
			intCnt=intCnt+1
		}
	}
	if (intCnt<=0)
	{
		alert(strMessage)
		strMail.select()
		strMail.focus()
		return false
	}
	return true
}
*/
function CheckEmail(strMail)
 {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(strMail.value))
	{
	return (true)
}
	alert("Invalid E-mail Address! Please re-enter.")
	strMail.focus();
	strMail.select();
	return (false)
}

/**************************************************************
function : CheckTaxID(p1,strMessage)
usage    : To check TaxID of the form ##-#######
inputs   : string containing taxid
output   : returns true if taxid is valid; otherwise returns false
e.g      : 12-3456789 is valid tax id
**************************************************************/
function CheckTaxID(p1,strMessage)
{
	var strMessage;
	if (p1.value=="")
	{
		return true;
	}
	if(p1.value.length!=10)
	{
		alert(strMessage);
		p1.select();
		p1.focus();		
		return false;
	}
	if(!IsDigit(p1.value.substring(0,2)))
	{
		alert(strMessage);
		p1.select();
		p1.focus();		
		return false;
	}
	if(p1.value.substring(2,3)!="-")
	{
		alert(strMessage);
		p1.select();
		p1.focus();		
		return false;
	}
	if(!IsDigit(p1.value.substring(3)))
	{
		alert(strMessage);
		p1.select();
		p1.focus();		
		return false;
	}
return true;
}

/**************************************************************
function : CheckSSN(p1,strMessage)
usage    : To check SSN number of the form ###-##-####
inputs   : string containing ssn number
output   : returns true if ssn number is valid; otherwise returns false
e.g      : 123-34-6789 is valid phone number
**************************************************************/
function CheckSSN(p1,strMessage)
{
	var strMessage;
	if (p1.value=="")
	{
		return true;
	}
	if(p1.value.length!=11)
	{
		alert(strMessage);
		p1.select();
		p1.focus();		
		return false;
	}
	if(!IsDigit(p1.value.substring(0,3)))
	{
		alert(strMessage);
		p1.select();
		p1.focus();		
		return false;
	}
	if(p1.value.substring(3,4)!="-")
	{
		alert(strMessage);
		p1.select();
		p1.focus();		
		return false;
	}
	if(!IsDigit(p1.value.substring(4,6)))
	{
		alert(strMessage);
		p1.select();
		p1.focus();		
		return false;
	}
	if(p1.value.substring(6,7)!="-")
	{
		alert(strMessage);
		p1.select();
		p1.focus();		
		return false;
	}
	if(!IsDigit(p1.value.substring(7)))
	{
		alert(strMessage);
		p1.select();
		p1.focus();		
		return false;
	}
return true;
}

///this function is used to check if value in textbox is empty
function CheckBlank(p,strMessage)
{
	if(Trim(p.value)=="")
	{
		alert(strMessage);
		p.select();
		p.focus();
		return false;
	}
	return true;
}

//this function is used to check new password and confirm new password
function Compare_Pass(p1,p2,strMessage)
{
	if(p1.value != p2.value)
	{
		alert(strMessage);
		p2.select();
		p2.value="";
		p2.focus();
		return false;
	}
	return true;
}

///Date Validation function
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

// Check that a US zip code is valid
function isValidZipcode(zipcode) {
   zipcode = removeSpaces(zipcode);
   if (!(zipcode.length == 5 || zipcode.length == 9 || zipcode.length == 10)) return false;
   if ((zipcode.length == 5 || zipcode.length == 9) && !isNumeric(zipcode)) return false;
   if (zipcode.length == 10 && zipcode.search && zipcode.search(/^\d{5}-\d{4}$/) == -1) return false;
   return true;
}



// Remove all spaces from a string
function removeSpaces(string) {
   var newString = '';
   for (var i = 0; i < string.length; i++) {
      if (string.charAt(i) != ' ') newString += string.charAt(i);
   }
   return newString;
}


//Checking for the special character in the string
function SpecialChar(str)
{
  var chk1 = "!@#$%^*()-+=|\~`{}[]:'<>?/";
  for(var i=0;i<str.length;i++)
   {
	var ch=str.charAt(i);
	var rtn1=chk1.indexOf(ch);
	if (rtn1 != -1)
		{
			alert("Please Enter Valid Entry");
			return false;
		}

   }
   return true;
}
function SpecialChar1(str)
{
  var chk1 = "!@$%^+=|\~`{}[]:<>?";
  for(var i=0;i<str.length;i++)
   {
	var ch=str.charAt(i);
	var rtn1=chk1.indexOf(ch);
	if (rtn1 != -1)
		{
			alert("Please Enter Valid Entry.\nYou can not enter character from set given below.\n! @ $ % ^ + = | \ ~ ` { } [ ] : < > ?");
			return false;
		}

   }
   return true;
}

function SpecialChar2(str)
{
  var chk1 = "%?";
  for(var i=0;i<str.length;i++)
   {
	var ch=str.charAt(i);
	var rtn1=chk1.indexOf(ch);
	if (rtn1 != -1)
		{
			alert("Please Enter Valid Entry. Do not use '%' or '?'.");
			return false;
		}

   }
   return true;
}

function isAlphanumeric (s)

{   var i;

    if (isEmpty(s)) 
       if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-alphanumeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number or letter.
        var c = s.charAt(i);

        if (! (isLetter(c) || IsDigit(c) ) )
        return false;
    }

    // All characters are numbers.
    return true;
}
function isNumInStr(s)

{   var i;

    if (isEmpty(s)) 
       if (isNumDigit.arguments.length == 1) return defaultEmptyOK;
       else return (isNumDigit.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-alphanumeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (IsDigit(c)) 
        return false;
    }

    // All characters are numbers. 
    return true;
}

function isAlphabatic (s)

{   var i;

    if (isEmpty(s)) 
       if (isAlphabatic.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphabatic.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-alphanumeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number or letter.
        var c = s.charAt(i);

        if (! (isLetter(c)) )
        return false;
    }

    // All characters are numbers or letters.
    return true;
}


// Returns true if character c is an English letter 
// (A .. Z, a..z).
//
// This could be tricky due to different character
// sets and orderings for various languages and platforms.

function isLetter (c)
{   
return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

// Check whether string s is empty.

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

//Checking for the special character in the string
function SpecialCharEmail(str)
{
  var chk1 = "!#$%^*()+=|\~`{} []:'<>?/";
  
  for(var i=0;i<str.length;i++)
   {
	var ch=str.charAt(i);
	var rtn1=chk1.indexOf(ch);
	if (rtn1 != -1)
		{
			alert("Please Enter Valid Email");
			return false;
		}

   }
   return true;
}

///////////////////////////////////
/////URL Validation
////////////////////////////////////
function ValidUrl(str)
{
	re = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	if (!re.test(str)) 
     {
           alert ("Please Enter Proper Site URL");          
           return false;
       }
      return true; 
      }
//////////////
///Validation of file  either image(*.gif of *.jpg) file or not
//////////////// 

function ValidImage(x)
{		
				var y=x.value;					
				var imglen=y.length;
				var imgdotpos=y.lastIndexOf(".");
				var imgext=y.substring(imgdotpos+1,imglen);
								
				if((imgext!="jpg")&& (imgext!="gif") && (imgext!="JPG")&& (imgext!="GIF"))
				{
					alert("Company Logo Image Must Be Of Type .jpg Or .gif")
					x.select();
					x.focus();
					return false;
				}
	}	
	
	
	//////////////////////////////////////////////////////////////
//<P>The <I>parseQueryString</I> function can be passed any query string (for 
//example, an arbitrary URL from another script), or you can pass 
//<I>location.search</I> to grab the query string from the browser DOM. It also 
//removes leading and trailing single quotes from values if found and converts 
//integer values to actual JavaScript integers instead of strings.</P>
	/////////////////////////////////////////////////////////////
function parseQueryString(queryString)
	 {
  var queryObject = new Object();
  queryString = queryString.replace(/^.*\?(.+)$/,'$1');

  while ((pair = queryString.match(/([^=]+)=\'?([^\&\']*)\'?\&?/)) && pair[0].length)
   {
    queryString = queryString.substring( pair[0].length );

    if (/^\-?\d+$/.test(pair[2])) pair[2] = parseInt(pair[2]);
    queryObject[pair[1]] = pair[2];
  }

  return queryObject;
}


////////////url validation
 

function IsValidURL1(urlString)

{

            var urlReg = "^(file|http|https|ftp):\\/\\/([a-zA-Z0-9]*\\.)?[a-zA-Z0-9-]*\\.[a-zA-Z0-9]*(\\.[a-zA-Z0-9]*)?\\/?$";

            var regex = new RegExp(urlReg);

            var okURL = regex.test(urlString);

            return okURL;

}


///////////Functions For Check All Facility Start

	function CheckAll(x,y)
	{
		var i;
		if(typeof(x)=="undefined")
			return;
		if(typeof(y)=="undefined")
			return;
		if(typeof(y.length)=="undefined")
		{
			y.checked=x.checked;
			return;
		}
		for(i=0;i<y.length;i++)
		{
			y[i].checked=x.checked;
		}
		
	}
	
	
	 

function GetMIMeType(cExt)
{

var cExt = new String(cExt);
cExt = cExt.toUpperCase(); 

if(cExt == "TXT" || cExt == "TEXT" || cExt == "JS" )
return "text/plain";
else if(cExt == "CSV" )
return "text/comma-separated-values"
else if(cExt == "HTM" || cExt == "HTML" || cExt == "ASP" || cExt == "CGI" || cExt == "PL" )
return "text/html";
else if(cExt == "PDF" )
return "application/pdf";
else if(cExt == "RTF" )
return "text/richtext";
else if(cExt == "XML" )
return "text/xml";
else if(cExt == "WPD" )
return "application/wordperfect";
else if(cExt == "WRI" )
return "application/mswrite";
else if(cExt == "XLS" || cExt == "XLS3" || cExt == "XLS4" || cExt == "XLS5" || cExt == "XLW" )
return "application/msexcel";
else if (cExt == "DOC" )
return "application/msword";
else if (cExt == "PPT" || cExt == "PPS" )
return "application/mspowerpoint"; 
else if (cExt == "WML" )
return "text/vnd.wap.wml";
else if (cExt == "WMLS" )
return "text/vnd.wap.wmlscript";
else if (cExt == "WBMP" )
return "image/vnd.wap.wbmp";
else if (cExt == "WMLC" )
return "application/vnd.wap.wmlc";
else if (cExt == "WMLSC" )
return "application/vnd.wap.wmlscriptc";
else if (cExt == "GIF" )
return "image/gif";
else if (cExt == "JPG" || cExt == "JPE" || cExt == "JPEG" )
return "image/jpeg";
else if (cExt == "PNG" )
return "image/x-png";
else if (cExt == "BMP" )
return "image/bmp";
else if (cExt == "TIF" || cExt == "TIFF" )
return "image/tiff";
else if(cExt == "XWD" )
return "image/x-xwindowdump";
else if(cExt == "IEF" )
return "image/ief";
else if (cExt == "AI" || cExt == "EPS" || cExt == "PS" )
return "application/postscript";
else if (cExt == "AU" || cExt == "SND" )
return "audio/basic";
else if (cExt == "WAV" )
return "audio/wav";
else if (cExt == "RA" || cExt == "RM" || cExt == "RAM" )
return "audio/x-pn-realaudio";
else if (cExt == "MID" || cExt == "MIDI" )
return "audio/x-midi";
else if (cExt == "MP3" )
return "audio/mp3";
else if (cExt == "M3U" )
return "audio/m3u";
else if (cExt == "AVI" )
return "video/avi";
else if (cExt == "MPG" || cExt == "MPEG" || cCat == "MPE" )
return "video/mpeg";
else if (cExt == "QT" || cExt == "MOV" || cExt == "QTVR" )
return "video/quicktime";
else if(cExt == "MOVIE" )
return "video/x-sgi-movie";
else if (cExt == "SWA" )
return "application/x-director";
else if (cExt == "SWF" )
return "application/x-shockwave-flash";
else if (cExt == "COM" || cExt == "EXE" || cExt == "DLL" || cExt == "OCX" )
return "application/octet-stream";
else if (cExt == "PDB" )
return "chemical/x-pdb";
else if (cExt == "ZIP" )
return "application/x-zip-compressed";
else
return "";
}

////////////////////////
//Function for Removing the Html Tags
//////////////////////// 
 function noHtml(txt) 
{
    a = txt.indexOf('<');
    b = txt.indexOf('>');
    len = txt.length;
    c = txt.substring(0, a);
    if(b == -1) {
       b = a;
    }
    d = txt.substring((b + 1), len);
    txt = c + d;
    cont = txt.indexOf('<');
    if (cont != -1) {
      txt = noHtml(txt);
    }
   var fromString="&nbsp;";
    var toString="";    
    var txt1=replaceSubstring(txt,fromString , toString);
    return txt1;
 }
 ///////////////////////////////////
////////Replacing substring //////
//////////////////////////////////
function replaceSubstring(inputString, fromString, toString) 
{
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") 
{
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) 
{
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   }
 else 
{ 
// String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") 
{
         for (var i=0; i < midStrings.length; i++) 
{
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; 
}
            if (fromString.indexOf(tempMidString) == -1) 
{
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      }
 // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) 
{
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   }
 // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; 
// Send the updated string back to the user
} 
// Ends the "replaceSubstring" function

//New Function for Phone Number Dipen shah 09222005

function CheckPhoneNew(p1,str)
{
  var chk1 = "1234567890,-#";
  for(var i=0;i<p1.value.length;i++)
   {
	var ch=p1.value.charAt(i);
		if(ch==" ")
			return true;
	var rtn1=chk1.indexOf(ch);
	if (rtn1 == -1)
		{
			alert(str);
			p1.select();
			p1.focus();
			return false;
		}
   }
   return true;	
}
	