// GLOBAL VARS
var nn4 = document.layers?1:0
var ie4 = (navigator.userAgent.toLowerCase().indexOf("msie 4") != -1)?1:0
formFieldHiliteColor = "#EEEED4"; //hilite colour for form elements
var dom = document.getElementById && !document.all;
var previous = "";
var eventObj;
var intended = /TEXT|TEXTAREA|OPTION/; // list of form elements that receive hilite

//This function opens the pop-up windows for the Help and Tour sections

function openHelp(ver)
{
	helpfile = open("/AdminHelp/Index.aspx?ver="+ver,"helpfile","left=0,top=0,width=763,height=540,scrollbars=0,status=1");
	helpfile.focus();
}

function openHelpReports()
{
	helpfile = open("../../adminhelp/index.html","helpfile","left=0,top=0,width=730,height=520,scrollbars=0,status=1");
	helpfile.focus();
}
function openTour()
{
	tour = window.open("admin_tour_p1.html","tour","left=0,top=0,width=763,height=540,scrollbars=0,status=0,resizable=1");
	tour.focus();
}

//function openDesc() {
//	popup = window.open("options_desc.html","window1","width=400,height=350,resize=1,status=1,scrollbars=1");
//	popup.focus();
//}

function winPopUp(url) {
	popup = window.open(url,"window1","width=400,height=350,resize=1,status=1,scrollbars=0");
	popup.focus();
}
function winPopUpLarge(url) {
	popup = window.open(url,"window1","width=580,height=450,status=1,scrollbars=1");
	popup.focus();
}
/***
TD HIGHLIGHTING
***/

// This function will highlight a table row or turn off Highlighting.
// Works for checkboxes that can be toggled checked/unchecked
function toggle(e, num)
{
	if (e.checked) {
	    hilite(e, true, num);	    
	}
	else {
	    hilite(e, false, num);
	}
}
// this is used IN Career Selector to highlight table rows
// the function will TURN OFF the lsast highlighted row
// when the next one is clicked
var lastHilite = null;
function toggle2(e, num)
{
	if (lastHilite != null) {
		hilite(lastHilite, false, num);
	}	
	hilite(e, true, num);
	lastHilite = e;
}

// do the TD highlighting
function hilite(e, lightup, swap)
{
	var r = null;
	
	// stop IE4 versions from executing this function
	// on Win and Mac
	if (navigator.userAgent.toLowerCase().indexOf("msie 4") != -1) {
		return;
	}
	
	if (e.parentNode && e.parentNode.parentNode) {
		r = e.parentNode.parentNode;
	}
	else if (e.parentElement && e.parentElement.parentElement) {
    	r = e.parentElement.parentElement;
	}
	
	// turn highlight on
	if (r && lightup) {  
		for (i=0; i<r.childNodes.length; i++) {
			if (r == e.parentNode.parentNode.parentNode.lastChild) {
				break;
			}	
			r.childNodes[i].className = "highlightBottomBorder";	
		}		
		r.className = "highlight" + swap;
	}
	
	// turn highlight off
	else if (r && !lightup) {
		for (i=0; i<r.childNodes.length; i++) {
			if (r == e.parentNode.parentNode.parentNode.lastChild) {
				break;
			}
			r.childNodes[i].className = "highlightBottomBorderWhite";	
		}
		r.className = "noHighlight";
	}
}


/**
*	Warren Davis Nov 29, 2005
*	FUNCTION toggleStyle(node, styleOne, styleTwo)
*	A basic system for toggling a style on a given node. The reference to the node is passed,
*	the className for the node is compared/set via a ternary...
*/
function toggleStyle(node, styleOne, styleTwo){	

	for(i=0; i<node.childNodes.length; i++){
		node.childNodes[i].className = (node.childNodes[i].className == styleOne || !node.childNodes[i].className) ? styleTwo : styleOne;			
	}

}

/**
*	Matthew Fabb April 17, 2006
*	A stripped down version of toggleStyle so that the style only turns to the "on" style and not off
*/
function turnOnStyle(node, style) {	
	for(i=0; i<node.childNodes.length; i++){
		node.childNodes[i].className = style;			
	}
}

/**
*	Warren Davis Nov 29, 2005
*	FUNCTION clearFormBox(node)
*	Small utility that clears a form field after a user event (eg. onclick)
*/
function clearFormField(node){
	// If the form field has been previously clicked, return
	if(node.runonce == "true"){
		return;
	}else{
	// else, set the value to "" and runonce (which is a custom attribute we created here) to 'true'
		node.value = "";
		node.runonce = "true";
	}
}



