﻿/*******************************************
Date: 23/03/2010
Developer: Rahul

Prameter description:
_ctrlIds: 'This variable contains the array of controls to validate'
_emptyText : 'This variable contains the control message text'
_invDataChk: 'This variable contains the string for input validation corresponding to controls arrays'
Where:
E = Email
I = Integer
F = Float
S = string   

*******************************************/

function chkInputValues(_ctrlIds, _emptyText, _invDataChk, _ctrlIDs4Comp, _ctrlIDs4CompVals) {
    var _status = true;

    ///validating blank values
    _status = chkEmptyValues(_ctrlIds, _emptyText);
    if (!_status) return false;

    ///validating Input values
    _status = chkInputValidation(_ctrlIds, _emptyText, _invDataChk);
    if (!_status) return false;

    ///validating the equality of values
    if ((_ctrlIDs4Comp != "undefined") && (_ctrlIDs4CompVals != "undefined")) {

    }

    return true;
}


////Returns the string if any control (mandatory) having blank values
function chkEmptyValues(_ctrlIds, _emptyText) {
    var _arrIDs = new Array();
    var _arrEmptyTxt = _emptyText.split('|');
    var _retMsg = "";
    var j = 0;
    for (var i = 0; i < _ctrlIds.length; i++) {
        _ctrlIds[i].style.backgroundColor = "white";
        switch (_ctrlIds[i].tagName.toLowerCase()) {
            case "select": if (_ctrlIds[i].selectedIndex == 0) {
                    _retMsg += "\n" + _arrEmptyTxt[i];
                    _arrIDs[j++] = _ctrlIds[i];
                    _ctrlIds[i].style.backgroundColor = "lightyellow";
                }

                break;
            case "input":
                if (_ctrlIds[i].type.toLowerCase() == 'text') {
                    if (_ctrlIds[i].value == "") {
                        _retMsg += "\n" + _arrEmptyTxt[i];
                        _arrIDs[j++] = _ctrlIds[i];
                        _ctrlIds[i].style.backgroundColor = "lightyellow";
                    }
                }
                break;
            case "textarea":
                if (_ctrlIds[i].value == "") {
                    _retMsg += "\n" + _arrEmptyTxt[i];
                    _arrIDs[j++] = _ctrlIds[i];
                    _ctrlIds[i].style.backgroundColor = "lightyellow";
                }
                break;
        } ////end of switch
    } ///end of for

    ///Prompting message & placing pointer to appropriate control
    if (_retMsg != "") {
        _retMsg = "Please Fill Details:\n" + _retMsg;
        alert(_retMsg);
        _arrIDs[0].focus();
        _arrIDs[0].select();
        return false;
    }

    return true;
}


///returns the string if any control having invalid data
function CompareInputValues(_ctrlIds, _ctrlIDs4CompVals) {
    var _arrIDs = new Array();
    //var _arrEmptyTxt = _emptyText.split('|');
    var _arrCtrl2Validate = _ctrlIDs4CompVals.split('|');
    var _retMsg = "";
    var j = 0;

    for (var i = 0; i < _ctrlIds.length; i++) {
        _ctrlIds[i][1].style.backgroundColor = "white";
        if ((_ctrlIds[i][0].tagName.toLowerCase() == "input") && (_ctrlIds[i][1].tagName.toLowerCase() == "input")) {
            if ((_ctrlIds[i][0].type.toLowerCase() == 'text') && (_ctrlIds[i][1].type.toLowerCase() == 'text')) {

                if (_arrCtrl2Validate[i] == "E" && (_ctrlIds[i][0].value != _ctrlIds[i][1].value)) {/// comparing emails
                    _retMsg += "\n Email Ids should be identical";
                    _arrIDs[j++] = _ctrlIds[i][1];
                    _ctrlIds[i][1].style.backgroundColor = "lightyellow";
                }
            }

        } ////end of if
    } ///end of for

    ///Prompting message & placing pointer to appropriate control
    if (_retMsg != "") {
        _retMsg = "Please Note:\n" + _retMsg;
        alert(_retMsg);
        _arrIDs[0].focus();
        _arrIDs[0].select();
        return false;
    }

    return true;
}

