var Preview;
var newWin;
var hWin;
var text = "";


var nWin = ""
var UserDate = ""
var ReturnEl = ""

function showCalendar(elName)
	{
	Height = 174
	Width = 245
	Top = 100
	Left = 100
	
	el = document.forms["FormName"].elements[elName]
	UserDate = el.value
	ReturnEl = elName
	
	if (nWin == "")
		{
		nWin = window.open(".product/cal_dhtml.htm", "Calendar", "height=" + Height + ",width=" + Width 
			+ ",top=" + Top + ",left=" + Left + ",status=no,toolbar=no,menubar=no,"
			+ "location=no,resizable=no,scrollbars=no")
		nWin.opener = window
		}
	else
		{
		CloseNWin()
		showCalendar(elName)
		}	
	}
	
function CloseNWin()
	{
	if (nWin != "")
		{
		nWin.close()
		nWin = ""
		}
	}

function getFileList() {
	if(document.all("id").value==" ") {
		if(confirm("Please save your newly created library prior to adding files to it. Would you like to save now?")) {
			litesave();
		}
	}
	else {
	document.frames("FLGallery").location.reload(true);
	document.all("FLGallery").height="425";
	displaydiv('fileList');
	}
}
function getTempview(pageid) {
	document.frames("TempGallery").location.reload(true);
	displaydiv('TempView');
}
function getTreeview(pageid) {
	if (pageid=="cr1") {
		alert("The Location of the Home Page cannot be changed.");
	}
	else {
	document.frames("TVGallery").location.reload(true);
	displaydiv('TreeView');
	}
}
function displayfileList(ofileList){
	if (ofileList==true) {
		document.editor.btnFileList.disabled=true;
	}
	else {
		document.editor.btnFileList.disabled=false;
	} 
}

function updateNav(parentId,parentName,parent) {
if (parent==true) {
	var parentF=window.frames("editorframe").window.frames("TVGallery");
	parentF.document.all("parentId").value=parentId;
	parentF.document.all("parentname").value=parentName;
}
else {
	document.all("parentId").value=parentId;
	document.all("parentname").value=parentName;
}
}
function confirmNav() {
var parentName;
var parentId;
parentName=document.all("parentname").value;
parentId=document.all("parentId").value;
	if (confirm("You have chosen " + parentName + ". Are you sure you want to continue?")) {	
		window.parent.document.editor.parentid.value=parentId;
		window.parent.document.editor.parentName.value=parentName;
		window.parent.document.all("TreeView").style.visibility='hidden';
	}
	else {
		window.parent.document.all("TreeView").style.visibility='hidden';
	}
}
function loadEditor() {
         var mod=document.editor.editMod.value;
		        if (mod=="Text") {
		           control.innerText=control.innerHTML;
			        document.editor.editMod.value="Text";
                 document.getElementById("editorBtns").style.visibility='hidden';
                 document.editor.ckHTML.checked=true;
	                }
}
function switchMod() {
		        var mod=document.editor.editMod.value;
		        if (mod=="WYSIWYG") {
		           control.innerText=control.innerHTML;
			        document.editor.editMod.value="Text";
                 document.getElementById("editorBtns").style.visibility='hidden';
                 document.editor.ckHTML.checked=true;
                 }
              else {
			          control.innerHTML=control.innerText;
			          document.editor.editMod.value="WYSIWYG";
                   document.getElementById("editorBtns").style.visibility='visible';
                   document.editor.ckHTML.checked=false;
	                }
}

function setIfrm(sIfrm,sSrc,sDiv,sDb) 
{
sIfrm.src=sSrc;
displaydiv(sDiv);
}
function showcc(billType) {
	if (billType=="cc") {
		displaydiv("ccinfo");
	}
	else {
		hidediv("ccinfo");
	}
//alert("Does this work!");
}

function setSearchTxt()
{
var searchTxt = window.parent.document.all("hlstr").value;
if (!searchTxt) {
alert("Please Highlight Text!");
}
}

function insertLink(url) {
var rng = window.parent.document.body.createTextRange();
var searchTxt = window.parent.document.all("hlstr").value;
rng.findText(searchTxt);
rng.select();
rng.execCommand('CreateLink',false,url);
}

function changeColor(th) {  
		//'resets' the background-color to white  
		th.style.background = "white";
}
function validate() {  
	var str = "";  
	var elements = document.getElementsByTagName('input'); 
	for(var i = 0; i < elements.length; i++) {   
	//var pattern = elements.item(i).getAttribute('pattern'); 
	var pattern = elements.item(i).getAttribute('pattern'); 
		//alert(pattern);   
		if (pattern != null) {      
			var value = elements.item(i).value;  
			//var offendingChar = value.match(pattern);  
			if(value.length == 0) {
			str += elements.item(i).getAttribute('dname')+" is required!\n"
			elements.item(i).style.background = "red";
			}
			//if(offendingChar != null || value.length==0) {     
			//str += elements.item(i).getAttribute('errorMsg')+ "\n";     
			//elements.item(i).style.background = "red";	       
			//}	    
		}  
	} 
  	if (str != "") {    
		alert("ERROR ALERT!!\n" +str);     
		return false;  
	} 
	else {    
	return true;  
	}
}