/****
FORM FIELD HIGHLIGHTING
***/
// check whether element clicked is a form element
function checkel(which)
{
	if (which.style && intended.test(which.tagName)) {
		if (dom && eventobj.nodeType==3) {
			eventobj = eventobj.parentNode.parentNode;
		}	
	return true;
	}
	else {
		return false;
	}	
}

// do form element hilighting
function hiliteForm(e) 
{
	eventobj = dom ? e.target : event.srcElement;
	
	if (previous != "") {
		if (checkel(previous)) {
			previous.style.backgroundColor = "";
		}	
		previous = eventobj;
		if (checkel(eventobj) && !eventobj.disabled) {
			eventobj.style.backgroundColor = formFieldHiliteColor;
		}	
	}
	
	else {
		if (checkel(eventobj) && !eventobj.disabled) {
			eventobj.style.backgroundColor = formFieldHiliteColor;
		}	
		previous = eventobj;
	}
}


// Disable trhe select box to choose an
// ending year for search.
function disableYear()
{
	var frm = document.forms[0];
	if (frm.endMonth.options[frm.endMonth.selectedIndex].value == "present") {
		frm.endYear.disabled = true;
	} 
	else {
		frm.endYear.disabled = false;
	}
}

/***
GENERAL FORM FUNCTIONS
***/
// return DOM reference
function obj(div)
{
	if (document.all && !document.getElementById) return document.all[div].style;
	else if (document.getElementById) return document.getElementById(div).style;
	else if (document.layers) return document.layers[div];
	else return;
}
// reset a form
function resetForm(name)
{
	document.forms[name].reset();	
}

//submit a form
function submitForm(name)
{
	document.forms[name].submit();
}

// toggle the CSS display property of an object
function toggleDisplay(div)
{
	if (document.layers) return;
	if ((obj(div).display == "none")||
	    (obj(div).display == ""))
	{
		obj(div).display = "block";
	}
	else
	{
		obj(div).display = "none";
	}
}

/************************************ 
turn on form element with text link 
*************************************/

function formElementOn(whichElem) 
{
	with(document.forms[0]) 
	{
		if (elements[whichElem].checked == false)
		{
			elements[whichElem].checked = true;
		}
		else
		{
			elements[whichElem].checked = false;
		}
	}	
}

// Uses the rollover functions in the HTML page and
// calls the imgOn or imgOff function depending on
// the curent rollover state of the img.
function imgSwap(img)
{
	if (document.layers)
	{
		window.open('cp_ep_popup.html','eduplan','left=0,top=0,width=510,height=500,scrollbars=1,status=1');
		return;
	}
	if (document.images)
	{
		if (document.images[img].src == eval(img + "on.src"))
		{
			imgOff(img);
		}
		else
		{
			imgOn(img);
		}
	}
}




/********
show an object
*********/
function show_obj(div) 
{
	obj(div).display = "block";
}


/********
hide an object
*********/
function hide_obj(div) 
{
	obj(div).display = "none";
}



/**************
FUNCTIONS FOR COLLAPSING SUB MENUS
ON THE LEFT SIDE OF PAGE FOR DOM ONLY BROWSERS
***************/
function subMenu(num, imgName)
{
	if (document.all && !document.getElementById) {
		dom = document.all["submenu"+num].style;
		if (num != 1) {
			document.all["submenu1"].style.display = "none";
			document.images["img26"].src = img26off.src;
		}
		if (num != 2) {
			document.all["submenu2"].style.display = "none";
			document.images["img16"].src = img16off.src;
		}
		if (num != 3) {
			document.all["submenu3"].style.display = "none";
			document.images["img27"].src = img27off.src;
		}
		if (num != 4) {
			document.all["submenu4"].style.display = "none";
			document.images["img17"].src = img17off.src;
		}
		if (num != 5) {
			document.all["submenu5"].style.display = "none";
			document.images["img18"].src = img18off.src;
		}
	} else {
		dom = document.getElementById("submenu"+num).style;
		if (num != 1) {
			document.getElementById("submenu1").style.display = "none";
			document.images["img26"].src = img26off.src;
		}
		if (num != 2) {
			document.getElementById("submenu2").style.display = "none";
			document.images["img16"].src = img16off.src;
		}
		if (num != 3) {
			document.getElementById("submenu3").style.display = "none";
			document.images["img27"].src = img27off.src;
		}
		if (num != 4) {
			document.getElementById("submenu4").style.display = "none";
			document.images["img17"].src = img17off.src;
		}
		if (num != 5) {
			document.getElementById("submenu5").style.display = "none";
			document.images["img18"].src = img18off.src;
		}
	}
	if (dom.display == "block") {
		dom.display = "none";
		document.images[imgName].src = eval(imgName + "off.src");
	} else {
		dom.display = "block";
		document.images[imgName].src = eval(imgName + "latch.src");
	}
}

