var timerID = null;
var timerRunning = false;
var old_minutes = 70;
var minutes_count = 30; //long for time (in minutes)

function stopclock (){
        if(timerRunning)
                clearTimeout(timerID);
        timerRunning = false;
}

function showtime (var_status) {
        var now = new Date();
        var hours = now.getHours();
        var minutes = now.getMinutes();
        var seconds = now.getSeconds()
        var timeValue = "" + ((hours >12) ? hours -12 :hours)
        timeValue += ((minutes < 10) ? ":0" : ":") + minutes
        timeValue += ((seconds < 10) ? ":0" : ":") + seconds
        timeValue += (hours >= 12) ? " P.M." : " A.M."
		if(parseInt(old_minutes) != parseInt(minutes)){
			old_minutes = minutes
			minutes_count = minutes_count - 1
			window.status = minutes_count + " minutes remaining" ;
			if(parseInt(minutes_count)== 0){
				if (var_status != 1){
					//top.location.href="../am_login.aspx"
					top.location.href="../am_logout.aspx"
					am_logout.aspx
					//flyto("../am_logout.asp");
				}
				else{
					top.location.href="../am_logout.aspx"
				}
			}
		}
        timerID = setTimeout("showtime(" + var_status + ")",1000);
        timerRunning = true;
}

function startclock () {
        // Make sure the clock is stopped
        stopclock();
        showtime(0);
}

function startclock_upd () {
        // Make sure the clock is stopped
        stopclock();
        showtime(1);
}

function numbersonly(){
	if (event.keyCode<48||event.keyCode>57){
		return false;
	} else{
		return true;
	}	
}
function validchar(){
	if ((event.keyCode > 39 && event.keyCode < 58) || (event.keyCode > 96 && event.keyCode < 123) || (event.keyCode > 64 && event.keyCode < 91) || (event.keyCode > 35 && event.keyCode < 39)){
		return true;
	} else{
		return false;
	}	
}
function decimalonly(){
	if ((event.keyCode>47&&event.keyCode<59) || (event.keyCode==46)){
		return true;
	} else{
		return false;
	}
}
function fback() 
{
					history.go(-1);
					return false;
}	
function fConfirm() 
{
	if (window.confirm("Are you sure want to delete this record?")) 
		return true;
	else
		return false;
}
	function Close(){
				window.close();
			}
			
			function f_appConfirm() 
{
	if (window.confirm("Are you sure want to change approval this record?")) 
		return true;
	else
		return false;
}
	function Close(){
				window.close();
			}
function DeleteConfirm(){
if (window.confirm("Are you sure want to delete this record ?"))
	return true;
else 
	return false;
}

function fclose(){
 window.close() ; 
}
var ErrMsg = "Right click is not allowed.";
function disableRightClick(btnClick)
{
if (navigator.appName == "Netscape" && btnClick.which == 3) // check for netscape and right click
{ 
alert(ErrMsg);
return false;
}
else if (navigator.appName =="Microsoft Internet Explorer" && event.button == 2) // for IE and Right Click
{
alert(ErrMsg);
return false;
}
}
document.onmousedown = disableRightClick;
history.forward(1);
var message = "Right click is not allowed.";

function clickIE4()
{
	if (event.button==2)
	{
		alert(message);
		return false;
	}
}

function clickNS4(e)
{
	if (document.layers||document.getElementById&&!document.all)
	{
		if (e.which==2||e.which==3)
		{
			alert(message);
			return false;
		}
	}
}

