function nothing()
{
}

function isEmpty(fld)
{
if ( fld == null ) {
  alert('Error: invalid field name.');
} else {
if ((fld.type == 'text') || (fld.type=='textarea') ||  (fld.type=='password') || (fld.type=='hidden'))
 {
  var s1=trim(fld.value);
  return ((s1 == "") || (s1.length == 0));
 }
if (fld.type == 'select-one')
return (fld.selectedIndex == 0);
}
}

function isIpEmpty(s)
{
var v=eval('document.forms[0]["'+s+'"]');
if (v == null) return false;
if ((v.type == 'text') || (v.type=='textarea') || (v.type=='password'))
 {
  var s1=trim(v.value);
  return ((s1 == "") || (s1.length == 0));
 }
if (v.type == 'select-one')
return (v.selectedIndex == 0);
}


function trim(s)
{
var s1="";
var i=0;
while ((i < s.length) && (s.charAt(i)==' '))
i++;
s1 = s.substring(i, s.length);
i=s1.length-1;
while ((i>0) && (s1.charAt(i)==' '))
i--;
return(s1.substring(0,i+1));
}


function filterIL(str)
{
if(str.match(/\d{10}/) != null)
 {
  var m = str.match(/(\d{3})(\d{3})(\d{4})/)
  return m[1]+"-"+m[2]+"-"+m[3];
 }
else
 {
  return str;
 }
}


function ReqAlert(field)
{
if (field.type == 'select-one')
 {
  alert("Required selection is not selected");
  field.focus();
 }
else
  if (field.type == 'hidden')
   {
    alert("Required selection for the "+ field.name + " is not selected.  Click the selection triangle next to the field to select the "+field.name + ".");
   }
  else
  {
   alert("Required Field is missing.");
   field.focus();
  }
}


function remove(field)
{
  s=field.value
  var x =''
  var i = 0
  var tt = ''
  var limits=s.length;
  for(i=0;i<limits;i++)
  {
    if(s.charAt(i)=="("||s.charAt(i)==")"||s.charAt(i)==' '||s.charAt(i)=="-")
      x=''
    else
      x=s.charAt(i)
      tt=tt+x
  }
  return (tt)
}


function LengthAlert(field)
{
  if (field.name=='contact_phone')
    alert("Contact Phone must be atleast 10 digits");
  else
    if (field.name == 'zip')
      alert("Zip must be atleast 5 digits");
  else
    if((field.name=='order_number_0')|| (field.name=='order_number_1')|| (field.name=='order_number_2'))
    {
      if (document.forms[0].name=="_OrderOPI" || document.forms[0].name=="_OrderOEB")
      {
        if(document.forms[0].sap_ck.checked)
        {
          if (  ( (remove(field).length < 6) ||( remove(field).length > 8) )&&( remove(field).length != 0)  )
            alert("SAP Order Number must be 6,7 or 8 digits");
        }
        else
          if((remove(field).length != 11)&&( remove(field).length != 0))
            alert("DOSS Order Number must be 11digits");
      }
      else
        if (document.forms[0].name=="_OrderOEB" && !document.forms[0].sap_ck.checked)
          alert("Order Number must be 11 digits");
    }
    field.focus();
}


function fieldlength(field)
{
  if((field.name=='order_number_0')|| (field.name=='order_number_1')|| (field.name=='order_number_2'))
  {
    if(document.forms[0].name=="_OrderOPI" || document.forms[0].name=="_OrderOEB")
    {
      if( document.forms[0].sap_ck.checked &&  (( (remove(field).length < 6) || (remove(field).length > 8) )&&( remove(field).length != 0)))
        return false
      if( ((remove(field).length != 11)&&( remove(field).length != 0) && !document.forms[0].sap_ck.checked))
        return false
    }
    return true
  }
  else
    if ((field.name == 'contact_phone') && ( remove(field).length < 10))
      return false
    else
      if ((field.name == 'zip') && (remove(field).length < 5))
        return false
      else
        return true
}

