//function autoskip(fieldName,fldMaxLength)

//function hasSpace(s) - return "true" or "false"
//function reallen(s) - returns the value after eliminating all the spaces
//function isBlank(s) 
//function validateDate(data, whatdate)
//function MinYearValidate(d) - returns false if year value is smaller than 1900
//function hasSpace(s) - returns true if the value has space
//function isNumericAll(c)
//function removeNonNumerics(s)
//function checkEmail(s)
function checkMLS(inval) {
  var strValid = "1234567890, ";
  var result = true;
  for (i=0; i<inval.length; i++) {
  	var cc = inval.substring(i, i+1, 1)
  	if (strValid.indexOf(cc) == -1) {	
  		result = false;
  		break;
  	}
  }
  return result;
}

function hasSpace(s)
{
  for( var i = 0 ; i < s.length ; i++)
  {
	var c = s.charAt(i)
	if (c == ' ') return true
  }
  return false
}
function isFuture(inval) {
	var d = new Date(inval)
	if (Date.parse(d) > Date.parse(new Date())) {
		return true
	}
	else {
		return false
	}
}
function isBlank(s)
{
	for( var i = 0 ; i < s.length ; i++)
	{
		var c = s.charAt(i)
		if( (c != ' ') && ( c != '\n') && (c != '\t')) return false
	}
	return true
}
 
  function removeNonNumerics( s )
  {
	if ( s == null ) return null
	s = '' + s
	var tmp = ''
	var isLeadingZero = true
	var result
	for ( var i = 0; i < s.length; i++ )
	{
	  var c = s.charAt( i )
	  result = isNumericAll( c )
	  if (result)
	  {
	    if ( isLeadingZero == true && c == '0' )
	      continue
		else
		  isLeadingZero = false
		tmp = tmp + c
	  }
	}
	return tmp
  }
  
  function checkEmail(inval) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(inval)){
		return true
	}
	else
	{
		return false
	}
}

function autoTab(input, len) {
	if(input.value.length >= len) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
}
function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
	if (input.form[i] == input) {
		index = i;
	}else i++;
	return index;
}
return true;
}

/*  Removes all charcaters except / , 0-9*/
function isNumeric3( c )
{	
	return (c == '/' || ( c >= '0' && c <= '9' ))
}
function removeNonNumerics3( s )
{

	if ( s == null ) return null
	s = '' + s
	var tmp = ''
	var isLeadingZero = false
	for ( var i = 0; i < s.length; i++ ){
		var c = s.charAt( i )
		if ( isNumeric3( c ) ){
			if ( isLeadingZero == true && c == '0' ){
				continue;
			}else{
				isLeadingZero = false
			}tmp = tmp + c
		}
	}return tmp
}

var inputField;
function autoskip(fieldName,fldMaxLength){
	var myForm=document.forms[document.forms.length - 1];
	var myField=myForm.elements[fieldName];
	var i;
	var myNextPos;
	for (i=0; i<myForm.elements.length - 1; i++) {
		if (myForm.elements[i].name == fieldName) {
			myNextPos=i + 1;
			i=myForm.elements.length;
		}
	}
	myField.nextField=myForm.elements[myNextPos];

	if(myField.maxLength == null)
	  myField.maxLength=fldMaxLength;

	myField.onkeydown=autoskip_keyDown;
	myField.onkeyup=autoskip_keyUp;
}

function autoskip_keyDown(){
	this.beforeLength=this.value.length;
	inputField=this;
}

function autoskip_keyUp(){
	if((this == inputField)&&(this.value.length > this.beforeLength)&&(this.value.length >= this.maxLength)){
		this.nextField.focus();
		inputField=null;
	}
}

function ignoreSpaces(string) {
	var temp = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
	temp += splitstring[i];
	return temp;
}

