// 'global' misc_functions.js v1.0
function GetCookie(name) { 
	var arg=name+"="; 
	var alen=arg.length; 
	var clen=document.cookie.length; 
	var i=0; 
	while (i<clen) { 
		var j=i+alen; 
		if (document.cookie.substring(i,j)==arg) 
			return "here"; 
		i=document.cookie.indexOf(" ",i)+1; 
		if (i==0) break; 
	} 
	return null; 
} 

function SetCookie(cookieName, popupPage, w, h, days) {
	var visit=GetCookie(cookieName); 
	if (visit==null){ 
		var expire=new Date(); 
		window.name = "thiswin"; 
		newwin=open(popupPage, "dispwin","width="+w+",height="+h+",scrollbars=no,menubar=no"); 
		expire=new Date(expire.getTime()+(days*86400000)); 
		document.cookie=cookieName+"=here; expires="+expire; 
	}
}
	
function newWindow(message, w, h) {
	leftPos = 0
	if (screen) {
		leftPos = screen.width - w
	}
	w = w - 10
	SiteWindow = window.open(message, 'message', 'scrollbars=1,width='+w+',height='+h+',left='+leftPos+',top=1,')
	SiteWindow.focus()
}

function popupWindow(page, w, h) {
	newwin = open(page, "dispwin", "width="+w+",height="+h+",scrollbars=no,menubar=no");
}

function countLetters(form) {
	var str = form.message.value
	document.forms[0].totlen.value=str.length
}

function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

function writeout(spanid, outputhtml) {
	if (document.getElementById) {
		if (window.HTMLElement) {
			spanNode = document.getElementById(spanid);
			while (spanNode.hasChildNodes()) spanNode.removeChild(spanNode.lastChild);
			var range = document.createRange();
			range.selectNodeContents(spanNode);
			spanNode.appendChild(range.createContextualFragment(outputhtml));
		} else {
			document.all(spanid).innerHTML = outputhtml;
		}
	} else if (document.all) {
		document.all(spanid).innerHTML = outputhtml;
//	} else if (document.layers) {
//		document.layers[spanid].document.open();
//		document.layers[spanid].document.writeln(outputhtml);
//		document.layers[spanid].document.close();
	}
}

