function do_link(section, params){
	
	var parts = section.split(".");
	var module = parts[0];
	var page = parts[1];
	
	var send_to_file, base_path;
	
	var array_params = Array();
	var i = 0;
	var send_params = "";
	var param = Array();
	array_params = params.split("&");
	
	if (URL_REWRITE == "on") {
	
		var force_files = SUBDOMAINS_FORCE_FILES_JS.split(",");
		if (SUBDOMAINS_STATUS == "on" && !js_in_array(section, force_files)) {
			var res_file = section.split(".");
			send_to_file = res_file[1];
			if (res_file[0] == "site") {
				res_file[0] = "www";
			}
			base_path = "http://" + res_file[0] + "." + DOMAIN_BASE;
		}
		else {
			send_to_file = section.replace(".", "-");
			base_path = PATH;
		}
	
		while (i < array_params.length){
			if (array_params[i] != "") {
				param = array_params[i].split("=");
				send_params = send_params + param[0] + "-" + param[1];
				if(i < (array_params.length - 1)) {
					send_params = send_params + "~";
				}
			}
			i ++;
		}
	
		if (send_params != "") {
			the_link = base_path + "/" + send_to_file + "~" + send_params + ".html";
		}
		else {
			the_link = base_path + "/" + send_to_file + ".html";
		}
		
	}
	
	else {
		the_link = PATH_INDEX + "?_init=" + module + "." + page + "&" + params;
	}
	
	return the_link;
}

function form_send_params(section, params, mode){
	
	if (mode == "rs") {
		
		var array_params = Array();
		var i = 0;
		var send_params = "";
		var param = Array();
		array_params = params.split("&");
		
		while (i < array_params.length){
			if (array_params[i] != '') {
				param = array_params[i].split("=");
				send_params = send_params + "<INPUT TYPE=\"HIDDEN\" NAME=\"" + param[0] + "\" VALUE=\"" + param[1] + "\">";
			}
			i ++;
		}
		
		if (send_params) {		
			document.open();
			document.write("<FORM METHOD=\"POST\" NAME=\"_form_send_params_\" ACTION=\"" + do_link(section, "") + "\">");
			document.write(send_params);
			alert(send_params);
			document.write("</FORM>");
			document.write("<SCR");
			document.write("IPT LANGUAGE=\"JavaScript\">document._form_send_params_.submit();</SCR");
			document.write("IPT>");			
			document.close();		
		}
	}
	else {
		document.location = do_link(section, params);
	}
	
	return false;
}

function form_do_submit(form_name, button_name){
	
	if (!form_is_submitted) {
		eval("document." + form_name + "." + button_name + ".disabled=true");
		eval("document." + form_name + ".submit()");
		form_is_submitted = 1;
	}
	
	return false;
}

function form_set_select(sel_name, form_name, sel_index){
	
	if ((form_name != "") && (typeof eval("document." + form_name + "." + sel_name) == "object")) {
	
		sel_length = eval("document." + form_name + "." + sel_name + ".length");
		
		for (optionCounter = 0; optionCounter < sel_length; optionCounter++) {
			
			if (eval("document." + form_name + "." + sel_name + ".options[optionCounter].value == '" + sel_index + "'")) {
				
				eval("document." + form_name + "." + sel_name + ".selectedIndex = optionCounter");
				
			}
			
		}
	
	}
	
}

function form_set_checked(check_name, form_name, checked_mode){
	
	if ((form_name != "") && (typeof eval("document." + form_name + "." + check_name) == "object")) {
	
		if (checked_mode != "" && checked_mode != 0 && checked_mode != "off") {
			eval("document." + form_name + "." + check_name + ".checked = true");
		}
	
	}
	
}

function form_set_radio(radio_name, form_name, selected_value){
    
	 if ((form_name != "") && (typeof eval("document." + form_name + "." + radio_name) == "object")) {
	 	
	 	eval("var rad = document." + form_name + "." + radio_name);

	 	for(i=0; i<rad.length; i++){
		
	 		if(rad[i].value == selected_value){
				rad[i].checked = true;
				return true;
			}
			
		}
		
		return false;
	}

}

