/*
    Website: http://www.PNRStatus.info
    Author: Patrick Dey
    Author URI: http://www.patrickdey.com
    Description: This file contains JavaScript functions used by the website PNRStatus.info

    Copyritight (c) 2009-2012 Patrick Dey, All rights reserved
    No part of the JavaScript file can be copied or used on another website without the author's prior permission
*/


function setFocus() { document.pnrForm.textPnrNumber.focus();}
function allTrim(input) { return input.replace(/^\s+|\s+$/g, ""); }
function leftTrim(input) { return input.replace(/^\s+/, ""); }
function rightTrim(input) { return input.replace(/\s+$/, ""); }
function replaceSpaces(input) { return input.replace(/\s/g, ""); }
function replaceHyphens(input) { return input.replace(/-/g, ""); }


function validatePNR()
{
    <!-- Strip away hyphens and spaces from input PNR -->
    var pnrNumber = replaceHyphens(replaceSpaces(document.pnrForm.textPnrNumber.value));
    
    <!-- Ensure that input PNR consists of 10 digits -->
    var regExPNR = /^\d\d\d\d\d\d\d\d\d\d$/

    if (regExPNR.test(pnrNumber) == false)
    {
        alert('Enter a valid 10-digit PNR number, for example, 1253408411');
        document.pnrForm.textPnrNumber.select();
        document.pnrForm.textPnrNumber.focus();
        return false;
    }

    <!-- Split the 10-digit PNR into two groups of 3-digit and 7-digit numbers -->
    var pnrNumberLeft3 = pnrNumber.substring(0, 3);
    var pnrNumberRight7 = pnrNumber.substring(3, 10);
    document.pnrForm.lccp_pnrno1.value = pnrNumberLeft3;
    document.pnrForm.lccp_pnrno2.value = pnrNumberRight7;
    
    return true;
}


function backToStatusEnquiryPage()
{
    document.getElementById('status-enquiry-page').src = "http://www.indianrail.gov.in/pnr_Enq.html";
    return true;
}

