////////////////////////////////////////////////////////////////////////////
// JavaScript Utilities
//
// Author: Cris Perdue (cris@perdues.com)
//
////////////////////////////////////////////////////////////////////////////

// True iff the browser is a Microsoft product.
var ie = navigator.appName.indexOf("Microsoft")==0;

// True iff the browser is a Netscape product
var nn = navigator.appName.indexOf("Netscape")==0;

// Browser major version number as an integer
var version = parseInt(navigator.appVersion);

// True iff JavaScript 1.1 or higher
var js1_1 =  (ie && version>=4) || (nn && version>=3);

// True iff JavaScript 1.2 or higher
var js1_2 = (version>=4 && (ie || nn));

// True if JavaScript 1.2 integrated with Java support.
// IE on the Mac does not let JavaScript drive or access
// state of Java applets, so this is false on that platform.
var jj = version>=4 && navigator.javaEnabled()
        && (nn || (ie && navigator.platform.substring(0, 3)!="Mac"));

// Substitute for location.pathname that works around
// IE4 behavior when a port number is present.
function pathname(w) {
  var p = w.location.pathname;
  if (p.indexOf("/:")==0)
    p = p.substring(p.indexOf("/", 1));
  return p;
}


// Use the window name to decide whether to try to close
// it and maybe refresh its opener.
function closeIfPopup() {
  if (window.name=="RPopup" || window.name=="Popup") {
    if (window.name=="RPopup") {
      window.opener.location.reload();
    }
    if (window.opener && !window.opener.closed) {
      window.close();
    }
  }
}


function popback(n) {
  window.open("/include/js/popback.html?n="+n, "Popup", "resizable,width=250,height=120");
}

function popupSmall(url) {
  if (js1_1) {
    window.open(url, "SmallPopup", "resizable,width=250,height=100");
    return false;
  }
}

// Pop up a "help window" named "Help".
function popupHelp(url) {
    var win = window.open(url, "Help",
      "resizable,scrollbars,width=600,height=400");
    // ,screenX=50,screenY=50,left=50,top=50");
    if (win.focus) win.focus();
    return false;
}


// Pop up a SMALL "features window" named "Features".
function popupFeatures(url) {
    var win = window.open(url, "Features",
      "resizable,scrollbars,width=640,height=480");
    // ,screenX=50,screenY=50,left=50,top=50");
    if (win.focus) win.focus();
    return false;
}

// Pop up a SMALL "glossary window" named "Glossary".
function popupGlossary(url) {
    var win = window.open(url, "Glossary",
      "resizable,scrollbars,width=250,height=100");
    // ,screenX=50,screenY=50,left=50,top=50");
    if (win.focus) win.focus();
    return false;
}



function backButton(caption, n) {
  if (version==4 && (nn || ie)) {
    document.writeln('<FORM name="back'+caption+'">');
    document.writeln('  <input type=button value="'+caption+'"'
		     +'    onclick="popback('+n+')">\n'
		     +'</FORM>');
  }
}

// Function with standard Portal policy for window sizes.
// This works within the limitations of IE4 available information.
// The biggest limitation here is that earlier browsers wind up with
// windows that are not very high.  I believe that specifying a width
// without a height is buggy, but we can try that.
// Navigator 4 resizes an existing window to these dimensions,
// but IE leaves existing window dimensions alone.  Navigator 4
// lets you resize a window later, and we should be able to open,
// then test whether the window is visiting a location, then
// resize if it appears to be new.
function openStdWin(url, winName, w, h) {
  if (w==null) w = 650;
  if (h==null) {
    h = 440;
    if (window.screen) {
      var sw = window.screen.availWidth;
      var sh = window.screen.availHeight;
      if (sw<w) w = sw;
      h = 440+.75*(sh-440);
    }
  }
  var win = window.open(url, winName, "resizable,scrollbars,width="+w+",height="+h);
  win.focus();
  return win;
}

/**
  Open a standard Portal window and center it.
*/
function openCenteredWin(url, winName, w, h) {
  var win = openStdWin(url, winName, w, h);
  win.moveTo(screen.availWidth/2 - w/2, screen.availHeight/2 -h/2);
  return win;
}

function endsWith(main, find) {
  var pos = main.length-find.length;
  return main.substring(pos)==pos;
}


// Check if a window refresh is requested, reload
// it and close the request.
function checkReload() {
  var rf = "__reload";
  var pos = main.length-rf.length;
  if (main.substring(pos)==rf) {
    window.location.reload();
    window.name = window.name.substring(0, pos);
  }
}

// setEditable
//  set all fields in the give form, with the given prefix 
//  to the given state (true == editable, false == disabled)

function setEditable(_form, _prefix, _editable) {
  for (var i = 0; i < _form.elements.length; i++) {
    var _element = _form.elements[i];
    if (_element.name.indexOf(_prefix) == 0) {
      _element.disabled = !_editable;
    }
  }
}


var message="Copyright 2005: turismoles.com";
function click(e) {
	if (document.all) {
		if (event.button == 2) {
		alert(message);
		return false;
		}
	}
	if (document.layers) {
		if (e.which == 3) {
			alert(message);
			return false;
		}
	}
}

//if (document.layers) {
//	document.captureEvents(Event.MOUSEDOWN);
//}
//document.onmousedown=click;


function disableselect(e){
	return false
}
function reEnable(){
	return true
}
//document.onselectstart=new Function ("return false")

//if (window.sidebar){
//	document.onmousedown=disableselect
//	document.onclick=reEnable
//}