function isDigit (c)
{
return ((c >= "0") && (c <= "9"))
}

function isInteger(s)
{
var i = 0;
if (s==null) return false;
s=trim(s);
for (i = 0; i < s.length; i++){
  if (i == 0 && s.charAt(i) == "-"){
	 continue;
  }
  if (!isDigit(s.charAt(i))) return false;
}
return true;
}


function NumAlert(field)
{
  alert("Field must be numeric.");
  field.focus();
}


function isDgt(c)
{
  if (c =="0" || c =="1" || c =="2" || c =="3" || c =="4" || c =="5" || c =="6" || c =="7" || c =="8" || c =="9") return true
  return false
//  return ((c >= "0") && (c <= "9"))
}


function isIntgr(s)
{
  x = remove(s)
  var i = 0;
  var extra='';
  var ext='';
  if((s.name=='order_number_0')|| (s.name=='order_number_1')|| (s.name=='order_number_2'))
  {
    if ((s.value==null) || (s.value==''))
    return true;
  }
  else
  if (s.value==null) return false;
    s=trim(s.value);
  if ((x.length >10)&&(s.name=='contact_phone'))
    last = 10
  else
    last = x.length
    for (i = 0; i < last; i++)
  if (!isDgt(x.charAt(i))) return false;
  if((s.name=='contact_phone') || (s.name == 'phone_ae') || (s.name == 'phone'))
  {
    for(var j=10;j<=x.length;j++)
    {
      if(x.charAt(j)=='e'||x.charAt(j)=='x'||x.charAt(j)=='t'||x.charAt(j)==' '||x.charAt(j)=='-')
        y=''
      else
        y=x.charAt(j)
        extra = extra+y
    }
 //ext=" x-"+x.substring(10,x.length)
    if (extra !='') ext=" x-"+extra
      s.value = "("+x.substring(0,3)+") "+x.substring(3,6)+"-"+x.substring(6,10)+ext;
      return true;
  }
  else
    if (s.name=='zip')
    {
      s.value = x.substring(0,5)+x.substring(5,x.length)
      return true;
    }
  else
    if((s.name=='order_number_0')|| (s.name=='order_number_1')|| (s.name=='order_number_2'))
    {
      if((x.value !='')||(x!=null))
      {
        if(document.forms[0].name=="_OrderOEB") s.value=x.substring(0,9)+"-"+x.substring(9,11)
        if(document.forms[0].name=="_OrderOPI" || document.forms[0].name=="_OrderOEB")
        {
          if(document.forms[0].sap_ck.checked)
            s.value=x.substring(0,x.length)
          else
            s.value=x.substring(0,9)+"-"+x.substring(9,11)
        }
        return true;
      }
    }
  else
    return true;
}


function filterNum(str)
{
  re = /^\$|,/g;
// remove "$" and ","
  return str.replace(re, "");
}

function isNumber(s)
{
  var i = 0;
  var decimal=false;
  var negative=false;
  if (s==null) return false;
  s=trim(s);
  for (i = 0; i < s.length; i++)
  {
    var c = s.charAt(i);
    if ((c == '-') && (i == 0))
      negative = true;
    else
    if ((c == '.') && !decimal)
      decimal = true;
    else
      if (!isDigit(c)) return false;
  }
  return true;
}

function isIpNumber(s)
{
  var v=eval('document.forms[0].'+s);
  if (v == null) return true;
  return isNumber(v.value);
}


function filterOrderNumber(str)
{
if(str.match(/\d{11}/) != null)
 {
  var m = str.match(/(\d{9})(\d{2})/)
  return m[1]+"-"+m[2];
 }
else
 {
  return str;
 }
}

function MakeArray(n)



{



for (var i = 1; i <= n; i++)



this[i] = 0;



return this



}











var DaysInMonth = new Array(12);

DaysInMonth[1] = 31;



DaysInMonth[2] = 29;   // must programmatically check this



DaysInMonth[3] = 31;



