﻿//======================================================//
function AddLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}
//======================================================//
var wini;
function Win(URL, name, width, height) {
    var x = screen.width;
    var y = screen.height;
    x = (x / 2) - (width / 2);
    y = (y / 2) - (height / 2);
    wini = window.open(URL, name, "top=" + y + ",left=" + x + ",toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,width=" + width + ",height=" + height + ",resizable=yes");
    wini.window.focus();
}
var swini;
function SemiWin(URL, name, width, height) {
    var x = screen.width;
    var y = screen.height;
    x = (x / 2) - (width / 2);
    y = (y / 2) - (height / 2);
    swini = window.open(URL, name, "top=" + y + ",left=" + x + ",toolbar=no,location=yes,status=yes,menubar=no,scrollbars=yes,width=" + width + ",height=" + height + ",resizable=yes");
    swini.window.focus();
}
//======================================================//
function ResetForm() {
    document.aspnetForm.reset();
    var sel = $Tag("select");
    for (var i = 0; i < sel.length; i++)
        RefreshDDL(sel[i]);
    Custom.clear();
}
//======================================================//
function HideSubmit(obj, vldGrp) {
    if (typeof (Page_ClientValidate) == 'function') {
        Page_ClientValidate(vldGrp);
        if (Page_IsValid)
            obj.style.display = 'none';
        else
            return false;
    }
    return true;
}
//======================================================//
function WaterMark(id, opt, txt, flipDir) {
    if (!$G(id))
        return;

    if ($G(id).value == "") { $G(id).style.color = opt._onblur; $G(id).value = txt; }
    $G(id).onblur = function() {
        if ($G(id).value == "") { $G(id).value = txt }
        if ($G(id).value == txt) { $G(id).style.color = opt._onblur; if (flipDir) { FlipDir(id, opt); } }
    };
    $G(id).onfocus = function() {
        if ($G(id).value == txt) { $G(id).value = "" }
        $G(id).style.color = opt._onfocus;
        if ($G(id).value == "") { if (flipDir) { FlipDir(id, opt); } }
    };
}
function FlipDir(id, opt) {
    if ($G(id).style.direction == "")
        $G(id).style.direction = opt.dir;
    if ($G(id).style.direction == "rtl")
        $G(id).style.direction = "ltr";
    else
        $G(id).style.direction = "rtl";
}
//======================================================//
function ClearDiv(divID) {
    if ($G(divID))
        $G(divID).innerHTML = "";
}
//======================================================//
function RefreshUpdatePanel(hiddenFieldID) {
    var hiddenField = $G(hiddenFieldID);
    if (hiddenField) {
        hiddenField.value = (new Date()).getTime();
        __doPostBack(hiddenFieldID, '');
    }
}
//======================================================//
function FileName(obj, divID) {
    if (obj.value != "") {
        document.getElementById(divID).innerHTML = obj.value.substring(obj.value.lastIndexOf('\\') + 1);
    }
}
//======================================================//
function Limit() {
    if (document.all && event.type == "paste")
        this.blur();

    if (this.value.length > this.getAttribute("maxi"))
        this.value = this.value.substring(0, this.getAttribute("maxi"));
    $G(this.getAttribute("spani")).innerHTML = this.getAttribute("maxi") - this.value.length;
}
function Maxi() {
    var ar = $Tag("textarea");

    for (var i = 0; i < ar.length; i++)
        if (ar[i].getAttribute("maxi") != null) {
        ar[i].onpaste = Limit;
        ar[i].onkeyup = Limit;
        ar[i].onblur = Limit;
    }
}
AddLoadEvent(Maxi);
//======================================================//
function AddFav(title, url) {
    if (window.sidebar) // firefox
        window.sidebar.addPanel(title, url, "");
    else if (window.opera && window.print) { // opera
        var elem = document.createElement('a');
        elem.setAttribute('href', url);
        elem.setAttribute('title', title);
        elem.setAttribute('rel', 'sidebar');
        elem.click();
    }
    else if (document.all)// ie
        window.external.AddFavorite(url, title);
}
function MakeHome(obj, url) {
    if (document.all) {
        obj.style.behavior = "url(#default#homepage)";
        obj.setHomePage(url);
    }
}
//======================================================//
function $G(e) { if (typeof e == 'string') e = document.getElementById(e); return e };
function $Tag(e) { if (typeof e == 'string') e = document.getElementsByTagName(e); return e };
//======================================================//
function Trim(strTmp) {
    strTmp = strTmp.replace(/^\s*|\s*$/g, "");
    return strTmp;
}
//======================================================//
var myimages = new Array();
function PreloadingImg() {
    for (x = 0; x < PreloadingImg.arguments.length; x++) {
        z = myimages.length;
        myimages[z] = new Image();
        myimages[z].src = PreloadingImg.arguments[x];
    }
}
//======================================================//
function IsIE6() {
    return (/MSIE (5\.5|6\.)/.test(navigator.userAgent));
}
//======================================================//
function CreateCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}
function ReadCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}
function EraseCookie(name) {
    CreateCookie(name, "", -1);
}
function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) +
    ((expiredays == null) ? "" : ";expires=" + exdate.toUTCString());
}
//======================================================//
var fa;
function Fader(id, t, r, txt) {
    clearTimeout(fa);
    if (t != null)
        $G(id).style.top = t + "px";
    if (r != null)
        $G(id).style.right = r + "px";
    if (txt != null)
        $G(id).innerHTML = txt;

    $("#" + id).stop(true, true);
    $("#" + id).show();
    fa = setTimeout('$("#' + id + '").fadeOut(5000)', 5000);
}
//======================================================//
function RedirectSec(intSec, spani, url) {
    intSec--;

    $G(spani).innerHTML = intSec + 1;
    if (intSec == -1) {
        setTimeout('window.location="' + url + '"', 200);
        return;
    }
    setTimeout("RedirectSec(" + intSec + ", '" + spani + "', '" + url + "')", 1000);
}
//======================================================//
ajax = {};
ajax.x = function() { try { return new ActiveXObject('Msxml2.XMLHTTP') } catch (e) { try { return new ActiveXObject('Microsoft.XMLHTTP') } catch (e) { return new XMLHttpRequest() } } };
ajax.serialize = function(f) { var g = function(n) { return f.getElementsByTagName(n) }; var nv = function(e) { if (e.name) return encodeURIComponent(e.name) + '=' + encodeURIComponent(e.value); else return '' }; var i = collect(g('input'), function(i) { if ((i.type != 'radio' && i.type != 'checkbox') || i.checked) return nv(i) }); var s = collect(g('select'), nv); var t = collect(g('textarea'), nv); return i.concat(s).concat(t).join('&'); };
ajax.send = function(u, f, m, a) { var x = ajax.x(); x.open(m, u, true); x.onreadystatechange = function() { if (x.readyState == 4) f(x) }; if (m == 'POST') x.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); x.send(a) };
ajax.get = function(url, func) { ajax.send(url, func, 'GET') };
ajax.gets = function(url) { var x = ajax.x(); x.open('GET', url, false); x.send(null); return x };
ajax.post = function(url, func, args) { ajax.send(url, func, 'POST', args) };
ajax.update = function(url, elm) { var e = $(elm); var f = function(r) { e.innerHTML = r }; ajax.get(url, f) };
ajax.submit = function(url, fun, frm) { ajax.post(url, fun, ajax.serialize(frm)) };
//======================================================//
function ToggleDisplay(id, isDis) {
    var dis = (isDis) ? "" : "none";
    for (var i = 2; i < ToggleDisplay.arguments.length; i++)
        $(arguments[i] + id).style.display = dis;
}
//======================================================//
function Comm(id) {
    if ($G(id)) {
        $G(id).style.display = ($G(id).style.display == "none") ? "" : "none";
    }
}
