function popitup(url,width,height,imgfit,title){
	var use_width;
	var use_height;
	var use_title;
	use_width = (width != null ? width : '860px');
	use_height = (height != null ? height : '650px');
	use_title = (title != null ? title : '');
	newwindow=window.open(url,'name','height=' + use_height + ',width=' + use_width + ',toolbar=no');
	if (imgfit == true)
	{
		newwindow.document.write('<html><head><title>' + use_title + '</title><\/head><body background="' + url + '"><\/body><\/html>');
		html = "<HTML><HEAD><TITLE>" + title + "</TITLE>"
			+ "</HEAD><BODY LEFTMARGIN=0 MARGINWIDTH=0 TOPMARGIN=0 MARGINHEIGHT=0>"
			+ "<CENTER>" 
			+ "<IMG SRC='" + url + "' BORDER=0 NAME=image " 
			+ "onload=''>"
			+ "</CENTER>" 
			+ "</BODY></HTML>";
		newwindow.document.open();
		newwindow.document.write(html);
		newwindow.document.close();
	}
	if (window.focus) {newwindow.focus()}
	return false;
}
				
function bookmarksite(title, url){
	if (document.all)
		window.external.AddFavorite(url, title);
	else if (window.sidebar)
		window.sidebar.addPanel(title, url, "");
}

function checkTextAreaMaxLength(textBox,e, comment_chars, length)
{
        
    var maxLength = parseInt(length);
    if(!checkSpecialKeys(e) && (e.keyCode!=8 && e.keyCode!=46))
    {
         if(textBox.value.length > maxLength-1)
         {
            if(window.event)//IE
              e.returnValue = false;
            else//Firefox
                e.preventDefault();
         }
         if (textBox.value.length > maxLength)
         {
			textBox.value = textBox.value.substring(0,maxLength);
         }
    }
    comment_chars.innerHTML = "Remaining character count " + (length - textBox.value.length);
}

function checkSpecialKeys(e)
{
    if(e.keyCode!=37 && e.keyCode!=38 && e.keyCode!=39 && e.keyCode!=40)
        return false;
    else
        return true;
}

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 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 getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
	return null;
}

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" : "");
	
	if (name == 'fontSize') {		
		alterFont();
	}

}

function deleteCookie(name) {  
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	var cval = getCookie(name);  
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function alterFont() {

	var fSize = getCookie("fontSize");

	if (fSize) {
		setActiveStyleSheet(fSize);
	} else {
		setActiveStyleSheet('default');
	}
}

function validate_comment_form() {
	var strError = "";
	var frm = document.post_comment_form;

	if (frm.name.value == "") {
		strError += "Your name is required.\n";
	}

	if (frm.email.value == "") {
		strError += "Your email address is required.\n";
	}

	if (frm.comment.value == "") {
		strError += "Your comment is required.\n";
	}

	if (strError != "") {
		alert(strError);
		return false;
	}
	else {
		return true;
	}
}

