﻿function sTrim(str)
{
    return str.replace(/^\s+|\s+$/g,"");
    
}

function checkText(obj, nextObj)
{
    if(sTrim(obj.value) != "")
    {
        nextObj.disabled = false;        
        // nextObj.style.backgroundColor = 'White';         
    }
    else
    {         
        nextObj.value = "";    
        // nextObj.style.backgroundColor = '#D8D2C4';         
        nextObj.disabled = true;
    }
}

function ValidateCheckInDate_Range(source, clientside_arguments) 
{
    var currentSplit = SearchCurrentDate.split("/");    
    var inSplit = clientside_arguments.Value.split("/");
    var strCurrent = currentSplit[2] + "/" + currentSplit[1] + "/" + currentSplit[0] // yyyy/mm/dd
    var strChkIn = inSplit[2] + "/" + inSplit[1] + "/" + inSplit[0] // yyyy/mm/dd
    currentDate = new Date(strCurrent);
    chkInDate = new Date(strChkIn);

    if (chkInDate.getDate().toString() == 'NaN') return;

    if (currentDate > chkInDate) 
    {
        clientside_arguments.IsValid = false;
        return;
    }    
}

function ValidateCheckOutDate_Prior(source, clientside_arguments) 
{   
    var chkIn = document.getElementById(checkinID);
    var inSplit = chkIn.value.split("/");
    var outSplit = clientside_arguments.Value.split("/");

    var strChkIn = inSplit[2] + "/" + inSplit[1] + "/" + inSplit[0] // yyyy/mm/dd
    var strChkOut = outSplit[2] + "/" + outSplit[1] + "/" + outSplit[0] // yyyy/mm/dd

    chkInDate = new Date(strChkIn);
    chkOutDate = new Date(strChkOut);

    if (chkInDate.getDate().toString() == 'NaN') return;
    if (chkOutDate.getDate().toString() == 'NaN') return;

    if (chkInDate >= chkOutDate) {

        clientside_arguments.IsValid = false;
        return;
    }    
}

function ValidateCheckOutDate_NoCheckIn(source, clientside_arguments) 
{
    var chkIn = document.getElementById(checkinID);
    var inSplit = chkIn.value.split("/");
    var outSplit = clientside_arguments.Value.split("/");

    var strChkIn = inSplit[2] + "/" + inSplit[1] + "/" + inSplit[0] // yyyy/mm/dd
    var strChkOut = outSplit[2] + "/" + outSplit[1] + "/" + outSplit[0] // yyyy/mm/dd

    chkInDate = new Date(strChkIn);
    chkOutDate = new Date(strChkOut);

    if (chkOutDate.getDate().toString() != 'NaN' && chkInDate.getDate().toString() == 'NaN') {

        clientside_arguments.IsValid = false;
        return;
    }
}

function ValidateCheckOutDate_NoCheckOut(source, clientside_arguments) 
{
    var chkIn = document.getElementById(checkinID);
    var inSplit = chkIn.value.split("/");
    var outSplit = clientside_arguments.Value.split("/");

    var strChkIn = inSplit[2] + "/" + inSplit[1] + "/" + inSplit[0] // yyyy/mm/dd
    var strChkOut = outSplit[2] + "/" + outSplit[1] + "/" + outSplit[0] // yyyy/mm/dd

    chkInDate = new Date(strChkIn);
    chkOutDate = new Date(strChkOut);

    if (chkOutDate.getDate().toString() == 'NaN' && chkInDate.getDate().toString() != 'NaN') {

        clientside_arguments.IsValid = false;
        return;
    }
}

function Updating(boxId, formId, iframeId) {

    var ok = true;
    try
    {        
        ok = Page_ClientValidate();

//        for (i = 0; i < Page_Validators.length; i++) {
//            alert(Page_Validators[i].errormessage);
//            alert("IsValid: " + Page_Validators[i].isvalid);
//        }
    }
    catch(err)
    {
        ok = true;
    }
    
    if (ok)
    {
        var form = document.getElementById(formId);
        var box = document.getElementById(boxId);
        var iframe = document.getElementById(iframeId);

        var pos = Position.get(form);
        box.style.height = (pos.height - 100) + "px";
        iframe.style.height = (pos.height - 100) + "px";

        fade(formId);
        appear(boxId);
    }
}

function setOpacity(domId, val) {
    obj = document.getElementById(domId);
    obj.style.MozOpacity = val;
    obj.style.opacity = val / 10;
    obj.style.filter = 'alpha(opacity=' + val * 10 + ')';
}

function fade(domId) {
    //Get the Element 
    obj = document.getElementById(domId);

    //Return false if the element is already hidden
    if (obj.style.display == "none") return false;

    //Set the initial value of alpha to 10 (Opaque)
    var alpha = 10;

    //Internal function
    function f() {
        //Decrement the alpha value
        alpha--;

        //Set the opacity of our element to the specified alpha
        setOpacity(domId, alpha);
        if (alpha > -1) {
            //If alpha is still bigger than -1 then..   
            setTimeout(f, 100);

            //..then call the function again after 100 milliseconds  
        }
        else {
            //otherwise..   
            // obj.style.display = 'none'; 
            //..otherwise now that we cant see the element anyways, hide it  
        }
    }
    setTimeout(f, 100);
    //This is where we call the f() function for the first time
};

