function make_uppercase(fieldnumber) {
 fieldnumber.value = fieldnumber.value.toUpperCase();
}


function make_lowercase(fieldnumber) {
 fieldnumber.value = fieldnumber.value.toLowerCase();
}

function checknum(fieldvalue) {
	  var isNum=true;
	   
	  for (j= 0; j<fieldvalue.length; j++) {
	  
	   if ((fieldvalue.substring(j,j+1) != "0") &&
	        (fieldvalue.substring(j,j+1) != "1") &&
			(fieldvalue.substring(j,j+1) != "2") &&
			(fieldvalue.substring(j,j+1) != "3") &&
			(fieldvalue.substring(j,j+1) != "4") &&
			(fieldvalue.substring(j,j+1) != "5") &&
			(fieldvalue.substring(j,j+1) != "6") &&
			(fieldvalue.substring(j,j+1) != "7") &&
			(fieldvalue.substring(j,j+1) != "8") &&
			(fieldvalue.substring(j,j+1) != "9")) {
			 isNum=false
			}
	      }
		  
	    return isNum;
	 }
	 
function checknum_slash(fieldvalue) {
	  var isNum=true;
	   
	  for (j= 0; j<fieldvalue.length; j++) {
	  
	   if ((fieldvalue.substring(j,j+1) != "/") &&
	        (fieldvalue.substring(j,j+1) != "0") &&
	        (fieldvalue.substring(j,j+1) != "1") &&
			(fieldvalue.substring(j,j+1) != "2") &&
			(fieldvalue.substring(j,j+1) != "3") &&
			(fieldvalue.substring(j,j+1) != "4") &&
			(fieldvalue.substring(j,j+1) != "5") &&
			(fieldvalue.substring(j,j+1) != "6") &&
			(fieldvalue.substring(j,j+1) != "7") &&
			(fieldvalue.substring(j,j+1) != "8") &&
			(fieldvalue.substring(j,j+1) != "9")) {
			 isNum=false
			}
	      }
		  
	    return isNum;
	 }
	 
function checkalpha(fieldvalue) {
	  var isAlpha=true;
	  for (j= 0; j<fieldvalue.length; j++) {
	   if ((fieldvalue.substring(j,j+1) != "A") &&
	        (fieldvalue.substring(j,j+1) != "B") &&
	        (fieldvalue.substring(j,j+1) != "C") &&
			(fieldvalue.substring(j,j+1) != "D") &&
			(fieldvalue.substring(j,j+1) != "E") &&
			(fieldvalue.substring(j,j+1) != "F") &&
			(fieldvalue.substring(j,j+1) != "G") &&
			(fieldvalue.substring(j,j+1) != "H") &&
			(fieldvalue.substring(j,j+1) != "I") &&
			(fieldvalue.substring(j,j+1) != "J") &&
			(fieldvalue.substring(j,j+1) != "K") &&
	        (fieldvalue.substring(j,j+1) != "L") &&
			(fieldvalue.substring(j,j+1) != "M") &&
			(fieldvalue.substring(j,j+1) != "N") &&
			(fieldvalue.substring(j,j+1) != "O") &&
			(fieldvalue.substring(j,j+1) != "P") &&
			(fieldvalue.substring(j,j+1) != "Q") &&
			(fieldvalue.substring(j,j+1) != "R") &&
			(fieldvalue.substring(j,j+1) != "S") &&
			(fieldvalue.substring(j,j+1) != "T") &&
	        (fieldvalue.substring(j,j+1) != "U") &&
			(fieldvalue.substring(j,j+1) != "V") &&
			(fieldvalue.substring(j,j+1) != "W") &&
			(fieldvalue.substring(j,j+1) != "X") &&
			(fieldvalue.substring(j,j+1) != "Y") &&
			(fieldvalue.substring(j,j+1) != "Z")) {
			 isAlpha=false
			}
	      }
	  return isAlpha;
	 }	 
	 
function checknum_hyphen(fieldvalue) {
	  var isNum=true;
	  for (j= 0; j<fieldvalue.length; j++) {
	   if ((fieldvalue.substring(j,j+1) != "-") &&
	        (fieldvalue.substring(j,j+1) != "0") &&
	        (fieldvalue.substring(j,j+1) != "1") &&
			(fieldvalue.substring(j,j+1) != "2") &&
			(fieldvalue.substring(j,j+1) != "3") &&
			(fieldvalue.substring(j,j+1) != "4") &&
			(fieldvalue.substring(j,j+1) != "5") &&
			(fieldvalue.substring(j,j+1) != "6") &&
			(fieldvalue.substring(j,j+1) != "7") &&
			(fieldvalue.substring(j,j+1) != "8") &&
			(fieldvalue.substring(j,j+1) != "9")) {
			 isNum=false
			}
	      }
	  return isNum;
	 }
	
