// JavaScript Document


var month;
var date;
var year;
var yearLength;
var hiddenYear,hiddenMonth,hiddenDate,hidden_txt,hidden;
var tempArray_year = new Array();
var tempArray_month = new Array();
var tempArray_date = new Array();

var colors=new Array();

colors['focus_on']='#EFF8D3';
colors['focus_off']='#ffffff';


function datepicker(date_id,given_date) {	
		
																
		dateTxt(date_id);																
		monthTxt(date_id);																
		yearTxt(date_id);																
		dateTxtChange(date_id);															
		monthTxtChange(date_id);														
		yearTxtChange(date_id);																	
		datepickerCalc(date_id);														
		hiddenTxtField(date_id);
		
		
		if(given_date){
			
			setCurrentDate(date_id,given_date);
				
		}else{
			
			currentYear(date_id);			
		}
		
		
}

function datepickerCalc(date_id) {														
			date =document.getElementById('dateTxt'+date_id).value;						
			month = document.getElementById('monthTxt'+date_id).value;				
			year = document.getElementById('yearTxt'+date_id).value;									 
}

function hiddenFunction(date_id) {																																				
																		
		datepickerCalc(date_id);														
		yearLength=year.length;															
		monthLength=month.length;														
		dateLength=date.length;															
		if(yearLength==1) {															
			 hiddenYear = document.getElementById('hiddenYear'+date_id).value=((200)+year);		
		}
		else if(yearLength==2) {														
			hiddenYear = document.getElementById('hiddenYear'+date_id).value=((20)+year);		
		}
		else if(yearLength==3) {														
			hiddenYear = document.getElementById('hiddenYear'+date_id).value=((2)+year);		
		}
		else {																			 
			hiddenYear = document.getElementById('hiddenYear'+date_id).value=year;
		}		
		if((monthLength==1) && (month!=0)) {															
			hiddenMonth = document.getElementById('hiddenMonth'+date_id).value=((0)+month);		
		}
		else {
			hiddenMonth = document.getElementById('hiddenMonth'+date_id).value=month;	
		}		
		if((dateLength==1) && (date!=0) ) {																 			
			hiddenDate = document.getElementById('hiddenDate'+date_id).value=((0)+date);		
		}
		else {
			hiddenDate = document.getElementById('hiddenDate'+date_id).value=date;		
		}		
		document.getElementById('yearTxt'+date_id).value=hiddenYear;					
		
		hidden = document.getElementById(date_id).value=hiddenYear+'-'+hiddenMonth+'-'+hiddenDate;	// Modified from hiddenText to Plain for easy data manipulation
    		
		
}



function monthFocus(date_id){
	
		date =document.getElementById('dateTxt'+date_id).value;							
		month = document.getElementById('monthTxt'+date_id);	
								
		if(date.length==2) {															
			month.focus();
		}	
}

function yearFocus(date_id) {
		month = document.getElementById('monthTxt'+date_id).value;			
		year = document.getElementById('yearTxt'+date_id);
		if(month.length==2) {
			year.focus();																
		}
}


function yearonFocus(date_id) {		
		
       document.getElementById('yearTxt'+date_id).style.backgroundColor=colors['focus_on'];
}

function yearonBlurevent(date_id) {
     document.getElementById('yearTxt'+date_id).style.backgroundColor=colors['focus_off'];
}

function yearonFocusevent(date_id) {
	year_onfocus = document.getElementById('yearTxt'+date_id).value; 	
	tempArray_year[0] =year_onfocus;
	year = document.getElementById('yearTxt'+date_id);	
	year.focus();	
	document.getElementById('yearTxt'+date_id).value="";
	year.style.backgroundColor=colors['focus_on'];
	
}	
function yearonBlurevent(date_id) {
	var year_onblur = document.getElementById('yearTxt'+date_id).value; 	
	if(year_onblur.length==0) {		
		document.getElementById('yearTxt'+date_id).value = year_onfocus;		
	}	
	document.getElementById('yearTxt'+date_id).style.backgroundColor=colors['focus_off'];
}


function monthonFocusevent(date_id) {	
	month_onfocus = document.getElementById('monthTxt'+date_id).value; 	
	tempArray_month[0] =month_onfocus;
	month = document.getElementById('monthTxt'+date_id);
	month.focus();
	document.getElementById('monthTxt'+date_id).value="";	
	month.style.backgroundColor=colors['focus_on'];
}

function monthonBlurevent(date_id) {
	var month_onblur =Number( document.getElementById('monthTxt'+date_id).value)+0; 	
	if((month_onblur.length==0) ||( month_onblur==0 )) {		
		document.getElementById('monthTxt'+date_id).value = month_onfocus;
		//tempArray[0]=month;		
	}
	
	document.getElementById('monthTxt'+date_id).style.backgroundColor=colors['focus_off'];
}

function dateonFocusevent(date_id) {	
	date_onfocus = document.getElementById('dateTxt'+date_id).value; 	
	tempArray_date[0] =date_onfocus;
	date = document.getElementById('dateTxt'+date_id);	
	document.getElementById('dateTxt'+date_id).value="";
	date.focus();
	date.style.backgroundColor=colors['focus_on'];

}

