//Open link in new window
var newWindow = null;

function closeWin(){
	if (newWindow != null){
		if(!newWindow.closed)
			newWindow.close();
	}
}

function popUpWin(url, type, strWidth, strHeight){
	
	closeWin();
	
	if (type == "fullScreen"){
		strWidth = screen.availWidth - 10;
		strHeight = screen.availHeight - 160;
	}
	
	var tools="";
	if (type == "standard" || type == "fullScreen") tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width="+strWidth+",height="+strHeight+",top=0,left=0";
	if (type == "console") tools = "resizable,toolbar=no,location=no,scrollbars=no,width="+strWidth+",height="+strHeight+",left=0,top=0";
	newWindow = window.open(url, 'newWin', tools);
	newWindow.focus();
}

// photostack
		function MM_jumpMenu(targ,selObj,restore){ //v3.0
  		eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  		if (restore) selObj.selectedIndex=0;
		}

	
// toggle visibility

function toggle( targetId ){
  if (document.getElementById){
  		target = document.getElementById( targetId );
  			if (target.style.display == "none"){
  				target.style.display = "";
  			} else {
  				target.style.display = "none";
  			}
  	}
}

 // this function is need to work around 
  // a bug in IE related to element attributes
  function hasClass(obj) {
     var result = false;
     if (obj.getAttributeNode("class") != null) {
         result = obj.getAttributeNode("class").value;
     }
     return result;
  }   

 function stripe(id) {

    // the flag we'll use to keep track of 
    // whether the current row is odd or even
    var even = false;
  
    // if arguments are provided to specify the colours
    // of the even & odd rows, then use the them;
    // otherwise use the following defaults:
    var evenColor = arguments[1] ? arguments[1] : "#fff";
    var oddColor = arguments[2] ? arguments[2] : "#eee";
  
    // obtain a reference to the desired table
    // if no such table exists, abort
    var table = document.getElementById(id);
    if (! table) { return; }
    
    // by definition, tables can have more than one tbody
    // element, so we'll have to get the list of child
    // &lt;tbody&gt;s 
    var tbodies = table.getElementsByTagName("tbody");

    // and iterate through them...
    for (var h = 0; h < tbodies.length; h++) {
    
     // find all the &lt;tr&gt; elements... 
      var trs = tbodies[h].getElementsByTagName("tr");
      
      // ... and iterate through them
      for (var i = 0; i < trs.length; i++) {

	    // avoid rows that have a class attribute
        // or backgroundColor style
	    if (!hasClass(trs[i]) && ! trs[i].style.backgroundColor) {
 
         // get all the cells in this row...
          var tds = trs[i].getElementsByTagName("td");
        
          // and iterate through them...
          for (var j = 0; j < tds.length; j++) {
        
            var mytd = tds[j];

            // avoid cells that have a class attribute
            // or backgroundColor style
	        if (! hasClass(mytd) && ! mytd.style.backgroundColor) {
        
		      mytd.style.backgroundColor = even ? evenColor : oddColor;
              
            }
          }
        }
        // flip from odd to even, or vice-versa
        even =  ! even;
      }
    }
  }

// for remembering comment preferences			
			var HOST = 'tangerine.local';
			
			// Copyright (c) 1996-1997 Athenia Associates.
			// http://www.webreference.com/js/
			// License is granted if and only if this entire
			// copyright notice is included. By Tomer Shiran.
			
			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;
			}
			
			function getCookie (name) {
			    var prefix = name + '=';
			    var c = document.cookie;
			    var nullstring = '';
			    var cookieStartIndex = c.indexOf(prefix);
			    if (cookieStartIndex == -1)
			        return nullstring;
			    var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
			    if (cookieEndIndex == -1)
			        cookieEndIndex = c.length;
			    return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
			}
			
			function deleteCookie (name, path, domain) {
			    if (getCookie(name))
			        document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
			}
			
			function fixDate (date) {
			    var base = new Date(0);
			    var skew = base.getTime();
			    if (skew > 0)
			        date.setTime(date.getTime() - skew);
			}
			
			function rememberMe (f) {
			    var now = new Date();
			    fixDate(now);
			    now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
			    setCookie('mtcmtauth', f.author.value, now, '', HOST, '');
			    setCookie('mtcmtmail', f.email.value, now, '', HOST, '');
			    setCookie('mtcmthome', f.url.value, now, '', HOST, '');
			}
			
			function forgetMe (f) {
			    deleteCookie('mtcmtmail', '', HOST);
			    deleteCookie('mtcmthome', '', HOST);
			    deleteCookie('mtcmtauth', '', HOST);
			    f.email.value = '';
			    f.author.value = '';
			    f.url.value = '';
			}
			
			//-->


// switch styles

function setActiveStyleSheet(title) {
  var i, a, main;
  for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if (a.getAttribute("rel") &&
        a.getAttribute("rel").indexOf("style") != -1 &&
        a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if (a.getAttribute("rel") &&
        a.getAttribute("rel").indexOf("style") != -1 &&
        a.getAttribute("title") &&
        !a.disabled
        ) return a.getAttribute("title");
  }
  return "one";
}

function getPreferredStyleSheet() {
  var i, a;
  for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if (a.getAttribute("rel") &&
        a.getAttribute("rel").indexOf("style") != -1 &&
        a.getAttribute("rel").indexOf("alt") == -1 &&
        a.getAttribute("title")
        ) return a.getAttribute("title");
  }
  return "one";
}

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 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 "one";
}

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


window.onload = function(e) {
  var cookie = readCookie('style');
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie('style', title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