function subMenuCheck(num)
{
	if (document.all && !document.getElementById)
	{
		dom = document.all["submenu"+num].style;
	}
	else
	{
		dom = document.getElementById("submenu"+num).style;
	}
	if (dom.display == "block") return true;
	else return false;
}



/**************
FUNCTIONS FOR POPUP SUB MENUS
ON THE LEFT SIDE OF PAGE FOR IE4, NN4
***************/
function subMenuV4(div, img)
{
	hideSubMenuV4();
	imgOn(img);
	if (document.layers)
	{
		document[div].visibility = "visible";
	}	
	else
	{
		document.all[div].style.visibility = "visible";
	}
	
}

function hideSubMenuV4()
{
	if (document.layers)
	{
		document.actAbilMenu.visibility = "hidden";
		document.careerPrepMenu.visibility = "hidden";
	}
	else
	{
		document.all['actAbilMenu'].style.visibility = "hidden";
		document.all['careerPrepMenu'].style.visibility = "hidden";
	}	
}



/************
Function to toggle the checkboxes
for the adm_homepage_assidn-advisor.html
************/
function assignGrade(all)
{
	var f = document.forms[0];
	if (all)
	{
		for (i=0; i < f.length; i++)
		{
			if (f.elements[i].name.indexOf("level") != -1)
			{
				f.elements[i].checked = false;
			}
		}
		f.gradeyes[0].checked = true
	}
	else
	{
		f.gradeyes[1].checked = true;
	}
}
function assignLetter(all)
{
	var f = document.forms[0];
	if (all)
	{
		for (i=0; i < f.length; i++)
		{
			if (f.elements[i].name.indexOf("let") != -1)
			{
				f.elements[i].checked = false;
			}
		}
		f.alphayes[0].checked = true
	}
	else
	{
		f.alphayes[1].checked = true;
	}
}



/************
Validate a textfield or password for ANY blank spaces
************/
function valBlankSpaces(frm, valEntry)
{
	var f = document.forms[frm];
	
	// check every textfield in the form for blank spaces
	if (valEntry == "all")
	{
		for (i=0; i < f.length; i++)
		{
			if ((f.elements[i].type == "text") || (f.elements[i].type == "text"))
			{
				if (!checkSplitLength(f.elements[i].value))
				{
					return true;
					break;
				}
			}
		}
		return false;
	}
	
	// check only one form field for blank spaces
	else
	{
		if (!checkSplitLength(f[valEntry].value))
		{
				return true;
		}
		return false;
	}
}
// Check to see if the textfield or password value
// has a length greater than 1. 
// If so, there are no spaces!
function checkSplitLength(val)
{
	var newString = 0;
	for (var i=0; i < val.length; i++) 
	{
        if (val.charAt(i) != " ")
		{
			newString += 1;
		}	
    }
	if (newString > 0) return true;
	else return false;
}


/***************
Legend popup layer control
see: cp_cm.html for example
***************/
function obj(div)
{
	if (document.all && !document.getElementById) return document.all[div].style;
	else if (document.getElementById) return document.getElementById(div).style;
	else if (document.layers) return document.layers[div];
	else return;
}
function showLyr(div)
{
	//alert(obj(div).visibility);
	obj(div).visibility = "visible";
}
function hideLyr(div)
{
	obj(div).visibility = "hidden";
}
function popupOn()
{
	obj("popup").filter  = "Alpha(Opacity=95,enabled=1)";
	showLyr("popup");
}
function quickNoteToggle(toggleOn)
{ 
	if(toggleOn)
	{
		showLyr("popup");	
	}
	else
	{
		hideLyr("popup");
	}
}