function dollarAmount(dform, dfield, dec) 
{ 
	Num = "" + eval("document." + dform + "." + dfield + ".value");
	Num = strToFloatRange( Num, 0, 100000000000000 )
	Num = numToDollars(Num, dec)
	eval("document." + dform + "." + dfield + ".value = Num");
	Num = dollarsToNum(Num)
	eval("document." + dform + "." + dfield + "Num.value = Num");
}

function dollarsToNum( n )
{
  var r;
  r = n.replace(",", "");
  r = r.replace(",", "");
  r = r.replace(",", "");
  r = r.replace(",", "");
  return ( r );
}
	
function isOverflow( n )
{
	return ( isNaN( n ) || n == Number.POSITIVE_INFINITY || n == Number.NEGATIVE_INFINITY )
}
function isNumeric( c )
{
	return ( c == '.' || c == '-' || ( c >= '0' && c <= '9') )
}
function removeNonNumerics( s )
{
	if ( s == null ) return null
	s = '' + s
	var tmp = ''
	var isLeadingZero = true
	for ( var i = 0; i < s.length; i++ )
	{
		var c = s.charAt( i )
		if ( isNumeric( c ) )
		{
			if ( isLeadingZero == true && c == '0' )
			{
				continue;
			}
			else
			{
				isLeadingZero = false
			}
			tmp = tmp + c
		}
	}
	return tmp
}
function strToInt( s )
{
	var n = parseInt( removeNonNumerics( s ) )
	if ( isNaN( n ) )
	{
		n = 0
	}
	return (n < 0) ? 0 : n;
}
function addCommas( tmp )
{
	var s = ''
	var len = tmp.length
	var end = len - 1
	for ( var i = 0; i < len; i++ )
	{
		c = tmp.charAt( end - i )
		s = c + ((i > 2 && i % 3 == 0) ? ',' : '') + s
	}
	return s
}
function _numToUnits( n, units_prefix, decimal_places, units_suffix )
{
	if ( isOverflow( n ) ) return 'N/A'
	var isNegative = ( n < 0 ) ? true : false
	var s = ''
	var d = strToInt( decimal_places )
	var x = Math.abs( Math.round ( n * Math.pow(10, decimal_places ) ) )
	if ( x == 0 )
	{
		var defaultStr = '0'
		if ( d > 0 )
		{
			defaultStr += '.'
			for ( var i = 0; i < d; i++ ) defaultStr += '0'
		}
		defaultStr = units_prefix + defaultStr + units_suffix
		return defaultStr
	}
	if ( d == 0 )
	{
		var tmp = '' + x
		s = addCommas( tmp )
	}
	else
	{
		var leftTmp = '' + x
		var rightTmp = '' + x
		var len = leftTmp.length
		for ( var i = 0; i < d + 1 - len; i++ )
		{
			leftTmp = '0' + leftTmp
			rightTmp = '0' + rightTmp
		}
		len = leftTmp.length
		var decimalSplit = len - d
		var leftStr = addCommas( leftTmp.substring( 0, decimalSplit ) )
		var rightStr = rightTmp.substring( decimalSplit, len )
		s = leftStr + '.' + rightStr
	}
	s = units_prefix + s + units_suffix
	if ( isNegative ) s = '-' + s
	return s
}
function numToDollars(n, d)
{
	//decimal Points
	return _numToUnits( n, '', d, '' )	//d - decimal Points
}
function strToFloatRange( s, low, high ) {
	var num = strToFloat( s );
	if (num < low)
	{
		num = low;
	}
	else
	{
		if(num > high)
		{
			num = high;
		}
	}
	return num;
}
function strToFloat( s )
{
	var n = parseFloat( removeNonNumerics( s ) )
	if ( isNaN( n ) )
	{
		n = 0
	}
	return (n < 0) ? 0 : n;
}

