document.oncontextmenu = contextMenu;
document.onmousemove   = fixStatus;
window.defaultStatus   = "FIDREC Online";

function contextMenu() { return true; }
function fixStatus() { window.status = window.defaultStatus; }

function trim(str) {
	var re = new RegExp("^[ \t]+|[ \t]+$", "g");
	return str.replace(re,"")
}

function chkInt( x, msg ) {
  y = x.value;
  if( y.length == 0 || y*1 != y ) { alert("Please input a integer for '" + msg + "' field"); }
  return ( y.length > 0 && y*1 == y  );
}

function chkFloat( x, msg ) {
  y = x.value;
  dot = 0;
  for( i = 0; i < y.length && (y.charAt(i) >= '0' && y.charAt(i) <= '9' || y.charAt(i) == '.'); i++, dot+=(y.charAt(i) == '.') );
  if( i < y.length || y.length == 0 || dot > 1 ) { alert("Please input a valid decimal number for '" + msg + "' field"); }
  return ( i == y.length && y.length > 0 && dot < 2 );
}

function sST( x, y ) {
  b = ( top.location.href.indexOf("display.htm") == -1 )
  parent.f_subtitle.subTitle.innerHTML = ((!b)? '<a target=f_content href="logout.asp?FL=0" title="Logout from eUBM"><img src="img/Logout.gif" align=absmiddle border=0></a><a target=f_content href="today.asp" title="Back to eUBM Today"><img src="img/Back.gif" align=absmiddle border=0></a> ' : '&nbsp;') + x;
  parent.f_subtitle.imgTitle.src = "icon/" + ((y)? y : "none") + ".gif";
}

function setCookie(sName, sValue) {
  document.cookie = sName + "=" + escape(sValue) + ";";
}

function getCookie(sName) {
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) return unescape(aCrumb[1]);
  }
  return null;
}

function shwHide( x, d ) {
  if( d.style.display == "none" ) {
    x.src = "../img/s_up.gif"; x.title = "Shink"; d.style.display = "";
  } else {
    x.src = "../img/s_down.gif"; x.title = "Expand"; d.style.display = "none";
  }
}
cL = null; cellValue = null;

function hL( x, n ) {
  if( x != cL ) if( n ) x.style.background='fdf4e0'; else x.style.background='';
}

function sP( x, n ) {
  if( cL ) cL.style.background='';
  cL = x; cL.style.background='ffcc88';
  cellValue = n;
}
function TargetTo0(url) {
	parent.frames(0).location.href = url + '?cellValue='+form1.Bank.value
}
function TargetTo(url) {
	parent.frames(1).location.href = url + '?cellValue='+cellValue
}


var m_chk = false
function checkAll(field)
{
	if(field == null) return;

	if(field.length) {
		for (i = 0; i < field.length; i++) {
			field[i].checked = !m_chk
		}
	}
	else {
		field.checked = !m_chk
	}
	
	m_chk = !m_chk
}

function GoOpenList(url,aName) {
	window.open (url,aName,'menubar=no,scrollbars=yes,status=no,width=400,height=200,resizable=yes')
}

function GoOpenList(url,aName,width,height) {
	window.open (url,aName,'menubar=no,scrollbars=yes,status=no,width=' + width + ',height=' + height + ',resizable=yes')
}

function GoOpenList(url,aName,width,height,menubar) {
	var LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
	var TopPosition = (screen.height) ? (screen.height-height)/10 : 0;
	window.open (url,aName,'top=' + TopPosition + ',left=' + LeftPosition + ',menubar=' + menubar + ',scrollbars=yes,status=no,width=' + width + ',height=' + height + ',resizable=yes')
}

function LimitPaste(fieldObj,maxChars){
  var diff = maxChars - fieldObj.value.length;
  if (diff < 0)
    fieldObj.value = fieldObj.value.substring(0,maxChars);
}

function LimitText(fieldObj,maxChars){
  var result = true;
  if (fieldObj.value.length >= maxChars)
    result = false;
  if (window.event)
    window.event.returnValue = result;
  return result;
}


function doSubmit(url) {
	document.forms[0].action=url
	document.forms[0].submit()
}
function doRefreshList(url) {
	
	parent.list.document.forms[0].action=url
	parent.list.document.forms[0].submit()
}
function doRefreshList2(url) {
	parent.parent.list.document.forms[0].action=url
	parent.parent.list.document.forms[0].submit()
}
function doRefreshDetail(url) {
	parent.detail.document.forms[0].action=url
	parent.detail.document.forms[0].submit()
}

function compareDte(dte_a,dte_b) {
	var hh,mm,arr
	arr = dte_a.split("/")
	DteA = new Date(arr[2],arr[1],arr[0])
	
	arr = dte_b.split("/")
	DteB = new Date(arr[2],arr[1],arr[0])
	
	if (DteA >= DteB)
		return false
	else
		return true
}



function verifyAllCheckBoxes() {
	var onecheck = false
	cellValue = '';
	if (form1.chkboxes.value) {
		if (form1.chkboxes.checked) {
			cellValue = form1.chkboxes.value;
			return true;
		}
		else {
			alert('Please Select the Checkbox')
			return false;
		}
	}
	for (var i=0;i<form1.chkboxes.length;i++) {
				if (form1.chkboxes(i).checked) {
					if (cellValue=='') 
						cellValue = form1.chkboxes(i).value
					else
						cellValue = cellValue + ',' + form1.chkboxes(i).value
					
					onecheck = true
				}
	} 
	if (!onecheck) {alert('Please Select At Least ONE checkbox');}
	return onecheck;
}

