var ajax_response_div = 'ajax-response';
var loading_time = 1000;
var timeout_time = 30000;
var ajax_button = 'ajax-button';
var ajax_disabled_button = ajax_button;
var submit_button = 'Submit';
var onclick_event;
var ajax_submitted = false;
var width = screen.width - 4;
var height = screen.height - 4;
var error_color = '#fcc';
var clear_color = '#fff';
var max_submenus = 0;

function get_xml_http_object()
 { var xml_http = null;
   
   if (window.XMLHttpRequest) 
	{ try 
	   { xml_http = new XMLHttpRequest(); } 
	  catch (e) 
	   { xml_http = false; }
    }
   else
    { try 
	   { xml_http = new ActiveXObject('Msxml2.XMLHTTP'); } 
      catch (e) 
	   { try 
	      { xml_http = new ActiveXObject('Microsoft.XMLHTTP'); } 
	     catch (e) 
	      { xml_http = false; }
       }
	}   
   
   return xml_http;
 } 
 
function ajax_timeout(msg)
 { ajax_clear_response();
   ajax_show_error(msg);
   ajax_enable_button();
   set_focus();
 } 
 
function ajax_show_loading(msg)
 { if (document.getElementById(ajax_response_div) != null)
    { document.getElementById(ajax_response_div).style.display = 'block';
	  document.getElementById(ajax_response_div).innerHTML = '<div class="ajax-loading"><div class="ajax-loading-wrapper"><div class="ajax-loading-default"><img class="padding-r-05" src="images/loading.gif" alt="' + msg + '" title="' + msg + '">' + msg + '</div></div></div><div class="ajax-loading-mask-default" style="filter: alpha(opacity=60); -moz-opacity: 0.6;"></div>'; 
	}
 } 
 
function ajax_show_error(msg)
 { if (document.getElementById(ajax_response_div) != null)
    { document.getElementById(ajax_response_div).style.display = 'block';
	  document.getElementById(ajax_response_div).innerHTML = '<a name="msg"></a><div class="ajax-loading"><div class="ajax-loading-wrapper"><div class="ajax-loading-error"><div class="float-l"><img class="padding-r-05" src="images/icons/error.gif"></div><div class="float-l">' + msg + '</div><div class="ajax-clear-response"><img class="hand" src="images/icons/button-close.gif" onclick="ajax_clear_response();"></div></div></div></div><div class="ajax-loading-mask" style="filter: alpha(opacity=60); -moz-opacity: 0.6;"></div>'; 
	}
 } 

function ajax_show_success(msg)
 { if (document.getElementById(ajax_response_div) != null)
    { document.getElementById(ajax_response_div).style.display = 'block';
	  document.getElementById(ajax_response_div).innerHTML = '<div class="ajax-loading"><div class="ajax-loading-wrapper"><div class="ajax-loading-success"><div class="float-l"><img class="padding-r-05" src="images/icons/success.gif"></div><div class="float-l">' + msg + '</div><div class="ajax-clear-response"><img class="hand" src="images/icons/button-close.gif" onclick="ajax_clear_response();"></div></div></div></div><div class="ajax-loading-mask" style="filter: alpha(opacity=60); -moz-opacity: 0.6;"></div>'; 
	} 
 }
 
function ajax_clear_field(el)
 { if (document.getElementById(el) != null)
    { document.getElementById(el).value = ''; }
   set_focus();	
 }  
 
function ajax_clear_response()
 { if (document.getElementById(ajax_response_div) != null)
    { document.getElementById(ajax_response_div).innerHTML = ''; 
	  document.getElementById(ajax_response_div).style.display = 'none';
	}
 } 
 
function ajax_disable_button(f, id)
 { ajax_disabled_button = ajax_button;
   if (id)
    { ajax_disabled_button = ajax_button + id; }

   if (document.getElementById(ajax_response_div) != null)
    { document.getElementById(ajax_response_div).style.display = 'none'; }
   if (document.getElementById(ajax_disabled_button) != null)
    { onclick_event = document.getElementById(ajax_disabled_button).getAttribute('onclick');
	  document.getElementById(ajax_disabled_button).setAttribute('onclick', null);
	  document.getElementById(ajax_disabled_button).className = 'button-disabled';
	  ajax_submitted = true;
	}
   if (document.getElementById(submit_button) != null)
    { document.getElementById(submit_button).disabled = true; 
	  ajax_submitted = true;
	}

   if (f)
    { var form = document.forms[f];
	  if (form != 'undefined')
	   { var field;
		 for (var i = 0; i < form.elements.length; i++) 
          { field = form.elements[i].name;
		    if (form.elements[i].type != 'hidden' && document.getElementById(field) != null)
			 { if (form.elements[i].type == 'radio' || form.elements[i].type == 'checkbox')
			    { document.getElementById(field).style.background = ''; }
			   else
			    { document.getElementById(field).style.background = clear_color; }
			 }
		  }
	   }	  
	} 
 } 
 
