
theObjects = document.getElementsByTagName("object"); 
for (var i = 0; i < theObjects.length; i++) 
{ 
    // Do not apply this fix to the oddcase character
    if (theObjects[i].name!="VHSS")
    {
        theObjects[i].outerHTML = theObjects[i].outerHTML; 
    }
}


//////////////////////////////////////////////////////////////////////////////
// File:        <framework>/scripts
// Author:      Seth Webster
// Abstract:    Provides base level global javascript methods
//              used by the PhpX Framework


//////////////
// PHPXFORM //
///////////////////////////////////////////////////////////////////////////////////////////////////

/**
*   object PhpXForm()
*   
*   The global PhpXForm Handler
*/
function PhpXForm()
{
            
}


// Contains the form object
PhpXForm.prototype.__formObject = null;
// A boolean indicating whether the form object has been initialized
PhpXForm.prototype.initialized = false;
// A container for the current validation group
PhpXForm.prototype.validationGroup = null;
// A boolean value that is set to true once the page loads.  It is used
// to prevent post backs while the page is still loading
PhpXForm.prototype.isLoaded = false;

// Initializes the phpXForm object
PhpXForm.prototype.initialize = function(formObj)
{
    this.__formObject = formObj;
    this.initialized = true;
}

PhpXForm.prototype.__setEventTriggerAndPost = function(objId, ValidationGroup)
{
	phpXForm.validationGroup = ValidationGroup;
	obj = document.getElementsByName(objId);
	if (obj && obj.length>0)
	{	
		obj = obj[0];
		hf = document.getElementById('phpHiddenField');
    	if (hf)
    	{
			hf.value = objId;
			//alert("Value set to:"+hf.value); 
			__internal_form_submit(phpXForm.__formObject);
		}
	}
	else 
	{
	    alert("Cannot find "+objId);
	}    
}

PhpXForm.prototype.__setEventTriggerAndPostAjax = function(objId, MethodOnComplete, ValidationGroup)
{
	obj = document.getElementsByName(objId);
	phpXForm.validationGroup = ValidationGroup;
	if (obj && obj.length>0)
	{	
		obj = obj[0];
	    //alert("Object Found: "+obj);
		hf = document.getElementById('phpHiddenField');
    	if (hf)
    	{
			hf.value = obj.name;
			//alert("Value set to:"+hf.value);
			var ao = new AjaxObj();
			ao.PostForm(this.__formObject,location,MethodOnComplete);			
		}
	}
	else
	{
	    alert("null");
	}
	return false;
}

PhpXForm.prototype.__setEventTrigger = function(trigger)
{
    if (typeof(trigger)!="object")
    {        
        obj = document.getElementsByName(trigger);        
        if (obj.length<=0)
        {
            obj = document.getElementById(trigger);
            obj = new Array();  
            obj[obj.length] = obj;
            
        }
    }
    else    
    {
        obj = new Array();
        obj[obj.length] = trigger;
    }
    if (obj && obj.length>0 || trigger==null)
    {
        if (null!=trigger) obj = obj[0];
   	    hf = document.getElementById('phpHiddenField');
	    if (hf)
	    {	        	        
	    	hf.value = trigger;	
        }      
        return true;
    }
    return false;
}

PhpXForm.prototype.updateControlArray = Array();

PhpXForm.prototype.__setEventTriggerAndPostAjaxPartial = 
    function(trigger, partialControlId, MethodOnComplete, UpdateControlId, ValidationGroup)
{
    if (null==this.updateControlArray[UpdateControlId])
    {
        this.updateControlArray[UpdateControlId] = 0;
    }
    this.updateControlArray[UpdateControlId]++;
	phpXForm.validationGroup = ValidationGroup;
    // Trigger may be an object, or a string
    var _this = this;
    if (this.__setEventTrigger(trigger))
    {
        valid = this.__validate(phpXForm.validationGroup);
        if (!valid)
            return;
	    var ao = new AjaxObj();    	
	    var reqComplete = function(req)
	    {
	        _this.__processPartialResult(req);
	        // ONCE We have done our post & replace,
	        // We'll delegate to the supplied callback
	        // to allow for any additional processing 
	        if (MethodOnComplete && MethodOnComplete!="") MethodOnComplete(req);
	        _this.updateControlArray[UpdateControlId]--;
	        updateControl = document.getElementById(UpdateControlId);
	        if (updateControl)// && _this.updateControlArray[UpdateControlId]==0)
	        {
	            styleObj = updateControl;
	            if (updateControl.style)
	                styleObj = updateControl.style;
	            styleObj.display = "none";
	        }


	    }
	    updateControl = document.getElementById(UpdateControlId);
	    if (updateControl)
	    {
	        styleObj = updateControl;
	        if (updateControl.style)
	            styleObj = updateControl.style;
	        styleObj.display = "block";
	    }
    	
    	
	    ao.PostFormPartialPage(document.forms[0],
	        location,
	        partialControlId,
	        reqComplete);			
    }    
}

