<!--
/*================================================================================
'	Validation
'
'	Purpose:	This include is used for form validation. The Validate() function is used
'				for client side	validation. 
'
'	Developer		Date			Change
'------------------------------------------------------------------------------
'	Chuck Smith		6/29/2001		Added Date type processing
'	Ron Spulick		6/17/2002		Added trim to date type
'	Chuck Rann		12/6/2002		Added ver 3 specs to validateprints
'	Byron Braxton		08/05/2003		Modified checkEmail to all more TLDs (CR# 65)
'=================================================================================*/
var bValidationOn = true;
var bBark = true;
var bNoBubble = false;
var mbClicked;
function validate(sFormName)
{


	if (bValidationOn == false)
	{
		return true;
	}
	var strConName,strConDesc,strConType,boolReq,objControl,strConValue,strErrMsg="";
	var sTimeErrMsg,sPhoneErrMsg,sCanZipErrMsg;
	
	var objDate;
	var strSpecialChars;
	
	strSpecialChars = '"`~\\!@#$%^&*()_-+={[}]|:;<,>.?/'
	strSpecialChars2 = '"`~\\!@#$%^&*()_+={[}]|:;<,>.?/'
	strSpace = ' '

	var oForm;
	if (sFormName == '')
		{
		oForm = document.forms[0];
		}
	else
		{
		for(i=0;i<document.forms.length;i++)
			{
			if (document.forms[i].name == sFormName)
				{
				oForm = document.forms[i];
				}
			}
		if (oForm == null)
			{
			oForm = document.forms[0];
			}
		}

	for(i=0;i<Elements.length;i++)
	{
		
		strConName=Elements[i][0];
		strConDesc=Elements[i][1];
		strConType=Elements[i][2];
		boolReq=Elements[i][3];
		objControl=oForm.elements[strConName];
		if(objControl==null)
		{
			/* Don't return an error if the control doesn't exist*/
			boolReq=false;
		}		
		
		if(boolReq=="True")
		{
			boolReq=true;
		}
		else
		{
			boolReq=false;
		}
		
		/*if(boolReq)
		{
			alert(strConName);
			alert("True");
		}
		else
		{
			alert(strConName);
			alert("False");
		}*/
		
		switch (strConType)
		{
			case "Date":

				strConValue=Trim(objControl.value);
				if(strConValue=="" && boolReq)
				{
					strErrMsg+=strConDesc + " " + "Left Blank" + "\n" ;
				}else{
				
					if (strConValue!="")
					{
						if (IsValidDateFormat(strConValue)==false)
						{
							strErrMsg+=strConDesc + " " + "Invalid Date Format, i.e.(mm/dd/yyyy)" + "\n" ;					
						}else{
							objDate = new Date(String(strConValue));
							
							if (objDate == 0 || isNaN(objDate)==true)
							{
								strErrMsg+=strConDesc + " " + "Invalid Date Format, i.e.(mm/dd/yyyy)" + "\n" ;
							}else{
								if (objDate.getFullYear() < 1800){
									strErrMsg+=strConDesc + " " + "Date must be 1/1/1800 or later \n" ;
								}							
							}
						}
					}
				}
				break;
			case "Time":
				strConValue=objControl.value;
				if(strConValue=="" && boolReq)
				{
					strErrMsg+=strConDesc + " " + "Left Blank" + "\n" ;
				}else{
					if (strConValue!="")
					{
						if ((sTimeErrMsg = IsValidTime(strConValue)) != "")
						{
							strErrMsg+=strConDesc + " " + sTimeErrMsg + "\n" ;
						}
					}
				}
				break;
						
			case "Text":
				strConValue=objControl.value;
				if(strConValue=="" && boolReq)
				{
					strErrMsg+=strConDesc + " " + "Left Blank" + "\n" ;
				}
				//else if (objControl.value.length > 30 && (strConDesc == "User name" || strConDesc == "Password"))
				//{
				//		strErrMsg+=strConDesc + " " + " has exceeded the 30 character limit" + "\n";
				//}				
				else
					if(objControl.value.length > 2500)
					{
						strErrMsg+=strConDesc + " " + " has exceeded the 2500 character limit" + "\n";
					}				
				break;
				
			case "Text10":
				strConValue=objControl.value;
				if(strConValue=="" && boolReq)
				{
					strErrMsg+=strConDesc + " " + "Left Blank" + "\n" ;
				}
				else
					if(objControl.value.length > 10)
					{
						strErrMsg+=strConDesc + " " + " has exceeded the 10 character limit" + "\n";
					}				
				break;

			case "Text25":
				strConValue=objControl.value;
				if(strConValue=="" && boolReq)
				{
					strErrMsg+=strConDesc + " " + "Left Blank" + "\n" ;
				}
				else
					if(objControl.value.length > 25)
					{
						strErrMsg+=strConDesc + " " + " has exceeded the 25 character limit" + "\n";
					}				
				break;

			case "Text35":
				strConValue=Trim(objControl.value);
				if(strConValue=="" && boolReq)
				{
					strErrMsg+=strConDesc + " " + "Left Blank" + "\n" ;
				}
				else
					if(objControl.value.length > 35)
					{
						strErrMsg+=strConDesc + " " + " has exceeded the 35 character limit" + "\n";
					}				
				break;

			case "Text45":
				strConValue=Trim(objControl.value);
				if(strConValue=="" && boolReq)
				{
					strErrMsg+=strConDesc + " " + "Left Blank" + "\n" ;
				}
				else
					if(objControl.value.length > 45)
					{
						strErrMsg+=strConDesc + " " + " has exceeded the 45 character limit" + "\n";
					}				
				break;
				
			case "Text50":
				strConValue=Trim(objControl.value);
				if(strConValue=="" && boolReq)
				{
					strErrMsg+=strConDesc + " " + "Left Blank" + "\n" ;
				}
				else
					if(objControl.value.length > 50)
					{
						strErrMsg+=strConDesc + " " + " has exceeded the 50 character limit" + "\n";
					}				
				break;
			case "Text60":
				strConValue=Trim(objControl.value);
				if(strConValue=="" && boolReq)
				{
					strErrMsg+=strConDesc + " " + "Left Blank" + "\n" ;
				}
				else
					if(objControl.value.length > 60)
					{
						strErrMsg+=strConDesc + " " + " has exceeded the 60 character limit" + "\n";
					}				
				break;
			case "Text80":
				strConValue=Trim(objControl.value);
				if(strConValue=="" && boolReq)
				{
					strErrMsg+=strConDesc + " " + "Left Blank" + "\n" ;
				}
				else
					if(objControl.value.length > 80)
					{
						strErrMsg+=strConDesc + " " + " has exceeded the 80 character limit" + "\n";
					}				
				break;				
			case "Text100":
				strConValue=objControl.value;
				if(strConValue=="" && boolReq)
				{
					strErrMsg+=strConDesc + " " + "Left Blank" + "\n" ;
				}
				else
					if(objControl.value.length > 100)
					{
						strErrMsg+=strConDesc + " " + " has exceeded the 100 character limit" + "\n";
					}				
				break;	
			case "Text105":
				strConValue=objControl.value;
				if(strConValue=="" && boolReq)
				{
					strErrMsg+=strConDesc + " " + "Left Blank" + "\n" ;
				}
				else
					if(objControl.value.length > 105)
					{
						strErrMsg+=strConDesc + " " + " has exceeded the 105 character limit" + "\n";
					}				
				break;	
			case "Text128":
				strConValue=objControl.value;
				if(strConValue=="" && boolReq)
				{
					strErrMsg+=strConDesc + " " + "Left Blank" + "\n" ;
				}
				else
					if(objControl.value.length > 128)
					{
						strErrMsg+=strConDesc + " " + " has exceeded the 128 character limit" + "\n";
					}				
				break;					
			case "Text130":
				strConValue=objControl.value;
				if(strConValue=="" && boolReq)
				{
					strErrMsg+=strConDesc + " " + "Left Blank" + "\n" ;
				}
				else
					if(objControl.value.length > 130)
					{
						strErrMsg+=strConDesc + " " + " has exceeded the 130 character limit" + "\n";
					}				
				break;				
						
			case "Text150":
				strConValue=objControl.value;
				if(strConValue=="" && boolReq)
				{
					strErrMsg+=strConDesc + " " + "Left Blank" + "\n" ;
				}
				else
					if(objControl.value.length > 150)
					{
						strErrMsg+=strConDesc + " " + " has exceeded the 150 character limit" + "\n";
					}				
				break;				
			
			case "Text250":
				strConValue=objControl.value;
				if(strConValue=="" && boolReq)
				{
					strErrMsg+=strConDesc + " " + "Left Blank" + "\n" ;
				}
				else
					if(objControl.value.length > 250)
					{
						strErrMsg+=strConDesc + " " + " has exceeded the 250 character limit" + "\n";
					}				
				break;				
				
			case "Text255":
				strConValue=objControl.value;
				if(strConValue=="" && boolReq)
				{
					strErrMsg+=strConDesc + " " + "Left Blank" + "\n" ;
				}
				else
					if(objControl.value.length > 255)
					{
						strErrMsg+=strConDesc + " " + " has exceeded the 255 character limit" + "\n";
					}				
				break;						
				
			case "Text500":
				strConValue=objControl.value;
				if(strConValue=="" && boolReq)
				{
					strErrMsg+=strConDesc + " " + "Left Blank" + "\n" ;
				}
				else
					if(objControl.value.length > 500)
					{
						strErrMsg+=strConDesc + " " + " has exceeded the 500 character limit" + "\n";
					}				
				break;				
				
			case "Text1000":
				strConValue=objControl.value;
				if(strConValue=="" && boolReq)
				{
					strErrMsg+=strConDesc + " " + "Left Blank" + "\n" ;
				}
				else
					if(objControl.value.length > 1000)
					{
						strErrMsg+=strConDesc + " " + " has exceeded the 1000 character limit" + "\n";
					}				
				break;
				
			case "Text1500":
				strConValue=objControl.value;
				if(strConValue=="" && boolReq)
				{
					strErrMsg+=strConDesc + " " + "Left Blank" + "\n" ;
				}
				else
					if(objControl.value.length > 1500)
					{
						strErrMsg+=strConDesc + " " + " has exceeded the 1500 character limit" + "\n";
					}				
				break;								
				
			case "AdName":
				strConValue=objControl.value;
				while(strConValue.charAt(strConValue.length-1)+''==' ')
					{
						strConValue=strConValue.substring(0,strConValue.length-1);
					}
				if(strConValue=="" && boolReq)
				{
					strErrMsg+=strConDesc + " " + "must be entered to continue." + "\n" ;
					mbClicked = false;
				}
				else
				{
					if(objControl.value.length > 11)
					{
						strErrMsg+=strConDesc + " " + " has exceeded the 11 character limit." + "\n";
					}
					var iItem,iCharPos,bInvalidChar=false;
					for(iItem=0;iItem<strConValue.length;iItem++)
					{
						for(iCharPos=0;iCharPos<strSpecialChars.length;iCharPos++)
						{
							if(strConValue.charAt(iItem)== strSpecialChars.charAt(iCharPos))
							{
								bInvalidChar=true;
								mbClicked = false;
							}
						}
					} 
					if(bInvalidChar)
					{
						strErrMsg+=strConDesc + " " + " may not contain special characters. (for example /<>|~{}[]*^)" + "\n";
					}	
					var bSpace=false;
					for(iItem=0;iItem<strConValue.length;iItem++)
					{					
						if(strConValue.charAt(iItem)== strSpace)
						{
							bSpace=true;
							mbClicked = false;
						}
						
					}
					if(bSpace)
					{
						strErrMsg+=strConDesc + " " + " may not contain spaces." + "\n";
					}								
							
				}
				break;
			case "CityName":
				strConValue=objControl.value;
				while(strConValue.charAt(strConValue.length-1)+''==' ')
					{
						strConValue=strConValue.substring(0,strConValue.length-1);
					}
				if(strConValue=="" && boolReq)
				{
					strErrMsg+=strConDesc + " " + "must be entered to continue." + "\n" ;
				}
				else
				{
					if(objControl.value.length > 30)
					{
						strErrMsg+=strConDesc + " " + " has exceeded the 30 character limit." + "\n";
					}
					var iItem,iCharPos,bInvalidChar=false;
					for(iItem=0;iItem<strConValue.length;iItem++)
					{
						for(iCharPos=0;iCharPos<strSpecialChars2.length;iCharPos++)
						{
							if(strConValue.charAt(iItem)== strSpecialChars2.charAt(iCharPos))
							{
								bInvalidChar=true;
							}
						}
					} 
					if(bInvalidChar)
					{
						strErrMsg+=strConDesc + " " + " may not contain special characters. (for example /<>|~{}[]*^)" + "\n";
					}									
							
				}
				break;	
							
			case "LayoutName":
				strConValue=objControl.value;
				while(strConValue.charAt(strConValue.length-1)+''==' ')
					{
						strConValue=strConValue.substring(0,strConValue.length-1);
					}
				if(strConValue=="" && boolReq)
				{
					strErrMsg+=strConDesc + " " + "must be entered to continue." + "\n" ;
				}
				else
				{
					if(objControl.value.length > 8)
					{
						strErrMsg+=strConDesc + " " + " has exceeded the 8 character limit." + "\n";
					}
					var iItem,iCharPos,bInvalidChar=false;
					for(iItem=0;iItem<strConValue.length;iItem++)
					{
						for(iCharPos=0;iCharPos<strSpecialChars.length;iCharPos++)
						{
							if(strConValue.charAt(iItem)== strSpecialChars.charAt(iCharPos))
							{
								bInvalidChar=true;
							}
						}
					} 
					if(bInvalidChar)
					{
						strErrMsg+=strConDesc + " " + " may not contain special characters. (for example /<>|~{}[]*^)" + "\n";
					}	
					var bSpace=false;
					for(iItem=0;iItem<strConValue.length;iItem++)
					{					
						if(strConValue.charAt(iItem)== strSpace)
						{
							bSpace=true;
						}
						
					}
					if(bSpace)
					{
						strErrMsg+=strConDesc + " " + " may not contain spaces." + "\n";
					}								
							
				}
				break;												
			
			case "CC":
				strConValue=objControl.value;
				if(strConValue=="" && boolReq)
				{
					strErrMsg+=strConDesc + " " + "Left Blank" + "\n" ;
				}
				break;
			case "Email":
				strConValue=objControl.value;
				if(strConValue=="" && boolReq)
				{
					strErrMsg+=strConDesc + " " + "Left Blank" + "\n" ;
				}else{
					if (strConValue!="")
					{
						if (!checkEmail(strConValue))
						{
							strErrMsg+=strConDesc + " " + "Invalid Format. (example x@x.x)" + "\n"
						}					
					}
				}
				break;
//					if (strConValue.indexOf("@") < 1 || strConValue.indexOf(".") < 2 || objControl.value.indexOf(" ") > 0)				
			case "Phone":
				strConValue=objControl.value;
				if(strConValue=="" && boolReq)
				{
					strErrMsg+=strConDesc + " " + "Left Blank" + "\n" ;
				}else{
					if (strConValue!="")
					{
						if ((sPhoneErrMsg = validatePHONE(strConValue)) != "")
						{
							strErrMsg+=strConDesc + " " + sPhoneErrMsg + "\n" ;
						}
					}
				}
				break;
			
			case "Phone12":
				strConValue=objControl.value;
				if(strConValue=="" && boolReq)
				{
					strErrMsg+=strConDesc + " " + "Left Blank" + "\n" ;
				}else{
					if (strConValue!="")
					{
						if ((sPhoneErrMsg = validatePHONE12(strConValue)) != "")
						{
							strErrMsg+=strConDesc + " " + sPhoneErrMsg + "\n" ;
						}
					}
				}
				break;
							
			case "Check":
				if(boolReq)
				{
					var iItem,bSelected=false;
					if (objControl.length==null)
					{
						if (objControl.checked)
						{
							bSelected=true;
						}
					}else{					
						for(iItem=0;iItem<objControl.length;iItem++)
						{
							if(objControl[iItem].checked)
							{
								bSelected=true;
							}
						}
					}
					if(!bSelected)
					{
						strErrMsg+=strConDesc + " " + "Selection Invalid" + "\n";
					}
						
				}
				break;
				
			case "Option":
				if(boolReq)
				{
					var iItem,bSelected=false;
					if (objControl.length==null)
					{
						if (objControl.checked)
						{
							bSelected=true;
						}
					}else{
						for(iItem=0;iItem<objControl.length;iItem++)
						{
							
							if(objControl[iItem].checked)
							{
								bSelected=true;
							}
						}
					}
					if(!bSelected)
					{
						strErrMsg+=strConDesc +  " " + "Selection Invalid" + "\n";
					}
						
				}
				break;
				
			case "Select":
				if(boolReq)
				{
					if (objControl){
						if((objControl.options[objControl.selectedIndex].value<1) || (objControl.options[objControl.selectedIndex].value==null))
						{
							strErrMsg+=strConDesc + " " + "Not Selected" + "\n"
						}
					}
				}
				
				break;
				
			case "SelBedrooms":
				if(boolReq)
				{
					if (objControl){
						if(objControl.selectedIndex==0)
						{
							strErrMsg+=strConDesc + " " + "Not Selected" + "\n"
						}
					}
				}
				
				break;				

			case "Zip":
				strConValue=objControl.value;
				if(strConValue=="" && boolReq)
				{
					strErrMsg+=strConDesc + " " + "Left Blank" + "\n" ;
				}else if (objControl.value!=""){
					if ((objControl.value.length != 5) && (objControl.value.length != 10))
					{					
						strErrMsg+=strConDesc + " " + "Invalid Entry" + "\n";
					}else{
						if (objControl.value.length == 10)
						{
							if ((objControl.value.substr(5,1) != "-") || (isNaN(objControl.value.substr(0,5))) || (isNaN(objControl.value.substr(6,4))))
							{
								strErrMsg+=strConDesc + " " + "Invalid Entry - Zip+4 requires the format 99999-9999" + "\n";
							}
						}else{
								
							if(isNaN(objControl.value))
							{
							strErrMsg+=strConDesc + " " + "Invalid Entry - Zip must be numeric" + "\n";
							}
						}
					}
				}
				break;			
				
			case "ZipCan":
				strConValue=objControl.value;
				if(strConValue=="" && boolReq)
				{
					strErrMsg+=strConDesc + " " + "Left Blank" + "\n" ;
				}else{
					if (strConValue!="")
					{
						if ((sCanZipErrMsg = validateCanadianZip(strConValue)) != "")
						{
							strErrMsg+=strConDesc + " " + sCanZipErrMsg + "\n" ;
						}
					}
				}
				break;
				
			case "Number":
				if(objControl.value=="")
				{
					if(boolReq)
					{
						strErrMsg+=strConDesc + " " + "Left Blank" +"\n";
					}
				}
				else
				{		
						if(!checkNumber(objControl.value))
						{
							strErrMsg+=strConDesc + " " + "Invalid Number" + "\n";
						}
				}
				break;	
			case "Number0-18":
				if(objControl.value=="")
				{
					if(boolReq)
					{
						strErrMsg+=strConDesc + " " + "Left Blank" +"\n";
					}
				}
				else
				{		
						if(!checkNumber(objControl.value))
						{
							strErrMsg+=strConDesc + " " + "Invalid Number" + "\n";
						}
				}
				if (objControl.value < 0 || objControl.value > 18)
				{
					strErrMsg+=strConDesc + " " + "must be between 0 and 18" + "\n";
				}
				break;
			case "Number0-25":
				if(objControl.value=="")
				{
					if(boolReq)
					{
						strErrMsg+=strConDesc + " " + "Left Blank" +"\n";
					}
				}
				else
				{		
						if(!checkNumber(objControl.value))
						{
							strErrMsg+=strConDesc + " " + "Invalid Number" + "\n";
						}
				}
				if (objControl.value < 0 || objControl.value > 25)
				{
					strErrMsg+=strConDesc + " " + "must be between 0 and 25" + "\n";
				}
				break;												
			case "Number1-99":
				if(objControl.value=="")
				{
					if(boolReq)
					{
						strErrMsg+=strConDesc + " " + "Left Blank" +"\n";
					}
				}
				else
				{		
						if(!checkNumber(objControl.value))
						{
							strErrMsg+=strConDesc + " " + "Invalid Number" + "\n";
						}
				}
				if (objControl.value < 1 || objControl.value > 99)
				{
					strErrMsg+=strConDesc + " " + "must be between 1 and 99" + "\n";
				}
				break;					
			case "Number1-1000":
				if(objControl.value=="")
				{
					if(boolReq)
					{
						strErrMsg+=strConDesc + " " + "Left Blank" +"\n";
					}
				}
				else
				{		
						if(!checkNumber(objControl.value))
						{
							strErrMsg+=strConDesc + " " + "Invalid Number" + "\n";
						}
				}
				if (objControl.value < 1 || objControl.value > 1000)
				{
					strErrMsg+=strConDesc + " " + "must be between 1 and 1000" + "\n";
				}
				break;		
				case "Positive-Number":
				if(objControl.value=="")
				{
					if(boolReq)
					{
						strErrMsg+=strConDesc + " " + "Left Blank" +"\n";
					}
				}
				else
				{		
						if(!checkNumber(objControl.value))
						{
							strErrMsg+=strConDesc + " " + "Invalid Number" + "\n";
						}
				}
				if (objControl.value <0)
				{
					strErrMsg+=strConDesc + " " + "must be positive number" + "\n";
				}
				break;		
				case "Positive-Integer":
				if(objControl.value=="")
				{
					if(boolReq)
					{
						strErrMsg+=strConDesc + " " + "Left Blank" +"\n";
					}
				}
				else
				{		
						if(!checkNumber(objControl.value))
						{
							strErrMsg+=strConDesc + " " + "Invalid Number" + "\n";
						}
						else
						{
							var num = objControl.value.toString(); 
							var idxpoint=num.indexOf('.'); 

							if (idxpoint > 0 || objControl.value <0 )
							{
								strErrMsg+=strConDesc + " " + "must be positive integer" + "\n";
							}
						}
				}
				
				break;								
			case "QuarkFactor":
				if(objControl.value=="")
				{
					if(boolReq)
					{
						strErrMsg+=strConDesc + " " + "Left Blank" +"\n";
					}
				}
				else
				{		
						if(!checkNumber(objControl.value))
						{
							strErrMsg+=strConDesc + " " + "Invalid Number" + "\n";
						}
				}
				if (objControl.value < .75 || objControl.value > 1.5)
				{
					strErrMsg+=strConDesc + " " + "must be between .75 and 1.5" + "\n";
				}
				break;						
		}
	}
	if(strErrMsg!="")
	{
		alert(strErrMsg);
		return false;
	}
	else
	{
		return true;
	}
	
	
}

