/****************************************************************************
	Administration Site Base Client Script
	Zac Hester
****************************************************************************/


/**
 * Detect IE for work-around code.
 */
var detect = navigator.userAgent.toLowerCase();
var isIE = detect.indexOf('msie') != -1;




/**
 * Page initialization.  Called when the body is loaded. 
 */

function init() {
	//Parse any URL query components.
	//parse_get();

		if(window.init_menu) {
			init_menu();
		}
		if(typeof(initScrollers) != "undefined") {
	    initScrollers();
	}

}


/**
 * Generic form checking script.
 */
function check_form() {
	var frm = document.getElementById('admin_form');
	var req = frm.elements['form_check'];

	//Allow the form if it doesn't have the standard ID.
	if(!frm) { return(true); }

	//Check for required fields list for this form.
	if(req && req.value.length) {

		//Build a list of fields for checking.
		var field_list = req.value.split(',');

		//Run through each field.
		for(var i = 0; i < field_list.length; ++i) {

			//Check for valid form element.
			if(frm.elements[field_list[i]]
				&& frm.elements[field_list[i]].value) {

				//Reference the element data and trim.
				var test = frm.elements[field_list[i]].value.trim();
	
				//Make sure the element has some info.
				if(test.length == 0) {
					alert('You must complete all required fields'
						+' before submitting the form.');
					frm.elements[field_list[i]].focus();
					return(false);
				}
			}
			else {
				alert('You must complete all required fields'
					+' before submitting the form.');
				return(false);
			}
		}
	}

	//Check for some password fields in the form.
	if(frm.elements['pass1'] && frm.elements['pass2']) {

		//Reference the password field's conditioned data.
		var test1 = frm.elements['pass1'].value.trim();
		var test2 = frm.elements['pass2'].value.trim();

		//Test for specified password and matching fields.
		if(test1.length > 0 && test1 != test2) {
			alert('When entering a password, both password fields'
				+' must match.');
			return(false);
		}
	}

	//If we make it this far, the form is okay.
	return(true);
}


/**
 * Delete confirmation and requesting.
 */
function confirm_delete(objid,referer,type) {

	//Confirm the deletion of this object.
	if(confirm('Are you sure you want to delete this?')) {

		//Run the processor to delete this object from the current module.
		window.location = 'process.php?action=delete'+'&id='+objid+'&referer='+referer+'&type='+type;
	}

	//They didn't confirm the deletion.
	return(false);
}

/**
 * Move record up in database
 */
function move_item_up(objid,type,key, referer) {

	//Confirm the deletion of this object.
	if(confirm('Are you sure you want to move this record?')) {

		//Run the processor to delete this object from the current module.
		window.location = 'process.php?action=move_item'+'&id='+objid+'&type='+type+'&key='+key+'&referer='+referer;
	}

	//They didn't confirm the deletion.
	return(false);
}   
/**
 * General-form delete confirmation.
 */
function request_delete(module, object, id) {
	if(confirm('Are you sure you want to delete this '+object+'?')) {
		var next = encodeURIComponent(window.location.toString());
		window.location = 'process.php?action=delete&id='+id+'&referer='+next;
	}
	return(false);
}

/**
 * Quickjump handler.
 */
function quickjump() {
	var sel = document.getElementById('qj');
	for(var i = 0; i < sel.options.length; ++i) {
		if(sel.options[i].selected == true
			&& sel.options[i].value.trim().length != 0) {
			window.location = sel.options[i].value;
			return(true);
		}
	}
	sel.options[0].selected = true;
	return(false);
}



/**
 * Simple whitespace trimmer.
 */
function trim(string) {
	var new_string = string.replace(/^\s+/g, '');
	new_string = new_string.replace(/\s+$/g, '');
	return(new_string);
}


/**
 * Add my own trim method to the String object.
 */
String.prototype.trim = function() {
    var str = this.replace(/^\s+/g, '');
    str = str.replace(/\s+$/g, '');
    return(str);
}


/**
 * Establish a global array to store the query data.
 */
var _GET = new Array();

/**
 * Parses the current page's GET query into a global array.
 *
 * @author Zac Hester <zac@zacharyhester.com>
 * @date 2005-10-28
 */
function parse_get() {

	//A temporary place to keep array items.
	var temp = new Array();

	//Pull the GET query of the current page.
	var get = window.location.search.substring(1);

	//Check for any query.
	if(get.length == 0) {
		return(false);
	}

	//Check for multiple query pairs.
	else if(get.indexOf('&') != -1) {

		//Break the query on the standard pair separator.
		var pairs = get.split('&');

		//Run through each key=value pair.
		for(var i = 0; i < pairs.length; ++i) {

			//Break the pair on the standard assignment separator.
			temp = pairs[i].split('=');

			//Load the data in the global array.
			parse_get_assign_pair(temp[0], temp[1]);
		}
	}

	//This query only has one pair.
	else {

		//Break the pair on the standard assignment separator.
		temp = get.split('=');

		//Load the data in the global array.
		parse_get_assign_pair(temp[0], temp[1]);
	}
}

/**
 * Assigns a parsed key=value pair to the global array.
 *
 * @author Zac Hester <zac@zacharyhester.com>
 * @date 2005-10-28
 *
 * @param key An extracted left-hand value from a query pair.
 * @param val An extracted right-hand value from a query pair.
 */
function parse_get_assign_pair(key, val) {

	//Every string from the query needs to be checked for plus-sign as
	//  spaces (PHP-style), and then unescape()d like usual.
	key = key.replace('+', ' ');
	key = unescape(key);
	val = val.replace('+', ' ');
	val = unescape(val);

	//Put the data in the global array.
	_GET[key] = val;
}
function upfontSize() {
document.getElementById('news_viewer_container').style.fontSize = "140%"
document.getElementById('news_viewer_container').style.lineHeight = "165%"

}
function downfontSize() {
document.getElementById('news_viewer_container').style.fontSize = ""
document.getElementById('news_viewer_container').style.lineHeight = ""

}

