var totalSeconds=0;
var curPopupWindow = null;

function showTime(){
	var d=new Date();
	var h=d.getHours().toString();
	var m=d.getMinutes().toString();
	var s=d.getSeconds();
	var semi;
	var msg='';

	totalSeconds+=1

	if((s/2)==Math.round(s/2)){
		semi='<FONT COLOR="#ffffff">:</FONT>';
		if(totalSeconds>840)msg='<BR><FONT COLOR=red>Your session will expire in&nbsp;'+(900-totalSeconds)+'&nbsp;seconds!</FONT>';
	}else{
		semi='<FONT COLOR="#52657B">:</FONT>';
		if(totalSeconds>840)msg='<BR>Your session will expire in&nbsp;'+(900-totalSeconds)+'&nbsp;seconds!';
	};

	if(totalSeconds>899)location.href='LOG.asp?act=out'

	if(h.length<2)h='0'+h;
	if(m.length<2)m='0'+m;
	document.getElementById('ct').innerHTML='&nbsp;'+h+semi+m+msg;
	window.setTimeout('showTime()', 1000);
}

function handleCheck(c,h){
	if(c.checked){h.value='on'}else{h.value=''};
}
//******************************
// Email validation
//******************************
function testemail(src) {
	var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
	return regex.test(src);
}

//******************************
// Trim
//******************************
function LTrim(str)
{
	var i = 0;
	var j = str.length - 1;

	if (str == null)
		return ('');

	for (i = 0; i < str.length; i++)
	{
		if (str.substr(i, 1) != ' ' &&
		    str.substr(i, 1) != '\t')
			break;
	}

	if (i <= j)
		return (str.substr(i, (j + 1) - i));
	else
		return ('');
}

function RTrim(str)
{
	var i = 0;
	var j = str.length - 1;

	if (str == null)
		return ('');

	for(j = str.length - 1; j >= 0; j--)
	{
		if (str.substr(j, 1) != ' ' &&
			str.substr(j, 1) != '\t')
		break;
	}

	if (i <= j)
		return (str.substr(i, (j + 1) - i));
	else
		return ('');
}

function Trim(str) {
	if (str == null)
		return ('');
	return RTrim(LTrim(str));
}

//******************************
// Date validation
//******************************
var dtCh= "/";

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;
    }
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var 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){
    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)
	if (strYr.charAt(0) == "0" && strYr.length > 3) strYr = strYr.substring(1)

	month = parseInt(strMonth)
	day = parseInt(strDay)
	year = parseInt(strYr)

	if (pos1 == -1 || pos2 == -1){
		alert("Date format should be: dd/mm/yyyy.")
		return false
	}
	if (strMonth.length < 1 || month < 1 || month > 12){
		alert("Please enter valid month.")
		return false
	}
	if (strDay.length < 1 || day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter valid day.")
		return false
	}
	if (strYear.length != 4 || year == 0){
		alert("Please enter 4 digit year.")
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1) != -1 || isInteger(stripCharsInBag(dtStr, dtCh)) == false){
		alert("Please enter valid date.")
		return false
	}
return true
}

function confirmDelete(msg, page) {
	if(confirm(msg)){location.href=page};
}

function showDate() {
	var d = new Date();
	var s='';

	d=d.toLocaleString();
	for(var i=0;i<d.length;i++)
	{
		if(d.substr(i,1)==' '){s=s+'&nbsp;'}else{s=s+d.substr(i,1)};
	}
	document.write(s+'&nbsp;&nbsp;');
}

// Dialog boxes
function setReturnValueEx(flds,vals){
	closePopup();
	var fld1;
	for(var i=0;i<flds.length;i++){
		fld1=document.getElementById(flds[i]);
		if(fld1){fld1.value=vals[i];}
	}
}

function getT(field, currTime) {
	var url = 'dlg/GT.asp';
	var features='width=200,height=200,dependent=no,resizable=no,toolbar=no,status=no,directories=no,menubar=no,scrollbars=0,center=yes';
	
	closePopup();

	curPopupWindow = window.open(url+'?fld='+field+'&time='+currTime, 'w', features, false);
	curPopupWindow.focus();
}

function getD(field, currDate) {
	var url = 'DLG/CAL.asp';
	var features='width=260,height=219,dependent=no,resizable=no,toolbar=no,status=no,directories=no,menubar=no,scrollbars=0,center=yes';
	
	closePopup();

	curPopupWindow = window.open(url+'?m=d&date='+currDate+'&fld='+field, 'w', features, false);
	curPopupWindow.focus();
}

function getW(currDate) {
	var url = 'DLG/CAL.asp';
	var features='width=260,height=219,dependent=no,resizable=no,toolbar=no,status=no,directories=no,menubar=no,scrollbars=0,center=yes';
	
	closePopup();

	curPopupWindow = window.open(url+'?m=w&date='+currDate, 'w', features, false);
	curPopupWindow.focus();
}

function getM(currDate) {
	var url = 'DLG/GM.asp';
	var features='width=200,height=200,dependent=no,resizable=no,toolbar=no,status=no,directories=no,menubar=no,scrollbars=0,center=yes';
	
	closePopup();

	curPopupWindow = window.open(url+'?date='+currDate, 'w', features, false);
	curPopupWindow.focus();
}

function getY(currYear) {
	var url = 'DLG/GY.asp';
	var features='width=200,height=200,dependent=no,resizable=no,toolbar=no,status=no,directories=no,menubar=no,scrollbars=0,center=yes';
	
	closePopup();

	curPopupWindow = window.open(url+'?date='+currYear, 'w', features, false);
	curPopupWindow.focus();
}

function closePopup() {
	if (curPopupWindow != null) {
		if (!curPopupWindow.closed) {
			curPopupWindow.close();
		}
		curPopupWindow = null;
	}
}

function setMenuVisibility(mnu, vis) {
	var tbl = document.getElementById('tblMnu'+mnu);
	var imgShow = document.getElementById('imgMnu'+mnu+'Show');
	var imgHide = document.getElementById('imgMnu'+mnu+'Hide');
	var iFrame = document.getElementById('i');

	switch(vis){
		case "0":{
			tbl.style.display = 'none';
			imgShow.style.display = '';
			imgHide.style.display = 'none';
			break;
		}
		case "1":{
			tbl.style.display = '';
			imgShow.style.display = 'none';
			imgHide.style.display = '';
			break;
		}
	}
	iFrame.src='r.asp?id=mnuvisibility&vis='+vis+'&mnu='+mnu+'&redir=no';
}

function selectOptions(lst, arr){
	for(var i=0;i<lst.options.length;i++){
		for(var j=0;j<arr.length;j++){
			if(lst.options[i].value==arr[j]){
				lst.options[i].selected=true;
			}
		}
	}
}

function loadLocations(cid,cmbL){
	var iFrame = document.getElementById('i');
	iFrame.src='r.asp?id=loadlocations&cid='+cid+'&cmb='+cmbL.name;
}