// isValidDate( month, day, year) --> returns [true] || [a string which is the error]

// noSpecialChar	(object)
// noSpecialChar2	(object)
// noNumbers		(object)
// onlyNumbers		(object)
// onlyNumbersNoDec	(object) 

//---------------------------------------
function gotoFocus ( objID ) {
	if ( objID.length >  0 ) { 
		if( document.getElementById(objID) ) { 	document.getElementById(objID).focus() ;  } 
	} 
}

//---------------------------------------
function isValidDate( month, day, year) {
	month = parseInt(month,10) ; day = parseInt(day,10) ; year = parseInt(year,10) ; 
	if ( ( month == "" || day == "" || year == "" ) || (isNaN(month)||isNaN(day)||isNaN(year)) )	{ return ("Not a valid date -->\n") ; }
	else if ( (month > 12 ) || isNaN(month) ) 		{ return ("Not a valid month \n") ;}
	else if ( (day > 31 ) || isNaN(day) ) 			{ return ("Not a valid date \n") ;}
	else if ( (year<1900)||(year>2080) ) 			{ return ("Not a valid year \n") ;}
	else	{
		var arrDate = new Array("0","31","28","31","30","31","30","31","31","30","31","30","31")    
		if ( month != 2)	{
			if ( day > parseInt(arrDate[month]) ) {
				return ("The date selected should be less than or equal to " + arrDate[month].toString() + " in " + myGetMonth(month).toString() + "--> \n")
			}
		}
		else	{
			if ((year % 4) == 0)	{
				if( day > 29 )	{ return ( "The date selected should be less than or equal to 29 in February, " + year + " -->\n" ) }
			}			
			else if( day > 28) { return (" The date selected should be less than or equal to 28 in February, " + year + " -->\n") }
		}
	}
	
	return true ;
		
	function myGetMonth( int ) {
		int = parseInt(int)
		var monthIndex = new Array ( 2 )
		monthIndex[0] = new Array ( 1,2,3,4,5,6,7,8,9,10,11,12 )
		monthIndex[1] = new Array ( "January",'Febuary','March','April','May','June','July','August','September','October','November','December' )
		for ( q = 1 ; q!=12 ; ++q ) {
			if ( int == monthIndex[0][q] ) {
				return ( monthIndex[1][q] )
			}
		}
		return ( "" )
	}

}

//function noSpecialChar(o) {
//	if ( !isNaN(o.value) ){ return }
//	
//	var n = 0 , A, B, C, D ;
//	while ( n < o.value.length ) {
//		A = ( (o.value.charAt(n) >= '0' ) && (o.value.charAt(n) <= '9' ) )
//		B = ( (o.value.charAt(n) >= 'a' ) && (o.value.charAt(n) <= 'z' ) )
//		C = ( (o.value.charAt(n) >= 'A' ) && (o.value.charAt(n) <= 'Z' ) )
//		D =   (o.value.charAt(n) == '.' ) 
//		if 	( A || D ) { ++n }
//			else {
//				if( n==0 ){ o.value = o.value.slice(n+1,o.value.length) }
//				else if ( n == o.value.length) { o.value = o.value.slice(0,n-1) }
//				else { 	o.value = o.value.slice(0,n) + o.value.slice(n+1,o.value.length) }
//			}
//	}
//}

//function noSpecialChar2(o) {
//	if ( !isNaN(o.value) ){ return }
//	
//	var n = 0 , A, B, C ;
//	while ( n < o.value.length ) {
//		A = ( (o.value.charAt(n) >= '0' ) && (o.value.charAt(n) <= '9' ) )
//		B = ( (o.value.charAt(n) >= 'a' ) && (o.value.charAt(n) <= 'z' ) )
//		C = ( (o.value.charAt(n) >= 'A' ) && (o.value.charAt(n) <= 'Z' ) )
//		if 	( A || D ) {
//			++n
//		}
//			else {
//				if( n==0 ){
//					o.value = o.value.slice(n+1,o.value.length)
//				}
//					else if ( n == o.value.length) {
//						o.value = o.value.slice(0,n-1)
//					}
//						else {
//							o.value = o.value.slice(0,n) + o.value.slice(n+1,o.value.length)
//						}
//			}
//	}
//}
//
//
//function noNumbers(object) {
//	if ( !isNaN(o.value) ){ return }
//	
//	var n = 0 , B, C ;
//	while ( n < o.value.length ) {
//		B = ( (o.value.charAt(n) >= 'a' ) && (o.value.charAt(n) <= 'z' ) )
//		C = ( (o.value.charAt(n) >= 'A' ) && (o.value.charAt(n) <= 'Z' ) )
//		if 	( A || D ) {
//			++n
//		}
//			else {
//				if( n==0 ){
//					o.value = o.value.slice(n+1,o.value.length)
//				}
//					else if ( n == o.value.length) {
//						o.value = o.value.slice(0,n-1)
//					}
//						else {
//							o.value = o.value.slice(0,n) + o.value.slice(n+1,o.value.length)
//						}
//			}
//		
//	}
//}