function form_set_inp(inp_name, form_name, inp_value){
	
	if ((form_name != "") && (typeof eval("document." + form_name + "." + inp_name) == "object")) {
		eval("document." + form_name + "." + inp_name + ".value = \"" + inp_value + "\"");
	}
	
}

function form_check_all(c) {
	
	var f = c.form;
	var ck = c.checked;
	
	for (i = 0; i < f.elements.length; i++) {
		if ((f.elements[i] != c) && (f.elements[i].type == "checkbox")) {
			f.elements[i].checked = ck;
		}
	}
	
}

function win_open(mypage, myname, w, h, win_position, Scrool){
	
	var win = null;
	var LeftPosition, TopPosition;
	
		
	if (w) {
	}
	else {
		w = 600;
	}
	
	if (h) {
	}
	else {
		h = 600;
	}
	
	if (win_position == "topright") {
		LeftPosition = (screen.width) ? (screen.width - w - 12) : 0;
		TopPosition = 20;
	}
	else if (win_position == "center") {
		LeftPosition = (screen.width) ? ((screen.width-w) / 2) : 0;
		TopPosition = (screen.height) ? ((screen.height-h) / 2) : 0;
	}
	
	settings = 'height = ' + h + ', width = ' + w + ', top = ' + TopPosition + ', left = ' + LeftPosition+', scrollbars = ' + Scrool + ', resizable = no';
	win = window.open(mypage, myname, settings);
	if (win == null) {
		alert("Your popup blocker stopped an window from opening\nPlease disable your popup blocker if you wish to see window content!");
	}
	
}

var EL_VISIB = new Array();
function dom_toggle_element(el, visible){

	visible = (visible != false && visible != true) ? (EL_VISIB[el] ? false : true) : visible;
	var el_handle = dom_get_element(el);
	
	if (el_handle) {
		if (!visible) {
			el_handle.style.display = 'none';
		}
		else if (visible) {
			el_handle.style.display = '';
		}
		
		EL_VISIB[el] = visible;
	}
}

function dom_get_element(id){
        var obj;

        if (document.all) {
                eval('obj = document.all("' + id + '")');
        }
        else if (document.layers) {                
                eval('obj = document.layers["' + id + '"]');
        }
        else if (document.getElementById) {        
                eval('obj = document.getElementById("' + id + '")');
        }
        
        return obj;
}