function appear(domId) {
    // Get the element
    obj = document.getElementById(domId);

    // set initial alpha value to 0 (invisible)
    setOpacity(domId, 0);

    // Return if it is already being displayed
    if (obj.style.display != "none") return false;

    // Un-hide the object before its animation
    obj.style.display = '';

    // Set the initial value of alpha to 0 (invisible)
    var alpha = 0;

    // Internal function
    function a() {
        // Increment alpha
        alpha++;

        // Set the opacity of our element to the specified alpha  
        setOpacity(domId, alpha);

        if (alpha < 11) setTimeout(a, 100);
        /*Till alpha is 10, keep calling the a() function after 100 milliseconds */
    }

    //This is where we call the a() function for the first time
    setTimeout(a, 100);
}

/**
* Copyright (c)2005-2008 Matt Kruse (javascripttoolbox.com)
* 
* Dual licensed under the MIT and GPL licenses. 
* This basically means you can use this code however you want for
* free, but don't claim to have written it yourself!
* Donations always accepted: http://www.JavascriptToolbox.com/donate/
* 
* Please do not link to the .js files on javascripttoolbox.com from
* your site. Copy the files locally to your server instead.
* 
*/
var Position = (function() {
    // Resolve a string identifier to an object
    // ========================================
    function resolveObject(s) {
        if (document.getElementById && document.getElementById(s) != null) {
            return document.getElementById(s);
        }
        else if (document.all && document.all[s] != null) {
            return document.all[s];
        }
        else if (document.anchors && document.anchors.length && document.anchors.length > 0 && document.anchors[0].x) {
            for (var i = 0; i < document.anchors.length; i++) {
                if (document.anchors[i].name == s) {
                    return document.anchors[i]
                }
            }
        }
    }

    var pos = {};
    pos.$VERSION = 1.0;

    // Set the position of an object
    // =============================
    pos.set = function(o, left, top) {
        if (typeof (o) == "string") {
            o = resolveObject(o);
        }
        if (o == null || !o.style) {
            return false;
        }

        // If the second parameter is an object, it is assumed to be the result of getPosition()
        if (typeof (left) == "object") {
            var pos = left;
            left = pos.left;
            top = pos.top;
        }

        o.style.left = left + "px";
        o.style.top = top + "px";
        return true;
    };

    // Retrieve the position and size of an object
    // ===========================================
    pos.get = function(o) {
        var fixBrowserQuirks = true;
        // If a string is passed in instead of an object ref, resolve it
        if (typeof (o) == "string") {
            o = resolveObject(o);
        }

        if (o == null) {
            return null;
        }

        var left = 0;
        var top = 0;
        var width = 0;
        var height = 0;
        var parentNode = null;
        var offsetParent = null;


        offsetParent = o.offsetParent;
        var originalObject = o;
        var el = o; // "el" will be nodes as we walk up, "o" will be saved for offsetParent references
        while (el.parentNode != null) {
            el = el.parentNode;
            if (el.offsetParent == null) {
            }
            else {
                var considerScroll = true;
                /*
                In Opera, if parentNode of the first object is scrollable, then offsetLeft/offsetTop already 
                take its scroll position into account. If elements further up the chain are scrollable, their 
                scroll offsets still need to be added in. And for some reason, TR nodes have a scrolltop value
                which must be ignored.
                */
                if (fixBrowserQuirks && window.opera) {
                    if (el == originalObject.parentNode || el.nodeName == "TR") {
                        considerScroll = false;
                    }
                }
                if (considerScroll) {
                    if (el.scrollTop && el.scrollTop > 0) {
                        top -= el.scrollTop;
                    }
                    if (el.scrollLeft && el.scrollLeft > 0) {
                        left -= el.scrollLeft;
                    }
                }
            }
            // If this node is also the offsetParent, add on the offsets and reset to the new offsetParent
            if (el == offsetParent) {
                left += o.offsetLeft;
                if (el.clientLeft && el.nodeName != "TABLE") {
                    left += el.clientLeft;
                }
                top += o.offsetTop;
                if (el.clientTop && el.nodeName != "TABLE") {
                    top += el.clientTop;
                }
                o = el;
                if (o.offsetParent == null) {
                    if (o.offsetLeft) {
                        left += o.offsetLeft;
                    }
                    if (o.offsetTop) {
                        top += o.offsetTop;
                    }
                }
                offsetParent = o.offsetParent;
            }
        }


        if (originalObject.offsetWidth) {
            width = originalObject.offsetWidth;
        }
        if (originalObject.offsetHeight) {
            height = originalObject.offsetHeight;
        }

        return { 'left': left, 'top': top, 'width': width, 'height': height
        };
    };

    // Retrieve the position of an object's center point
    // =================================================
    pos.getCenter = function(o) {
        var c = this.get(o);
        if (c == null) { return null; }
        c.left = c.left + (c.width / 2);
        c.top = c.top + (c.height / 2);
        return c;
    };

    return pos;
})();