DaysInMonth[4] = 30;



DaysInMonth[5] = 31;



DaysInMonth[6] = 30;



DaysInMonth[7] = 31;



DaysInMonth[8] = 31;



DaysInMonth[9] = 30;



DaysInMonth[10] = 31;



DaysInMonth[11] = 30;



DaysInMonth[12] = 31;











function FebDays(year)



{



return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );



}











function isDate(s, fourDigitYear)



{



var month="";



var day="";



var year="";



if (s==null) return false;



var s1=trim(s);



if ((s1 == "") || (s1.length == 0)) return true;



var i=s.indexOf('/');



if (i == -1) return false;



month=s.substr(0,i);



s1=s.substr(i+1,s.length);



i=s1.indexOf('/');



if (i == -1) return false;



day=s1.substr(0,i);



year=s1.substr(i+1,s1.length);
if (fourDigitYear && year.length != 4) return false;



if (month.substr(0,1) == '0') month=month.substr(1,2);



if (day.substr(0,1) == '0') day=day.substr(1,2);



if (!isInteger(month)) return false;



if (!isInteger(year)) return false;



if (!isInteger(day)) return false;



var intYear = parseInt(year,10);



var intMonth = parseInt(month,10);



var intDay = parseInt(day,10);



if (intYear < 100) intYear = intYear + 1900;



if ((intYear < 1900) || (intYear > 2100)) return false;



if ((intMonth < 1) || (intMonth > 12)) return false;



if ((intDay < 1) || (intDay > DaysInMonth[intMonth])) return false;



if ((intMonth == 2) && (intDay > FebDays(intYear))) return false;



return true;



}











function isIpDate(s)



{



var v=eval('document.forms[0].'+s);



if (v == null) return true;



return isDate(v.value);



}











function DateAlert(field)



{



  alert("Field must be a valid date (MM/DD/YYYY).");



  field.focus();



}







function filterDate(str)



{



  re = /-/g;



  return str.replace(re, "/");



}








function isCurrency(s)
{
  var i = 0;
  var decimal=false;
  var dollar=false;
  var digits=0;
  if (s==null) return true;
  var s=trim(s);
  for (i = s.length-1; i >=0; i--)
  {
    var c = s.charAt(i);
    if ((c == '.') && !decimal)
    {
      decimal = true;
      if(digits>2)
        return false;
        digits = 0;
    }
    else if ((c == ',') && (digits==3))
      {
        digits = 0;
        decimal = true;
      }
    else if ((c == '$') && (i==0))
      dollar = true;
    else if (isDigit(c))
      digits++;
    else
      return false;
  }
  return true;
}


function isIpCurrency(s)
{
  var v=eval('document.forms[0].'+s);
  if (v == null) return true;
  return isCurrency(v.value);
}



function isNotPhone(fld)
{
  alert("Phone number must be 10 digits, you can add an extenstion by including an \'x\'. \n Example:  555-123-4567 x102");
  fld.focus();
}


function isPhone(s)
//Check for a phone number, plus let through for the x in extension.
{
  var i = 0;
//index for counting
  var n = 0;
//number count to ensure users put in area code and number
  var y = 0;
//Tell the program to stop counting when x or X is met

  if(s == null)
  {
    return false;
  //null send back empty
  }
  s = trim(s);
  for(i = 0; i < s.length; i++)	//count up char by char
  {
    if(!isDigit(s.charAt(i)))
    {
      if(s.charAt(i) == ' ' || s.charAt(i) == '-' || s.charAt(i) == '(' || s.charAt(i) == ')')
      {
        n--;
      }
      else if((s.charAt(i)!='x' && s.charAt(i)!='X')|| n < 10)
   //is it an extension, and if so, do they have enough number already?
      {
        return false;
      }
      else
      {
        y=1;
      }
    }
    if(y==0)
    {
      n++;
  //count that number
    }
  }
  if(n >= 10)
  {
    return true;
  }
  else
  {
    return false;
  }
}

