// start csjs
var ns4 = (document.layers); 
var ie4 = (document.all && !document.getElementById);
var ie5 = (document.all && document.getElementById);
var ns6 = (!document.all && document.getElementById);

function testConnection(){
	alert("test connection called")
}

function attach(id){
  var obj
   if(ns4) obj = document.layers[id];
   else if(ie4) obj = document.all[id];
     else if(ie5 || ns6) obj = document.getElementById(id);
   return obj
}

function hide_obj(id){
  temp_Obj = attach(id);
  if(NS4) temp_Obj.visibility = "hide";
  else temp_Obj.style.visibility = "hidden"
}

function show_obj(id){
  temp_Obj = attach(id);
  if(ns4) temp_Obj.visibility = "show";
  else temp_Obj.style.visibility = "visible"
}

function switch_vis_obj(id){
	temp_Obj = document.getElementById(id);

  if( temp_Obj.style.visibility == "visible"){
		temp_Obj.style.visibility = "hidden"
		temp_Obj.style.display="none"
	} else {
		  temp_Obj.style.visibility = "visible"
		temp_Obj.style.display=""
	}
}

var IFrameObj; // our IFrame object

function callToServer(theFormName, URL) {
	if (!document.createElement) {return true};
	var IFrameDoc;
	var responseMessage = document.getElementById('responseMessage');
	responseMessage.style.display = 'inline';
	responseMessage.innerHTML = '<font face="Arial, Helvetica, sans-serif" size="2" color="#FF0000">loading data...</font>';
	
	if (!IFrameObj && document.createElement) {
		var tempIFrame=document.createElement('iframe');
		tempIFrame.setAttribute('id','RSIFrame');
		tempIFrame.style.border='0px';
		tempIFrame.style.width='1px';
		tempIFrame.style.height='1px';
		IFrameObj = document.body.appendChild(tempIFrame);
	
		if (document.frames) {
			IFrameObj = document.frames['RSIFrame'];
		}
	}
	
	if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj.contentDocument) {
		setTimeout('callToServer("'+theFormName+'")',10);
		return false;
	}
	
	if (IFrameObj.contentDocument) {
		// For NS6
		IFrameDoc = IFrameObj.contentDocument; 
	} else if (IFrameObj.contentWindow) {
		// For IE5.5 and IE6
		IFrameDoc = IFrameObj.contentWindow.document;
	} else if (IFrameObj.document) {
		// For IE5
		IFrameDoc = IFrameObj.document;
	} else {
		return true;
	}
	
	IFrameDoc.location.replace(URL);
	return false;
}


function handleResponse(retVal) {
	resultArray = document.frames['RSIFrame'].arr
	units = document.getElementById('units')
	units.options.length = 1;	
	for(jjj=0;jjj < resultArray.length; jjj++){
		tOption = unescape(resultArray[jjj])
		tOptionArray = tOption.split("|")
		newOption = new Option(tOptionArray[0],tOptionArray[1])
		
		units.options[units.length] = newOption	 
	}

	var responseMessage = document.getElementById('responseMessage');
	responseMessage.innerHTML = '<font face="Arial, Helvetica, sans-serif" size="2" color="#009900">records loaded...';
}


// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
	if(value > 0){
		  var curCookie = name + "=" + escape(value) +
		      ((expires) ? "; expires=" + expires.toGMTString() : "") +
		      ((path) ? "; path=" + path : "") +
		      ((domain) ? "; domain=" + domain : "") +
		      ((secure) ? "; secure" : "");
		  document.cookie = curCookie;
	} else {
		deleteCookie(name)
	}
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}


function redirect(){

}

function sectorJumpMenu(targ,selObj,restore){
	SectorId = selObj.options[selObj.selectedIndex].value
	if(SectorId != "none"){
		 eval("parent.location='index.aspx?page=sectorOverview&sectorId="+SectorId+"'");
	}
}

function careerJumpMenu(targ,selObj,restore, aSectorId){
	OccupationId = selObj.options[selObj.selectedIndex].value
	if(OccupationId != "none"){
		 eval("parent.location='index.aspx?page=occupationView&sectorId=" + aSectorId + "&OccupationId=" + OccupationId + "'");
	}
}