PhpXForm.prototype.__processPartialResult = function(req)
{
        _this = this;
        SetEventTrigger(null);
        // To maintain state, we require that a state object
        // be returned from the server
        // ---
        // Here we retrieve it from the result text,
        // and replace the form's current state object with the new
        // one
        state = req.responseXML.getElementsByTagName("state");
        _this.__setFormState(state);    	    
        // Because this is a partial post/update, 
        // we will retrieve the element from the result
        // that contains our new HTML
        // --
        // First, we get the destination HTML element
        
        // Reload Scripts if provided
        scripts = req.responseXML.getElementsByTagName("script");
        if (scripts.length>0)
        {
            src = scripts[0].attributes.getNamedItem("src").nodeValue;
            clientId = scripts[0].attributes.getNamedItem("clientId").nodeValue;
            scriptObj = document.getElementById(clientId);
            var head = document.getElementsByTagName("head").item(0);
            var oScript = document.getElementById("oScript");
            if (oScript)
                head.removeChild(oScript);
            oScript = document.createElement("script");
            //document.write(this.CrossDomainRequestProxy+"?object="+Object+"&method="+Method+"&"+paramsStr+"&requestId="+idx);
            oScript.setAttribute("src",src);
            oScript.setAttribute("id",clientId);   
            head.appendChild(oScript);    
        }
        else
        {
            // alert("Ajax Error: Script element not found");
        }

        
        controls = req.responseXML.getElementsByTagName("control");
        if (controls.length>0)
        {
            partialControlId = controls[0].attributes.getNamedItem("id").nodeValue;
        }
        
        fillObj = document.getElementById(partialControlId);
        // Next, we retrieve the response element from
        // the XML document
        response = req.responseXML.getElementsByTagName("response");
        // Hopefully, we got one
        if (response && response.length>0)
        {
            // pare it down to the single element
            response = response[0];
            response = response.firstChild;
        }
        else
        {
            alert("Ajax Error: Unable to locate the response element");
        }
        

        var controlHtml = new String(req.responseText);
        idx = controlHtml.indexOf("<control");
        idx = controlHtml.indexOf(">",idx)+1;	                
        controlHtml = controlHtml.substring(idx, (controlHtml.indexOf("</control>")));             
        
        // We need both objects to be successful
        if (fillObj && response)
        {		
            // Because mozilla doesn't support the convenience of outerHTML, 
            // and IE doesn't support document.createRange, we have to give 
            // 2 different methods of replacing the HTML
            // ---	
            // MOZILLA        
            if (document.createRange)
            {
                //TODO: Determine a better way to handle mowzilla
                range = document.createRange();
                range.selectNode(fillObj);
                range.setStartBefore(fillObj);
                var df = range.createContextualFragment(controlHtml);			            
                fillObj.parentNode.replaceChild(df, fillObj);
            }
            // IE
            else
            {
                fillObj.outerHTML = controlHtml;
            }	        
        }
}

PhpXForm.prototype.__setFormState = function(state)
{
    if (state && state.length>0)
    {
        state = state[0];
        stateId = state.getAttribute("id");
        docstate = document.getElementById(stateId);
        docstate.value = state.getAttribute("value");
        state.parentNode.removeChild(state);
    }
    else
    {
        alert("Ajax Error: Unable to locate the state element");
    }
}

PhpXForm.prototype.__submit = function()
{
    if (!this.isLoaded)
        return;
    var validationResult = this.__validate(phpXForm.validationGroup);
    if (validationResult==true)
    {
        this.__formObject.submit();
        return;
    }
    _restore_watermarks();    
    return false;
}

