 

is = new BrowserCheck()
ThisDate=new Date();
var currentYear
var currentMonth = ThisDate.getMonth()+1
var currentDay = ThisDate.getDate()
if ( currentMonth < 10)
{
	currentMonth = "0" + currentMonth
}
if ( currentDay < 10)
{
	currentDay = "0" + currentDay
}
if ( is.ns )
{
	currentYear = ThisDate.getYear()+1900	
}
if ( is.ie )
{
	currentYear = ThisDate.getYear()
}
TodayDate=(currentYear)+"-"+currentMonth+"-"+currentDay
TDate=(currentDay)+"/"+currentMonth+"/"+currentYear
TodayPickupDate=(currentDay)+"/"+currentMonth+"/"+currentYear 


function fnCall()
{
	window.status = "Loading Calendar"
	var myCalendar = window.open( "/wpi/calendar.html", "myCalendar", "menubar =no,toolbar=no,status=no,directories=no,scrollbars=no,resizable=no,width=190,height=240")
}

function setDate( strDate )
{
	document.forms[0].PU_1_Date.value = strDate
	fnCheckDate(document.forms[0].PU_1_Date)
}

function fnCheckDate(text)
{
	var userdate = fnValidDate(text)
	if ( userdate != false )
	{

	var numHiDateValue = 950400000  
	var ThisDate = new Date(currentYear, currentMonth-1, currentDay)
	var numTodayDateSec = parseInt(ThisDate.getTime())

	var numHiDateSec = parseInt( numTodayDateSec + numHiDateValue )

	//check whether the date entered is greater than today and within next 11 days.
	 var newdate = new Date( userdate.substring(6,10), userdate.substring(3,5)-1, userdate.substring(0,2) )
	 var numNewDateSec = parseInt(newdate.getTime())
		 if ( (numNewDateSec < numTodayDateSec ) )
		 {
			alert("You cannot schedule pickups for past dates")
			text.value = currentDay + "/" + currentMonth + "/" + currentYear
			text.select()
			text.focus()
			return false
		 }

		 if ( ( numNewDateSec - numHiDateSec ) >= 0 )
		 {
			alert("You cannot schedule pickups for more than 10 days in advance ")
			text.value = currentDay + "/" + currentMonth + "/" + currentYear
			text.select()
			text.focus()
			return false

		 }
	}
	else
	{
		text.value = currentDay + "/" + currentMonth + "/" + currentYear
		text.select()
		text.focus()
		return false

	}
	return true
}



// the date can be in the following format (ddmmyy, ddmmyyyy, dd-mm-yy, dd-mm-yyyy, dd/mm/yy, dd/mm/yyyy)

