﻿

//JavaScript Error Messages
var FE_ERR01 = "FE_ERR01: Please enter a valid Zipcode.";
var FE_ERR02 = "FE_ERR02: Please enter the valid email address.";
var FE_ERR03 = "FE_ERR03: Please enter only digits in ";
var FE_ERR05 = "FE_ERR05: Select atleast one option from ";
var FE_ERR018 = "FE_ERR018: The passwords do not match. Please re-enter the passwords.";
var FE_ERR019 = "FE_ERR019: Please enter only characters and digits (A To Z and 0 To 9) in ";
var FE_ERR020 = "FE_ERR020: Please enter minimun six characters in ";
var FE_ERR021 = "FE_ERR021: Please create atleast one version and module.";
var FE_ERR022 = "FE_ERR022: Please create atleast one module of each version.";
var FE_ERR025 = "FE_ERR025: Version can't be duplicated.";
var FE_ERR026 = "FE_ERR026: Module can't be duplicated.";
var FE_ERR027 = "FE_ERR027: Please select a node to delete.";
var FE_ERR029 = "FE_ERR029: Please insert version name.";
var FE_ERR030 = "FE_ERR030: This version already exists, please enter another version.";
var FE_ERR032 = "FE_ERR032: Please enter module name and select version.";
var FE_ERR033 = "FE_ERR033: This module already exists, please enter another module.";
var FE_ERR034 = "FE_ERR034: Version and module names cannot be blank.";
var FE_ERR043 = "FE_ERR043: Please select a node to activate.";
var FE_ERR044 = "FE_ERR044: Please select a node to deactivate.";
var FE_ERR045 = "FE_ERR045: Maximum value should be greater than minimum.";
var FE_ERR046 = "FE_ERR048: The email do not match. Please re-enter the emails.";


// General Messages
var MSG_CANNOT_EMPTY = " cannot be empty.";
var MSG_CONFIRM_DELETE = "Are you sure you want to delete this record?";
var MSG_CONFIRM_UPDATE = "Are you sure you want to update this record?";
var MSG_MODULE_ADDED = "Module has been added successfully.";
var MSG_VERSION_ADDED = "Version has been added successfully.";
var MSG_Deleted_Successfully = "Successfully deleted.";
////Messages - End

// JScript File
//// File Upload ////
function file_change(sender, args) { check_upload_queue(sender); }

function check_upload_queue(ctrl) {
    var btn = document.getElementById("btn-upload");
    if (ctrl.GetFiles().length > 0) btn.className = "upload";
    else btn.className = "upload-d";
}

function add_file(ctrl, el) {
    ctrl.AddFile();
    if (ctrl.FileCount == ctrl.MaximumFileCount) el.className = "add-d";
}

function remove_file(ctrl, item) {
    if (ctrl.FileCount > 1) ctrl.RemoveFileAt(item);
    //else { ctrl.ClearFiles();ctrl.AddFile(); }
    //else ctrl.ClearFiles();
    //ctrl.ClearFiles();

    if (ctrl.FileCount < ctrl.MaximumFileCount) document.getElementById("btn-add").className = "add";
}


function upload_begin(sender, args) {
    //UploadDialog.Show();
}


function upload_end(sender, args) {
    //alert('upload done')
}

function generate_file_list(ctrl, cur) {
    var files = ctrl.GetFiles();
    var out = "";
    var cls = "done";

    for (var f in files) {
        var file = files[f].substring(files[f].lastIndexOf("\\") + 1, files[f].length);
        var li = "<li class=\"" + cls + "\">";
        if (file == cur) {
            li = (ctrl.Uploading) ? "<li class=\"cur\">" : "<li class=\"done\">";
            cls = "";
        }
        out += li + file + "</li>";
    }

    return "<ul>" + out + "</ul>";
}

//	File size functions
function format_file_size(n, fmt) {
    if (!fmt) {		//	no formatting specified; automatically select the best format
        if (n < 1000) fmt = "b";
        else if (n < 1000000) fmt = "kb";
        else if (n < 1000000000) fmt = "mb";
        else fmt = "gb";
    }

    switch (fmt.toLowerCase()) {
        case "kb": return String((n * 0.001).toFixed(2)) + " KB"; break;
        case "mb": return String((n * 0.000001).toFixed(2)) + " MB"; break;
        case "gb": return String((n * 0.000000001).toFixed(2)) + " GB"; break;
        default: return String(n.toFixed(2)) + " B";
    }
}

function get_percentage(n) { return String(Math.round(n * 100)); }

//	Time functions
function format_time(t, txt) {
    var s = Math.floor(t);
    var m = Math.floor(s / 60);
    var h = Math.floor(m / 60);

    if (!txt) {
        //	Output will always have be least mm:ss
        s = pad_time(s % 60);
        m = pad_time(m % 60) + ":";
        h = (h == 0) ? "" : pad_time(h % 60) + ":";

        return (h + m + s);
    } else {
        var secs = (s > 1) ? "seconds" : "second"; 		//	plural & singular second units
        var mins = (m > 1) ? "minute" : "minute"; 		//	plural & singular minute units
        var hours = (h > 1) ? "hours" : "hour"; 			//	plural & singular hour units

        s = (s > 0) ? String(s) + " " + secs : ""; 		//	string or empty?
        m = (m > 0) ? String(m) + " " + mins : ""; 		//	string or empty?
        h = (h > 0) ? String(h) + " " + hours : ""; 		//	string or empty?

        var out = "";
        if (h !== "") {										//	longer than an hour
            out = h;
            if (m != "") out += ", " + m; 				//	at least one minute
            if (s != "") out += ", " + s; 				//	at least one second
        }

        if (m !== "" && out == "") {						//	shorter than an hour, greater than 60 seconds
            out += m;
            if (s != "") out += ", " + s; 				//	at least one second
        }

        if (s !== "" && out == "") out = s; 				//	at least one second

        if (out == "") out = "less than 1 second"; 		//	less than a second

        return out;
    }
}

