// global variables
var _browserType = navigator.appName;
var _isIEBrowser = (_browserType == 'Microsoft Internet Explorer');
var _vUID = '';
var _ip = false;
var _ips = false;

// global constants
var _cXmlNodeTypeElement = 1; //xml node type is Element

function openWindow(url, windowData, width, height, top, left, resizable, scrollbars) {
  var settings = buildWindowOpenArguments(width, height, top, left, resizable, scrollbars);
  window.open(url, windowData, settings);
}

function buildWindowOpenArguments(width, height, top, left, resizable, scrollbars) {
  var resizable = (resizable ? 'yes' : 'no');
  var scrollbars = (scrollbars ? 'yes' : 'no');
  var settings = 'width=' + width + ',height=' + height + ',resizable=' + resizable + ',scrollbars=' + scrollbars;
  if (top)
    settings += ',top=' + top;
  if (left)
    settings += ',left=' + left;
  return settings
}

function openPopupWindow(url, windowData, width, height, top, left, resizable, scrollbars) {
  url += (url.indexOf('?') >= 0 ? '&' : '?') + 'popupMode=true';
  openWindow(url, windowData, width, height, top, left, resizable, scrollbars);
}

function showHelpPage(url) {
  openPopupWindow(url, null, 650, 300, 100, 100, 'yes', 'yes');
}

function getObjectPath(objectName) {
  return getApplicationName() + objectName;
}

function getPageName() {
  var pagePath = window.location.pathname;
  var pos = pagePath.indexOf('/', 1);
  return pagePath.substring(pos + 1, pagePath.length).toLowerCase();
}

function getPageMainForm(formName) {
  formName = (formName ? formName : 'form1');
  return document.forms[formName];
}

function submitPage(sNewFormAction, formName) {
  var frm = getPageMainForm(formName);
  if (frm) {
    frm.action = sNewFormAction;
    if (frm.__VIEWSTATE) frm.__VIEWSTATE.name = 'NOVIEWSTATE';
    frm.submit();
  }
}

function submitPageWithDelay(sNewFormAction, delay) {
  setTimeout('submitPage(\'' + sNewFormAction + '\')', delay);
}

function redirectPage(url) {
  document.location.href = url;
}

function redirectPageWithDelay(url, delay) {
  setTimeout('redirectPage(\'' + url + '\')', delay);
}

function browserDetect(text) {
   str = (navigator.userAgent.toLowerCase()).indexOf(text) + 1;
   data = text;
   return str;
}

function getInternetExplorerVersion() {
	var rv = -1; // Return value assumes failure.
	if (navigator.appName == 'Microsoft Internet Explorer') {
		var ua = navigator.userAgent;
		var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
		if (re.exec(ua) != null)
			rv = parseFloat( RegExp.$1 );
	}
	return rv;
}

function getWindowWidth() {
  // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
  if (typeof window.innerWidth != 'undefined') {
    return window.innerWidth;
  }
  // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
  else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
    return document.documentElement.clientWidth;
  }
  // older versions of IE 
  else {
    return document.getElementsByTagName('body')[0].clientWidth;
  }
}

function getWindowHeight() {
  // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
  if (typeof window.innerHeight != 'undefined') {
    return window.innerHeight;
  }
  // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
  else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientHeight != 'undefined' && document.documentElement.clientHeight != 0) {
    return document.documentElement.clientHeight;
  }
  // older versions of IE 
  else {
    return document.getElementsByTagName('body')[0].clientHeight;
  }
}

function doNothing() {
  // not supposed to do anything
}

function checkSearchText(e) {
  var ev =(window.event ? window.event : e); //IE:Moz
  var keyCode = (ev.keyCode ? ev.keyCode : ev.charCode);
  if (keyCode == 47 || keyCode == 92) { // '/' '\'
    if (ev.preventDefault)
      ev.preventDefault();
    else
      ev.returnValue = false;
    return false;
  }
}

function getCookie(c_name, c_item_name) {
  var rslt = '';
  if (document.cookie.length > 0) {
    c_start = document.cookie.indexOf(c_name + "=");
    if (c_start != -1) { 
      c_start = c_start + c_name.length+1; 
      c_end = document.cookie.indexOf(";",c_start);
      if (c_end == -1)
        c_end = document.cookie.length;
      rslt = unescape(document.cookie.substring(c_start,c_end));
    }
  }
  if (rslt != '' && c_item_name) {
    i_start = rslt.indexOf(c_item_name + "=");
    if (i_start != -1) {
      i_start = i_start + c_item_name.length+1; 
      i_end = rslt.indexOf("&",i_start);
      if (i_end == -1)
        i_end = rslt.length;
      rslt = unescape(rslt.substring(i_start,i_end));
      return rslt;
    }
    else
      return '';
  }
  return rslt;
}

function set_onFocus() {
	var links = document.getElementsByTagName('A');
	for(i=0;i<links.length; i++)
		links[i].setAttribute("onfocus", "blur()");
}

function showBanner(bannerID, bannerSrc, bannerWidth, bannerHeight) {
  var banner = document.getElementById(bannerID); 
  var windowWidth = getWindowWidth();
  if (banner && (bannerID != 'leftBanner' || (bannerID == 'leftBanner' && windowWidth >= 1000)))
    banner.innerHTML = '<IFRAME style="BACKGROUND-COLOR: transparent" marginWidth="0" marginHeight="0" src="' + bannerSrc + '" height="' + bannerHeight + '" width="' + bannerWidth + '" scrolling="no" frameBorder="no" allowTransparency></IFRAME>';
  else if (banner && bannerID == 'leftBanner' && windowWidth < 1000)
    banner.style.display = 'none';
}

function showFlashBanner(bannerID, bannerSrc, bannerWidth, bannerHeight, wmode) {
  var banner = document.getElementById(bannerID);
  if (banner) banner.innerHTML = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" WIDTH="' + bannerWidth + '" HEIGHT="' + bannerHeight + '"><PARAM NAME="movie" VALUE="' + bannerSrc + '"><PARAM NAME="quality" VALUE="high"><PARAM NAME="allowScriptAccess" VALUE="always">' + (wmode ? '<param name="wmode" value="' + wmode + '" />' : '') + '<EMBED src="' + bannerSrc + '" quality="high" WIDTH="' + bannerWidth + '" HEIGHT="' + bannerHeight + '" ' + (wmode ? 'wmode="' + wmode + '"' : '') + ' allowScriptAccess="always" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED></OBJECT>';
}

function handleBannerAction(bannerID, actionName) {
  switch (actionName) {
    case 'close': hideBanner(bannerID); break;
    default:
      if (typeof(window['handleBannerActionEx']) == 'function')
        handleBannerActionEx(bannerID, actionName);
  }
}

function hideBanner(bannerID) {
  var banner = document.getElementById(bannerID);
  if (banner) banner.style.display = 'none';
}

function addBookmarkEx(url, title) {
  if (window.sidebar) // Mozilla Firefox Bookmark	
    window.sidebar.addPanel(title, url, "");
  else if (window.external) // IE Favorite
    window.external.AddFavorite( url, title);
}

function doSearch() {
  var searchText = document.getElementById("searchText").value;
  if (searchText != 'חיפוש' && searchText != '')
    document.getElementById("headerSearch").submit();
}

function doLoad() {
  set_onFocus();
  if (typeof(window['showBanners']) == 'function')
    showBanners();
}
//window.onload = doLoad;