function fnValidDate ( text)
{
	var numLengthDate = text.value.length
	var strDate  = text.value
// check for any other format other than [dd/mm/yy, dd-mm-yy, ddmmyy, dd/mm/yyyy, dd-mm-yyyy, ddmmyyyy]
	if ( text.value != "" )
	{
		var strCMonth 
		var strCDay 
		var strCYear
	 	var strMaxYear
		var strMinYear
		var iFirstIndex = -1
		var iLastIndex
		var strLength
		var strLeap
		var strFlag
		if( strDate.indexOf("-") != -1)
		{
			strFlag = 1
		}
		else
		{
			if ( strDate.indexOf("/") != -1)
			{
				strFlag = 2
			}
			else
			{
				strFlag =3
			}
		}

		// check for dd-mm-yy,dd-mm-yyyy, d-m-yy,d-m-yyyy format
		if( strFlag == 1)
		{
			iFirstIndex = strDate.indexOf("-")
			iLastIndex = strDate.lastIndexOf("-")
			if ( (iFirstIndex == iLastIndex) && (iLastIndex != -1))
			{
				alert("Invalid Date")
				text.value=""
				text.focus()
				return false
			}
			if( iFirstIndex != -1 ) 		
			{	
				strLength = strDate.length
				strCMonth = strDate.substring( iFirstIndex + 1, iLastIndex)

				if( strCMonth.length == 1)
				{
					strCMonth = "0" + strCMonth
				}
				strCDay   = strDate.substring(0,iFirstIndex)
			
				if( strCDay.length == 1)
				{
					strCDay = "0" + strCDay
				}
				else if ( strCDay.length > 2 )
				{
					alert("Invalid Date")
					text.value=""
					text.focus()
					return false
				}
				strCYear  = strDate.substring(iLastIndex+1,strLength)
				if (strCYear=="" )
				{
					alert("Invalid Date")
					text.value=""
					text.focus()
					return false
				}
				if( strCYear.length == 3)
				{
					alert("Invalid Date")
					text.value=""
					text.focus()
					return false
				}
				if( strCYear.length == 1)
				{
					strCYear = "0" + strCYear
				}
				strCYear  = fnCommonDateValid( strCDay, strCMonth , strCYear, text)						
				if(!strCYear)
				{
					text.value=""
					text.focus()
					return false
	
				}
			}
		}		
		// check for dd/mm/yy,dd/mm/yyyy, d/m/yy,d/m/yyyy format
		if( strFlag == 2)
		{
			iFirstIndex = strDate.indexOf("/")
			iLastIndex = strDate.lastIndexOf("/")
			if ( (iFirstIndex == iLastIndex) && (iLastIndex != -1))
			{
				alert("Invalid Date")
				text.value=""
				text.focus()
				return false

			}
			if( iFirstIndex != -1 ) 		
			{
				strLength = strDate.length
				strCMonth = strDate.substring( iFirstIndex + 1, iLastIndex)

				if( strCMonth.length == 1)
				{
					strCMonth = "0" + strCMonth
				}
				strCDay   = strDate.substring(0,iFirstIndex)
			
				if( strCDay.length == 1)
				{
					strCDay = "0" + strCDay
				}
				else if ( strCDay.length > 2 )
				{
					alert("Invalid Date")
					text.value=""
					text.focus()
					return false
				}
				strCYear  = strDate.substring(iLastIndex+1,strLength)
				if (strCYear=="" )
				{
					alert("Invalid Date")
					text.value=""
					text.focus()
					return false
				}
				if( strCYear.length == 3)
				{
					alert("Invalid Date")
					text.value=""
					text.focus()
					return false
				}
			
				if( strCYear.length == 1)
				{
					strCYear = "0" + strCYear
					
				}
				strCYear  = fnCommonDateValid( strCDay, strCMonth , strCYear, text)						
				if(!strCYear)
				{
					text.value=""
					text.focus()
					return false
	
				}				 
			}

		} 			
		// check for ddmmyy,ddmmyyyy
		if( strFlag == 3)
		{
				
			if((strDate.length < 6) ||(strDate.length > 8)||(strDate.length==7))
			{
				alert("Invalid Date")
				text.value=""
				text.focus()
				return false
			}
			if ( (iFirstIndex == -1) && ((strDate.length == 6) || (strDate.length == 8)))
			{
				if ( fnIsInteger(strDate))
				{
					alert("Invalid Date")
					text.value=""
					text.focus()
					return false
				}
				strLength = strDate.length
				strCDay   = strDate.substring(0,2)
				strCMonth = strDate.substring(2,4)
				strCYear  = strDate.substring(4,strLength)
			
				strCYear  = fnCommonDateValid( strCDay, strCMonth , strCYear, text)
				if(!strCYear)
				{
					text.value=""
					text.focus()
					return false
	
				}
			}
			
		}		
				
		// putting the correct date in the corresponding field
		text.value=( strCDay + "/" + strCMonth + "/" + strCYear )
		return  text.value 

 	}// end block text.value != ""
}
//END Function fnValiddate



	//validate month,day and year as number
	function fnCommonDateValid( strCDay, strCMonth, strCYear , text)	
	{
			var strLeap   =  strCYear%4    //to check strLeap year
			if ( fnIsInteger(strCMonth))
			{
				alert("Invalid Date - Month")
				return false
			}		
			
			if ( fnIsInteger(strCDay))
			{
				alert("Invalid Date - Day")
				return false
			}
		
			if ( fnIsInteger(strCYear))
			{
				alert("Invalid Date - Year")
				return false
			}
			if ((strCYear.length != 4 )&&(strCYear.length != 3 ))
			{
				strCYear = fnSlidingWindow( strCDay, strCMonth , strCYear , TDate)	
				
			}
			if(!(fnValidDay(strCDay , strCMonth , strLeap, text, strCYear)))
			{
					 
					return false
			}
			if(!(fnValidMonth(strCMonth, text)))
			{
					
				return false
			}
			if(!(fnValidYear(strCYear, text)))
			{
				
				return false
			}	
			return strCYear
	}



	function fnSlidingWindow( strCDay, strCMonth, strCYear, strCurrent)		
	{
		var strYY= strCurrent.substring(6,10)
		var strDD= strCurrent.substring(0,2)
		var strMM= strCurrent.substring(3,5)
		strMM = parseInt(strMM) -1
		

		var strMaxYear
		var strMinYear
		monthArray = new Array ( "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" )
		var strCurrentMonth = monthArray[strMM]
		var today = new Date(strCurrentMonth + " " + strDD + "," + strYY)// TDate in (month dd,yyyy) format
		var numMilCurrentDate = today.getTime()
	
		var strMonth 
		var minDate 
		var numMilMinDate
		var maxDate
		var numMilMaxDate
		var numMaxDiff
		var numMinDiff
		var strCurrentCentury
		var strCurrentYear
		var strCentury
		var strLastIndex = strCurrent.lastIndexOf("/")
		strCurrentCentury = strCurrent.substring( strLastIndex + 1 , strLastIndex + 3)
		strCurrentYear = strCurrent.substring( strLastIndex + 3, strLastIndex + 5)
		if ( strCurrentYear > "49")
		{
			strCentury = parseInt(strCurrentCentury) + 1
		}
		else 
		{
			strCentury = strCurrentCentury 
		}
				
		strMaxYear = strCentury + strCYear
		strMinYear = (strCentury - "1" ) + strCYear
		
		strMonth = monthArray[strCMonth - "1"]
		minDate = new Date ( strMonth +" "+ strCDay+", "+ strMinYear )
		numMilMinDate = minDate.getTime()
		
		maxDate = new Date ( strMonth +" "+ strCDay+", "+ strMaxYear ) 
		numMilMaxDate = maxDate.getTime()

		numMaxDiff = numMilMaxDate - numMilCurrentDate
		numMinDiff = numMilCurrentDate - numMilMinDate 
		if ( numMaxDiff > numMinDiff ) 
		{
	   		strCYear = (strCentury - "1" ) + strCYear 
	 	}
		else 
		{
  				strCYear = strCentury + strCYear 
	 	}
		return strCYear
	}