function pad_time(t) { return String(((t > 9) ? "" : "0") + t); }

function get_file_position(ctrl, cur) {
    var files = ctrl.GetFiles();
    for (var i = 0; i < files.length; i++) {
        var file = files[i].substring(files[i].lastIndexOf("\\") + 1, files[i].length);
        if (file == cur) return String(i + 1);
    }

    return "1";
}

function init_upload(ctrl) {
    ctrl.Upload();
    UploadDialog.Show();
}

(new Image()).src = "images/vertical.png";
//// File Upload - End ////

//////// Menu ////////
function updateMenu() {
    Menu1.set_expandSlide(parseInt(document.getElementById('selExpandSlide').value));
    Menu1.set_expandTransition(parseInt(document.getElementById('selExpandTransition').value));
    Menu1.set_expandDuration(parseInt(document.getElementById('txtExpandDuration').value));
    Menu1.set_expandDelay(parseInt(document.getElementById('txtExpandDelay').value));
    Menu1.set_expandOnClick(!!(document.getElementById('chkExpandOnClick').checked));
    Menu1.set_collapseSlide(parseInt(document.getElementById('selCollapseSlide').value));
    Menu1.set_collapseTransition(parseInt(document.getElementById('selCollapseTransition').value));
    Menu1.set_collapseDuration(parseInt(document.getElementById('txtCollapseDuration').value));
    Menu1.set_collapseDelay(parseInt(document.getElementById('txtCollapseDelay').value));
    Menu1.set_cascadeCollapse(!!(document.getElementById('chkCascadeCollapse').checked));
}

function SetColor(colImg) {
    var chosen = document.getElementById('ChosenColor');
    chosen.style.backgroundColor = colImg.style.backgroundColor;
    chosen.innerHTML = colImg.alt;
}
//////// Menu - End ////////


// Controls Valdtion Script //////

// alert("vs");
/*
1 for IsAlphaString
2 for IsNumeric
3 for IsValidEmail
4 for isValidZipCode
5 for IsValidLength
6 for IsDecimalNumber
7 for IsValidDate
8 for IsEmpty
9 for IsMatchPassword
10 for CheckingCheckBox are filled
11 for Checking Textbox decimal values
12 for Check ComboBox selected
13 for checking allComboBox selected 
14 for checking duplication on whole form on textboxes
15 for checking duplication in Combobox value 
16 for Comparing two Date 
17 for Just Checking empty text box don't produces error
18 for Just Checking Text Area is not empty. return true and false 
19 for Atleast one combo box is selected 
20 for checking duplication in Combobox value with combobox staring name\
21 for checking vaid url
22 for checking IsEmpty of combobox value field
23 For Checking atleast one Check Box is selected in a checkboxlist control
24 For IsInt

25 for IsNumericAndHyphen : Function to Validate Numeric Values and hyphen
26 IsNumericWithoutComma
27 for IsHtmlInjection
UTILITY METHODS
---------------
1. OPEN WINDOW FOR SERVER BUTTONS
Opens a new window and return false to stop a server button from postback
	
function OpenNewWindow(IEpage,pageName,w,h,PostBack)

2. CLOSE WINDOW 

function CloseWindow()
	
3. SET FOCUS ON THE GIVEN CONTROL

function SetFocus(ControlName)
	
4. Function USe For Checking atleast one Check Box is selected in a checkboxlist;

function ValidateChechBoxList(frmName,chkListName)	
*/


