

// HTML to Entities (form) script- By JavaScriptKit.com (http://www.javascriptkit.com)
// For this and over 400+ free scripts, visit JavaScript Kit- http://www.javascriptkit.com/
// This notice must stay intact for use

function html2entities(){
var re=/[(<>"'&]/g
for (i=0; i<arguments.length; i++)
arguments[i].value=arguments[i].value.replace(re, function(m){return replacechar(m)})
}

function replacechar(match){
if (match=="<")
return "&lt;"
else if (match==">")
return "&gt;"
else if (match=="\"")
return "&quot;"
else if (match=="'")
return "&#039;"
else if (match=="&")
return "&amp;"
}



function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_changeProp(objName,theProp,theValue) { //v3.0
 //
 eval("$('"+objName+"')."+theProp+"='"+theValue+"'");  //we use $() notation from the Prototype library
 
}



function autotab(original,destination){
	if (original.getAttribute&&original.value.length==original.getAttribute("maxlength"))
	destination.focus()
}



Event.observe(document, 'keypress', keypress_handler); //to capture key input

function keypress_handler(event) {  //captures key input from keyboard - with Prototype library functions
  //var evK=String.fromCharCode(event.keyCode);
  switch(event.keyCode) {
    //case Event.KEY_TAB:    alert('Tab Pressed');
   // case Event.KEY_RETURN: updateRating_Post(); // Enter key pressed

/*			KEY_ESC 	 Number 	 27: Constant. Code for the Esc key.
			KEY_LEFT 	Number 	37: Constant. Code for the Left arrow key.
			KEY_UP 	Number 	38: Constant. Code for the Up arrow key.
			KEY_RIGHT 	Number 	39: Constant. Code for the Right arrow key.
			KEY_DOWN 	Number 	40: Constant. Code for the Down arrow key.
			KEY_DELETE 	Number 	46: Constant. Code for the Delete key.         */
default: switch(String.fromCharCode(event.keyCode)) {
      //   case 'A':            alert('A Pressed');
     // case 'B':            alert('B Pressed');
	 //
	 //	 
	 
	 //default: alert(evK);
    }
  }
}



		
		
function CompleteDate(datefield){
var todaysDate=new Date();
var currentYear=todaysDate.getFullYear();
var DateFieldValue=$(datefield).value;
//alert(DateFieldValue);
if (DateFieldValue.length==4 && DateFieldValue.indexOf("/")==-1)
	{       
		monthFieldValue=DateFieldValue.substr(0,2);
		DayFieldValue=DateFieldValue.substr(2,2);
		DateFieldValue=monthFieldValue+"/"+DayFieldValue+"/"+currentYear;
		//alert(DateFieldValue);
		$(datefield).value=DateFieldValue;
		$(datefield).focus();
		$(datefield).select();
	}
}

function resetValidateForm(){
				$('fnameValid').innerHTML='';	
				$('lnameValid').innerHTML='';	
				$('emailaddrValid').innerHTML='';	
				//$('radiogroupEventChoiceValid').innerHTML='';
				//$('radiogroupSessionChoiceValid').innerHTML='';
				//Element.toggleClassName('fname', 'formattedBoxAlignedDefault');
				//Element.toggleClassName('lname', 'formattedBoxAlignedDefault');
				//Element.toggleClassName('emailaddr', 'formattedBoxAlignedDefault');
}
function ValidateForm(myForm) {
		 // Validation code -we inititialize the class from validation.js
		//var f = new Validate();  //we use the Validate() from the included js validation.js
		//		alert(myForm.name);
            
				if (myForm.name="msgsend") {
					
					if ($('fname').value.length<1) {
					$('fname').focus();
					$('fname').select();
					//				Element.toggleClassName('fname', 'formattedBoxHighlight');
					$('fnameValid').innerHTML='   First name required !';
					//alert();
					return false;
					}
					
					if ($('lname').value.length<1) {
					$('lname').focus();
					$('lname').select();
					//				Element.toggleClassName('lname', 'formattedBoxHighlight');
					$('lnameValid').innerHTML='  Last name required !';
					//alert('Please provide Last Name !');
					return false;
					
					}
					
					
									  
							//			------Validate email----------------------------
						
							
							//do a basic check for null, zero-length string, ".", "@",
				//and the absence of spaces
					if ($('emailaddr') == null || $('emailaddr').length == 0 ||
					$('emailaddr').value.indexOf('.') == -1 ||
					$('emailaddr').value.indexOf('@') == -1 ||
					$('emailaddr').value.indexOf(' ') != -1){
					$('emailaddrValid').innerHTML='Make sure the email address does ' +
					'not contain any spaces '+
					'and is otherwise valid (e.g., contains the \"commercial at\" @ sign).';
					
					$('emailaddr').focus();
					$('emailaddr').select();	
					return false;
					}
					
						/* The local part cannot begin or end with a "."
						Regular expression specifies: the group of characters before the @
						symbol must be made up of at least two word characters, followed by zero
						or one period char, followed by at least 2 word characters. */
						//regex=/(^\w{2,})@/;
						/*regex=/(^\w{2,}\.?\w{2,})@/;
						
						_match = regex.exec($('emailaddr').value);
					
						if ( _match){
							user=RegExp.$1;
							//				alert("user: "+user);
						} else {
						   $('emailaddrValid').innerHTML="Make sure the user name is more than two characters, "+
								"does not begin or end with a period (.), or is not otherwise "+
								"invalid!";
						 $('emailaddr').focus();
						 $('emailaddr').select();	
						   return false;
							
						}*/
						//get the domain after the @ char
						//first take care of domain literals like @[19.25.0.1], however rare
					regex=/@(\[\d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3}\])$/;
					_match = regex.exec($('emailaddr').value);
				
					if( _match){
						domain=RegExp.$1;
						return true;
					} 
					else {
				/* The @ character followed by at least two chars that are not a period (.),
				followed by a period, followed by zero or one instances of two or more
				characters ending with a period, followed by two-three chars that are
				not periods */}
					
					
					regex=/@(\w{2,}\.(\w{2,}\.)?[a-zA-Z]{2,3})$/;
					_match = regex.exec($('emailaddr').value);
					
					
					if( _match){
						domain=RegExp.$1;
					   //				   alert("domain: "+domain);
					} 
					else {
					 $('emailaddrValid').innerHTML='The domain portion of the email had less than 2 chars '+
									 'or was otherwise invalid!';
						
					 $('emailaddr').focus();
					 $('emailaddr').select();	
						return false;
					 }
		
				
	
			     return true;

				} // for the contacts form
				
				
				
				else if (myForm.name="registration")
				{
										if ($('fname').value.length<1) {
					$('fname').focus();
					$('fname').select();
					//				Element.toggleClassName('fname', 'formattedBoxHighlight');
					$('fnameValid').innerHTML='   First name required !';
					//alert();
					return false;
					}
					
					if ($('lname').value.length<1) {
					$('lname').focus();
					$('lname').select();
					//				Element.toggleClassName('lname', 'formattedBoxHighlight');
					$('lnameValid').innerHTML='  Last name required !';
					//alert('Please provide Last Name !');
					return false;
					
					}
					
					
									  
							//			------Validate email----------------------------
						
							
							//do a basic check for null, zero-length string, ".", "@",
				//and the absence of spaces
					if ($('emailaddr') == null || $('emailaddr').length == 0 ||
					$('emailaddr').value.indexOf('.') == -1 ||
					$('emailaddr').value.indexOf('@') == -1 ||
					$('emailaddr').value.indexOf(' ') != -1){
					$('emailaddrValid').innerHTML='Make sure the email address does ' +
					'not contain any spaces '+
					'and is otherwise valid (e.g., contains the \"commercial at\" @ sign).';
					
					$('emailaddr').focus();
					$('emailaddr').select();	
					return false;
					}
					
						/* The local part cannot begin or end with a "."
						Regular expression specifies: the group of characters before the @
						symbol must be made up of at least two word characters, followed by zero
						or one period char, followed by at least 2 word characters. */
						//regex=/(^\w{2,})@/;
						/*regex=/(^\w{2,}\.?\w{2,})@/;
						
						_match = regex.exec($('emailaddr').value);
					
						if ( _match){
							user=RegExp.$1;
							//				alert("user: "+user);
						} else {
						   $('emailaddrValid').innerHTML="Make sure the user name is more than two characters, "+
								"does not begin or end with a period (.), or is not otherwise "+
								"invalid!";
						 $('emailaddr').focus();
						 $('emailaddr').select();	
						   return false;
							
						}*/
						//get the domain after the @ char
						//first take care of domain literals like @[19.25.0.1], however rare
					regex=/@(\[\d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3}\])$/;
					_match = regex.exec($('emailaddr').value);
				
					if( _match){
						domain=RegExp.$1;
						return true;
					} 
					else {
				/* The @ character followed by at least two chars that are not a period (.),
				followed by a period, followed by zero or one instances of two or more
				characters ending with a period, followed by two-three chars that are
				not periods */}
					
					
					regex=/@(\w{2,}\.(\w{2,}\.)?[a-zA-Z]{2,3})$/;
					_match = regex.exec($('emailaddr').value);
					
					
					if( _match){
						domain=RegExp.$1;
					   //				   alert("domain: "+domain);
					} 
					else {
					 $('emailaddrValid').innerHTML='The domain portion of the email had less than 2 chars '+
									 'or was otherwise invalid!';
						
					 $('emailaddr').focus();
					 $('emailaddr').select();	
						return false;
					 }
		
				
	
			     return true;
				}

}



