<!--//



function getRowsForLinks() {
	var tables = document.getElementsByTagName("table");
	for(j = 0; j < tables.length; j++) {
		var xTableId = tables[j].id;
		if (xTableId.indexOf("listings") >= 0)
			convertRowsToLinks(xTableId);
		}
	}

function convertRowsToLinks(xTableId) {
	var table = document.getElementById(xTableId);
	if (table) {
//		var rows = document.getElementById(xTableId).getElementsByTagName("tr");
		var rows = table.rows;
		for(i = 0; i < rows.length; i++) {
			var link = rows[i].getElementsByTagName("a")
			if (link.length == 1) {
				rows[i].onclick = new Function("document.location.href='" + link[0].href + "'");
				rows[i].onmouseover = setRowEvents;
				}
			}
		}
	}

function setRowEvents() {
	var thisClass = this.className;
	this.className="highlight";
	this.onmouseout= new Function("this.className='"+thisClass+"'");
	}


function printWindow() {
	bV = parseInt(navigator.appVersion);
	if (bV >= 4) window.print();
	}


function hidePs() {
	for(j = 1; j <= 4; j++) {
		document.getElementById("p"+j).style.visibility="hidden";
		}
	}


function checkThis(a) {
	if (a.checked==1)
		a.value=1;
	else
		a.value=0;
	}


function printWindow() {
	bV = parseInt(navigator.appVersion)
	if (bV >= 4) window.print()
	}


	
function checkEnter(e) { 				// e is event object passed from function invocation; 
										// var characterCode literal character code will be stored in this variable
	if (e && e.which) {
		e = e;							// if which property of event object is supported (NN4)
		characterCode = e.which; 		// character code is contained in NN4's which property
		}
	else {
		e = event;
		characterCode = e.keyCode; 		// character code is contained in IE's keyCode property
		}

	if (characterCode == 13) { 			// if generated character code is equal to ascii 13 (if enter key)
		document.forms[0].submit(); 	// submit the form
		return false;
		}
	else
		return true;

	}

function checkTab(e) { 				// e is event object passed from function invocation; 
										// var characterCode literal character code will be stored in this variable
	if (e && e.which) {
		e = e;							// if which property of event object is supported (NN4)
		characterCode = e.which; 		// character code is contained in NN4's which property
		}
	else {
		e = event;
		characterCode = e.keyCode; 		// character code is contained in IE's keyCode property
		}

	if (characterCode != 9)	 			// if generated character code is equal to ascii 9 (if tab key)
		return false;
	else
		return true;

	}


function sleep(milliseconds) {
	var start = new Date().getTime();
	for (var i = 0; i < 1e7; i++) {
		if ((new Date().getTime() - start) > milliseconds)
		break;
		}
	}


function isSet(variable) {
	return (typeof(variable) != 'undefined');
	}


function ab(amt) {
	return Math.abs(amt);
	}



function toggleRows(tableID,remote) {

	if (remote)
		startRow = 0;
	else
		startRow = 1;

	tbl = document.getElementById(tableID);
	var len = tbl.rows.length;
	var vStyle = (tbl.rows[startRow].style.display == "none" ? "" : "none");

	for(i=startRow ; i< len; i++) {
		tbl.rows[i].style.display = vStyle;
		}

	document.getElementById(tableID+'Button').src = "/icon/"+(tbl.rows[startRow].style.display == "none" ? "add" : "delete")+".gif";

	}


function isArray(obj) {
	if (obj.constructor.toString().indexOf("Array") == -1)
		return false;
	else
		return true;
	}
	

function strpos(haystack, needle, offset) {
	// example: strpos('Kevin van Zonneveld', 'e', 5);
	// returns: 14
	var i = (haystack+'').indexOf(needle,offset); 
	return (i===-1 ? false : i);
	}




// AJAX bits


function clearList(listElem) {
	while(listElem.options.length > 0)
		listElem.options[0] = null;
	}







// ============
// FORM HELPERS
// ============

//shows an object
function show(obj) {
	obj.style.display = "block";
	}

//hides an object
function hide(obj) {
	obj.style.display = "none";
	}
	
//returns an object referenced based on an ID
function getObj(ID) {
	return document.getElementById(ID);
	}

//returns requirement if requirement exists, else returns false
function isReq(obj) {
	return (obj.getAttribute('req') ? obj.getAttribute('req') : "--");
	}
function getCheck(obj) {
	return (obj.getAttribute('check') ? obj.getAttribute('check') : "");
	}
//displays error message if object has invalid input, then turns focus to that object
function badInput(obj, message) {
	alert(message);
	obj.focus();
	return false;
	}

/*	
function getValue(ID) {
	var temp = getObj(ID);
	return temp.value;
	}

function unSet(obj) {
	obj.value = "";
	}

function isSet(check) {
	if (check.value == "") return false;
	else return true;
	}

function isLen(input, len) {
	if (input.value.length==len) return true;
	else return false;
	}
*/
function validForm(url, form) {
	makePOSTRequest(url, get(form), false);
	}

