﻿var UI_DateFormat = "MM/dd/yyyy";
var UI_DataTimeFormat = "MM/dd/yyyy HH:mm";

function NavCss() {
    var title = $("title").html();
    if (title == "SSW_Home") {
        $(".navline li a").eq(0).attr("class", "menu_home_on");
    } else {
        $(".navline li a").eq(0).attr("class", "menu_home_a");
    }
    if (title == "SSW_About Us") {
        $(".navline li a").eq(1).attr("class", "menu_aboutus_on");
    } else {
        $(".navline li a").eq(1).attr("class", "menu_aboutus_a");
    }
    if (title == "SSW_Our work") {
        $(".navline li a").eq(2).attr("class", "menu_ourwork_on");
    } else {
        $(".navline li a").eq(2).attr("class", "menu_ourwork_a");
    }
    if (title == "SSW_Subs / Vendors" || title == "SSW_Bid List" || title == "SSW_FTP Browser") {
        $(".navline li a").eq(3).attr("class", "menu_subsvendors_on");
    } else {
        $(".navline li a").eq(3).attr("class", "menu_subsvendors_a");
    }
    if (title == "SSW_Contact us") {
        $(".navline li a").eq(4).attr("class", "menu_contactus_on");
    } else {
        $(".navline li a").eq(4).attr("class", "menu_contactus_a");
    }
}
//for index page flash
var t = n = count = 0;
function BigPicFlash() {
    $(".homeads a").css("cursor", "pointer");
    count = $(".bigpic img").size();
    $(".bigpic img").not(":first").hide();
    $(".dots a img:first").attr("src", "images/dot_on.gif");
    $(".dots a").each(function(i) {
        $(this).attr("name", "" + (i + 1) + "")
    });
    $(".bigpic img").each(function(i) {
        $(this).attr("name", "" + (i + 1) + "")
    });
    $(".dots a").click(function() {
        var i = $(this).attr("name") - 1;
        n = i;
        if (i >= count) return;
        $(".bigpic img").filter(":visible").fadeOut(500).parent().children().eq(i).fadeIn(1000);
        $(this).children("img").attr("src", "images/dot_on.gif");
        $(this).parent("span").siblings().children("a").children("img").attr("src", "images/dot_a.gif");
    });
    $(".btn_leftbutton_a").click(function() {
        var num = $(".bigpic img").filter(":visible").attr("name");
        $(".dots a").eq(num - 2).trigger('click');
    });
    $(".btn_rightbutton_a").click(function() {
        var num = $(".bigpic img").filter(":visible").attr("name");
        if (num == count) {
            $(".dots a").eq(0).trigger('click');
        } else {
            $(".dots a").eq(num).trigger('click');
        }
    });
    //here is control to auto change pocture
    //    t = setInterval("showAuto()", 5000);
    //	$(".bigpic").hover(function(){clearInterval(t)}, function(){t = setInterval("showAuto()", 5000);});

}
function showAuto() {
    n = n >= (count - 1) ? 0 : n + 1;
    $(".dots a").eq(n).trigger('click');
}

//for index page flash end


///   datepickter function
function usedatepickter(id) {
    $('#' + id + '').DatePicker({
        format: 'm/d/Y',
        date: $('#' + id + '').val(),
        current: $('#' + id + '').val(),

        starts: 1,
        position: 'r',
        onBeforeShow: function() {
            $('#' + id + '').DatePickerSetDate($('#' + id + '').val(), true);
        },
        onChange: function(formated, dates) {
            $('#' + id + '').val(formated);
            $('#' + id + '').DatePickerHide();

        }
    });
}