function fnValidMonth( strCMonth, text )	
		{
			if ( strCMonth <"01" || strCMonth > "12" )    //month validation
			{ 
				alert ( "Invalid Date - Month")
				text.value=""
				text.focus()
				return false
			}
			return true 	
		}


function fnValidYear( strCYear, text) 
{
			var strLength = strCYear.Length

			for ( i= 0; i < strLength; i++ )  // year validation
     		{ 
         	  	var str_onechar = strCYear.substring ( i, i+1 ) 
					if ( str_onechar < "0" || str_onechar > "9" )
					{ 
						alert ( "Invalid Date - Year" )
						text.value=""
				  		text.focus()	
				  		return	false
					}
			}

		  	if ( ( strCYear == "00") || ( strCYear == "0000") || (strCYear == "" ) ) // check to see that the year is not blank
			{
				alert ( "Invalid Date - Year cannot be blank" )
				text.value=""
				text.focus()	
		      return false
			}
			return true
		}
		


function fnValidDay( strCDay, strCMonth , strLeap , text, strCYear)	
		{      
			if((strCDay.length) >2)	
			{
			  		return 	false
			}
			if ( strCMonth == "02" )    // validation for FEB month 
			{ 
			   if ( strCDay > "28" )
      		{		
			   	if ( strCDay == "29" )
					{
				
							if ( strLeap  != "0" ) 	//check for leap year
							{			
								alert ( "Invalid Date - Not a Leap Year" )
								text.value=""
								text.focus()	
			      	 		return false
							}
		
							// check for century years
							if ( strCYear.substring(2,4) == "00" )
							{
					
								if ( strCYear%400 != "0" )
								{
									alert ( "Invalid Date - Not a Century Year" )
									text.value=""
									text.focus()	
		       					return false
	
								}
							}
						// end check for century year
				  }
		       
			 	 else	// date is greater than 29 i.e. it is a invalid day
		  		 
		  		  {
						alert( "Invalid date - Day greater than 29 invalid for February " )
						text.value=""
	        			text.focus()
				  		return 	false
		   	  }		
		  	}
		  	// end check for days more than 28
  	   }
		// end check for FEB month
	
			
		// check for Apr, Jun, Sept and Nov months		
		if ( strCMonth == "04" ||strCMonth == "06"|| strCMonth == "09"||strCMonth == "11" )
		{ 
			if ( strCDay > "30" )
      	                { 
				alert( "Invalid Date " )
				text.value=""
   	     			text.focus()
		    		return false
			 }
		}
		// end check for Apr, Jun, Sept and Nov months		
		if ( strCDay <"01" || strCDay > "31" )    //day validation
		{ 
			alert ( "Invalid Date")
			text.value=""
			text.focus()
			return false
		}
		return true
	}// end function fnValidDay




// to check that the text entered is in English
function fnCheckLanguage(field)
{
	var ch;
	for ( var i=0; i<field.value.length; i++ )
	{
		ch = field.value.charAt(i)
		if ( (ch >=' ' && ch<= '~') )
		{
		}
		else
		{
			alert("Please Enter English Characters only")
			field.value=""
			field.focus()
			return -1
		}
	}
}