function CheckForm(CheckCode, ControlName, Caption, MinValue, MaxValue, ControlName2) {

    if (CheckCode == 1)
        return IsAplhaString(ControlName, Caption);

    else if (CheckCode == 2)
        return IsNumeric(ControlName, Caption);

    else if (CheckCode == 3)
        return IsValidEmail(ControlName, Caption);

    else if (CheckCode == 4)
        return IsValidZipCode(ControlName, Caption);

    else if (CheckCode == 5)
        return IsValidLength(ControlName, Caption, MinValue, MaxValue);

    else if (CheckCode == 6)
        return IsDecimalNumber(ControlName, Caption);

    else if (CheckCode == 7)
        return IsValidDate(ControlName, Caption, MinValue);

    else if (CheckCode == 8)

        return IsEmpty(ControlName, Caption);

    else if (CheckCode == 9)
        return IsMatchPassword(ControlName, ControlName2);

    else if (CheckCode == 10)
        return IsCheckBoxChecked(ControlName, Caption, MinValue, MaxValue);

    else if (CheckCode == 11)
        return IsTextBoxDecimal(ControlName, Caption);

    else if (CheckCode == 12)
        return IsComboBoxSelected(ControlName, Caption);

    else if (CheckCode == 13)
        return IsAllComboBoxSelected(ControlName, Caption, MinValue, MaxValue);

    // for checking that the text box is not duplicated  
    else if (CheckCode == 14)
        return IsDuplicateTextBox(ControlName, MinValue, MaxValue, Caption, ControlName2);

    // for checking that the combo box is not duplicated  
    else if (CheckCode == 15)
        return IsDuplicateComboBox(ControlName, Caption);
    // for checking that the combo box is not duplicated	  
    else if (CheckCode == 16) {

        return IsCompareDate(ControlName, ControlName2, Caption);
    }
    // for checking that field is not empty. No alert is generated
    else if (CheckCode == 17)
        return IsEmptyTrue(ControlName);

    // for checking that field is not empty. No alert is generated
    else if (CheckCode == 18)
        return IsTextAreaEmptyTrue(ControlName);

    // for checking at least one combo box is selected 
    else if (CheckCode == 19)
        return IsOneComboBoxSelected(ControlName, Caption, MinValue, MaxValue, ControlName2);
    // for checking that the combo box is not duplicated  
    else if (CheckCode == 20)
        return IsDuplicateComboBoxWithName(ControlName, Caption, MinValue);
    //for  checking valid url
    else if (CheckCode == 21)
        return isValidURL(ControlName, Caption);
    //for  checking Empty DropdownList
    else if (CheckCode == 22)
        return IsEmptyDropDownList(ControlName, Caption);
    //For checking atleast one checkbox checked in checkboxlist control
    else if (CheckCode == 23)
        return IsOneCheckedInList(ControlName, Caption);

    else if (CheckCode == 24)
        return IsInt(ControlName, Caption);
    else if (CheckCode == 25)
        return IsMatchEmail(ControlName1, ControlName2); ///IsNumericWithoutComma	
    else if (CheckCode == 26)
        return IsNumericWithoutComma(ControlName, Caption);
    else if (CheckCode == 27)
        return IsHtmlInjection(ControlName, Caption);

}

function IsMatchEmail(ControlName1, ControlName2) {
    if (trim(ControlName1.value) == trim(ControlName2.value))
        return true;
    else {
        alert("The both Email do not match. Please re-enter the email");
        ControlName1.focus();
        ControlName1.select();
        return false;
    }
}
// Function USe For Checking atleast one Check Box is selected;
function IsCheckBoxChecked(FormName, Caption, MinValue, MaxValue) {
    if (MinValue == '' || MinValue == 0 || MinValue == null)
        MinValue = 0;

    if (MaxValue == '' || MaxValue == 0 || MaxValue == null)
        MaxValue = FormName.elements.length;
    for (i = MinValue; i < MaxValue; i++) {
        if ((FormName.elements[i].type) == ("checkbox"))
            if (FormName.elements[i].checked == 1)
            return true;
    }

    if (Caption == "")
        alert("Please check at least one check box.");
    else
        alert("Please check at least one " + Caption);
    return false;
}

// Function USe For Checking atleast one Check Box is selected in a checkboxlist;
function ValidateChechBoxList(frmName, chkListName, ControlName) {
    var chkList = new Array();
    var k = 0;

    for (a = 0; a <= frmName.elements.length - 1; a++) {
        if ((frmName.elements[a].type == 'checkbox') && (frmName.elements[a].id.substring(0, frmName.elements[a].id.length - 2) == chkListName)) {
            chkList[k] = frmName.elements[a];
            k++;
        }
    }

    for (a = 0; a <= chkList.length - 1; a++) {
        if (chkList[a].checked == true)
            return true;
    }

    alert('Please check at least one ' + ControlName);
    return false;

}

// Function Use For Checking all TextBox should have integer value;
function IsTextBoxDecimal(FormName, Caption) {
    for (i = 0; i < FormName.elements.length; i++) {
        if ((FormName.elements[i].type) == ("text"))
            if (!(IsDecimalNumber(FormName.elements[i], "")))
            return false;
    }
    return true;
}




// IsAllComboBoxSelected , Check for all Combobox in the forms are selected 
// Caption would be multiple so for three combos e.g Caption = 'test1~test2~test3'

function IsAllComboBoxSelected(FormName, Caption, MinValue, MaxValue) {
    var NameArray;
    NameArray = Caption.split("~");


    if (MinValue == '' || MinValue == 0 || MinValue == null)
        MinValue = 0;

    if (MaxValue == '' || MaxValue == 0 || MaxValue == null)
        MaxValue = FormName.elements.length;


    count = 0;
    for (i = MinValue; i < MaxValue; i++) {
        if ((FormName.elements[i].type) == ("select-one")) {
            if (FormName.elements[i][FormName.elements[i].selectedIndex].text.length == 0) {
                alert("Please select " + NameArray[count] + ".");
                FormName.elements[i].focus();
                return false;
            }
            count++;
        }
    }
    return true;
}


// IsAtLeastOneComboBoxSelected , Check for all Combobox in the forms are selected 
// Caption would be multiple so for three combos e.g Caption = 'test1~test2~test3'

function IsOneComboBoxSelected(FormName, Caption, MinValue, MaxValue, ControlName) {
    if (MinValue == '' || MinValue == 0 || MinValue == null)
        MinValue = 0;

    if (MaxValue == '' || MaxValue == 0 || MaxValue == null)
        MaxValue = FormName.elements.length;

    FirstComboIndex = 0;
    for (i = MinValue; i < MaxValue; i++) {
        if ((FormName.elements[i].type == "select-one") && (FormName.elements[i].name.substring(0, 17) == "tblSaleForCastddl")) {
            if (FirstComboIndex == 0)
                FirstComboIndex = i;
            if (trim(FormName.elements[i][FormName.elements[i].selectedIndex].text).length != 0) {
                return true;
            }
        }
    }
    alert("Please select one of the " + Caption + ".");
    FormName.elements[FirstComboIndex].focus();
    return false;
}


