function writeContent(txt, div) {
	if(document.all) {
		x = document.all[div];
		x.innerHTML = txt;
	} else {
		document.getElementById(div).innerHTML = txt;
	}
}

var dynDivLoad = false;
var hasSideMenu = true;

function showProcessingMesg(div) {
	var alt = 'Processing ... Please Wait!';
	var txt = '' +
		'<div class="buttonSm">'+
			'<div class="blank">'+
				'<a alt="'+alt+'" title="'+alt+'">Processing ....</a>'+
			'</div>'+
		'</div>';
	writeContent(txt, div)
}

function updateDiv(url, divID, params, loading, err, evalScripts) {
	var req = new Ajax.Request(
		url, 
		{
			method: "get",
			asynchronous: true, 
			parameters: params,
			onLoading:function() {
				if(evalScripts != 1) {
					$(divID).style.display = 'block';
					$(divID).innerHTML = loading;
				}
	      	},
			onComplete:function(request) {
				if(request.status != 200) {
					if(evalScripts != 1) {
						$(divID).innerHTML = err;
					}
				} else {
					if(evalScripts == 1) {
						//var xtra = "$('"+divID+"').style.display = 'none';"
						eval(request.responseText);
						//$(divID).innerHTML = '';
						//$(divID).style.display = 'none';
					} else {
						$(divID).innerHTML = request.responseText;
					}
				}
			}
		}
	);
}

// Check to see if form value is empty
function notEmpty(str) { 
	var notEmpty = false; 
	for(i = 0; i < str.length; i++) { 
		if(str.charAt(i) != ' ' && str.charAt(i) != '\n' && str.charAt(i) != '\r' && str.charAt(i) != '\t')  
			notEmpty = true; 
	} 
	return notEmpty; 
} 

function reloadPage() {
	//window.location.reload();
	//history.go(0);
	window.location.href=window.location.href;
}

// Nifty function to add onload events without overwriting
// ones already there courtesy of the lovely and talented
// Simon Willison http://simon.incutio.com/
function addLoadEvent(func) {   
    var oldonload = window.onload;
    if (typeof window.onload != 'function'){
        window.onload = func;
    } else {
        window.onload = function(){
        	oldonload();
        	func();
        }
    }
}

function addResizeEvent(func) {   
    var oldonresize = window.onresize;
    if (typeof window.onresize != 'function'){
        window.onresize = func;
    } else {
        window.onresize = function(){
        oldonresize();
        func();
        }
    }
}

function initHighlight() {
	var formCol = document.getElementsByTagName('form');
	var formColLength = formCol.length;
	for(i = 0; i < formCol.length; i++) {
		var ele = document.forms[i].elements;
		for(var j = 0; j < ele.length; j++) {
			element = ele[j];
			if (element.type) {
				switch (element.type) {
					case 'radio':
					case 'checkbox':
						element.style.border = 'none';
						break;
					case 'select-one':
					case 'select-multiple':
						break;
					case 'password':
					case 'text':
					case 'textarea':
			            element.onfocus = function () {this.className = 'highlightActiveField';}
			            element.onblur = function () {this.className = 'highlightInactiveField';}
				}
			}
		}
	}
}

function popupMessage(mesg, width, height, title, type) {
	if('undefined' == typeof title) { title = 'Message';}

	if('undefined' == typeof type) { type = 'error';}
	var icon = '<img src="images/buttons/popup_'+type+'.gif" width="16" height="16" align="left" /> ';

	var url = 'index.php?a=popupMessage'+'&message='+mesg+'&title='+icon+title;
	document.popup.show(url, width, height, null);
}

function getIEVersionNumber() {
	var ua = navigator.userAgent;
	var MSIEOffset = ua.indexOf("MSIE ");

	if(MSIEOffset == -1) {
		return 0;
	} else {
		return parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset)));
	}
}

function setCookie(name, value, expires, path, domain, secure) {
	/*
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
    */
    document.cookie= name + "=" + escape(value);
}

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 storeScreenResolution() {
	var sRes = getCookie('screen_res');
	if(sRes == null) {
		setCookie('screen_res', screen.width+'x'+screen.height);
	}
}

addLoadEvent(initHighlight);
addLoadEvent(storeScreenResolution);

