// Popup Window

function openWin(url, width, height) {
	var win;
	var windowName;
	var params;
	params = "toolbar=0,";
	params += "location=0,";
	params += "directories=0,";
	params += "status=0,";
	params += "menubar=0,";
	params += "scrollbars=0,";
	params += "resizable=0,";
	params += "top=50,";
	params += "left=50,";
	params += "width="+width+",";
	params += "height="+height;
	win = window.open(url, windowName, params);
}


// Input Box Clearer

function clearInputBox(txtBox) {
   try {
      txtBox.value = "";
   }
   catch (e) {
      // just catch the exception
   }
}

// Window Closer

function closeWindow() {
self.close();
}

// Comparison Table (Family Pages)

function addEvent( obj, type, fn ) {
	if (obj.addEventListener) {
		obj.addEventListener( type, fn, false );
		EventCache.add(obj, type, fn);
	}
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
		EventCache.add(obj, type, fn);
	}
	else {
		obj["on"+type] = obj["e"+type+fn];
	}
}
	
var EventCache = function(){
	var listEvents = [];
	return {
		listEvents : listEvents,
		add : function(node, sEventName, fHandler){
			listEvents.push(arguments);
		},
		flush : function(){
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1){
				item = listEvents[i];
				if(item[0].removeEventListener){
					item[0].removeEventListener(item[1], item[2], item[3]);
				};
				if(item[1].substring(0, 2) != "on"){
					item[1] = "on" + item[1];
				};
				if(item[0].detachEvent){
					item[0].detachEvent(item[1], item[2]);
				};
				item[0][item[1]] = null;
			};
		}
	};
}();
addEvent(window,'unload',EventCache.flush);

// popupwindow functions
function popupwindow(file, width, height) {
/* this is where we take in the file information */
	var WIDTH_SPACE = 20;
	var HEIGHT_SPACE = 20;
	
	if (popupwindow.arguments[0] == null || popupwindow.arguments[0].length < 3) {
	   return false;
	}
	else if ((popupwindow.arguments[1] == null) || 
	    (popupwindow.arguments[1].length < 1) ||
	    (popupwindow.arguments[2] == null) ||
	    (popupwindow.arguments[2].length < 1)) {

	    var resultArray = calculateDimensions(popupwindow.arguments[0]);
	    openPopupWindow(popupwindow.arguments[0], getWidth(resultArray[0], WIDTH_SPACE), getHeight(resultArray[1], HEIGHT_SPACE));
	}
	else {
	    openPopupWindow(popupwindow.arguments[0], popupwindow.arguments[1], popupwindow.arguments[2]);
	}
}

function calculateDimensions(filename) {

	var matchparam = /(\d+)x(\d+)_/;
	var sizeArray = new Array(2);
	sizeArray[0] = 500;
	sizeArray[1] = 500;
	
	if (window.RegExp) {
		var regexp = new RegExp(matchparam);
		
		if (regexp.test(filename)) {
			filename.match(matchparam);
			sizeArray[0] = RegExp.$1;
			sizeArray[1] = RegExp.$2;
		}
	}
	
	return sizeArray;
}

function getWidth(w, space) {
	return parseInt(parseInt(w)+parseInt(space));
}

function getHeight(h, space) {
	return parseInt(parseInt(h)+parseInt(space));
}

function openPopupWindow(url, width, height)
{
	var newwindow = null;
	var name = "feature_ss";

	newwindow = window.open(url,name,"height="+height+",width="+width+",resizable=yes");
	if (window.focus) { newwindow.focus(); }
}
// End popup window functions

// Image Preload function
var arImages=new Array();
function ImagePreload() {
    for(x=0; x < pImages.length; x++) {
        arImages[x] = new Image();
        arImages[x].src=pImages[x];
    }
}

// Macromedia hack/fix for Active X warning when displaying flash-swf files, windows media, QuickTime, etc. 
//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
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 = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';
  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":
        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 "id":
      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;
}

// Function to add window load event
// Copyright Simon Willison
// http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addWindowLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