function onlyNumbers(o) {
	if ( !isNaN(o.value) ){ return ; }

	var n = 0 , A, D ;
	while ( n < o.value.length ) {
		A = ( (o.value.charAt(n) >= '0' ) && (o.value.charAt(n) <= '9' ) )
		D =   (o.value.charAt(n) == '.' ) 
		if 	( A || D ) { ++n }
		else {
			if( n==0 ){ o.value = o.value.slice(n+1,o.value.length) }
			else if ( n == o.value.length) { o.value = o.value.slice(0,n-1) }
			else { 	o.value = o.value.slice(0,n) + o.value.slice(n+1,o.value.length) }
		}
		
	}
}
function onlyNumbersNoDec(o) {
	if ( !isNaN(o.value) ){
		return
	}

	var n = 0 , A, D ;
	while ( n < o.value.length ) {
		A = ( (o.value.charAt(n) >= '0' ) && (o.value.charAt(n) <= '9' ) )
		if 	( A ) { ++n }
		else {
			if( n==0 ){ o.value = o.value.slice(n+1,o.value.length) }
			else if ( n == o.value.length) { o.value = o.value.slice(0,n-1) }
			else { o.value = o.value.slice(0,n) + o.value.slice(n+1,o.value.length) }
		}
		
	}
}
function tableRowOver( obj , direction ) {
	if( direction == "1") {
		if( obj.className == "row_A") { 	obj.className = "row_A_u" }
		else if( obj.className == "row_B") { obj.className = "row_B_u" }
	}
	else if ( direction == "0") {
		if( obj.className == "row_A_u") { obj.className = "row_A" }
		else if( obj.className == "row_B_u") { obj.className = "row_B" }
	}
}

function fixRowFormating( tableID , val0 ) {
	var classValue = "row_A"
	
	for( var i = val0 ; i != document.getElementById(tableID).getElementsByTagName('tr').length ; ++i) {
		if (((document.getElementById(tableID).getElementsByTagName('tr')[i].style.display).length == 0 ) ||( (document.getElementById(tableID).getElementsByTagName('tr')[i].style.display).toLowerCase()  == "block"   )) {
			document.getElementById(tableID).getElementsByTagName('tr')[i].className = classValue
			if(classValue == "row_A") { classValue = "row_B" }
			else { classValue = "row_A" }
		}
		
	}
}

//used with 'onKeyPress' -------------
//Ex: onKeyPress="formatOnlyNumbersWithPeriod()"
function onKeyPressOnlyNumbersWithPeriod() {
	if(event.keyCode <48 || event.keyCode>57) {
		if(event.keyCode != 46) {
			return event.returnValue = false;
		}
	}
	
}
function onKeyPressOnlyNumbers() {
	if(event.keyCode <48 || event.keyCode>57) {
			return event.returnValue = false;
	}
	
}

//function $( strElementID ) {
//	return document.getElementById('strElementID')
//}

function getObjOffsetPos(obj,mode) {
    var iPos = 0 ;
    while(obj.tagName != "BODY") {
		if (mode == "L") { iPos += obj.offsetLeft; }
		else if(mode == "T") { iPos += obj.offsetTop; }
        obj = obj.offsetParent; 
    }
    return iPos;
}
/*
function addCellToTb(oTable,Celldata,intCellPos,altRows) {
	//var tbl = document.getElementById('htmTable_CusComments');
	var lastRow = oTable.rows.length;
	//var iteration = lastRow;
	var row = oTable.insertRow(lastRow);
	row.className = "row_A"
	
	var oCell = row.insertCell(intCellPos);
	var oTextNode = document.createTextNode(Celldata);
	oCell.appendChild(oTextNode);
	
}
*/
function clearRowsFromTable(tableID,KeeperRowNum ) {
	if ( document.getElementById(tableID) ) {
		var tbl = document.getElementById(tableID)
		var lastRow = tbl.rows.length;
		while(lastRow > KeeperRowNum) { tbl.deleteRow(lastRow - 1); lastRow = tbl.rows.length ; }
	}
}


//---------------------------------------
// Used to set the style for the new "Input.buttons"
function btn0(oThis,mode) {
	oThis.getElementsByTagName('IMG')[0].src = "/IMAGES/buttons/btn"+mode+"_L.gif"
	oThis.getElementsByTagName('IMG')[1].src = "/IMAGES/buttons/btn"+mode+"_R.gif"
	oThis.getElementsByTagName('TD')[1].className = "btn"+mode+"txt"
}


function trim(stringToTrim)
{
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}    	

//Check for null values for double and integer..
function checkForMinVal(val,type)
{
   if (type == "double")
   {
        if (decRound(val) == decRound(-1.7976931348623157e+308))
           val = '';
   }             
   else if (type == "int")
   {
        if (val == -2147483648)
           val = '';
   }        
   return val;       
}


function getDollar(value)
{
    value = value + ''
    if (value.indexOf('-') == 0)
        value = "-" + "$" + value.replace(/-/,'');
    else
        value = "$" + value;
        
    return value;
}
function IsValidEmail(strEmail)
{
    
     if (strEmail.toLowerCase().search(/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/) != -1)
        return true;
    else
        return false;
}
