function handleKeyPress(e)
{
  var key=e.keyCode || e.which;
  if (key==13){
    register();
  }
}

function isSTCNumber(num)
{
  var strNumber = new String();

  strNumber = num;

  if(num.length == 12 && strNumber.substr(04) == "9665")
  {
	 return true;
	}

  else if(num.length == 10 && strNumber.substr(0,2) == "05")
  {
    return true;
  }
  else if(num.length == 9 && strNumber.substr(0,1) == "5")
  {
    return true;
  }

  return false;
}



function validateRegister()
{


    var msisdn = document.frmLogin.MSISDN;


    if (!IsEmpty(msisdn.value))
    {
      if(lang == 1)
      {
        alert('please enter the mobile number');
      }
      else
      {
        alert('الرجاء ادخال رقم الجوال');
      }
        msisdn.focus();
        return false;

    }

if (!IsIntegerNumber(msisdn.value))
    {
      if(lang == 1)
      {
        alert('please enter numbers only');
      }
      else
      {
        alert('الرجاء ادخال ارقام فقط');
      }
        msisdn.focus();
        return false;

    }

if (msisdn.value.length >12 || msisdn.value.length <9)
    {
      if(lang == 1)
      {
        alert('please enter a valid mobile number');
      }
      else
      {
        alert('الرجاء ادخال رقم جوال صحيح');
      }
        msisdn.focus();
        return false;

    }

    if (!isSTCNumber(msisdn.value))
    {
      if(lang == 1)
      {
        alert('please enter a valid mobile number');
      }
      else
      {
        alert('الرجاء ادخال رقم جوال صحيح');
      }
        msisdn.focus();
        return false;

    }



    return true;
}

function validateLogin()
{

var msisdn = document.frmLogin.MSISDN;
var password = document.frmLogin.password;

    if (!IsEmpty(msisdn.value))
    {
      if(lang == 1)
      {
        alert('please enter the mobile number');
      }
      else
      {
        alert('الرجاء ادخال رقم الجوال');
      }
        msisdn.focus();
        return false;

    }

if (!IsIntegerNumber(msisdn.value))
    {
      if(lang == 1)
      {
        alert('please enter numbers only');
      }
      else
      {
        alert('الرجاء ادخال ارقام فقط');
      }
        msisdn.focus();
        return false;

    }

if (msisdn.value.length >12 || msisdn.value.length <9)
    {
      if(lang == 1)
      {
        alert('please enter a valid mobile number');
      }
      else
      {
        alert('الرجاء ادخال رقم جوال صحيح');
      }
        msisdn.focus();
        return false;

    }

    if (!isSTCNumber(msisdn.value))
    {
      if(lang == 1)
      {
        alert('please enter a valid mobile number');
      }
      else
      {
        alert('الرجاء ادخال رقم جوال صحيح');
      }
        msisdn.focus();
        return false;

    }


    if (!IsEmpty(password.value))
    {
      if(lang == 1)
      {
        alert('please enter the access code');
      }
      else
      {
        alert('الرجاء ادخال رمز المرور');
      }
        password.focus();
        return false;

    }

if (!IsIntegerNumber(password.value))
    {
      if(lang == 1)
      {
        alert('please enter numbers only');
      }
      else
      {
        alert('الرجاء ادخال ارقام فقط');
      }
        password.focus();
        return false;

    }

if (password.value.length != 6)
    {
      if(lang == 1)
      {
        alert('The access code must be 6 digits');
      }
      else
      {
        alert('رمز المرور يجب ان يتكون من 6 خانات');
      }
        msisdn.focus();
        return false;

    }




    return true;
}

function register()
{

  if(validateLogin())
  {

    document.frmLogin.action = "../jsp/stclogin";
    document.frmLogin.submit();
  }

}

function newUser()
{
  if(validateRegister())
  {
    document.frmLogin.action = "../jsp/stcnewuser";
    document.frmLogin.submit();
  }

}