// MESSAGE BOX SYSTEM v1.2 ---------------------------------------------------------------------------------------------------------------------------------------------------
// used to replace the classic alert box, written and checked for Internet Explorer v6+, Firefox, Netscape v7+ only, other browsers may crash if they do not fully support DOM
function messageBox() {
	
	// R - this variable can only be read
	// R/W - this variable can be read and also overwritten

	// detect microsoft IE - R
	this.isMSIE = (navigator.appName.toLowerCase().indexOf("microsoft") >= 0) ? true : false;	
	
	this.coordCenter = new Array(0,0);	// coordinates for the exact center of the screen - R
	this.scrollCoords = new Array(0,0);	// scroll offset amount array - R
	
	this.msgBoxHeight = 100;		// message box height - R/W
	this.msgBoxWidth = 300;			// message box width - R/W
	this.msgBoxTop = 0;			// message box top corner position - R
	this.msgBoxLeft = 0;			// message box left corner position - R
	
	this.containerStyle = null;		// container style - R
	this.msgBoxHtml = null;			// container style - R
	
	this.mBoxLocker = null;			// referrence to message box blocking layer element - R
	this.mBox = null;			// referrence to message box element - R
	
	// GET SCROLL OFFSET --------------------------------------------------------------------------
	// cross browser function to get x and y offsets for scrolling windows
	this.getScrollCoords = function () {
		var scrOfX = 0, scrOfY = 0;
		
		if (typeof(window.pageYOffset) == "number") {
			//Netscape compliant
			scrOfY = window.pageYOffset;
			scrOfX = window.pageXOffset;
		} 
		else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
			//DOM compliant
			scrOfY = document.body.scrollTop;
			scrOfX = document.body.scrollLeft;
		}
		else if	(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
			//IE6 standards compliant mode
			scrOfY = document.documentElement.scrollTop;
			scrOfX = document.documentElement.scrollLeft;
		}
		
		return [ scrOfX, scrOfY ];
	};
	
	// CLOSE MSG BOX ---------------------------------------------------------------------------
	// closes message box
	this.close = function() {
		
		this.mBoxLocker.style.display = "none";
		this.mBox.style.display = "none";
		
		// unset onscroll event to prevent useless processing
		window.onscroll = null;
	};
	
	// POP MSG BOX ------------------------------------------------------------------------------
	// message box function, used instead of the classic alert function to display the messages in a customizable html format
	this.pop = function(msg, position) {
		
		// if microsoft internet explorer
		if (this.isMSIE) {
			positionStyle = "absolute";
		}
		else {
			positionStyle = "fixed";
		}
		
		var screenWidth = window.innerWidth ? window.innerWidth : document.body.offsetWidth;
		var screenHeight = window.innerHeight ? window.innerHeight : document.body.offsetHeight;
		
		var pageHeight = document.body.scrollHeight;
		var pageWidth = document.body.scrollWidth;

		// set center screen coordinates
		this.coordCenter[0] = Math.round(screenWidth/2);
		this.coordCenter[1] = Math.round(screenHeight/2);
		
		// set coordinates based on requested relative position
		if (position == "center" || !position) {
			this.msgBoxLeft = this.coordCenter[0] - Math.round(this.msgBoxWidth/2);
			this.msgBoxTop = this.coordCenter[1] - Math.round(this.msgBoxHeight/2);
		}
		
		// if IE, the scrolling offset must be taken into consideration as the message box's position is absolute
		if (this.isMSIE) {
			// get cross browser scroll coords
			this.scrollCoords = this.getScrollCoords();
			
			this.msgBoxLeft += document.body.scrollLeft;
			this.msgBoxTop += document.body.scrollTop;
		}
		
		// create locking element if none exist
		if (!this.mBoxLocker) {
			// IE way to create the locker
			if (this.isMSIE) {
				// place locker container
				this.mBoxLocker = document.createElement("div");
				document.body.appendChild(this.mBoxLocker);
				
				// create locker as html within container
				this.mBoxLocker.innerHTML = '<div id="msgBoxLocker" style="position: absolute; top: 0px; left: 0px; width: ' + pageWidth + 'px; height: ' + pageHeight + 'px; background: #333333; filter:alpha(opacity=50); -moz-opacity:0.2; opacity: 0.2;"></div>';
				
				// get new referrence to the locker
				this.mBoxLocker = document.getElementById("msgBoxLocker");

			}
			// usual way to create the locker
			else {
				this.mBoxLocker = document.createElement("div");
			
				this.mBoxLocker.setAttribute("id", "msgBoxLocker");
				this.mBoxLocker.setAttribute("style", "position: absolute; top: 0px; left: 0px; width: " + pageWidth + "px; height: " + pageHeight + "px; background: #333333; filter:alpha(opacity=50); -moz-opacity:0.2; opacity: 0.2; display: none;");			
				
				// append on document
				document.body.appendChild(this.mBoxLocker);
			}
		}
		
		// prepare message box content
		var msgBoxHeader = "MessageBox";
		var msgBoxBody = msg;
		var msgBoxFooter = '<input type="button" class="button" value="OK" onClick="msgBox.close();">';
		
		// if IE, get container element which is the msgBox's parent
		if (this.isMSIE) {
			if (this.mBox) {
				this.mBox = this.mBox.parentNode;
			}
		}
		
		// build msg box data
		this.containerStyle = 'position: ' + positionStyle + '; top: ' + this.msgBoxTop + 'px; left: ' + this.msgBoxLeft + 'px; width: ' + this.msgBoxWidth + 'px; height: ' + this.msgBoxHeight + 'px; padding: 0px; display: none;';
		this.msgBoxHtml = '<table width="' + this.msgBoxWidth + '" height="' + this.msgBoxHeight + '" cellpadding="0" cellspacing="0" border="1"><tr><td><table width="100%" height="100%" cellpadding="1" cellspacing="1" class="msgBoxStyle"><tr><td class="msgBoxHeaderStyle">' + msgBoxHeader + '</td></tr><tr><td class="msgBoxBodyStyle">' + msgBoxBody + '</td></tr><tr><td class="msgBoxFooterStyle">' + msgBoxFooter + '</td></tr></table></td></tr></table>';
		
		// create msgBox container element if none available
		if (!this.mBox) {
			this.mBox = document.createElement("div");
			
			// if browser is not IE, build message box as usual
			if (!this.isMSIE) {
				this.mBox.setAttribute("id", "msgBox");
				this.mBox.setAttribute("style", this.containerStyle);
				this.mBox.setAttribute("class", "msgBoxContainerStyle");
			}

			// append on document
			document.body.appendChild(this.mBox);
		}

		// set content depending on browser
		if (this.isMSIE) {
			// if browser is MSIE, create actual msgbox div inside current container div otherwise positioning will get messed up
			mBoxInnerHtml = '<div id="msgBox" style="' + this.containerStyle + '" class="msgBoxContainerStyle">' + this.msgBoxHtml + '</div>';
		}
		else {
			mBoxInnerHtml = this.msgBoxHtml;
		}
		
		// msgBox MAIN HTML
		this.mBox.innerHTML = mBoxInnerHtml;
		
		// get elements as referrence thru their name, this will make sure the referrences are pointed right, also hardcoded string ID's must be used as IE will have the .id pointed to the container
		this.mBoxLocker = document.getElementById("msgBoxLocker");
		this.mBox = document.getElementById("msgBox");

		// display msg box and locking element in the exact given order
		this.mBoxLocker.style.display = "";
		this.mBox.style.display = "";

		// if it is IE, set the onScroll event to drag the message box after it so it is kept in the center of the screen
		if (this.isMSIE) {
			window.onscroll = this.tuneMsgBoxIE;
		}
	};
	
	// TUNE FOR IE -----------------------------------------------------------------------------
	// tune message box position for Internet Explorer, this. cannot be used because in IE the event will point the this. referrence to the event triggering element
	this.tuneMsgBoxIE = function (){
		
		// get cross browser scroll coords
		msgBox.scrollCoords = msgBox.getScrollCoords();
		
		// calculate new position
		msgBox.msgBoxLeft = document.body.scrollLeft + msgBox.coordCenter[0] - Math.round(msgBox.msgBoxWidth/2);
		msgBox.msgBoxTop = document.body.scrollTop + msgBox.coordCenter[1] - Math.round(msgBox.msgBoxHeight/2);
		
		// reposition msgBox
		msgBox.mBox.style.left = msgBox.msgBoxLeft;
		msgBox.mBox.style.top = msgBox.msgBoxTop;
	};
}