function validateCanadianZip(fieldVal)
{
 //var pocMASK = /(\w{3}) (\w{3})$/
 var pocMASK = /(\w)(\d)(\w) (\d)(\w)(\d)$/
 
 var matchArray = fieldVal.match(pocMASK)
	
 if (matchArray==null)
 {
  return "Not a valid Canadian Zip Code ";
 }
return "";
}
function validatePHONE(fieldVal)
{
 var pocMASK = /(\d{3})-(\d{3})-(\d{4})$/
 var parMASK = /[(](\d{3})[)]\s(\d{3})-(\d{4})$/	
 var matchArray = fieldVal.match(pocMASK)
 var matchArrayParen = fieldVal.match(parMASK)
 if (matchArray==null && matchArrayParen==null)
 {
  return "Not a valid phone number \nUse 999-999-9999 or (999) 999-9999 ";
 }
return "";
}

function validatePHONE12(fieldVal)
{
 var pocMASK = /(\d{3})-(\d{3})-(\d{4})$/
 var parMASK = /[(](\d{3})[)]\s(\d{3})-(\d{4})$/	
 var matchArray = fieldVal.match(pocMASK)
 var matchArrayParen = fieldVal.match(parMASK)
 if (matchArray==null && matchArrayParen==null)
 {
  return "Not a valid phone number \nUse 999-999-9999 ";
 }
return "";
}

