/*****************************************************
 All javascript herein is copyrighted (c) to its respectful
 owners and 4Shadow Studios
 copyright (c) 2004, All rights reserved
*****************************************************/



/*****************************************************
 Image Rollovers
*****************************************************/
function MM_swapImgRestore() { //v3.0

var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/*****************************************************
 Determine DOM Types
*****************************************************/
var DOMtype = '';
if (document.getElementById) {
    DOMtype = "STD";
} else if (document.all) {
    DOMtype = "IE4";
} else if (document.layers) {
    DOMtype = "NS4";
}

/*****************************************************
 Find ID within page
*****************************************************/
var docObjects = new Array();
function find_object(idtitle, forcefetch)
{
    if (forcefetch || typeof(docObjects[idtitle]) == "undefined") {
    switch (DOMtype) {
    case "STD":
    {
        docObjects[idtitle] = document.getElementById(idtitle);
    }
    break;

    case "IE4":
    {
        docObjects[idtitle] = document.all[idtitle];
    }
    break;
	
    case "NS4":
    {
        docObjects[idtitle] = document.layers[idtitle];
    }
    break;
    }
    }
    return docObjects[idtitle];
}

/***************************************************** 
 Toggle / Close / Open Display with Cookie Option
*****************************************************/
function change_display(idtitle,action,cookie,imgName) {
    idObj = find_object(idtitle);
    imgObj = find_object("img" + idtitle);
    if (idObj) {
       switch (action) {
       case "toggle":

          if (idObj.style.display == 'none') {
             idObj.style.display = "";
             if (imgObj) imgObj.src = "/images_atbv1/" + imgName + "_expanded.gif";

             if (cookie) setCookie(idtitle,'1',null,'/','aphasiatoolbox.com');
          } else {
             idObj.style.display = "none";
             if (imgObj) imgObj.src = "/images_atbv1/" + imgName + ".gif";
             if (cookie) setCookie(idtitle,'0',null,'/','aphasiatoolbox.com');
          }
       break;

       case "close":
          idObj.style.display = "none";
       break;

       case "open":
          idObj.style.display = "";
       break;
       }
       return true; //if idObj exists
    } else
       return false; //if idObj doesnt exist
}

/*****************************************************
 Change text size
*****************************************************/
function changeTextSize(chgsize) {
    if (!document.documentElement || !document.body) return;
    var newSize = 100;
    var startSize = parseInt(getTextSize());
    if (!startSize || startSize < 50) startSize = 100;
    switch (chgsize) {
        case "incr":
            newSize = startSize + 5;
        break;

        case "decr":
            newSize = startSize - 5;
        break;

        case "reset":
            newSize = 100;
        break;

        default:
            newSize = parseInt(getCookie("my-textsize"));
            if (!newSize) newSize = startSize;
        break;
    }
    if (newSize < 50) newSize = 50;
    newSize += "%";
    document.documentElement.style.fontSize = newSize;
    document.body.style.fontSize = newSize;
    var expires = new Date();
    expires.setTime(expires.getTime() +  (1000 * 60 * 60 * 24 * 30 * 6));
    expires = fixDate(expires);
    setCookie("my-textsize",newSize,expires);
}

/*****************************************************
 Get current text size
*****************************************************/
function getTextSize() {
    if (!document.body) return 0;
    var size = 0;
    var body = document.body;
    if (body.style && body.style.fontSize) {
        size = body.style.fontSize;
    } else if (typeof(getComputedStyle) != "undefined") {
        size = getComputedStyle(body,'').getPropertyValue("font-size");
    } else if (body.currentStyle) {
        size = body.currentStyle.fontSize;
    }
    return size;
}

/*****************************************************
 Disable button after clicked and submit form
*****************************************************/
function click_once(obj_input,submit_form,new_location)
{
    obj_input.disabled = true;
    obj_input.value = 'Please wait...';
    if(submit_form) obj_input.form.submit();
    if(new_location) location.replace(new_location);
}

/*****************************************************
 Pop Up Window
*****************************************************/
var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
    if(pos=="random") {
        LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
        TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
    }
    if(pos=="center") {
        LeftPosition=(screen.width)?(screen.width-w)/2:100;
        TopPosition=(screen.height)?(screen.height-h)/2:100;
    }
    else if((pos!="center" && pos!="random") || pos==null) {
        LeftPosition=0;
        TopPosition=20;
    }
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
win=window.open(mypage,myname,settings);
}

/*****************************************************
 Detect Flash
*****************************************************/
function isDefined(property) {
  return (typeof property != 'undefined');
}

