function LTrim(str)
	{
		 for (var i=0; ((str.charAt(i)<=" ")&&(str.charAt(i)!="")); i++);
		 return str.substring(i,str.length);
	}
function RTrim(str) 
	{
	 for (var i=str.length-1; ((str.charAt(i)<=" ")&&(str.charAt(i)!="")); i--);
	 return str.substring(0,i+1);
	}
function Trim(str)
{
	 return LTrim(RTrim(str));
}


function  checkstatus(theForm) {
  if (Trim(theForm.trackno.value)=="")
  {
   alert("Please enter Tracking Number.");
    theForm.trackno.focus();
    return (false);
  }
  if (isNaN(theForm.trackno.value))
  {
  alert("Please enter only Numerical Value.");
  theForm.trackno.value="";
  theForm.trackno.focus()
  return(false)
  }
  
  if (Trim(theForm.imeino.value)=="")
  {
   alert("Please enter IMEI/ESN Number.");
    theForm.imeino.focus();
    return (false);
  }return (true);
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function isEmailAddr(email)
{
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function validate_billing(theForm)
{
  if (Trim(theForm.b_Name.value) == "")
  {
    alert("Please enter a value for the \"Name\" field.");
    theForm.b_Name.focus();
    return (false);
  }
  if (theForm.b_Name.value.length < 1)
  {
    alert("Please enter at least 1 characters in the \"Name\" field.");
    theForm.b_Name.focus();
    return (false);
  }

  if (theForm.b_Name.value.length > 40)
  {
    alert("Please enter at most 40 characters in the \"Name\" field.");
    theForm.b_Name.focus();
    return (false);
  }
  
   if (Trim(theForm.b_street.value) == "")
  {
    alert("Please enter a value for the \"Address\" field.");
    theForm.b_street.focus();
    return (false);
  }
   if (Trim(theForm.b_city.value) == "")
  {
    alert("Please enter a value for the \"City\" field.");
    theForm.b_city.focus();
    return (false);
  }
   if (Trim(theForm.b_state.value) == "")
  {
    alert("Please enter a value for the \"State\" field.");
    theForm.b_state.focus();
    return (false);
  }
  if (Trim(theForm.b_zip.value) == "")
  {
    alert("Please enter a value for the \"Zip\" field.");
    theForm.b_zip.focus();
    return (false);
  }
   if (theForm.b_country.selectedIndex == 0)
  {
    alert("The first \"Country\" option is not a valid selection.  Please choose Your Country Name.");
    theForm.b_country.focus();
    return (false);
  }
   if (theForm.b_country.selectedIndex == 0)
  {
    alert("The first \"Country\" option is not a valid selection.  Please choose Your Country Name.");
    theForm.b_country.focus();
    return (false);
  } 
  if (Trim(theForm.email.value) == "")
  {
    alert("Please enter a value for the \"email\" field.");
    theForm.email.focus();
    return (false);
  }
   if (!isEmailAddr(theForm.email.value))
  {
    alert("Please enter a valid email address in the form: yourname@yourdomain.com");
    theForm.email.focus();
    return (false);
  }  
  
  if (Trim(theForm.MobileNumber.value) == "")
  {
    alert("Please enter a value for the Contact Number field.");
    theForm.MobileNumber.focus();
    return (false);
  }
  
  if (isNaN(theForm.MobileNumber.value))
  {
  alert("Please enter only Numerical Value.");
  theForm.MobileNumber.value="";
  theForm.MobileNumber.focus()
  return(false)
  }
  
  if (theForm.MobileNumber.value.length < 10)
  {
    alert("Please enter at least 10 characters in the Contact Number field.");
    theForm.MobileNumber.focus();
    return (false);
  }  

  if (theForm.Model.selectedIndex == 0)
  {
    alert("The first \"Select Your Phone\" option is not a valid selection.  Please choose one of the other options.");
    theForm.Model.focus();
    return (false);
  }

  if (theForm.Network.selectedIndex == 0)
  {
    alert("The first Network option is not a valid selection.  Please choose one of the other options.");
    theForm.Network.focus();
    return (false);
  }
  
  if (Trim(theForm.IMEINumber.value) == "")
  {
    alert("Please enter a value for the \"IMEINumber\" field.");
    theForm.IMEINumber.focus();
    return (false);
  }
  
   if (theForm.IMEINumber.value.length < 15)
  {
    alert("Please enter at least 15 digits in the \"IMEINumber\" field.");
    theForm.IMEINumber.focus();
    return (false);
  }

 return (true);
}

