
// Storage place for generic javascript functions
var SA_body = document.documentElement ? document.documentElement : (document.body ? document.body : null);

function addEvent(elm, evType, fn, useCapture) {
    var r = true;
    if(elm.addEventListener) elm.addEventListener(evType, fn, useCapture);
    else if(elm.attachEvent) r = elm.attachEvent('on' + evType, fn);
    else elm['on' + evType] = fn;
    return r;
}

function removeEvent(elm, evType, fn, useCapture) {
    if(elm.removeEventListener) elm.removeEventListener(evType, fn, useCapture);
    if(elm.detachEvent) elm.detachEvent('on' + evType, fn);
    elm['on' + evType] = null;
    return true;
}


function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') window.onload = func;
    else { window.onload = function() { oldonload(); func(); } }
}

function copyObj(obj) {
    var c = new Object();
    for(var e in obj) c[e] = obj[e];
    return c;
}

function mousePos(e) {
    if(!e) return null;
    var pos = new Object();
    
    pos['x'] = (e.pageX ? e.pageX : e.clientX + SA_body.scrollLeft);
    pos['y'] = (e.pageY ? e.pageY : e.clientY + SA_body.scrollTop);

    return pos;
}

// isInArray -- true if 'needle' is in 'haystack'
function WW_isInArray( needle, haystack ) {
    if(needle == undefined || haystack == undefined) return false;

    for(i_hay = 0; i_hay < haystack.length; i_hay++) {
        if(needle == haystack[i_hay]) { return true; }
    }
    return false;
}

var _WW_focus_id;
function WW_setFocus(id) {
    _WW_focus_id = id;
}

var _WW_focus_ignore = new Array();
function WW_ignoreForm(form) {
    _WW_focus_ignore.push(form);
}

function WW_focusElement(el) {
    var exclusionList = new Array('hidden', 'checkbox', 'radio', 'file', 'select-one', 'select-multiple', 'reset', 'button', 'submit');
    if(el && el.type && !WW_isInArray(el.type, exclusionList) && el.style && el.style.display != 'none') {
        if(WW_elementHeight(el) + el.offsetHeight < WW_windowHeight()) { el.focus(); }
        return true;
    }
    return false;
}

// focusFirst
//  -- focuses the first 'usable' field on a page
function WW_focusFirst() {    
    if(_WW_focus_id) {
        if(WW_focusElement(document.getElementById(_WW_focus_id))) { return; }
    }
    
    // others = 'text'
    for(i = 0; i < document.forms.length; i++) {
        if(document.forms[i] && document.forms[i].elements &&
           !WW_isInArray(document.forms[i], _WW_focus_ignore)) {
        for(j = 0; j < document.forms[i].elements.length; j++) {
            element = document.forms[i].elements[j];
            if(WW_focusElement(element)) { return; }
        }
        }
    }
}

function WW_windowHeight() {
    if(window.innerHeight && typeof(window.innerHeight) == 'number') return window.innerHeight;
    else if(document.documentElement && document.documentElement.clientHeight) return document.documentElement.clientHeight;
    else if(document.body && document.body.clientHeight) return document.body.clientHeight;
    else return false;
}
function WW_elementHeight( element ) {
    // calculate the location of the element in the page by moving up the heirachy
    yPos = element.offsetTop;
    tempEl = element.offsetParent;
    while (tempEl != null) {
        yPos += tempEl.offsetTop;
        tempEl = tempEl.offsetParent;
    }
    return yPos;
}

function WW_pageWidth() 
{
    return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;
}

function WW_pageHeight() 
{
    return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;
}

function WW_posLeft() 
{
    return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement && document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;
}

function WW_posTop() 
{
    return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement && document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;
}

function WW_$(x)
{
    return document.getElementById(x);
}

function WW_scrollFix()
{
    var obol=WW_$('ol');
    obol.style.top=WW_posTop()+'px';
    obol.style.left=WW_posLeft()+'px';
}

function WW_sizeFix()
{
    var obol=WW_$('ol');
    obol.style.height=WW_pageHeight()+'px';
    obol.style.width=WW_pageWidth()+'px';
}

function WW_kp(e)
{
    ky=e?e.which:event.keyCode;
    if(ky==88||ky==120)WW_hm();
    return false
}

function WW_inf(h)
{
    tag=document.getElementsByTagName('select');
        for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=h;
        
    tag=document.getElementsByTagName('iframe');
        for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=h;
        
    tag=document.getElementsByTagName('object');
        for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=h;
}

