var which_mode = "simple";


function show_expert() {
	which_mode = "complex";
	expert_mode.style.display = '';
	simple_mode.style.display = 'none';
	document.addContent.expert_content.value = bpitEditor.document.body.innerHTML;
}

function show_simple() {
	which_mode = "simple";
	expert_mode.style.display = 'none';
	simple_mode.style.display = '';
	bpitEditor.document.body.innerHTML = document.addContent.expert_content.value;
}

function send_page() {
	if (document.addContent.name.value == "") {
	alert("You must enter a name for the page before submitting.");
	} else {
	//set_x();
	document.addContent.submit();
	}
}

function send_question() {
	if (document.addContent.name.value == "") {
	alert("You must enter a name for the page before submitting.");
	} else {
		//if (document.addContent.answer1.value=="") {
		//alert("You must enter at least one answer for the question.");
		//} else {
			document.addContent.submit();
		//}
	}
}

function send_page_OO() {
document.addContent.submit();
}

function set_x() {
	var x = bpitEditor.document.body.innerHTML;
	var y = document.addContent.expert_content.value;
	if (which_mode == "simple") {
	document.addContent.content.value = x;
	} else {
	document.addContent.content.value = y;
	}
}

function button_over(doitButton)
        {
        doitButton.style.backgroundColor = "#CCCCCC";
        doitButton.style.borderColor = "#FFFFFF #666666 #666666 #FFFFFF";
        }
function button_out(doitButton)
        {
        doitButton.style.backgroundColor = "CCCCCC";
        doitButton.style.borderColor = "#CCCCCC";
        }
function button_down(doitButton)
        {
        doitButton.style.backgroundColor = "#CCCCCC";
        doitButton.style.borderColor = "#666666 #FFFFFF #FFFFFF #666666";
        }
function button_up(doitButton)
    {
    doitButton.style.backgroundColor = "#CCCCCC";
        doitButton.style.borderColor = "#CCCCCC";
    }

function doit(it) {
	  var tr = frames.bpitEditor.document.selection.createRange()
	  tr.execCommand(it)
	  tr.select()
	  frames.bpitEditor.focus()
           }
		   
function del_mod(which) {
	if (confirm("Are you sure you want to delete this Module? If you have lessons and pages attached to this module, they will be lost.")) {
		location="st_structure.asp?code=delete&theID=" + which;
	}
}

function del_lesson(which) {
	if (confirm("Are you sure you want to delete this Lesson? If you have pages attached to this lesson, they will be lost.")) {
		location="st_structure.asp?code=delete&theID=" + which;
	}
}

function del_page(which) {
	if (confirm("Are you sure you want to delete this Page?")) {
		location="st_content.asp?code=delete&theID=" + which;
	}
}

function open_menu_window(myLoc) {
		myWin= open(myLoc, "Menu" ,"width=500,height=500,location=no,status=no,toolbar=no,menubar=no,scrollbars=yes");
		myWin.focus();	
}

function open_search_window(myLoc) {
		myWin= open(myLoc, "Menu" ,"width=800,height=600,location=yes,status=yes,toolbar=yes,menubar=yes,resize=true,scrollbars=yes");
		myWin.focus();	
}

function openContent(myLoc) {
		cwWin= open(myLoc, "courseware" ,"width=775,height=525,location=no,status=no,toolbar=no,menubar=no,scrollbars=no");
		cwWin.focus();	
}

function openContent_full(myLoc) {
		cwWin= open(myLoc, "courseware" ,"width=775,height=525,location=no,status=no,toolbar=no,menubar=no,scrollbars=no,fullscreen=yes");
		cwWin.focus();	
}

function popStats (name, start, end) {
	//myWin= open("", "Stats" ,"width=400,height=200,status=no,toolbar=no,menubar=no,scrollbars=no");
	//myWin.document.writeln('<html><head></head><body><table align=center width=90% border=0 class="text"><tr><td><strong>' + name + '</strong></td></tr><tr><td>Started: ' + start + '</td></tr><tr><td>Completed: ' + end + '</td></tr></body></html>');
	//myWin.focus();
	//alert (name + "\nStarted: " + start + "\nCompleted: " + end);

}

function popInfo (where) {
	myWin= open(where, "Info" ,"width=600,height=500,status=no,toolbar=no,menubar=no,scrollbars=yes");
	myWin.focus();
	
}

function launch_ilt_pres(loc) {
		myWin= open(loc, "Presentation" ,"width=775,height=525,location=no,status=no,toolbar=no,menubar=no,scrollbars=no");
		myWin.focus();	
}

function launch_ilt_pres_ss(loc) {
		myWin= open(loc, "Presentation" ,"width=775,height=525,location=no,status=no,toolbar=no,menubar=no,scrollbars=no");
		myWin.focus();	
}

function launch_ilt_pres_ss_menu(loc) {
		myWin= open(loc, "Presentation" ,"width=1000,height=525,location=no,status=no,toolbar=no,menubar=no,scrollbars=no");
		myWin.focus();	
}

function launch_ilt_pres_ss_menu_l(loc) {
		myWin= open(loc, "Presentation" ,"width=1215,height=725,location=no,status=no,toolbar=no,menubar=no,scrollbars=no");
		myWin.focus();	
}

function launch_ilt_pres_l(loc) {
		myWin= open(loc, "Presentation" ,"width=990,height=725,location=no,status=no,toolbar=no,menubar=no,scrollbars=auto");
		myWin.focus();	
}
function launch_ilt_pres_ss_l(loc) {
		myWin= open(loc, "Presentation" ,"width=1240,height=725,location=no,status=no,toolbar=no,menubar=no,scrollbars=auto");
		myWin.focus();	
}