function dateonBlurevent(date_id) {
	var date_onblur =Number(document.getElementById('dateTxt'+date_id).value)+0; 	
	if ( (date_onblur.length == 0) || (date_onblur == 0) ) {
				
		document.getElementById('dateTxt'+date_id).value = date_onfocus;		
	}	

	document.getElementById('dateTxt'+date_id).style.backgroundColor=colors['focus_off'];
}

function currentYear(date_id) { 
	
		var db = new Array('0') ;
		var currentYear = new Date();
		var curr_date = currentYear.getDate();
		var curr_month= currentYear.getMonth();
		var curr_year = currentYear.getFullYear();
		
		if(curr_date < 10) {
			current_date = document.getElementById('dateTxt'+date_id).value =(db[0]+curr_date);
		}
		else  {
			current_date = document.getElementById('dateTxt'+date_id).value =curr_date;
		}
		if (curr_month < 9) {
			
			current_month = document.getElementById('monthTxt'+date_id).value = (db[0]+(curr_month+1));
		}
		else {
			current_month = document.getElementById('monthTxt'+date_id).value = curr_month+1;
		}
		
		var current_year = document.getElementById('yearTxt'+date_id).value = curr_year;
		hidden = document.getElementById(date_id).value=current_year +'-'+current_month+'-'+current_date;	
	
}		



function setCurrentDate(date_id,given_date){
	
	
		var given_date_detail=given_date.split('-');
	
		var current_date = document.getElementById('dateTxt'+date_id).value =given_date_detail[2];	
		
		var current_month = document.getElementById('monthTxt'+date_id).value =given_date_detail[1];
		
		var current_year = document.getElementById('yearTxt'+date_id).value =given_date_detail[0];	
		
		hidden = document.getElementById(date_id).value=current_year +'-'+current_month+'-'+current_date;	
	

}



function dateTxt(date_id) {		
	dateTxtbox = '<input style="width:20px;"  onKeyPress="return PR_All_Numeric(this);"  onbeforedeactivate="return PR_Value_Check(this,\'min\',32);"  onPaste="return PR_All_Numeric();"	 onchange="hiddenFunction(\''+date_id+'\');" onkeyup="monthFocus(\''+date_id+'\');"  onfocus="dateonFocusevent(\''+date_id+'\');" onblur="dateonBlurevent(\''+date_id+'\');" type="text" id="dateTxt'+date_id+'" name="dateTxt'+date_id+'" maxlength="2" size="2" value=""/><b>_</b>'; 
	document.write(dateTxtbox);		
}
function monthTxt(date_id) {	
	monthTxtbox = '<input style="width:20px"  onKeyPress="return PR_All_Numeric(this);"  onPaste="return PR_All_Numeric();"  onbeforedeactivate="return PR_Value_Check(this,\'min\',13);"   onfocus="monthonFocusevent(\''+date_id+'\');"  onchange="hiddenFunction(\''+date_id+'\');" onkeyup="yearFocus(\''+date_id+'\');" onblur="monthonBlurevent(\''+date_id+'\');" type="text" id="monthTxt'+date_id+'" name="monthTxt'+date_id+'" maxlength="2" size="2" value=""/><b>_</b>';
	document.write(monthTxtbox); 
}
function yearTxt(date_id) {	
	yearTxtbox = '<input style="width:40px"  onKeyPress="return PR_All_Numeric(this);"  onPaste="return PR_All_Numeric();"  onchange="hiddenFunction(\''+date_id+'\');" onfocus="yearonFocusevent(\''+date_id+'\');"  onblur="yearonBlurevent(\''+date_id+'\');"  type="text"  id="yearTxt'+date_id+'" name="yearTxt'+date_id+'"     maxlength="4" size="4" value=""     />';
	document.write(yearTxtbox); 	
}



function dateTxtChange(date_id) {	
	dateTxtbox = '<input  type="hidden"  id="hiddenDate'+date_id+'" name="hiddenDate'+date_id+'" maxlength="2" size="2" value="DD"/>';
	document.write(dateTxtbox); 	
}
function monthTxtChange(date_id) {	
	monthTxtbox = '<input  type="hidden"  id="hiddenMonth'+date_id+'" name="hiddenMonth'+date_id+'" maxlength="2" size="2" value="MM"/>';
	document.write(monthTxtbox); 	
}
function yearTxtChange(date_id) {	
	yearTxtbox = '<input  type="hidden"  id="hiddenYear'+date_id+'" name="hiddenYear'+date_id+'" maxlength="4" size="4" value="YYYY"/>';
	document.write(yearTxtbox); 	
}


function hiddenTxtField(date_id) {	
	hiddenTxtbox = '<input type="hidden"  id="'+date_id+'" name="'+date_id+'" />';   // Modified from hiddenText to Plain for easy data manipulation
	document.write(hiddenTxtbox);
}

