﻿// JScript File
function sendform(fname,x)
{	
	nosubmit=0;

	if (x == "savebutton")
	{			
		if(fname == "appointment" )
		{nosubmit = validatedata(fname);}
	}			
	else if (x == "clearbutton")
	{
		for (i=0; i<=document.all(fname).elements.length-1; i++)
		{
			if( document.all(fname).elements[i].type == "text")
			{document.all(fname).elements[i].value = "";}										
			if( document.all(fname).elements[i].type == "textarea")
			{document.all(fname).elements[i].value = "";}			
		}		
		return;
	}
		
	if( nosubmit != -1 )
	{document.all(fname).submit();}
}

/**************************
/ -1 = invalid character (not number)
/ -2 = insufficient num of characters
/
/ strInput = the value to check
/ forwhat = check for 'num' or 'str'
/ strsize = minimum length of value
**************************/
function checkTo(strInput,forwhat,strsize) 
{		
isemail=0;
isdate=0;
isdatecount=0;

	for( ic=0; ic<strInput.length; ic++ ) 
	{
		x = strInput.charAt(ic);
	
		if( forwhat == 'num' ) 
		{	
			if(x <= " " || x == "," || x == "(" || x == "-" || x == "_" || x == ")" || x == "<" || x == ">" || x == "@" || x == ";" ||
				x == "'" || x == "`" || x == ":" || x == "\\" || x == "\"" || x== "[" || x == "]" ||
				(x >= "a" && x <= "z") || (x >= "A" && x <= "Z")) 
			{
				return -1;
				break;
			}			
		}		
		else if( forwhat == 'str' ) 
		{
		//alert(x);
			if(x == " " || x == "(" || x == ")" || x == "<" || x == ">" || x == "@" || x == ";" ||
				x == "'" || x == ":" || x == "\\" || x == "\"" || x== "[" || x == "]" || x == ".") 
			{
				return -1;
				break;
			}			
		}
		else if( forwhat == 'spacedstr' ) 
		{
			if(x == "<" || x == ">" || x == "@" || x == "'" || x == "\\" || x == "\"" || x== "[" || x == "]") 
			{
				return -1;
				break;
			}			
		}
		else if( forwhat == 'email' ) 
		{	
			if(x == "@") 
			{
				isemail = 1;				
			}					
		}
		else if( forwhat == 'date' ) 
		{	
			if(x <= " " || x == "(" || x == ")" || x == "<" || x == ">" || x == "@" || x == ";" ||
				x == "'" || x == "`" || x == ":" || x == "\\" || x == "\"" || x== "[" || x == "]" ||
				(x >= "a" && x <= "z") || (x >= "A" && x <= "Z")) 
			{
				return -1;
				break;
			}
			else if(x == "/") 
			{
				isdatecount = isdatecount + 1;				
			}		
	}
	}
	
	//finishing date check..
	if( forwhat == 'date' && isdatecount != 2 )
	{
		return -1;		
	}	
		
	//finishing email check..
	if( forwhat == 'email' && strInput.length <= 7)
	{
		return -1;
	}
	else if( forwhat == 'email' && isemail != 1 )
	{
		return -1;		
	}	
		
	//checking regular string length for blanks. 		
	if( strInput.length < strsize ) 
	{
		return -1;			
	}
	else if( strInput.length <= 0 )
	{
		return -1;
	}
	else
	{
		return 1;		
	}
}

function validatedata(fname)
{	
	if( fname == "appointment" )
	{
		if( checkTo(document.getElementById("REQUEST_FNAME").value,"str",1) == -1 )
		{
			alert('Field Requires a VALID Character Value (No Spaces), First Name.');
			return -1;	
		}
		if( checkTo(document.getElementById("REQUEST_LNAME").value,"str",1) == -1 )
		{
			alert('Field Requires a VALID Character Value (No Spaces), Last Name.');
			return -1;	
		}
		if( checkTo(document.getElementById("REQUEST_EMAIL").value,"email",1) == -1 )
		{
			alert('Field Requires a VALID Email Address.');
			return -1;
		}
		if( checkTo(document.getElementById("REQUEST_PHONE").value,"num",10) == -1 )
		{
			alert('Field Requires a Numeric Value, H/W Phone.');
			return -1;	
		}
		/*if( checkTo(fvalue,"spacedstr",1) == -1 )
		{
			alert('Please Enter A Message.');
			return -1;	
		}*/		
	}	
return 1;
}