function IsValidDateFormat(dateStr)
{
	var datePat = /(\d{1,2})\/(\d{1,2})\/(\d{4})$/
	var matchArray = dateStr.match(datePat);
	
		
	if (matchArray==null)
	{
	 return false
	}else{
		return true;
	}
}
function EnableValidation(bEnabled)
{
	bValidationOn = bEnabled;
}

function IsValidTime(timeStr) {
// Checks if time is in HH:MM:SS AM/PM format.
// The seconds are optional.

var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;

var matchArray = timeStr.match(timePat);
if (matchArray == null) {
	return "Time is not in a valid format, i.e.(h:m am/pm)";
}
hour = matchArray[1];
minute = matchArray[2];
second = matchArray[4];
ampm = matchArray[6];

if (second=="") { second = null; }
if (ampm=="") { ampm = null }

if (hour < 0  || hour > 12) {
	return "Hour must be between 1 and 12.";
}
if (hour <= 12 && ampm == null) {
	return "You must specify AM or PM.";
}
if  (hour > 12 && ampm != null) {
	return "You can't specify AM or PM for 24 hour time.";
}
if (minute<0 || minute > 59) {
	return "Minute must be between 0 and 59.";
}
if (second != null && (second < 0 || second > 59)) {
	return "Second must be between 0 and 59.";
}
return false;
}
function checkNumber(sNumber) { 
var sNum=sNumber.toString(); 
var idecpoint=sNum.indexOf('.'); 
var ilast=0; 

idecpoint>-1 ? ilast=idecpoint-1 : ilast=sNum.length-1; 

//strip the commas and see if this is a number 
var tempString = sNum; 
while (tempString.indexOf(',') != -1) { 
tempString=tempString.substring(0, tempString.indexOf(',')) + 
tempString.substring(tempString.indexOf(',')+1); 
} 

if (isNaN(tempString)) 
return false; 

//start from ilast and find the last comma 
var icomma=sNum.lastIndexOf(',', ilast); 
var idiff=0; 
while (icomma != -1) { 
idiff=ilast-icomma; 
if (idiff != 3) { 
return false; 
break; 
} 
ilast=icomma - 1; 
icomma=sNum.lastIndexOf(',', ilast); 
} 
return true; 
} 
function checkEmail(sEmailVal) {
  var regex = /^[a-zA-Z0-9._\-&]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]*$/;
			  
  return regex.test(sEmailVal);
}
function validatefiles()
{
	var form = window.document.forms[0];
	var hold;
	
	var hold = '';
	
	for (var i = 0; i < form.elements.length; i++)
	{
		if (form.elements[i].type == "file")
		{
			hold = hold + form.elements[i].value
		}
	}
	
	if (hold.length == 0)
	{
		alert("No files to upload");
		return false
	}
	else
	{
		return true
	}
}