// IsComboBoxSelected , Check for Combobox is selected 
function IsComboBoxSelected(ControlName, Caption) {
    if (ControlName[ControlName.selectedIndex].text == "<--SELECT-->") {
        alert("Please select from " + Caption + ".");
        ControlName.focus();
        return false;
    }
    if (trim(ControlName[ControlName.selectedIndex].text).length == 0) {
        alert("Please select " + Caption + ".");
        ControlName.focus();
        return false;
    }
    return true;
}

//Check for Empty
function IsEmpty(ControlName, Caption) {
    if (ControlName == null) {
        return true;
    }
    if (trim(ControlName.value).length == 0) {
        alert("FE_ERR04: " + Caption + MSG_CANNOT_EMPTY);
        ControlName.focus();
        ControlName.select();
        return false;
    }
    return true;
}

//Check for Empty Dropdownlist
function IsEmptyDropDownList(ControlName, Caption) {
    if (trim(ControlName.value).length == 0 || trim(ControlName.value) == 0) {
        alert("FE_ERR04: " + Caption + MSG_CANNOT_EMPTY);
        ControlName.focus();
        return false;
    }
    return true;
}

// isEmpty , Check for Empty
function IsEmptyTrue(ControlName) {
    if (trim(ControlName.value).length == 0)
        return false;
    else
        return true;
}

// isEmpty , Check for Empty
function IsTextAreaEmptyTrue(ControlName) {
    alert("Implementation is not defined");
}



//Length Check Function 
function IsValidLength(ControlName, Caption, MinValue, MaxValue) {
    if ((trim(ControlName.value).length >= MinValue) && (trim(ControlName.value).length <= MaxValue))
        return true;
    else {
        alert("The " + Caption + " entered charactered has exceed.");
        ControlName.focus();
        ControlName.select();
        return false;
    }
    return true;
}


// Decimal Check Function
function IsDecimalNumber(ControlName, Caption) {
    if (isNaN(ControlName.value)) {
        alert("Please enter only digits in the " + Caption + ".");
        ControlName.focus();
        ControlName.select();
        return false;
    }
    return true;
}


// IsNumeric Function to Validate Numeric Values
function IsNumeric(ControlName, Caption) {
    if (trim(ControlName.value).length == 0)
        return true;

    checkOK = "0123456789.,";
    checkStr = trim(ControlName.value);
    allValid = true;
    decPoints = 2;
    allNum = "";

    for (i = 0; i < checkStr.length; i++) {
        ch = checkStr.charAt(i);
        for (j = 0; j < checkOK.length; j++)
            if (ch == checkOK.charAt(j))
            break;
        if (j == checkOK.length) {
            allValid = false;
            break;
        }
        if (ch == ".") {
            allNum += ".";
            decPoints++;
        }
        else
            allNum += ch;
    }

    if (!allValid) {
        alert(FE_ERR03 + Caption + ".");
        ControlName.focus();
        ControlName.select();
        return (false);
    }
    return true;
}

// IsNumericAndHyphen Function to Validate Numeric Values and hyphen
function IsNumericAndHyphen(ControlName, Caption) {
    if (trim(ControlName.value).length == 0)
        return true;

    checkOK = "0123456789.,-()";
    checkStr = trim(ControlName.value);
    allValid = true;
    decPoints = 2;
    allNum = "";

    for (i = 0; i < checkStr.length; i++) {
        ch = checkStr.charAt(i);
        for (j = 0; j < checkOK.length; j++)
            if (ch == checkOK.charAt(j))
            break;
        if (j == checkOK.length) {
            allValid = false;
            break;
        }
        if (ch == ".") {
            allNum += ".";
            decPoints++;
        }
        else
            allNum += ch;
    }

    if (!allValid) {
        alert("Please enter only digits in the " + Caption + ".");
        ControlName.focus();
        ControlName.select();
        return (false);
    }
    return true;
}

// Check Date for Validity 
function IsValidDate(ControlName, Caption, CheckYear) {
    if (trim(ControlName.value).length == 0)
        return true;

    var varMonth = "";
    var varDay = "";
    var varYear = "";

    str = ControlName.value.split("/");

    if ((str[0] == null) || (str[1] == null) || (str[2] == null)) {
        alert("Please enter valid date(s) in proper format: mm/dd/yyyy");
        ControlName.focus();
        ControlName.select();
        return false;
    }

    varMonth = str[0];
    varDay = str[1];
    varYear = str[2];

    if (CheckYear == 1) {
        today = new Date();
        if (parseInt(varYear, 10) >= 1753) {
            if (varYear > today.getFullYear()) {
                alert("Please enter valid date(s) in proper format: mm/dd/yyyy");
                ControlName.focus();
                ControlName.select();
                return false;
            }
        }
    }

    if (varDay.length == 0) {
        alert("Please enter valid date(s) in proper format: mm/dd/yyyy");
        ControlName.focus();
        ControlName.select();
        return false;
    }
    else if (varMonth.length == 0) {
        alert("Please enter valid date(s) in proper format: mm/dd/yyyy");
        ControlName.focus();
        ControlName.select();
        return false;
    }
    else if (!(varYear >= 1753 && varYear <= 9999)) {
        alert("Please enter valid date(s) in proper format: mm/dd/yyyy");
        ControlName.focus();
        ControlName.select();
        return false;
    }

    else if (parseInt(varDay, 10) < 1 || parseInt(varDay, 10) > 31) {
        alert("Please enter valid date(s) in proper format: mm/dd/yyyy");
        ControlName.focus();
        ControlName.select();
        return false;
    }
    else if (parseInt(varMonth, 10) < 1 || parseInt(varMonth, 10) > 12) {
        alert("Please enter valid date(s) in proper format: mm/dd/yyyy");
        ControlName.focus();
        ControlName.select();
        return false;
    }
    else if (varMonth == 2) {
        if (varDay.value > 29) {
            alert("Please enter valid date(s) in proper format: mm/dd/yyyy");
            ControlName.focus();
            ControlName.select();
            return false;
        }
    }
    else if (varMonth == 4 || varMonth == 6 || varMonth == 9 || varMonth == 11) {
        if (varDay > 30) {
            alert("Please enter valid date(s) in proper format: mm/dd/yyyy");
            ControlName.focus();
            ControlName.select();
            return false;
        }
    }

    return true;
}


