/** URL utilities to help with Code Ignitor pathing issues **/

/** 
The assumption is that the htaccess file has been set to avoid having to use 'index.php' as
as part of the URL. If this is not the case, then the URL segments are going to be worked with
in the functions below.
*/



/** --------------------------------------------------------------------------------
*
* To change an installation, set the working directory to the installed folder's name.
*
*/
//var working_folder = '~occumedn';		// Folder where installed into.
var working_folder = '';


//########################################################################
// ALTER THIS SECTION AT YOUR OWN RISK



function FULL_SECTIONS()
{
	var url = top.location.href.split("/");
	var str = "";

	for(idx=0; idx < url.length; idx++)
	{
		str = str + url[idx] +'\n';
	}

	return str;
}



/**
*	Return equivalent $_SERVER['SERVER_NAME'] value
*
*/
function _SERVER_NAME()
{
	var url = top.location.href.split("/");
	
	return url[0] + "//"  + url[2];
}


/**
*	Return the Code Ignitor application path
*
*/
function _APPLICATION_ROOT()
{
	var url = top.location.href.split("/");
	//return url[3] + "/" + url[4];

	return working_folder;
}

/**
*	Return the Code Ignitor scripting path
*
*/
function _SCRIPTING_ROOT()
{
	var url = top.location.href.split("/");
	return url[3] + "/system/application";
}


/**
*	Return the Code Ignitor Controller with methods and parameters
*
*/
function _CONTROLLER()
{
	var url = top.location.href.split("/");
	var str = "";

	for (idx=5; idx <url.length; idx++)
	{
		str = str + url[idx];
		if (idx < url.length) str = str + '/';
	}

	return str.substring(0,str.length-1);
}


/** Shortcuts ------------------------------------------------**/
var IP 				= _SERVER_NAME();
var App 			= _APPLICATION_ROOT();
var WEB				= IP + '/' + working_folder 		+ '/';
var SCRIPT_DIR 		= IP + '/' + _SCRIPTING_ROOT()  	+ '/scripts';
var MODELS_DIR		= IP + '/' + _SCRIPTING_ROOT()  	+ '/models';
var CONTROLLERS_DIR = IP + '/' + _APPLICATION_ROOT();



function getElementsByClassName(oElm, strTagName, strClassName)
{
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++)
    {
        oElement = arrElements[i];
        if(oRegExp.test(oElement.className))
        {
            arrReturnElements.push(oElement);
        }
    }
    return (arrReturnElements)
}



function evoGetStyle(element, tag)
{
	var value = element.style.tag;
	
	if (!value)
	{
		if(document.defaultView)
		    value = document.defaultView.getComputedStyle(element, "").getPropertyValue(tag);
		else if(element.currentStyle)
			value = element.currentStyle[tag];
	}
	
	if (tag == "width" || tag == "height")
		return value.split("px")[0];
	else
		return value;
}