function DeleteCookie (name) {
  var exp = new Date();
  exp.setTime (exp.getTime() - 1);
  var cval = GetCookie (name);
  if (cval != null)
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
  var argv = GetCookie.arguments;
  var argc = GetCookie.arguments.length;
  var defaultvalue = (argc > 1) ? argv[1] : null;
  var arg = name + "=";
  var alen = arg.length;
  var cookievalue;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg){
      cookievalue = getCookieVal(j);
      if(cookievalue == "null") return defaultvalue;
      return getCookieVal (j);
    }
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return defaultvalue;
}

function SetCookie (name, value) {
  var argv = SetCookie.arguments;
  var argc = SetCookie.arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;
  document.cookie = name + "=" + escape (value) +
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
}

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
  var argv = GetCookie.arguments;
  var argc = GetCookie.arguments.length;
  var defaultvalue = (argc > 1) ? argv[1] : null;
  var arg = name + "=";
  var alen = arg.length;
  var cookievalue;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg){
      cookievalue = getCookieVal(j);
      if(cookievalue == "null") return defaultvalue;
      return getCookieVal (j);
    }
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return defaultvalue;
}

function SetCookie (name, value) {
  var argv = SetCookie.arguments;
  var argc = SetCookie.arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;
  document.cookie = name + "=" + escape (value) +
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
}

function DeleteCookie (name) {
  var exp = new Date();
  exp.setTime (exp.getTime() - 1);  // This cookie is history
  var cval = GetCookie (name);
  if (cval != null)
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function makearray(n) {
	this.length = n
	for (var i = 1; i <= n; i++) {
		this[i] = null;
    }
    return this;
}

function IsIn(value,search) {
	if(search.indexOf(value) != -1) {
	  return 1;
    }
    else {
		return 0;
    }
}

function DateFormat(format,twoplace) {
var operators = 'HIMSpdDmMyY%';
var value = '';

var today = new Date();
var datevalue = '';

weekday = today.getDay();
month = today.getMonth();
year=today.getYear();
if(year > 1900) year -= 1900; // correct for year
date = today.getDate();
var days = new makearray(7);
days[0] = 'Sunday';
days[1] = 'Monday';
days[2] = 'Tuesday';
days[3] = 'Wednesday';
days[4] = 'Thursday';
days[5] = 'Friday';
days[6] = 'Saturday';
var months = new makearray(12);
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';

hours = today.getHours();
minutes = today.getMinutes();
seconds =today.getSeconds();

var pos = 0;
while (pos < format.length) {
	if( format.substring(pos,pos+1) != '%') 
	{
		datevalue += format.substring(pos,pos+1);
		pos++;
		continue;
	} else {
		if (!IsIn(format.substring(pos,pos+1), operators))		{			datevalue += format.substring(pos,pos+1);
			pos++;
			continue;
		} else {
			if ( format.substring(pos,pos+1) == '%') 			{
				pos++; // look ahead
				if (format.substring(pos,pos+1) == '%') 
				{
					datevalue += '%';
					pos++;
					continue;
				} else {
				if (format.substring(pos,pos+1) == 'd') 
				{
					if(twoplace) if(date < 10) datevalue += '0';
					datevalue += date;
					pos++;
					continue;
				} else {				if (format.substring(pos,pos+1) == 'A') 
				{					datevalue += days[weekday];
					pos++;
					continue;
				} else {
				if (format.substring(pos,pos+1) == 'a') 
				{
					datevalue += days[weekday].substring(0,3);
					pos++;
					continue;
				} else {
				if (format.substring(pos,pos+1) == 'm') 
				{
					if(twoplace) if(month+1 < 10) datevalue += '0';
					datevalue += month+1;
					pos++;
					continue;
				} else {
				if (format.substring(pos,pos+1) == 'B') 
				{
					datevalue += months[month];
					pos++;
					continue;
				} else {
				if (format.substring(pos,pos+1) == 'b') 
				{					datevalue += months[month].substring(0,3);
					pos++;
					continue;
				} else {
				if (format.substring(pos,pos+1) == 'y') 
				{
					datevalue += year;
					pos++;
					continue;
				} else {
				if (format.substring(pos,pos+1) == 'Y') 
				{
					datevalue += 1900 + year;
					pos++;
					continue;
				} else {
				if (format.substring(pos,pos+1) == 'H') 
				{
					if(twoplace) if(hours < 10) datevalue += '0';
					datevalue += hours;
					pos++;
					continue;
				} else {
				if (format.substring(pos,pos+1) == 'M') 
				{
					if(twoplace) if(minutes < 10) datevalue += '0';
					datevalue += minutes;
					pos++;
					continue;
				} else {
				if (format.substring(pos,pos+1) == 'I') 
				{
					var newhours = hours;
					if(hours > 12) newhours = hours - 12;
					//if(twoplace) LeadZeroCookie(newhours);
					datevalue += newhours;
					pos++;
					continue;
				} else {
				if (format.substring(pos,pos+1) == 'S') 
				{
					if(twoplace) if(seconds < 10) datevalue += '0';
					datevalue += seconds;
					pos++;
					continue;
				} else {
				if (format.substring(pos,pos+1) == 'p') 
				{
					if (hours < 12) 
						datevalue += 'AM';
					else 						datevalue += 'PM';
					pos++;
					continue;
				} 
       pos++; // ignore the char 
		}
} } } } } } } } } } } } } } } } return datevalue}
