function isValidNominalAmntPerShare(value){ 
	if( value <= 0 ) {
		alert('Per Share value should be greater than zero');
		return false;
	}
	if(!isInteger(value))
	{
		alert('Invalid value!! Rs. per share');
		return false;		
	}
	if (value % 10!=0) {
		alert('Per Share value should be a multiple of 10');
		return false;
	}
	return true;
}

function echeck(str) {
  var at="@"
  var dot="."
  var lat=str.indexOf(at)
  var lstr=str.length
  var ldot=str.indexOf(dot)
  if (str.indexOf(at)==-1){
     alert("Invalid E-mail ID")
     return false
  }
  if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
     alert("Invalid E-mail ID")
     return false
  }
  if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
      alert("Invalid E-mail ID")
      return false
  }
   if (str.indexOf(at,(lat+1))!=-1){
      alert("Invalid E-mail ID")
      return false
   }
   if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
      alert("Invalid E-mail ID")
      return false
   }
   if (str.indexOf(dot,(lat+2))==-1){
      alert("Invalid E-mail ID")
      return false
   }
   if (str.indexOf(" ")!=-1){
      alert("Invalid E-mail ID")
      return false
   }
   return true          
}

//For formA jsp
function insertTrnsfrShareDebuntureRow(){
	
	var rows = trnsfrShrDebuntureGrid.object.rowCount();
	if(rows<31){
		trnsfrShrDebuntureGrid.object.insertRow();
		trnsfrShrDebuntureGrid.object.setCell(rows,0,rows+1) ;
		
	return true;
	}
	alert("Maximum no of rows allowed in this table are 30. You cannot add more row than this number. ");
	return false;
}
function deleteTrnsfrShareDebuntureRow()
{
		
	  trnsfrShrDebuntureGrid.object.deleteRow();	
      var rowCnt = trnsfrShrDebuntureGrid.object.rowCount();
      var rowLoopCnt = 0;
 
      if(rowCnt > 0){             

            for(rowLoopCnt = 0;rowLoopCnt < rowCnt;rowLoopCnt++){
                trnsfrShrDebuntureGrid.object.setCell(rowLoopCnt,0,rowLoopCnt+1) ;
				
            }     
      }
}
//For formA jsp
function insertDirRow(){
	
	var rows = directorGrid.object.rowCount();
	if(rows<55){
		directorGrid.object.insertRow();
	return true;
	}
	alert("Maximum no of rows allowed in this table are 55. You cannot add more rows than this number. ");
	return false;
}
//For formA jsp
function insertmembersDebentureRow(){
	var rows = membersDebentureGrid.object.rowCount();
	if(rows<31){
		membersDebentureGrid.object.insertRow();
	return true;
	}
	alert("Maximum no of rows allowed in this table are 30. You cannot add more row than this number. ");
	return false;
}
//trim left spaces ' xyz  ' --> ' xyz'
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}
//trim right spaces ' xyz  ' --> 'xyz  '
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

//trim spaces around ' xyz  ' --> 'xyz'
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}

function submitNameSearch(){
	var shouldSubmit= true;
	if(secpform.searchName.value == ""){
		alert("Please enter the company name to search.");
		shouldSubmit = false;
	}
	
	if(shouldSubmit){
		secpform.submit();
	}
}

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "-";
var dtSl= "/";
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 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 isDateWithSlash(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtSl)
	var pos2=dtStr.indexOf(dtSl,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(dtSl,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtSl))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}
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 isValidNIC(NIC) {
	var matchArr = NIC.match(/^(\d{5})-\d{7}-\d{1}$/);
	var numDashes = NIC.split('-').length - 1;
	if (matchArr == null || numDashes == 1) {
		return false;
	}
	return true;
}	