// Check for String 
function IsAplhaString(ControlName, Caption) {
    checkOK = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
    checkStr = ControlName.value;
    allValid = true;
    decPoints = 0;
    allNum = "";

    for (i = 0; i < checkStr.length; i++) {
        ch = checkStr.charAt(i);
        for (j = 0; j < checkOK.length; j++)
            if (ch == checkOK.charAt(j))
            break;
        if (j == checkOK.length) {
            allValid = false;
            break;
        }
        if (ch == ".") {
            allNum += ".";
            decPoints++;
        }
        else
            allNum += ch;
    }
    if (!allValid) {
        alert("Please enter only alpha string in the " + Caption + ".");
        ControlName.focus();
        ControlName.select();
        return (false);
    }

    if (decPoints > 0) {
        alert("Please enter a valid alpha string in the " + Caption + ".");
        ControlName.focus();
        ControlName.select();
        return (false);
    }
    return true;
}


// Validate for Email
function IsValidEmail(ControlName, Caption) {
    if (trim(ControlName.value).length == 0)
        return true;

    str = ControlName.value;
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

    if (filter.test(str))
        return true;
    else {
        alert(FE_ERR02);
        ControlName.focus();
        ControlName.select();
        return false;
    }
}



// Validate for ZipCode , isValidZipCode
function IsValidZipCode(ControlName, Caption) {
    if (trim(ControlName.value).length == 0)
        return true;

    str = ControlName.value;
    var filter = /\d{5}(-\d{4})?/;
    if (filter.test(str))
        return true;
    else {
        alert(FE_ERR01);
        ControlName.focus();
        ControlName.select();
        return false;
    }
}

/// This function is used to triming the data as there are now function available in javascript 
function ltrim(str) {
    while ("" + str.charAt(0) == " ")
        str = str.substring(1, str.length);
    return str;
}

/// This function is used to triming the data as there are now function 
// available in javascript. This is called with the trim 

function reverse(str) {
    var reversedstr = "";
    var strArray;
    strArray = str.split("");
    for (var i = str.length - 1; i >= 0; i--) {
        reversedstr += strArray[i];
    }
    return reversedstr;
}

/// This function is used to triming the data as there are now function 
// available in javascript. It will first call the lrtim and then reverse and again call the ltrim

function trim(str) {
    str = ltrim(str);
    str = reverse(str);
    str = ltrim(str);
    str = reverse(str);
    return str;
}

function IsMatchPassword(ControlName1, ControlName2) {
    if (trim(ControlName1.value) == trim(ControlName2.value)) {
        return true;
    }
    else {
        alert(FE_ERR046);
        ControlName1.focus();
        ControlName1.select();
        return false;
    }
}

function IsMatch(ControlName1, ControlName2, ErrMsg) {
    if (trim(ControlName1.value) == trim(ControlName2.value)) {
        return true;
    }
    else {
        alert(ErrMsg);
        ControlName1.focus();
        ControlName1.select();
        return false;
    }
}



function IsDuplicateTextBox(FormName, MinValue, MaxValue, Caption, HTMLControlName) {
    for (i = 0; i < FormName.elements.length; i++)
        if ((FormName.elements[i].type == "text") && (FormName.elements[i].name.substring(MinValue, MaxValue) == HTMLControlName))
        for (j = i + 1; j < FormName.elements.length; j++)
        if ((FormName.elements[j].type == "text") && (FormName.elements[j].name.substring(MinValue, MaxValue) == HTMLControlName))
        if (FormName.elements[i].value == FormName.elements[j].value) {
        alert(Caption + " cannot be duplicated.");
        FormName.elements[j].focus();
        FormName.elements[j].select();
        return false;
    }

    return true;
}

// for checking the duplicate values in the combo box 			
function IsDuplicateComboBox(FormName, Caption) {
    for (i = 0; i < FormName.elements.length; i++)
        if (FormName.elements[i].type == "select-one") {

        for (j = i + 1; j < FormName.elements.length; j++)
            if (FormName.elements[j].type == "select-one")
            if ((FormName.elements[i][FormName.elements[i].selectedIndex].text == FormName.elements[j][FormName.elements[j].selectedIndex].text)
						&& ((FormName.elements[i][FormName.elements[i].selectedIndex].text != ""))) //||(FormName.elements[i][FormName.elements[i].selectedIndex].text != null)))
        {
            alert(Caption + " cannot be duplicated.");
            FormName.elements[j].focus();
            return false;
        }
    }
    return true;
}