if (document.layers)
{
	document.captureEvents(Event.MOUSEDOWN);
	document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById)
{
	document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("alert(message);return false")


function keyhandler(e) {
    if (document.layers)
        Key = e.which;
    else 
        Key = window.event.keyCode;
        //alert(Key);
 
//    if (((Key>39) && (Key<59)) ||
// ((Key>96) && (Key<123)) ||
// ((Key>63) && (Key<91)) ||
// (Key==38) ||
// (Key==32) ||
// (Key==37) ||
// (Key == 13))

    if (((Key > 1) && (Key < 128))) {
        return true;
            }
 if (!e) e = window.event; 
  return false;
}
document.onkeypress = keyhandler;
function checkKP() {
	if (event.ctrlKey) {
		if ((event.keyCode==78) || (event.keyCode==104))
			event.returnValue = false;	
	}
}
var submitcount=0;
function checksubmit()
{
	if (submitcount == 0){
		submitcount++;
		return true;
	}else {
		var sErrMsgNull = 'Your transaction is being processed, Please be patient.';
		alert (sErrMsgNull);
		return false;
	}
}

function disablebackspace() {
  if (window.focus) window.focus();
  document.onkeydown=catchbackspace;
  document.onkeyup=catchbackspace;
}

function catchbackspace() {
  if (!e) e=window.event;
  if (e.keyCode==8){
    alert("Backspace key was pressed.");
    return false;
  }
}

			var oInput;
			var oHidden;
			var oValidasi;
			
			function formatNumber(pValue){
			    var strValue = '';
			    var fltValue = 0;

				while (pValue.indexOf(",") > 0){ 
						pValue = pValue.replace(",","");
				}	
				if(isNaN(pValue)) {
					lStrValue=0;			
				} else {
					pValue = parseFloat(pValue);
					if (isNaN(pValue)){
						pValue=0;
						lStrValue=0;
					} else {		
	
						var lArrPre = pValue.toString().split('.')
						var lStrValue = '';
						var lBytLength = 0;
						
						
							
							lBytLength = lArrPre[0].length - 3;
					
						while (lBytLength > 0){
							lStrValue = ',' + lArrPre[0].substr(lBytLength, 3) + lStrValue;
							lBytLength -= 3;
						}
						
						lBytLength += 3;
						
						if(pValue  < 0) 
						{
							if (lBytLength == 1)
							 {
								lStrValue = '-' + lStrValue.substr(1, lStrValue.length) ;
							 } 
							else
							{
								lStrValue = lArrPre[0].substr(0, lBytLength) + lStrValue;
							}
							
							
						}
						 else 
						{
							lStrValue = lArrPre[0].substr(0, lBytLength) + lStrValue;
						}
						
						if (lArrPre.length == 2){
							lStrValue += '.' + lArrPre[1];
						}
					}

				}
				return lStrValue;
			}
	
			function formatValue(pInput, pHidden, pValidasi){
				var oInput = eval('document.forms[0].' + pInput);
				var oHidden = eval('document.forms[0].' + pHidden);
				var oValidasi = eval('document.forms[0].' + pValidasi);
				
				var total = oInput.value;		
				oInput.value = formatNumber(total);	
				total = oInput.value;	
				while (total.indexOf(",") > 0){ 
						total = total.replace(",","");
				}
				oHidden.value = total;
				oValidasi.value = total;

			}
				
			function clearFormatValue(pInput){
				var oInput = eval('document.forms[0].' + pInput)
			
				
				var total = oInput.value;
				while (total.indexOf(",") > 0){ 
						total = total.replace(",","");
				}	
				oInput.value = total;
			}
			function blurDummy()
			{
				document.forms[0].txtInputDummy.focus();
				document.forms[0].txtInputDummy.blur();
			}

			function OnTabChanged(sender, args) //ini buat nyimpen state di client ketika ada event AutoPostBack
			{		    			        
			    sender.get_clientStateField().value = sender.saveClientState();			   
			}

            function functionName() {
                parent._left.location.href = "http://www.kaskus.us";
            }

            function onCalendarShown() {

                var cal = $find("calendar1");
                //Setting the default mode to month
                cal._switchMode("months", true);

                //Iterate every month Item and attach click event to it
                if (cal._monthsBody) {
                    for (var i = 0; i < cal._monthsBody.rows.length; i++) {
                        var row = cal._monthsBody.rows[i];
                        for (var j = 0; j < row.cells.length; j++) {
                            Sys.UI.DomEvent.addHandler(row.cells[j].firstChild, "click", call);
                        }
                    }
                }
            }

            function onCalendarHidden() {
                var cal = $find("calendar1");
                //Iterate every month Item and remove click event from it
                if (cal._monthsBody) {
                    for (var i = 0; i < cal._monthsBody.rows.length; i++) {
                        var row = cal._monthsBody.rows[i];
                        for (var j = 0; j < row.cells.length; j++) {
                            Sys.UI.DomEvent.removeHandler(row.cells[j].firstChild, "click", call);
                        }
                    }
                }

            }

            function call(eventElement) {
                var target = eventElement.target;
                switch (target.mode) {
                    case "month":
                        var cal = $find("calendar1");
                        cal._visibleDate = target.date;
                        cal.set_selectedDate(target.date);
                        cal._switchMonth(target.date);
                        cal._blur.post(true);
                        cal.raiseDateSelectionChanged();
                        break;
                }
            }