//checks that the field is not empty and the input value is either a integer or a float
function checkAmount(fieldValue) {
	decallowed = 2;  // how many decimals are allowed?
	if (isNaN(fieldValue) || trim(fieldValue) == "") {
		return false;
	}
	else 
	{
		if (fieldValue.indexOf('.') == -1) fieldValue += ".";
			dectext = fieldValue.substring(fieldValue.indexOf('.')+1, fieldValue.length);
		if (dectext.length > decallowed)
		{
			return false;
	    }
   }
   return true;
}
//checks that the input value is either a integer or a float
function chkDollarAmount(fieldValue) {
	decallowed = 2;  // how many decimals are allowed?
	if (isNaN(fieldValue)) {
		return false;
	}
	else 
	{
		if (fieldValue.indexOf('.') == -1) fieldValue += ".";
			dectext = fieldValue.substring(fieldValue.indexOf('.')+1, fieldValue.length);
		if (dectext.length > decallowed)
		{
			return false;
	    }
   }
   return true;
}
function isStrMatch(str1, str2){
  return str1.toUpperCase() == str2.toUpperCase();
}
function trim(str) {
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}
function FP_preloadImgs() {//v1.0
 var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
 for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; }
}

function FP_swapImgRestore() {//v1.0
 var doc=document,i; if(doc.$imgSwaps) { for(i=0;i<doc.$imgSwaps.length;i++) {
  var elm=doc.$imgSwaps[i]; if(elm) { elm.src=elm.$src; elm.$src=null; } } 
  doc.$imgSwaps=null; }
}

function FP_swapImg() {//v1.0
 var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length;
 n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm;
 elm.$src=elm.src; elm.src=args[n+1]; } }
}

function FP_getObjectByID(id,o) {//v1.0
 var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
 else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
 if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
 for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
 f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
 for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
 return null;
}

function validateUploadFile(filename, reqExtension, extDesc){
		if((filename == null || filename == '')) {
			alert('Please select a valid file by clicking browse button');
			return false;
		} else {
			var indexOfDot = filename.indexOf('.')
			var extension = null
			if(indexOfDot != -1) {
				extension = filename.substring(indexOfDot+1, filename.length)
			}
			if((extension == null) || (extension == '') || (extension.toLowerCase() != reqExtension.toLowerCase())) {
				alert('Please select a valid '+extDesc+' file by clicking browse button');
				return false;
			}
		}
		return true;
}

function wopen(url, name, w, h)
{
w += 32;
h += 96;
wleft = (screen.width - w) / 2;
wtop = (screen.height - h) / 2;
 var win = window.open(url,
  name,
  'width=' + w + ', height=' + h + ', ' +
   'left=' + wleft + ', top=' + wtop + ', ' +
  'location=no, menubar=no, ' +
  'status=no, toolbar=no, scrollbars=no, resizable=no');
 win.resizeTo(w, h);
 win.moveTo(wleft, wtop);
 win.focus();
}

function focusNextOnInput(thisCompNm, nextCompNm, curLen, e){
	var thisComp = document.forms[0].elements[thisCompNm];
	var nextComp = document.forms[0].elements[nextCompNm];
	var keynum;
	var keychar;
	var numcheck;
	if((thisComp!= null) && (thisComp.value.length == curLen))
	{
		keynum = e.keyCode;
		keychar = String.fromCharCode(keynum);
		numcheck = new RegExp("[a-zA-Z0-9]");
		if(numcheck.test(keychar)){
			nextComp.focus();
		}
	}
}

function isValidDate(iDate){
    var dateArray = iDate.split("/");
    var date=new Date();
    date.setFullYear(dateArray[2],dateArray[1]-1,dateArray[0]);
    var currentDate=new Date(); 
    if(date > currentDate){           
            return false;
    }
	return true;
}
//checks that value is integer or float(upto 2 decimel places)
function isDollar(fieldValue) {
	decallowed = 2;  // how many decimals are allowed?
	
	if (isNaN(fieldValue) ) {
		return false;
	}
	else if( trim(fieldValue) == "" && fieldValue.length>0){	
		return false;		
	}
	else {
		if (fieldValue.indexOf('.') == -1) 
			fieldValue += ".";		
		dectext = fieldValue.substring(fieldValue.indexOf('.')+1, fieldValue.length);
		if (dectext.length > decallowed){
		
			return false;
	    	}
   	}	
   return true;
}
