function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
}

function chkDigit(field){
	/*var regdigit=/^(([0-9])*[- .(]*([0-9])*[- .)]*[0-9][- .]*[0-9])+$/;
	if(!regdigit.test(field)){
		return true;
	}
return false;*/
	if(IsNumeric(field)){
		return false;
	}else{
		return true;
	}
}

function chkCharacter(field){
	var regchar=/^[\w\s]+$/;
	if(!regchar.test(field)){
		return true;
	}
return false;
}

function chkEmail(field){
	var emailexp= /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
	if(!emailexp.test(field)){
		return true;
	}
return false;
}

function chkEmpty(field){
	if(trim(field.value) == ""){
		return true;
	}
return false;
}

function IsAllSpaces(myStr){
	while (myStr.substring(0, 1) == " ") 
	{
	myStr = myStr.substring(1, myStr.length);
	}
	if(myStr == "")
	return true;
return false;
}
		
function changeRowColor(id,totalRows){
for(i=0; i<totalRows; i++){
	
	var idd='row'+i;
	if(id==idd){
	ele=document.getElementById(idd);
	ele.className='BGSWAP';	
	}else{
	ele=document.getElementById(idd);
	ele.className='BG';	
	}
}//for loop	
}//function

function delRow(rowNum,parent){
	var mainDevId=document.getElementById(parent);
	var innerDevId=document.getElementById(rowNum);
	mainDevId.removeChild(innerDevId);
}

function SelectOption(OptionListName, ListVal){
	for (i=0; i < OptionListName.length; i++){
		if (OptionListName.options[i].value == ListVal){
			OptionListName.selectedIndex = i;
			break;
		}
	}
}
// return the value of the radio button that is checked 
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}
////////////////////////////////////////

function moveSelectedOptions(from,to) {
	for (var i=0; i<from.options.length; i++) {
	var o = from.options[i];
	//if (!hasOptions(to)) { var index = 0; } else { var index=to.options.length; }
	to.options[i] = new Option( o.text, o.value, false, false);
	}//for loop...*/
}//function closing.

function toggleLayer(whichLayer)
{
if (document.getElementById)
{
// this is the way the standards work
var style2 = document.getElementById(whichLayer).style;
style2.display = style2.display? "":"block";
}
else if (document.all)
{
// this is the way old msie versions work
var style2 = document.all[whichLayer].style;
style2.display = style2.display? "":"block";
}
else if (document.layers)
{
// this is the way nn4 works
var style2 = document.layers[whichLayer].style;
style2.display = style2.display? "":"block";
}
}


/*************************************************************/
function deleteRecords(frm,fieldName,moduleName){
	var len = frm.elements.length;
	var count = 0;
	 for (var i = 0; i < len; i++){
		if(frm.elements[i].checked == true){
			count = 1;
			break;
		}
	 }
	if(count >= 1){
		var answer = confirm('Are you sure to Delete Record?');
		if(answer == 1){
		fieldName.value=moduleName;
		//alert(fieldName.value);
		frm.submit();
		}else{
		return false;
		}
	}
	else{
		alert('Please select atleast one record to delete');
		return false;
	}
}

/*************************************************************/

function activateRecords(frm,fieldName,moduleName){
	var len = frm.elements.length;
	var count = 0;
	 for (var i = 0; i < len; i++){
		if(frm.elements[i].checked == true){
			count = 1;
			break;
		}
	 }
	if(count >= 1){
		var answer = confirm('Are you sure to activate selected record(s). ?');
		if(answer == 1){
		fieldName.value=moduleName;
		frm.submit();
		}else{
		return false;
		}
	}
	else{
		alert('Please select atleast one record to activate');
		return false;
	}
}

/*************************************************************/

function deactivateRecords(frm,fieldName,moduleName){
	var len = frm.elements.length;
	var count = 0;
	 for (var i = 0; i < len; i++){
		if(frm.elements[i].checked == true){
			count = 1;
			break;
		}
	 }
	if(count >= 1){
		var answer = confirm('Are you sure to de-activate record(s). ?');
		if(answer == 1){
		fieldName.value=moduleName;
		frm.submit();
		}else{
		return false;
		}
	}
	else{
		alert('Please select atleast one record to de-activate');
		return false;
	}
}

/*************************************************************/
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function AnyNoneCheck(frm) {
var len = frm.elements.length;
	for(var i = 0; i <= len; i++) {
	
	if( frm.elements[i] != undefined){
	
		if(frm.elements[i].checked){		
		frm.AC.checked=true;
		}else{
		frm.AC.checked=false;
		return false;
		}
	
	}//undefined check closing.	
		
	}//FOR LOOP
}//FUNCITON CLOSING.

function CheckAll(frm)
{
	
	var len = frm.elements.length;
	if (frm.AC.checked==true)
    {
	    for (var i = 0; i < len; i++)
		 {
	      	frm.elements[i].checked=true;
	     }
	}
	else{
	      for (var i = 0; i < len; i++)
		  {
	       	frm.elements[i].checked=false;
	      }
	    }
}//FUNCTION CLOSING