var flashVersion = 0;
function getFlashVersion() {
    var latestFlashVersion = 8;
    var agent = navigator.userAgent.toLowerCase(); 
   
    // NS3 needs flashVersion to be a local variable
    if (agent.indexOf("mozilla/3") != -1 && agent.indexOf("msie") == -1) {
        flashVersion = 0;
    }
   
    // NS3+, Opera3+, IE5+ Mac (support plugin array):  check for Flash plugin in plugin array
    if (navigator.plugins != null && navigator.plugins.length > 0) {
        var flashPlugin = navigator.plugins['Shockwave Flash'];
        if (typeof flashPlugin == 'object') { 
            for (var i = latestFlashVersion; i >= 3; i--) {
                if (flashPlugin.description.indexOf(i + '.') != -1) {
                    flashVersion = i;
                    break;
                }
            }
        }
    }

    // IE4+ Win32:  attempt to create an ActiveX object using VBScript
    else if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && agent.indexOf("win")!=-1 && agent.indexOf("16bit")==-1) {
        var doc = '<scr' + 'ipt language="VBScript"\> \n';
        doc += 'On Error Resume Next \n';
        doc += 'Dim obFlash \n';
        doc += 'For i = ' + latestFlashVersion + ' To 3 Step -1 \n';
        doc += '   Set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash." & i) \n';
        doc += '   If IsObject(obFlash) Then \n';
        doc += '      flashVersion = i \n';
        doc += '      Exit For \n';
        doc += '   End If \n';
        doc += 'Next \n';
        doc += '</scr' + 'ipt\> \n';
        document.write(doc);
    }
      
    // WebTV 2.5 supports flash 3
    else if (agent.indexOf("webtv/2.5") != -1) flashVersion = 3;

    // older WebTV supports flash 2
    else if (agent.indexOf("webtv") != -1) flashVersion = 2;

    // Can't detect in all other cases
    else {
        flashVersion = flashVersion_DONTKNOW;
    }

    return flashVersion;
}

flashVersion_DONTKNOW = -1;

/*****************************************************
 Remember flash version in a cookie
*****************************************************/
var dontKnow = false;
var flashVersion = 0;

// Retrieve flash cookie
var cookieStart = document.cookie.indexOf('flash');
if (cookieStart != -1) {
    var cookieEnd = document.cookie.indexOf(';', cookieStart);
    if (cookieEnd == -1) cookieEnd = document.cookie.length;
    flashVersion = document.cookie.substring(cookieStart + 6, cookieEnd); 
}

// If the cookie doesn't exist...
else {
   
    // use flash_detect.js to return the Flash version
    flashVersion = getFlashVersion();
   
    // write the version information to a cookie
    document.cookie = 'flash=' + flashVersion;
}

// For the situation where we can't detect, set the values of the reference variables
if (flashVersion == flashVersion_DONTKNOW) {
    flashVersion = 0;
    dontKnow = true;
}

/*****************************************************
 Write flash or non flash code
*****************************************************/
function writeFlashCode(hasFlashCode,noFlashCode) {
    var requiredFlashVersion = 5;
            
    if (flashVersion >= requiredFlashVersion) {
        document.write(hasFlashCode);
    }
    else {
        document.write(noFlashCode);
    }
}

/*****************************************************
 Write a Cookie Value
*****************************************************/
function setCookie(name, value, expires, path, domain, secure) {
   var curCookie = name + '=' + escape(value) + ((expires) ? '; expires=' + expires.toGMTString() : '') + ((path) ? '; path=' + path : '') + ((domain) ? '; domain=' + domain : '') + ((secure) ? '; secure' : '');
   document.cookie = curCookie;
}

/*****************************************************
 Retrieve a Cookie Value
*****************************************************/
function getCookie(name) {
   var dc = document.cookie;
   
   // find beginning of cookie value in document.cookie
   var prefix = name + "=";
   var begin = dc.indexOf("; " + prefix);
   if (begin == -1) {
      begin = dc.indexOf(prefix);
      if (begin != 0) return null;
   }
   else begin += 2;
   
   // find end of cookie value
   var end = document.cookie.indexOf(";", begin);
   if (end == -1) end = dc.length;
   
   // return cookie value
   return unescape(dc.substring(begin + prefix.length, end));
}

/*****************************************************
 Delete a Cookie Value
*****************************************************/
function deleteCookie(name, path, domain) {
   var value = getCookie(name);
   if (value != null) document.cookie = name + '=' + ((path) ? '; path=' + path : '') + ((domain) ? '; domain=' + domain : '') + '; expires=Thu, 01-Jan-70 00:00:01 GMT';
   return value;
}

/*****************************************************
 Fix Netscape 2.X Bug
*****************************************************/
function fixDate(date) {
   var workingDate = date;
   var base = new Date(0);
   var skew = base.getTime();
   if (skew > 0) workingDate.setTime(workingDate.getTime() - skew);
   return workingDate;
}

/*****************************************************
 Test for Cookie Support
*****************************************************/
function supportsCookies(rootPath) {
   setCookie('checking_for_cookie_support', 'testing123', '', (rootPath != null ? rootPath : ''));
   if (getCookie('checking_for_cookie_support')) return true;
   else return false;
}