﻿//var DOMAIN = 'http://localhost:1903/Website/';
//var DOMAIN = 'http://dev.buildsystem.in/';
var DOMAIN = 'http://buildsystem.in/';

//==========================company Offices(fill city dropdown on state change)====================
function populateCities() {

    // first of all update the city based on the state
    updateCityCallBack($("#state_name").val());
    // then hook the change event of the city dropdown so that it updates cities all the time
    $("#state_name").bind("change", function(e) { updateCityCallBack($("#state_name").val()); });
}

function updateCityCallBack(stateid) {
    var cityname = $("#hdval").val();

    $("#city_name").html("<option value=''>Loading cities...</option>").attr("disabled", "disabled");
    $.ajax({
        url: DOMAIN + "member/company_offices.aspx?stateid=" + stateid,
        type: "GET",
        success: function(citiesJson) {
            var cities = eval(citiesJson);
            var citiesHtml = "";
            $(cities).each(function(i, option) {
                if (option == cityname) {
                    citiesHtml += '<option selected value="' + option + '">' + option + '</option>';
                }
                else {
                    citiesHtml += '<option value="' + option + '">' + option + '</option>';
                }
            });

            $("#city_name").removeAttr("disabled").html(citiesHtml);
        }
    });
}
function strcity() {
    var str = $("#city_name_edit").val();
    //alert(str);
    $('#hdval').val(str);
}
//==========================end of company Offices(fill city dropdown on state change)====================
//==================material_and_model.aspx=====================================

var selectedRows = [];
// this will hide gird chk boxex
function hidechkboxgvallL5() {
    var grid = $("#<%= gvallL5.ClientID %>");
    $('.cbox').hide();
    $("#cb_" + grid[0].id).hide();
}
//
// store the selected row in array for persisting/restoring
//
function rowSelected(rowID, isSelected) {

    selectedRows[rowID] = isSelected;

    updateSelectedRowsHidden();
    //printSelectedElements();
}
//
// prints the currently selected rows on the screen
//
//        function printSelectedElements() {
//            $("#listOfSelectedRows").html("");
//            for (var row in selectedRows) {
//                if (selectedRows[row])
//                    $("#listOfSelectedRows").append(row + ",");
//            }
//        }
//

// update a hidden field on the page with selected rows, so that they are available after postback
//
function updateSelectedRowsHidden() {

    var selectedValues = "";

    for (var row in selectedRows) {
        if (selectedRows[row])
            selectedValues = selectedValues + row + ",";
    }
    document.getElementById('ctl00_ctl00_main_main_hdl5').value = selectedValues;
}
//
// restore the selected rows state when the grid loads after paging, sorting, filtering
//
function restoreSelectedRows() {
    var grid = $("#<%= gvallL5.ClientID %>");
    for (var row in selectedRows) {
        if (selectedRows[row])
            grid.setSelection(row);
    }
}
//===========end material_and_model.aspx==========================

//===================vendorDiscountTaxL4.aspx====================================

var selectedRows = [];
// this will hide gird chk boxex
function hidechkboxgvVendorManufacturerLevel4() {
    var grid = $("#<%= gvVendorManufacturerLevel4.ClientID %>");
    $('.cbox').hide();
    $("#cb_" + grid[0].id).hide();
}
//
// store the selected row in array for persisting/restoring
//
function rowSelectedgvVendorManufacturerLevel4(rowID, isSelected) {

    selectedRows[rowID] = isSelected;

    updateSelectedRowsHiddengvVendorManufacturerLevel4();
    //printSelectedElements();
}
//
// prints the currently selected rows on the screen
//
//        function printSelectedElements() {
//            $("#listOfSelectedRows").html("");
//            for (var row in selectedRows) {
//                if (selectedRows[row])
//                    $("#listOfSelectedRows").append(row + ",");
//            }
//        }
//

