	function validate_password_field(password_div,error_div)
	{
	  var str=jQuery('#'+password_div).val();
		jQuery('#submit_feedback').html('');
		error_div="#"+error_div;
		str=trim(str);
		if (str.length==0)
		{
		  jQuery(error_div).html('<p class="error">Password is too short!</p>');
		  return true;
		}
		if (is_alphachar(str)==false)
		{
		  jQuery(error_div).html('<p class="error">Can only contain letters and numbers!</p>');
		  return true;
		}
		if (str.length<6)
		{
		  jQuery(error_div).html('<p class="error">Password is too short!</p>');
		  return true;
		}
		else
		{
			if (str.length>20)
			{
		  	jQuery(error_div).html('<p class="error">Password is too long!</p>');
		  	return true;
			}	
			else
			{
		  	jQuery(error_div).html('<p class="confirmation">Password OK!</p>');
		  	return true;
			}	
		}
	};	
	
	function is_alphachar(str)
	{
	  var	reg_exp = /^([a-zA-Z0-9_-]+)$/;
		if (reg_exp.test(str)==false)
		  return false;
		else
			return true;
	};
	
	function is_numeric(sText)
	{
  	var ValidChars = "0123456789.";
  	var IsNumber=true;
  	var Char;
  	for (i = 0; i < sText.length && IsNumber == true; i++) 
  	{ 
    	Char = sText.charAt(i); 
   	 if (ValidChars.indexOf(Char) == -1) 
   	 {
   		 	IsNumber = false;
 	   }
 	 }
   return IsNumber;
	}

	function is_numeric_key(evt)
	{
  	var charCode = (evt.which) ? evt.which : evt.keyCode
  	if (charCode > 31 && (charCode < 48 || charCode > 57))
    	return false;

   	return true;
	}

	function is_float_key(evt,field)
	{
 		var charCode = (evt.which) ? evt.which : evt.keyCode
	
		if (charCode==46 && field.val().toString().indexOf('.')!=-1)
			return false;
	
 		if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode!=46)
  	  return false;

 		return true;
	}
	
	function round_float_field(field,decimals)
	{
		var float_value=parseFloat(field.val());
		field.val()=float_value.toFixed(decimals);
	}

	function trim(str)
	{
		if (!str)
			var str='';
		var trimmed=str.replace(/^\s+|\s+jQuery/g, '') ;
		return trimmed;
	};	
	
	function validate_form_field(error_div_id,form_div,validate_script)
	{
		error_div_id="#"+error_div_id;
		form_div="#"+form_div;
		jQuery(error_div_id).fadeIn("fast");
		jQuery(error_div_id).html('<p class="information">Validating.....</p>');
		jQuery('#submit_feedback').html('');
		var url=validate_script+jQuery(form_div).val()+"&random="+Math.random();
		
		jQuery(error_div_id).load(url);
		
		return true;
	};
	
	function submit_activate_account(status_div,id)
	{
		status_div="#"+status_div
		jQuery(status_div).html('<p class="information">Submitting form.....</p>');
		jQuery('#activate_account_link').html('Processing......');
		jQuery('#activate_account_link').onclick=function(){};
		
		var do_submit=true;
		if ((jQuery('#new_password_error').html().indexOf('class="error"')>-1) || (jQuery('#confirm_password_error').html().indexOf('class="error"')>-1))
		{
			do_submit=false;
			jQuery(status_div).html(jQuery(status_div).html()+'<p class="error">You have some invalid form settings please correct them and try again.</p>');
		}
		if (jQuery('#current_password').val().toString().length<6)
		{
			do_submit=false;
			jQuery(status_div).html(jQuery(status_div).html()+'<p class="error">The current password is invalid.</p>');		
		}
		if (jQuery('#new_password').val() != jQuery('#confirm_password').val())
		{
			do_submit=false;
			jQuery(status_div).html(jQuery(status_div).html()+'<p class="error">The new passwords do not match.  Please correct and try again.</p>');
		}
		if ((jQuery('#new_password').val() == jQuery('#confirm_password').val()) && (jQuery('#new_password').val() == jQuery('#current_password').val()))
		{
			do_submit=false;
			jQuery(status_div).html(jQuery(status_div).html()+'<p class="error">>The new password must be different to the old password.</p>');
		}

		if (do_submit==false)
		{
			jQuery('#activate_account_link').html('Activate Account');
			jQuery('#activate_account_link').onclick=function(){submit_activate_account('submit_feedback',id);};
		}	
		else
		{
			jQuery(status_div).html(jQuery(status_div).html()+'<p class="confirmation">New Password is ok!</p>');
			jQuery(status_div).html(jQuery(status_div).html()+'<p class="confirmation">Checking current password.......</p>');
			var check_url='/validation_scripts/validate_activate_account.php?id='+id+'&password='+jQuery('#current_password').val()+'&new_pass='+jQuery('#new_password').val()+'&random='+Math.random();
			
			jQuery.get(check_url, function(data,textStatus){
									if (data!='0')
									{
										var response_array=data.split(',');
										jQuery(status_div).html(jQuery(status_div).html() + '<p class="error">Error No.: '+response_array[0]+' '+response_array[1]+'</p>');
										jQuery('#activate_account_link').html('Activate Account');
										jQuery('#activate_account_link').onclick=function(){submit_activate_account('submit_feedback',id);};
										return true;
									}
									else
									{
										jQuery(status_div).html(jQuery(status_div).html() + '<p class="confirmation">Account Activation Successful!</p>');
										create_window();
										return true;
									}	
			});
		}	
		return true;
	};
	
	function submit_password_reset_request(status_div,id)
	{
		status_div="#"+status_div;
		jQuery(status_div).html('<p class="information">Submitting form.....</p>');
		jQuery('#reset_password_link').html('Processing......');
		jQuery('#reset_password_link').onclick=function(){return true;};
		
		var do_submit=true;
		var check_url='/validation_scripts/validate_password_reset_request.php?id='+id+'&random='+Math.random();
		jQuery.get(check_url, function(data,textStatus){
									var response_array=data.split(",");
									
									if (response_array[0]!=0)
									{
										jQuery('#reset_password_link').html('Reset Password');
										jQuery('#reset_password_link').onclick=function(){submit_password_reset_request('submit_feedback',id);};
										jQuery(status_div).html('<p class="error">'+response_array[1]+'</p>');
										return true;
									}
									else
									{
										jQuery(status_div).html('<p class="confirmation">Success!</p>');
										jQuery('#request_sent').slideDown("slow");
										jQuery('#reset_password_link').html('Email Sent');
										return true;
									}	
			});
		return true;
	};	
	function submit_login(status_div,id)
	{
		status_div="#"+status_div;
		jQuery(status_div).html('<p class="information">Submitting form.......</p>');
		jQuery('#login_link').html('Processing......');
		jQuery('#login_link').onclick=function(){return true;};
		
		var do_submit=true;
		var check_url='/validation_scripts/validate_login.php?id='+id+'&location='+jQuery('#location').val()+'&username='+jQuery('#username').val()+'&password='+jQuery('#password').val()+'&random='+Math.random();
			jQuery.get(check_url, function (data,textStatus)
								{
									var response_array=data.split(",");
									
									if (response_array[0]!=0)
									{
										jQuery('#login_link').html('Login');
										jQuery('#login_link').onclick=function(){submit_login('submit_feedback',id);};
										jQuery(status_div).html('<p class="error">'+response_array[1]+'</p>');
										return true;
									}
									else
									{
										jQuery(status_div).html(jQuery(status_div).html() + '<p class="confirmation">Login successful!</p>');
										window.location.href="/app/index.htm";
										return true;
									}	
			});
		return true;
	};
	
	function submit_sign_me_up(status_div)
	{
		status_div="#"+status_div;
		jQuery(status_div).html('<p class="information">Submitting form.....</p>');
		var check_contact_name='/validation_scripts/validate_contact_name.php?contact_name='+jQuery('#contact_name').val()+'&random='+Math.random();
		
		var check_contact_email='/validation_scripts/validate_email.php?email='+jQuery('#contact_email').val()+'&random='+Math.random();
		
		var check_login_name='/validation_scripts/validate_login_name.php?login='+jQuery('#login_name').val()+'&random='+Math.random();
		
		jQuery('#sign_me_up_link').html('Processing......');
		jQuery('#sign_me_up_link').onclick=function(){};
		
		var sign_me_up='/validation_scripts/sign_me_up.php?login='+jQuery('#login_name').val()+'&contact_name='+jQuery('#contact_name').val()+'&email='+jQuery('#contact_email').val()+'&timezone='+jQuery('#timezone').val()+'&random='+Math.random();
		//alert(status_div + ' \\ ' + validate_script + ' \\ ' + url);
		jQuery.get(check_contact_name, function (data,textStatus){
									jQuery(status_div).html(data+jQuery(status_div).html());
									jQuery.get(check_contact_email, function (data2,textStatus){
															jQuery(status_div).html(data2 + jQuery(status_div).html());
															jQuery.get(check_login_name,function (data3,textStatus)
																				{
																					jQuery(status_div).html(data3 + jQuery(status_div).html());
																					if (jQuery(status_div).html().indexOf('class="error"')>-1)
																					{
																						jQuery(status_div).html('<p class="error">You have some invalid form settings please correct them and try again.</p>'+jQuery(status_div).html());
																						jQuery('#sign_me_up_link').html('Sign Me Up');
																						jQuery('#sign_me_up_link').onclick=function(){submit_sign_me_up('submit_feedback');};
																					}
																					else
																					{
																						jQuery(status_div).html('<p class="information">Creating your Online Time Clock MTS Account!</p>' + jQuery(status_div).html());
																						jQuery.get(sign_me_up,function (data4,textStatus)
																											{
																												var response_array=data4.split(",");
																												if (response_array.length!=1) //an error has occurred
																												{
																													jQuery(status_div).html('<p class="error">Error No:'+response_array[0]+' Message: '+response_array[1]+'</p>' +jQuery(status_div).html());
																													jQuery('#sign_me_up_link').html('Sign Me Up');
																													jQuery('#sign_me_up_link').onclick=function(){submit_sign_me_up('submit_feedback');};
																												}
																												else
																												{
																													jQuery(status_div).html(data4 +jQuery(status_div).html());
																													create_window();
																												}
																											}
																						);
																					}
															});
									});
			});
		return true;
	};
	
	function submit_account(status_div)
	{
		status_div="#"+status_div;
		var login_name=jQuery('#login_name').val();
		login_name=trim(login_name);
		if (login_name.length<6)
		{
			jQuery(status_div).html('<p class="error">Error No: 1<br />Message: Invalid Account Name</p><br>');
			return true;
		}
		jQuery('#feedback').fadeOut();
		jQuery(status_div).html('<p class="information">Submitting form.....</p>');
		jQuery('#login_link').html('Processing......');
		jQuery('#login_link').onclick=function(){return true;};
		
		var do_submit=true;
		var check_url='/validation_scripts/validate_account.php?login_name='+login_name+'&random='+Math.random();
		jQuery.get(check_url,function (data,textStatus)
								{
									if (data!='0')
									{
										var response_array=data.split(",")
										
										jQuery('#login_link').html('Submit');
										jQuery('#login_link').onclick=function(){submit_account('submit_feedback');};

										jQuery('#feedback').html('<p class="error">Error No: '+response_array[0]+'<br />Message:'+response_array[1]+'</p><br>');
										jQuery('#feedback').slideDown('slow');
										return true;
									}
									else
									{
										//window.location="/login/"+login_name;
										window.location="/login/"+login_name;
										return true;
									}	
								}
			);
		return true;
	};	
	function check_email(email)
	{
    var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    if(pattern.test(email))
		{         
			return true;   
    }
		else
		{   
			return false; 
    }	
	}
	
	function press_button_on_enter(evt,button_id)
	{
  	var charCode = (evt.which) ? evt.which : evt.keyCode
	
		if (charCode==13)
		{
		  fireEvent(jQuery("#"+button_id),'click');	
			return false;
		}	
	}
	
	function fireEvent(element,event)
	{
    //if (document.createEventObject)
		//{
    //    // dispatch for IE
    //    var evt = document.createEventObject();
   //     return element.fireEvent('on'+event,evt)
   //}
    //else
		//{
        // dispatch for firefox + others
   //     var evt = document.createEvent("HTMLEvents");
   //     evt.initEvent(event, true, true ); // event type,bubbling,cancelable
   //     return !element.dispatchEvent(evt);
   // }
		element.trigger(event);
	}

	function setCookie(c_name,value,expiredays)
	{
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+expiredays);
		document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
	}

	function getCookie(c_name)
	{
		if (document.cookie.length>0)
  	{
  		c_start=document.cookie.indexOf(c_name + "=");
  		if (c_start!=-1)
    	{
    		c_start=c_start + c_name.length+1;
    		c_end=document.cookie.indexOf(";",c_start);
    		if (c_end==-1) 
					c_end=document.cookie.length;
    		return unescape(document.cookie.substring(c_start,c_end));
    	}
  	}
		return "";
	}
