var Now = new Date();
var Start = Now.getTime();

if (screen && screen.width && screen.width>1 && screen.width<801) {
  document.write("<style>");
  document.write("#content {overflow:hidden}\n");
  document.write("#gsright {display:none}\n");
  document.write("#middlestuff,#rightstuff {display:none}\n");
  document.write("#toptable,#content {width:780px !important}\n");
  document.write("#toptable {padding-left:20px}\n");
  document.write("#content2 {width:732px !important}\n");
  document.write("</style>");
}

function navigate(Event) {
  if(Event==null) Event=event;
  if(Event.type!='keyup') return;
  switch (Event.keyCode) {
    case 27:
      var murl = document.location.href.match(/\/\/([^\.]*)\.([^\/]*)/);
      document.location.href="http://"+murl[1]+"." + murl[2] + "/myblog.mws";
      return;
    case 119:
    case 120:
      document.getElementById('quickupdate').style.display='block';
      document.getElementById('iama').focus();
    default: return;
  }
}
document.onkeyup=navigate;

function loadControl() {
  if (document.getElementById("timerms")) {
    var n = new Date();           // Grab new copy of date
    var s = n.getTime();          // Grab current millisecond #
    var diff = s - Start; 
    document.getElementById("timerms").innerHTML=diff+"ms";
  }
  if (!document.location.href.match(/\?/)) {
    var murl = document.location.href.match(/\/\/([^\.]*)\.([^\/]*)/);
    document.cookie = "escape"+"="+document.location.href+"; path=/; domain="+murl[2];
  }
//  var indiead = document.getElementById("indiead");
//  if (indiead) {
//    for (var i=0;i<indiead.childNodes.length;i++) {
//      if (indiead.childNodes[i] && indiead.childNodes[i].childNodes[0] && indiead.childNodes[i].childNodes[0].width && indiead.childNodes[i].childNodes[0].width > 468)
//        document.getElementById("googlesearch").style.display='none';
//    }
//  }
}

function getCalendarDate(now) {
  var months = new Array(13);
  months[0] = "January";
  months[1] = "February";
  months[2] = "March";
  months[3] = "April";
  months[4] = "May";
  months[5] = "June";
  months[6] = "July";
  months[7] = "August";
  months[8] = "September";
  months[9] = "October";
  months[10] = "November";
  months[11] = "December";
  var monthnumber = now.getMonth();
  var monthname = months[monthnumber];
  var monthday = now.getDate();
  var year = now.getYear();
  if(year < 2000) { year = year + 1900; }
  var dateString = monthname + 
  ' ' + 
  monthday + 
  ', ' + 
  year;
  return dateString;
} 

function getClockTime(now) {
  var hour = now.getHours();
  var minute = now.getMinutes();
  var second = now.getSeconds();
  var ap = "AM";
  if (hour > 11) { ap = "PM"; }
  if (hour > 12) { hour = hour - 12; }
  if (hour == 0) { hour = 12; }
  if (minute < 10) { minute = "0" + minute; }
  var timeString = hour + 
  ':' + 
  minute + 
  " " + 
  ap;
  return timeString;
} 


function goDate(t,u) {
  d = new Date(t*1000);
  if (u) {
	document.write((getCalendarDate(d)+" at "+getClockTime(d)).toUpperCase());
  } else {
    document.write(getCalendarDate(d)+" at "+getClockTime(d));
  }
}

function iAm() {
  var iamq = document.getElementById('iamq');
  var iama = document.getElementById('iama');
  var bg = document.forms["iform"];
  bg.action.value='iam';
  bg.param.value=iamq[iamq.selectedIndex].innerHTML+":"+iama.value;
  bg.submit();
}

function setStyleById(i, p, v) {
	var n = document.getElementById(i);
	n.style[p] = v;
}

function setStyleByClass(t,c,p,v){
  var ie = (document.all) ? true : false;
	var elements;
	if(t == '*') {
		elements = (ie) ? document.all : document.getElementsByTagName('*');
	} else {
		elements = document.getElementsByTagName(t);
	}
	for(var i = 0; i < elements.length; i++){
		var node = elements.item(i);
		for(var j = 0; j < node.attributes.length; j++) {
			if(node.attributes.item(j).nodeName == 'class') {
				if(node.attributes.item(j).nodeValue == c) {
					eval('node.style.' + p + " = '" +v + "'");
				}
			}
		}
	}
}

function gotcookies() {
  setCookie("cookietest","true");
  var x= getCookie("cookietest");
  deleteCookie("cookietest");
  return x;
}

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 dc = 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;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

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 switchmode() {
  var htmlmode = getCookie('htmlmode');
  if (htmlmode == "1") {
    htmlmode = "2";
  } else {
    htmlmode = "1";
  }
  var today = new Date();
  var expire = new Date();
  expire.setTime(today.getTime() + 3600000*24*200);
  setCookie("htmlmode",htmlmode, expire, "/")
  setTimeout("document.location.href=document.location.href",500);
}