function updateDIV(divID,HTMLcode,parameterprovided){  //this will update any div tag with the HTML provided in the replacement code
	    
		$(divID).innerHTML ='<img src="../images/16_loading.gif">  Loading ...';
		
		eval("var vardivID=''+divID");
				var varParameter=	parameterprovided;
				//	alert(varParameter);

		var myAjax = new Ajax.Updater(vardivID,HTMLcode , {method: 'post' , parameters: varParameter,  evalScripts: true,requestHeaders: ["If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT"]}); // requestHeaders -- to avoid caching in IE -----------

		}





function UpdateConfirmation_Post(){//used for updating the audit record part
			//first serialize the form to catch all the fields that were added to the innerHTML with Ajax.Updater previuosly then output the loading message
	//alert(ValidateForm($('frmAddNewUWAudit')));
	//if (ValidateForm($('registrationForm'))) {
	var pars = Form.serialize($('registrationForm'));
	$('msgplaceholder').innerHTML ='<img src="img/16_loading.gif">  Updating...';
	//alert	(pars);
	var myAjax = new Ajax.Updater('msgplaceholder','register.asp'  , {method: 'post' , parameters: pars, evalScripts: true,requestHeaders: ["If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT"]});
	//}
	

}

function splitString(varString,delimiter) {
var temp = new Array();
temp = varString.split(delimiter);
return temp; 

}


function EmptyMessageHolder(){
$('msgplaceholder').innerHTML = '';
}


function updatePayment() {
var courseValue = splitString($('course').value,'-');
//alert(courseValue[0]+'  '+courseValue[1]+'   '+courseValue[2]);
$('item_number').value=courseValue[0];
$('item_name').value=courseValue[1]+'  '+courseValue[2];
$('amount').value=courseValue[3];

}