// update a hidden field on the page with selected rows, so that they are available after postback
//
function updateSelectedRowsHiddengvVendorManufacturerLevel4() {

    var selectedValues = "";

    for (var row in selectedRows) {
        if (selectedRows[row]) {

            // row = row.split("_");

            selectedValues = selectedValues + row + ",";

        }
    }

    document.getElementById('ctl00_ctl00_main_main_hdl4').value = selectedValues;
}
//
// restore the selected rows state when the grid loads after paging, sorting, filtering
//
function restoreSelectedRowsgvVendorManufacturerLevel4() {
    var grid = $("#<%= gvVendorManufacturerLevel4.ClientID %>");
    for (var row in selectedRows) {
        if (selectedRows[row])
            grid.setSelection(row);
    }
}
//===========end vendorDiscountTaxL4.aspx=============================

//===================vendorDiscountTaxL5.aspx====================================

var selectedRows1 = [];
// this will hide gird chk boxex
function hidechkboxgvVendorManufacturerLevel5() {
    var grid = $("#<%= gvVendorManufacturerLevel5.ClientID %>");
    $('.cbox').hide();
    $("#cb_" + grid[0].id).hide();
}
//
// store the selected row in array for persisting/restoring
//
function rowSelectedgvVendorManufacturerLevel5(rowID, isSelected) {

    selectedRows1[rowID] = isSelected;

    updateSelectedRowsHiddengvVendorManufacturerLevel5();
    //printSelectedElements();
}
//
// prints the currently selected rows on the screen
//
//        function printSelectedElements() {
//            $("#listOfSelectedRows").html("");
//            for (var row in selectedRows) {
//                if (selectedRows[row])
//                    $("#listOfSelectedRows").append(row + ",");
//            }
//        }
//

// update a hidden field on the page with selected rows, so that they are available after postback
//
function updateSelectedRowsHiddengvVendorManufacturerLevel5() {

    var selectedValues1 = "";

    for (var row in selectedRows1) {
        if (selectedRows1[row])
            selectedValues1 = selectedValues1 + row + ",";
    }

    document.getElementById('ctl00_ctl00_main_main_hdl5').value = selectedValues1;
}
//
// restore the selected rows state when the grid loads after paging, sorting, filtering
//
function restoreSelectedRowsgvVendorManufacturerLevel5() {
    var grid = $("#<%= gvVendorManufacturerLevel5.ClientID %>");
    for (var row in selectedRows1) {
        if (selectedRows1[row])
            grid.setSelection(row);
    }
}
//===========end vendorDiscountTaxL5.aspx=============================

function vendorDiscount() {
    if (document.getElementById('ctl00_ctl00_main_main_txtdiscount').value == '') {

        alert("Please enter discount value");
        return false;
    }
    //var rdolist = document.getElementsByName("ctl00_ctl00_main_main_rblDiscountOption");
    var rdolist_0 = document.getElementById("ctl00_ctl00_main_main_rblDiscountOption_0");
    var rdolist_1 = document.getElementById("ctl00_ctl00_main_main_rblDiscountOption_1");


    if (rdolist_0.checked) {
        return checkSelectedIds('ctl00_ctl00_main_main_hdl4', 'Please select atleast one L4');
        //alert("L4");
    }
    if (rdolist_1.checked) {
        return checkSelectedIds('ctl00_ctl00_main_main_hdl5', 'Please select atleast one L5');
        //alert("L5");
    }
}