function forgotPassword()
{
  if(validateRegister())
  {
    document.frmLogin.action = "../jsp/stcpassword";
    document.frmLogin.submit();
  }

}



function validateMainLogin(Form)
{


var msisdn = Form.userName;
var password = Form.password;

    if (!IsEmpty(msisdn.value))
    {
      if(lang == 1)
      {
        alert('please enter your mobile number');
      }
      else
      {
        alert('الرجاء ادخال رقم الجوال');
      }
        msisdn.focus();
        return false;

    }

if (!IsIntegerNumber(msisdn.value))
    {
      if(lang == 1)
      {
        alert('please enter numbers only');
      }
      else
      {
        alert('الرجاء ادخال ارقام فقط');
      }
        msisdn.focus();
        return false;

    }

if (msisdn.value.length !=12)
    {
      if(lang == 1)
      {
        alert('The mobile number must be 12 digits.');
      }
      else
      {
        alert('رقم الجوال يجب ان يكون من 12 خانات');
      }
        msisdn.focus();
        return false;

    }

    /*if (!isSTCNumber(msisdn.value))
    {
      if(lang == 1)
      {
        alert('please enter a valid mobile number');
      }
      else
      {
        alert('الرجاء ادخال رقم جوال صحيح');
      }
        msisdn.focus();
        return false;

    }*/


    if (!IsEmpty(password.value))
    {
      if(lang == 1)
      {
        alert('please enter your password');
      }
      else
      {
        alert('الرجاء ادخال رمز المرور');
      }
        password.focus();
        return false;

    }


  if(msisdn.value.length == 12 && msisdn.value.substr(0,3) == "966")
  {

  if(msisdn.value.substr(3,2) != "50" && msisdn.value.substr(3,2) != "51" 
  	  && msisdn.value.substr(3,2) != "52" && msisdn.value.substr(3,2) != "53" 
  	  && msisdn.value.substr(3,2) != "54" && msisdn.value.substr(3,2) != "55" 
  	  && msisdn.value.substr(3,2) != "56")
	{
	 if(lang == 1)
      {
        alert('please enter a valid mobile number');
      }
      else
      {
        alert('الرجاء ادخال رقم جوال صحيح');
      }
         msisdn.focus();
        return false;
	}
    
  }



if (!IsIntegerNumber(password.value))
    {
      if(lang == 1)
      {
        alert('Please make sure you enter the digits only');
      }
      else
      {
        alert('الرجاء التأكد من إدخال أرقام فقط');
      }
        password.focus();
        return false;

    }

if (password.value.length != 6)
    {
      if(lang == 1)
      {
        alert('The password must contain 6 digits.');
      }
      else
      {
        alert('رمز المرور يجب ان يكون من 6 خانات');
      }
        msisdn.focus();
        return false;

    }

    return true;
}

function loginForgotPassword(formName)
{

  Form = document.getElementById(formName);

   var msisdn = Form.userName;


    if (!IsEmpty(msisdn.value))
    {
      if(lang == 1)
      {
        alert('please enter the mobile number');
      }
      else
      {
        alert('الرجاء ادخال رقم الجوال');
      }
        msisdn.focus();
        return false;

    }

if (!IsIntegerNumber(msisdn.value))
    {
      if(lang == 1)
      {
        alert('please enter numbers only');
      }
      else
      {
        alert('الرجاء ادخال ارقام فقط');
      }
        msisdn.focus();
        return false;

    }

/*if (msisdn.value.length >12 || msisdn.value.length <9)
    {
      if(lang == 1)
      {
        alert('please enter a valid mobile number');
      }
      else
      {
        alert('الرجاء ادخال رقم جوال صحيح');
      }
        msisdn.focus();
        return false;

    }*/

    document.frmForgotPassword.action = "../forgotpassword";
    document.frmForgotPassword.userName.value = document.frmMainLogin.userName.value;
    document.frmForgotPassword.submit();


}



