/*
	Check all checkbox
*/
function checkAll(FormName)
{
	for (var i=0;i< eval("document." + FormName + ".elements.length") ;i++) 
	{
		var x = eval("document." + FormName + ".elements["+ i + "]");
		if (x.name != 'selall')
		{
		      x.checked = eval("document."+ FormName +".selall.checked");
		}
	}
}

/*

PS: form name should be "form"
	
Date Format in Brazilian 
Usage into tag INPUT TEXT:
onKeyDown=DateFormatBr("fieldName_name",event)
	
*/
function DateFormatBr(fieldName,keyPressed) {
	var KeyPress = keyPressed.keyCode;
	vr = document.form[fieldName].value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	size = vr.length + 1;

	if ( KeyPress != 9 && KeyPress != 8 ){
		if ( size > 2 && size < 5 )
			document.form[fieldName].value = vr.substr( 0, size - 2  ) + '/' + vr.substr( size - 2, size );
		if ( size >= 5 && size <= 10 )
			document.form[fieldName].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); }
}


/*
PS: form name should be "form"

Description:	Value Format type Money in Brazilian

Usage on tag INPUT TEXT AND TEXTAREA
onKeyDown=ValueFormatBr("fieldName",<MaxSize>,event)
 - MaxSize can be a value of 0 until 17

*/

function ValueFormatBr(fieldName,maxSize,keyPressed) {
	var tecla = keyPressed.keyCode;
	vr = document.form[fieldName].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	size = vr.length;
	if (size < maxSize && tecla != 8){ size = vr.length + 1 ; }

	if (tecla == 8 ){	size = size - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		count = 0;
		if ( size <= 2 ){ 
			count=0;
	 		document.form[fieldName].value = vr ; 
			}
	 	if ( (size > 2) && (size <= 5) ){
			count=1;
	 		document.form[fieldName].value = vr.substr( 0, size - 2 ) + ',' + vr.substr( size - 2, size ) ; 
			}
	 	if ( (size >= 6) && (size <= 8) ){
			count=2;
	 		document.form[fieldName].value = vr.substr( 0, size - 5 ) + '.' + vr.substr( size - 5, 3 ) + ',' + vr.substr( size - 2, size ) ; 
			}
	 	if ( (size >= 9) && (size <= 11) ){
			count=3;
	 		document.form[fieldName].value = vr.substr( 0, size - 8 ) + '.' + vr.substr( size - 8, 3 ) + '.' + vr.substr( size - 5, 3 ) + ',' + vr.substr( size - 2, size ) ; 
			}
	 	if ( (size >= 12) && (size <= 14) ){
			count=4;
	 		document.form[fieldName].value = vr.substr( 0, size - 11 ) + '.' + vr.substr( size - 11, 3 ) + '.' + vr.substr( size - 8, 3 ) + '.' + vr.substr( size - 5, 3 ) + ',' + vr.substr( size - 2, size ) ; 
			}
	 	if ( (size >= 15) && (size <= 17) ){
			count=5;
	 		document.form[fieldName].value = vr.substr( 0, size - 14 ) + '.' + vr.substr( size - 14, 3 ) + '.' + vr.substr( size - 11, 3 ) + '.' + vr.substr( size - 8, 3 ) + '.' + vr.substr( size - 5, 3 ) + ',' + vr.substr( size - 2, size ) ;
			}
	}
	status = size;
	if (size >= maxSize) 
	{
		document.form[fieldName].value = document.form[fieldName].value.substring(0, maxSize+count - 1);
	}
}


/*
Check all checkbox
Usage:
	Put :
	<input type="checkbox" name="sellall" onClick="CheckAll('formName')">

formName = name of form

*/
function CheckAll(formName,boxName) {
	if (!boxName) boxName = "selall";
	
	for (var i=0 ; i < eval("document." + formName + ".elements.length") ; i++) 
	{
		var x = eval("document." + formName + ".elements["+ i + "]");
		status=x.name;
		if (x.name != boxName)
		      x.checked = eval("document."+ formName + "." + boxName + ".checked");
	}
}



function jumpMenu(targ,selObj,restore){
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function openWindow(theURL,winName,features) { //v2.0
  if(!features)
  {
      features="width=300,height=300,status=yes";
  }
  window.open(theURL,winName,features);
}


















// define Field isDate(); prototype
function _Field_isDate(mask){
	var strMask = _param(arguments[0], "mm/dd/yyyy");
	var iMaskMonth = strMask.lastIndexOf("m") - strMask.indexOf("m") + 1;
	var iMaskDay = strMask.lastIndexOf("d") - strMask.indexOf("d") + 1;
	var iMaskYear = strMask.lastIndexOf("y") - strMask.indexOf("y") + 1;

	var strDate = this.value;

	// find the delimiter
	var delim = "", lstMask = "mdy";
	for( var i=0; i < strMask.length; i++ ){
		if (lstMask.indexOf(strMask.substring(i, i+1)) == -1){
			delim = strMask.substring(i, i+1);
			break;
		}
  }
	aMask = strMask.split(delim);
	if( aMask.length == 3 ){
		dt = this.value.split(delim);
		if( dt.length != 3 ) this.error = "An invalid date was provided for " + this.description + " field.";
		for( i=0; i < aMask.length; i++ ){
			if( aMask[i].indexOf("m") > -1 ) var sMonth = dt[i];
			else if( aMask[i].indexOf("d") > -1 ) var sDay = dt[i];
			else if( aMask[i].indexOf("y") > -1 ) var sYear = dt[i];
		}
	} else if( mask.length == 1 ){
		var sMonth = this.value.substring(strMask.indexOf("m")-1, strMask.lastIndexOf("m"));
		var sDay = this.value.substring(strMask.indexOf("d")-1, strMask.lastIndexOf("d"));
		var sYear = this.value.substring(strMask.indexOf("y")-1, strMask.lastIndexOf("y"));
	} else {
		this.error = "An invalid date mask was provided for " + this.description + " field.";
	}

	var iMonth = parseInt(sMonth, 10);
	var iDay = parseInt(sDay, 10);
	var iYear = parseInt(sYear, 10);

	if( isNaN(iMonth) || sMonth.length > iMaskMonth ) iMonth = 0;
	if( isNaN(iDay) || sDay.length > iMaskDay ) iDay = 0;
	if( isNaN(sYear) || sYear.length != iMaskYear ) sYear = null;

	lst30dayMonths = ",4,6,9,11,";

	if( sYear == null ){
		this.error = "An invalid year was provided for the " + this.description + " field. The year \n   should be a " + iMaskYear + " digit number.";
	} else if(  (iMonth < 1) || (iMonth > 12 ) ){
		this.error = "An invalid month was provided for " + this.description + " field.";
	} else {
		if( iYear < 100 ) var iYear = iYear + ((iYear > 20) ? 1900 : 2000);
		var iYear = (sYear.length == 4) ? parseInt(sYear) : parseInt("20" + sYear);
		if( lst30dayMonths.indexOf("," + iMonth + ",") > -1 ){
			if( (iDay < 1) || (iDay > 30 ) ) this.error = "An invalid day was provided for the " + this.description + " field.";
		} else if( iMonth == 2 ){
			if( (iDay < 1) || (iDay > 28 && !( (iDay == 29) && (iYear%4 == 0 ) ) ) ) this.error = "An invalid day was provided for the " + this.description + " field.";
		} else {
			if( (iDay < 1) || (iDay > 31 ) ) this.error = "An invalid day was provided for the " + this.description + " field.";
		}
	}

}