function numbersonly(myfield, e, dec)
	{
	var key;
	var keychar;
	
	if (window.event)
	key = window.event.keyCode;
	else if (e)
	key = e.which;
	else
	return true;

	keychar = String.fromCharCode(key);
	// control keys
	if ((key==null) || (key==0) || (key==8) || 
	 (key==9) || (key==13) || (key==27) )
	 return true;
	// numbers
	else if ((("0123456789.-").indexOf(keychar) > -1))
	return true;
	// decimal point jump
	else if (dec && (keychar == "."))
	 {
	 myfield.form.elements[dec].focus();
	 return false;
	 }
else
alert('Please enter only numbers, charactors are not allowed.');
return false;
}


function validateEmail(addr,man,db) {
	
if (addr == '' && man) {
	if (db){
		alert('Email address is mandatory.');
		return false;
	} 
}
var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
for (i=0; i<invalidChars.length; i++) {
   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
      if (db){//return false and alert
	  alert('Email address contains invalid characters.');
      return false;
	  }else{//only return false without debugging dialog.
      return false;
	  }///
   }
}
for (i=0; i<addr.length; i++) {
   if (addr.charCodeAt(i)>127) {
      if (db){
	    alert("Email address contains non ascii characters.");
      return false;
	  }else{//only return false without debugging dialog.
      return false;
	  }///
   }
}

var atPos = addr.indexOf('@',0);
if (atPos == -1) {
   if (db){
	alert('Email address must contains an @.');
   return false;
   }else{//only return false without debugging dialog.
      return false;
   }
}
if (atPos == 0) {
   if (db){
    alert('Email address must not start with @.');
   return false;
   }else{//only return false without debugging dialog.
      return false;
	  }///
}
if (addr.indexOf('@', atPos + 1) > - 1) {
   if (db){
	 alert('Email address must contains only one @.');
   return false;
   }
}
if (addr.indexOf('.', atPos) == -1) {
   if (db){
      alert('Email address must contains a period in the domain name.');
   return false;
   }else{//only return false without debugging dialog.
      return false;
	  }////
}
if (addr.indexOf('@.',0) != -1) {
   if (db){
      alert('Period must not immediately follow @ in email address.');
   return false;
   }else{//only return false without debugging dialog.
      return false;
	  }/////
}
if (addr.indexOf('.@',0) != -1){
   if (db){
   	  alert('Period must not immediately precede @ in email address.');
   return false;
   }else{//only return false without debugging dialog.
      return false;
	  }///
}
if (addr.indexOf('..',0) != -1) {
   if (db){ 
   	alert('Two periods must not be adjacent in email address.');
   return false;
   }else{//only return false without debugging dialog.
      return false;
	  }////
}
var suffix = addr.substring(addr.lastIndexOf('.')+1);
if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
   if (db){ 
	 alert('Invalid primary domain in email address.');
   return false;
   }else{//only return false without debugging dialog.
      return false;
	  }///
}
return true;
}

function help(mypage,myname,anchor,w,h,scroll,res){	
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable=no'
mywindow2 = window.open(mypage,myname,settings)
mywindow2.location.href = mypage + '#' + anchor;
    if (mywindow2.opener == null) mywindow2.opener = self;
	mywindow2.focus();
}


function printit(){  
if (window.print) {
    window.print();  
} else {
    var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
	document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
    WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";  
}
}

function adWindow(mypage,myname,w,h,scroll,res){	
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable=no,statusbar=yes';
ad = window.open(mypage,myname,settings);
ad.focus();
}


function fullScreenWindow(mypage,myname){
settings ='scrollbars=yes,resizable=yes,statusbar=yes'
fullWindow = window.open(mypage,myname,settings)
fullWindow.focus();
}

function checkFinancialYear(UserYear,CurrentYear)
{
	if(UserYear<CurrentYear){
		return false;
	}else if(UserYear > CurrentYear){
		return false;
	}else{
	return true;
	}
}


function chkdate(starting,ending){
	var aPart = starting.split('-');
	var bPart = ending.split('-');
	var startDate = new Date(aPart[2],aPart[1]-1,aPart[0]);
	var endDate = new Date(bPart[2],bPart[1]-1,bPart[0]);
	
	var sDiff = endDate.valueOf() - startDate.valueOf();
	//alert(sDiff);
	if(sDiff<0)
    	return true;
	else
		return false;
}

function round(number,X) {
// rounds number to X decimal places, defaults to 2
    X = (!X ? 2 : X);
    return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

function cent(amount) {
// returns the amount in the .99 format
    amount -= 0;
    return (amount == Math.floor(amount)) ? amount + '.00' : (  (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
}

////////////////////////////////////////////////////////////////
///////////////////Format Check like dd-mm-yyyy/////////////////
/*** DHTML date validation script for dd/mm/yyyy.*//////////////
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 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
}
// set date format.
function dateFormat(e, dateValue){
	var key;
	if (window.event)
		key = window.event.keyCode;
	else if (e)
		key = e.which;
		
	//alert(key);
	//alert(dateValue.value.length);
	if(dateValue.value.length == 2 && key!=8)
		dateValue.value = dateValue.value + '-';
	else if(dateValue.value.length == 5 && key!=8)
		dateValue.value = dateValue.value + '-';
	else if(dateValue.value.length > 9)
		dateValue.value = dateValue.value.substring(0, 10)
}

function disableEndAccounts(field,chkBox){
	field.value=0;
	if(chkBox.checked==true)
		field.disabled=true;
	else
		field.disabled=false;
}

function formatAmount(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + num + '.' + cents);
}
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////