/*
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), 2006-2007 Pagefusion.com, All Rights Reserved.
Author: Chris Paul, chris.paul@pagefusion.com
Support portal: www.pagefusion.com

Filename: /libraries/core/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 gebi(elemID) {return document.getElementById(elemID);}

function node_gebt(targElem, targTag) {return targElem.getElementsByTagName(targTag);}

function getURLParams(strHref) {
	var aReturn=new Array();
	if (strHref.indexOf("?") > -1) {
		var strQueryString=strHref.substring(strHref.indexOf("?")+1);
		strQueryString=strQueryString.toLowerCase();
		var aQueryString=strQueryString.split("&");
		for ( var iParam = 0; iParam < aQueryString.length; iParam++ ) {
//			if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ) {
				var aParam=aQueryString[iParam].split("=");
				aReturn[aParam[0]]=aParam[1];
//				break;
//			}
		}
	}
	return aReturn;
}

function FunctionFeeder(theFunc, args) {
	if (!(theFunc instanceof Function))
        theFunc = eval(theFunc);
	var oldArgs = args;
    return function () {
        theFunc(oldArgs);
    };
};

function FunctionFeeder2(theFunc, arg1, arg2) {
	if (!(theFunc instanceof Function))
        theFunc = eval(theFunc);
	var oldArg1 = arg1;
	var oldArg2 = arg2;
    return function () {
        theFunc(oldArg1, oldArg2);
    };
};

function setStyle(objId, styleName, styleVal) {
    document.getElementById(objId).style[styleName]=styleVal;
}

function openFileManager(url) {
	top.open(url, 'fileManager', 'width=800,height=600,scrollbars=1,resizable=1');
} // function

function toggle_content_areas() {
	
	var object=document.getElementById("middle_center");
	
	if (object.className == "middle_center_layout") {
		object=document.getElementById("background"); object.className="background_normal";
		object=document.getElementById("header_left"); object.className="header_left";
		object=document.getElementById("header_center"); object.className="header_center";
		object=document.getElementById("header_right"); object.className="header_right";
		
		object=document.getElementById("top_left"); object.className="top_left";
		object=document.getElementById("top_center"); object.className="top_center";
		object=document.getElementById("top_right"); object.className="top_right";
		
		object=document.getElementById("middle_left"); object.className="middle_left";
		object=document.getElementById("middle_center"); object.className="middle_center";
		object=document.getElementById("middle_right"); object.className="middle_right";
		
		object=document.getElementById("bottom_left"); object.className="bottom_left";
		object=document.getElementById("bottom_center"); object.className="bottom_center";
		object=document.getElementById("bottom_right"); object.className="bottom_right";
		
		object=document.getElementById("footer_left"); object.className="footer_left";
		object=document.getElementById("footer_center"); object.className="footer_center";
		object=document.getElementById("footer_right"); object.className="footer_right";
	} else {
		object=document.getElementById("background"); object.className="background_layout";
		
		object=document.getElementById("header_left"); object.className="header_left_layout";
		object=document.getElementById("header_center"); object.className="header_center_layout";
		object=document.getElementById("header_right"); object.className="header_right_layout";
		
		object=document.getElementById("top_left"); object.className="top_left_layout";
		object=document.getElementById("top_center"); object.className="top_center_layout";
		object=document.getElementById("top_right"); object.className="top_right_layout";
		
		object=document.getElementById("middle_left"); object.className="middle_left_layout";
		object=document.getElementById("middle_center"); object.className="middle_center_layout";
		object=document.getElementById("middle_right"); object.className="middle_right_layout";
		
		object=document.getElementById("bottom_left"); object.className="bottom_left_layout";
		object=document.getElementById("bottom_center"); object.className="bottom_center_layout";
		object=document.getElementById("bottom_right"); object.className="bottom_right_layout";
		
		object=document.getElementById("footer_left"); object.className="footer_left_layout";
		object=document.getElementById("footer_center"); object.className="footer_center_layout";
		object=document.getElementById("footer_right"); object.className="footer_right_layout";
	} // if
} // 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 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 trim(string,chr) {
    return stripTrailing(stripLeading(string,chr),chr)
}