// to check that the text entered is in English for Special Instructions field
function fnCheckLanguageSpcl(field)
{
	var ch;
	for ( var i=0; i<75; i++ )
	{
		ch = field.value.charAt(i)
		if ( (ch<= '~') )
		{
		}
		else
		{
			alert("Please Enter English Characters only")
			field.value=""
			field.focus()
			return -1
		}
	}
}


// This function is check the browser type and the version
// based on which the date handling changes. 
function BrowserCheck()
{
	var b = navigator.appName
	if (b=="Netscape") this.b = "ns"
	else if (b=="Microsoft Internet Explorer") this.b = "ie"
	else this.b = b
	this.v = parseInt(navigator.appVersion)
	this.ns = (this.b=="ns" && this.v>=4)
	this.ns4 = (this.b=="ns" && this.v==4)
	this.ns5 = (this.b=="ns" && this.v==5)
	this.ie = (this.b=="ie" && this.v>=4)
	this.ie4 = (navigator.userAgent.indexOf('MSIE 4')>0)
	this.ie5 = (navigator.userAgent.indexOf('MSIE 5')>0)
	if (this.ie5) this.v = 5
	this.min = (this.ns||this.ie)
	
}

// this function is to bring the focus to the previous page.
function fnBack()
{
	history.back()
}


// this function to bring the focus to the Main Schedule Pickup page
function fnMainPage()
{
	self.location.href="/wpi/wpi.jsp"
}

// this function calls the clear function to clear the fields and sets the
// focus to the first field on the screen. it also calls the function to set 
// the hidden field to the current date and time value.
function fnCallClear()
{

	if ( document.forms[1].formSubmit.value == 1 )
	{
		return
	}

	fnClear()
	fnFocus()

}

//this function is to set the focus on the OK button of the success page
function fnSetSuccessFocus()
{
	document.forms[0].ok_but.focus()
}

//this function is to set the focus on the Edit button of the error page
function fnSetErrorFocus()
{
	document.forms[0].edit_but.focus()
}

// this function clears the screen and brings the fields to the default value
function fnClear()
{
	document.forms[0].Req_1_AccNo.value=""
	document.forms[0].PL_1_CmpnyNm.value=""
	document.forms[0].PU_1_Pcs.value="1"
	document.forms[0].PU_1_CT_1_Nm.value=""
	document.forms[0].PU_1_WghtTot.value="0.5"
	document.forms[0].PU_1_CT_1_PhNo.value=""
	document.forms[0].PU_1_CT_1_PhExt.value=""
	document.forms[0].PL_1_Addr1.value=""
	document.forms[0].PL_1_Addr2.value=""
	document.forms[0].PL_1_City.value=""
	document.forms[0].PL_1_DvsnNm.value=""
	document.forms[0].PL_1_Lctn.value="Front Desk"
	document.forms[0].PL_1_PostCd.value=""
	document.forms[0].PU_1_SpclInstr.value=""

	numIdx = 0
	document.forms[0].PL_1_CtryCd.options[numIdx].selected = true

	numIdx = 0
	while ( document.forms[0].PL_1_LctnTyp.options[numIdx].value != "B" )
	{
		numIdx++ 
	}
	document.forms[0].PL_1_LctnTyp.options[numIdx].selected = true

	numIdx = 0
	while ( document.forms[0].cboCloseTimeHH.options[numIdx].value != "18" )
	{
		numIdx++ 
	}
	document.forms[0].cboCloseTimeHH.options[numIdx].selected = true

	numIdx = 0
	while ( document.forms[0].cboCloseTimeMM.options[numIdx].value != "00" )
	{
		numIdx++ 
	}
	document.forms[0].cboCloseTimeMM.options[numIdx].selected = true

	numIdx = 0
	while ( document.forms[0].cboReadyTimeHH.options[numIdx].value != "00" )
	{
		numIdx++ 
	}
	document.forms[0].cboReadyTimeHH.options[numIdx].selected = true

	numIdx = 0
	while ( document.forms[0].cboReadyTimeMM.options[numIdx].value != "00" )
	{
		numIdx++ 
	}
	document.forms[0].cboReadyTimeMM.options[numIdx].selected = true
	document.forms[0].PU_1_Date.value = TodayPickupDate

}


// this function gets only the first 75 characters of the text area field.
function getTextArea(field, maxSize)
{
    if ( fnIsEmpty(field) )
    {
        return 
    }

    var string = new String(field.value)

    if ( string.length > maxSize )
    {
        field.value = string.substr(0, maxSize)
    }

    return
}



