function vtanggal(field,required)
{ 
    if (field.value.length>=6)
    {
		var month,day,year;
		if (field.value.indexOf("/") == -1 && field.value.indexOf("-") == -1)
		{
			var l = field.value.length;
			day = parseInt(field.value.substr(0,2-l%2),10);
			month = parseInt(field.value.substr(2-l%2,2),10);
			year = parseInt(field.value.substr(4-l%2),10);
		}
		else
		{	var comps;
			if (field.value.indexOf("/") != -1)
				comps = field.value.split("/");
			else
				comps = field.value.split("-");
			day = parseInt(comps[0],10);
			year = parseInt(comps[2],10);
			month = parseInt(comps[1],10);
		}
		if (month >= 1 && month <= 12 && day >= 1 && day <=31 && ((year >= 0 && year < 100) || (year>1800  && year <2079)))
		{
			if (year < 50)
			year += 2000;
			else if (year < 100)
			year += 1900;
			if (month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12) 
			{ 
              if (day > 31) 
			  {
				alertfocus("Date is invalid",field,"text");				
				return false;
			  }
			}
			if (month==4 || month==6 || month==9 || month==11) 
			{ 
              if (day > 30) 
			  {
				alertfocus("Date is invalid",field,"text");				
				return false;
			   }
			}
            if (month==2)
 			{
			if ((((year + 2000) % 4)==0) && (((year + 2000) % 400)!=0) || (((year+ 2000) % 400)==0))
			{
				if (day > 29)
				{
					alertfocus("Date is invalid",field,"text");				
					return false;
			  	}
			}
			else
			{
				if (day > 28)
				{
					alertfocus("Date is invalid",field,"text");				
					return false;
				}
			}
			}
			if(month.toString().length==1)
				month = '0' + month.toString()

			if(day.toString().length==1)
				day = '0' + day.toString()
				
			field.value = day+'/'+month+'/'+year;
		}
		else
		{
			alertfocus("Format tanggal salah (format tanggal yg benar DD/MM/YY or DD/MM/YYYY)",field,"text");				
			return false;
		}
   }
   else
   { 
		if (required || field.value!='')
		{
			alertfocus("Format tanggal salah",field,"text");				
			return false;
		}
   }
   return true;	
}
function alertfocus(msg,field,type)
{
	alert(msg);
	setfocus(field,type);
}
function setfocus(object,type)
{ 
	ieb=(document.all)?true:false;
	nsb=(document.layers)?true:false;

	if ((object.disabled==false && ieb==true)||(nsb==true))
	{
		
		switch(type)
		{
			case "combo" : object.selectedIndex=0; object.focus(); break;
			case "text"  : object.focus(); object.select(); break;
			default : object.focus();
		}
	}
}
function DateAdd(startDate, numDays, numMonths, numYears)
{
	var returnDate = new Date(startDate.getTime());
	var yearsToAdd = numYears;
	
	var month = returnDate.getMonth()	+ numMonths;
	if (month > 11)
	{
		yearsToAdd = Math.floor((month+1)/12);
		month -= 12*yearsToAdd;
		yearsToAdd += numYears;
	}
	returnDate.setMonth(month);
	returnDate.setFullYear(returnDate.getFullYear()	+ yearsToAdd);
	
	returnDate.setTime(returnDate.getTime()+60000*60*24*numDays);
	
	return returnDate;

}

function suycDateDiff( start, end, interval, rounding ) {

    var iOut = 0;
    
    var startMsg = "Check the Start Date and End Date\n"
        startMsg += "must be a valid date format.\n\n"
        startMsg += "Please try again." ;
		
    var intervalMsg = "Sorry the dateAdd function only accepts\n"
        intervalMsg += "d, h, m OR s intervals.\n\n"
        intervalMsg += "Please try again." ;

    var bufferA = Date.parse( start ) ;
    var bufferB = Date.parse( end ) ;
    	
    if ( isNaN (bufferA) || isNaN (bufferB) ) {
        alert( startMsg ) ;
        return null ;
    }
	
    if ( interval.charAt == 'undefined' ) {
        alert( intervalMsg ) ;
        return null ;
    }
    
    var number = bufferB-bufferA ;
    
    switch (interval.charAt(0))
    {
        case 'd': case 'D': 
            iOut = parseInt(number / 86400000) ;
            if(rounding) iOut += parseInt((number % 86400000)/43200001) ;
            break ;
        case 'h': case 'H':
            iOut = parseInt(number / 3600000 ) ;
            if(rounding) iOut += parseInt((number % 3600000)/1800001) ;
            break ;
        case 'm': case 'M':
            iOut = parseInt(number / 60000 ) ;
            if(rounding) iOut += parseInt((number % 60000)/30001) ;
            break ;
        case 's': case 'S':
            iOut = parseInt(number / 1000 ) ;
            if(rounding) iOut += parseInt((number % 1000)/501) ;
            break ;
        default:
        alert(intervalMsg) ;
        return null ;
    }
    
    return iOut ;
}
function numbersonly()
{
	if (event.keyCode<44 || event.keyCode>57) 
	{
		return false;
	} 
	else 
	{
		return true;
	}	
 }