function BarkAtTypist(objControl, length)
{

	if (window.event.keyCode > 46 || window.event.keyCode == 32)
	{
		if (objControl.value.length >= length)
		{
			if (bBark == true)
			{
				bNoBubble = true;
				alert("Character limit reached.");
				bBark = false;
				bNoBubble = false;
			}
		}
		
		if (objControl.value.length == length)
		{
			objControl.value = Left(objControl.value, length);
			return false
		}	
		else
		{
			return true
		}
		
	}
}

function BarkAtMouseist(objControl, length)
{
	ASCIICheck(objControl);
	
	if (objControl.value.length > length)
	{
	
		if (bNoBubble == false)
		{
			alert("Character limit exceeded.  You may not be able to save this text.");
			return false;
		}
	}	
	else
	{
		return true;
	}

}

function ASCIICheck(objControl)
{

	var i;
	var str;
	var bIllegal;

	str = objControl.value
	bIllegal = 0
	
	for(i = 0; i < objControl.value.length; i++)
	{
		if (str.charCodeAt(i) > 128)
		{
			alert("Invalid character " + Mid(str, i, 1) + " at position " + (i + 1));
			bIllegal = 1
		}
		if (str.charCodeAt(i) == 9)
		{
			//alert("Invalid character (TAB)" + " at position " + (i + 1));
			bIllegal = 1
		}
		if (str.charCodeAt(i) == 10)
		{
			//alert("Invalid character (carridge return)" + " at position " + (i + 1));
			bIllegal = 1
		}
		if (str.charCodeAt(i) == 13)
		{
			//alert("Invalid character (line feed)" + " at position " + (i + 1));
			bIllegal = 1
		}
	}
	
	if (bIllegal != 0)
	{
		//alert("Tabs, Returns or invalid charactors were found and will be removed from the text block when you select Save and Continue.");
		alert("Tabs and/or Returns were found in the current text block.");
		return false;
	}
	else
	{
		return true;
	}
}

//sshen check text area
function CheckTextArea(objControl, length)
{
	
	if (ASCIICheckText(objControl)!=true)
	{
		if (confirm("Tabs, returns or invalid characters were found in the text block. \n Click OK to allow the system to remove them and display the clean text.\n Click Cancel to clean the text yourself."))
		{
			objControl.value = CleanText(objControl);
			return false;
		}
		else
		{
			return false;
		}
	}
	
	if (objControl.value.length > length)
	{
	
		if (bNoBubble == false)
		{
			alert("Character limit exceeded.  You may not be able to save this text.");
			return false;
		}
	}	
	else
	{
		return true;
	}

}
//check text area ascii value
function ASCIICheckText(objControl)
{

	var i;
	var str;
	var bIllegal;

	str = objControl.value
	bIllegal = 0
	
	for(i = 0; i < objControl.value.length; i++)
	{
		if (str.charCodeAt(i) > 128)
		{
			//alert("Invalid character " + Mid(str, i, 1) + " at position " + (i + 1));
			bIllegal = 1
		}
		if(str.charAt(i)=='<' && str.charAt(i+1)!=' ')
		{
			//HTML Formatting
			bIllegal = 1;
		}
		if(str.charAt(i)=='>' && str.charAt(i-1)!=' ')
		{
			//HTML Formatting
			bIllegal = 1;
		}			
		if (str.charCodeAt(i) == 9)
		{
			//alert("Invalid character (TAB)" + " at position " + (i + 1));
			bIllegal = 1
		}
		if (str.charCodeAt(i) == 10)
		{
			//alert("Invalid character (carriage return)" + " at position " + (i + 1));
			bIllegal = 1
		}
		if (str.charCodeAt(i) == 13)
		{
			//alert("Invalid character (line feed)" + " at position " + (i + 1));
			bIllegal = 1
		}
	}
	
	if (bIllegal != 0)
	{
		//alert("Tabs, Returns or invalid charactors were found and will be removed from the text block when you select Save and Continue.");
		//alert("Tabs, Returns or invalid charactors were found in the text block.");
		return false;
	}
	else
	{
		return true;
	}
}