function verifyAllCheckBox() {
	var onecheck = false
	cellValue = '';
	if (form1.chkbox.value) {
		if (form1.chkbox.checked) {
			cellValue = form1.chkbox.value;
			return true;
		}
		else {
			alert('Please Select the Checkbox')
			return false;
		}
	}
	for (var i=0;i<form1.chkbox.length;i++) {
				if (form1.chkbox(i).checked) {
					if (cellValue=='') 
						cellValue = form1.chkbox(i).value
					else
						cellValue = cellValue + ',' + form1.chkbox(i).value
					
					onecheck = true
				}
	} 
	if (!onecheck) {alert('Please Select At Least ONE checkbox');}
	return onecheck;
}

var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function isAlphanumeric(value){
	var re = /^[a-zA-Z0-9]+$/ ;
	return re.test(value);
}

function isEmail(s) {
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	return filter.test(s)
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : dd/mm/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function isDate(dtStr,field){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert('The date format should be : dd/mm/yyyy in "' + field + '"')
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert('Please enter a valid month in "' + field + '"')
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert('Please enter a valid day in "' + field + '"')
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert('Please enter a valid 4 digit year between '+minYear+' and '+maxYear + 'in "' + field + '"')
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert('Please enter a valid date in "' + field + '"')
		return false
	}
return true
}

function ValidateForm(){
	var dt=document.frmSample.txtDate
	if (isDate(dt.value)==false){
		dt.focus()
		return false
	}
    return true
 }
 
 function pausecomp(Amount) {
 d = new Date() //today's date
 while(1) {
	mill=new Date() // Date Now
	diff = mill-d //difference in milliseconds
	if( diff > Amount ) 
	{break;}
 }
 }
 
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;}
checkflag = "true";
//return "Uncheck All"; 
}
else {
for (i = 0; i < field.length; i++) {
field[i].checked = false; }
checkflag = "false";
//return "Check All"; 
}
}

/*
function roundTo(num, decPlaces) {
	var d = 10 * decPlaces
	return Math.round(num * d)/d
}
*/

function roundTo (num, decplaces) {
	num = parseFloat(num);
	if (!isNaN(num)) {
		var str = "" + Math.round (eval(num) * Math.pow(10,decplaces));
		if (str.indexOf("e") != -1) {
			return "Out of Range";
		}
		while (str.length <= decplaces) {
			str = "0" + str;
		}
		var decpoint = str.length - decplaces;
		return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
	} else {
		return "NaN";
	}
}


// validates that the entry is a positive or negative number
function isNumber(value, msg) {
    var str = value;
    var oneDecimal = false;
    var oneChar = 0;
    // make sure value hasn't cast to a number data type
    str = str.toString();
    
    if(str == "") {
		if(msg) alert("Please enter a valid decimal number for '" + msg + "' field");
		return false
	}
    for (var i = 0; i < str.length; i++) {
        oneChar = str.charAt(i).charCodeAt(0);
        // OK for minus sign as first character
        if (oneChar == 45) {
            if (i == 0) {
                continue;
            } else {
				if(msg) alert("Please input a valid decimal number for '" + msg + "' field");
                return false;
            }
        }
        // OK for one decimal point
        if (oneChar == 46) {
            if (!oneDecimal) {
                oneDecimal = true;
                continue;
            } else {
	            if(msg) alert("Please input a valid decimal number for '" + msg + "' field");
                return false;
            }
        }
        // characters outside of 0 through 9 not OK
        if (oneChar < 48 || oneChar > 57) {
		   if(msg) alert("Please input a valid decimal number for '" + msg + "' field");
            return false;
        }
    }
    return true;
}

function actionInfo() {
	alert("To add a new item to the list, go to 'Manage Dropdown List'");
}


/********************
* For css tab menu
*********************/
var selObj;
function selTab(obj) {
	if(selObj)
		selObj.className = ""

	obj.className = "onthis"
	selObj = obj
}

var selTblObj;
function selTable(tableId) {
	if(selTblObj)
		selTblObj.style.visibility = "hidden"
	
	var tbl = document.getElementById(tableId);
	if(tbl) {
		tbl.style.visibility = "visible"
		selTblObj = tbl
	}
}





/******************************************************
Form field Limiter script- By Dynamic Drive
For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
This credit MUST stay intact for use
*******************************************************/

var ns6=document.getElementById&&!document.all

function restrictinput(maxlength,e,placeholder){
	if (window.event&&event.srcElement.value.length>=maxlength)
		return false
	else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
	var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
	if (pressedkey.test(String.fromCharCode(e.which)))
		e.stopPropagation()
	}
}

function countlimit(maxlength,e,placeholder){
	var theform=eval(placeholder)
	var lengthleft=maxlength-theform.value.length
	var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
	if (window.event||e.target&&e.target==eval(placeholder)){
		if (lengthleft<0)
			theform.value=theform.value.substring(0,maxlength)
		placeholderobj.innerHTML=lengthleft
	}
}

function displaylimit(theform,thelimit){
	var limit_text='<b><span id="'+theform.toString()+'">'+thelimit+'</span></b> '
	if (document.all||ns6)
		document.write(limit_text)
	if (document.all){
		eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
		eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
	}
	else if (ns6){
		document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true); 
		document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true); 
	}
}

function accessDenied() {
	alert("This action is not allowed as you do not have the access rights.")
}