//Download FTPsource for biddetail page
function Ftpsource(path,title) {
    var cont = GetPageContent("/FtpResource.aspx?title=" + title);
    showLightBox('', cont, 750, 380, 'Ftp Resource', '', '');
    $("#lb_close_btn").click(function() {
        hideLightBox();
    });
    changelightboxstyle();
    ///add ftplogon function
//    $(".ubox #txtuname").focus(function() {
//        $(this).attr("value","");
//    });
//    $('.pbox input[name=paswd]').focus(function() {
//        $(".pbox").children().toggle();
//        $('.pbox input[name=password]').focus();
//    });

//    $('.pbox input[name=password]').focus(function() {
//        $(this).attr("value", "");
//    });
//    
//    $('.pbox input[name=password]').blur(function() {
//    var pwd = $('.pbox input[name=password]').val();
//        //去掉回车空格
//        pwd = pwd.replace(/(^\s*)|(\s*$)/g, "");
//        if (pwd == null || pwd == "")
//            $(".pbox").children().toggle();
//    });
    ///add ftplogon function end
    
    GetFTPListByPath(path);
}
function GetFTPListByPath(path) {
    $("#select_resource tr td").hover(
                function() {
                    $(this).css("background-color", "#f0f0f0");
                },
                function() {
                $(this).css("background-color", "#E5E2DB");
                }
            );
    var historyPath = path;
    $("#hdn_path").val(path);
    var currentpath = "";
    if (path != "") {
        var arrpath = new Array();
        var currentpathfile = "";
        if (historyPath.indexOf(".") > -1) {
            arrpath = historyPath.split("/");
            currentpathfile = arrpath.pop();
            historyPath = "/";
            for (var i = 1; i < arrpath.length; i++) {
                historyPath = historyPath + arrpath[i] + "/";
            }
            $("#select_resource").append("<tr><td>" + currentpathfile + "</td></tr>");
            $("#hdn_historyPath").val(historyPath);
            $("#hdn_currentpath").val(currentpathfile);
            BindFTPListForDetailpage();
            $("#l_historyPath").hide();

        } else {
        historyPath = historyPath.replace("Root", "");
            showLoadingMessage();
            $.ajax({
                type: "POST",
                url: "/WebService/BidWebService.asmx/GetFileList",
                data: "{ 'historyPath': '" + historyPath + "', 'currentpath': '" + currentpath + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(result) {
                    for (var i = 0; i < result.d.length; i++) {
                        var str = result.d[i];
                        $("#select_resource").append("<tr><td>" + str + "</td></tr>");
                    }
                    historyPath = historyPath.replace(path, "/");
                    pathLink(historyPath, currentpath);
                    BindFTPListForDetailpage(path);
                    hideLoadingMessage();

                },
                error: function(err) {
                    alert(err.statusText + err.responseText);
                    hideLoadingMessage();
                }

            });
        }
    }
}

