﻿var firefox=document.getElementById&&!document.all;	

function getControl(ID){
    return document.getElementById(ID)
}
		
		function bodyLoad(){
             var xx = document.getElementById("form1");
             xx.title.focus();
        }
		
		
		
		function numericOnly(e){

			var keycode = 0;
			
			if(!firefox){
				keycode = window.event.keyCode;
			}else{
				keycode = e.charCode;
			}		
			if(firefox && keycode == 0){
				return true;
			}
			
			if(	
			    keycode == 8 || //backspace
			    keycode == 127  //delete
			    )		// \
			{ 
			    return true;
			}
			
			if(keycode<48 || keycode >57){
				if(!firefox){
					window.event.keyCode = 8;
				}else{
					return false;
				}
			}
		}
		
		function dayPhoneOnly(e, contact)
		{
		    var blnIncorrectStart = false;
		     var keycode = 0;
			
			if(!firefox){
				keycode = window.event.keyCode;
			}else{
				keycode = e.charCode;
			}		
			if(firefox && keycode == 0){
				return true;
			}
			
			if(	
			    keycode == 8 || //backspace
			    keycode == 127  //delete
			    )		// \
			{ 
			    return true;
			}
		    
		    if(contact.length == 0){
		        if(keycode != 48){
		            blnIncorrectStart = true;
		        }
		    }
		   
		    if(blnIncorrectStart){
				    if(!firefox){
					    window.event.keyCode = 8;
				    }else{
					    return false;
				    }
		    }
		    
		    numericOnly(e);
	    }
		
		function mobilePhoneOnly(e, mobile){
		    var blnIncorrectStart = false;
		    
		    var keycode = 0;
			
			if(!firefox){
				keycode = window.event.keyCode;
			}else{
				keycode = e.charCode;
			}		
			if(firefox && keycode == 0){
				return true;
			}
			
			if(	
			    keycode == 8 || //backspace
			    keycode == 127  //delete
			    )		// \
			{ 
			    return true;
			}
		    
		    if(mobile.length == 0){
		        if(keycode != 48){
		            blnIncorrectStart = true;
		        }
		    }
		    if(mobile.length == 1){
		        if(keycode != 52){
		            blnIncorrectStart = true;
		        }
		    }
		    if(blnIncorrectStart){
				    if(!firefox){
					    window.event.keyCode = 8;
				    }else{
					    return false;
				    }
		    }
		    
		    numericOnly(e);  
	    }
		
		function alphaOnly(e){
		    var keycode = 0;
			
			if(!firefox){
				keycode = window.event.keyCode;
			}else{
				keycode = e.charCode;
			}
			
			if(firefox && keycode == 0){
				return true;
			}
			
			if(	
			    keycode == 8 || //backspace
			    keycode == 127 || //delete
			    keycode == 32 ||	// space
				keycode == 39 ||	// '
				keycode == 45 ||	// -
				keycode == 92 ||	// /
				keycode == 47)		// \
			{ 
			    return true;
			}			
			
			if( (keycode<65 || keycode >90 ) && (keycode < 97 || keycode > 122)){
				if(!firefox){
					window.event.keyCode = 8;
				}else{
					return false;
				}
				//window.event.cancelBubble = true;
			}
	    }
	    
	    function alphaNumericOnly(e){
	        var keycode = 0;
			
			if(!firefox){
				keycode = window.event.keyCode;
			}else{
				keycode = e.charCode;
			}
			
			if(firefox && keycode == 0){
				return true;
			}
			
			if(keycode == 32 ){ //space bar
			    return true;
			}
			
			if(	
			    keycode == 8 || //backspace
			    keycode == 127  //delete
			    )		// \
			{ 
			    return true;
			}			
			
			if (keycode == 45 ||	// -
				keycode == 44 ||	// ,
				keycode == 47 ||	// \
				keycode == 92 ||	// /
				keycode == 39)		// '
			{
				return true;
			}
			
			if( (keycode<65 || keycode >90 ) && (keycode < 97 || keycode > 122) && (keycode<48 || keycode >57)){
				if(!firefox){
					window.event.keyCode = 8;
				}else{
					return false;
				}
				//window.event.cancelBubble = true;
			}
	    }
	    
	    function currencyOnly(keycode){
			
			if(keycode == 46){ // period
			    return true;
			}
			
			if(firefox && keycode == 0){
				return true;
			}
			
			if(	
			    keycode == 8 || //backspace
			    keycode == 127  //delete
			    )		// \
			{ 
			    return true;
			}
			
			if(keycode<48 || keycode >57){
			    return false;
			}
			return true;
	    }
	    
	    function currencyOnly(keycode){
			
			if(keycode == 46){ // period
			    return true;
			}
			
			if(firefox && keycode == 0){
				return true;
			}
			
			if(	
			    keycode == 8 || //backspace
			    keycode == 127  //delete
			    )		// \
			{ 
			    return true;
			}
			
			if(keycode<48 || keycode >57){
			    return false;
			}
			return true;
	    }
	    
	    function checkPurchaseAmount(e){
	    
	        var keycode = 0;
			
			if(!firefox){
				keycode = window.event.keyCode;
			}else{
				keycode = e.charCode;
			}
			
			if(!currencyOnly(keycode)){
			   if(!firefox){
					window.event.keyCode = 8;
					return false;
				}else{
					return false;
				}
			}
			
			
			
	        var xx = document.getElementById("form1");	        
	        var val = xx.purchaseamount.value
	        
	        var len = val.length;
	        
	        if(len == 4 && val.indexOf(".") < 0 && keycode != 46){
	            if(!firefox){
					window.event.keyCode = 8;
					return false;
				}else{
					return false;
				}
	        }
	        
	       if(val.indexOf(".") > -1 && val.indexOf(".") == val.length-3){
	            if(!firefox){
					window.event.keyCode = 8;
					return false;
				}else{
					return false;
				}
	       }
	        
	    }
	    
	    function emailCharsOnly(e){
	         var keycode = 0;
			
			if(!firefox){
				keycode = window.event.keyCode;
			}else{
				keycode = e.charCode;
			}
			
			if(firefox && keycode == 0){
				return true;
			}
			
			//alert(keycode);
			    //period               @             _
			if(keycode == 46 || keycode == 64 || keycode == 95){ //.@_
			    return true;
			}			
			
			if( (keycode<48 || keycode >57) && (keycode<65 || keycode >90 ) && (keycode < 97 || keycode > 122)){
				if(!firefox){
					window.event.keyCode = 8;
				}else{
					return false;
				}
				//window.event.cancelBubble = true;
			}
	    }
		
		function checkLength(e,len){
			var obj
			if(!firefox){
				obj = window.event.srcElement;
			}else{
				obj = e.target;
			}
				if(obj.value == ""){return;}
				
				if(obj.value.length < len){
					alert("Please make sure this field is " + len + " numbers long");
					obj.focus();
				}
		} 

