/*
########################################################
##			                                   	
##    Application Name:		Validate Module
##    Developed by Stoco Software Design, LLC		
##                                                   
##    (e-mail responder@stoco.net)                 
##                                   		     
##    Version 1.0                                
##                                                 
##    Script Version 1.0.003                       
##    Last Modified: December 14, 2002                  
##    copyright (c) 2002, 2003                          
##                                                 
##    For additional information visit              
##    http://stoco.net/                     
##                                                 
##################################################################
# COPYRIGHT NOTICE:
#
# Copyright 2002, 2003 Stoco Software Design, LLC.  All Rights Reserved.
#
# This program is a commercial product and must not be copied, modified,
# distributed, or installed without a user license from
# Stoco Software Design, LLC.
#
# For more info visit http://www.stoco.net/
#
###################################################################
*/

var control = 0;
var LastElement;
var LastError;
	
	function validate(vType, FElement) {
		
            var failure;
			
			if (control > 0) {
			   if (!(FElement == LastElement)) {
			   	  LastElement.focus();
				  return 0;
			   }
			}
			
			control++;

            if      (vType == "int") {failure = validateInt(FElement.value); }
            else if (vType == "int0") {failure = validateIntZero(FElement.value); }
            else if (vType == "negint") {failure = validateNegInt(FElement.value); }
            else if (vType == "cur" ) {failure = validateCur(FElement.value); }
            else if (vType == "notnull") {failure = validateNotNull(FElement.value); }
			else if (vType == "email") {failure = validateEmail (FElement.value); }

            if (failure) {		
			    LastError = "- Formatting Error -\n\n" + failure;
				LastElement = FElement;
                alert (LastError + "\n\nField: " + FElement.name);
                FElement.focus();
            } else {
			  control = 0;
			  LastError = "";
			  LastElement = 0;
			}
	}
	
	function validateNotNull (val) {
            var errMsg = "This field can't be blank.";
            if (!(val)) {return errMsg; }
	}
	
	function validateIntZero (val) {
	    var errMsg = "This value must be a number greater than or equal to zero.";
            if (!(val >= 0)) { return errMsg; }
            if (!(val.match(/\d/))) {return errMsg; }
	}
	
	function validateNegInt (val) {
            var errMsg = "This value must be a number.";
            if (!(val.match(/^-?\d+$/))) { return errMsg; }
	}

	function validateEmail (val) {
            var errMsg = "This value must be a valid Email Address.";
            if (!(val.match(/.*\@.*\..*/))) { return errMsg; }
	}
	
	function validateInt (val) {
            var errMsg = "This value must be a number greater than zero.";
            if (!(val > 0)) { return errMsg; }
            if (!(val.match(/\d/))) {return errMsg; }
	}
	
	function validateCur (val) {
            var errMsg = "Currency format is not correct.\nPlease change to decimal format xx.xx";
            var myCur = val;
            
            if (myCur.match(/\$/)) {return "Don't include a currency symbol."; }
            if (!(myCur.match(/^\d+\.\d\d$/))) {return errMsg; }
	}
	
	
	function resetDate(thisForm) {

            var startTime   = new Date();
                    
            var rawTime = startTime
                
            rawTime  = Math.round( startTime.getTime() / 1000 );
                
            thisForm.record_date.value = rawTime;
		
	    thisForm.payment_date.value = startTime;
	
	}
	
	function showTemplate (templateName, myType, sUsername, sSession) {
	
	    window.open(ScriptDir + "/ssd_pageviewer.pl?pagename=" + templateName + "&type=" + myType + "&username=" + sUsername + "&session=" + sSession);
	}


// </script>