//---- calendar function
			/*<![CDATA[*/

					tx_rlmpdateselectlib_calendar._SDN = new Array
					("Sun",
					 "Mon",
					 "Tue",
					 "Wed",
					 "Thu",
					 "Fri",
					 "Sat",
					 "Sun")

					tx_rlmpdateselectlib_calendar._DN = new Array
					("Sunday",
					 "Monday",
					 "Tuesday",
					 "Wednesday",
					 "Thursday",
					 "Friday",
					 "Saturday",
					 "Sunday")

					tx_rlmpdateselectlib_calendar._MN = new Array
					("January",
					 "February",
					 "March",
					 "April",
					 "May",
					 "June",
					 "July",
					 "August",
					 "September",
					 "October",
					 "November",
					 "December")

					tx_rlmpdateselectlib_calendar._SMN = new Array
					("Jan",
					 "Feb",
					 "Mar",
					 "Apr",
					 "May",
					 "Jun",
					 "Jul",
					 "Aug",
					 "Sep",
					 "Oct",
					 "Nov",
					 "Dec")

						// tooltips
						//For latest version visit: http://dynarch.com/mishoo/calendar.epl Distributed under GNU LGPL.  See http://gnu.org/licenses/lgpl.html for details
					tx_rlmpdateselectlib_calendar._TT = {};
					tx_rlmpdateselectlib_calendar._TT["ABOUT"] = "DHTML Date/Time Selector (c) dynarch.com 2002-2003";
					tx_rlmpdateselectlib_calendar._TT["ABOUT_TIME"] = "";
					tx_rlmpdateselectlib_calendar._TT["TOGGLE"] = "Toggle first day of week";
					tx_rlmpdateselectlib_calendar._TT["PREV_YEAR"] = "Prev. year (hold for menu)";
					tx_rlmpdateselectlib_calendar._TT["PREV_MONTH"] = "Prev. month (hold for menu)";
					tx_rlmpdateselectlib_calendar._TT["GO_TODAY"] = "Go Today";
					tx_rlmpdateselectlib_calendar._TT["NEXT_MONTH"] = "Next month (hold for menu)";
					tx_rlmpdateselectlib_calendar._TT["NEXT_YEAR"] = "Next year (hold for menu)";
					tx_rlmpdateselectlib_calendar._TT["SEL_DATE"] = "Select date";
					tx_rlmpdateselectlib_calendar._TT["DRAG_TO_MOVE"] = "Drag to move";
					tx_rlmpdateselectlib_calendar._TT["PART_TODAY"] = " (today)";
					tx_rlmpdateselectlib_calendar._TT["MON_FIRST"] = "";
					tx_rlmpdateselectlib_calendar._TT["SUN_FIRST"] = "";
					tx_rlmpdateselectlib_calendar._TT["DAY_FIRST"] = "Toggle: Week starts with %s";

					tx_rlmpdateselectlib_calendar._TT["CLOSE"] = "Close";
					tx_rlmpdateselectlib_calendar._TT["TODAY"] = "Today";

						// date formats
					tx_rlmpdateselectlib_calendar._TT["DEF_DATE_FORMAT"] = "%Y-%m-%d";
					tx_rlmpdateselectlib_calendar._TT["TT_DATE_FORMAT"] = "%A, %B %e";
					tx_rlmpdateselectlib_calendar._TT["WEEKEND"] = "6,0";

					tx_rlmpdateselectlib_calendar._TT["WK"] = "wk";

						// This function gets called when the end-user clicks on some date.
					function tx_rlmpdateselectlib_selected(cal, date) {
						cal.sel.value = date; // just update the date in the input field.
						//cal.sel.onchange();
						cal.callCloseHandler();
						if (cal.dateClicked) 
							tx_rlmpdateselectlib_closeHandler(cal);
						
					}

						// And this gets called when the end-user clicks on the _selected_ date,
						// or clicks on the "Close" button.  It just hides the calendar without
						// destroying it.
					function tx_rlmpdateselectlib_closeHandler(cal) {
						cal.hide();                        // hide the calendar
					}

						// This function shows the calendar under the element having the given id.
						// It takes care of catching "mousedown" signals on document and hiding the
						// calendar if the click was outside.
					function tx_rlmpdateselectlib_showCalendar (id, format) {
						var el = document.getElementById(id);
						if (calendar != null) {				// we already have some calendar created
							calendar.hide();				// so we hide it first.
						} else {
								// first-time call, create the calendar.
							var cal = new tx_rlmpdateselectlib_calendar(false, null, tx_rlmpdateselectlib_selected, tx_rlmpdateselectlib_closeHandler);
							cal.weekNumbers = 1;
							calendar = cal;                  // remember it in the global var
							cal.setRange(1900, 2070);        // min/max year allowed.
							cal.create();
						}
						calendar.setDateFormat(format);    // set the specified date format
						calendar.parseDate(el.value);      // try to parse the text in field
						calendar.sel = el;                 // inform it what input field we use
					  calendar.showAtElement(el);
					  return false;
					}
			/*]]>*/

