
//********************************************************
// styles
// modified from http://dhtmlkitchen.com/learn/js/setstyle/index.jsp
//********************************************************

function getStyle(el,style){
 var value = el.style[toCamelCase(style)];
 if (!value){
  if (document.defaultView) value=document.defaultView.getComputedStyle(el,"").getPropertyValue(style);
  else if (el.currentStyle) value=el.currentStyle[toCamelCase(style)];
 }
  return value;
}

function setStyle(el, style, value) {
 el.style[style]=value;
}

function toCamelCase( sInput ) {
  var oStringList = sInput.split('-');
  if(oStringList.length == 1) 
    return oStringList[0];
  var ret = sInput.indexOf("-") == 0 ?
   oStringList[0].charAt(0).toUpperCase() + oStringList[0].substring(1) : oStringList[0];
  for(var i = 1, len = oStringList.length; i < len; i++){
    var s = oStringList[i];
    ret += s.charAt(0).toUpperCase() + s.substring(1)
  }
  return ret;
}

function show(id){document.getElementById(id).style['display']='block';}
function hide(id){document.getElementById(id).style['display']='none';}
function toggle_display(id){document.getElementById(id).style['display']=='none'?show(id):hide(id);}
function mask(id){document.getElementById(id).style['visibility']='hidden';}
function unmask(id){document.getElementById(id).style['visibility']='visible';}


//********************************************************
// links
//********************************************************

function mail_to(user,domain,subject,body){
 var url='mailto:'+user+'@'+domain;
 if (subject){ url+='?subject='+subject; if (body){ url+='&body='+body; } }
 window.location=url;
}


//********************************************************
// include_once
// modified from http://www.phpied.com/javascript-include/
//********************************************************

var included_files = new Array();
function include_once(script_filename) {
  for (var i = 0; i < included_files.length; i++) 
  { if (included_files[i] == script_filename) return; }
  included_files[included_files.length] = script_filename;
  include_dom(script_filename);
}

function include_dom(script_filename) {
  var html_doc = document.getElementsByTagName('HEAD').item(0);
  var t=script_filename.substring(script_filename.lastIndexOf('.')+1);
  if (t=='js') {
    var file = document.createElement('script');
    file.setAttribute('language','javascript');
    file.setAttribute('type','text/javascript');
    file.setAttribute('src',script_filename);
  } else if (t=='css') {
    var file = document.createElement('link');
    file.setAttribute('rel','stylesheet');
    file.setAttribute('type','text/css');
    file.setAttribute('href',script_filename);
  }
  html_doc.appendChild(file);
  return false;
}


//********************************************************
// cookies
// from http://www.quirksmode.org/js/cookies.html
//********************************************************

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


//********************************************************
// window
//********************************************************

function param(k){
var ss=document.location.search;
var params=ss.substr(1,ss.length-1).split(';');
for (var i=0;i<params.length;i++){ var args = params[i].split('=');
if (args[0]==k){ if (args.length > 1) return args[1]; return args[0]; }
}}

function set_status(str){status=str;}

function resize_n_center(win,w,h){
var t=win.top; if(w<64)w=500; if(h<64)h=400;
if (t.innerWidth) {
	w+=t.outerWidth-t.innerWidth;
	h+=t.outerHeight-t.innerHeight;
} else if (t.document.documentElement.clientWidth) {
	win.resizeTo(800,600);
	w+=800-t.document.documentElement.clientWidth;
	h+=600-t.document.documentElement.clientHeight;
} else if (t.document.body.offsetWidth) {
	win.resizeTo(800,600);
	w+=800-t.document.body.offsetWidth;
	h+=600-t.document.body.offsetHeight;
}
win.moveTo((screen.width-w)/2,(screen.height-h)/2);
win.resizeTo(w,h);
}

function do_popup(a,w,h){
var opts = 'toolbar=no,location=no,status=no,menubar=no';
opts+=',scrollbars=yes,resizable=yes';
opts+=',width='+w+',height='+h+',dependent=yes';
var win=window.open(a,a,opts);
win.focus(); resize_n_center(win,w,h);
return false;
}

function parse_popups(el){
if (!el) el=document;
if (!el.getElementsByTagName) return false;
var links = el.getElementsByTagName('a');
for (var i=0; i<links.length; i++) { if (links[i].className.match("popup")) { 
    links[i].onclick = function() { 
        var w=parseInt(this.style.width.substring(0,3));
        var h=parseInt(this.style.height.substring(0,3));
        return do_popup(this.href,w,h); 
    };
}}
}


//********************************************************
// correctPNG
// from http://homepage.ntlworld.com/bobosola/
// 
// correctly handle PNG transparency in Win IE 5.5 & 6.
//********************************************************

function correctPNG()
{
   if (document.body.filters)
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? img.className : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgTitle
            + " class=\"" + imgClass + " png_span\""
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}

//********************************************************
// page loading
//********************************************************

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

addLoadEvent(parse_popups);

// fix transparent PNGs in IE5+6
// this only fixes images in the HTML
// it does not affect CSS images
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])
if ((version >= 5.5) && (version < 7)) addLoadEvent(correctPNG);
