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 isCtrl = false;
var keywords_timeout = 0;
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 xml2str(xmlNode)
 { try 
    { return (new XMLSerializer()).serializeToString(xmlNode); } // Gecko-based browsers, Safari, Opera.
   catch (e) 
    { try 
	   { return xmlNode.xml; } // Internet Explorer.
      catch (e)
       { alert('Xmlserializer not supported'); } //Strange Browser
    }
   return false;
 }
 
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 disable_enter_key(e)
 { if (e.keyCode == 13 || e.which == 13)
    { return false; }
   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 browser_is(b) // MSIE, Firefox, Opera, Netscape, Firebird, Konqueror, Chrome, OmniWeb, Apple, iCab, Safari, Camino
 { if (navigator.userAgent.indexOf(b) != -1)
    { return true; }
   return false;
 }

function ie_version() // MSIE x.x
 { if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
    { var ieversion = new Number(RegExp.$1)
      return ieversion;
	}
   return 0;	
 }

function ff_version() // Firefox/x.x or Firefox x.x
 { if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))
    { var ffversion = new Number(RegExp.$1)
      return ffversion;
	}
   return 0;	
 }

function opera_version() // Opera/x.x or Opera x.x
 { if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent))
    { var oprversion = new Number(RegExp.$1)
      return oprversion;
	}
   return 0;	
 }
 
function show_hide(id)
 { id = document.getElementById(id);
   if (id != null)
    { id.className = ('none' == id.className) ? '' : 'none'; }
   return false;	
 }
  
function print_special()
 { if (document.getElementById != null)
    { var html = '<html><head>';   
	  if (document.getElementsByTagName != null)
       { var head_tags = document.getElementsByTagName('head');
         if (head_tags.length > 0)
          { html += head_tags[0].innerHTML; }
       }
      html += '</head><body>';
	   var print_ready = document.getElementById('print_ready');
      if (print_ready != null)
       { html += print_ready.innerHTML; }
      else
       { return; }
      html += '</body></html>';
	  var print_win = window.open('', 'print_special');
      print_win.document.open();
      print_win.document.write(html);
      print_win.document.close();
      print_win.print();
      return false;
    }
   return false;	
 }

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 row_over(object, classname)
 { object.className = classname; }

function submit_form(f) 
 { ajax_disable_button(f);
   document.forms[f].submit();
   return false;   
 }
 
function submit_form_only(f) 
 { document.forms[f].submit();
   return false;   
 }

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 popup2(url, width, height)
 { var win = window.open(url,'popup_width','toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0, copyhistory=0, width=' + (width + 20) + ', height=' + height + ', screenX=0, screenY=0, top=0, left=0'); 
   win.moveTo((screen.width / 2) - ((width + 20) / 2), 0);
   win.focus();
 } 
 
function popup3(url, width1, height1)
 { width1 = width1 || width;
   height1 = height1 || height;
   var win = window.open(url,'popup_width','toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=1, resizable=1, copyhistory=0, width=' + (width1 + 20) + ', height=' + height1 + ', screenX=0, screenY=0, top=0, left=0'); 
   win.moveTo((screen.width / 2) - ((width1 + 20) / 2), 0);
   win.focus();
 } 
 
function set_focus(pos, action) 
 { pos = pos || 0;
   if (document.forms.length > 0) 
    { var field = document.forms[pos];
      for (i = 0; i < field.length; i++) 
	   { if ((field.elements[i].type != 'image') && (field.elements[i].type != 'hidden') && (field.elements[i].type != 'reset') && (field.elements[i].type != 'submit'))
	      { if (!document.forms[pos].elements[i].disabled && document.forms[pos].elements[i].value == '')
		     { document.forms[pos].elements[i].focus(); }
			if (action == 'select' && ((field.elements[i].type == 'text') || (field.elements[i].type == 'password'))) 
			 { document.forms[pos].elements[i].select(); }
            break;
          }
       }
    }
 }
 
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 truebody()
 { return (!window.opera && document.compatMode && document.compatMode != 'BackCompat') ? document.documentElement : document.body; } 
 
function find_pos(obj)
 { var curleft = curtop = 0;
   if (obj.offsetParent)
    { do
	   { curleft += obj.offsetLeft;
		 curtop += obj.offsetTop;
	   }
	  while (obj = obj.offsetParent);
	}
   return [curleft, curtop];
 }

function check(f, v)
 { var key;
   for (i in document.forms[f])
    { key = i.substr(0, 3);
	  if ((key == 'cid' || key == 'vid') && document.getElementById(i).disabled === false)
       { document.forms[f][i].checked = v; }
	}
 }
 
function check_length(textarea, counter, max)
 { var txt = document.getElementById(textarea);
   var count = document.getElementById(counter);
   if (txt != null && count != null)
    { var length = txt.value.length;
	  if (length > max) 
	   { txt.value = txt.value.substring(0, max); }
	  else
	   { count.innerHTML = max - length; }
	}
 }
 
function hide_div(obj) 
 { if (obj.style.visibility == 'visible') 
    { obj.style.visibility = 'hidden';
      obj.style.display = 'none';
    }
 }

function show_div(obj) 
 { if (obj.style.visibility != 'visible') 
    { obj.style.visibility = 'visible';
      obj.style.display = 'inline';
    }
 }
 
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'; }
	      } 
	   }
    }
 }
 
function is_numeric(text)
 { var chars = "0123456789.";
   var is_number = true;
   var character;

   for (i = 0; i < text.length && is_number == true; i++)
    { character = text.charAt(i); 
      if (chars.indexOf(character) == -1) 
       { is_number = false; }
    }
   return is_number;
 }
 
function is_valid_date(str) 
 { var pattern = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
   var matchArray = str.match(pattern);
   if (matchArray == null) 
    { return false; }
   day = matchArray[1];	
   month = matchArray[3];
   year = matchArray[5];
 
   if (month < 1 || month > 12) 
    { return false; }
   if (day < 1 || day > 31) 
    { return false; }
   if ((month == 4 || month == 6 || month == 9 || month == 11) && day == 31) 
    { return false; }
   if (month == 2) 
    { var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
      if (day > 29 || (day == 29 && !isleap)) 
	   { return false; }
    }
   return true;
 }
 
function display_date(dateObj)
 { month = dateObj.getMonth() + 1;
   month = (month < 10) ? '0' + month : month;
   day = dateObj.getDate();
   day = (day < 10) ? '0' + day : day;
   year  = dateObj.getYear();
   if (year < 2000) 
    { year += 1900; }
   return (day + '/' + month + '/' + year);
 }
 
window.onerror = function() 
 { silent_error_handler(); }

document.onkeyup = function(e)
 { var ev = e || window.event;
   var key = ev.keyCode || ev.which;
   if (key == 17 || key == 17 || ev.ctrlKey) 
    { isCtrl = false; }
 }
document.onkeydown = function(e)
 { var ev = e || window.event;
   var key = ev.keyCode || ev.which;
   if (key == 17 || key == 17 || ev.ctrlKey) 
    { isCtrl = true; }
 }

window.onload = function() 
 { set_focus(); }