/*displays and hides the archieve popups
function toggleArchivePopup(toggleOn, formNum) { 
	//alert((formNum != null));
	/if (toggleOn) {
		if ((formNum != 0) && (formNum != null)) {
			hideForm(formNum);
		}
		showLyr("archivepopup");
	} else {
		if ((formNum != 0) && (formNum != null)) {
			showForm(formNum);
		}
		hideLyr("archivepopup");
	}
}*/



/****************************************************
Create a dynamic popup window via passed parameters
*****************************************************/
function openWizard(theURL, Name, popW, popH, scroll) { 
	var winleft = (screen.width - popW) / 2;
	var winUp = (screen.height - popH) / 2;
	if ((typeof scroll == 'string' && scroll.toLowerCase() == 'true') || scroll == true || scroll == '1') scroll = 1; else scroll = 0;
	winProp = 'width='+popW+',height='+popH+',left='+winleft+',top='+winUp+',scrollbars='+scroll+',resizable';
	Win = window.open(theURL, Name, winProp);

	if (parseInt(navigator.appVersion) >= 4) {
		Win.window.focus();
	}
}


/****************************************************
Toggles form checkboxes off based on parent/child
relationship (kinda like a tree)

parent: <input id="goalsAndPlans" type="checkbox" name="section8" value="Goals &amp; Plans" />
child:	<input type="checkbox" name="section262" value="Career &amp; Life Goals " group="goalsAndPlans" onclick="toggleTree(this);"/>

the id of the parent becomes the group name the children belong to.
*****************************************************/
function toggleTree(n){
	
	var node = n;
	var group;
	var ref;

	// get name of group (object)
	group = node.getAttribute('group');	

	// get name of current node
	child = node.getAttribute('value');	
	
	// is parent
	if(group == null){
	
		// reassign group to good value
		group = node.id;
	
		// if currently no object
		if(document[group] == null){
			// create a new global object with the name of the group (which is the 'id' of the parent)
			ref = document[group] = new Object();
			
			ref.group = group;

			// attach new array to hold names of children (the id's)
			ref.children = new Array();		
		}		
		
		// turn on all children of this group
		recurseNodes(document, group);		
		return; 		
		
	// is child, no object	
	}else if(document[group] == undefined){
		
		// create a new global object with the name of the group (which is the 'id' of the parent)
		ref = document[group] = new Object();		
		ref.group = group;

		// attach new array to hold names of children (the id's)
		ref.children = new Array();			
	}

	//
	addRemoveChildren(document[group], child, "");
}


function recurseNodes(a,b){

	// variables
	var node = a;
	var group = b;	
	var nodeList;
	var i;
	var checked;

	// if node has children
	if(node.hasChildNodes()){
		
		// get array of children
		nodeList = node.childNodes;
		
		for(i=0; i<nodeList.length; i++)
		{
			// if childnode is an 'element' node (ie. <html>/<input> or other tags)
			if(nodeList[i].nodeType == 1){
			
				// if childnode has group attribute we're looking for
				if(nodeList[i].getAttribute('group') == group){
					
					// if parent node (the group node parent id) is checked
					if(document.getElementById(group).checked == true){
						//alert("turn everything on");
						nodeList[i].checked = true;
						// add this child to object, if not already there
						// add/remove the child from the global object
						addRemoveChildren(document[group], nodeList[i].value, "add");						
					}else{
						nodeList[i].checked = false;
						// add/remove the child from the global object
						addRemoveChildren(document[group], nodeList[i].value, "remove");						
					}			
				}
			
				// keep recursing through tree
				recurseNodes(nodeList[i], group);
			}
		}
	}
}


function addRemoveChildren(a,b,o){

	// get reference to global object
	var ref = a;
	var child = b;
	var addRemove = o;
	var i;		
	var idx;
	
	for(i=0; i<ref.children.length; i++){ if(ref.children[i] == child){ idx = i; }}
	
	if(addRemove == "add"){
		if(idx == null){
			// child not on stack, so add
			ref.children.push(child);
		}
	}else if(addRemove == "remove"){
		if(idx != null){
			// if only 1 child on stack
			if(idx == ref.children.length-1){
				// take child off stack
				ref.children.pop();	
			}else{
				// take child off stack
				ref.children.splice(idx,1);	
			}
		}
	}else{
		if(idx == null){
			// child not on stack, so add
			ref.children.push(child);
		}else{
			// if only 1 child on stack
			if(idx == ref.children.length-1){
				// take child off stack
				ref.children.pop();	
			}else{
				// take child off stack
				ref.children.splice(idx,1);	
			}			
		}
		document.getElementById(ref.group).checked = (ref.children.length < 1) ? false : true;
	}
}

