    // Validator Object
    var valid = new Object();

    // REGEX Elements

        // matches zip codes
        valid.zipCode = /\d{5}(-\d{4})?/;

        // matches $17.23 or $14,281,545.45 or ...
        valid.Currency = /\$\d{1,3}(,\d{3})*\.\d{2}/;

        // matches 5:04 or 12:34 but not 75:83
        valid.Time = /^([1-9]|1[0-2]):[0-5]\d$/;

        //matches email
        valid.emailAddress = /.../;

        // matches phone ###-###-####
        valid.phoneNumber = /^\(?\d{3}\)?\s|-\d{3}-\d{4}$/;

        // International Phone Number
        valid.phoneNumberInternational = /^\d(\d|-){7,20}/;

        // IP Address
        valid.ipAddress = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;

        // Date xx/xx/xxxx
        valid.Date = /^(((0?[1-9]|[12]\d|3[01])\.(0[13578]|[13578]|1[02])\.((1[6-9]|[2-9]\d)\d{2}))|((0?[1-9]|[12]\d|30)\.(0[13456789]|[13456789]|1[012])\.((1[6-9]|[2-9]\d)\d{2}))|((0?[1-9]|1\d|2[0-8])\.0?2\.((1[6-9]|[2-9]\d)\d{2}))|(29\.0?2\.((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$/;

        // State Abbreviation
        valid.State = /^(AK|AL|AR|AZ|CA|CO|CT|DC|DE|FL|GA|HI|IA|ID|IL|IN|KS|KY|LA|MA|MD|ME|MI|MN|MO|MS|MT|NB|NC|ND|NH|NJ|NM|NV|NY|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VA|VT|WA|WI|WV|WY)$/i;

        // Social Security Number
        valid.SSN = /^\d{3}\-\d{2}\-\d{4}$/;

		// String of more than 3 chars
        valid.Required = /.../;

		// String of more than 1 chars
        valid.Required1 = /./;

		// String of more than 2 chars
        valid.Required2 = /../;

        valid.shortMonth = /(0[1-9]|1[012])/;
        
        valid.shortYear = /(0[7-9]|1[0-9])/;

        valid.CvcCvv = /([0-9][0-9][0-9][0-9]|[0-9][0-9][0-9])/
        
        valid.CCType = /^(MC|VI|AM|DI)$/i;
        
        //Childage greater than 0
        valid.ChildAge = /^([1-9])?[1-9]$|^[1-9]0$/;
        
        valid.Email = /^([a-z0-9])(([\-.]|[_]+)?([a-z0-9]+))*(@)([a-z0-9])((([-]+)?([a-z0-9]+))?)*((.[a-z]{2,3})?(.[a-z]{2,6}))$/i;
    
  function checkvisable(object)
    {
    var par = object;
while (par.tagName != 'FORM') 
{
if (par.style.visibility=='hidden') {
return false
}
par = par.parentNode 
}
return true
    
    }
    
    function validateForm(theForm) {
var firsterror; 
var ierr = 0;
        var elArr = theForm.elements; 
        
        for(var i = 0; i < elArr.length; i++) {
        
                try{
                if( checkvisable(elArr[i])){
                } else
                {
                
                //ClearDDValue(elArr[i]);
                }
                }
                catch(e) {};
        // loop all controls on page.
           with(elArr[i]) { 
				//get the validator to use
              var v = elArr[i].getAttribute('validator'); 
              if(!v) continue; 
				// get patten matching regular expression
				if ( v == 'Checked'){
				    if ( elArr[i].checked == true){
				
				        var gotIt = true;
				        	
				       }
				    else{
				
				        var gotIt = false;
				    }

				}
				
				
				else
				{
				
				var cascade = elArr[i].getAttribute('parentcontrol');
				    if(cascade != null){
    				var cascadeArray = null;
    				
    				cascadeArray = cascade.split(",");
    				
    		            for (var cascadeLoc = 0; cascadeLoc < cascadeArray.length; cascadeLoc++)
    		            {
    		            var _temp = cascadeArray[cascadeLoc];
				            var ParentControl = document.getElementById(_temp);
            				
				            if ((ParentControl != null && ParentControl.checked != true) || elArr[i].disabled == true){

                                var gotIt = true; 
  
				            }else{
				            
				                var thePat = valid[v]; 
                                var gotIt = thePat.exec(value); 

				            }
    				}
				    }
				    else{
    		    var thePat = valid[v]; 
              // execute reg expression pattern mathing
              var gotIt = thePat.exec(value); 
              //Warning message to show
    				
				    }	
				cascade = null;		
             
              
              }
			var ActiveTE = document.getElementById(elArr[i].getAttribute('validatetarget'));	
				// is the control visable otherwise do nothing
				if( checkvisable(elArr[i])){
				// Hide the Error message first just in case
				if (ActiveTE != null){
					  ActiveTE.style.display='none';
					  ActiveTE.style.visibility='hidden';
					  }
					  				  if(! gotIt){
              //If this is the first error then set the firsterror pointer so we can set focus
					if(ierr == 0) {firsterror = elArr[i];} else {} ;                  
                 //If the control does not pass the test then show error message
						try{
		             	ierr = 1;
		             	if (ActiveTE != null){
						ActiveTE.style.display='inline';
						ActiveTE.style.visibility='visible';
						}}
						catch(e) {};}
              }
              
           }
        }
        
if (ierr==0) {
        // no errors - Then continue
        return true;
}else{ 
try
{


if ( firsterror.getAttribute('ErrAlert') != null){

alert(firsterror.getAttribute('ErrAlert'));

}

if ( firsterror.getAttribute('ErrPopUp') != null){

wizardPopup(firsterror.getAttribute('ErrPopUp'));

}

// try to set the error on the first erroring control
firsterror.select();
}
catch (e) {} ;
// the was an error stop the page posting.
return false;}

    }
    
    
    function wizardPopup(name){
    
    
	switch (name)
	{
	case "Insurance":
	 openthePopUp("/daily/m3e/Insurance_payment.aspx","Elvia Reiseversicherung");
	break;

	default:
	
	break;
	
	}

    
    
    
    
    
    }
    
    
    function openthePopUp(fileName, title)
{
insuranceWnd=window.open(fileName,null,"left=100,top=100,resizable=no,scrollbars=no,width=500,height=600,statusbar=no,status=no,menubar=no,location=no");

insuranceWnd.focus(); } 
