// JScript source code
// Example: obj = findObj("image1");
function findObj(theObj, theDoc)
{
	var p, i, foundObj;
		
	if(!theDoc) theDoc = document;
	if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
	{
		theDoc = parent.frames[theObj.substring(p+1)].document;
		theObj = theObj.substring(0,p);
	}
	if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
	for (i=0; !foundObj && i < theDoc.forms.length; i++) 
		foundObj = theDoc.forms[i][theObj];
	for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
		foundObj = findObj(theObj,theDoc.layers[i].document);
	if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
		
	return foundObj;
}

// * Dependencies * 
// this function requires the following snippets:
// JavaScript/readable_MM_functions/findObj
//
// Accepts a variable number of arguments, in triplets as follows:
// arg 1: simple name of a layer object, such as "Layer1"
// arg 2: ignored (for backward compatibility)
// arg 3: 'hide' or 'show'
// repeat...
//
// Example: showHideLayers(Layer1,'','show',Layer2,'','hide');
function showHideLayers()
{ 
	var i, visStr, obj, args = showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3)
	{
		if ((obj = findObj(args[i])) != null)
		{
		visStr = args[i+2];
		if (obj.style)
		{
			obj = obj.style;
			if(visStr == 'show') visStr = 'inline';
			else if(visStr == 'hide') visStr = 'none';
		}
		obj.display = visStr;
		}
	}
}

// Example:
// alert( readCookie("myCookie") );
function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}


// Example:
// writeCookie("myCookie", "my name", 24);
// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.
function writeCookie(name, value, hours)
{
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}


function IsEmptyAlert(obj, name) {
	if (obj.value == "") {
		alert("Please enter a value for \"" + name + "\"");
		obj.focus();
		return true;
	}
	return false;
}

function IsEmpty(obj) {
	if (obj.value == "") return true;
	return false;
}

function SelectValue(objSlct, val) {
	for (i=0;i<objSlct.length;i++) {
		if (objSlct.options[i].value == val) {
			//alert(objSlct.options[i].value + "   " + i);
			objSlct.selectedIndex = i;
			break;
		}
	}
}

function SelectTextValue(objSlct, val) {
	for (i=0;i<objSlct.length;i++) {
		if (objSlct.options[i].text == val) {
			//alert(objSlct.options[i].value + "   " + i);
			objSlct.selectedIndex = i;
			break;
		}
	}
}

function replace(str, find, replace) {
	while (str.indexOf(find) >= 0) {
		var i = str.indexOf(find);
		str = str.substr(0, i) + replace + str.substr(i + find.length);
		//alert("found " + find + " replacing with " + replace + " = " + str);
	}
	return str;
}