/**********************************************************
*	Warren, Dec 14, 2005
*	function confirmDelete(msg,urlA,urlB)
*	Generic confirmation javascript popup
*	@msg  : the message to show
*	@urlA : url to go to if 'confirmed'
*	@urlB : url to go to if 'canceled'
***********************************************************/
function confirmDelete(msg, urlA, urlB){
	choice = confirm(msg);
	
	if(choice){ window.location = urlA	; }
	else{ window.location = urlB; }
	
}

// Switching the radio button in a form based
function switchRadioBtn (checked, radioBtnName, btnArrayNum) {
	if (checked) {
		document.forms[0].elements[radioBtnName][btnArrayNum].checked = true;
	}
}

//unchecks the criteria checkboxes
function resetCriteriaBoxes (checked) {
	if (checked) {
		for(i=1; i <= 16; i++) {
			document.forms[0].elements["criteria" + i].checked = false;
			//alert(document.forms[0].elements["criteria" + i].checked);
		}	
	}
}

//checks all of the checkboxes in the page
function checkAllCheckboxes () {
	elmentsLength = document.forms[0].elements.length;
	for (i = 0; i < elmentsLength; i++) {
		if (document.forms[0].elements[i].type == "checkbox") {
			document.forms[0].elements[i].checked = true;
		}
	}
}

//unchecks all of the checkboxes in the page
function uncheckAllCheckboxes () {
	elmentsLength = document.forms[0].elements.length;
	for (i = 0; i < elmentsLength; i++) {
		if (document.forms[0].elements[i].type == "checkbox") {
			document.forms[0].elements[i].checked = false;
		}
	}
}

//turns the visibility of form elements to hidden
function hideForm (num) {
	//document.forms[0].elements.length;
	if ((num == "") || (num == null)) {
		elmentsLength = document.forms[0].elements.length;
	} else {
		elmentsLength = num;
	}
	for (i = 0; i < elmentsLength; i++) {
		document.forms[0].elements[i].style.visibility = "hidden";
	}
}

//turns the visibility of form elements to hidden
function showForm (num) {
	//document.forms[0].elements.length;
	if ((num == "") || (num == null)) {
		elmentsLength = document.forms[0].elements.length;
	} else {
		elmentsLength = num;
	}
	for (i = 0; i < elmentsLength; i++) {
		document.forms[0].elements[i].style.visibility = "visible";
	}
}

function setHighLights () {
    if (document.forms[0])
   {
	    currentForm = document.forms[0];
    	
	    elmentsLength = currentForm.elements.length;
	    for (j = 0; j < elmentsLength; j++) {
		    if (currentForm.elements[j].type == "checkbox") {
			    if (currentForm.elements[j].checked == true) {
				    turnOnStyle(currentForm.elements[j].parentNode.parentNode, 'rowColourBeige');
			    } else {
				    turnOnStyle(currentForm.elements[j].parentNode.parentNode, 'rowColourWhite');
			    }
		    }
	    }
	}
}

function toggleArchivePopup (div,iframe) {
	var state=false;

	var DivRef = document.getElementById(div);
	var IfrRef = document.getElementById(iframe);

	if (DivRef.style.display=="none") {
	    state=true;
	} else {
		state=false;
	}

	if (state) {
		DivRef.style.display = "block";
		IfrRef.style.width = DivRef.offsetWidth;
		IfrRef.style.height = DivRef.offsetHeight;
		IfrRef.style.top = DivRef.offsetTop; 
		IfrRef.style.left = DivRef.offsetLeft; 
		IfrRef.style.zIndex = DivRef.style.zIndex - 1;
		IfrRef.style.display = "block";
		IfrRef.style.backgroundColor = "black";
	} else {
		IfrRef.style.width = 0;
		IfrRef.style.height = 0;
		IfrRef.style.top = 0; 
		IfrRef.style.left = 0; 
		DivRef.style.display = "none";
		IfrRef.style.display = "none";
	}
}

// Checks to see if there's content in the text box value passed and if there is
// then the check box is checked off
function checkContentCheckBox (content, checkboxName) {
	if ((content != "") && (content != " ") && (content != "  ")) {
		document.forms[0][checkboxName].checked = true;
	} else {
		document.forms[0][checkboxName].checked = false;
	}
	setHighLights();
}