///returns the string if controls having not matching values
function chkInputValidation(_ctrlIds, _emptyText, _invDataChk) {
    var _arrIDs = new Array();
    var _arrEmptyTxt = _emptyText.split('|');
    var _arrCtrl2Validate = _invDataChk.split('|');
    var _retMsg = "";
    var j = 0;

    for (var i = 0; i < _ctrlIds.length; i++) {
        _ctrlIds[i].style.backgroundColor = "white";
        switch (_ctrlIds[i].tagName.toLowerCase()) {
            case "input":
                if (_ctrlIds[i].type.toLowerCase() == 'text') {
                    if (_arrCtrl2Validate[i] == "E" && !emailCheck(_ctrlIds[i].value)) {/// validating emails
                        _retMsg += "\n Invalid " + _arrEmptyTxt[i];
                        _arrIDs[j++] = _ctrlIds[i];
                        _ctrlIds[i].style.backgroundColor = "lightyellow";
                    }
                }
                break;
        } ////end of switch
    } ///end of for

    ///Prompting message & placing pointer to appropriate control
    if (_retMsg != "") {
        _retMsg = "You have entered:\n" + _retMsg;
        alert(_retMsg);
        _arrIDs[0].focus();
        _arrIDs[0].select();
        return false;
    }

    return true;
}


/**********************************************************************************
******************** Added by Vishav <26.05.2011> ********************************/

function DontAllowCntrlAlt(e) {
    var code = (document.all) ? event.keyCode : e.which;
    var ctrl = (document.all) ? event.ctrlKey : e.modifiers & Event.CONTROL_MASK;
    var msg = "";
    if (document.all) {
        if (ctrl && code == 86) //CTRL+V
        { window.event.returnValue = false; }
        else if (ctrl && code == 67) //CTRL+C (Copy)
        { window.event.returnValue = false; }
        else
            return true;
    }
    else {
        if (ctrl == 2) //CTRL key
        { return false; }
    }
}



function captureRightClick(e) {
    var msg1 = "Right Click Is Disabled.";
    if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) {
        alert(msg1);
        event.returnValue = false;
    }
    if (navigator.appName == 'Netscape' && (e.which == 2 || e.which == 3)) {
        alert(msg1);
    }
    return false;
}




//Validate Input
function Validate_Input() {
    //Get Controls
    var objTxoldpswd = document.getElementById("txtOldPassword");
    var objTxnewpswd = document.getElementById("txtNewPassword");
    var objTxcnfrmpswd = document.getElementById("txtConfirmPassword");
    //Message start
    var MsgTxt = "Please Fill Details: \n\n";

    //Check empty fields
    if (objTxoldpswd != null && trim(objTxoldpswd.value) == '')
    { MsgTxt += "Old Password\n"; objTxoldpswd.style.backgroundcolor = "lightyellow"; }
    else
    { objTxoldpswd.style.backgroundcolor = "white"; }

    if (objTxnewpswd != null && trim(objTxnewpswd.value) == '')
    { MsgTxt += "New Password\n"; objTxnewpswd.style.backgroundcolor = "lightyellow"; }
    else
    { objTxnewpswd.style.backgroundcolor = "white"; }

    if (objTxcnfrmpswd != null && trim(objTxcnfrmpswd.value) == '')
    { MsgTxt += "Confirm Password\n"; objTxcnfrmpswd.style.backgroundcolor = "lightyellow"; }
    else
    { objTxcnfrmpswd.style.backgroundcolor = "white"; }

    if (MsgTxt == "Please Fill Details: \n\n") {
        //Compare Password
        if (objTxoldpswd.value != myCurrPswd)
        { alert("Invalid password!\nPlease enter your profile password."); ClearCtrls(); return false; }
        else if (objTxnewpswd.value != objTxcnfrmpswd.value)
        { alert("Password mismatch!\nNew & confirm password should be same."); ClearCtrls(); return false; }
        else
            return true;
    }
    else {
        alert(MsgTxt);
        if (objTxoldpswd != null && trim(objTxoldpswd.value) == '')
        { objTxoldpswd.focus(); return false; }
        else if (objTxnewpswd != null && trim(objTxnewpswd.value) == '')
        { objTxnewpswd.focus(); return false; }
        else if (objTxcnfrmpswd != null && trim(objTxcnfrmpswd.value) == '')
        { objTxcnfrmpswd.focus(); return false; }
    }
}


