﻿// Yah! JS is the best!
var html = {
    init: function () {
        $('html').removeClass('no-js');
    }
};
var dropdowns = {
    init: function () {
        $('.sub').hide();
        $('#nav li').hover(
        function () {
            $(this).children('.sub').fadeIn('500').show();            
        }, function () {
            $(this).children('.sub').hide();
        });
    }
};
var formTable = {
    init: function () {

        // Step 2 - Ownership Information
        $('.add-row-ownership').click(function (e) {
            e.preventDefault;
            var random = Math.floor(Math.random() * 1000000)
            var howManyRows = 'a' + $('#ownership_information .textbox').length + random;
            $('#ownership_information').append('<tr class="form-table-row"><td><input class="textbox" id="ownershipinformation_' + howManyRows + '_text1" name="ownershipinformation_' + howManyRows + '_text1" type="text" value="" /><br class="clear" /><td><input class="textbox smallbox" id="ownershipinformation_' + howManyRows + '_text2" name="ownershipinformation_' + howManyRows + '_text2" type="text" value="" /></td><td><input class="textbox halfbox" id="ownershipinformation_' + howManyRows + '_text3" name="ownershipinformation_' + howManyRows + '_text3" type="text" value="" /></td><td class="remove"><a class="remove-row">Remove</a><input id="ownershipinformation_ID" name="ownershipinformation_ID" type="hidden" value="' + howManyRows + '" /><input id="ownershipinformation_' + howManyRows + '_fieldGroup" name="ownershipinformation_' + howManyRows + '_fieldGroup" type="hidden" value="ownershipinformation" /></td></tr>')
        });
        

        // Step 3. Parent / Affiliation Information
        $('.add-row-company').click(function () {
            var random = Math.floor(Math.random() * 1000000)
            var howManyRows = 'a' + $('#ownership_company .textbox').length + random;
            $('#ownership_company').append('<tr class="form-table-row"><td style="width:200px;"><input class="textbox halfbox" id="ParentCompany_' + howManyRows + '_text1" name="ParentCompany_' + howManyRows + '_text1" type="text" value="" /><td style="width:350px;"><input class="textbox" id="ParentCompany_' + howManyRows + '_text2" name="ParentCompany_' + howManyRows + '_text2" type="text" value="" /></td></td><td class="remove"><a class="remove-row">Remove</a><input id="ParentCompany_ID" name="ParentCompany_ID" type="hidden" value="' + howManyRows + '" /><input id="ParentCompany_' + howManyRows + '_fieldGroup" name="ParentCompany_' + howManyRows + '_fieldGroup" type="hidden" value="ParentCompany" /></td></tr>')
        });

        // Step 3. Union Affiliation
        $('.add-row-union').click(function () {
            var random = Math.floor(Math.random() * 1000000)
            var howManyRows = 'a' + $('#union .textbox').length + random;
            $('#union_name').append('<tr class="form-table-row"><td style="width:350px;"><input class="textbox" id="UnionAffiliation_ad16' + howManyRows + '_text1" name="UnionAffiliation_ad16' + howManyRows + '_text1" type="text" value="" /></td><td><a class="remove-row">Remove</a><input id="UnionAffiliation_ID" name="UnionAffiliation_ID" type="hidden" value="ad16' + howManyRows + '" /><input id="UnionAffiliation_ad16' + howManyRows + '_fieldGroup" name="UnionAffiliation_ad16' + howManyRows + '_fieldGroup" type="hidden" value="UnionAffiliation" /></td></tr>')
        });

        // Step 3. Minority Certifications
        $('.add-row-minority').click(function () {
            var random = Math.floor(Math.random() * 1000000)
            var howManyRows = 'a' + $('#minority_certfications .textbox').length + random;
            $('#minority_certfications').append('<tr class="form-table-row"><td style="width:330px;"><input class="textbox mediumbox" id="MinorityCertification_a16a' + howManyRows + '_text1" name="MinorityCertification_a16a' + howManyRows + '_text1" type="text" value="" /></td><td style="width:150px;"><input class="textbox mediumbox" id="MinorityCertification_a16a' + howManyRows + '_text2" name="MinorityCertification_a16a' + howManyRows + '_text2" type="text" value="" /></td><td style="width:95px;"><input class="textbox smallbox" id="MinorityCertification_a16a' + howManyRows + '_text3" name="MinorityCertification_a16a' + howManyRows + '_text3" type="text" value="" /></td><td><input class="textbox smallbox" id="MinorityCertification_a16a' + howManyRows + '_text4" name="MinorityCertification_a16a' + howManyRows + '_text4" type="text" value="" /></td><td class="remove"><a class="remove-row">Remove</a><input id="MinorityCertification_ID" name="MinorityCertification_ID" type="hidden" value="a16a' + howManyRows + '" /><input id="MinorityCertification_a16a' + howManyRows + '_fieldGroup" name="MinorityCertification_a16a' + howManyRows + '_fieldGroup" type="hidden" value="MinorityCertification" /></td></tr>')
        });

        
        $('.add-row-licenses').click(function () {
            var random = Math.floor(Math.random() * 1000000)
            var howManyRows = 'a' + random;
            $('#licenses').append('<tr class="form-table-row"><td><input class="textbox mediumbox" id="License_' + howManyRows + '_text1" name="License_' + howManyRows + '_text1" type="text" value="" /><br class="clear" /></td><td><input class="textbox mediumbox" id="License_' + howManyRows + '_text2" name="License_' + howManyRows + '_text2" type="text" value="" /></td><td><input class="textbox smallbox" id="License_' + howManyRows + '_text3" name="License_' + howManyRows + '_text3" type="text" value="" /><br class="clear" /></td><td><input class="textbox smallbox" id="License_' + howManyRows + '_text4" name="License_' + howManyRows + '_text4" type="text" value="" /><br class="clear" /><td><td class="remove"><a class="remove-row">Remove</a><input id="License_ID" name="License_ID" type="hidden" value="' + howManyRows + '" /><input id="License_' + howManyRows + '_fieldGroup" name="License_' + howManyRows + '_fieldGroup" type="hidden" value="License" /></td></tr>')
        })
        $('.add-row-geographic').click(function () {
            var random = Math.floor(Math.random() * 1000000)
            var howManyRows = 'a' + random;
            $('#geographic_regions').append('<tr class="form-table-row"><td><input type="text" id="_preWorkPerformed1' + howManyRows + '"' + '"class="textbox" style="width:100%;" /></td><td class="remove"><a class="remove-row">Remove</a></td></tr>')

        })
        $('.add-row-customer').click(function () {
            var random = Math.floor(Math.random() * 1000000)
            var howManyRows = 'a' + random;
            $('#customer_references').append('<tr class="form-table-row"><td><input class="textbox mediumbox" id="CustomerReference' + howManyRows + '_text1" name="CustomerReference_' + howManyRows + '_text1" type="text" value="" /><br class="clear" /></td><td><input class="textbox smallbox" id="CustomerReference_' + howManyRows + '_text2" name="CustomerReference_' + howManyRows + '_text2" type="text" value="" /></td><td><input class="textbox smallbox" id="CustomerReference_' + howManyRows + '_text3" name="CustomerReference_' + howManyRows + '_text3" type="text" value="" /></td><td><input class="textbox smallbox" id="CustomerReference_' + howManyRows + '_text5" name="CustomerReference_648' + howManyRows + '_text5" type="text" value="" /></td><td class="remove"><a class="remove-row">Remove</a><input id="CustomerReference_ID" name="CustomerReference_ID" type="hidden" value="648' + howManyRows + '" /><input id="CustomerReference_648' + howManyRows + '_fieldGroup" name="CustomerReference_648' + howManyRows + '_fieldGroup" type="hidden" value="CustomerReference" /></td></tr>')
        })
        $('.add-row-trade').click(function () {
            var random = Math.floor(Math.random() * 1000000)
            var howManyRows = 'a' + random;
            $('#trade_customer_references').append('<tr class="form-table-row"><td><input class="textbox mediumbox" id="TradeCustomerReference_' + howManyRows + '_text1" name="TradeCustomerReference_' + howManyRows + '_text1" type="text" value="" /><br class="clear" /></td><td><input class="textbox smallbox" id="TradeCustomerReference_' + howManyRows + '_text2" name="TradeCustomerReference_' + howManyRows + '_text2" type="text" value="" /></td><td><input class="textbox smallbox" id="TradeCustomerReference_' + howManyRows + '_text3" name="TradeCustomerReference_' + howManyRows + '_text3" type="text" value="" /></td><td><input class="textbox smallbox" id="TradeCustomerReference_' + howManyRows + '_text5" name="TradeCustomerReference_' + howManyRows + '_text5" type="text" value="" /></td><td class="remove"><input id="TradeCustomerReference_ID" name="TradeCustomerReference_ID" type="hidden" value="' + howManyRows + '" /><input id="TradeCustomerReference_' + howManyRows + '_fieldGroup" name="TradeCustomerReference_' + howManyRows + '_fieldGroup" type="hidden" value="TradeCustomerReference" /><a class="remove-row">Remove</a></td></tr>')
        })
        $('.add-row-contactor').click(function () {
            var random = Math.floor(Math.random() * 1000000)
            var howManyRows = 'a' + random;
            $('#general_contractor').append('<tr class="form-table-row"><td><input class="textbox mediumbox" id="GeneralContractorReference_' + howManyRows + '_text1" name="GeneralContractorReference_' + howManyRows + '_text1" type="text" value="" /><br class="clear" /></td><td><input class="textbox smallbox" id="GeneralContractorReference_' + howManyRows + '_text2" name="GeneralContractorReference_' + howManyRows + '_text2" type="text" value="" /></td><td><input class="textbox smallbox" id="GeneralContractorReference_' + howManyRows + '_text3" name="GeneralContractorReference_' + howManyRows + '_text3" type="text" value="" /></td><td><input class="textbox smallbox" id="GeneralContractorReference_' + howManyRows + '_text5" name="GeneralContractorReference_' + howManyRows + '_text5" type="text" value="" /></td><td class="remove"><a class="remove-row">Remove</a><input id="GeneralContractorReference_ID" name="GeneralContractorReference_ID" type="hidden" value="' + howManyRows + '" /><input id="GeneralContractorReference_' + howManyRows + '_fieldGroup" name="GeneralContractorReference_' + howManyRows + '_fieldGroup" type="hidden" value="GeneralContractorReference" /></td></tr>')
        })


        // Removes Row
        $('.remove-row').live("click", function () {
            $(this).parents('tr, em').remove();
        });

        //Remove Final Border
        $('.form-table .form-table-row:last td').addClass('noborder');
    }
};
var loadingimg = {
    init: function () {
        $('.button, .save-add').click(function () {
            $('.ajax-loader').show();
            setTimeout(function () {
                $(".ajax-loader").hide()
            }, 3000);
        });
    }
};
var save = {
    init: function () {
        $('div.save').delay(200).fadeIn(700);
    }
}
var tabs = {
    init: function () {
        $(".tab_content").hide();
        $("ul.tabs li:first").addClass("active").show();
        $(".tab_content:first").show();

        $("ul.tabs li").click(function () {
            $("ul.tabs li").removeClass("active");
            $(this).addClass("active");
            $(".tab_content").hide();
            var activeTab = $(this).find("a").attr("href");
            $(activeTab).fadeIn();
            return false;
        });
    }
};
var services = {
    init: function () {        
        function highlight(e) {
            $(e).css({ backgroundColor: "#a5d2ff" }).animate({ backgroundColor: "#fff" }, 1500);
        }
        
        var url = window.location.hash;
        if (url == ("#GP")) {
            highlight(".dtgp, .ddgp");
        }
       
        $('a.de').click(function () { highlight(".dtde, .ddde"); });
        $('a.cs').click(function () { highlight(".dtcs, .ddcs"); });
        $('a.ve').click(function () { highlight(".dtve, .ddve"); });
        $('a.pm').click(function () { highlight(".dtpm, .ddpm"); });
        $('a.pf').click(function () { highlight(".dtpf, .ddpf"); });
        $('a.in').click(function () { highlight(".dtin, .ddin"); });
        $('a.gp').click(function () { highlight(".dtgp, .ddgp"); });
    }
};
var toggler = {
    init: function () {
        $('body').click(function () {
            $('#login-utility ul').removeClass('toggle');
            $('#login-utility').removeClass('login-toggle');
        });
        $('.login-account').click(function (e) {
            $('#login-utility ul').addClass('toggle');
            $('#login-utility').addClass('login-toggle');
            e.stopPropagation();
            e.preventDefault();
        });
    }
};
// Ready set init!
function initialize() {
    html.init();
    dropdowns.init();
    formTable.init();
    loadingimg.init();
    save.init();
    tabs.init();
    services.init();
    toggler.init();
}

$(function () {
    initialize();
});