// this function is to get the current date and time. 
// for netscape the date is added 1900 to get the date in YYYY format.
function currentdate()
{
	var currentHH = ThisDate.getHours()
	if ( currentHH < 10)
	{
		currentHH = "0" + currentHH
	}

	var currentMM = ThisDate.getMinutes()
	if ( currentMM < 10)
	{
		currentMM = "0" + currentMM
	}

	var currentSS = ThisDate.getSeconds()
	if ( currentSS < 10)
	{
		currentSS = "0" + currentSS
	}

	var currentMS = ThisDate.getMilliseconds()
	if ( currentMS < 10)
	{
		currentMS = "00" + currentMS
	}
	else
	{
		if ( currentMS < 100)
		{
			currentMS = "0" + currentMS
		}

	}
	var TimeTodayDate = TodayDate + " " + currentHH + ":" + currentMM + ":" + currentSS + "." + currentMS
	document.forms[1].MH_1_MsgTm.value = TimeTodayDate + "+08:00"
}


// this function is to validate the weight.
function fnValidateWeight()
{
	var numWeightEntered = document.forms[0].PU_1_WghtTot.value
	var numFirstPart = ''
	var numDecimalPart = ''
 	
	numDecimalIndex = numWeightEntered.indexOf(".")

	if (numDecimalIndex != -1)
	{
		numFirstPart = numWeightEntered.substring(0, numDecimalIndex)
		numDecimalPart = numWeightEntered.substring(numDecimalIndex+1)
		
		if (numFirstPart == '')
		{
			document.forms[0].PU_1_WghtTot.value = '0' + document.forms[0].PU_1_WghtTot.value 			
		}
		else
		{
			if ( ( fnIsInteger ( numFirstPart ) ) == -1 ) 
			{
	 			alert("Total Weight is a Numeric Field")
				document.forms[0].PU_1_WghtTot.select()
				document.forms[0].PU_1_WghtTot.focus()
 				return -1	   
	 		}
 			else if (numFirstPart.length > 4)
 			{
	 			alert("Maximum permissible Weight is 9999.9")
				document.forms[0].PU_1_WghtTot.select()
				document.forms[0].PU_1_WghtTot.focus()
 				return -1	   
	 		}
 		}

		if (numDecimalPart == '')
		{
			document.forms[0].PU_1_WghtTot.value += '0'
		}
		else
		 {
			if ( (fnIsInteger (numDecimalPart)) == -1)
			{		
	 			alert("Total Weight is a Numeric Field")
				document.forms[0].PU_1_WghtTot.select()
				document.forms[0].PU_1_WghtTot.focus()
 				return -1	   
			}
			else if (numDecimalPart.length > 1)
			{
				alert("Only one decimal place allowed.")
				document.forms[0].PU_1_WghtTot.select()
				document.forms[0].PU_1_WghtTot.focus()
 				return -1	   
			}
				
		}

	}
	
	else
	{
		if ((fnIsInteger(numWeightEntered)) == -1)
		{
	 		alert("Total Weight is a Numeric Field")
			document.forms[0].PU_1_WghtTot.select()
			document.forms[0].PU_1_WghtTot.focus()
 			return -1	   
		}
		else if (numWeightEntered.length > 4)
		{
	 			alert("Maximum permissible Weight is 9999.9")
				document.forms[0].PU_1_WghtTot.select()
				document.forms[0].PU_1_WghtTot.focus()
 				return -1	   
		}		
	}

	if ( document.forms[0].PU_1_WghtTot.value <= 0 )
	{
		alert("Zero Value not allowed")
		document.forms[0].PU_1_WghtTot.select()
		document.forms[0].PU_1_WghtTot.focus()
 		return -1	   
	}
}

// this function is to validate the total number of pieces.
function fnValidatePieces()
{
	if ( fnIsInteger( document.forms[0].PU_1_Pcs.value ) == -1 )
	{
		alert("Total Pieces is a Numeric Field")
		document.forms[0].PU_1_Pcs.select()
		document.forms[0].PU_1_Pcs.focus()
 		return -1	   
	}
	else
	{
		if ( document.forms[0].PU_1_Pcs.value <= 0 )
		{
			alert("Zero Value not allowed")
			document.forms[0].PU_1_Pcs.select()
			document.forms[0].PU_1_Pcs.focus()
 			return -1	   

		}
	}
}


