<!--
/*================================================================================
'	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 "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 "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 "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 (!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 "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) > 127)
		{
			alert("Invalid character " + Mid(str, i, 1) + " at position " + (i + 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 and/or Returns 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;
	}
}

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
	
	
	
	myTR = objTable.insertRow();
	myTD = myTR.insertCell();
	myTD.innerText = sFailMessage;
	myTD.className = sClassName;
	
	window.open(sURL,null,sStyle);
	myTD.innerText = sSuccessMessage;
	
}

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()));
}

//  End -->