// create instance of the msgBox object, warning: multiple instances will not work and the instance must be named as msgBox
var msgBox = new messageBox();

// END MESSAGE BOX SYSTEM ----------------------------------------------------------------------------------------------------


// DOM REMOTE OPERATIONS SYSTEM ----------------------------------------------------------------------------------------------------
var dir_remote_container = null; // referrence to div element that contains the iframe
var dir_remote_script_path = do_link("site.remote_ops", "pp=empty&mode=init"); // http path to remote operations script
var dir_remote_callback = null; // referrence to callback function
var dir_remote_package = new Array(); // data package that the remote takes and sends to server
var dir_remote_status = "available"; // status of remote, can be "available", "ready", "running", "disabled"
var dir_remote_hidden = true; // set true or false to toggle remote visibility
var dir_remote_timeout_interval = 30; // number of seconds of no activity while running action to declare timeout

function dom_timeout_check(mode){
	
	// initiate timeout
	if (mode == "init"){
		setTimeout("dom_timeout_check();", dir_remote_timeout_interval * 1000);
	}
	// else, check for timeout
	else {
		if (dir_remote_status == "running") {
			// set remote status to disabled to reset remote
			dir_remote_status = "disabled";
	
			// reset remote
			//dom_init_remote(dir_remote_callback);
			
			// reset data package
			dir_remote_package = new Array();
			
			// reset remote status to available
			dir_remote_status = "available";
			
			alert("The request could not be completed.\nPlease try again later.");
		}
	}
}

