function GetHelp() {
  var GetHelpWindow = window.open('Help/Help_Frames.asp','Instructions','height=500,width=600,resizable');
  GetHelpWindow.focus();
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MoveActivityUp(aid,xid,yid,ysiid) {
  var vp = "XEGY_AdminAccept.asp?a=mu&el=a&id="+aid+"&id2="+xid+"&id3="+yid+"&id4="+ysiid;
  window.location.href = vp;
}

function MoveActivityDown(aid,xid,yid,ysiid) {
  var vp = "XEGY_AdminAccept.asp?a=md&el=a&id="+aid+"&id2="+xid+"&id3="+yid+"&id4="+ysiid;
  window.location.href = vp;
}

function GetDate(el)
{
	window.dateField = document.forms[0][el];
	calendar = window.open('XEGY_DatePicker.html','DatePicker','width=200,height=250,left=150,top=275')
}

function EncodeQString(qStr)
{
	return escape(qStr);
}

function DecodeQString(qStr)
{
	return unescape(qStr);
}

function GetFile(url,wheight,wwidth,wtop,wleft,woptions,aid) {

  var wincoords = ",left="+wleft+",screenX="+wleft+",top="+wtop+",screenY="+wtop+",";
  if(url.substr(0,8) == '/Library'){
	  var EditorWindow = window.open(EncodeQString(url),'ViewFile'+aid,'height='+wheight+',width='+wwidth+wincoords+woptions);
  }else{
	  var EditorWindow = window.open(url,'ViewFile'+aid,'height='+wheight+',width='+wwidth+wincoords+woptions);
  }
  EditorWindow.focus();
}

function Trim(TRIM_VALUE) {
		
	if (TRIM_VALUE.length < 1) return "";
	
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	
	if (TRIM_VALUE=="") {
		return "";
	} else {
		return TRIM_VALUE;
	}
}

function RTrim(VALUE) {

	var w_space = String.fromCharCode(32);
	var strTemp = "";
	var v_length = VALUE.length;
	var iTemp = v_length -1;
	
	if (v_length < 0) return "";
			
	while (iTemp > -1) {
		if (!(VALUE.charAt(iTemp) == w_space)) {
			strTemp = VALUE.substring(0, iTemp +1);
			break;
		}
		iTemp = iTemp-1;
	}
	
	return strTemp;
}

function LTrim(VALUE) {

	var w_space = String.fromCharCode(32);
	var strTemp = "";
	var iTemp = 0;
	var v_length = VALUE.length;
	
	if (v_length < 1) return "";
	
	while(iTemp < v_length) {
		if(!(VALUE.charAt(iTemp) == w_space)) {
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	}
	return strTemp;
}

function isInteger(vlu) {

	var tmp_vlu, i, vlen;
	
	tmp_vlu = Trim(vlu);
	if (tmp_vlu.length < 1) {
		return false;
	} else {
		vlen = tmp_vlu.length;
	}
	
	//	Leading "-" is okay
	
	if (tmp_vlu.charAt(0) == "-") {
		tmp_vlu = tmp_vlu.substring(1);
	} 
	
	for (var i = 0; i < tmp_vlu.length; i++) {
		if (!(isDigit(tmp_vlu.charAt(i)))) {
			return false;
		}
	}
	
	return true;
}
		
function isDigit(aChar) {

	myCharCode = aChar.charCodeAt(0);
   
	if((myCharCode > 47) && (myCharCode <  58)) {
		return true;
	}
   
	return false;
}	

function adjustIFrameSize (iframeWindow) {
  if (iframeWindow.document.height) {
    var iframeElement = document.getElementById(iframeWindow.name);
    iframeElement.style.height = iframeWindow.document.height + 'px';
    iframeElement.style.width = iframeWindow.document.width + 'px';
  }
  else if (document.all) {
    var iframeElement = document.all[iframeWindow.name];
    if (iframeWindow.document.compatMode && iframeWindow.document.compatMode != 'BackCompat')
    {
      iframeElement.style.height = iframeWindow.document.documentElement.scrollHeight + 5 + 'px';
      iframeElement.style.width = iframeWindow.document.documentElement.scrollWidth + 5 + 'px';
    }
    else {
      iframeElement.style.height = iframeWindow.document.body.scrollHeight + 60 + 'px';
      iframeElement.style.width = iframeWindow.document.body.scrollWidth + 5 + 'px';
    }
  }
}

function fitWindow() {
	if (document.body.scrollWidth){
		iWidth = document.body.scrollWidth;
		iHeight = document.body.scrollHeight;
	}else{
		//iWidth = document.body.clientWidth;
		//iHeight = document.body.clientHeight;
		iWidth = window.innerWidth;
		iHeight = window.innerHeight;
	}
	//alert(iWidth + ',' + iHeight);
	window.resizeTo(iWidth + 35, iHeight + 35);
}

function ShowActivity(url,wheight,wwidth,wtop,wleft,woptions,aid) {
	if (wtop == "" || wtop == undefined){wtop = 100;}
	if (wleft == "" || wleft == undefined){wleft = 100;}
	var wincoords = ",left="+wleft+",screenX="+wleft+",top="+wtop+",screenY="+wtop+",";
	if (wheight == "" || wheight == undefined){wheight = 600;}
	if (wwidth == "" || wwidth == undefined){wwidth = 800;}
	if (woptions == "" || woptions == undefined){woptions = 'scrollbars,resizable,menubar';}
	if (aid == "" || aid == undefined){aid = '';}
	var ActivityWindow = window.open(url,'Activity'+aid,'height='+wheight+',width='+wwidth+wincoords+woptions);
	ActivityWindow.focus();
}

function PreRequisite(mand,aid,st) {
  if (mand) {
	alert('This activity has a prequisite that is not yet completed.');  
  }
  else {
	if (confirm('This activity has a prequisite that is not yet completed. Do you still want to complete this activity')) {
	  window.location.href = "XEGY_AdminAccept.asp?a=e&el=trst&id="+aid+"&id3="+st;	
	}
  }
}

function PreRequisiteExt(mand,aid,st,pvt,prereqs) 
{
  if (mand) 
  {
	if (pvt == 0) //any
	{
		alert('This activity has prequisite(s).\r\nAt least one of these activities must be completed. \r\n \r\n' + prereqs + '\r\n \r\n');  
	}
	else
	{
		alert('This activity has prequisite(s).\r\nAll of these activities must be completed. \r\n \r\n' + prereqs + '\r\n \r\n');  
	}
  }
  else 
  {
	if (confirm('This activity has prequisite(s).\r\n Do you still want to complete this activity? \r\n \r\n' + prereqs + '\r\n \r\n')) 
	{
	  window.location.href = "XEGY_AdminAccept.asp?a=e&el=trst&id="+aid+"&id3="+st;	
	}
  }
}