// this function validates the page before submitting the form
function validatePage()
{
	if ( document.forms[1].formSubmit.value == 1 )
	{
		return
	}

	if ( fnIsEmpty(document.forms[0].PU_1_Date) )
	{
		alert ("Pickup Date is a required field")
		document.forms[0].PU_1_Date.focus()
		return
	}
	else
	{
		if( !(fnCheckDate(document.forms[0].PU_1_Date)) )
		{
			return
		}
	}
	if( !(validatePickupTime()) )
	{
		return
	}

	if ( fnIsEmpty(document.forms[0].Req_1_AccNo) )
	{
		alert ("Account is a required field")
		document.forms[0].Req_1_AccNo.focus()
		return
	}
	else
	{
		var numInteger = document.forms[0].Req_1_AccNo.value
		if ( fnIsInteger( numInteger ) == -1 )
		{
			alert ("Account Number is a Numeric field")
			document.forms[0].Req_1_AccNo.select()
			document.forms[0].Req_1_AccNo.focus()
			return
		}
		else
		{
			if (document.forms[0].Req_1_AccNo.value.length < 9 )
			{
				alert ("Account Number is a 9 digit field")
				document.forms[0].Req_1_AccNo.select()
				document.forms[0].Req_1_AccNo.focus()
				return
			}
		}
	}

	if ( fnIsEmpty(document.forms[0].PU_1_CT_1_Nm) )
	{
		alert ("Contact is a required field")
		document.forms[0].PU_1_CT_1_Nm.focus()
		return
	}
	else
	{
		if ( fnCheckLanguage(document.forms[0].PU_1_CT_1_Nm) == -1 )
		{
			return
		}
	}

	if ( fnIsEmpty(document.forms[0].PU_1_CT_1_PhNo) )
	{
		alert ("Phone is a required field Please enter")
		document.forms[0].PU_1_CT_1_PhNo.focus()
		return
	}
	else
	{
		if ( fnCheckLanguage(document.forms[0].PU_1_CT_1_PhNo) == -1 )
		{
			return
		}
	
	}

	if ( fnIsEmpty(document.forms[0].PL_1_Addr1) )
	{
		alert ("Address is a required field")
		document.forms[0].PL_1_Addr1.focus()
		return
	}
	else
	{
		if ( fnCheckLanguage(document.forms[0].PL_1_Addr1) == -1 )
		{
			return
		}
	
	}

	if ( fnIsEmpty(document.forms[0].PL_1_City) )
	{
		alert ("City is a required field")
		document.forms[0].PL_1_City.focus()
		return
	}
	else
	{
		if ( fnCheckLanguage(document.forms[0].PL_1_City) == -1 )
		{
			return
		}
	
	}

	if ( ! (fnIsEmpty(document.forms[0].PU_1_SpclInstr) ) )
	{
		var string = new String(document.forms[0].PU_1_SpclInstr.value)
		if ( string.length > 75 )
		{
			if ( (confirm("Special Instructions has more than 75 characters. Only the first 75 characters will be accepted. Would you like to change the message ?" ) ) )
			{
				document.forms[0].PU_1_SpclInstr.select()
				document.forms[0].PU_1_SpclInstr.focus()
				return
			}
			else
			{
        			document.forms[0].PU_1_SpclInstr.value = string.substr(0,75)

			}
		}
		if ( fnCheckLanguageSpcl(document.forms[0].PU_1_SpclInstr) == -1 )
		{
			return
		}
	}

	if ( fnIsEmpty(document.forms[0].PL_1_Lctn) )
	{
		alert ("Location of Packages is a required field")
		document.forms[0].PL_1_Lctn.focus()
		return
	}
	else
	{
		if ( fnCheckLanguage(document.forms[0].PL_1_Lctn) == -1 )
		{
			return
		}
	
	}

	if ( fnIsEmpty(document.forms[0].PU_1_Pcs) )
	{
		alert ("Pieces is a required field")
		document.forms[0].PU_1_Pcs.focus()
		return
	}
	else
	{
		if( fnValidatePieces() == -1 )
		{
			return
		}
	}

	if ( fnIsEmpty(document.forms[0].PU_1_WghtTot) )
	{
		alert ("Weight is a required field")
		document.forms[0].PU_1_WghtTot.focus()
		return
	}
	else
	{
		if( fnValidateWeight() == -1 )
		{
			return
		}
	}

	if ( fnCheckLanguage(document.forms[0].PL_1_CmpnyNm) == -1 )
	{
		return
	}
	

	if ( fnCheckLanguage(document.forms[0].PU_1_CT_1_PhExt) == -1 )
	{
		return
	}


	if ( fnCheckLanguage(document.forms[0].PL_1_Addr2) == -1 )
	{
		return
	}

	if ( fnCheckLanguage(document.forms[0].PL_1_DvsnNm) == -1 )
	{
		return
	}

	if ( fnCheckLanguage(document.forms[0].PL_1_PostCd) == -1 )
	{
		return
	}
        

	fnFillFormSubmit()
	document.forms[1].formSubmit.value = 1
	document.forms[1].submit()


}