function IsCompareDate(Control1, Control2, Caption) {

    var f = new Date(Control1.value);
    var n = new Date(Control2.value);

    if ((Date.parse(f.toDateString()) > Date.parse(n.toDateString()))) {
        if (Caption == "") {
            alert("From date must be less than To date");
        }
        else {
            alert(Caption);
        }
        Control1.focus();
        Control1.select();
        return false;
    }
    else
        return true;

}


function DateCK(Control1, Control2, Caption) {


    if (trim(Control1.value).length == 0)
        return true;
    if (trim(Control2.value).length == 0)
        return true;

    var f = new Date(Control1.value);
    var n = new Date(Control2.value);

    if (f.getTime() > n.getTime()) {
        alert(Caption);
        Control2.focus();
        Control2.select();
        return false;
    }
    else
        return true;

}


//for checking duplicate value in combo box with combo box starting name			
function IsDuplicateComboBoxWithName(FormName, Caption, MinValue) {
    for (i = 0; i < FormName.elements.length; i++)
        if ((FormName.elements[i].type == "select-one") && (FormName.elements[i].name.substring(0, MinValue.length) == MinValue)) {
        for (j = i + 1; j < FormName.elements.length; j++)
            if ((FormName.elements[j].type == "select-one") && (FormName.elements[j].name.substring(0, MinValue.length) == MinValue))
            if ((FormName.elements[i][FormName.elements[i].selectedIndex].text == FormName.elements[j][FormName.elements[j].selectedIndex].text)
							&& ((FormName.elements[i][FormName.elements[i].selectedIndex].text != ""))) {
            alert(Caption + " cannot be duplicated.");
            FormName.elements[j].focus();
            return false;
        }
    }
    return true;
}

function checkMin(control, Caption, MinVal) {
    if (control.value.length < MinVal) {
        alert("Enter " + MinVal + " characters for " + Caption);
        control.focus();
        return false;
    }
    return true;
}

function IsComboUnAssigned(ControlName, Caption) {
    if (trim(ControlName[ControlName.selectedIndex].text) == "SELECT") {
        alert("Please select " + Caption + ".");
        ControlName.focus();
        return false;
    }
    return true;
}

function setFocus(ControlName, Caption) {
    ControlName.focus();
}


function getQueryVariable(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) {
            return pair[1];

        }
    }
}


function NumaricOnly() {
    // BZK to allow only numaric value
    // alert(event.keyCode);

    if ((event.keyCode != 8) && (event.keyCode != 46)
				&& (event.keyCode != 189) && (event.keyCode != 109)
				&& (event.keyCode != 9) && (event.keyCode != 13)
				&& (event.keyCode != 110) && (event.keyCode != 188)
				&& (event.keyCode != 190) && !((event.keyCode > 36) && (event.keyCode < 41))
				&& !((event.keyCode > 47) && (event.keyCode < 58))
				&& !((event.keyCode > 95) && (event.keyCode < 106))
				)
        event.returnValue = false;
} //NumaricOnly


function modelesswin(url, mwidth, mheight) {
    if (document.all && window.print) {
        eval('window.showModelessDialog(url,"","help:0;resizable:0;scrollbars:0;dialogWidth:' + mwidth + 'px;dialogHeight:' + mheight + 'px")')
    }
    else {
        eval('window.open(url,"","width=' + mwidth + 'px,height=' + mheight + 'px,resizable=0,scrollbars=0")')
    }
}



function isValidURL(oText, Caption) {
    if (oText.value == '')
        return true;
    //var oRegExp = /[^:]+:\/\/[^:\/]+(:[0-9]+)?\/?.*/;
    var oRegExp = /(:[0-9]+)?\/?.*/;
    if (!oRegExp.test(oText.value)) {
        alert('The ' + Caption + ' you have entered is invalid.');
        oText.focus();
        oText.select();
        return false;
    }
}

var winOrg = null;
function openWindow(IEpage, pageName, w, h) {
    var windowprops = "screenX=0,screenY=0,width=" + w + ",height=" + h + ",location=no,toolbar=no,menubar=no,status=no,scrollbars=yes, resizable=yes,top=60, left=50 ";
    winOrg = window.open(IEpage.toString(), "", windowprops.toString());
}

/*OPEN WINDOW FOR SERVER BUTTONS
openwindow and return false to stop a server button from postback

IEpage = the url of the page to open
pageName = pageName
w = width 
h = height
PostBack = Boolean value to allow or deny postback for the button 
*/
function OpenNewWindow(IEpage, pageName, w, h, PostBack) {
    var windowprops = "screenX=0,screenY=0,width=" + w + ",height=" + h + ",location=no,toolbar=no,menubar=no,status=no,scrollbars=yes, resizable=yes,top=60, left=50 ";
    window.open(IEpage.toString(), "", windowprops.toString());
    return PostBack;
}

//CLOSE WINDOW 
function CloseWindow() {
    window.close;
}

function CloseWindow_Suppress() {
    if ((confirm("Are you sure you want to exit this window?")) == true) {
        window.opener = window;
        window.close();
    }
    else
        return false;
}
function CloseWindow_Suppress_NoMessage() {
    window.opener = window;
    window.close();
}

