function cascadeSelection(f, obj) {
	var rootNodeID = obj.id;
	var priorStatus = obj.checked;
	for (var i=0;i<f.length;i++){
	  if (f[i].id.indexOf(rootNodeID) != -1 && f[i].id != rootNodeID) f[i].checked = !f[i].checked;
	}
}

function init() {
  if (!document.getElementById) return
  var imgOriginSrc;
  var imgTemp = new Array();
  var imgarr = document.getElementsByTagName('img');
  for (var i = 0; i < imgarr.length; i++) {
    if (imgarr[i].getAttribute('jsrc')) {
        imgTemp[i] = new Image();
        imgTemp[i].src = imgarr[i].getAttribute('src');
		imgarr[i].setAttribute('src', imgTemp[i].src);
        imgarr[i].onmouseover = function() {
			imgOriginSrc = this.getAttribute('src');
            this.setAttribute('src',this.getAttribute('jsrc'))
        }
        imgarr[i].onmouseout = function() {
			if (imgOriginSrc) {
				this.setAttribute('src',imgOriginSrc);
			}
        }
    }
  }
}
onload=init;

function displayWindow(url, width, height) {

        var Win = window.open(url,"displayWindow",'width=' + width + ',height=' + height + ',resizable=1,scrollbars=yes,menubar=no,status=no' );

}