// this function is to fill the values in th form that has to be submitted.
function fnFillFormSubmit()
{
	document.forms[1].Req_1_AccNo.value = document.forms[0].Req_1_AccNo.value

	document.forms[1].PL_1_LctnTyp.value = document.forms[0].PL_1_LctnTyp.options[document.forms[0].PL_1_LctnTyp.selectedIndex].value
	document.forms[1].PL_1_CmpnyNm.value = document.forms[0].PL_1_CmpnyNm.value
	document.forms[1].PL_1_Addr1.value = document.forms[0].PL_1_Addr1.value
	document.forms[1].PL_1_Addr2.value = document.forms[0].PL_1_Addr2.value
	document.forms[1].PL_1_Lctn.value = document.forms[0].PL_1_Lctn.value
	document.forms[1].PL_1_City.value = document.forms[0].PL_1_City.value
	document.forms[1].PL_1_CtryCd.value = document.forms[0].PL_1_CtryCd.options[document.forms[0].PL_1_CtryCd.selectedIndex].value
	document.forms[1].PL_1_DvsnNm.value = document.forms[0].PL_1_DvsnNm.value
	document.forms[1].PL_1_PostCd.value = document.forms[0].PL_1_PostCd.value

	fnGetPickupDate()
	document.forms[1].PU_1_Pcs.value = document.forms[0].PU_1_Pcs.value
	document.forms[1].PU_1_WghtTot.value = document.forms[0].PU_1_WghtTot.value
	document.forms[1].PU_1_SpclInstr.value = document.forms[0].PU_1_SpclInstr.value
	if (document.forms[1].PU_1_SpclInstr.value.length > 75 )
	{
		document.forms[1].PU_1_SpclInstr.value = document.forms[1].PU_1_SpclInstr.value.substring(0,75)
	}
	document.forms[1].PU_1_CT_1_Nm.value = document.forms[0].PU_1_CT_1_Nm.value
	document.forms[1].PU_1_CT_1_PhNo.value = document.forms[0].PU_1_CT_1_PhNo.value
	document.forms[1].PU_1_CT_1_PhExt.value = document.forms[0].PU_1_CT_1_PhExt.value
	//Added by Prashant
	if ( document.forms[1].MH_1_MsgTm.value == "" || document.forms[1].MH_1_MsgTm.value == null )
	{
		currentdate()
	}
}

function fnGetPickupDate()
{
	var strPickupDate = document.forms[0].PU_1_Date.value

	var strCurrentDay = strPickupDate.substring(0,2)
	var strCurrentMonth = strPickupDate.substring(3,5)
	var strCurrentYear = strPickupDate.substring(6,10)

	document.forms[1].PU_1_Date.value = strCurrentYear + "-" + strCurrentMonth + "-" + strCurrentDay

}


// this function is to check whether the input field is numeric 
function fnIsInteger( value )
{
	for ( var numCtr = 0 ; numCtr < value.length; numCtr++ )
	{
		var numChar = value.charAt(numCtr)
		if( ( numChar < "0" ) || ( numChar > "9" ) )
		{
			return -1
		}
	}

}



// this function is to check whether the field is empty.
function fnIsEmpty(field)
{
    fnRemoveSpace(field) // to remove the leading and trailing spaces.
    var strInput = field.value

    if ( strInput == null || strInput == "" ) 
    {
        return true
    }

    return false

}

// this function is to remove the leading and the trailing spaces in 
// any field.
function fnRemoveSpace( field )
{
	var numCtr, numLength, numIndex
	numLength = field.value.length  
	if (numLength == 0)            
	{                            
		return               
	}                        
	for ( numCtr = 0; numCtr < numLength ; numCtr++ )
	{                                 
	   numIndex = (numLength - numCtr - 1)
	   if ((field.value).charAt(numIndex) != " " )
           {                         
	      field.value = (field.value).substring(0,(numIndex + 1))
	      break             
           }
	   if ( numCtr == numLength -1 )
	   {
		field.value=""
	   }
	}
	numLength = field.value.length
	if ( numLength != 0 )
	{
		for ( numCtr = 0 ; numCtr < numLength ; numCtr++ )
		{
			if((field.value).charAt(numCtr) !=  " ")
			{
				field.value = (field.value).substring(numCtr,numLength)
				break
			}
			if (numCtr == numLength - 1)
			{
				field.value = ""
			}

		}
	}
}                         