function StopPostBack(evt) {
    if (evt.keyCode == 13)
        return false;
}

//SET FOCUS ON THE GIVEN CONTROL
function SetFocus(ControlName) {
    document.getElementById('ControlName').focus();
}


// Bzk
function IsPositive(ControlName, Caption) {

    if (ControlName.value > 0)
    { return true; }

    if (!(ControlName.value > 0)) {
        alert("Please enter positive value in the " + Caption + ".");
        ControlName.focus();
        return (false);
    }
}

//add new functions
/************************************************************/
var isNS4 = (navigator.appName == "Netscape") ? 1 : 0;
function specialNotAllow() {
    var retVal = true;
    if (!isNS4) {
        if (((event.keyCode > 33 && event.keyCode < 48) || (event.keyCode > 57 && event.keyCode < 65) || (event.keyCode > 90 && event.keyCode < 97)) && (event.keyCode != 44) && (event.keyCode != 46) && (event.keyCode != 39)) {
            alert("Special Characters are Not Allowed");
            event.returnValue = false;
            retVal = false;
        }
    }
    else {
        if (((event.keyCode > 33 && event.keyCode < 48) || (event.keyCode > 57 && event.keyCode < 65) || (event.keyCode > 90 && event.keyCode < 97)) && (event.keyCode != 44) && (event.keyCode != 46) && (event.keyCode != 39))
            alert("Special Characters are Not Allowed");
        retVal = false;
    }

    return retVal;
}

/****************************************************************/
/************************************************************ for address field only to ristrict <, >*/
var isNS4 = (navigator.appName == "Netscape") ? 1 : 0;
function specialNotAllowInAddress() {
    var retVal = true;

    if (!isNS4) {
        if (((event.keyCode > 35 && event.keyCode < 48) || (event.keyCode > 57 && event.keyCode < 65) || (event.keyCode > 90 && event.keyCode < 97)) && (event.keyCode != 44) && (event.keyCode != 46) && (event.keyCode != 45) && (event.keyCode != 39)) {
            alert("Special Characters are Not Allowed");
            event.returnValue = false;
            retVal = false;
        }
    }
    else {
        if (((event.keyCode > 35 && event.keyCode < 48) || (event.keyCode > 57 && event.keyCode < 65) || (event.keyCode > 90 && event.keyCode < 97)) && (event.keyCode != 44) && (event.keyCode != 46) && (event.keyCode != 45) && (event.keyCode != 39))

            alert("Special Characters are Not Allowed");
        retVal = false;
    }

    return retVal;
}


// Function USe For Checking atleast one Check Box is selected in a checkboxlist control;
function IsOneCheckedInList(ControlName, Caption, MinValue, MaxValue) {
    alert("Implemention is not available");
}

function IsInt(ControlName, Caption) {
    if (trim(ControlName.value).length == 0)
        return true;

    checkOK = "0123456789";
    checkStr = trim(ControlName.value);
    allValid = true;
    decPoints = 2;
    allNum = "";

    for (i = 0; i < checkStr.length; i++) {
        ch = checkStr.charAt(i);
        for (j = 0; j < checkOK.length; j++)
            if (ch == checkOK.charAt(j))
            break;
        if (j == checkOK.length) {
            allValid = false;
            break;
        }
        if (ch == ".") {
            allNum += ".";
            decPoints++;
        }
        else
            allNum += ch;
    }

    if (!allValid) {
        alert("Please enter only digits in the " + Caption + ".");
        ControlName.focus();
        ControlName.select();
        return (false);
    }
    return true;
}





/****************************************************************/
//CLOSE: add new functions
function delete_cookie() {
    try {
        if (window.screenLeft > 10003) {
            var cookie_date = new Date();  // current date & time
            cookie_date.setTime(cookie_date.getTime() - 1);
            document.cookie = 'UID=""; expires=' + cookie_date.toGMTString();
            document.cookie = 'PWD=""; expires=' + cookie_date.toGMTString();
        }

    }
    catch (e) { alert(e.message); }
}

function IsNumericWithoutComma(ControlName, Caption) {
    if (trim(ControlName.value).length == 0)
        return true;

    checkOK = "0123456789";
    checkStr = trim(ControlName.value);
    allValid = true;
    decPoints = 2;
    allNum = "";

    for (i = 0; i < checkStr.length; i++) {
        ch = checkStr.charAt(i);
        for (j = 0; j < checkOK.length; j++)
            if (ch == checkOK.charAt(j))
            break;
        if (j == checkOK.length) {
            allValid = false;
            break;
        }
        if (ch == ".") {
            allNum += ".";
            decPoints++;
        }
        else
            allNum += ch;
    }

    if (!allValid) {
        alert("Please enter only digits in the " + Caption + ".");
        ControlName.focus();
        ControlName.select();
        return (false);
    }
    return true;
}
function IsHtmlInjection(ControlName, Caption) {
    checkOK = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.@()&-_/+= ";
    checkStr = ControlName.value;
    allValid = true;
    decPoints = 0;
    allNum = "";

    for (i = 0; i < checkStr.length; i++) {
        ch = checkStr.charAt(i);
        for (j = 0; j < checkOK.length; j++)
            if (ch == checkOK.charAt(j))
            break;
        if (j == checkOK.length) {
            allValid = false;
            break;
        }
        if (ch == ".") {
            allNum += ".";
            decPoints++;
        }
        else
            allNum += ch;
    }
    if (!allValid) {
        alert("Please enter only alpha string in the " + Caption + ".");
        ControlName.focus();
        ControlName.select();
        return (false);
    }

    if (decPoints > 0) {
        alert("Please enter a valid alpha string in the " + Caption + ".");
        ControlName.focus();
        ControlName.select();
        return (false);
    }
    return true;
}

