  function TrimAllSpaces(instr)
{
   var tempstr = new String(instr)
   var tempstr2 = new String()
   var i
   for (i = 0; i < tempstr.length; i ++)
   {
      if (tempstr.charAt(i) != " ")
         tempstr2 += tempstr.charAt(i)
   }
   return tempstr2
}

function areAllDigits(str){
   var temp = new String(str)
   var i
   for (i = 0; i < temp.length; i ++)
   {
      if (temp.charAt(i) < "0" || temp.charAt(i) > "9")
         return false
   }
   return true
}


function isValidphone(str){
   var temp = TrimAllSpaces(str)
  if (areAllDigits(temp)){
  if (temp.length > 5 )
  return true
  
  }
 
  return false
  }


function isValidEmail(email){
	format = /^\w+([\._]?w+)*@\w+([\._]?\w+)*$/
	if(format.test(email)){
		return true
	}else{
		return false
	}
}

  function CheckForm(obj)
{	
	var msg = new String()
	var valid = true
	var focus = 0
	if(obj.elements["tName"].value.length == 0){
		msg = "Please enter Contact Name!"
		focus = 1
	}
else if(!isValidphone(obj.elements["Phone"].value)){
		msg = msg + "The phone number must be greater than 6 digits!"
		focus = 2
	}
	
	else if (!isValidEmail(obj.elements["Email"].value)){ 
		       msg = "Invalide email address!"
		       focus = 6
	}
else if(obj.elements["Manufacturer"].value.length == 0){
		msg = "Please enter Itme Name!"
		focus = 1
	}
	else if(obj.elements["Serial"].value.length == 0){
		msg = "Please enter Itme Number!"
		focus = 1
	}
		
	else{
		obj.elements[focus].focus()
	}
	
	if(msg.length > 0)
	{
		window.alert(msg)
		return false
	}
		
		
	return true	
	
}