function dom_remote_send_data(action_type, action_data){
	// if the system has been initiated, go ahead and preapare the data package and set the remote's status to "ready"
	if (dir_remote_container.childNodes.length) {
		dir_remote_package['action_type'] = action_type;
		dir_remote_package['action_data'] = action_data;
		dir_remote_status = "ready";
	}
	// else, display error message
	else{
		alert("Remote system not initiated. Please run init function first.");
	}
}

function dom_remote_receive_data(action_result, action_response){
	
	// reset data package
	dir_remote_package = new Array();
	
	// if callback function is defined, call it
	if (dir_remote_callback) {
		dir_remote_callback(action_result, action_response);
	}
	// if server answered with success code then display message
	else if (action_result == "success") {
		alert(action_response);
	}
	// if server answered with failed code then display failure reason
	else if (action_result == "failed") {
		alert(action_response);
	}
}

function dom_init_remote(callback_function, container){

	// get reference to container
	dir_remote_container = dom_get_element(container);
	
	// hide container
	if (dir_remote_hidden) {
		//dir_remote_container.style.visibility = "hidden";
		dir_remote_container.style.width = 1;
		dir_remote_container.style.height = 1;
		dir_remote_container.style.overflow = "auto";
	}
	
	// reset content of remote container just to make sure there is nothing inside
	dir_remote_container.setAttribute("innerHTML", "");
	
	// try to remove old iframe child in case there is one, this is used in case of reset
	if (dir_remote_container.childNodes[0]) {
		dir_remote_container.removeChild(dir_remote_container.childNodes[0]);
	}
	
	// set referrence to callback function if given
	if (callback_function) {
		//dir_callback_function = callback_function;
	}
	
	// create default iframe element with null src
	var el = document.createElement("iframe");
	el.setAttribute("src", dir_remote_script_path);
	dir_remote_container.appendChild(el);
}

// END DOM REMOTE OPERATIONS SYSTEM ----------------------------------------------------------------------------------------------------

// DOM MENU EFFECT SYSTEM -----------------------------------------------------------------------------------------------

var options_container = null;
var OPT = new Array();
var last_selected = null;
var last_hovered = null;
var last_hovered_class = null;

function bind_menu_effect(container_id, css_default, css_over, css_selected, option_type, onclick_callback_function, selected_option_index, aux_data){

	// init options index, this will count first option as 1 and last option as options.length this cannot be done thru node index as there are nodes that are skipped between the options
	var options_index = 0;
	
	// set default selected option index
	selected_option_index = selected_option_index ? selected_option_index : null;
	
	// get referrence to options container
	options_container = dom_get_element(container_id);
	
	// set default option node type if none is given
	option_type = option_type ? option_type : "TD";
	
	// prepare options
	for(node_index=0; node_index < options_container.childNodes.length; node_index++){
		if(options_container.childNodes[node_index].nodeName == option_type){

			// increment options index
			options_index++;
			
			// if default option is given then mark it as selected
			if(selected_option_index && options_index == selected_option_index){
				last_selected = options_container.childNodes[node_index];
				options_container.childNodes[node_index].className = css_selected;
			}
			else{
				options_container.childNodes[node_index].className = css_default;
			}
			
			// set property on option to store it's order_index
			options_container.childNodes[node_index].option_index = options_index;
			
			// any aux data needed to be passed to the callback function is set as a string in this variable
			options_container.childNodes[node_index].aux_data = aux_data;
			
			// BIND "MOUSE IS OVER OPTION" EVENT -------------------------------------------------
			options_container.childNodes[node_index].onmouseover = function(){
				
				// set last_hovered option's class to it's last class before selection
				if(last_hovered){
					last_hovered.className = last_hovered_class;
				}
				
				// set last_hovered_class to hovered option's current class
				last_hovered_class = this.className;
				
				// set current hovered option to over class
				this.className = css_over;
				
				// set last_hovered to current hovered option
				last_hovered = this;
				
			};
			
			// BIND "MOUSE IS OUT" EVENT -------------------------------------------------
			options_container.childNodes[node_index].onmouseout = function(){
				
				// set last_hovered option's class to it's last class before selection
				if(last_hovered){
					last_hovered.className = last_hovered_class;
				}
				
				// reset all effect variables
				last_hovered = null;
				last_hovered_class = null;
				
			};
			
			// BIND "OPTION CLICK" EVENT -------------------------------------------------
			options_container.childNodes[node_index].onclick = function(){
				
				// set last selected option's class to default
				if(last_selected){
					last_selected.className = css_default;
				}
				
				// set this option's last hovered class to selected class
				last_hovered_class = css_selected;
				
				// set class of hovered option to selected class
				this.className = css_selected;
				
				// set last selected option to current option
				last_selected = this;
				
				// if onclick callback function is defined, run it
				if(onclick_callback_function){
					onclick_callback_function(this);
				}
				
			};
		}
	}
}