function vendorTax() {
    //var rdolist = document.getElementsByName("ctl00_ctl00_main_main_rblDiscountOption");
    var rdolist_0 = document.getElementById("ctl00_ctl00_main_main_rblDiscountOption_0");
    var rdolist_1 = document.getElementById("ctl00_ctl00_main_main_rblDiscountOption_1");


    if (rdolist_0.checked) {

        var str = checkSelectedIds('ctl00_ctl00_main_main_hdl4', 'Please select atleast one L4');
        if (str == true) {
            var l4 = document.getElementById("ctl00_ctl00_main_main_hdl4").value;
            popup('vendorTax/4/' + l4, 1004, 800);
            return false;
        }
        else {
            return false;
        }
        //alert("L4");
    }
    if (rdolist_1.checked) {
        var str = checkSelectedIds('ctl00_ctl00_main_main_hdl5', 'Please select atleast one L5');
        if (str == true) {
            var l5 = document.getElementById("ctl00_ctl00_main_main_hdl5").value;
            popup('vendorTax/5/' + l5, 1004, 800);
            return false;
        }
        else {
            return false;
        }
    }
}
//================================================================================
function hidechkboxgvallTax() {
    var grid = $("#<%= gvVendorTaxAll.ClientID %>");
    $('.cbox').hide();
    $("#cb_" + grid[0].id).hide();
}
//==============================================================================
function goToNext() {
    var from = "login";

    var s = document.getElementById("ctl00_ctl00_main_left_l1").text;
    if (s != 'Register as Vendor') {
        var str = s[9].split("Login as ");
        location.href = DOMAIN + "member/Default.aspx?type=" + str + "&from=" + from;
    }
    else {
        //alert('hi');
        //location.href = "<%= DOMAIN %>Default4.aspx";
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        }
        else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }

        if (xmlhttp != null) {
            xmlhttp.onreadystatechange = function() {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {

                    var res = xmlhttp.responseText.toString();

                    if (res == 'Valid') {

                        alert('Sucessfully Updated');
                        document.getElementById("ctl00_ctl00_main_left_l1").text = "Login as Vendor";
                        var s = document.getElementById("ctl00_ctl00_main_l1").text;
                        //alert(s);
                        if (s != 'Register as Vendor') {
                            var str = s[9].split("Login as ");
                            location.href = DOMAIN + "member/Default.aspx?type=" + str + "&from=" + from;
                        }
                        //                                           
                    }
                    else {
                        alert(res);
                        //document.getElementById("txtHint").innerHTML = "";
                    }
                }
            }
            xmlhttp.open("GET", DOMAIN + "member/memberRegisterAsVendor.aspx", true);
            xmlhttp.send();
        }
        else {

            alert("The XMLHttpRequest not supported");
            //document.getElementById("txtHint").innerHTML = "";
        }

    }
}
//=================================================================
function goToManufacturer() {
    var from = "login";

    var s = document.getElementById("ctl00_ctl00_main_left_lM").text;
    if (s == 'Login as Manufacturer') {
        // var str = s[9].split("Login as ");
        location.href = DOMAIN + "member/Default.aspx?type=M&from=" + from;
    }
    else {
        //alert('hi');
        //location.href = "<%= DOMAIN %>Default4.aspx";
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        }
        else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }

        if (xmlhttp != null) {
            xmlhttp.onreadystatechange = function() {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {

                    var res = xmlhttp.responseText.toString();

                    if (res == 'Valid') {

                        alert('Sucessfully Updated');
                        location.href = DOMAIN + "member/Default.aspx?type=M&from=" + from;
                        //document.getElementById("ctl00_ctl00_main_left_lM").visible = true;
                        //                        var s = document.getElementById("ctl00_ctl00_main_l1").text;
                        //                        //alert(s);
                        //                        if (s != 'Register as Vendor') {
                        //                            var str = s[9].split("Login as ");
                        //                            location.href = DOMAIN + "member/Default.aspx?type=" + str + "&from=" + from;
                        //                        }
                        //                                           
                    }
                    else {
                        alert(res);
                        //document.getElementById("txtHint").innerHTML = "";
                    }
                }
            }
            xmlhttp.open("GET", DOMAIN + "member/memberRegisterAsOtherMemberType.aspx?type=2", true);
            xmlhttp.send();
        }
        else {

            alert("The XMLHttpRequest not supported");
            //document.getElementById("txtHint").innerHTML = "";
        }

    }
}
//=================================================================
function goToVendor() {
    var from = "login";

    var s = document.getElementById("ctl00_ctl00_main_left_lV").text;
    if (s == 'Login as Vendor') {
       // var str = s[9].split("Login as ");
        location.href = DOMAIN + "member/Default.aspx?type=V&from=" + from;
    }
    else {
        //alert('hi');
        //location.href = "<%= DOMAIN %>Default4.aspx";
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        }
        else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }

        if (xmlhttp != null) {
            xmlhttp.onreadystatechange = function() {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {

                    var res = xmlhttp.responseText.toString();

                    if (res == 'Valid') {

                        alert('Sucessfully Updated');
                        location.href = DOMAIN + "member/Default.aspx?type=V&from=" + from;
                        //document.getElementById("ctl00_ctl00_main_left_lV").visible = true;
//                        var s = document.getElementById("ctl00_ctl00_main_l1").text;
//                        //alert(s);
//                        if (s != 'Register as Vendor') {
//                            var str = s[9].split("Login as ");
//                            location.href = DOMAIN + "member/Default.aspx?type=" + str + "&from=" + from;
//                        }
                        //                                           
                    }
                    else {
                        alert(res);
                        //document.getElementById("txtHint").innerHTML = "";
                    }
                }
            }
            xmlhttp.open("GET", DOMAIN + "member/memberRegisterAsOtherMemberType.aspx?type=3", true);
            xmlhttp.send();
        }
        else {

            alert("The XMLHttpRequest not supported");
            //document.getElementById("txtHint").innerHTML = "";
        }

    }
}