function makePOSTRequest(url, parameters, xml) {
	
	http_request = false;

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			// set type accordingly to anticipated content type
			//if (xml) http_request.overrideMimeType('text/xml');
			//else 
			http_request.overrideMimeType('text/html');
			}
		}
	else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
			}
		catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
				}
			catch (e) {}
			}
		}

	if (!http_request) {
		alert('Cannot create XMLHTTP instance');
		return false;
		}

	http_request.onreadystatechange = function() {
		if (http_request.readyState != 4) {
			return;
			}
		if (http_request.status != 200 && http_request.status != 0) {
			alert('There was a problem with the request.\n(status = ' + http_request.status + ')');
			return false;
			}
		var result = http_request.responseText;
		return alertContents(result);
		}
		
	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", parameters.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.send(parameters);
	}

function checkForm(form) {
	
	var req = "";
	var password = "";
	
	for(i=0; i<form.length; i++) {
		
		var temp = form.elements[i];
		req = isReq(temp);
		
		if (req!="--") {

			if (temp.value=="") {
				return badInput(temp,"Please complete all required fields.");
				}

			if (temp.type == "select-one") {
				if (temp.options[temp.selectedIndex] =="") {
					return badInput(temp,"Please complete all required fields.");
					}
				}
			
			if (temp.type == "password") {			//possible password setting 
				if (password=="") {
					password = temp.value;
					}
				else if (password!==temp.value) {
					return badInput(temp,"Your passwords do not match.\nPlease re-enter passwords.");
					}
				}
			
			if (req=="phone") {
				if (temp.value.length != temp.size) {
					return badInput(temp,"Phone number has an incorrect length.");
					}
				}	
			}
		}
	return true;
	}


function get(obj) {//name, value, required, check, error

	var getstr = "";

	for (i=0; i<obj.length; i++) {
	
		var temp = obj.elements[i];
		
		if (temp.type == "text" || temp.type=="password") {
			getstr += temp.name + "=" + 
			temp.value + "|" +
			isReq(temp) + "|" +
			getCheck(temp) + "|" +
			temp.title + '&';
			}

		if (temp.type == "checkbox" || temp.type == "radio") {
			if (temp.checked) {
				getstr += temp.name + "=" + 
				temp.value + "|" +
				isReq(temp) + "|" +
				getCheck(temp) + "|" +
				temp.title + '&';
				}
			}
		
		if (temp.type == "select-one") {
			getstr += temp.name + "=" + 
			temp.options[temp.selectedIndex].value + "|" +
			isReq(temp) + "|" +
			getCheck(temp) + "|" +
			temp.title + '&';
			}
		}
	return getstr + "end=|--||";
	}


// END FORM HELPERS








function showLoading(message) {
	parent.document.getElementById('loading').style.display='block';
	parent.document.getElementById('loadImage').src='/images/blank.gif';
	parent.document.getElementById('loadImage').src='/images/loading.gif';
	parent.document.getElementById('loadStatus').innerHTML=(message ? (message == 1 ? 'Loading Data' : message) : 'Rendering')+'...';
	}
function hideLoading(message) {
	parent.document.getElementById('loadStatus').innerHTML=(message ? message : 'Loading Data')+'...';
	parent.document.getElementById('loading').style.display='none';
	}



// ----------------------------------------
// DHTML Window Child Helpers - Joey Kippen
// ----------------------------------------

function openmypage(entry,title) { 				// run DHTML Window AJAX widget codes
	ajaxwin=parent.dhtmlwindow.open("ajaxbox", "ajax", "/admin/common/dictionary.php?entry=" + entry, (title ? title : 'Structure Help'), "width=320px,height=200px,left=500px,top=200px,resize=1,scrolling=1");
	if (!entry)
		ajaxwin.close();
	ajaxwin.onclose=function() {
		return true;							 	// Run custom code when window is about to be closed
		}
	}
	
function loadentry(entry,title) {
	if (isSet(ajaxwin) && ajaxwin.on) {
		if (!ajaxwin.isClosed) {
			var path = "/admin/common/dictionary.php?entry=" + entry;
			ajaxwin.load('ajax', path, (title ? title : 'Structure Help'));
			}
		else {
			openmypage(entry);
			}
		}
	}
	
function getHelpers() {
	var tags = document.getElementsByTagName('span');
	
	if (ajaxwin.on)
		ajaxwin.on=false;
	else
		ajaxwin.on=true;

	for(i=0; i<tags.length; i++) {
		var temp = tags[i];
		if (temp.className == "whelp") {
			if (ajaxwin.on) {
				temp.style.color = "red";
				temp.style.cursor = "pointer";
				}
			else {
				temp.style.color = "black";
				temp.style.cursor = "normal";
				}
			}
		}
	return ajaxwin.on;
	}
	

function infoBox(text,width,height,hidden,moreThanText,id,transparent) {	// open DHTML Window generic popup

	if (!width)
		width = 260;
	if (!height)
		height = 180;
	
	inlinewin=parent.dhtmlwindow.open("inlinebox", "inline", text, '', "width="+width+"px,height="+height+"px,left=500px,top=200px,resize=1,scrolling=1");
	inlinewin.onclose=function() {
		return true;						 	// Run custom code when window is about to be closed
		}
	}


// DHTML Window Helpers - END

//-->