PhpXForm.prototype.__validate = function(ValidationGroup)
{
    var allOk = true;
    // Clear old errors
    _clear_watermarks();   
    for(x=0;x<this.validationCallbacks.length;x++)
    {        
        var vo = this.validationCallbacks[x];
        if (ValidationGroup==null || vo.ValidationGroup==ValidationGroup)
        {
            vo.FailureCallback(vo.Owner, true);
            vo.Passed = true;
        }
    }
    // Iterate through validation objects for 
    // this validation group and call parents
    for(x=0;x<this.validationCallbacks.length;x++)
    {        
        var vo = this.validationCallbacks[x];
        if (ValidationGroup==null || vo.ValidationGroup==ValidationGroup)
        {
            obj = document.getElementsByName(vo.Object);
            if (obj.length<=0)
                continue;
            res = vo.Callback(vo.Object,vo.Context==null?"":vo.Context, vo);
            vo.Passed = res;
        }
    }
    
    // Iterate and pop failed errors
    for(x=0;x<this.validationCallbacks.length;x++)
    {
        var vo = this.validationCallbacks[x];
        if (ValidationGroup==null || vo.ValidationGroup==ValidationGroup)
        {
            if (!vo.Passed && vo.FailureCallback)
            {
                vo.FailureCallback(vo.Owner);
                if (vo.Object.focus)
                    vo.Object.focus();
                allOk=false;
            }
        }
            
    }
    
    phpXForm.validationGroup = null;    
    return allOk;
}


PhpXForm.prototype.validationCallbacks = Array();

PhpXForm.prototype.AddValidationCallback = function(owner, objToValidate, Callback, FailureCallback, Context)
{
    
    var vo = new ValidationObject(owner, objToValidate, Callback, FailureCallback, Context);
    this.validationCallbacks[this.validationCallbacks.length] = vo;
}

var phpXForm = new PhpXForm();


////////////////////////
// VALIDATION OBJECTS //
//////////////////////////////////////////////////////////////////////////////////////////////////

/**
*   function ValidationObect()    
*   
*   Provides an object to contain validation information
*/
function ValidationObject(Owner, objToValidate, ValidationCallback, 
                          ValidationGroup, FailureCallback, Context)
{
    this.Owner = Owner;
    this.ValidationGroup = ValidationGroup;
    this.Object = objToValidate;
    this.Callback = ValidationCallback;
    this.FailureCallback = FailureCallback;
    this.Context = Context;
}


///////////////////////////////
// GLOBAL FORM POST ROUTINES //
//////////////////////////////////////////////////////////////////////////////

// Our non-object
function __internal_form_submit(frmObj)
{   
    
    phpXForm.__submit();
    return false;
}



// Finds a particluar object and sets the hidden form field
// with the found object's name
// Then, the form is posted back with that information to 
// signify who the event trigger was
function SetEventTriggerAndPost(objId, ValidationGroup)
{    
    phpXForm.__setEventTriggerAndPost(objId, ValidationGroup);
}

function SetEventTriggerAndPostAjax(objId, MethodOnComplete, ValidationGroup)
{    
    phpXForm.__setEventTriggerAndPostAjax(objId, MethodOnComplete, ValidationGroup);
}

function SetEventTrigger(trigger)
{
    return phpXForm.__setEventTrigger(trigger);
}

function SetEventTriggerAndPostAjaxPartial(trigger, partialControlId, MethodOnComplete, UpdateControlId, ValidationGroup)
{  
    phpXForm.__setEventTriggerAndPostAjaxPartial(
            trigger, 
            partialControlId, 
            MethodOnComplete,
            UpdateControlId, 
            ValidationGroup);
}

function AjaxRequest(Url, Callback)
{
    reqComplete = function(req)
    {
        if (req.exception)
        {
            alert(req.exception.JSODException.Message.value);
        }
        else
        {
            ao = null;
            Callback(req);
        }
    }
    var ao = new AjaxObj();
    ao.LoadUrl(Url,reqComplete);
}




document.setElementOpacity = function(elementId, opacity)
{
    if (typeof(elementId)=="object")
        elementId = elementId.id;
    currentOpac(elementId, opacity, 500);
}