//=================================================================
function goToArchitect() {
    var from = "login";
    
    var s = document.getElementById("ctl00_ctl00_main_left_lA").text;
    if (s == 'Login as Architect') {
        // var str = s[9].split("Login as ");
        location.href = DOMAIN + "member/Default.aspx?type=A&from=" + from;
    }
    else {
        //alert('hi');
        //location.href = "<%= DOMAIN %>Default4.aspx";
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        }
        else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }

        if (xmlhttp != null) {
            xmlhttp.onreadystatechange = function() {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {

                    var res = xmlhttp.responseText.toString();

                    if (res == 'Valid') {

                        alert('Sucessfully Updated');
                        location.href = DOMAIN + "member/Default.aspx?type=A&from=" + from;
                        //document.getElementById("ctl00_ctl00_main_left_lA").visible = true;
                        //                        var s = document.getElementById("ctl00_ctl00_main_l1").text;
                        //                        //alert(s);
                        //                        if (s != 'Register as Vendor') {
                        //                            var str = s[9].split("Login as ");
                        //                            location.href = DOMAIN + "member/Default.aspx?type=" + str + "&from=" + from;
                        //                        }
                        //                                           
                    }
                    else {
                        alert(res);
                        //document.getElementById("txtHint").innerHTML = "";
                    }
                }
            }
            xmlhttp.open("GET", DOMAIN + "member/memberRegisterAsOtherMemberType.aspx?type=5", true);
            xmlhttp.send();
        }
        else {

            alert("The XMLHttpRequest not supported");
            //document.getElementById("txtHint").innerHTML = "";
        }

    }
}

//==================user_masterlist.aspx=====================================

var selectedRows = [];
// this will hide gird chk boxex
function hidechkboxgvallManufacturer5() {
    var grid = $("#<%= gvallManufacturer5.ClientID %>");
    $('.cbox').hide();
    $("#cb_" + grid[0].id).hide();
}
//
// store the selected row in array for persisting/restoring
//
function rowSelected(rowID, isSelected) {

    selectedRows[rowID] = isSelected;

    updateSelectedRowsHidden();
    //printSelectedElements();
}
//
// prints the currently selected rows on the screen
//
//        function printSelectedElements() {
//            $("#listOfSelectedRows").html("");
//            for (var row in selectedRows) {
//                if (selectedRows[row])
//                    $("#listOfSelectedRows").append(row + ",");
//            }
//        }
//

// update a hidden field on the page with selected rows, so that they are available after postback
//
function updateSelectedRowsHidden() {

    var selectedValues = "";

    for (var row in selectedRows) {
        if (selectedRows[row])
            selectedValues = selectedValues + row + ",";
    }
    document.getElementById('ctl00_ctl00_main_main_hd_level4_id_company_id').value = selectedValues;
}
//
// restore the selected rows state when the grid loads after paging, sorting, filtering
//
function restoreSelectedRows() {
    var grid = $("#<%= gvallL5.ClientID %>");
    for (var row in selectedRows) {
        if (selectedRows[row])
            grid.setSelection(row);
    }
}
//===========end user_masterlist.aspx==========================


           
    