function Start(page) {
var wint = 600;
var option = "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,top=0,left=0,width=800,height="+ wint;
OpenWin = window.open(page, "CtrlWindow", option);
}
function Start2(page) {
var wint = 600;
var option = "toolbar=yesn,menubar=yes,location=no,scrollbars=yes,resizable=yes,top=0,left=0,width=800,height="+ wint;
OpenWin = window.open(page, "CtrlWindow", option);
}
function small_window(myurl) {
var newWindow;
var props = 'scrollBars=yes,resizable=yes,toolbar=no,menubar=no,location=no,directories=no,top=20,left=50,width=700,height=280';
newWindow = window.open(myurl, "newWindow", props);
}
function small_window2(myurl) {
var newWindow;
var winl = (screen.width - 35);
var wint = (screen.height - 120);
var props = 'scrollBars=yes,resizable=yes,toolbar=no,menubar=no,location=no,directories=no,top=0,left=0,width=' + winl +',height='+ wint;
newWindow = window.open(myurl, "newWindow", props);
}
function small_window3(myurl) {
var newWindow;
var props = 'scrollBars=yes,resizable=yes,toolbar=no,menubar=no,location=no,directories=no,top=20,left=50,width=700,height=350';
newWindow = window.open(myurl, "newWindow", props);
}
function small_window4(myurl) {
var newWindow;
var props = 'scrollBars=yes,resizable=yes,toolbar=no,menubar=no,location=no,directories=no,top=20,left=50,width=580,height=500';
newWindow = window.open(myurl, "newWindow", props);
}
function small_window5(myurl) {
var newWindow;
var props = 'scrollBars=yes,resizable=yes,toolbar=no,menubar=no,location=no,directories=no,top=0,left=0,width=700,height=500';
newWindow = window.open(myurl, "newWindow", props);
}
function full_window(page) {
var wint = screen.height;
var winw = screen.width;
var option = "toolbar=no,menubar=yes,location=no,scrollbars=yes,resizable=yes,top=0,left=0,width=" + winw + ",height="+ wint;
OpenWin = window.open(page, "CtrlWindow", option);
}
function openSlide(myurl) {
var slide;
var props = 'scrollBars=no,resizable=yes,toolbar=no,menubar=no,location=no,directories=no,top=0,left=0,width=650,height=420';
slide = window.open(myurl, "slide", props);
}
function StartSlide(page) {
	//var wint = 380;
	var wint = 250;
	var option = "toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,top=65,left=125,width=322,height="+ wint;
	OpenWin = window.open(page, "images", option);
}

function MoreOH(page) {
var wint = 500;
var option = "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,top=0,left=0,width=600,height="+ wint;
OpenWinOH = window.open(page, "OH", option);
}


function getPreviousMonth(inval) {
	var date, d, m, y, result;
	date = new Date(inval);
	m = date.getMonth();
	y = date.getFullYear();
	d = date.getDate()
	if (m == 0) { y = y - 1; m = 11;}
	else { m = m - 1;}
	// month starts at 0 end 11
	result = (m + 1) + "/" + d + "/" + y
	return result;
}
function getNextMonth(inval) {
	var date, d, m, y, result;
	date = new Date(inval);
	m = date.getMonth();
	y = date.getFullYear();
	d = date.getDate()
	if (m == 11) { y = y + 1; m = 0;}
	else { m = m + 1;}
	// month starts at 0 end 11
	result = (m + 1) + "/" + d + "/" + y
	return result;
}

function EditInput(input, add, where)
{
  if(input.value.length >= 8)
  {}
  else
  {
    if(input.value.length >= where)
	{
	  if ( input.value.substring(where-2,where-1) == add )
	  { 
	    if ( where == 3 )
	    { 
	      input.value = '0' + input.value.substring(0,where-2) + add + input.value.substring(where-1,where+1) 
	    }
	    if ( where == 6 )
	    {
	      input.value = input.value.substring(0,3) + '0' + input.value.substring(3,where-2) + add + input.value.substring(where-1,where+1)
	    }
	  }
	  if ( input.value.substring(where-1,where) != add ) 
	  { 
	    input.value = input.value.substring(0,where-1) + add + input.value.substring(where-1,where+1) 
	  }
	}
  }
}