//var aTextConversionDictionary = new Array("bdr:bedroom","bedrm:bedroom","bth:bath","bthrm:bathroom");
var aTextConversionDictionary = new Array("ac:air conditioner","acr:acreage","add'l:additional","appl:appliances","appt:appointment","approx:approximate","avail:available","balc:balcony","bbq:bar b que","b'ful:beautiful","bkyd:backyard","bldg:building","bsmt:basement","ba:bath","bdrms:bedrooms","bkfst:breakfast","blt:built","cath:cathedral","ceil:ceiling","c-fans:ceiling fans","cntr:center","contemp:contemporary","constr:construction","cstm:custom","cvrd:covered","crtyrd:courtyard","dbl:double","dr:dining room","din:dining","dwnstrs:downstairs","elec:electric","elem:elementary","fam:family","fncd:fenced","frplc:fireplace","flr:floors","flrpln:floorplan","frml:formal","frtyd:front yard","gmrm:game room","gar:garage","grnd:ground","hdwd:hardwood","incl:including","incl:includes","irrig:irrigation","kit/nook:kitchen/nook","kit/bkfast:kitchen/breakfast","lndry:laundry","lndscpd:landscape","lg:large","lux:luxury","lib:library","lr:living room","liv:living ","ll:lower level","maint:maintenance","mins:minutes","min:minimum","mo:month","mstr:master","mtg:meeting","mtn.:mountain","nat'l :national","n'hood:neighborhood","Ofc:office","prof:professional","pkwy:parkway","pln:plan","pmts:payments","prch:porch","priv:private","prkng:parking","rm:room","rec:recreational","rec.rm:recreational room","schls:schools","scrnd.:screened","spac:space","scrnd:screened","spklr:sprinkler","sq.ft.:square footage","sq:square","ft:footage","stor:storage","sunrm:sunroom","ste:suite","stry:story","unfin:unfinished","util:utilities","vltd:vaulted","v-ceilings:vaulted ceilings","wrnty:warranty","wrkrm:workroom","wrksp:workspace","wrkshop:workshop","xtra:extra","yrd:yard","yr:year");

function CheckTextForConversion(objControl)
{
	var i;
	var source;
	var target;
	var replaceFound;
	
	
	for(i in aTextConversionDictionary)
	{
		var sItem = aTextConversionDictionary[i];
		var aItem = sItem.split(":");
		
		source = ' ' + aItem[0] + ' ';
		target = ' ' + aItem[1] + ' ';
		if (objControl.value.indexOf(source) > 0)
		{
			return false;
		}
	}
	return true;
}

function ConvertText(objControl)
{
	var i;
	var source;
	var target;
	var replaceString;
	
	
	replaceString = objControl.value;
	for(i in aTextConversionDictionary)
	{
		var sItem = aTextConversionDictionary[i];
		var aItem = sItem.split(":");
		
		source = ' ' + aItem[0] + ' ';
		target = ' ' + aItem[1] + ' ';
		objControl.value = objControl.value
		if (objControl.value.indexOf(source) > 0)
		{
			replaceString = replaceString.replace(source,target);
		}
	}
	return replaceString;
}


//clean text area invalid value
function CleanText(objControl)
{
	var i;
	var str;
	var newstr;
	var strlen;

	strlen = objControl.value.length;
	str = objControl.value
	bIllegal = 0
	//alert("length " + objControl.value.length)
	for(i = 0; i < objControl.value.length; i++)
	{   
		if (str.charCodeAt(i) > 128)
		{
			str = str.replace(str.charAt(i),'');
			if (i=0)
			{
				i=0
			}
			else
			{
				i=i-1
			}		
		}
		
		
		if(str.charAt(i)=='<' && str.charAt(i+1)!=' ')
		{
			newstr='';
			//alert("str" + str + str.charAt(i) + i)
			newstr = str.substr(i,strlen-i)
			newstr= newstr.replace(newstr.charAt(0),' ');
			//alert("new string " + newstr);
			str=str.substr(0,i) + newstr
			
			//alert("str1" + str)
			i=0;
		}
		
		if(str.charAt(i)=='>' && str.charAt(i-1)!=' ')
		{
			newstr='';
			newstr = str.substr(i,strlen-i)
			newstr= newstr.replace(newstr.charAt(0),' ');
			//alert("new string " + newstr);
			str=str.substr(0,i) + newstr;
			//alert("str1" + str)			
			i=0;
		}	
		if (str.charCodeAt(i) == 9)
		{
			str = str.replace(str.charAt(i),' ');
		}
		if (str.charCodeAt(i) == 13)
		{
			if(str.charCodeAt(i)==13 && str.charCodeAt(i+1)!=10)
			{
				str = str.replace(str.charAt(i),'');
				str = str.replace(str.charAt(i),' ');
			}
			else
			{
				str = str.replace(str.charAt(i),' ');
			}
		}
		if (str.charCodeAt(i) == 10)
		{
			str = str.replace(str.charAt(i),' ');
		}
		
	}

	return str;
}

//check text area ascii value
function PunctuationCheckText(objControl)
{

	var i;
	var str;
	var bIllegal;

	str = objControl.value;
	bIllegal = 1;
	
	for(i = 0; i < objControl.value.length; i++)
	{
		if (str.charCodeAt(i) == 32)
		{
			bIllegal = 0;
		}
		else if ((str.charCodeAt(i) >= 48) && (str.charCodeAt(i) <= 57))
		{
			bIllegal = 0;
		}	
		else if ((str.charCodeAt(i) >= 65) && (str.charCodeAt(i) <= 90))
		{
			bIllegal = 0;
		}	
		else if ((str.charCodeAt(i) >= 97) && (str.charCodeAt(i) <= 122))
		{
			bIllegal = 0;
		}	
		else
		{
			bIllegal = 1;
			break;					
		}
	}
	
	if (bIllegal != 1)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function Left(str, n)
/***
        IN: str - the string we are LEFTing
            n - the number of characters we want to return

        RETVAL: n characters from the left side of the string
***/
{
        if (n <= 0)     // Invalid bound, return blank string
                return "";
        else if (n > String(str).length)   // Invalid bound, return
                return str;                // entire string
        else // Valid bound, return appropriate substring
                return String(str).substring(0,n);
}

function Right(str, n)
/***
        IN: str - the string we are RIGHTing
            n - the number of characters we want to return

        RETVAL: n characters from the right side of the string
***/
{
        if (n <= 0)     // Invalid bound, return blank string
           return "";
        else if (n > String(str).length)   // Invalid bound, return
           return str;                     // entire string
        else { // Valid bound, return appropriate substring
           var iLen = String(str).length;
           return String(str).substring(iLen, iLen - n);
        }
}

function InStr(strSearch, charSearchFor)
/*
InStr(strSearch, charSearchFor) : Returns the first location a substring (SearchForStr)
                           was found in the string str.  (If the character is not
                           found, -1 is returned.)
                           
Requires use of:
	Mid function
	Len function
*/
{
	for (i=0; i < Len(strSearch); i++)
	{
	    if (charSearchFor == Mid(strSearch, i, 1))
	    {
			return i;
	    }
	}
	return -1;
}

function Mid(str, start, len)
/***
        IN: str - the string we are LEFTing
            start - our string's starting position (0 based!!)
            len - how many characters from start we want to get

        RETVAL: The substring from start to start+len
***/
{
        // Make sure start and len are within proper bounds
        if (start < 0 || len < 0) return "";

        var iEnd, iLen = String(str).length;
        if (start + len > iLen)
                iEnd = iLen;
        else
                iEnd = start + len;

        return String(str).substring(start,iEnd);
}

function Len(str)
/***
        IN: str - the string whose length we are interested in

        RETVAL: The number of characters in the string
***/
{  return String(str).length;  }

function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

function RTrim(str)
/*
   PURPOSE: Remove trailing blanks from our string.
   IN: str - the string we want to RTrim

*/
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}

function Trim(str)
/*
   PURPOSE: Remove trailing and leading blanks from our string.
   IN: str - the string we want to Trim

   RETVAL: A Trimmed string!
*/
{
   return RTrim(LTrim(str));
}

function LCase(Value) 
{
	return Value.toString().toLowerCase();
}

function UCase(Value) 
{
	return Value.toString().toUpperCase();
}