// function to bring the initial focus to the first field on the page
function fnFocus()
{
	currentdate()
	fnSetTime()
	if ( document.forms[0].PU_1_Date.value == "" )
	{
		document.forms[0].PU_1_Date.value = TodayPickupDate
	}
	document.forms[0].Req_1_AccNo.focus()
	document.forms[1].formSubmit.value = "0"
}

// this function is to set the field as per the current time
function fnSetTime()
{

    var numCurrentDate = new Date()
	var requestTmHH = numCurrentDate.getHours()
	var requestTmMM = numCurrentDate.getMinutes()

    var HHInd = document.forms[0].cboReadyTimeHH.selectedIndex    
    var MMInd = document.forms[0].cboReadyTimeMM.selectedIndex    

    var readyTmHH = parseInt(document.forms[0].cboReadyTimeHH[HHInd].text)
    var readyTmMM = parseInt(document.forms[0].cboReadyTimeMM[MMInd].text)

	if ( (readyTmHH == 0) && (readyTmMM == 0 ) )
	{
	var numIdx = 0
	while ( document.forms[0].cboReadyTimeHH.options[numIdx].value != requestTmHH )
	{
		numIdx++ 
	}
	document.forms[0].cboReadyTimeHH.options[numIdx].selected = true

	var numIdx = 0
	while ( document.forms[0].cboReadyTimeMM.options[numIdx].value != requestTmMM )
	{
		numIdx++ 
	}
	document.forms[0].cboReadyTimeMM.options[numIdx].selected = true
	document.forms[0].PU_1_Date.value = TodayPickupDate
	}


}


// function to validate the pick up time
function validatePickupTime() 
{

    var pickupDate = document.forms[0].PU_1_Date.value

	var numCurrentDate = new Date()

	var requestTmHH = numCurrentDate.getHours()

	var requestTmMM = numCurrentDate.getMinutes()

    var HHInd = document.forms[0].cboReadyTimeHH.selectedIndex    

    var MMInd = document.forms[0].cboReadyTimeMM.selectedIndex    

    var readyTmHH = parseInt(document.forms[0].cboReadyTimeHH[HHInd].text)

    var readyTmMM = parseInt(document.forms[0].cboReadyTimeMM[MMInd].text)


    var HHInd = document.forms[0].cboCloseTimeHH.selectedIndex    

    var MMInd = document.forms[0].cboCloseTimeMM.selectedIndex    

    var closeTmHH = parseInt(document.forms[0].cboCloseTimeHH[HHInd].text)

    var closeTmMM = parseInt(document.forms[0].cboCloseTimeMM[MMInd].text)


	if ( pickupDate != TodayPickupDate )
	{
		if(!( (readyTmHH < closeTmHH) || ( (readyTmHH==closeTmHH) && (readyTmMM <= closeTmMM) ) ) )
		{
			alert("Ready Time must be earlier than or same as the Closing Time")
			document.forms[0].cboReadyTimeHH.focus()
			return false
		}
	}
	else
	{

	if ( !( (requestTmHH < (closeTmHH -1))  || ( (requestTmHH == (closeTmHH - 1)) && ( requestTmMM <= closeTmMM )) ) )
	{
		alert("Pickup request must be at least 1 hour before closing Time")
		document.forms[0].cboCloseTimeHH.focus()
		return false
	}

	if ( !( (requestTmHH<readyTmHH ) || ( (requestTmHH == readyTmHH) && (requestTmMM < readyTmMM) ) ) )
	{
		alert("Ready Time must be greater than Current Time")
		document.forms[0].cboReadyTimeHH.focus()
		return false

	}

	if(!( (readyTmHH < closeTmHH) || ( (readyTmHH==closeTmHH) && (readyTmMM <= closeTmMM) ) ) )
	{
		alert("Ready Time must be earlier than or same as the Closing Time")
		document.forms[0].cboReadyTimeHH.focus()
		return false
	}
	}
	if ( readyTmHH < 10 )
	{
		readyTmHH = "0" + readyTmHH
	}
	if ( readyTmMM < 10 )
	{
		readyTmMM = "0" + readyTmMM
	}
	if ( closeTmHH < 10 )
	{
		closeTmHH = "0" + closeTmHH
	}
	if ( closeTmMM < 10 )
	{
		closeTmMM = "0" + closeTmMM
	}

 	var ReadyTime = readyTmHH + ":" + readyTmMM
	var CloseTime = closeTmHH + ":" + closeTmMM

	document.forms[1].PU_1_RdyByTm.value = ReadyTime
	document.forms[1].PU_1_ClsTm.value = CloseTime

    return true

}

