function assignToPageJS() {
	//Get the selected value entered by the user
	var selectedValue = document.forms[0].assignToPage.value;
	//var selectedValue = document.forms[0].assignToPage.options[document.forms[0].assignToPage.selectedIndex].value;
	
	//split the section and page apart
	var splitValue = selectedValue.split('/');
	
	//Section and Page
	var section = splitValue[0];
	var page = splitValue[1];
	
	//Get the total number of assignments made already, used to define which class
	var totalNumberOfAssignments = parseInt(document.forms[0].numOfPages.value);
	
	//Determine which class to use
	var classNumber = (totalNumberOfAssignments % 2) + 1;
	
	//Append this new assignment to them
	var x = document.getElementById('newPageAssignments').insertRow(1);
	var w = x.insertCell(0);
	var y = x.insertCell(1);
	var z = x.insertCell(2);
	x.id = parseInt(totalNumberOfAssignments+1);
	x.className = "row"+classNumber;
	w.innerHTML = section;
	w.className = "rowL";
	y.innerHTML = page;
	z.className = "rowR";
	z.style.textAlign = "center";
	z.innerHTML = '<a href="javascript:;" onClick="deleteRow(this);"><img src="../../graphx/icon_delete.gif" alt="Delete" border="0"></a>';
	
	//Update the total number of pages assigned
	document.forms[0].numOfPages.value = totalNumberOfAssignments+1;
	
	//Update the hidden form elements
	var formElement = "newAssignmentRow_"+ parseInt(totalNumberOfAssignments+1);
	eval("document.forms[0]."+ formElement +".value = '"+section+"/"+page+"'");
}

//Delete a selected assigned to row
function deleteRow(row) {
	var i=row.parentNode.parentNode.rowIndex;
	document.getElementById('newPageAssignments').deleteRow(i);
	
	//Get the total number of assignments made already, used to define which class
	var totalNumberOfAssignments = parseInt(document.forms[0].numOfPages.value);
	
	//Update the total number of pages assigned
	//document.forms[0].numOfPages.value = totalNumberOfAssignments-1; //Hoy 2/25 Leave number the same, so as not to overwrite old data
	
	//Delete the hidden input field
	var formElement = "newAssignmentRow_"+i;
	eval("document.forms[0]."+ formElement +".value = ''");
}

//Changes teh status of a click on row item, by update two hidden input fields in form and submit form
function changeStatus(id,status) {
	var newStatus = '';
	
	//Change the status
	if(status == 'Active') {
		newStatus = 'Inactive';
	} else {
		newStatus = 'Active';
	}
	
	//Update the form elements
	document.forms[0].id.value = id;
	document.forms[0].status.value = newStatus;
	
	//Submit the form
	document.forms[0].submit();

}

//Load up the preview Page
function loadPreviewPage(elementList) {
	
	var previewWindow = window.open('../preview.php','previewWindow','location=1,status=1,scrollbars=1,width=640,height=400')

	document.forms[0].target="previewWindow";
	document.forms[0].elementList = elementList;
	document.forms[0].action = "../preview.php";
	
}

//Make sure the action and target of form is set to self
function submitForm() {
	document.forms[0].target="_self";
	document.forms[0].action = "";
}

//Make sure the action and target of form is set to self
function submitFormNoValid() {
	document.forms[0].target="_self";
	document.forms[0].action = "";
	document.forms[0].onsubmit = "";
}

//Limit the number of characters that can be added to an element
function limitChars(total,element) {
	var elementValue = element.value;
	if(elementValue.length > total) {
		element.value = elementValue.substr(0,total);
		alert('The character limit of '+total+' has been reached!');
	}
}

function requireState(element,formNum) {
	var country = element.value;
	var stateElement = document.forms[formNum].state;
	if((country == 'USA') || (country == 'Canada')) {
		stateElement.title = 'State';
		changeStateRow('');
	} else {
		stateElement.title = '';
		changeStateRow('none');

	}
}

function changeStateRow(display) {
	var Rows = document.getElementsByTagName('tr');
	for(var i=0; i < Rows.length; i++) {
		if(Rows[i].id=='stateRow') {
			Rows[i].style.display = display;
		}
	}
}