function spewimagewarning(objControl, obj4x6, objPhotoType)
{

	if((objControl.value == 'Large' || objControl.value == 164)&& (objPhotoType != 101))
	{
		alert('Warning! Large images are only supported for \n the following layouts and/or positions: \n 0100, 0101 \n 0200 - Positions 1 and 2 \n 0201 - Positions 1 and 2 \n 0302 - Position 1 \n 0307 - Position 3 \n 0408 - Position 1 \n 0411 - Position 1  (Previously Layout #409) \n 0700 - Position 1');
	}

	validateprints(obj4x6, objControl, objPhotoType);

}

function validateprints(objControl, objPhotoUsage, objPhotoType)
{

	var sPhotoUsage = objPhotoUsage[objPhotoUsage.selectedIndex].text;
	var bUsageGood = false
	if (objControl.value > 0)
	{
		switch (sPhotoUsage)
			{
				case "Small":	
					bUsageGood = true;
					break;
				case "Large":
					bUsageGood = true;
					break;
				case "Cover":
					bUsageGood = false;
					break;
				case "Digest":
					bUsageGood = false;
					break;
				case "Spread":
					bUsageGood = false;
					break;
			}
	}	
	else
	{
		bUsageGood = true;
	}
	
	if (objPhotoType == 101 && objControl.value > 0)
	{
		alert('You cannot order 4x6s for Advertiser photos.');
		objControl.value=0;
	}
	else
	{
		if (bUsageGood == true && objControl.value > 0)
		{
			if((objControl.value != 1) && (objControl.value % 6 != 0))
			{
				alert("4x6 prints must be ordered as \n singles or multiples of 6.");
				objControl.value=0;
			}
		}
		else
		{
			if (bUsageGood == false)
			{
				alert('You cannot order 4x6s for ' + sPhotoUsage + ' photos.');
				objControl.value=0;
			}
		}
	}

}

function XMLEncode(sText) 
{

	sText = sText.replace(/&/gi, "&#38;");
	sText = sText.replace(/</gi, "&#60;");
	sText = sText.replace(/>/gi, "&#62;");
		
	return sText;
	
}

function debug(msg)
{

	var p

	if (!debug.box)
	{
		debug.box = document.createElement("div");
		debug.box.setAttribute("style", "background-color: white; font-family: monospace; border: solid black 3px; padding 10px;");
		document.body.appendChild(debug.box);
		debug.box.innerHTML = "<h2 style='text-align:center'>JavaScript Debug</h2>";	
	}		
	
	p = document.createElement("p");
	
	p.appendChild(document.createTextNode(msg));
	debug.box.appendChild(p);
	
}

function Sleep(numberMillis) 
{
    var now = new Date();
    var exitTime = now.getTime() + numberMillis;
    while (true) {
        now = new Date();
        if (now.getTime() > exitTime)
            return;
    }
}

function PopUpValidate(objTable, sStyle, sURL, sFailMessage, sSuccessMessage, sClassName)
{
	var objPopUp
	var myTR
	var myTD
	
	try
	{
		if (win&&ie6)
		{
			myTR = objTable.insertRow(0);
			myTD = myTR.insertCell(0);
			myTD.innerHTML = sFailMessage;
			myTD.className = sClassName;
			window.open(sURL,null,sStyle);
			myTD.innerHTML = sSuccessMessage;	
		}
		else
		{
			window.open(sURL,null,sStyle);
		}	
	}
	catch (ex)
	{
		window.open(sURL,null,sStyle);
	}


	
}

function ClickLock()
{
	mbClicked = true;	
	//alert('Buttons are now Locked')
}

function ClickUnlock()
{
	mbClicked = false;
	//alert('Buttons are now Unlocked')
}

function XMLRPCPost(sURL, sMethod, sXMLIn)
{
	/*================================================================================
	'	XMLRPCPost
	'
	'	Purpose:	This function is used for Client Side XMLRPC calls from JavaScript 
	'
	'	Developer		Date			Change
	'------------------------------------------------------------------------------
	'	Stephen Vick	20030425		Creator
	'=================================================================================*/	
	try
	{

		var oHTTP = new ActiveXObject("MSXML2.XMLHTTP");
		var oDomIn = new ActiveXObject("MSXML2.DOMDocument.3.0");
		var oDomParams = new ActiveXObject("MSXML2.DOMDocument.3.0");
		var oXMLElement;
		var oXMLParentElement;
		
	
		oHTTP.Open("POST", sURL, false);
		
		oDomParams.loadXML(sXMLIn);
		
		oXMLParentElement = oDomIn.appendChild(oDomIn.createElement("methodCall"));
		oXMLElement = oXMLParentElement.appendChild(oDomIn.createElement("methodName"));
		oXMLElement.text = sMethod;
		oXMLElement = oXMLParentElement.appendChild(oDomIn.createElement("params"));
		oXMLElement = oXMLElement.appendChild(oDomIn.createElement("param"));
		oXMLElement = oXMLElement.appendChild(oDomIn.createElement("value"));
		oXMLElement = oXMLElement.appendChild(oDomIn.createElement("string"));
		oXMLElement = oXMLElement.appendChild(oDomParams.selectSingleNode("*"));
		
		
		oHTTP.Send(oDomIn.xml);
	
		return oHTTP.responseText;
	}
	catch(oError)
	{
		if (oError instanceof Error)
		{
			//I have intentionally avoiding using a DOM to return the fault XML. 
			//This is done so that in the event the client cannot instantiate a DOMDocument
			//ActiveX component we can still return properly well formed fault XML.
			return "<?xml version=\"1.0\"?><methodResponse><fault><struct><member><name>faultCode</name><value><int>" + oError.number + "</int></value></member><member><name>faultString</name><value><string>" + oError.message + "</string></value></member></struct></value></fault></methodResonse>";
		}
	}		
	
}

