function noCopyMouse(e) 
{
    var isRight = (e.button) ? (e.button == 2) : (e.which == 3);
    if(isRight) 
    {
        //alert('You are prompted to type this twice for a reason!');
        return false;
    }
    return true;
}
function noCopyKey(e) 
{
    var forbiddenKeys = new Array('c','x','v');
    var keyCode = (e.keyCode) ? e.keyCode : e.which;
    var isCtrl;

    if(window.event)
        isCtrl = e.ctrlKey
    else
        isCtrl = (window.Event) ? ((e.modifiers & Event.CTRL_MASK) == Event.CTRL_MASK) : false;
    
    if(isCtrl) 
    {
        for(i = 0; i < forbiddenKeys.length; i++) 
        {
            if(forbiddenKeys[i] == String.fromCharCode(keyCode).toLowerCase()) 
            {
                //alert('You are prompted to type this twice for a reason!');
                return false;
            }
        }
    }
    return true;
}
function NumericDataOnly()
{
    var key = window.event.keyCode;
    if ( key > 47 && key < 58 )
        return;
    else 
        window.event.returnValue = null;
}
function CheckTermsNConditions(source,args)
{
    arrObj = document.getElementsByTagName("input");
    for(i=0; i<arrObj.length; i++)
    {
        if(arrObj[i].type == "checkbox") 
        {
            if(arrObj[i].id.indexOf("chkTermsNConditions") >=0)
            {
                if(arrObj[i].checked == true)
                    args.IsValid = true;
                else
                {
                    args.IsValid = false;
                    alert("Please read carefully Terms & Conditions before registering at www.DoorStepLibrary.com. We like you to join us at www.DoorStepLibrary.com");
                }
            }
        }
    }
}
function checkUseridNPersonalEmail(source,args)
{
    arrObj = document.getElementsByTagName("input");
    var userid = "";
    for(i=0; i<arrObj.length; i++)
    {
        if(arrObj[i].type == "text") 
        {
            if(arrObj[i].id.indexOf("txtPersonalEmail") >=0 || arrObj[i].id.indexOf("txtUserid") >=0)
            {
                if(arrObj[i].id.indexOf("txtUserid") >=0)
                    userid = arrObj[i].value;
                if(userid != "" && arrObj[i].id.indexOf("txtPersonalEmail") >=0 && arrObj[i].value != "")
                {
                    if(userid == arrObj[i].value)
                    {
                        args.IsValid = false;
                        alert("Personal email must be different from the userid.");
                    }
                    else
                        args.IsValid = true;
                }
            }
        }
    }
}
function PasswordMatch(txtUserId,txtConUserId,txtPassId,txtConPassId,hdnPassId)
{
    txtUserObj = document.getElementById(txtUserId);
    txtConUserObj = document.getElementById(txtConUserId);
    
    txtPassObj = document.getElementById(txtPassId);
    txtConPassObj = document.getElementById(txtConPassId);
    if(txtUserObj.value != "" && txtConUserObj.value != "" && txtPassObj.value != "" && txtConPassObj.value != "")
    {
        if(txtUserObj.value != txtConUserObj.value)
        {
            txtUserObj.value = "";
            txtConUserObj.value = "";
            alert("UserId and confirm UserId must be match! Enter UserId again.");
        }
        else
        {
            if(txtPassObj.value != txtConPassObj.value)
            {
                txtPassObj.value = "";
                txtConPassObj.value = "";
                alert("Password and confirm Password must be match! Enter password again.");
            }
            else if(txtPassObj.value == txtConPassObj.value)
            {
                SHA(txtPassId,hdnPassId);
            }
        }
    }
}
function CheckPassword(source,args)
{
    var txtPassObj = '';
    var txtConPassObj = '';
    var hdnObj = '';
    var InputList = document.getElementsByTagName("INPUT");
    for(var i=0; i<InputList.length; i++)
    {
        if(InputList[i].type == "password")
        {
            if(InputList[i].id.indexOf("txtPassword") > 0)
            {
                txtPassObj = document.getElementById(InputList[i].id);
                break;
            }
        }
    }
    for(var i=0; i<InputList.length; i++)
    {
        if(InputList[i].type == "password")
        {
            if(InputList[i].id.indexOf("txtConfrimPass") > 0)
            {
                txtConPassObj = document.getElementById(InputList[i].id);
                break;
            }
        }
    }
    for(var i=0; i<InputList.length; i++)
    {
        if(InputList[i].type == "hidden")
        {
            if(InputList[i].id.indexOf("hdnPass") > 0)
            {
                hdnObj = document.getElementById(InputList[i].id);
                break;
            }
        }
    }
    if(txtPassObj.value == "")
    {
        args.IsValid = false;
        alert("Enter Password !");
    }
    else if(txtConPassObj.value == "")
    {
        args.IsValid = false;
        alert("Enter Password again to confrim !");
    }
    else if(txtPassObj.value != "" && txtConPassObj.value != "")
    {
        if(txtPassObj.value != txtConPassObj.value)
        {
            args.IsValid = false;
            txtPassObj.value = "";
            txtConPassObj.value = "";
            alert("Password and confirm Password must be match! Enter password again.");
        }
        else if(txtPassObj.value == txtConPassObj.value)
        {
            args.IsValid = true;
            hdnObj.value = hex_sha1(txtConPassObj.value);
        }
    }
}


