var ie = (document.all) ? true:false;
var nn4 = (document.layers) ? true:false;
var nn6 = (document.getElementById && !document.all) ? true:false;
function getSel(theform,flag) {
	if (document.getSelection) txt = document.frames("myEditor").document.frames("textEdit").document.getSelection();
	else if (document.selection) txt = document.frames("myEditor").document.frames("textEdit").document.selection.createRange().text;
	else return;
	if(flag) {
		if(flag=="br") {
			var newTag1 = '<br>';
			var wholeText = document.frames("myEditor").document.frames("textEdit").document.body.innerHTML;//document.forms(strForm).EditorValue.value;
			newText = wholeText.replace(strText,'<span class="' + styleName + '">' + strText + '</span>');
			document.frames("myEditor").document.frames("textEdit").document.body.innerHTML = newText;
		} else if (flag=="div") {
			var newTag2 = '';
			var wholeText = document.frames("myEditor").document.frames("textEdit").document.body.innerHTML;//document.forms(strForm).EditorValue.value;
			newText = wholeText.replace(strText,'<span class="' + styleName + '">' + strText + '</span>');
			document.frames("myEditor").document.frames("textEdit").document.body.innerHTML = newText;
		}
	} else {
		styleVal = document.forms(theform).elements.styles.options[document.forms(theform).elements.styles.selectedIndex].value;
		applyStyle(theform,txt,styleVal);
	}
}
function setCursorPos() {
  globalCursorPos = getCursorPos(page.EditorValue);
}

//This function returns the index of the cursor location in
//the value of the input text element
//It is important to make sure that the sWeirdString variable contains
//a set of characters that will not be encountered normally in your
//text
function getCursorPos(textElement) {
  //save off the current value to restore it later,
  var sOldText = textElement.value;
//create a range object and save off it's text
  var objRange = document.selection.createRange();
  var sOldRange = objRange.text;
//set this string to a small string that will not normally be 
encountered
  var sWeirdString = '#%~';
//insert the weirdstring where the cursor is at
  objRange.text = sOldRange + sWeirdString; objRange.moveStart('character', (0 - sOldRange.length - sWeirdString.length));

//save off the new string with the weirdstring in it
  var sNewText = textElement.value;

//set the actual text value back to how it was
  objRange.text = sOldRange;

//look through the new string we saved off and find the location of
//the weirdstring that was inserted and return that value
  for (i=0; i <= sNewText.length; i++) {
    var sTemp = sNewText.substring(i, i + sWeirdString.length);
    if (sTemp == sWeirdString) {
      var cursorPos = (i - sOldRange.length);
      return cursorPos;
    }
  }
}

//this function inserts the input string into the textarea
//where the cursor was at
function insertString(stringToInsert) {
  var firstPart = document.frames("myEditor").document.frames("textEdit").document.body.innerHTML.substring(0, globalCursorPos);
  var secondPart = document.frames("myEditor").document.frames("textEdit").document.body.innerHTML.substring(globalCursorPos,page.EditorValue.value.length);
  document.frames("myEditor").document.frames("textEdit").document.body.innerHTML = firstPart + stringToInsert + secondPart;
}


function applyStyle(strForm,strText,styleName) {
	var newTag = '<span class="' + styleName + '">' + strText + '</span>';
	var wholeText = document.frames("myEditor").document.frames("textEdit").document.body.innerHTML;//document.forms(strForm).EditorValue.value;
	newText = wholeText.replace(strText,'<span class="' + styleName + '">' + strText + '</span>');
	document.frames("myEditor").document.frames("textEdit").document.body.innerHTML = newText;
}
function copyVal() {
	document.all.text.value=document.all.EditorValue.value;
}
function jump(loc) {
	location='/web/page/'+loc+'/interior.asp';
}

function alignTop(el,lay) {
	if (nn4 && !document.layers[lay]) {
		return;
	}
	if (ie && !document.all(lay)) {
		return;
	}
	if (nn6 && !document.getElementById(lay)) {
		return;
	}
	var vContentLayer;
	var vEl;
	if (nn4) {
		vContentLayer = document.layers[lay];
		vEl=document.images[el];
		xPos = vEl.left;
		yPos = vEl.top;
		tempEl = vEl.offsetParent;
		while (tempEl != null) {
        	xPos += tempEl.left;
			yPos += tempEl.top;
        	tempEl = tempEl.parent.document.offsetLeft;
    	}
	}
	if (ie) {
		vContentLayer = document.all(lay);
		vEl=document.getElementById(el);
		xPos = vEl.offsetLeft;
		yPos = vEl.offsetTop;
		tempEl = vEl.offsetParent;
		while (tempEl != null) {
        	xPos += tempEl.offsetLeft;
			yPos += tempEl.offsetTop;
        	tempEl = tempEl.offsetParent;
    	}
	}
	
	if (nn6) {
		vContentLayer = document.getElementById(lay);
		vEl=document.getElementById(el);
		xPos = vEl.offsetLeft;
		yPos = vEl.offsetTop;
		tempEl = vEl.offsetParent;
		while (tempEl != null) {
        	xPos += tempEl.offsetLeft;
			yPos += tempEl.offsetTop;
        	tempEl = tempEl.offsetParent;
    	}
	}
	if(el=="clientsNav") {
		layswap(lay,'1', eval(xPos-1), eval(yPos+24));
	} else {
		layswap(lay,'1', eval(xPos), eval(yPos+24));
	}
}




function layswap(id,trigger,xPos,yPos) {
    if (document.layers && document.layers[id] != null) {
		//var x=parseInt(xPos)-0;
		//var y=parseInt(yPos)-0;
		//var x=eval(xPos);
		//var y=eval(yPos);
		alert(xPos);
		alert(yPos);
       	document.layers[id].left = xPos;
        document.layers[id].top = yPos;
    }
    
	if (ie) {
        document.all[id].style.posLeft = xPos;
        document.all[id].style.posTop = yPos;
    }
	
	if (nn6) {
		document.getElementById(''+id+'').style.left = xPos;
		document.getElementById(''+id+'').style.top = yPos;
	}

	if (trigger=="1"){
		if (nn4) {
			document.layers[''+id+''].visibility = "show";
		}
		
		if (ie) {
			document.all[''+id+''].style.visibility = "visible";
		}
		
		if (nn6) {
			document.getElementById(''+id+'').style.visibility = "visible";
		}
	}
	else if (trigger=="0"){
		if (nn4) {
			document.layers[''+id+''].visibility = "hide";
		}
		
		if (ie) {
			document.all[''+id+''].style.visibility = "hidden";
		}
		
		if (nn6) {
			document.getElementById(''+id+'').style.visibility = "hidden";
		}
	}
}
  if(window.attachEvent)
    window.attachEvent("onload",setListeners);

  function setListeners(){
    inputList = document.getElementsByTagName("INPUT");
    for(i=0;i<inputList.length;i++){
      inputList[i].attachEvent("onpropertychange",restoreStyles);
      inputList[i].style.backgroundColor = "";
    }
    selectList = document.getElementsByTagName("SELECT");
    for(i=0;i<selectList.length;i++){
      selectList[i].attachEvent("onpropertychange",restoreStyles);
      selectList[i].style.backgroundColor = "";
    }
  }

  function restoreStyles(){
    if(event.srcElement.style.backgroundColor != "")
      event.srcElement.style.backgroundColor = "";
  }
  

   function redirect(myUrl) {
      
         location=myUrl;
      }
 