function show_calendar(str_target, str_datetime) {
	ClickUnlock();
	var arr_months = ["January", "February", "March", "April", "May", "June",
		"July", "August", "September", "October", "November", "December"];
	var week_days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
	var n_weekstart = 0; // day week starts from (normally 0 or 1)

	var dt_datetime = (str_datetime == null || str_datetime =="" ?  new Date() : str2dt(str_datetime));
	var dt_prev_month = new Date(dt_datetime);
	dt_prev_month.setMonth(dt_datetime.getMonth()-1);
	var dt_next_month = new Date(dt_datetime);
	dt_next_month.setMonth(dt_datetime.getMonth()+1);
	var dt_firstday = new Date(dt_datetime);
	dt_firstday.setDate(1);
	dt_firstday.setDate(1-(7+dt_firstday.getDay()-n_weekstart)%7);
	var dt_lastday = new Date(dt_next_month);
	dt_lastday.setDate(0);
	
	// html generation (feel free to tune it for your particular application)
	// print calendar header
	var str_buffer = new String (
		"<html>\n"+
		"<head>\n"+
		"	<title>Calendar</title>\n"+
		"</head>\n"+
		"<body bgcolor=\"White\">\n"+
		"<table class=\"clsOTable\" cellspacing=\"0\" border=\"0\" width=\"100%\">\n"+
		"<tr><td bgcolor=\"#4682B4\">\n"+
		"<table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" width=\"100%\">\n"+
		"<tr>\n	<td bgcolor=\"#4682B4\"><a href=\"javascript:window.opener.show_calendar('"+
		str_target+"', '"+ dt2dtstr(dt_prev_month) + "');\">"+
		"<img src=\"/Images/prev.gif\" width=\"16\" height=\"16\" border=\"0\""+
		" alt=\"Previous Month\"></a></td>\n"+
		"	<td bgcolor=\"#4682B4\" colspan=\"5\">"+
		"<font color=\"white\" face=\"tahoma, verdana\" size=\"2\">"
		+arr_months[dt_datetime.getMonth()]+" "+dt_datetime.getFullYear()+"</font></td>\n"+
		"	<td bgcolor=\"#4682B4\" align=\"right\"><a href=\"javascript:window.opener.show_calendar('"
		+str_target+"', '"+dt2dtstr(dt_next_month) + "');\">"+
		"<img src=\"/Images/next.gif\" width=\"16\" height=\"16\" border=\"0\""+
		" alt=\"Next Month\"></a></td>\n</tr>\n"
	);

	var dt_current_day = new Date(dt_firstday);
	// print weekdays titles
	str_buffer += "<tr>\n";
	for (var n=0; n<7; n++)
		str_buffer += "	<td bgcolor=\"#87CEFA\">"+
		"<font color=\"white\" face=\"tahoma, verdana\" size=\"2\">"+
		week_days[(n_weekstart+n)%7]+"</font></td>\n";
	// print calendar table
	str_buffer += "</tr>\n";
	while (dt_current_day.getMonth() == dt_datetime.getMonth() ||
		dt_current_day.getMonth() == dt_firstday.getMonth()) {
		// print row heder
		str_buffer += "<tr>\n";
		for (var n_current_wday=0; n_current_wday<7; n_current_wday++) {
				if (dt_current_day.getDate() == dt_datetime.getDate() &&
					dt_current_day.getMonth() == dt_datetime.getMonth())
					// print current date
					str_buffer += "	<td bgcolor=\"#FFB6C1\" align=\"right\">";
				else if (dt_current_day.getDay() == 0 || dt_current_day.getDay() == 6)
					// weekend days
					str_buffer += "	<td bgcolor=\"#DBEAF5\" align=\"right\">";
				else
					// print working days of current month
					str_buffer += "	<td bgcolor=\"white\" align=\"right\">";

				if (dt_current_day.getMonth() == dt_datetime.getMonth())
					// print days of current month
					str_buffer += "<a href=\"javascript:window.opener."+str_target+
					".value='"+dt2dtstr(dt_current_day)+"'; window.close();\">"+
					"<font color=\"black\" face=\"tahoma, verdana\" size=\"2\">";
				else 
					// print days of other months
					str_buffer += "<a href=\"javascript:window.opener."+str_target+
					".value='"+dt2dtstr(dt_current_day)+"'; window.close();\">"+
					"<font color=\"gray\" face=\"tahoma, verdana\" size=\"2\">";
				str_buffer += dt_current_day.getDate()+"</font></a></td>\n";
				dt_current_day.setDate(dt_current_day.getDate()+1);
		}
		// print row footer
		str_buffer += "</tr>\n";
	}
	// print calendar footer
	str_buffer +=
		"<form name=\"cal\">\n<tr><td colspan=\"7\" bgcolor=\"#87CEFA\">"+
		"<font color=\"White\" face=\"tahoma, verdana\" size=\"2\">"+
		"</font></td></tr>\n</form>\n" +
		"</table>\n" +
		"</tr>\n</td>\n</table>\n" +
		"</body>\n" +
		"</html>\n";

	var vWinCal = window.open("", "Calendar", 
		"width=230,height=220,status=no,resizable=no,top=200,left=200");
	vWinCal.opener = self;
	var calc_doc = vWinCal.document;
	calc_doc.write (str_buffer);
	calc_doc.close();
}
function str2dt(str_datetime) {
	
	if (IsValidDateFormat(str_datetime) == true)
	{
		return (new Date (str_datetime));
	}
	else
	{
		return new Date();
	}
}
function dt2dtstr(dt_datetime) {
	return (new String (
			(dt_datetime.getMonth()+1)+"/"+dt_datetime.getDate()+"/"+dt_datetime.getFullYear()));
}

function GUIDGen() 
{
    try
    {
        var x = new ActiveXObject("Scriptlet.TypeLib");
    	return (x.GUID);
    }
    catch (e)
    {
    	return ("{00000000-0000-0000-0000-000000000000}");
    }
}

//BEGIN Browser Sniff CS1.1

var exclude=1;
var agt=navigator.userAgent.toLowerCase();
var win=0;var mac=0;var lin=1;
if(agt.indexOf('win')!=-1){win=1;lin=0;}
if(agt.indexOf('mac')!=-1){mac=1;lin=0;}
var lnx=0;if(lin){lnx=1;}
var ice=0;
var ie=0;var ie4=0;var ie5=0;var ie6=0;var com=0;var dcm;
var op5=0;var op6=0;var op7=0;
var ns4=0;var ns6=0;var ns7=0;var mz7=0;var kde=0;var saf=0;
if(typeof navigator.vendor!="undefined" && navigator.vendor=="KDE"){
	var thisKDE=agt;
	var splitKDE=thisKDE.split("konqueror/");
	var aKDE=splitKDE[1].split("; ");
	var KDEn=parseFloat(aKDE[0]);
	if(KDEn>=2.2){
		kde=1;
		ns6=1;
		exclude=0;
		}
	}
else if(agt.indexOf('webtv')!=-1){exclude=1;}
else if(typeof window.opera!="undefined"){
	exclude=0;
	if(/opera[\/ ][5]/.test(agt)){op5=1;}
	if(/opera[\/ ][6]/.test(agt)){op6=1;}
	if(/opera[\/ ][7-9]/.test(agt)){op7=1;}
	}
else if(typeof document.all!="undefined"&&!kde){
	exclude=0;
	ie=1;
	if(typeof document.getElementById!="undefined"){
		ie5=1;
		if(agt.indexOf("msie 6")!=-1){
			ie6=1;
			dcm=document.compatMode;
			if(dcm!="BackCompat"){com=1;}
			}
		}
	else{ie4=1;}
	}
else if(typeof document.getElementById!="undefined"){
	exclude=0;
	if(agt.indexOf("netscape/6")!=-1||agt.indexOf("netscape6")!=-1){ns6=1;}
	else if(agt.indexOf("netscape/7")!=-1||agt.indexOf("netscape7")!=-1){ns6=1;ns7=1;}
	else if(agt.indexOf("gecko")!=-1){ns6=1;mz7=1;}
	if(agt.indexOf("safari")!=-1 || (typeof document.childNodes!="undefined" && typeof document.all=="undefined" && typeof navigator.taintEnabled=="undefined")){mz7=0;ns6=1;saf=1;}
	}
else if((agt.indexOf('mozilla')!=-1)&&(parseInt(navigator.appVersion)>=4)){
	exclude=0;
	ns4=1;
	if(typeof navigator.mimeTypes['*']=="undefined"){
		exclude=1;
		ns4=0;
		}
	}
if(agt.indexOf('escape')!=-1){exclude=1;ns4=0;}
if(typeof navigator.__ice_version!="undefined"){exclude=1;ie4=0;}

