var enterBtn;

function checkEnter(e){
  keyCode = (e)? e.which: event.keyCode;
  
  if(keyCode==13&&enterBtn){
	document.getElementById(enterBtn).focus();
  }
}

function setEnter(btn) {
	enterBtn = btn;	
	document.onkeypress = checkEnter;
	//checkEnter(event);
}

function setEnterKey(btn) {
	enterBtn = btn;
	document.onkeypress = checkEnter;
}

function timerWarning() {
	window.setTimeout("alert('Your user session is about to expire in 2 minutes.  If you wish to continue being logged into the KePRO South Secure Area, please make a page request immediately.');", (28 * 60 * 1000));
	window.setTimeout("alert('Your user session has expired! You will be redirected back to the login screen.');", (30 * 60 * 1000));
	// showTimeout((30 * 60));
}

function showTimeout(x) {
	window.status = 'Login session will expire in ' + x + ' secs.';
	x--;
	timeleft = window.setTimeout("showTimeout(" + x + ")", 1000);	
}

function loading(o) {
	o.innerHTML += "<br /><span class='ErrorMessage'>Loading report, please wait...</span>";	
}

function complete(value,d) {
    var cell;

	if (d) {		
		cell = window.opener.opener.document.getElementById(getQueryValue("id"));
	} else {		
		cell = window.opener.document.getElementById(getQueryValue("id"));
	}

	if (cell) {
		cell.innerText = value;
	} else {
		alert('Could not find cell.');
	}
	
	window.close();
}

function mov(span) {
	span.className = "clhover";
}
function mou(span) {
	span.className = "cl";
}

function IsNumeric(strString) {
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++) {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1) blnResult = false;
   }

   return blnResult;
}

function AddFixItStatus(caseid, cell) {
	var img = new Image();
	img.src = "/sArea/images/xpRecentDoc.gif";

	if (cell.innerHTML.indexOf(img.src)<=0) cell.innerHTML += "<img alt='Access the status of Fix-Its and Error Notices for this case.' onclick=\"window.open('responder.aspx?t=fixit&f=status&c=" + caseid + "', 'Responder', 'width=485,height=360')\" onmouseover=\"this.style.cursor='hand'\" src=\"" + img.src + "\">";
}

function getQueryValue(a) {
	q = location.search;

	getParam = function(arg) {
		var st = q.indexOf('?' + arg);
		if (st==-1) st = q.indexOf('&' + arg);
		
		if (st >= 0) {
			var pntr = st + arg.length+2;
			if (q.indexOf("&", pntr) >= 0) {
				return q.substring(pntr, q.indexOf("&", pntr));
			} else {
				return q.substring(pntr, q.length);
			}
			return null;
		}
	}

	return getParam(a);
}

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;
	}
} //End Function

function RTrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0) return "";
	var iTemp = v_length -1;

	while(iTemp > -1){
		if(VALUE.charAt(iTemp) == w_space){
		}else{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;
	} //End While

	return strTemp;
} //End Function

function LTrim(VALUE){
	var w_space = String.fromCharCode(32);
	if(v_length < 1) return "";
	var v_length = VALUE.length;
	var strTemp = "";
	var iTemp = 0;

	while(iTemp < v_length){
		if(VALUE.charAt(iTemp) == w_space){
		}else{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	} //End While

	return strTemp;
} //End Function