/**********************************************
 LMCore.js
 Basic ActiveCampus JavaScript functions including
    imageswapper, popup, external site frame, and quicklinks
 Author:  M. Dempster 3//01
 Copyright:  LiquidMatrix Corp.
**********************************************/

/**********************************************
 Browser control variables  
 These variables determine which browser is being used
**********************************************/ 
var isNav = (document.layers) ? true:false				//Layers compliant browser (Netscape 4.x)
var isIE = (document.all) ? true:false				//IE4/5 compliant browser 
var isDOM = (document.getElementById) ? true:false	   	//DOM Compliant browser (NS6, Opera 5)
var isOther = (!isNav&&!isDOM&&!isIE) ? true:false				//Other browser (NS3, Lynx)


/**********************************************
 jumpto(formobj, stringexp)
 form:  
 	use:  Required
	Datatype:  JS Form Obj
	A valid reference to a form object on the page.
 name:  
 	use:  Required
	Datatype:  String
	A valid reference to a select control.    
 Return:  Nothing
 Description:   Takes the value of the selected item in selector name, and forwards browser to that value.  
 				During the forward process, it resets the selector to default (index=0)
 Tips:  Normally, form is passed this.form, which is a generic reference to the form enclosing name
**********************************************/ 
function jumpto(form, name) {
	var myindex= eval('form.'+ name + '.selectedIndex');			//Gets index of user selection in Stringexp
    var myval=eval('form.' + name + '.options[myindex].value');		//Gets value at myindex
    eval('form.'+ name + '.selectedIndex = 0');						//Resets selected index to 0 (default)
	if (myval != "") {
        
	     location.href=myval;									//If value is local, send this window to new page.
       
    }
}


/**********************************************
 popup(stringexp, stringexp, integer, integer, stringexp, stringexp, )
 Note:  All vars are type STring and are required
 URL:  Valid URL of a webpage (determines page to be shown in new window)
 Name: String (determines name of new window)
 wwidth: Integer (determines width of new window)
 wheight: Integer (determined height of new window)
 wresize: 0 or 1 (determines if window can be resized or not)
 wscrolls:  yes or no (determines if scrollbars will be created on window)
 Return:  Nothing
 Description:   Pops open new window with parameters specified above.
**********************************************/ 
function popup(url, name, wwidth, wheight, wresize, wscrolls){
    eval("window.open('" + url + "','" + name + "','toolbar=no,menubar=no,address=no,status=no,dependent=no,resizable=" + wresize + ",scrollbars=" + wscrolls + ",height=" + wheight + ",width=" + wwidth + "')");
}


/**********************************************
 external(stringexp)
 url:  
 	use:  Required
	Datatype: String
	A valid reference to a web site address   
 Return:  Nothing
 Description:   Takes the value of URL, and creates a new window containing the External site frame, which displays the address specified
**********************************************/ 
function external(url){
    eval("window.open('/external.asp?URL=" + escape(url) + "','ACEXT','toolbar=yes,menubar=yes,address=yes,status=yes,dependent=no,resizable=1,height=540,width=760')");
}


/**********************************************
 - jump(e)
 - init()
Description:   
	These 2 functions allow autojumping between "multitextbox" fields with defined lengths, such as SSN, phone, zip, etc
	This works with a hidden variable in the form named "autojumpsets" that has sets of comma-separated pairs that represent the IDs of the fields you want
	to jump between, and all pairs delimited by a "!"
	ex: <input name="autojumpsets" value="SSN3,SSN2!SSN2,SSN4!Zip,Zip_p4" />
**********************************************/ 
function jump(e) {
	if (!e) var e = window.event;
	arrLink = document.getElementById('autojumpsets').value.split("!"); 
	for (var i=0;i<arrLink.length;i++)
	{
		fields = arrLink[i].split(","); 
		if (fields[0] == this.id) {
			if (this.value.length == this.maxLength && e.keyCode != 9 && e.keyCode != 16) {
				document.getElementById(fields[1]).focus();
			}
		}
	}
}
function init() {
	if (document.getElementById('autojumpsets')) {
		arrLink = document.getElementById('autojumpsets').value.split("!"); 
		for (var i=0;i<arrLink.length;i++)
		{
			fields = arrLink[i].split(","); 
			document.getElementById(fields[0]).onkeyup = jump;
		}
	}
}
window.onload = init;



/*************************
TODO LIST FUINCTIONS
***************************/
function openList() {
	setElementVisibility('todoOpen', 'visible');
	if (navigator.appVersion.indexOf('Mac') != -1) {
		top.todoList.bodyheight();
	} 
}
function createReference(Element) {
	if (isDOM && !isIE) {
		oRef = eval("document.getElementById('" + Element + "').style")
	} else if (isNav) {
		oRef = eval("document.layers['" + Element + "']")
	} else {
		oRef = eval("document.all." + Element + ".style")
	}
	return oRef
}

function setElementVisibility(Element, state) {
	oElement = createReference(Element)
	if (state.toLowerCase() == 'visible'){
		document.getElementById(Element).className = 'displayOnPage';
	}
	oElement.visibility = state.toLowerCase(); 
}


function getElementVisibility(Element, state) {
	oElement = createReference(Element)
	elementVis = oElement.visibility;
	return elementVis
}

function adjustIFrameSize (iframeWindow) {
  if (iframeWindow.document.height) {
	var iframeElement = parent.document.getElementById(iframeWindow.name);
	iframeElement.style.height = (iframeWindow.document.height) + 'px';
	iframeElement.style.width = iframeWindow.document.width + 'px';
  }
  else if (document.all) {
	var iframeElement = parent.document.all[iframeWindow.name];
	if (iframeWindow.document.compatMode &&  iframeWindow.document.compatMode != 'BackCompat') 
	{
	  iframeElement.style.height = iframeWindow.document.documentElement.scrollHeight + 'px';
	  iframeElement.style.width = iframeWindow.document.documentElement.scrollWidth + 'px';
	}
	else {
	  iframeElement.style.height = iframeWindow.document.body.scrollHeight +  'px';
	  iframeElement.style.width = iframeWindow.document.body.scrollWidth + 'px';
	}
  }
}

function bodyheight () {
			x = document.body.offsetHeight
			parent.document.getElementById("todoList").style.height = x + 'px'
}

function setup() {
	if (navigator.appVersion.indexOf('Mac') == -1) {
		if (parent.adjustIFrameSize) parent.adjustIFrameSize(window);
	}
}
function setElementClass() {
    for (var i=0; i<setElementClass.arguments.length; i+=2) {
		if (top.isIE) { 
			eval('document.all.' + setElementClass.arguments[i] + '.className = "' + setElementClass.arguments[i+1] + '"'); 
		} else if (top.isDOM) {
			eval('document.getElementById(\'' + setElementClass.arguments[i] + '\').className = "' + setElementClass.arguments[i+1] + '"'); 
		}
	}
}

