

// IE Compatiable dectection for ActiveEdit Tag
function checkBrowser() {
	if (navigator.appName == "Netscape") {
		var message = "The Active Edit software used to format Program Notes and Biographies requires a Internet Explorer Browser.\n\nClick CANCEL if you have Internet Explorer installed on your computer\n\nClick OK to go to Microsoft's website to download a copy";
		var return_value = confirm(message);	
   		if ( return_value == true ) {
			window.location="http://www.microsoft.com/windows/ie/downloads/recommended/ie55sp2/default.asp?FinishURL=%2Fdownloads%2Frelease%2Easp%3FReleaseID%3D31770%26area%3Dsearch%26ordinal%3D2%26redirect%3Dno";       
   		}	   			
	}
}

// print preview and word count functions //

function DelHTML(HTMLWord) {
	a = HTMLWord.indexOf("<");
	b = HTMLWord.indexOf(">");	
	HTMLlen = HTMLWord.length;	
	c = HTMLWord.substring(0, a);	
	if(b == -1)
	b = a;	
	d = HTMLWord.substring((b + 1), HTMLlen);	
	Word = c + d;	
	tmp = Word.indexOf("<");	
	if(tmp != -1)
	Word = DelHTML(Word);	
	return Word;
}

function wordCount(Type) {	
	if (aeObjects.Body.DOM.body.innerHTML == "") {
		alert('Word Count:  0');
	} else {
		ToCheck = aeObjects.Body.DOM.body.innerHTML;	
		Checked = DelHTML(ToCheck);
		
		var formcontent = aeObjects.Body.DOM.body.innerHTML;
		Checked=Checked.split(" ");
		alert('Word Count:  ' + Checked.length);
	}	
}


function printThis(Type) {		
	// Biography Print		
	if (Type == "Bio") {		
		// define new wind param
		newWindow = window.open('', 'newWin', 'width=1, height=1');
		
		// build out new window
		newWindow.document.open();
		newWindow.document.write("<html><head><\/head><body><br><br><br><br><b>" + document.Form.bioName.value + "</b><br>Author: <i>" + document.Form.bioAuthor.value + "</i><p>" + aeObjects.Body.DOM.body.innerHTML + "<\/body><\/html>");
		newWindow.document.close();				
	}
	// Program Note print
	if (Type == "PN") {		
		// define new wind param
		newWindow = window.open('', 'newWin', 'width=1, height=1');
		
		// build out new window
		newWindow.document.open();
		newWindow.document.write("<html><head><\/head><body><br><br><br><br><b>" + document.Form.pnComposer.value + "</b><br><u>" + document.Form.pnPiece.value + "</u><br><i>" + document.Form.pnPieceCom.value + "</i><p>" + aeObjects.Body.DOM.body.innerHTML + "<\/body><\/html>");
		newWindow.document.close();				
	}	
	// print out window
		if (window.print){
	  			newWindow.print();
		} else {
			alert('Please upgrade your browser to use this feature');
		}
		newWindow = newWindow.close();		
}



function preview(previewType) {	
	// Biography Preview
	if (previewType == "Bio") {		
		// define new wind param
		newWindow = window.open('', 'newWin', 'scrollbars=yes, resizable=yes, width=500, height=400');
		
		// build out new window
		newWindow.document.write("<html><head><title>Preview<\/title><\/head><body><b>" + document.Form.bioName.value + "</b><br>Author: <i>" + document.Form.bioAuthor.value + "</i><p>" + aeObjects.Body.DOM.body.innerHTML + "<\/body><\/html>");
	}		
	// Program Notes Preview
	if (previewType == "PN") {		
		// define new wind param
		newWindow = window.open('', 'newWin', 'scrollbars=yes, resizable=yes, width=500, height=400');
		
		// build out new window
		newWindow.document.write("<html><head><\/head><body><br><b>" + document.Form.pnComposer.value + "</b><br><u>" + document.Form.pnPiece.value + "</u><br><i>" + document.Form.pnPieceCom.value + "</i><p>" + aeObjects.Body.DOM.body.innerHTML + "<\/body><\/html>");
	}		
}

function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}


// memo field
function viewMemo(memo) {
	// if the memo field is undefined, assign value
	if (document.Form.Memo.value == "") {
		// sub carrigae return \n for holder we place as we queried for memo info
		document.Form.Memo.value = memo;	
		document.Form.Memo.value = replace(document.Form.Memo.value,'::cr::','\n');	
	}
	
	var memoWindow = window.open('knowledgebase/kbMemo.cfm', 'memoWindow', 'scrollbars=no, resizable=yes, width=350, height=290, left=25, top=25');
}

/// validation shite //////
function bioValid() {	
	if (document.Form.bioName.value=="") {
			document.Form.bioName.focus();
    		alert('Please provide a subject name for the Biography');
       		return false; 
	}
	if (document.Form.bioAuthor.value=="") {
			document.Form.bioAuthor.focus();
    		alert('Please provide a Author for the Biography');
       		return false; 
	}	
	
	return true;
}
	
/// verify delete
function DeleteChecked(type)	{
		// program notes
		if ( type == 1){
	    	var message = "Delete checked Program Notes?";
		}
		// bios
		if ( type == 2){
	    	var message = "Delete checked Biographies?";
		}		
		// cal value of user choice		
	    	var return_value = confirm(message);	    
    		if ( return_value == true ) {
				return true;       
    		}
   			else {
      			return false;
     		}
	}