function ValidatePhone(iPhone){
   var Input=iPhone;
   var isPhone=checknum_hyphen(Input);    // check for numbers and '-'
   if (!isPhone) {return isPhone};
   tmpArray=Input.split("-");  
        
   if (tmpArray.length==4) {            //format 1-215-491-3448
      var i,j,k,l;
      i=tmpArray[0]; 	        
      j=tmpArray[1];           
      k=tmpArray[2];          
      l=tmpArray[3];
	  if (i.length != 1 || j.length!=3 || k.length!=3 || l.length!=4) {    //too many or not enough numbers in each segment
	   isPhone=false;
	   return isPhone;
	  }
	  if (i!="1") {
	   isPhone=false;
	   return isPhone;
	  }
	}
	if (tmpArray.length==3) {            //format 215-491-3448
      var i,j,k
      j=tmpArray[0]; 	        
      k=tmpArray[1];           
      l=tmpArray[2];          
      if (j.length != 3 || k.length !=3 || l.length != 4) {    //too many or not enough numbers in each segment
	   isPhone=false;
	   return isPhone;
	  }
	}
	if (tmpArray.length<=2) {            //forgot area-code
      isPhone=false;
	   return isPhone;
	  }
	return isPhone;
}	
	
function ValidateDate(iDate){
   //var isdate=true;
   var days=[0,31,28,31,30,31,30,31,31,30,31,30,31];
   var Input=iDate;
   var isdate=checknum_slash(Input);    // check for numbers and '/'
   if (!isdate) {return isdate};
   tmpArray=Input.split("/");           // demo is for MM/DD/YYYY formatted entry 
   if (tmpArray.length==3) {            // but can be easily modified to validate DD/MM/YYYY
      var i,j,k,i1;
      i=tmpArray[0];
	  j=tmpArray[1];           // check length of each array for input error
      k=tmpArray[2];
	  if (i.length == 0 || j.length ==0 || k.length != 4) {    //too many or not enough numbers in each segment
	   isPhone=false;
	   return isPhone;
	  }
	  	  
      i=parseInt(tmpArray[0],10); 	        // month
      j=parseInt(tmpArray[1],10);           // day
      k=parseInt(tmpArray[2],10);          // year
      if (i<=0 || j<=0 || k<0) {
	   isdate=false;
	   return isdate;
	  }
      if (i>12) {
	    isdate=false;
	   return isdate;
	   }         // month is more than 12???
      if (k<2000 || k>2050) { 
	   isdate=false;
	   return isdate;              
	  }
	  if (k%400==0) {                   // you need 4-digits year to do proper leap year check
         days[2]=29;                    // Feb 29 every 400th years
      } else if (k%4!=0 || k%100==0) {
         days[2]=28;                    
      } else {
         days[2]=29;                    // Feb 29 every 4 years except century mark other than 400th
      }
      if (j>days[i]) {
	   isdate=false;
	   return isdate;}
    }
	if (tmpArray.length!=3) {
	  isdate=false;
	  return isdate;
	 }
   return isdate;
}

function emailCheck (emailStr) {
	 var ismail = true;
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address. 
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	alert("Email address seems incorrect (check @ and .'s)")
	ismail=false;
	return ismail
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    alert("The username doesn't seem to be valid.")
	ismail=false;
    return ismail
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Destination IP address is invalid!")
		return false
	    }
    }
    return ismail
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("The domain name doesn't seem to be valid.")
	ismail=false;
    return ismail
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   alert("The address must end in a three-letter domain, or two letter country.")
   ismail=false;
   return ismail
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
   alert(errStr)
   ismail=false;
   return ismail
}

// If we've gotten this far, everything's valid!
return ismail;
}

var space = " .,/<>?!'`;:@#$%^&*()_+=-~[]{}" + '"' + "\\\n\t";

function replace(term) {
	var charStrip;
	var newTerm="";
	var next;
	var isSpace = false;

	for (var i=0; i < term.length; i++){
		isSpace=false;
		next=term.substring(i,i+1);
		for (var j=0; j < space.length; j++) {
			charStrip=space.substring(j, j+1);
			if (charStrip == next) {
				isSpace=true;
			}
		}
		if (!isSpace) {newTerm = newTerm + next};
	}
	return newTerm;
}

function validateForm(form) {
	var fieldpn = form.pn;
	var fieldpnvalue = fieldpn.value;

	if (!fieldpnvalue) {
		alert("Please enter a Part Number with at least 3 characters or numbers");
		fieldpn.focus();
		return false;
	}

	if (fieldpnvalue) {
		fieldpn.value=replace(fieldpnvalue);
		if (fieldpn.value.length < 3) {
			alert("Please enter at least 3 characters or numbers");
			fieldpn.focus();
			return false;
		}
	}
	make_uppercase(fieldpn);
	MM_showHideLayers('plswait','','show');
}

function MM_showHideLayers() { //v3.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
		if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
		obj.visibility=v; 
	}
}
	 



