﻿/// <reference name="MicrosoftAjax.js"/>
/// <reference path="~/Scripts/jquery-1.3.2-vsdoc2.js" />
/// <reference path="~/Scripts/005.jquery-blockUI.2.31.min.js" />
/// <reference path="~/Scripts/010.jquery-impromptu.3.0.min.js" />
/// <reference path="~/Scripts/020.jquery-alphanumeric.min.js" />
/// <reference path="~/Scripts/025.jquery-queryString.2.1.7.min.js" />
/// <reference path="~/Scripts/015.jquery-jgrowl.1.2.4.min.js" />
/// <reference path="~/Scripts/jquery.tooltip.min.js" />
/// <reference path="~/Scripts/160.Main.min.js" />
/// <reference path="~/WS/wsTD.asmx" />

var winH = "";
var winW = "";
var blank = new Image();
blank.src = 'Img/Common/cp.gif';

function fixPng(png)
{
    // get src
    var src = png.src;
    // set width and height
    if (!png.style.width) { png.style.width = $(png).width(); }
    if (!png.style.height) { png.style.height = $(png).height(); }
    // replace by blank image
    png.onload = function() { };
    png.src = blank.src;
    // set filter (display original image)
    png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
}
 function getWinSize()
 {
    winH = $(window).height();
    winW = $(window).width();
 }
function Mid(String, Start, Length) {
    if (String === null) {
        return false;
    }

    if (Start > String.length) {
        return '';
    }

    if (Length === null || Length.length == 0) {
        return false;
    }

    return String.substr((Start - 1), Length);
}
function doFilterRedir(id) {
    doFindOnPage(id);
}

function doFindOnPage(id) {
    clearPopUp();
    $.blockUI();
    $("#hidFindProd").val(id);
    __doPostBack('cmdFindProd', '');
}