function careerFlash(OccupationId,aSectorId){
	tURL = "index.aspx?page=occupationView&sectorId=" + aSectorId + "&OccupationId=" + OccupationId
	tWinName = "CareerWindow"
	tWinProperties = "menubar=false,width=516,height=550,scrollbars"
	newWindow = window.open(tURL, tWinName, tWinProperties)
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function ValidateFormConfirmPassword(form) {
	
	var requiredFields
	var tValidatedOK = true
	var tMessage = "The following field(s) are required:\n"
	aRequiredFields = form.fldRequiredFields.value
	requiredFields = aRequiredFields.split(",")
	
	for(i in requiredFields){
		tItem = requiredFields[i].split("|")
		tValue = eval("form." + tItem[0] + " .value")
		if (tValue == ""){
			tMessage += "          " + tItem[1] + "\n"
			tValidatedOK = false
		}
	}
	if(tValidatedOK == false){
		alert(tMessage)
	} else {
		if(form.fldUserPassword.value == form.fldUsersPasswordConfirm.value){
			form.submit()
		} else {
			alert("Your Password and Password Confirm do not match.\nPlease re-enter")
		}
	}
	
	
}

function ValidateForm(form) {
	
	var requiredFields
	var tValidatedOK = true
	var tMessage = "The following field(s) are required:\n"
	aRequiredFields = form.fldRequiredFields.value
	requiredFields = aRequiredFields.split(",")
	
	for(i in requiredFields){
		tItem = requiredFields[i].split("|")
		tValue = eval("form." + tItem[0] + " .value")
		if (tValue == ""){
			tMessage += "          " + tItem[1] + "\n"
			tValidatedOK = false
		}
	}
	if(tValidatedOK == false){
		alert(tMessage)
	} else {
		form.submit()
	}
}

function valueTypeOf(aValue){
	tMod = aValue % 1
	if(isNaN(tMod)){
		return "NaN"
	} else { 
		if (tMod == "0"){
			return "Integer"
		} else {
			return "Float"
		}
	}
}

function isInteger(aObj, aErrMsg){
	if(valueTypeOf(aObj.value) == "Integer"){
		return true
	} else {
		alert(aErrMsg)
		return false
	}
}


function isPositiveInteger(aObj, aErrMsg){
	if(valueTypeOf(aObj.value) == "Integer"){
		return true
	} else {
		alert(aErrMsg)
		return false
	}
}

function isFloat(aObj, aErrMsg){
	if(valueTypeOf(aObj.value) == "Float"){
		return true
	} else {
		alert(aErrMsg)
		return false
	}
}

function MM_validateForm() { //v3.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (val!=''+num) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+'\n'; }
  } if (errors) alert('The following information is required:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

var NS6 = (navigator.vendor == ("Netscape6") || navigator.product == ("Gecko"));
var menuTimer = null;
var menuTimerDelay = 2250;


function switchMenus(aWhichMenu){
	clearMenus()
	MM_showHideLayers(aWhichMenu,'','show')
}

function clearMenus(){
	for(var i = 0; i < arrSubMenus.length; i++){
		MM_showHideLayers(arrSubMenus[i],'','hide')
	}
}

function startMenuTimer(){
	if( menuTimer != null ){
		clearTimeout(menuTimer);
	}
	menuTimer = setTimeout("clearMenus()", menuTimerDelay );
}

function getHand(){
	return NS6 ? 'pointer' : 'hand'
}

function getArrow(){
	return NS6 ? 'arrow' : 'arrow'
}

///NS4
function switchMenusNS4(aWhichMenu){
	
}

function clearMenusNS4(){

}

function startMenuTimerNS4(){
	
}


function clearFields(aFields){
	// this funcion is specific to the RTQ survey
	arFields = aFields.split(",")
	
	for(i=1; i < arFields.length; i++){
		tStr = "document.form1." + arFields[i]
		tItem = eval(tStr)
		
		tType=(arFields[i].substr(0,1))
		
		if(tType == "t"){//Training Numbers
			tItem.value = ""	
		}
		
		if(tType == "p"){//Priority Radio Buttons
			tItem[0].checked = false
			tItem[1].checked = false
			tItem[2].checked = false
		}
	}
}

function isPositiveTrainingInteger(aObj, aErrMsg){
	if(valueTypeOf(aObj.value) == "Integer"){
		return true
	} else {
		alert(aErrMsg)
		return false
	}
}

function setFav(UnitId, checked){
	var cookieInfo = document.cookie.split("; ");
	var fav = new Array()
	
	for (counter=0; counter<cookieInfo.length; counter++)
	{
		tCookieName = cookieInfo[counter].split("=")[0]
		
		if(tCookieName == "fav"){
			favCookie = new String(cookieInfo[counter].split("=")[1])
			if(favCookie != "undefined"){
				arrItems = favCookie.split(",")
				for(zzz = 0;  zzz < arrItems.length; zzz++){
					fav[fav.length] = arrItems[zzz]
				}
			}
		}
	}
	if(checked == true){
		var tFound = false
		for(i=0;i < fav.length;i++){
			if(fav[i]== UnitId){
				tFound = true
			}
		}
		if(tFound == false){
			fav[fav.length] = UnitId
		}
	} else {
		var tFound = false
		var tPos = 0
		for(i=0;i < fav.length;i++){
			if(fav[i]== UnitId){
				tFound = true
				tPos = i
			}
		}
		if(tFound == true){
			partA = fav.slice(0,tPos)
			partB = fav.slice(tPos + 1)
			fav = partA.concat(partB);
			
		}
	}
	
	document.cookie = "fav=" + fav.toString() +"; "
	
	
}

// end csjs