function getActiveText(e) { 
// Sets text MSIE or Netscape active 
// text based on browser, puts text in form
text = (document.all) ? document.selection.createRange().text : document.getSelection();
document.editor.hlstr.value = text;
return true;
}
function NewWindow(url,windowWidth,windowHeight,scrollbar)
{  
	// set the window features
	var features = "width=" + windowWidth + ",height=" + windowHeight + ",scrollbars=" + scrollbar;
	// open the window
	window.open(url, "popup", features);
}
function deletefile(dbase,ftype)
{
var input;
if (ftype=='i') 
{
var x=document.forms("editor").imageid;
var oid=document.forms("editor").id.value;
var filename=x.options[x.selectedIndex].text;
var x=document.forms("editor").imageid;
var fileid=x.options[x.selectedIndex].value;
}
else 
{
var x=document.forms("editor").fileid;
var filename=x.options[x.selectedIndex].text;
var oid=document.forms("editor").id.value;
var x=document.forms("editor").fileid;
var fileid=x.options[x.selectedIndex].value;
}
var url="upload.php?id="+oid+"&filename=" + filename + "&fileid=" + fileid + "&mod=d&ftype="+ ftype +"&church_db=" + dbase;
NewWindow(url,300,300,'no');
}
function modify(modv) {
	document.contentselect.mod.value = modv;
	document.contentselect.submit();
}
function litesave() {
	if(validate()){
	document.editor.mod.value = "save";
	document.editor.submit();
	}
}
function liteclosed() {
		if (confirm("Do you want to Save before closing?")) 
		{
			document.editor.closed.value = "true";
			litesave();
		}
		else {
			document.editor.mod.value = "close";
			document.editor.submit();
		}
}
function save() {
	if (document.editor.editMod.value=="WYSIWYG") {
	if (control.innerHTML == "" || control.innerHTML == null) {
		document.editor.content.value = "under construction";
	}
	else {
		document.editor.content.value = control.innerHTML;
	}
	}
	else {
	if (control.innerText == "" || control.innerText == null) {
		document.editor.content.value = "under construction";
	}
	else {
		document.editor.content.value = control.innerText;
	}	
	}
	if (document.editor.content.value =="" || document.editor.content.value ==null) {
		alert("Body is Required");
		history.go(-1);
	}
	if(validate()){
	document.editor.mod.value = "save";
	document.editor.submit();
	}
}
function tstclosed() {
		if (confirm("Do you want to Save before closing?")) 
		{
			document.editor.closed.value = "true";
			save();
		}
		else {
			document.editor.mod.value = "close";
			document.editor.submit();
		}
}
function cancel() {
	document.editor.mod.value = "cancel";
	document.editor.submit();
}
function create() {
	document.contentselect.mod.value = "create";
	document.contentselect.id.value = "";
	document.contentselect.submit();
}

function deleted() {
	if (confirm("Are you sure you want to delete?")) 
	{
	document.contentselect.mod.value = "delete";
	document.contentselect.submit();
	}
}

function preview() {
	var pagetitle;
	var url;
	var pagecontent;
	var clientpath;
	pagecontent = control.innerHTML;
	clientpath = 'demo/clients/';
	pagetitle = document.editor.pagetitle.value;
	url = 'http://webpenner.com/demo/clients/base/page.php?pagecontent=' + pagecontent + '&pagetitle=' + pagetitle;
	window.open(url, "popup");
}