//Validate Form
function validateForm(aform) {
	var user_level;
	var el = aform.elements;
	var errorMsg = '';
	var specialCaseImplantablesErr = '';
	
	if(aform.name == 'register') {
		specialCaseImplantablesErr = "Applications Interested In\n";
	}
	
	for(var i = 0 ; i < el.length ; ++i) {
		//alert(el[i].type);
		if(el[i].type == 'checkbox') {
			if(el[i].checked == false && el[i].title.length > 0) {
				errorMsg += el[i].title + '\n';
			} else if(el[i].checked == true && ((el[i].id == 'implantable') || (el[i].id == 'nonimplantable'))) { //Special Cases
				specialCaseImplantablesErr = '';
			}
		} else if (el[i].type == 'select-one') {
			if(el[i].selectedIndex == 0 && el[i].title.length > 0) {
				errorMsg += el[i].title + '\n';
			}
		} else if (el[i].name == 'calloutContent') { //FCK Editor
			var FCKString = FCKeditorAPI.GetInstance('calloutContent').GetXHTML();
			if(FCKString.length == 0) { 
				errorMsg += el[i].title + '\n';
			}
		} else {
			if(el[i].value.length == 0 && el[i].title.length > 0) {
				errorMsg += el[i].title + '\n';
			}
		}
	}
	
	//Special Case for Implantables
	errorMsg += specialCaseImplantablesErr;
	
	if(errorMsg.length > 0) {
		errorMsg = 'Please complete all required fields below:\n'+errorMsg;
		alert(errorMsg);
		return false;
	} else {
		return true;
	}
	
	return false;
}

//Reset from elemnets, used onClick on filters
function resetValues(list) {
	
	//split the list apart
	var splitValue = list.split(',');
	
	//loop through the array and set all values to null
	for(var i = 0 ; i < splitValue.length ; ++i) {
		eval("document.forms[0]."+splitValue[i]+".value=''");
	}
}

//Display the Modal
function displayModal(divId) {

	closeOtherModals(divId);
	
	window.scrollTo(0,0);
	document.getElementById('body').style.overflow = 'hidden';
	document.getElementById('greyBox').style.display = '';
	eval("document.getElementById('"+divId+"').style.display = ''");
}

//Close the Modal
function closeModal(divId) {
	document.getElementById('body').style.overflow = 'auto';
	document.getElementById('greyBox').style.display = "none";
	eval("document.getElementById('"+divId+"').style.display = 'none'");
}

//Close any other open modals
function closeOtherModals(divId) {
	if(divId == 'register') {
		document.getElementById('login').style.display = "none";
	}
}

//Update the style of a given modal
function updateStyle(divID,styleElement,styleValue) {
	eval("document.getElementById('"+divID+"').style."+styleElement+" = '"+styleValue+"'");
}

//Validate the email colleague form
function checkInvite(TheForm) {
    var errors = '';
	if(TheForm.first_name.value.length == 0) {
		errors = "- First Name\n";
    }
	if(TheForm.last_name.value.length == 0) {
		errors += "- Last Name\n";
    }
	if(TheForm.email.value.length == 0) {
		errors += "- Email\n";
    }
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(TheForm.email.value)) {
		
	} else {
		errors += "- A properly formatted email address\n";
	}
	if(TheForm.comments.value.length == 0) {
		errors += "- Comments\n";
    }
	if(TheForm.first_name1.value.length == 0) {
		errors += "- Colleague's First Name\n";
    }
	if(TheForm.last_name1.value.length == 0) {
		errors += "- Colleague's Last Name\n";
    }
	if(TheForm.email1.value.length == 0) {
		errors += "- Colleague's Email\n";
    }
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(TheForm.email1.value)) {
		
	} else {
		errors += "- A properly formatted colleague's email address\n";
	}
	if(errors != '') {
		alert('The form needs some corrections before it can be submitted.\n' + errors);
		return false;
	} 
return true;
}

function convertLoginToModal() {
	updateStyle('loginContainer','border','0px');
	updateStyle('loginContainer','margin','0px');
	updateStyle('loginContainer','backgroundColor','#ffffff');
}