/*
THIS LICENSE HEADER MUST REMAIN INTACT FOR LEGAL USE!
Pagefusion; Pagefusion Core Platform
Description: A powerful, easy-to-use, and highly customizable content management system.
Copyright (C), 2008 Pagefusion.com, All Rights Reserved.
Author: Chris Paul, chris.paul@pagefusion.com
Support portal: www.pagefusion.com

Filename: /libraries/core/javascript/main.js
Description: handles miscellaneous javascript stuff

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
*/

function setStyle(objId, styleName, styleVal) {
    document.getElementById(objId).style[styleName]=styleVal;
} // function

function setClass(objId, classNameVal) {
    document.getElementById(objId).className=classNameVal;
} // function

function openFileManager(url) {
	top.open(url, 'pf_window', 'width=800,height=600,scrollbars=1,resizable=1');
} // function

function stripLeading(string,chr) {
   var finished = false;
   for (var i = 0; i < string.length && !finished; i++)
       if (string.substring(i,i+1) != chr) finished = true;
   if (finished) return string.substring(i-1); else return string;
} // function

function stripTrailing(string,chr) {
   var finished = false;
   for (var i = string.length - 1; i > -1 && !finished; i--)
       if (string.substring(i,i+1) != chr) finished = true;
   if (finished) return string.substring(0,i+2); else return string;
} // function

function trim(string,chr) {
    return stripTrailing(stripLeading(string,chr),chr)
} // function

function pfml(varstr) {
	var tmpstr="/index.php?";
	if (varstr.indexOf("PID")>-1) {
		varstr=tmpstr+varstr;
	} else if (varstr.indexOf("PGID")>-1) {
		varstr=tmpstr+"PID="+jmPID+"&"+varstr;
	} else { 
		varstr=tmpstr+"PID="+jmPID+"&PGID="+jmPGID+"&"+varstr;
	}
	top.location.href=varstr;
} // function

// load javascript/css file dynamically within *.js file
function loadFile(filename, filetype) {
	if (filetype=="js") {
		var fileref = document.createElement('script');
		fileref.setAttribute("type","text/javascript");
		fileref.setAttribute("src", filename);
		
	} else if (filetype=="css") {
		var fileref = document.createElement("link");
		fileref.setAttribute("rel", "stylesheet");
		fileref.setAttribute("type", "text/css");
		fileref.setAttribute("href", filename);
	} // if
	
	if (typeof fileref != "undefined") {
		//alert(filename);
		document.getElementsByTagName("head")[0].appendChild(fileref);
	} // if
} // function

// select all rows within grid
function select_all(form, field) {
	var strlen = field.length;
	with (document.forms[form]) {
		for (i=0; i<elements.length; i++) {
			thiselm = elements[i];
			if (thiselm.name.substring(0,strlen) == field) {
				thiselm.checked = !thiselm.checked
			} // if
		} // for
	} // with
} // function


