function getObject(id) {
	var ret=null;
    if (document.getElementById) {
        eval("ret = document.getElementById(id)");
    } else {
        if (document.layers) {
            ret = document.layers[id];
        } else {
            if (document.all) {
                eval("ret = document.all." + id);
            }
        }
    }
	return(ret);
}

function changeVisibility(id, show) {
	if(show) {
		NNtype='show';
		IEtype='visible';
		WC3type='visible';
	} else {
		NNtype='hidden';
		IEtype='hidden';
		WC3type='hidden';
	}
    if (document.getElementById) {
        eval("document.getElementById(id).style.visibility = \"" + WC3type + "\"");
    } else {
        if (document.layers) {
            document.layers[id].visibility = NNtype;
        } else {
            if (document.all) {
                eval("document.all." + id + ".style.visibility = \"" + IEtype + "\"");
            }
        }
    }
}
function changeDisplay(id, show) {
	action = "none";
	if(show) {
       action  =  "block";
	}
	getObject(id).style.display = action;
/*    if (document.getElementById) {
        eval("document.getElementById(id).style.display = \"" + action + "\"");
    } else {
        if (document.layers) {
            document.layers[id].display = action;
        } else {
            if (document.all) {
                eval("document.all." + id + ".style.display = \"" + action + "\"");
            }
        }
    }*/
}

function toggleDisplay(id) {
/*	var current="";
    if (document.getElementById) {
        eval("current = document.getElementById(id).style.display");
    } else {
        if (document.layers) {
            current = document.layers[id].display;
        } else {
            if (document.all) {
                eval("current = document.all." + id + ".style.display ");
            }
        }
    }
    if(current=="none") {
		changeDisplay(id,true);
    } else {
		changeDisplay(id,false);
    }
    */
    if(getObject(id).style.display=="none"||getObject(id).style.display=="") {
		changeDisplay(id,true);
		return true;
    } else {
		changeDisplay(id,false);
		return false;
    }
}

function toggleDisplayRemember(id) {
	// create an instance of the Date object
	var cookieExpiration = new Date();
	// fix the bug in Navigator 2.0, Macintosh
	fixDate(cookieExpiration);
	// cookie expires in one year (actually, 365 days)
	// 365 days in a year
	// 24 hours in a day
	// 60 minutes in an hour
	// 60 seconds in a minute
	// 1000 milliseconds in a second
	cookieExpiration.setTime(cookieExpiration.getTime() + 2 * 7 * 24 * 60 * 60 * 1000);

	setCookie(id,toggleDisplay(id),cookieExpiration);
}

function initDisplayRemember(id) {
	var tmp = getCookie(id);
	if(tmp!=null) {
		changeDisplay(id,"true"==tmp);
	}
}

function addZeros(width,num) {
	var ret=""+num;
	var tmp=1;
	while(ret.length<width) {
		ret="0"+ret;
	}
	return ret;
}

function calcweek(now) {
	// Week of the year script - By Ada Shimar (ada@chalktv.com)
	// Based on code by Duncan Kabinu, Florida Department of Agriculture.
	// Modified by Italian anonimous on 19.08.2002
	// Visit JavaScript Kit (http://javascriptkit.com) for this script and 400+ more

	var totalDays = 0;
	years=now.getYear();
	var days = new Array(12); // Array to hold the total days in a month
	days[0] = 31;
	days[2] = 31;
	days[3] = 30;
	days[4] = 31;
	days[5] = 30;
	days[6] = 31;
	days[7] = 31;
	days[8] = 30;
	days[9] = 31;
	days[10] = 30;
	days[11] = 31;
	 
	// Check to see if this is a leap year
	if (Math.round(now.getYear()/4) == now.getYear()/4) {
		days[1] = 29
	}else{
		days[1] = 28
	}
	 
	// If this is January no need for any fancy calculation otherwise figure out the
	// total number of days to date and then determine what week
	if (now.getMonth() == 0) { 
		totalDays = totalDays + now.getDate();
	} else {
		var curMonth = now.getMonth();
		for (var count = 1; count <= curMonth; count++) {
			totalDays = totalDays + days[count - 1];
		}
		totalDays = totalDays + now.getDate();
	}

	// Here is the modification: considering when start the 1st week of year.
	// Originally was only: var week = Math.round(totalDays/7)
	// Check if browser is "Microsoft Internet Explorer" or not and apply the right var
	var agt=navigator.userAgent.toLowerCase();
	if ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1)) {
		var firstday=new Date("01/01/"+String(now.getYear())).getDay();
	} else {
		var firstday=new Date("01/01/"+String(1900+now.getYear())).getDay();
	}
	var diff=7-firstday+1;
	var week = Math.round((totalDays+diff-firstday)/7)+1;
	return week;
}

function getthedate(id) {
	var mydate=new Date();
	
	//change font size here
	var cdate= addZeros(2,mydate.getHours())+":" + addZeros(2,mydate.getMinutes())+":" +addZeros(2,mydate.getSeconds()) + "&nbsp;/&nbsp;" + mydate.getDate() + "." + (mydate.getMonth()+1)+ ".&nbsp;/&nbsp;" + calcweek(mydate);

	getObject(id).innerHTML=cdate;
}

function startTheTimer(id) {
	if (getObject(id)) {
		setInterval("getthedate('"+id+"')",1000);
	}
}

// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
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;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
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));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
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";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

function trim(str) {
	return( (""+str).replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') );
}

function convertUrl(id,type,val,target) {
	obj = getObject(id);
	if(val.length>0) {

		if("1" == target) {
			obj.target="_blank";
		} else {
			obj.target="";
		}
		
		removeNodeChildren(obj);
		
		switch(parseInt(type)) {
			case 1:
				obj.href="view-source:"+formatURL(val);
				obj.appendChild(document.createTextNode("source"));
			break;
			case 2:
				obj.href=formatURL(val);
				obj.appendChild(document.createTextNode("link"));
			break;
			case 3:
				obj.href='http://access.adobe.com/perl/convertPDF.pl?reflow_p=checkbox&url='+formatURL(val);
				obj.text = "pdf->html";
			break;
			case 4:
				obj.href='http://access.adobe.com/perl/convertPDF.pl?url='+formatURL(val);
				obj.text = "pdf->html";
			break;
			default:
			break;
		}
	} else {
		obj.target = "";
		obj.href = "";
	}
}

function formatURL(url) {
	url=trim(url);
	if(url.indexOf("http://")!=0 && url.indexOf("ftp://")!=0 && url.indexOf("file://")!=0) {
		return "http://"+url;
	}
	return url;
}

function removeNodeChildren(obj) {
	while(obj.hasChildNodes() == true)
	{
		obj.removeChild(obj.childNodes[0]);
	}
}

function convertTool(id,type,val) {
	obj = getObject(id);
	if(val.length>0) {
		switch(type) {
			case "webirc":
			if(val.length == 8) {
				obj.innerHTML="123"+val;
				var ipArray = new Array(4);
				ipArray[0]=val.substring(0,2);
				ipArray[1]=val.substring(2,4);
				ipArray[2]=val.substring(4,6);
				ipArray[3]=val.substring(6,8);
				obj.innerHTML= parseInt('0x'+ipArray[0])+"."+parseInt('0x'+ipArray[1])+"."+parseInt('0x'+ipArray[2])+"."+parseInt('0x'+ipArray[3]);
			} else {
				obj.innerHTML="";
			}
			break;
		}
	} else {
		obj.innerHTML="";
	}

}