//////// Contols - End /////////
function IsSelectedListBox(ControlName, Caption, PageName, TabNo) {
    if (ControlName == null) {
        return false;
    }

    for (i = 0; i < ControlName.length; i++) {
        if (ControlName[i].selected == true) {
            return true;
        }
    }
    ActivatePanel(PageName, TabNo);
    alert(FE_ERR05 + Caption);
    return false;
}


function CheckPassword(ControlName, Caption, PageName, TabNo) {
    if (ControlName == null) {
        return true;
    }
    var filter = /^([a-zA-Z0-9]|[.]|[-]|[_])*$/;

    if (ControlName.value.length < 6) {
        ActivatePanel(PageName, TabNo);
        alert(FE_ERR020 + Caption);
        ControlName.focus();
        ControlName.select();
        return false;
    }

    if (filter.test(ControlName.value)) {
        return true;
    }
    else {
        ActivatePanel(PageName, TabNo);
        alert(FE_ERR019 + Caption);
        ControlName.focus();
        ControlName.select();
        return false;
    }
    return false;
}


function ChkBlankAndDublicateTreeNode(ControlName1, ControlName2) {
    var PrjTabObj = ctl00_ContentPlaceHolder1_tbstProject.get_tabs();
    var rootNodes = ctl00_ContentPlaceHolder1_TreeViewTesting.get_nodes();
    var childNodes;

    //if Tree is Blank
    if (rootNodes.get_length() == 0) {
        alert(FE_ERR021);
        PrjTabObj.getTab(1).select();
        ControlName1.focus();
        return false;
    }
    //chk atleast one module of each Version if not then return
    for (var i = 0; i < rootNodes.get_length(); i++) {
        var childNodes = rootNodes.getNode(i).get_nodes();
        if (childNodes.get_length() == 0) {
            alert(FE_ERR022);
            PrjTabObj.getTab(1).select();
            ControlName2.focus();
            return false;
        }
    }

    //check if version is duplicating then return    
    for (var i = 0; i < rootNodes.get_length(); i++) {
        var counter = 0;
        for (var j = 0; j < rootNodes.get_length(); j++) {
            if (rootNodes.getNode(j).get_text() == rootNodes.getNode(i).get_text()) {
                counter++;
                if (counter > 1) {
                    PrjTabObj.getTab(1).select();
                    alert(FE_ERR025);
                    return false;
                }
            }
        }
    }

    //check if module is duplicating then return   
    for (var i = 0; i < rootNodes.get_length(); i++) {
        childNodes = rootNodes.getNode(i).get_nodes();
        if (childNodes.get_length() > 1) {
            for (var j = 0; j < childNodes.get_length(); j++) {
                var counter = 0;
                for (var k = 0; k < childNodes.get_length(); k++) {
                    if (childNodes.getNode(k).Text == childNodes.getNode(j).Text) {
                        counter++;
                        if (counter > 1) {
                            PrjTabObj.getTab(1).select();
                            alert(FE_ERR026);
                            return false;
                        }
                    }
                }
            }
        }
    }

    return true;
}




// Check IsValidUserID
function CheckIsValidData(ControlName, Caption, PageName, TabNo) {
    if (ControlName == null) {
        return true;
    }
    var filter = /^([a-zA-Z0-9]|[.]|[-]|[_])*$/;
    if (filter.test(ControlName.value)) {
        return true;
    }
    else {
        alert(FE_ERR019 + Caption);
        ControlName.focus();
        ControlName.select();
        return false;
    }
    return false;
}

//Check is valid input
function CheckIsValidInput(ControlName, Caption, PageName) {
    if (ControlName == null) {
        return true;
    }

    var filter = /^([a-zA-Z0-9]|[.]|[-]|[_])*$/;
    if (filter.test(ControlName.value)) {
        return true;
    }
    else {

        alert(FE_ERR019 + Caption);
        ControlName.focus();
        ControlName.select();
        return false;
    }
}

//Check Confirmation
function confirmation(Caption) {
    if (Caption == 'Delete') {
        var answer = confirm(MSG_CONFIRM_DELETE);
    }
    else {
        var answer = confirm(MSG_CONFIRM_UPDATE);
    }
    if (answer) {
        return true;
    }
    else {
        return false;
    }
    return false;
}

function ActivatePanel(PageName, TabNo) {
    if (PageName == 'User') {
        var UserTabObj = ctl00_ContentPlaceHolder1_tbstUser.get_tabs();
        UserTabObj.getTab(TabNo).select();
    }
    else if (PageName == 'SetupScreen') {
        var SetupScreenTabObj = ctl00_ContentPlaceHolder1_tbstSetupScreen.get_tabs();
        SetupScreenTabObj.getTab(TabNo).select();

    }
}


function CompareNumericValue(ControlName1, ControlName2, SetupPageName, SetupTabNo) {
    var T1 = ControlName1.value;
    var T2 = ControlName2.value;

    if (parseInt(T1) > parseInt(T2)) {
        ActivatePanel(SetupPageName, SetupTabNo);
        ControlName1.focus();
        ControlName1.select();
        alert(FE_ERR045);
        return false;
    }
    return true;
}