function ajax_enable_button()
 { if (document.getElementById(ajax_disabled_button) != null)
    { document.getElementById(ajax_disabled_button).setAttribute('onclick', onclick_event);
	  document.getElementById(ajax_disabled_button).className = 'button-enabled';
	  ajax_submitted = false; 
	}
   if (document.getElementById(submit_button) != null)
    { document.getElementById(submit_button).disabled = false; 
	  ajax_submitted = false; 
	}
 }
 
function silent_error_handler() 
 { return true; }

function get_px_in_em(el)
 { var temp_div = el.appendChild(document.createElement('div'));
   with(temp_div.style)
    { margin = '0em';
      padding = '0em';
      border = 'none';
      height = '1em';
      width = '1em';
    }
   var px_in_em = temp_div.offsetHeight;
   el.removeChild(temp_div);
   return px_in_em;
 }
  
function get_url_param(name) // use: var param = get_url_param('variable')
 { name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
   var regexS = "[\\?\/]" + name + "\/([^\/#]*)";  
   var regex = new RegExp(regexS);  
   var results = regex.exec(window.location.href);  
   if (results == null)    
    { return ''; }
   else 
    { return results[1]; }
 }
 
function get_parameter_names() // get all querystring parameter names
 { var params = new Array();
   var regex = /[\?\/]([^\/]+)\//g;
   while ((results = regex.exec(window.location.href)) != null)
	{ params.push(results[1]); }
   return params;
 }

function popup_window(url)
 { window.open(url,'popup_window','toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=1, resizable=1, copyhistory=0, width=' + width + ', height=' + height + ', screenX=0, screenY=0, top=0, left=0'); }
 
function popup(url)
 { window.open(url,'popup','toolbar=1, location=1, directories=1, status=1, menubar=1, scrollbars=1, resizable=1, copyhistory=1, width=' + width + ', height=' + height + ', screenX=0, screenY=0, top=0, left=0'); } 
 
function url_encode(string) 
 { if (window.encodeURIComponent) 
    { return encodeURIComponent(string); }
   return escape(string);
 }

function url_decode(string)
 { if (window.decodeURIComponent)
    { return decodeURIComponent(string); }
   return unescape(string);
 }

function compatibility_encode(string)
 { string = string.replace(/\+/g, '__PLUS__');
   string = string.replace(/\//g, '__SLASH__');
   string = string.replace(/\\/g, '__BACKSLASH__');
   string = string.replace(/&/g, '__AMPERSAND__');
   string = string.replace(/</g, '__LEFT_ANGLE_BRACKET__');
   string = string.replace(/>/g, '__RIGHT_ANGLE_BRACKET__');
   return url_encode(string);
 }

function toggle_submenus(menus, menu_id, submenus, dir) 
 { if (submenus > max_submenus)
    { max_submenus = submenus; }
	
   for (var i = 1; i <= menus; i++)
    { var obj;
	  if (i == menu_id)
	   { if (document.getElementById('menu-image' + menu_id) != null)
       { if (document.getElementById('menu-image' + menu_id).src.indexOf('open.gif') != -1)
	         { document.getElementById('menu-image' + menu_id).src = dir + 'folder.gif'; }
	        else
	         { document.getElementById('menu-image' + menu_id).src = dir + 'folder-open.gif'; }
	      }
		  
         for (j = 1; j <= submenus; j++)
	      { obj = document.getElementById('submenu' + menu_id + '.' + j);
	        if (obj != null)
	         { if (obj.className == 'subcategory')
	            { obj.className = 'none'; }
	           else
	            { obj.className = 'subcategory'; }
	         }
	      }
	   }
	  else
	   { if (document.getElementById('menu-image' + i) != null)
	      { document.getElementById('menu-image' + i).src = dir + 'folder.gif'; }

		 for (j = 1; j <= max_submenus; j++)
	      { obj = document.getElementById('submenu' + i + '.' + j);
	        if (obj != null)
	         { obj.className = 'none'; }
	      } 
	   }
    }
 }
 
window.onerror = function() 
 { silent_error_handler(); }