//END Browser Sniff CS1.1

	var imagePath='/Images/';
	
	var ie=document.all;
	var dom=document.getElementById;
	var ns4=document.layers;
	var bShow=false;
	var textCtl;

	function setTimePicker(t) {
		textCtl.value=t;
		closeTimePicker();
	}

	function refreshTimePicker(mode) {
		
		if (mode==0)
			{ 
				suffix="am"; 
			}
		else
			{ 
				suffix="pm"; 
			}

		sHTML = "<table><tr><td><table cellpadding=3 cellspacing=0 bgcolor='#f0f0f0'>";
		for (i=0;i<=11;i++) {

			sHTML+="<tr align=right style='font-family:verdana;font-size:9px;color:#000000;'>";

			if (i==0) {
				hr = 12;
			}
			else {
				hr=i;
			}	

			for (j=0;j<4;j++) {
				sHTML+="<td width=57 style='cursor:hand' onmouseover='this.style.backgroundColor=\"#66CCFF\"' onmouseout='this.style.backgroundColor=\"\"' onclick='setTimePicker(\""+ hr + ":" + padZero(j*15) + " " + suffix + "\")'><a style='text-decoration:none;color:#000000' href='javascript:setTimePicker(\""+ hr + ":" + padZero(j*15) + " " + suffix + "\")'>" + hr + ":"+padZero(j*15) + "<font color=\"#808080\">" + suffix + "</font></a></td>";
			}

			sHTML+="</tr>";
		}
		sHTML += "</table></td></tr></table>";
		document.getElementById("timePickerContent").innerHTML = sHTML;
	}

	if (dom){
		document.write ("<div id='timepicker' style='z-index:+999;position:absolute;visibility:hidden;'><table style='border-width:3px;border-style:solid;border-color:#0033AA' bgcolor='#ffffff' cellpadding=0><tr bgcolor='#0033AA'><td><table cellpadding=0 cellspacing=0 width='100%' background='" + imagePath + "titleback.gif'><tr valign=bottom height=21><td style='font-family:verdana;font-size:11px;color:#ffffff;padding:3px' valign=center><B>&nbsp;&nbsp;Select a Time&nbsp;&nbsp;</B></td><td><img id='iconAM' src='" + imagePath + "am1.gif' onclick='document.getElementById(\"iconAM\").src=\"" + imagePath + "am1.gif\";document.getElementById(\"iconPM\").src=\"" + imagePath + "pm2.gif\";refreshTimePicker(0)' style='cursor:hand'></td><td><img id='iconPM' src='" + imagePath + "pm2.gif' onclick='document.getElementById(\"iconAM\").src=\"" + imagePath + "am2.gif\";document.getElementById(\"iconPM\").src=\"" + imagePath + "pm1.gif\";refreshTimePicker(1)' style='cursor:hand'></td><td align=right valign=center>&nbsp;<img onclick='closeTimePicker()' src='" + imagePath + "close.gif'  STYLE='cursor:hand'>&nbsp;</td></tr></table></td></tr><tr><td colspan=2><span id='timePickerContent'></span></td></tr></table></div>");
		refreshTimePicker(0);
	}

	var crossobj=(dom)?document.getElementById("timepicker").style : ie? document.all.timepicker : document.timepicker;
	var currentCtl

	function selectTime(ctl,ctl2) {
		var leftpos=0
		var toppos=0

		textCtl=ctl2;
		currentCtl = ctl
		currentCtl.src=imagePath + "timepicker2.gif";

		aTag = ctl
		do {
			aTag = aTag.offsetParent;
			leftpos	+= aTag.offsetLeft;
			toppos += aTag.offsetTop;
		} while(aTag.tagName!="BODY");
		crossobj.left =	ctl.offsetLeft	+ leftpos 
		crossobj.top = ctl.offsetTop +	toppos + ctl.offsetHeight +	2 
		crossobj.visibility=(dom||ie)? "visible" : "show"
		hideElement( 'SELECT', document.getElementById("calendar") );
		hideElement( 'APPLET', document.getElementById("calendar") );			
		bShow = true;
	}

	// hides <select> and <applet> objects (for IE only)
	function hideElement( elmID, overDiv ){
		if( ie ){
			for( i = 0; i < document.all.tags( elmID ).length; i++ ){
				obj = document.all.tags( elmID )[i];
				if( !obj || !obj.offsetParent ){
						continue;
				}
				  // Find the element's offsetTop and offsetLeft relative to the BODY tag.
				  objLeft   = obj.offsetLeft;
				  objTop    = obj.offsetTop;
				  objParent = obj.offsetParent;
				  while( objParent.tagName.toUpperCase() != "BODY" )
				  {
					objLeft  += objParent.offsetLeft;
					objTop   += objParent.offsetTop;
					objParent = objParent.offsetParent;
				  }
				  objHeight = obj.offsetHeight;
				  objWidth = obj.offsetWidth;
				  if(( overDiv.offsetLeft + overDiv.offsetWidth ) <= objLeft );
				  else if(( overDiv.offsetTop + overDiv.offsetHeight ) <= objTop );
				  else if( overDiv.offsetTop >= ( objTop + objHeight + obj.height ));
				  else if( overDiv.offsetLeft >= ( objLeft + objWidth ));
				  else
				  {
					obj.style.visibility = "hidden";
				  }
			}
		}
	}
		 
	//unhides <select> and <applet> objects (for IE only)
	function showElement( elmID ){
		if( ie ){
			for( i = 0; i < document.all.tags( elmID ).length; i++ ){
				obj = document.all.tags( elmID )[i];
				if( !obj || !obj.offsetParent ){
						continue;
				}
				obj.style.visibility = "";
			}
		}
	}

	function closeTimePicker() {
		crossobj.visibility="hidden"
		showElement( 'SELECT' );
		showElement( 'APPLET' );
		currentCtl.src=imagePath + "timepicker.gif"
	}

	document.onkeypress = function hideTimePicker1 () { 
		if (event.keyCode==27){
			if (!bShow){
				closeTimePicker();
			}
		}
	}

	function isDigit(c) {
		
		return ((c=='0')||(c=='1')||(c=='2')||(c=='3')||(c=='4')||(c=='5')||(c=='6')||(c=='7')||(c=='8')||(c=='9'))
	}

	function isNumeric(n) {
		
		num = parseInt(n,10);

		return !isNaN(num);
	}

	function padZero(n) {
		v="";
		if (n<10){ 
			return ('0'+n);
		}
		else
		{
			return n;
		}
	}

	function validateDatePicker(ctl) {

		t=ctl.value.toLowerCase();
		t=t.replace(" ","");
		t=t.replace(".",":");
		t=t.replace("-","");

		if ((isNumeric(t))&&(t.length==4))
		{
			t=t.charAt(0)+t.charAt(1)+":"+t.charAt(2)+t.charAt(3);
		}

		var t=new String(t);
		tl=t.length;

		if (tl==1 ) {
			if (isDigit(t)) {
				ctl.value=t+":00 am";
			}
			else {
				return false;
			}
		}
		else if (tl==2) {
			if (isNumeric(t)) {
				if (parseInt(t,10)<13){
					if (t.charAt(1)!=":") {
						ctl.value= t + ':00 am';
					} 
					else {
						ctl.value= t + '00 am';
					}
				}
				else if (parseInt(t,10)==24) {
					ctl.value= "0:00 am";
				}
				else if (parseInt(t,10)<24) {
					if (t.charAt(1)!=":") {
						ctl.value= (t-12) + ':00 pm';
					} 
					else {
						ctl.value= (t-12) + '00 pm';
					}
				}
				else if (parseInt(t,10)<=60) {
					ctl.value= '0:'+padZero(t)+' am';
				}
				else {
					ctl.value= '1:'+padZero(t%60)+' am';
				}
			}
			else
   		    {
				if ((t.charAt(0)==":")&&(isDigit(t.charAt(1)))) {
					ctl.value = "0:" + padZero(parseInt(t.charAt(1),10)) + " am";
				}
				else {
					return false;
				}
			}
		}
		else if (tl>=3) {

			var arr = t.split(":");
			if (t.indexOf(":") > 0)
			{
				hr=parseInt(arr[0],10);
				mn=parseInt(arr[1],10);

				if (t.indexOf("pm")>0) {
					mode="pm";
				}
				else {
					mode="am";
				}

				if (isNaN(hr)) {
					hr=0;
				} else {
					if (hr>24) {
						return false;
					}
					else if (hr==24) {
						mode="am";
						hr=0;
					}
					else if (hr>12) {
						mode="pm";
						hr-=12;
					}
				}
			
				if (isNaN(mn)) {
					mn=0;
				}
				else {
					if (mn>60) {
						mn=mn%60;
						hr+=1;
					}
				}
			} else {

				hr=parseInt(arr[0],10);

				if (isNaN(hr)) {
					hr=0;
				} else {
					if (hr>24) {
						return false;
					}
					else if (hr==24) {
						mode="am";
						hr=0;
					}
					else if (hr>12) {
						mode="pm";
						hr-=12;
					}
				}

				mn = 0;
			}
			
			if (hr==24) {
				hr=0;
				mode="am";
			}
			ctl.value=hr+":"+padZero(mn)+" "+mode;
		}
	}

//  End -->