/*
* Matthew Fabb May 19, 2006
* Checks to see if the checkbox is checked and if so then displays the review revise layer
*/
function reviewRevisePopup() {
	if (document.forms[0].yesReviewRevise.checked == true) {
		showLyr("reviewReviseDiv");
	}
}

function showRRComment() {
		
}

/*
Matthew Fabb - August 8, 2006
JavaScript code used to snap div's to an img location
MM_findObj is needed to run the function properly
*/

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function P7_Snap() { //v2.63 by PVII
 var x,y,ox,bx,oy,p,tx,a,b,k,d,da,e,el,tw,q0,xx,yy,w1,pa='px',args=P7_Snap.arguments;a=parseInt(a);
 if(document.layers||window.opera){pa='';}for(k=0;k<(args.length);k+=4){
 if((g=MM_findObj(args[k]))!=null){if((el=MM_findObj(args[k+1]))!=null){
 a=parseInt(args[k+2]);b=parseInt(args[k+3]);x=0;y=0;ox=0;oy=0;p="";tx=1;
 da="document.all['"+args[k]+"']";if(document.getElementById){
 d="document.getElementsByName('"+args[k]+"')[0]";if(!eval(d)){
 d="document.getElementById('"+args[k]+"')";if(!eval(d)){d=da;}}
 }else if(document.all){d=da;}if(document.all||document.getElementById){while(tx==1){
 p+=".offsetParent";if(eval(d+p)){x+=parseInt(eval(d+p+".offsetLeft"));y+=parseInt(eval(d+p+".offsetTop"));
 }else{tx=0;}}ox=parseInt(g.offsetLeft);oy=parseInt(g.offsetTop);tw=x+ox+y+oy;
 if(tw==0||(navigator.appVersion.indexOf("MSIE 4")>-1&&navigator.appVersion.indexOf("Mac")>-1)){
  ox=0;oy=0;if(g.style.left){x=parseInt(g.style.left);y=parseInt(g.style.top);}else{
  w1=parseInt(el.style.width);bx=(a<0)?-5-w1:-10;a=(Math.abs(a)<1000)?0:a;b=(Math.abs(b)<1000)?0:b;
  x=document.body.scrollLeft+event.clientX+bx;y=document.body.scrollTop+event.clientY;}}
 }else if(document.layers){x=g.x;y=g.y;q0=document.layers,dd="";for(var s=0;s<q0.length;s++){
  dd='document.'+q0[s].name;if(eval(dd+'.document.'+args[k])){x+=eval(dd+'.left');y+=eval(dd+'.top');
  break;}}}e=(document.layers)?el:el.style;xx=parseInt(x+ox+a),yy=parseInt(y+oy+b);
 if(navigator.appVersion.indexOf("MSIE 5")>-1 && navigator.appVersion.indexOf("Mac")>-1){
  xx+=parseInt(document.body.leftMargin);yy+=parseInt(document.body.topMargin);}
 e.left=xx+pa;e.top=yy+pa;}}}
}

/*
* Matthew Fabb - August 10, 2006
* Built off of the toggleArchivePopup function and used to turn on the iFrame
* and use it to block form elements from appearing in front of divs
*/
function turnOnFormBlocker (div,iframe) {
	var DivRef = document.getElementById(div);
	var IfrRef = document.getElementById(iframe);

    if (IfrRef){
	    IfrRef.style.width = DivRef.offsetWidth;
	    IfrRef.style.height = DivRef.offsetHeight;
	    IfrRef.style.top = DivRef.offsetTop; 
	    IfrRef.style.left = DivRef.offsetLeft; 
	    IfrRef.style.zIndex = DivRef.style.zIndex - 1;
	    IfrRef.style.display = "block";
	    IfrRef.style.backgroundColor = "black";
	}else{
	    // object doesnt exist
	}
}

/*
* Matthew Fabb - August 10, 2006
* Built off of the toggleArchivePopup function and used to turn off the iFrame
* that is used to block form elements from appearing in front of divs
*/
function turnOffFormBlocker (iframe) {
	var IfrRef = document.getElementById(iframe);

    if (IfrRef){
	    IfrRef.style.width = 0;
	    IfrRef.style.height = 0;
	    IfrRef.style.top = 0; 
	    IfrRef.style.left = 0; 
	    IfrRef.style.display = "none";
	}else{
	    // object doesnt exist
	}	    
}


// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1980;
var maxYear=2007;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}