document.slideToggle = function(elementId, totalTimeMs, ForcedMode, CallOnComplete)
{
    var s = new SlideAnimation(elementId, totalTimeMs, ForcedMode, CallOnComplete);
    s.Animate();       
    return s;
}

var __animations = new Collection();


/*
 * CCallWrapper.js
 * $Revision: 1.3 $ $Date: 2003/07/07 18:32:43 $
 */

/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is Netscape code.
 *
 * The Initial Developer of the Original Code is
 * Netscape Corporation.
 * Portions created by the Initial Developer are Copyright (C) 2003
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s): Bob Clary <bclary@netscape.com>
 *
 * ***** END LICENSE BLOCK ***** */

function CCallWrapper(aObjectReference, 
                      aDelay,
                      aMethodName, 
                      aArgument0,
                      aArgument1,
                      aArgument2,
                      aArgument3,
                      aArgument4,
                      aArgument5,
                      aArgument6,
                      aArgument7,
                      aArgument8,
                      aArgument9
                      )
{
  this.mId = 'CCallWrapper_' + (CCallWrapper.mCounter++);
  this.mObjectReference = aObjectReference;
  this.mDelay     = aDelay;
  this.mTimerId = 0;
  this.mMethodName = aMethodName;
  this.mArgument0 = aArgument0;
  this.mArgument1 = aArgument1;
  this.mArgument2 = aArgument2;
  this.mArgument3 = aArgument3;
  this.mArgument4 = aArgument4;
  this.mArgument5 = aArgument5;
  this.mArgument6 = aArgument6;
  this.mArgument7 = aArgument7;
  this.mArgument8 = aArgument8;
  this.mArgument9 = aArgument9;
  CCallWrapper.mPendingCalls[this.mId] = this;
}

CCallWrapper.prototype.execute = function()
{
  this.mObjectReference[this.mMethodName](this.mArgument0,
                                          this.mArgument1,
                                          this.mArgument2,
                                          this.mArgument3,
                                          this.mArgument4,
                                          this.mArgument5,
                                          this.mArgument6,
                                          this.mArgument7,
                                          this.mArgument8,
                                          this.mArgument9
                                          );
  delete CCallWrapper.mPendingCalls[this.mId];
};

CCallWrapper.prototype.cancel = function()
{
  clearTimeout(this.mTimerId);
  delete CCallWrapper.mPendingCalls[this.mId];
};

CCallWrapper.asyncExecute = function (/* CCallWrapper */ callwrapper)
{
  CCallWrapper.mPendingCalls[callwrapper.mId].mTimerId = setTimeout('CCallWrapper.mPendingCalls["' + callwrapper.mId + '"].execute()', callwrapper.mDelay);
};

CCallWrapper.mCounter = 0;
CCallWrapper.mPendingCalls = {};

//////////////////////////////
// ANIMATIONS & TRANSITIONS //
////////////////////////////////////////////////////////////////////////////////

// OPACITY
function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var obj = document.getElementById(id);
	var object = document.getElementById(id).style;
	if (!obj)
	    return;
	if ((!object.backgroundColor || object.backgroundColor=="") &&
	    (!object.backgroundImage || object.backgroundImage==""))
	{
	    // TRY TO LOCATE PARENT BACKGROUND ELEMENT
	    pNode = obj.parentNode;	    
	    while (null!=pNode)
	    {
	        pStyle = pNode.style ? pNode.style : pNode;
	        if (pStyle.backgroundColor && pStyle.backgroundColor!="")
	        {
	            object.backgroundColor = pStyle.backgroundColor;
	            break;
	        }
	        pNode = pNode.parentNode;
	    }
	} 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}

// ACCORDION DIV'S
function SlideAnimation(elementId, speed, forcedMode, callOnComplete)
{
    
    this.ElementId = elementId;
    this.speed = speed;
    this.CallOnComplete = callOnComplete;
    this.forcedMode = forcedMode;
    for(i=0;i<__animations.length();i++)
    {
        if (__animations.data[i].ElementId==this.ElementId)
        {
            __animations.data[i].speed = speed;
            __animations.data[i].CallOnComplete = callOnComplete;
            __animations.data[i].forcedMode = forcedMode;
            return __animations.data[i];
        }
    }
    __animations.Add(this);    
}