function BindFTPListForDetailpage(path) {
    $("#select_resource tr:even td").attr("class", "rowa");
    $("#select_resource tr:odd td").attr("class", "rowb");

    $("#select_resource tr td").each(function() {
        $(this).click(function() {
            var historyPath = $("#hdn_historyPath").val().trim();
            var currentpath = $("#hdn_currentpath").val().trim();
            selectvalue = $(this).html();

            if (selectvalue.indexOf(".") > -1) {
                if (path == undefined) {

                } else {
                    //historyPath = path + historyPath;
                    if (historyPath.indexOf("//") > -1) {
                        historyPath = historyPath.replace("//", "/");
                    }
                }
                $.ajax({
                    type: "POST",
                    url: "/WebService/BidWebService.asmx/DownloadFile",
                    data: "{ 'historyPath': '" + historyPath + "', 'currentpath': '" + selectvalue + "'}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function(result) {
                        hideLoadingMessage();
                        location = ("/FTPHandler.ashx?data=" + result.d);
                    },
                    error: function(err) {
                        //alert(err.statusText + err.responseText);
                        hideLoadingMessage();
                    }

                });
            } else {
                historyPath =historyPath + selectvalue.trim() + "/";
                currentpath = "";
                if (historyPath.indexOf("//") > -1) {
                    historyPath = historyPath.replace("//", "/");
                }

                showLoadingMessage();
                $.ajax({
                    type: "POST",
                    url: "/WebService/BidWebService.asmx/GetFileList",
                    data: "{ 'historyPath': '" + historyPath + "', 'currentpath': '" + currentpath + "'}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function(result) {
                        $("#select_resource").html("");
                        for (var i = 0; i < result.d.length; i++) {
                            var str = result.d[i];
                            $("#select_resource").append("<tr><td>" + str + "</td></tr>");
                        }
                        historyPath = historyPath.replace(path, "/");
                        if (historyPath.indexOf("//") > -1) {
                            historyPath = historyPath.replace("//", "/");
                        }
                        pathLink(historyPath, currentpath);
                        BindFTPListForDetailpage(path);
                        hideLoadingMessage();
                    },
                    error: function(err) {
                        alert(err.statusText + err.responseText);
                        hideLoadingMessage();
                    }

                });

            }
        });
    });

}
function backUpLevel() {
    var path = $("#hdn_path").val();
    if (path.indexOf(".") > -1) {

    } else {
        var historyPath = $("#hdn_historyPath").val();
        if (path.replace("Root", "") == historyPath) {
            alert("you don't have the Permission.");
        } else {
            var arr = new Array();
            arr = historyPath.split("/");
            arr.pop();
            arr.pop();
            historyPath = "/";
            for (var i = 1; i < arr.length; i++) {
                historyPath = historyPath + arr[i] + "/";
            }

            //historyPath = path + historyPath;
            if (historyPath.indexOf("//") > -1) {
                historyPath = historyPath.replace("//", "/");
            }
            var currentpath = "";


            showLoadingMessage();
            $.ajax({
                type: "POST",
                url: "/WebService/BidWebService.asmx/GetFileList",
                data: "{ 'historyPath': '" + historyPath + "', 'currentpath': '" + currentpath + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(result) {
                    $("#select_resource").html("");
                    for (var i = 0; i < result.d.length; i++) {
                        var str = result.d[i];
                        $("#select_resource").append("<tr><td>" + str + "</td></tr>");
                    }
                    historyPath = historyPath.replace(path, "/");
                    pathLink(historyPath, currentpath);
                    BindFTPListForDetailpage(path);
                    hideLoadingMessage();
                },
                error: function(err) {
                    alert(err.statusText + err.responseText);
                    hideLoadingMessage();
                }

            });
        }
    }
}
function pathLink(historyPath, currentpath) {
    $("#hdn_historyPath").val(historyPath);
    var arr = new Array();
    arr = historyPath.split("/");
    arr.pop();
    currentpath = arr.pop();
    historyPath = "/";
    for (var i = 1; i < arr.length; i++) {
        historyPath += arr[i] + "/";
    }
        $("#l_historyPath").html("Root" + historyPath);
        $("#l_currentPath").html(currentpath);
    return false;
}
//Download FTPsource for biddetail page end
function changelightboxstyle() {
    var content = $(".lightbox_content").html();
    $("#V2editControl").html("");
    $("#V2editControl").html(content);
}

function jumptohomepage() {
    location = "index.aspx";
}
function logonForFtp() {
    var username = $('.txtuname').val();
    var password = $('.txtpwd').val();
    
    $.ajax({
        type: "POST",
        url: "/WebService/BidWebService.asmx/CheckFtpUser",
        data: "{ 'username': '" + username + "', 'password': '" + password + "'}",
        contentType: "application/json; charset=utf-8",
        success: function(result) {
            if (result.d != "error") {
                $("#ctl00_ContentPlaceHolder1_FTPLogin").trigger("click");
            } else {
                alert("Invalid Username/Password");
            }
        },
        error: function(err) {
            alert(err.statusText + err.responseText);

        }
    });

}
function showloginform() {
    $(".ftplogonform").fadeIn(2000);
}
function hidelohinfrom() {
    $(".ftplogonform").fadeOut(1000);
}