function reloadPage(addInfo, clear)
{
    clearPopUp(true);
    //$.blockUI();
    var info = $.query.get("aInfo");

    while (info != "") {
        $.query.REMOVE("aInfo");
        info = $.query.get("aInfo");
    }
    var qs = $.query.toString();
    var page = "";
    var cp = $.query.get("cPage");
    if (cp == "") {
        if ($("#DgPager1_pn").val() > 1) {
            page = (qs.length > 0 ? '&' : '?') + 'cPage=' + eval($("#DgPager1_pn").val() - 1);
        }
    }
    var ai = "";
    if (addInfo) {
        ai = (qs.length > 0 ? '&' : '?') + 'aInfo=' + addInfo;
    }
    
        var linkURL = "";
        var doc = location.href;
        if (location.search) {
            var callingURL = location.href;
            if (callingURL.indexOf('?') != -1) {
                linkURL = callingURL.substring(callingURL.indexOf('?') + 1, callingURL.length);
                doc = Mid(callingURL, 1, (callingURL.length - linkURL.length - 1));
            }
        }
    
    if (jQuery.browser.safari) {
        document.location.href = doc + qs + page + ai;
    } else {
        window.location.replace(doc + qs + page + ai);
    }
    
}
function ShowMD(title, src, width, height, top, showClose) {
    getWinSize();
    clearPopUp();
    var sc = true;
    if (showClose == false)
    {
        sc = false;
    }
    if (width + 15 > winW)
    {
        width = winW - 15;
    }
    if (top != null)
    {
        if ((height + top + 15) > winH)
        {
            height = winH - top - 15;
        }
    } else
    {
        if ((height + 35) > winH)
        {
            height = winH - 35;
        }
    }
    height -= 5;
    var titleH = "23px";
    if (title == "" || title == null) {
        titleH = "0px";
    }
    var rn = Math.floor(Math.random() * 1000);
    var dId = 'divBUIPU' + rn;
    //var dX = '<div id="' + dId + '" style="cursor: default;"><div id="divBUIPUHead" style="background-color: #404040; height: 23px; width: 100%;"><div style="float: right; width: 25px; height: 23px; padding: 2px;"><img id="aiClose" alt="Close" src="Images/CloseButton.gif" onclick="clearPopUp();" /></div><div style="width: 250px; text-align: left; padding-top: 3px;"><span style="font-weight: bold; color: White; padding: 3px; height: 23px; font-size: 10pt; text-align: left; font-family: Verdana;">' + title + '</span></div></div><iframe id="ifBUIPU" scrolling="no" height="' + height + '" width="' + width + '" src="' + src + '" frameborder="0"></iframe></div>';
    var dX = '<div id="' + dId + '" style="cursor: default; height: ' + height + 'px; width: ' + width + 'px;"><div id="divBUIPUHead" style="background-color: #404040; height: ' + titleH + '; width: 100%;"><div style="float: right; width: 25px; height: 19px; padding: 2px; text-align: right;"><img id="aiClose" alt="Close" onclick="clearPopUp();" src="Images/CloseButton.gif" /></div><div style="text-align: left; padding-top: 3px; float: left;"><span style="font-weight: bold; color: White; padding: 3px; height: 23px; font-size: 10pt; text-align: left; font-family: Verdana;">' + title + '</span></div></div><iframe id="ifBUIPU" frameborder="0" height="' + eval(height - 13) + '" scrolling="no" src="' + src + '" width="100%"></iframe></div>';
    $.blockUI({ message: dX, css: {
        width: width + 'px',
        height: eval(height + 10) + 'px',
        left: (winW - width) / 2 + 'px',
        top: ((top != null) ? top + 'px' : '20px')
        },
        focusInput: true,
        iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank', 
        forceIframe: true
    });
    if (sc == true)
    {
        $("#aiClose").show();
    } else {
        $("#aiClose").hide();
    }
} 
function ShowMessageDialog(title, htmlMessage, width, height, top, showClose) {
    getWinSize();
    clearPopUp();
    var sc = true;
    if (showClose == false)
    {
        sc = false;
    }
    if (width + 15 > winW)
    {
        width = winW - 15;
    }
    if (top != null)
    {
        if ((height + top + 15) > winH)
        {
            height = winH - top - 15;
        }
    } else
    {
        if ((height + 35) > winH)
        {
            height = winH - 35;
        }
    }
    height -= 5;
    var titleH = "23px";
    if (title == "" || title == null) {
        titleH = "0px";
    }
    var rn = Math.floor(Math.random() * 1000);
    var dId = 'divBUIPU' + rn;
    htmlMessage = unescape(htmlMessage);
    //var dX = '<div id="' + dId + '" style="cursor: default;"><div id="divBUIPUHead" style="background-color: #404040; height: 23px; width: 100%;"><div style="float: right; width: 25px; height: 23px; padding: 2px;"><img id="aiClose" alt="Close" src="Images/CloseButton.gif" onclick="clearPopUp();" /></div><div style="width: 250px; text-align: left; padding-top: 3px;"><span style="font-weight: bold; color: White; padding: 3px; height: 23px; font-size: 10pt; text-align: left; font-family: Verdana;">' + title + '</span></div></div><iframe id="ifBUIPU" scrolling="no" height="' + height + '" width="' + width + '" src="' + src + '" frameborder="0"></iframe></div>';
    var dX = '<div id="' + dId + '" style="cursor: default; height: ' + height + 'px; width: ' + width + 'px;"><div id="divBUIPUHead" style="background-color: #404040; height: ' + titleH + '; width: 100%;"><div style="float: right; width: 25px; height: 19px; padding: 2px; text-align: right;"><img id="aiClose" alt="Close" onclick="clearPopUp();" src="Images/CloseButton.gif" /></div><div style="text-align: left; padding-top: 3px; float: left;"><span style="font-weight: bold; color: White; padding: 3px; height: 23px; font-size: 10pt; text-align: left; font-family: Verdana;">' + title + '</span></div></div><div id="divBUIPU" style="width: 100%; height: 100%; overflow:auto; text-align: left;">' + htmlMessage + '</div></div>';
    $.blockUI({ message: dX, css: {
        width: width + 'px',
        height: eval(height + 10) + 'px',
        left: (winW - width) / 2 + 'px',
        top: ((top != null) ? top + 'px' : '20px')
        },
        focusInput: true,
        iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank', 
        forceIframe: true
    });
    if (sc == true)
    {
        $("#aiClose").show();
    } else {
        $("#aiClose").hide();
    }
} 
function clearPopUp(noUnblock) {
    $("div[id^=divBUIPU]").unbind().remove();
    if (!noUnblock) {
        $.unblockUI();
    }
    try 
    {
        parent.frames['header'].$.unblockUI();
    }
    catch (err) { }
}


function wsFail(res) {
try
  {
    $.unblockUI();
  }
catch(err)
  {
  //Handle errors here
  }
    
}
function showAlertMessage(msg, postAction)
{
    $(document).ready(function()
    {
        $.prompt(msg, {
            prefix: 'dss',
            submit: function()
            {
                if (postAction != null)
                {
                    eval(postAction);
                }
            }

        });
    });
}

function fixAllPNGs() {
    var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
    if (badBrowser) {
        // get all pngs on page
        $('img[src$=.png]').each(function() {
            if (!this.complete) {
                this.onload = function() { fixPng(this); };
            } else {
                fixPng(this);
            }
        });
    }

}
$(document).ready(function () {
    fixAllPNGs();
});