// JavaScript Document
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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 MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// Function OpenCalendar PlaceHolder
// OpenCalendar script is programmatically added in MasterPage

function SetDate(formName, id, newDate, postBack)
{
	eval('var theform = document.' + formName + ';');
	popUp.close();
	theform.elements[id].value = newDate;
	if (postBack)
		__doPostBack(id,'');
}

function openReportViewerWindow(QueryCriteria)
{
	var vResults;
	var ReportURL = OpenUrl(document.location.href,"/Report/ReportViewer.aspx");
	//alert(QueryCriteria);
	if (QueryCriteria != "") {
		window.status ="Wait...CCPS is preparing report.";
		ReportURL = ReportURL + "?" + QueryCriteria;
		//vResults = window.showModalDialog(ReportURL,"","center:yes;scroll:yes;dialogWidth:800px;dialogHeight:650px;status:no;menu:yes;");
		vResults = window.open(ReportURL,"","center:yes;scroll:yes;dialogWidth:800px;dialogHeight:650px;status:no;menu:yes;");
		window.status="Ready";
	}
}
function DisableEnterKey()
{
//alert(window.event.keyCode)
if (window.event.keyCode == 13)
window.event.keyCode =0;
} 
function formatDate() {
    var _ret = true;
    var key = window.event.keyCode;
    var len = window.event.srcElement.value.length;
    if (key <= 46 || key > 57 || key == 47 ) {
        window.event.keyCode = 0;
        _ret = false;
    }
    if (len >= 10) {
        window.event.keyCode = 0;
        _ret = false;
    }	
    if (len == 2 || len == 5) {
        window.event.srcElement.value += "/";
    }
    return _ret;
}
function formatTime() {
    var _ret = true;
    var key = window.event.keyCode;
    var len = window.event.srcElement.value.length;
    if (key <= 46 || key > 57 || key == 47 ) {
        window.event.keyCode = 0;
        _ret = false;
    }
    if (len >= 5) {
        window.event.keyCode = 0;
        _ret = false;
    }	
    if (len == 2) {
        window.event.srcElement.value += ":";
    }
    return _ret;
}
// this only allows 0-9
function onlyDigits(e) {
	var _ret = true;
	if (window.event.keyCode <= 46 || window.event.keyCode > 57) {
		window.event.keyCode = 0;
		_ret = false;
	}
	return (_ret); 
}

// this allows 0-9 and .
function onlyDollarDigits(e) { 
	var _ret = true;
	if (window.event.keyCode < 46 || window.event.keyCode > 57) {
		window.event.keyCode = 0;
		_ret = false;
	}
	return (_ret); 
}

// this allows 0-9 and ,
function onlyDigitsPlusComma(e) { 
	var _ret = true;
	if ((window.event.keyCode <= 43 || window.event.keyCode > 57 || window.event.keyCode == 45 || window.event.keyCode == 46)) {
		window.event.keyCode = 0;
		_ret = false;
	}
	return (_ret); 
}

function OpenUrl(path,filetoopen) {

DocURL=path;

//this is where the http or https will be, as found by searching for :// but skipping the res://

protocolIndex=DocURL.indexOf("://", 4);

//this finds the ending slash for the domain server

serverIndex=DocURL.indexOf("/", protocolIndex + 3);
appIndex = DocURL.indexOf("/", serverIndex + 3);
appLength = appIndex - serverIndex -1;

//for the href, we need a valid URL to the domain. We search for the # symbol to find the begining
//of the true URL, and add 1 to skip it - this is the BeginURL value. We use serverIndex as the end marker.
//urlresult=DocURL.substring(protocolIndex - 4,serverIndex);

BeginURL=DocURL.indexOf("#",1) + 1;
urlresult=DocURL.substring(BeginURL, serverIndex);
if (protocolIndex - BeginURL > 7)
urlresult=""

//for display, we need to skip after http://, and go to the next slash

displayresult=DocURL.substring(protocolIndex + 3, serverIndex);

if (DocURL.indexOf("ccps")>0) {
    appname = DocURL.substring(appIndex-appLength,appIndex);
    displayresult = displayresult +  '/' + appname;
}

var modifiedpath = 'http://'+displayresult+ filetoopen;
return modifiedpath;

//var obj_calwindow = window.open('http://'+displayresult+ filetoopen);

}

function CheckMaxLength(text,long) 
{
	var maxlength = new Number(long); // Change number to your max length.
	if (text.value.length > maxlength){
		text.value = text.value.substring(0,maxlength);
		alert(" Only " + long + " chars are allowed in this field");
	}
}

function sessionTimeout() {
    alert("Your session has been idle for 50 minutes and is about to expire.  If you don't perform an action immediately you will be logged out of the system.");
}


