//////////////////////////////////////////////////////////////////////
//check year valid range
function check_year(dateform) {
	year=dateform.y.value;
	if (year > 0 && year < 4000){
		return (true);
	}
	alert("Invalid Year ! Please enter year between 1 and 3999");
	return (false);
}
//////////////////////////////////////////////////////////////////////
//popup window
function popup(width, height, url){
		pLeft=(screen.width/2)-(width/2);
		PTop=(screen.height/2)-(height/2);
		fullev=window.open(url,"fulleventwindow",	"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width="+width+",height="+height+",left="+pLeft+",top="+PTop);
		fullev.document.focus();
}
//////////////////////////////////////////////////////////////////////
//show popup
	var popup_layer="popup1";//the popup window (div) name 
	function update_date(popupdiv){
		popup_layer=popupdiv;
		displaypopup();
	}
	
	function displaypopup(){	
		//hide selection combo boxes
		hideselect();
		
		document.getElementById("popup_overlay").style.display="block";
		overlaysize();
		
		document.getElementById(popup_layer).style.display="block";
		
		//repositionpopup();
		popup_position();
	}
	
	function hidepopup(){
		document.getElementById("popup_overlay").style.display="none";
		document.getElementById(popup_layer).style.display="none";
		
		//show selection combo boxes
		showselect();		
	}
	
	//this function to hide all the selection combo boxes [since it always overlaps the layers over it i.e displays over it]
	function hideselect(){
		selectboxes=document.getElementsByTagName("SELECT");
		for(i=0; i<selectboxes.length; i++){
			selectboxes[i].style.visibility="hidden";
		}
	}
	//show the select combo boxes
	function showselect(){
		selectboxes=document.getElementsByTagName("SELECT");
		for(i=0; i<selectboxes.length; i++){
			selectboxes[i].style.visibility="visible";
		}
	}
	
	//this function to resize the overlay
	function overlaysize(){
		if (window.innerHeight && window.scrollMaxY || window.innerWidth && window.scrollMaxX) {	
			yScroll = window.innerHeight + window.scrollMaxY;
			xScroll = window.innerWidth + window.scrollMaxX;
			var deff = document.documentElement;
			var wff = (deff&&deff.clientWidth) || document.body.clientWidth || window.innerWidth || self.innerWidth;
			var hff = (deff&&deff.clientHeight) || document.body.clientHeight || window.innerHeight || self.innerHeight;
			xScroll -= (window.innerWidth - wff);
			yScroll -= (window.innerHeight - hff);
		} else if (document.body.scrollHeight > document.body.offsetHeight || document.body.scrollWidth > document.body.offsetWidth){ // all but Explorer Mac
			yScroll = document.body.scrollHeight;
			xScroll = document.body.scrollWidth;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			yScroll = document.body.offsetHeight;
			xScroll = document.body.offsetWidth;
		}

		document.getElementById("popup_overlay").style.width=xScroll;
		document.getElementById("popup_overlay").style.height=yScroll;
	}
	
	//this function to position the popup in the middle of the screen
	function popup_position() {
		//recalculate overlay size
		overlaysize();
		
		TB_WIDTH=document.getElementById(popup_layer).offsetWidth;
		TB_HEIGHT=document.getElementById(popup_layer).offsetHeight;
		
		var pagesize = TB_getPageSize();	
		var arrayPageScroll = TB_getPageScrollTop();
		/*var style = {width: TB_WIDTH, left: (arrayPageScroll[0] + (pagesize[0] - TB_WIDTH)/2), top: (arrayPageScroll[1] + (pagesize[1]-TB_HEIGHT)/2)};
		document.getElementById(popup).css(style);*/
		 document.getElementById(popup_layer).style.top=arrayPageScroll[1] + (pagesize[1]-TB_HEIGHT)/2;
		 document.getElementById(popup_layer).style.left=arrayPageScroll[0] + (pagesize[0] - TB_WIDTH)/2;		
	}
	
	function TB_getPageScrollTop(){
		var yScrolltop;
		var xScrollleft;
		if (self.pageYOffset || self.pageXOffset) {
			yScrolltop = self.pageYOffset;
			xScrollleft = self.pageXOffset;
		} else if (document.documentElement && document.documentElement.scrollTop || document.documentElement.scrollLeft ){	 // Explorer 6 Strict
			yScrolltop = document.documentElement.scrollTop;
			xScrollleft = document.documentElement.scrollLeft;
		} else if (document.body) {// all other Explorers
			yScrolltop = document.body.scrollTop;
			xScrollleft = document.body.scrollLeft;
		}
		arrayPageScroll = new Array(xScrollleft,yScrolltop) 
		return arrayPageScroll;
	}
	
	function TB_getPageSize(){
		var de = document.documentElement;
		var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
		var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight
		arrayPageSize = new Array(w,h) 
		return arrayPageSize;
	}

		//reposition the popup window after page resize
		onresize=popup_position;
		//onresize=repositionpopup;
				
		//reposition window on page scroll		
		onscroll=popup_position;
		//onscroll=repositionpopup;