SlideAnimation.prototype.__timeouts = new Collection();

SlideAnimation.prototype.Animate = function ()
{
    _this = this;

    obj = document.getElementById(this.ElementId);
    if (!obj)
        return;      

    var slideFuncComplete = function()
    {
        _this.__isAnimated = false;
        for(i=0;i<_this.__timeouts.length();i++)
        {
            t = _this.__timeouts.data[i];
            if (!isNaN(t))
            {
                clearTimeout(t);
            }
        }
        _this.__timeouts.Clear();
        if (obj.action=="open")
        {
            obj.style.height = "auto";
        }
        _this.__abort = false;
        if (_this.CallOnComplete)
            _this.CallOnComplete(_this);

    }


    if (this.__isAnimated)
    {
        return;
        this.__abort = true;
        slideFuncComplete();
    }
    this.__isAnimated = true;
    
    var totalSteps = 100;
    var totalTimeMs = this.speed;
    // Get a reference to the style object
    style = obj.style ? obj.style : obj;    
    // Intialize element if necessary
    if (!obj.slideInitialized)
    {
        obj.slideIsOpen = false;        
        obj.totalTimeMs = totalTimeMs;
        // Cause element to expand to correct height so that we
        // may capture it
        style.height = "auto";
        // Capture original height and store on the element
        obj.originalHeight = obj.clientHeight ? obj.clientHeight : obj.offsetHeight;
        // set and store our stepping interval -- the total height divided into steps
        obj.stepInterval = obj.originalHeight/totalSteps;
        // set and store our time interval
        obj.timeInterval = totalTimeMs/totalSteps;
        // Set the height to zero to hide it
        style.height = "0px";
        obj.currentHeight = 0;
        obj.slideIsOpen = false;
        // Cause overflow to be hidden so that as the element expands,
        // the contents are revealed
        style.overflow = "hidden";
        style.display = "block";
        // Set the opacity to zero
        changeOpac(0,this.ElementId);        
        // Set our initialized flag
        obj.slideInitialized = true;        
    }

    obj.currentStep = 0;
    var slideFuncOpen = function()
    {
        if (_this.forcedMode=="Close")
            return;
        if (!_this.__abort)
        {
            obj.currentHeight = (obj.currentHeight+obj.stepInterval);
            style.height = obj.currentHeight+"px";       
            style.display = 'block'; 
            style.overflow = "visible";
            obj.action="open";
        }
    }
    
    var slideFuncClose = function()
    {
        if (_this.forcedMode=="Open")
        {            
            return;
        }
        if (!_this.__abort)
        {
            obj.currentHeight = (obj.currentHeight-obj.stepInterval);
            if (obj.currentHeight<0)
                obj.currentHeight = 0;
            style.height = obj.currentHeight+"px";                        
            obj.action="close";
        }
    }

    
    var timer = 0;
    var speed = Math.round(totalTimeMs / 100);
    if (obj.currentHeight<obj.originalHeight)
    {
        opacity(this.ElementId,0,100,totalTimeMs);
        for (i=0;i<totalSteps+1;i++)
        {
            var t = setTimeout(slideFuncOpen,(timer*speed));
            this.__timeouts.Add(t);
            timer++;
        }
    } 
    else
    {   
        if (_this.forcedMode!="Open")
            opacity(this.ElementId,100,0,totalTimeMs);                
        var endResult = obj.currentHeight;
        while(endResult>0)
        {
            var t = setTimeout(slideFuncClose,(timer*speed));
            endResult = endResult-obj.stepInterval;
            this.__timeouts.Add(t);
            timer++;
        }
    } 
    
    setTimeout(slideFuncComplete,(timer*speed));   
    
}



////////////////////////
// WATERMARK ROUTINES //
//////////////////////////////////////////////////////////////////////////////
function _clear_watermarks()
{
    for(i=0;i<watermarkObjects.length;i++)
    {
        obj = document.getElementById(watermarkObjects[i].object);
        if (obj && obj.value==watermarkObjects[i].watermarkText)
            obj.value = "";
    }
}

function _restore_watermarks()
{
    for(i=0;i<watermarkObjects.length;i++)
    {
        obj = document.getElementById(watermarkObjects[i].object);
        if (obj && obj.value=="")
            obj.value = watermarkObjects[i].watermarkText;
    }
}