function WW_dis(d)
{
    form = document.getElementsByTagName('form');

    // Input fields
    for(i=form.length-1; i>=0; i--) {
        inputs = form[i].getElementsByTagName('input');
        for(j=inputs.length-1;j>=0;j--) {
            tempId = inputs[j].id;
            tempName = inputs[j].name;
            tempVal = inputs[j].value;
            inputs[j].disabled = d;

            var hiddenEl = document.createElement('input');
            hiddenEl.setAttribute('type', 'hidden');
            hiddenEl.setAttribute('id', tempId);
            hiddenEl.setAttribute('name', tempName);
            hiddenEl.setAttribute('value', tempVal);
            form[i].appendChild(hiddenEl);
        }
    }

    // Select fields
    for(i=form.length-1; i>=0; i--) {
        selects = form[i].getElementsByTagName('select');
        for(j=selects.length-1;j>=0;j--) {
            tempId = selects[j].id;
            tempName = selects[j].name;
            tempVal = selects[j].value;
            selects[j].disabled = d;

            var hiddenEl = document.createElement('input');
            hiddenEl.setAttribute('type', 'hidden');
            hiddenEl.setAttribute('id', tempId);
            hiddenEl.setAttribute('name', tempName);
            hiddenEl.setAttribute('value', tempVal);
            form[i].appendChild(hiddenEl);
        }
    }

    //tag=document.getElementsByTagName('select');
        //for(i=tag.length-1;i>=0;i--)tag[i].disabled=d;

    //tag=document.getElementsByTagName('input');
        //for(i=tag.length-1;i>=0;i--)tag[i].disabled=d;
}

function WW_popup_wait()
{
    var obl='dialogBox';
    var wd='400';
    var ht='200';

    var v='visible';
    var h='hidden';
    var b='block';
    var p='px';
    var obol=WW_$('ol'); var obbxd = WW_$('mbd');
    if(WW_$(obl)) {
        obbxd.innerHTML = WW_$(obl).innerHTML;
        obol.style.height=WW_pageHeight()+p;
        obol.style.width=WW_pageWidth()+p;
        obol.style.top=WW_posTop()+p;
        obol.style.left=WW_posLeft()+p;
        obol.style.display=b;
        var tp=WW_posTop()+((WW_pageHeight()-ht)/2)-12;
        var lt=WW_posLeft()+((WW_pageWidth()-wd)/2)-12;
        var obbx=WW_$('mbox');
        obbx.style.top=(tp<0?0:tp)+p;
        obbx.style.left=(lt<0?0:lt)+p;
        obbx.style.width=wd+p;
        obbx.style.height=ht+p;
        WW_inf(v);
        //WW_dis(true); //** not working because the data won't get posted to the server and cause the form to stuck **
        obbx.style.display=b;
    }
    return false;
}

function WW_hm()
{
    var v='visible';
    var n='none';
    if(WW_$('ol')) WW_$('ol').style.display=n;
    if(WW_$('mbox')) WW_$('mbox').style.display=n;
    WW_inf(v);
    document.onkeypress=''
}

function WW_initmb()
{
    var ab='absolute';
    var n='none';
    var obody=document.getElementsByTagName('body')[0];
    var frag=document.createDocumentFragment();
    var obol=document.createElement('div');
    obol.setAttribute('id','ol');
    obol.style.display=n;
    obol.style.position=ab;
    obol.style.top=0;
    obol.style.left=0;
    obol.style.zIndex=998;
    obol.style.width='100%';
    frag.appendChild(obol);
    var obbx=document.createElement('div');
    obbx.setAttribute('id','mbox');
    obbx.style.display=n;
    obbx.style.position=ab;
    obbx.style.zIndex=999;
    var obl=document.createElement('span');
    obbx.appendChild(obl);
    var obbxd=document.createElement('div');
    obbxd.setAttribute('id','mbd');
    obl.appendChild(obbxd);
    frag.insertBefore(obbx,obol.nextSibling);
    obody.insertBefore(frag,obody.firstChild);
    window.onscroll = WW_scrollFix; window.onresize = WW_sizeFix;
}


//v1.7
// Flash Player Version Detection
// Detect Client Browser type
// Copyright 2005-2008 Adobe Systems Incorporated.  All rights reserved.
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
function ControlVersion()
{
	var version;
	var axo;
	var e;
	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry
	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}
	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";
			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";
			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}
	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}
	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}
	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}
	
	return version;
}
// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");			
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			var versionRevision = descArray[3];
			if (versionRevision == "") {
				versionRevision = descArray[4];
			}
			if (versionRevision[0] == "d") {
				versionRevision = versionRevision.substring(1);
			} else if (versionRevision[0] == "r") {
				versionRevision = versionRevision.substring(1);
				if (versionRevision.indexOf("d") > 0) {
					versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
				}
			}
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		flashVer = ControlVersion();
	}	
	return flashVer;
}
// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
	versionStr = GetSwfVer();
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			// Given "WIN 2,0,0,11"
			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			tempString        = tempArray[1];			// "2,0,0,11"
			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];
        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer)) {
			return true;
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer))
				return true;
			else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision))
					return true;
			}
		}
		return false;
	}
}
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}
function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '';
  if (isIE && isWin && !isOpera)
  {
    str += '<object ';
    for (var i in objAttrs)
    {
      str += i + '="' + objAttrs[i] + '" ';
    }
    str += '>';
    for (var i in params)
    {
      str += '<param name="' + i + '" value="' + params[i] + '" /> ';
    }
    str += '</object>';
  }
  else
  {
    str += '<embed ';
    for (var i in embedAttrs)
    {
      str += i + '="' + embedAttrs[i] + '" ';
    }
    str += '> </embed>';
  }
  document.write(str);
}
function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}
function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}
function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    
    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblclick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
      case "id":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}