function openStore(url) {
	MM_openBrWindow(url,'tradingco','width=600,height=500,menubar=yes,resizable=yes,scrollbars=yes,toolbar=yes');
	return void(0);
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function show(object) {
  if (document.getElementById) {
    document.getElementById(object).style.visibility = 'visible';
  }
  else if (document.layers && document.layers[object]) {
    document.layers[object].visibility = 'visible';
  }
  else if (document.all) {
    document.all[object].style.visibility = 'visible';
  }
}

function hide(object) {
  if (document.getElementById) {
    document.getElementById(object).style.visibility = 'hidden';
  }
  else if (document.layers && document.layers[object]) {
    document.layers[object].visibility = 'hidden';
  }
  else if (document.all) {
    document.all[object].style.visibility = 'hidden';
  }
}

function CheckFile(f1,f2,xfa) {
	if (!f1.value) {
		alert("Please select a file to upload!");
		return false;
	} else {
		f2.value=xfa;
		hide('on_off_form');
		show('pleasewait');
		return true;
	  }
}

function confirmchanges(msg) {
if (msg == null) {
	msg = 'Are you sure you want to delete this record? Please note that these changes cannot be undone!';
}
if (window.confirm(msg)) 
        { return true;
        } 
else { return false; 
        }  
   }

function confirmandgo(url, msg) {
if (msg == null) {
	msg = 'Are you sure you want to delete this record? Please note that these changes cannot be undone!';
}
if (window.confirm(msg)) 
	{ 
		parent.location=url;
	} 
else { 
		return false; 
      }  
   }

function selectall(selfield,holder,selbutton,el){
if (holder.value == 'true'){
	var elval = false;
	holder.value = 'false'
	selbutton.value = 'Select All'
	} 
	else{
	var elval = true;
	holder.value = 'true'
	selbutton.value = 'Clear All'
	}
	for (var i=0;i<el.elements.length;i++){
    var e = el.elements[i];

    if (e.name == selfield) {e.checked = elval;}
	}
}
function launchEditor(f) {
	MM_openBrWindow("index.cfm?fuseaction=common.editor&textareafield=" + f,"win","scrollbars=yes,resizable=yes,width=640,height=450");
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function confirmBatchDelete() {
	if (document.forms[0].DeletePageContents == null) {
		return true;
	} else {
		for (i=0; i<document.forms[0].DeletePageContents.length; i++) {
			if (document.forms[0].DeletePageContents[i].checked) {
				return confirm('Are you sure you want to DELETE all selected elements?');
			}
		}
	}
	return true;
} 

function change(e,bg){
	if (!bg) var bg = "#e0e0e0";
	document.getElementById(e).style.borderColor = "#ff0000";
	document.getElementById(e).style.backgroundColor = bg;
}

function change_back(e){
	document.getElementById(e).style.borderColor = "#cccccc";
	document.getElementById(e).style.backgroundColor = "";
}

function checkSearch(fieldlen) {
	if (!fieldlen) {
		alert("You must specify a search criteria.");
		return false;
	} else {
		return true;
	}
}

function highlight(e,cell, bg) {
	if (e.checked) {
		change(cell, bg);
	} else {
		change_back(cell, bg);
	}
}

function confirmandsubmit(msg, f) {
	if (confirm(msg)) {
		f.submit();
		return true;
	} else {
		return false;
	}
}
 

// START Copyright protection scripts
var specialcase = ((navigator.userAgent.indexOf('Mac') != -1) || document.all)
var flag = 0;
var msg = '© 2005 Olowalu Town LLC.\nThis image is not available for public use.\nMahalo.';
var x,y,x1,y1,copyAttempt;

function photo_init()
{
	if (!(document.getElementById || document.all || document.layers)) return;
	if (specialcase && document.layers)
	{
		document.captureEvents(Event.MOUSEMOVE);
		document.onmousemove = special;
	}
	for (i=0;i<document.images.length;i++)
	{
		document.images[i].onmousedown = checkIt;
		document.images[i].onmouseup = function() {return false};
		if (specialcase)
		{
			document.images[i].onmousemove = special;
			document.images[i].onclick = clearIt;
		}
	}
}

function checkIt(e)
{
	copyAttempt = 0;
	if (window.Event)
	{
		x = e.screenX;
		y = e.screenY;
		theButt = (e.which == 3);
	}
	else
	{
		x = window.event.clientX;
		y = window.event.clientY;
		theButt = (window.event.button == 2);
	}
	if (theButt)
	{
		copyAttempt = 1;
		flag = 0;
		alert(msg);
		return false; // NN4 only
	}
	if (specialcase) flag = 1;
	return false;
}

function special(e)
{
	theObj = '';
	if (window.Event)
	{
		x1 = e.screenX;
		y1 = e.screenY;
		if (e.target.parentNode) theObj = e.target.parentNode.tagName;
	}
	else
	{
		x1 = window.event.clientX;
		y1 = window.event.clientY;
		theObj = window.event.srcElement.parentElement.tagName;
	}
	var isLink = (theObj == 'A');
	if (flag && (!isLink || ((Math.abs(x-x1) > 10) || (Math.abs(y-y1) > 10))))
	{
		copyAttempt = 1;
		flag = 0;
		alert(msg);
		return false;
	}
}

function clearIt()
{
	flag = 0;
	if (copyAttempt)
	{
		copyAttempt = 0;
		return false;
	}
}
// END Copyright protection scripts


function findReplace() {
	var fromString = prompt('Find:', '');
	if (fromString != null) {
		var toString = prompt('Replace:', '');
	}
	if (toString != null) {
		document.forms[0].ContentBody.value = replaceSubstring(document.forms[0].ContentBody.value, fromString, toString);
	}
}

function replaceSubstring(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function

function imgCoordinatesFinder (evt, img) {
  var offsetX = 0;
  var offsetY = 0;
  if (document.coordCounter == null) {
	  document.coordCounter = 1;
  } else document.coordCounter++;
  if (window.event) {
    offsetX = window.event.offsetX;
    offsetY = window.event.offsetY;
  }
  else if (evt.target) {
    var coords = {x: 0, y: 0 };
    var el = evt.target;
    do {
      coords.x += el.offsetLeft;
      coords.y += el.offsetTop;
    }
    while ((el = el.offsetParent));
    offsetX = evt.clientX - coords.x;
    offsetY = evt.clientY - coords.y;
    //alert(offsetX + ',' + offsetY);
  }
  if ((document.coordCounter%2) != 0) {
	  document.form1.CropLeft.value = offsetX;
	  document.form1.CropTop.value = offsetY;
  } else {
	  document.form1.CropRight.value = (document.form1.width.value - offsetX);
	  document.form1.CropBottom.value = (document.form1.height.value - offsetY);
  }
}
