/*******************************************/
/*  Copyright 2001 - Jon Dunfee            */
/*  http://www.3b.net/globaljs             */
/*  last updated: December 17, 2002        */
/*  Permission granted for unlimited use   */
/*  so far as the copyright notice above   */
/*  remains intact.                        */
/*******************************************/

/****************************************** NS Resize Script */
if (document.layers)
{
   origWidth = innerWidth;
   origHeight = innerHeight;
}
function resizeDetected()
{
   if (document.layers)
   {
      if (innerWidth != origWidth || innerHeight != origHeight)
      {
         // location.reload();
   		location.href = location.href;
      }
   }
}

/****************************************** Image Manipulation */
function newImage(theImgLoc)
{
    if (document.images)
    {
        var theNewImg = new Image();
        theNewImg.src = theImgLoc;
        return theNewImg;
    }
}

function swapImg(theImg, theSrc, theDiv)
{
    if(theDiv)
    {
        (document.all || document.getElementById)?eval("document.images."+theImg+".src = "+theSrc+".src"):eval("document."+theDiv+".document.images."+theImg+".src = "+theSrc+".src");
    }
    else
    {
        eval("document.images."+theImg+".src = "+theSrc+".src");
    }
}

/****************************************** DHTML Common Scripts */
function divStyle(theDiv)
{
    if (document.getElementById) { return document.getElementById(theDiv).style; }
    return eval("document."+((document.all)?"all."+theDiv+".style":theDiv));
}
function moveDiv(thisDiv,L,T,Z)
{
    (document.all)?divStyle(thisDiv).pixelLeft = L:divStyle(thisDiv).left = L;
    (document.all)?divStyle(thisDiv).pixelTop = T:divStyle(thisDiv).top = T;
    if(Z) { divStyle(thisDiv).zIndex = Z; }
}

function clipDiv(thisDiv,cT,cR,cB,cL)
{
    if (navigator.appName.indexOf("Opera") == -1)
    {
        if (document.all || document.getElementById) { divStyle(thisDiv).clip = "rect("+cT+" "+cR+" "+cB+" "+cL+")"; }
        else
        {
            divStyle(thisDiv).clip.top = cT;
            divStyle(thisDiv).clip.bottom = cB;
            divStyle(thisDiv).clip.left = cL;
            divStyle(thisDiv).clip.right = cR;
        }
    }
}

function showDiv()
{ 
    for(var sDi=0;sDi<showDiv.arguments.length;sDi++)
    {
        if (document.getElementById) { node = document.getElementById(showDiv.arguments[sDi]).style.visibility='visible'; }
        else divStyle(showDiv.arguments[sDi]).visibility = "visible";
    }
}

function hideDiv()
{
    for(var hDi=0;hDi<hideDiv.arguments.length;hDi++)
    {
        if (document.getElementById) { node = document.getElementById(hideDiv.arguments[hDi]).style.visibility='hidden'; }
        else divStyle(hideDiv.arguments[hDi]).visibility=(document.all)?"hidden":"hide";
    }
}

/****************************************** DHTML Additional Scripts */
function divVal(thisDiv,whichVal)
{
    if(whichVal == "L")
    {
        if (document.getElementById) { return document.getElementById(thisDiv).offsetLeft; }
        else { return ((document.all)?eval('document.all.'+thisDiv+'.offsetLeft'):divStyle(thisDiv).left); }
    }
    if(whichVal == "T")
    {
        if (document.getElementById) { return document.getElementById(thisDiv).offsetTop; }
        else { return ((document.all)?eval('document.all.'+thisDiv+'.offsetTop'):divStyle(thisDiv).top); }
    }
    if(whichVal == "Z") 
    {
        if (document.getElementById) { return document.getElementById(thisDiv).zIndex; }
        else { return ((document.all)?eval('document.all.'+thisDiv+'.zIndex'):divStyle(thisDiv).zIndex); }
    }
}

function transAdd(trans)
{
    return ((navigator.userAgent.indexOf('MSIE 5.5')>0 || navigator.userAgent.indexOf('MSIE 6')>0)?((trans < 24)?'style="filter:revealTrans(duration=1,transition=23);"':'style="filter:blendTrans(duration=1);"'):'');
}

function transDiv(thisDiv,dur,trans)
{
    var navApp = navigator.appVersion;
    if(navApp.substring(navApp.indexOf("MSIE")+5,navApp.indexOf("MSIE")+8) >= 5.5)
    {
        var theDiv = document.getElementById(thisDiv);
        if(trans == 24)
        {
            hideDiv(thisDiv);
            if(theDiv.filters)
            {
                theDiv.filters.blendTrans.Duration=dur;
                theDiv.filters.blendTrans.stop();
                theDiv.filters.blendTrans.apply();
            }
            showDiv(thisDiv);
            if(theDiv.filters)
            {
                theDiv.filters.blendTrans.play();
            }
        }
        else
        {
            hideDiv(thisDiv);
            if(theDiv.filters)
            {
                theDiv.filters.revealTrans.Transition=((trans)?trans:23);
                theDiv.filters.revealTrans.Duration=dur;
                theDiv.filters.revealTrans.stop();
                theDiv.filters.revealTrans.apply();
            }
            showDiv(thisDiv);
            if(theDiv.filters)
            {
                theDiv.filters.revealTrans.play();
            }
        }
    }
    else
    {
        showDiv(thisDiv);
    }
}

function fadeDiv(theDiv,speed,show,alpha)
{
    var alpha = (alpha)?alpha+10:10;
    hideDiv(theDiv);
    if(document.all)
    {
        document.getElementById(theDiv).style.filter = "alpha(opacity="+((show)?alpha:100-alpha)+")";
    }
    showDiv(theDiv);
    if(alpha < 100)
    {
        setTimeout("fadeDiv('"+theDiv+"',"+speed+","+show+","+alpha+")",speed);
    }
    else if(!show)
    {
        hideDiv(theDiv);
    }
}
/****************************************** New Document.Write */
function w(theText)
{
    document.write(theText);
}

function wl(theText)
{
    document.writeln(theText);
}

/****************************************** Input Focus Color Change */
function inputFocus(f,t)
{
    f.style.backgroundColor = (t)?"#ECEBF5":"#ffffff";
}

/****************************************** Simple String Validation */
function isValid(string,vstring)
{
         if(vstring == "alpha") { var regex = /^([a-z])+$/; }
    else if(vstring == "ALPHA") { var regex = /^([A-Z])+$/; }
    else if(vstring == "Alpha") { var regex = /^([a-zA-Z])+$/; }
    else if(vstring == "num")   { var regex = /^([0-9])+$|^([0-9])+(\.)?([0-9])*$/; }
    else if(vstring == "$")     { var regex = /^([0-9])+(\.)?([0-9])?([0-9])?$/; }
    else if(vstring == "email") { var regex = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; }
    else if(vstring == "phone") { var regex = /^\(?\d{3}\)?(\-| |\.)?\d{3}(\-| |\.)?\d{4}$/; }
    else if(vstring == "ssn")   { var regex = /^\d{3}\-?\d{2}\-?\d{4}$/; }
    else if(vstring == "url")   { var regex = /^http:\/\/([a-zA-Z0-9_\.\-])+\.+([a-zA-Z0-9_\.\-])/; }
    else if(vstring == "zip")   { var regex = /^(\d{5})(-(\d{4}))?$/; }
    else var regex = vstring;
    return regex.test(string);
}
