

function validateDollar( fld , txt, blankTxt) 
{ 
   var temp_value = fld.value; 

   if (temp_value == "" && blankTxt != "") 
   { 
    fld.style.backgroundColor='#ffe04f';
     alert(blankTxt); 
     return false; 
   } 
   var Chars = "0123456789."; 
   for (var i = 0; i < temp_value.length; i++) 
   { 
       if (Chars.indexOf(temp_value.charAt(i)) == -1) 
       { 
          fld.style.backgroundColor='#ffe04f';
           alert(txt); 
          fld.value = '';
           return false; 
       } 
   } 
   fld.style.backgroundColor='WHITE';
	return true;
} 

function validatePhone( fld , txt, blankTxt) 
{ 
   var temp_value = fld.value; 

   if (temp_value == "" && blankTxt != "") 
   { 
     fld.style.backgroundColor='#ffe04f';
     alert(blankTxt); 
     return false; 
   } 
   var Chars = "0123456789-"; 
   for (var i = 0; i < temp_value.length; i++) 
   { 
       if (Chars.indexOf(temp_value.charAt(i)) == -1) 
       { 
          fld.style.backgroundColor='#ffe04f';
           alert(txt); 
          fld.value = '';
           return false; 
       } 
   } 
   fld.style.backgroundColor='WHITE';
	return true;
} 

function validateNumber( fld , txt, blankTxt) 
{ 
   var temp_value = fld.value; 
	
   if (temp_value == "" && blankTxt != "") 
   {
      fld.style.backgroundColor='#ffe04f';
     alert(blankTxt); 
     return false; 
   }
   else if(temp_value == "" && blankTxt == "")
   {
    fld.value = '';
    fld.style.backgroundColor='WHITE';
    return true;
   }
   var Chars = "0123456789"; 
   for (var i = 0; i < temp_value.length; i++) 
   { 
       if (Chars.indexOf(temp_value.charAt(i)) == -1) 
       { 
          fld.style.backgroundColor='#ffe04f';
           alert(txt);
	   fld.value = ""; 
          
           return false; 
       } 
   } 
   fld.style.backgroundColor='WHITE';
	return true;
} 

function validateNumberLimit( fld , txt, blankTxt, limit) 
{ 
   var temp_value = fld.value; 
	
   if (temp_value == "" && blankTxt != "") 
   {
      fld.style.backgroundColor='#ffe04f';
     alert(blankTxt); 
     return false; 
   }
   else if(temp_value == "" && blankTxt == "")
   {
    fld.value = '';
    fld.style.backgroundColor='WHITE';
    return true;
   }
   else if(temp_value > limit)
   {
    
    fld.style.backgroundColor='#ffe04f';
     alert(txt); 
     return false; 
   }
   var Chars = "0123456789"; 
   for (var i = 0; i < temp_value.length; i++) 
   { 
       if (Chars.indexOf(temp_value.charAt(i)) == -1) 
       { 
          fld.style.backgroundColor='#ffe04f';
           alert(txt);
	   fld.value = ""; 
          
           return false; 
       } 
   } 
   fld.style.backgroundColor='WHITE';
	return true;
} 


function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + num + '.' + cents);
}



function textCounter(field, maxlimit)
{
  clear();
  tmpStr = field.value;
  tmpStr= replaceChars(tmpStr);

  if (tmpStr.length > maxlimit) // if too long...trim it!
  {
    tmpStr = tmpStr.substring(0, maxlimit);
    field.style.backgroundColor='#ffe04f';
    alert("This field has a max character limit of "+maxlimit);
  }
  else
  {
    field.style.backgroundColor='WHITE';
  }
  field.value=tmpStr;
}

function textCounter(field, maxlimit, displayName)
{
  tmpStr = field.value;
  tmpStr= replaceChars(tmpStr);

  if (tmpStr.length > maxlimit) // if too long...trim it!
  {
    tmpStr = tmpStr.substring(0, maxlimit);
    field.style.backgroundColor='#ffe04f';
    alert("The "+displayName+" field has a max character limit of "+maxlimit);
  }
  else
  {
    field.style.backgroundColor='WHITE';
  }
  field.value=tmpStr;
}

function newline(field)
{
  textCounter(field, 2000);
  tmpStr = field.value;
  
  if (tmpStr.length == 40)
  {
    field.value = tmpStr + "\n";
  }
}

function replaceChars(entry)
{
  out = "&"; // replace this
  add = " and "; // with this
  temp = "" + entry; // temporary holder

  while (temp.indexOf(out)>-1)
  {
    pos= temp.indexOf(out);
    temp = "" + (temp.substring(0, pos) + add +
    temp.substring((pos + out.length), temp.length));
  }
  
  out = "'"; // replace this
  add = ""; // with this
  

  while (temp.indexOf(out)>-1)
  {
    pos= temp.indexOf(out);
    temp = "" + (temp.substring(0, pos) + add +
    temp.substring((pos + out.length), temp.length));
  }
  return temp;
}


function trim(strText) { 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
}