////////////////////////////////////////////////////////////////////////////////////////////
/////////       Password    -   STA
////////////////////////////////////////////////////////////////////////////////////////////
/*
 * Configurable variables. You may need to tweak these to be compatible with
 * the server-side, but the defaults work in most cases.
 */
var hexcase = 0;  /* hex output format. 0 - lowercase; 1 - uppercase        */
var b64pad  = ""; /* base-64 pad character. "=" for strict RFC compliance   */
var chrsz   = 8;  /* bits per input character. 8 - ASCII; 16 - Unicode      */


function SHA(tid,hid)
{
    to = document.getElementById(tid);
    ho = document.getElementById(hid);
    ho.value = hex_sha1(to.value);
}

function hex_sha1(s)
{
    return binb2hex(core_sha1(str2binb(s),s.length * chrsz));
}

/*
 * Convert an array of big-endian words to a hex string.
 */
function binb2hex(binarray)
{
  var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
  var str = "";
  for(var i = 0; i < binarray.length * 4; i++)
  {
    str += hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8+4)) & 0xF) +
           hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8  )) & 0xF);
  }
  return str;
}

function core_sha1(x, len)
{
  /* append padding */
  x[len >> 5] |= 0x80 << (24 - len % 32);
  x[((len + 64 >> 9) << 4) + 15] = len;

  var w = Array(80);
  var a =  1732584193;
  var b = -271733879;
  var c = -1732584194;
  var d =  271733878;
  var e = -1009589776;

  for(var i = 0; i < x.length; i += 16)
  {
    var olda = a;
    var oldb = b;
    var oldc = c;
    var oldd = d;
    var olde = e;

    for(var j = 0; j < 80; j++)
    {
      if(j < 16) w[j] = x[i + j];
      else w[j] = rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1);
      var t = safe_add(safe_add(rol(a, 5), sha1_ft(j, b, c, d)),
                       safe_add(safe_add(e, w[j]), sha1_kt(j)));
      e = d;
      d = c;
      c = rol(b, 30);
      b = a;
      a = t;
    }

    a = safe_add(a, olda);
    b = safe_add(b, oldb);
    c = safe_add(c, oldc);
    d = safe_add(d, oldd);
    e = safe_add(e, olde);
  }
  return Array(a, b, c, d, e);
}

/*
 * Add integers, wrapping at 2^32. This uses 16-bit operations internally
 * to work around bugs in some JS interpreters.
 */
function safe_add(x, y)
{
  var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  return (msw << 16) | (lsw & 0xFFFF);
}

/*
 * Bitwise rotate a 32-bit number to the left.
 */
function rol(num, cnt)
{
  return (num << cnt) | (num >>> (32 - cnt));
}

/*
 * Perform the appropriate triplet combination function for the current
 * iteration
 */
function sha1_ft(t, b, c, d)
{
  if(t < 20) return (b & c) | ((~b) & d);
  if(t < 40) return b ^ c ^ d;
  if(t < 60) return (b & c) | (b & d) | (c & d);
  return b ^ c ^ d;
}

/*
 * Determine the appropriate additive constant for the current iteration
 */
function sha1_kt(t)
{
  return (t < 20) ?  1518500249 : (t < 40) ?  1859775393 :
         (t < 60) ? -1894007588 : -899497514;
}

/*
 * Convert an 8-bit or 16-bit string to an array of big-endian words
 * In 8-bit function, characters >255 have their hi-byte silently ignored.
 */
function str2binb(str)
{
  var bin = Array();
  var mask = (1 << chrsz) - 1;
  for(var i = 0; i < str.length * chrsz; i += chrsz)
    bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (32 - chrsz - i%32);
  return bin;
}

////////////////////////////////////////////////////////////////////////////////////////////
/////////       Password        - END
////////////////////////////////////////////////////////////////////////////////////////////