// END DOM MENU EFFECT SYSTEM -----------------------------------------------------------------------------------------------
function getObjByName(name,doc) {
	var o = 0;
  	if(!doc) {
  		doc = document;
  	}
  	if(doc[name]) {
  		o=doc[name];
  	}
  	if(document.all && doc.all[name]) {
  		o=doc.all[name];
  	}
  	if(o) {
    		if(!o.getElementsByTagName) {
    			o.getElementsByTagName = getElementsArray;
    		}
    		return o;
  	}
  	if(document.layers) {
    		for(var i=0; i < doc.layers.length; i++){
      			var lyrdoc = doc.layers[i].document;
      			if(lyrdoc[name]) {
      				return lyrdoc[name];
      			}
      			if(lyrdoc.layers.length > 0) {
        				var o = getObjByName(name,lyrdoc);
        				if(o) {
        					return o;
        				}
      			}
    		}
  	}
  	return 0;
}

function textCounter(field, cntfield, maxlimit) {
	var obj_field = getObjByName(field);
	var obj_cntfield = getObjByName(cntfield);
	if (obj_field.value.length > maxlimit){
        	obj_field.value = obj_field.value.substring(0, maxlimit);
	}
   	else {
       		obj_cntfield.value = maxlimit - obj_field.value.length;
   	}
}

function print_array(arr, lvl) {

	lvl = (lvl > 0) ? lvl : 1;
	var level = lvl;
	
	var tab = "\t";
	if (level > 1) {
		for (k=1; k < level-1; k++) {
			tab += "\t";
		}
		
		var buff = "Array\n" + tab + "(\n";
		tab += "\t";
	}
	else {
		var buff = "Array\n(\n";
	}
	
	var i = 0;
	for (var i in arr) {
		if (typeof(arr[i]) == "object") {
			buff += tab + "[" + i + "]" + " => " + print_array(arr[i], level + 1) + tab + ")\n";
		}
		else {
			buff += tab + "[" + i + "]" + " => " + arr[i] + tab + "\n";
		}
	}
	
	if (level > 1) {
		return buff;
	}
	else {
		alert(buff + ")\n");
	}
}

function js_in_array(the_needle, the_haystack) {

	var the_hay = the_haystack.toString();
	if(the_hay == '') {
		return false;
	}
	var the_pattern = new RegExp(the_needle, 'g');
	var matched = the_pattern.test(the_haystack);
	return matched;
}

// REMOTE REQUEST FUNCTIONS
var http_request = false;
var http_remote_result = "";

function remote_data_request(url, parameters, callback_function) {
	
	http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType("text/xml");
		}
	}
	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) {
			if (http_request.status == 200) {
				// alert(function_call);
				http_remote_result = http_request.responseText;
				eval(http_remote_result);
				eval(callback_function);
			} 
			else {
				alert("There was a problem with the request.");
			}
		}
	};
	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);
	
}