function launch_pda(loc) {
		myWin= open(loc, "Presentation" ,"width=240,height=320,location=no,status=no,toolbar=no,menubar=no,scrollbars=yes");
		myWin.focus();	
}

function previewPage(which) {
		myWin= open("st_preview_page.asp?theID=" + which, "Preview" ,"width=775,height=575,location=no,status=yes,toolbar=no,menubar=no,scrollbars=no");
		myWin.focus();
}

function previewPageLarge(which) {
		myWin= open("st_preview_page.asp?theID=" + which, "Preview" ,"width=990,height=730,location=no,status=yes,toolbar=no,menubar=no,scrollbars=no");
		myWin.focus();
}

function showImage(where) {
		myWin= open(where, "Preview" ,"width=500,height=500,location=no,status=no,toolbar=no,menubar=no,scrollbars=auto");
		myWin.focus();	
}

function deleteUser(which) {
	if (confirm("Are you sure you want to delete this user account?")) {
		location = "st_edit_user_admin.asp?code=go&theUser=" + which;
	}
}

function deleteDev(which) {
	if (confirm("Are you sure you want to delete this developer account?")) {
		location = "st_edit_dev_admin.asp?code=go&theUser=" + which;
	}
}

function popTypes() {
		myWin= open("popTypes.html", "Types" ,"width=500,height=350,location=no,status=no,toolbar=no,menubar=no,scrollbars=auto");
		myWin.focus();
}

function deleteCourse(which) {
	if (confirm("Are you SURE you wish to delete this course. The entire contents of this course\nwill be LOST including all pages, lessons and images!")) {
		if (confirm("Are you really sure?")) {
			location="st_main.asp?code=delete&deleteID=" + which;
		}
	}
}

function confirmDeleteImage(where) {
	if (confirm("Are you sure you want to remove this image?")) {
	location = where;
	}

}

function viewComment(theID) {
		myWin= open("st_viewComment.asp?page_id=" + theID, "comments" ,"width=600,height=500,location=no,status=yes,toolbar=no,menubar=no,scrollbars=auto");
		myWin.focus();
}

function closeComment(which, pageID) {
	if (confirm("Are you sure you want to remove this comment?")) {
	location = "st_viewComment.asp?code=delete&deleteID=" + which + "&page_id=" + pageID;
	}
}

function popCrit() {
		myWin= open("popCrit.html", "Types" ,"width=500,height=350,location=no,status=no,toolbar=no,menubar=no,scrollbars=auto");
		myWin.focus();
}

function deleteCrit(which) {
	if (confirm("Are you sure you want to delete this Criteria? You will\nlose the criteria option and all data associated with it.")) {
	location = "st_criteria.asp?code=delete&deleteID=" + which;
	}
}

function popContent(what) {
		myWin= open("st_showContent.asp?theID=" + what, "Content_Preview" ,"width=600,height=500,location=no,status=yes,toolbar=no,menubar=no,scrollbars=auto");
		myWin.focus();
}

function pickType() {
//check for converting from existing free
var qs = new Querystring();
var convertID = qs.get("convertID")
//convertID = 17;
	if(document.signup.accType[0].checked) {
		if (convertID != null) {
			alert("You can not extend your free ten day trial. You must sign up for a payed account.");
		} else {
			location="signup3.asp?free=1";
		}
	} else {
	document.signup.convertID.value=convertID;
	document.signup.submit();
	}
}

function Querystring(qs) { // optionally pass a querystring to parse
	this.params = new Object()
	this.get=Querystring_get
	
	if (qs == null)
		qs=location.search.substring(1,location.search.length)

	if (qs.length == 0) return

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ')
	var args = qs.split('&') // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=')
		var name = unescape(pair[0])

		if (pair.length == 2)
			value = unescape(pair[1])
		else
			value = name
		
		this.params[name] = value
	}
}

function Querystring_get(key, default_) {
	// This silly looking line changes UNDEFINED to NULL
	if (default_ == null) default_ = null;
	
	var value=this.params[key]
	if (value==null) value=default_;
	
	return value
}

function pasteContent(what) {
addContent.narrText.value=what;
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
   
function clearNameField() {
//alert("doing it");
if (document.addContent.name.value == "New Page Name") {
document.addContent.name.value = "";
}
}

function switchRole() {
	//alert(roleSelect.roles.value);
	if (roleSelect.roles.value == 'learner') {
		parent.location = 'st_del.html';
	}
	if (roleSelect.roles.value == 'instructor') {
		parent.location = 'st_ins.html';
	}
	if (roleSelect.roles.value == 'manager') {
		parent.location = 'st_man.html';
	}
	if (roleSelect.roles.value == 'reporter') {
		parent.location = 'st_rep.html';
	}
	if (roleSelect.roles.value == 'developer') {
		parent.location = 'st_dev.html';
	}
	if (roleSelect.roles.value == 'contentadmin') {
		parent.location = 'st_cont.html';
	}
	if (roleSelect.roles.value == 'admin') {
		parent.location = 'st_admin.html';
	}
}

function Set_Cookie( name, value, expires, path, domain, secure ) 
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct 
expires time, the current script below will set 
it for x number of days, to make it for hours, 
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

 function roll(obj, highlightcolor)
 {
  obj.style.backgroundColor = highlightcolor;
 }