	// function to popup a window
		function NewWindow(mypage, myname, w, h, sscroll) 
		{
			var winl = (screen.width - w)/2;
			var wint = (screen.height - h)/2;
			winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+sscroll+',resizable';
			 win=window.open(mypage, myname, winprops);

			if (parseInt(navigator.appVersion) >= 4) { 
				win.window.focus(); 
			}//end if
		}// end of function
      // function  to swap color on mouse over table
		function chTdBg(tdID,oldcolor)
		{ 

			if (document.getElementById(tdID).bgColor== oldcolor){
					document.getElementById(tdID).bgColor= "#003366";
			}
			else{
				document.getElementById(tdID).bgColor = oldcolor;
			}// end if
		}// end function

function getWeek(year,month,day){
    //lets calc weeknumber the cruel and hard way :D
    //Find JulianDay 
    month += 1; //use 1-12
    var a = Math.floor((14-(month))/12);
    var y = year+4800-a;
    var m = (month)+(12*a)-3;
    var jd = day + Math.floor(((153*m)+2)/5) + 
                 (365*y) + Math.floor(y/4) - Math.floor(y/100) + 
                 Math.floor(y/400) - 32045;      // (gregorian calendar)
    //var jd = (day+1)+Math.Round(((153*m)+2)/5)+(365+y) + 
    //                 Math.round(y/4)-32083;    // (julian calendar)
    
    //now calc weeknumber according to JD
    var d4 = (jd+31741-(jd%7))%146097%36524%1461;
    var L = Math.floor(d4/1460);
    var d1 = ((d4-L)%365)+L;
    NumberOfWeek = Math.floor(d1/7) + 1;
    return NumberOfWeek;        
}
//=====================================================================================================
function CheckKeypressAcceptDateValueOnly(e)
{
	//alert(event.keyCode);
	if (e.keyCode < 47 || e.keyCode > 57)
	{
		e.returnValue = false;
		alert("คุณสามารถกรอกข้อมูลเป็นตัวเลขตั้งแต่ 0-9 และ '/' เท่านั้น  เช่น \"2005/08/01\"");
		//alert("Please enter ( 0-9 and '/' ) only.");
	}
}
function calculateRangeDate( strStartDate,  objTarget )
{
	//alert(strStartDate.value);
	//alert(strEndDate.value);
	strEndDate.value = "2007/12/31";
	if ( strStartDate.value != "" && strEndDate.value != "" )
	{
		var strSDate = new String(strStartDate.value) ;
		var strEDate =new String(strEndDate.value) ;

		if( ( strStartDate.value.length < 3 ) && ( strEndDate.value.length < 3 ) )
		{
			totalDays = "" ;
			if (objTarget.value == "" )
			{
				objTarget.value =  totalDays ;
			}
			return ;
		}

		var arr_startdate = strSDate.split('/');
		var arr_enddate = strEDate.split('/');
		
		if ( ( arr_startdate.length != 3 ) && ( arr_enddate.length != 3 ) )
		{
			totalDays = "" ;
			if (objTarget.value == "" )
			{
				objTarget.value =  totalDays ;
			}
			return ;
		}
		
		var sDate = arr_startdate[1] + "/" + arr_startdate[2] + "/" + arr_startdate[0]
		var eDate =arr_enddate[1] + "/" + arr_enddate[2] + "/" + arr_enddate[0]
		var startDate = new  Date(sDate) ;
		var endDate = new  Date(eDate) ;
		var millisecondPerDay = 86400000 ;
		var diffDate, resultDiffDate, totalDays, intPosPoint ;
		//alert( strStartDate + " ==> " + strEndDate ) ;
		//alert( startDate + " ==> " + endDate ) ;
		diffDate = endDate - startDate    //difference in milliseconds
		iResultDiffDate  = diffDate/millisecondPerDay//calculate days 
		//alert( "  ==> " + iResultDiffDate ) ;
		if( iResultDiffDate >= 0 )
		{
			iResultDiffDate = iResultDiffDate + 1 ;
		}
		resultDiffDate = new String(iResultDiffDate)  ;  // convert number to string
		//alert( "  ==> " + resultDiffDate ) ;
		intPosPoint = resultDiffDate.indexOf(".") ;   //find the decimal point
	    point = new String(intPosPoint)  ;
		//alert( " Position Point ==> '" + intPosPoint + "'" ) ;
		if( intPosPoint != -1 )
		{
			totalDays = resultDiffDate.substring(0,intPosPoint)  ; //get just the whole days
			//alert( "1 Total  Days ==> " + totalDays ) ;
		}
		else
		{
			totalDays = resultDiffDate
			//alert( "2 Total  Days ==> " + totalDays ) ;
		}

		if(isNaN(totalDays))
		{
			if (objTarget.value == "" )
			{
				totalDays = "" ;
			}
			else
			{
				totalDays = objTarget.value ;
			}
		}
	}
	else
	{
		if (objTarget.value == "" )
		{
			totalDays = "" ;
		}
		else
		{
			totalDays = objTarget.value ;
		}
	}
	objTarget.value =  totalDays ;
	//alert( "Total  Days ==> " + totalDays ) ;
	return ;
}
//=====================================================================================================
function toggleCheckBoxes(formName)   {
// toggle Check Boxes using Prototype Library
	var form=$(formName);
	var i=form.getElements('checkbox');
	i.each(function(item)
		{
		if (item.checked){
			item.checked=false;
		}
		else {
			item.checked=true;
		}
		}
	);
} 

// required prototype --