function changeView(){
	var curLOC = document.location + '';
	var CONF = confirm('WARNING:\nChanges since your last save will be lost. To change your view without saving your most recent changes, select "OK". To save your most recent changes select "Cancel" then select the "Save" button.');
	if(CONF == 1){
		if(curLOC.indexOf("mode=design")!= -1){
			curLOC = curLOC.replace(/design/g,'html');
		}else{
			curLOC = curLOC.replace(/html/g,'design');
		}
		document.location = curLOC
	}
}
function help(section){ hWin = window.open('common/help.asp#'+section, 'hWin', 'scrollbars=yes,resizeable=yes'); hWin.focus(); }
function exitManager(){
	if(newWin){ newWin.close(); }
	if(Preview){ Preview.close(); }
	if(hWin){ hWin.close(); }
	document.location = 'admin.asp';
}
var winX = 0;
var winY = 0;
var curKey = 0;
function recKey(key){
	curKey = key;
}
function recCursor(){
	if(curKey == 16){
		winX = window.event.x;
		winY = window.event.y;
		insertPlaceholder('^');
	}
}
function insertPlaceholder(addSTR){
	STR = document.body.createTextRange();
	STR.moveToPoint(winX, winY);
	STR.pasteHTML(addSTR);
	control.focus();
}
function setString(addSTR){
	var searchString = escape(control.innerHTML);
	if(searchString.indexOf("%5E") != -1){
		searchString = searchString.replace('%5E', addSTR);
		control.innerHTML = unescape(searchString);
	}else{
		control.innerHTML += addSTR;
	}
	control.focus();
}
function createLink(newLink){
	var link = newLink.split("|");
	var lType = 'PID';
	document.control.pageList.selectedIndex = 0;
	if(link[1] == '0'){
		lType = 'PG';
		link[1] = link[2];
	}
	link[2] = prompt('The display text for this link is:', link[2]);
	setString('<A HREF="../templates/default.asp?id='+link[0]+'&'+lType+'='+link[1]+'&RID='+link[3]+'">'+link[2]+'</A> ');
}
function createSiteLink(href){
	document.execCommand('CreateLink', false, 'http://www.e-zekiel.com');
	control.focus();
}
function createMediaLink(newLink){
	var link = prompt('The display text for this link is:', newLink.substring((newLink.lastIndexOf("/")+1), newLink.lastIndexOf(".")));
	var linkPath = newLink.substring(0, newLink.lastIndexOf("."));
	var linkType = newLink.substring((newLink.lastIndexOf(".")+1), newLink.length);
	if((linkType == "rm")||(linkType == "mp3")){
		linkType = "ram";
		setString('<A HREF="http://www.real.com" TARGET="_blank"><IMG SRC="http://63.241.144.187/clientImages/rm.gif" WIDTH=16 HEIGHT=13 ALT="Real Media File" BORDER=0></A> <A HREF="'+linkPath+'.'+linkType+'" TARGET="_blank">'+link+'</A> ');
	}else{
		setString('<A HREF="'+newLink+'" TARGET="_blank">'+link+'</A> ');
	}
}
function importScript(scriptREF){
	setString('<DIV CLASS="scriptBlock"><BLOCKQUOTE LANGUAGE="JavaScript" SRC="http://'+scriptREF+'"></BLOCKQUOTE></DIV>');
}
function importCode(code){
	setString(code);
}
function createTable(){
	var TBL = '';
	var ROW = '';
	var COLS = prompt('ADD COLUMNS:\nHow many columns do you need?',2);
	var ROWS = prompt('ADD ROWS:\nHow many rows do you need?',1);
	var BORDER = confirm('ADD BORDER:\nClick "OK" to add a border to your table.');
	if(BORDER == 1){ BORDER = 1; }else{ BORDER = 0; }
	if((COLS - 1) > 0){
		for(x = 1; x <= COLS; x++){
			ROW += '<TD VALIGN="TOP" class="cell">Type Here Cell '+ x +'</TD>';
		}
		if(ROWS <= 0){ ROWS = 1; }
		for(x = 1; x <= ROWS; x++){
			TBL += '<TR>'+ ROW +'</TR>';
		}
		setString('<TABLE WIDTH="100%" CELLPADDING="3" CELLSPACING="0" BORDER="'+BORDER+'">'+ TBL +'</TABLE>');
	}
}
function createForm(id){
	var recip = prompt('FORM RECIPIENT:\nEnter an e-mail address for the person that should recieve this form response.','');
	var subject = prompt('FORM SUBJECT:\nEnter a subject for the response e-mail.','');
	setString('<FORM METHOD="POST" ACTION="../mail.asp?id='+id+'"><INPUT TYPE="HIDDEN" NAME="recip" VALUE="'+recip+'"><INPUT TYPE="HIDDEN" NAME="subject" VALUE="'+subject+'">');
}
document.execCommand('LiveResize',false,1);
document.execCommand('MultipleSelection',false,1);
function onlink(button){
	document.images[button].src = 'images/' + button + '_h.gif';
}
function offlink(button){
	document.images[button].src = 'images/' + button + '.gif';
}
function displaydiv(divName){
	document.all[divName].style.visibility = 'visible';
}
function hidediv(divName){
	document.all[divName].style.visibility = 'hidden';
}
function FormElement(element){
	var name = prompt('Enter a name for this '+element+'.','');
	var value = prompt('Enter a default value for this '+element+'.','');
	document.input.formElements.selectedIndex = 0;
	setString('<INPUT TYPE="'+element+'" NAME="'+name+'" VALUE="'+value+'"> '+name+' ');
}