var watermarkObjects = Array();
function _register_watermark(objId,watermarkText)
{
    var o = new Object();
    o.object = objId;
    o.watermarkText = watermarkText;
    watermarkObjects[watermarkObjects.length] = o;
}


///////////////////////////
// GLOBAL EVENT HANDLERS //
///////////////////////////////////////////////////////////////
function __onload(obj)
{    
    phpXForm.initialize(document.forms[0]);
    phpXForm.isLoaded = true;
}




///////////////////////////////
// SPECIAL PROTOTYPE METHODS //
///////////////////////////////////////////////////////////////
// DOCUMENT
document.getElementPosition = function(obj)
{
    x = findPosX(obj);
    y = findPosY(obj);
    ret = new Point(x,y);
    return ret; 
}
// STRING 
// Useful string extensions
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}


//////////////////
// MISC OBJECTS //
////////////////////////////////////////////////////////////////

function Point(X, Y)
{
    this.X = X;
    this.Y = Y;
}

function Size(Width, Height)
{
    this.Width = Width;
    this.Height = Height;
}

function Rectangle(X, Y, Width, Height)
{
    this.X = X;
    this.Y = Y;
    this.Width = Width;
    this.Height = Height;
}

////////////////
// COLLECTION //
////////////////////////////////////////////////////////////////

function Collection()
{
}

Collection.prototype.data = Array();

Collection.prototype.Add = function(Item)
{
    this.data[this.data.length] = Item;
}

Collection.prototype.Remove = function(Item)
{
    idx = this.IndexOf(Item);
    if (idx<0)
        return;
    this[idx] = null;
}

Collection.prototype.Clear = function()
{
    this.data = Array();
}

Collection.prototype.IndexOf = function(Item)
{
    for (i=0;i<this.data.length;i++)
    {
        if(Item==this.data[i])
            return i;
    }
    return -1;
}

Collection.prototype.length = function()
{
    return this.data.length;
}


/////////////////////
// HELPER METHODS  //
///////////////////////////////////////////////////////////

function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
}

function findPosY(obj)
{
    var curtop = 0;
    if(obj.offsetParent)
    while(1)
    {
      curtop += obj.offsetTop;
      if(!obj.offsetParent)
        break;
      obj = obj.offsetParent;
    }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
}

function GetClientSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return new Size(myWidth,myHeight);
}

/// DESIGNER

function DesignerDrag(obj)
{
    this.object = obj;                
    st = (obj.style)?obj.style:obj;
    st.position='absolute';
}

function IsLeapYear(Year)
{
    return ((Year % 4==0 && Year % 100 != 0) || Year % 400==0);
}

//////// DATE TIME

var daysInMonth = Array();
daysInMonth[1] = 31;
daysInMonth[2] = 28;
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;



function dateChange(yearId, monthId, dayId)
{
    var isLeap = false;
    yearObj = document.getElementById(yearId);
    monthObj = document.getElementById(monthId);
    isLeap = IsLeapYear(yearObj.value);
    dayObj = document.getElementById(dayId);
    
    if (monthObj.value<=0)
        return;
    
    if (isLeap)
        daysInMonth[2] = 29;
    else
        daysInMonth[2] = 28;
    
    var currVal = dayObj.value;   
    dayObj.options.length = 0;
    dayObj.options[dayObj.options.length] = new Option("Select...",-1);        
    for(i=1;i<=daysInMonth[monthObj.value];i++)
    {
        dayObj.options[dayObj.options.length] = new Option(i,i);        
        if (dayObj.options[dayObj.options.length-1].value==currVal)
            dayObj.options[dayObj.options.length-1].selected = 'selected';
    }
}

function setCaretToEnd (control) {
  if (control.createTextRange) {
    var range = control.createTextRange();
    range.collapse(false);
    range.select();
  }
  else if (control.setSelectionRange) {
    control.focus();
    var length = control.value.length;
    control.setSelectionRange(length, length);
  }
}

function setCaretToStart (control) {
  if (control.createTextRange) {
    var range = control.createTextRange();
    range.collapse(true);
    range.select();
  }
  else if (control.setSelectionRange) {
    control.focus();
    control.setSelectionRange(0, 0);
  }
}