function surfto(location, width, height) {
	popup = window.open(location, "MessageWindow", "toolbar=yes,menubar=yes,top=0,left=500,scrollbars=yes,resizable=yes,height=" + height + ",width=" + width);
}

function PhoneValidation(strng) {
var matchArr = strng.match(/^(\d{3})-?\d{3}-?\d{4}$/);
var numDashes = strng.split('-').length - 1;
if (matchArr == null || numDashes == 1) {
alert('Invalid Phone number. Must be 10 digits or in the form NNN-NNN-NNNN.');
return false;
}
else {
return true;
   }
}

/*
this function takes the text string card number and runs the Mod 10 formula on its respective digits.
Mod 10 is the check digit formula for the supported cards these functions attempt to validate.
this function returns true if the number passes the check digit test. false otherwise.
*/
function mod10( cardNumber ) { // LUHN Formula for validation of credit card numbers.
	var ar = new Array( cardNumber.length );
	var i = 0,sum = 0;
    	for( i = 0; i < cardNumber.length; ++i ) {
    		ar[i] = parseInt(cardNumber.charAt(i));
    	}
    	for( i = ar.length -2; i >= 0; i-=2 ) { // you have to start from the right, and work back.
    		ar[i] *= 2;							 // every second digit starting with the right most (check digit)
    		if( ar[i] > 9 ) ar[i]-=9;			 // will be doubled, and summed with the skipped digits.
    	}										 // if the double digit is > 9, add those individual digits together 


        	for( i = 0; i < ar.length; ++i ) {
        		sum += ar[i];						 // if the sum is divisible by 10 mod10 succeeds
        	}
        	return (((sum%10)==0)?true:false);	 	
    }


        function expired( month, year ) {
        	var now = new Date();							// this function is designed to be Y2K compliant.
        	var expiresIn = new Date(year,month,0,0,0);		// create an expired on date object with valid thru expiration date
        	expiresIn.setMonth(expiresIn.getMonth()+1);		// adjust the month, to first day, hour, minute & second of expired month
        	if( now.getTime() < expiresIn.getTime() ) return false;
        	return true;									// then we get the miliseconds, and do a long integer comparison
    }

/*
This function will check string length, valid characters, specific credit card prefixes and test
the Mod 10 (LUHN Formula) for validating possible credit card numbers. This function can only
authorize that the given card data is potentially valid. It will still need to run actual
card validation routines to verify the actual account.
this function returns true if the card number could be valid for the card type and expiration date.
false otherwise.
*/
        function validateCard(cardNumber,cardType,cardMonth,cardYear) {
        	if( cardNumber.length == 0 ) {						
        		alert("Please enter a valid card number.");
        		return false;
								
        	}
        	for( var i = 0; i < cardNumber.length; ++i ) {		// make sure the number is all digits.. (by design)
        		var c = cardNumber.charAt(i);


            		if( c < '0' || c > '9' ) {
            			alert("Please enter a valid card number. Use only digits. Do not use spaces or hyphens.");
            			return false;
            		}
            	}
            	var length = cardNumber.length;			//perform card specific length and prefix tests
                	switch( cardType ) {
                		case 'a':
                    			if( length != 15 ) {
                    				alert("Please enter a valid American Express Card number.");
                    				return;
                    			}
                    			var prefix = parseInt( cardNumber.substring(0,2));
                        			if( prefix != 34 && prefix != 37 ) {
                        				alert("Please enter a valid American Express Card number.");
                        				return;
                        			}
                        			break;
                        		case 'd':
                           			if( length != 16 ) {
                            				alert("Please enter a valid Discover Card number.");
                            				return;
                            			}
                            			var prefix = parseInt( cardNumber.substring(0,4));
                                			if( prefix != 6011 ) {
                                				alert("Please enter a valid Discover Card number.");
                                				return;
                                			}
                                			break;
                                		case 'm':
                                    			if( length != 16 ) {
                                    				alert("Please enter a valid MasterCard number.");
                                    				return;
                                    			}
                                    			var prefix = parseInt( cardNumber.substring(0,2));


                                        			if( prefix < 51 || prefix > 55) {
                                        				alert("Please enter a valid MasterCard Card number.");
                                        				return;
                                        			}
                                        			break;
                                        		case 'v':
                                           			if( length != 16 && length != 13 ) {
                                            				alert("Please enter a valid Visa Card number.");
                                            				return;
                                            			}
                                            			var prefix = parseInt( cardNumber.substring(0,1));


                                                			if( prefix != 4 ) {
                                                				alert("Please enter a valid Visa Card number.");
                                                				return;
                                                			}
                                                			break;
                                                	}
                                                	if( !mod10( cardNumber ) ) { 		// run the check digit algorithm
                                                		alert("Sorry! This is not a valid credit card number.");
                                                		return false;
                                                	}
                                                	if( expired( cardMonth, cardYear ) ) {							// check if entered date is already expired.
                                                		alert("Sorry! The expiration date you have entered would make this card invalid.");
														
                                                		return false;
                                                	}
                                                	
                                                	return true; // at this point card has not been proven to be invalid
}
	
	function isEmpty(strng) {
		if (strng == null || strng == "") {
			return true;
		}
		for (i=0;i<strng.length;i++) {
			if (strng.charAt(i) != ' ')
			return false;
			}
			return true;
		}
		
	function checkCheckBox(f){
		if (isEmpty(f.FIRST_NAME.value))
		{	
			alert('Please enter your first name.');
			return false;
		}
		else
		if (isEmpty(f.LAST_NAME.value))
		{	
			alert('Please enter your last name.');
			return false;
		}
		else
		if (isEmpty(f.ADDRESS.value))
		{	
			alert('Please enter your street address.');
			return false;
		}
		else
		if (isEmpty(f.CITY.value))
		{	
			alert('Please enter the city name.');
			return false;
		}
		else
		if (isEmpty(f.ZIP.value))
		{	
			alert('Please enter the ZIP code.');
			return false;
		}
		else
		if (isNaN(f.ZIP.value) || f.ZIP.value.length != 5)
		{	
			alert('Please enter a valid 5 digits ZIP code.');
			return false;
		}
		else
		if (isEmpty(f.PHONE.value))
		{	
			alert('Please enter your phone number.');
			return false;
		}
		else
		if (!PhoneValidation(f.PHONE.value))
		{	
			return false;
		}
		else
		if (isEmpty(f.EMAIL.value))
		{	
			alert('Please enter your email address.');
			return false;
		}
		else
		if (!ValidEmail(f.EMAIL.value))
		{	
			alert('Please enter a valid email address.');
			return false;
		}
		else
		if (!f.terms.checked)
		{
			alert('You must agree to the terms and conditions to proceed.');
			return false;
		}else
			return true;
		}
		
function DataValidate()
{
	Msg = '';
	reviewform.Submit.disabled=true;
		if (!reviewform.terms.checked)
		{			
		 	alert('Please check the box confirming you have read and agree to our terms and conditions.');
			reviewform.terms.focus();
			reviewform.Submit.disabled=false;
			return false;
		 }

	else
	
	return true;
}
		
function checkCheckBox2(f){
		//f.mysubmit.disabled=true;
		if (!f.terms.checked)
		{
			alert('You must agree to the terms and conditions to proceed.');
			return false;
			f.mysubmit.disabled=false;
		}
		else 
		//document.getElementById('mysubmit').disabled = true;
		return true;
		
		//f.mysubmit.disabled=true;						
		}
		
function checkSubmit() { 
showHide('hidden') 
if (!reviewform.terms.checked) 
{ 
alert("Please check the box to continue.");
reviewform.terms.focus(); 
showHide('visible') 
return false 
} 
return true 
} 


function showHide(vis) { 
reviewform.mysubmit.style.visibility = vis; 
} 
		
			
		
	function ValidEmail(str) {
	Valid = false;
	if (str.length > 0) {
		if (str.indexOf(' ') > 0 || str.indexOf(',') > 0 || str.indexOf(';') > 0)
				return false;		
				at = str.indexOf('@');
				if (at > 0) {
					dot = str.indexOf('.',at);
				if (dot > (at + 1) && dot < str.length - 1)
				Valid = true;
		}			
	}
	return Valid;
}

function emailMe() {
			var f = document.FEMAIL;
				if (isEmpty(f.EMAIL.value)) {
					alert('Please enter your email address.');
					f.EMAIL.focus();				
				}
				else
				if (!ValidEmail(f.EMAIL.value)) {
					alert('Please enter a valid email address.');
					f.EMAIL.focus();				
				}
				else {
					f.submit();
				}				
}

function reviewsend() {
			var f = document.reviewform;
				if (!f.terms.checked) {
					alert('Please check this box in order to accept the terms and conditions.');
					f.terms.focus();	
					//f.mysubmit.disabled=false;
					//document.getElementById("mysubmit").disabled=false;

				}
				else {
					f.submit();
					//f.mysubmit.disabled=true;
					//document.getElementById("mysubmit").disabled=true;
				}				
}

		function submitit() {
			var o = document.FORDER;
				if (isEmpty(o.FIRST_NAME.value)) {
					alert('Please enter your first name.');
					o.FIRST_NAME.focus();				
				}
				else
				if (isEmpty(o.LAST_NAME.value)) {
					alert('Please enter your last name.');
					o.LAST_NAME.focus();				
				}
				else
				if (isEmpty(o.ADDRESS.value)) {
					alert('Please enter your street address.');
					o.ADDRESS.focus();				
				}
				else
				if (isEmpty(o.CITY.value)) {
					alert('Please enter the city name.');
					o.CITY.focus();				
				}
				else 
				if (isEmpty(o.ZIP.value)) {
					alert('Please enter the ZIP code.');
					o.ZIP.focus();				
				}
				else
				if (isNaN(o.ZIP.value) || o.ZIP.value.length != 5) {
					alert('Please enter a valid 5 digits ZIP Code');
					o.ZIP.focus();				
				}
				else
				if (isEmpty(o.EMAIL.value)) {
					alert('Please enter your email address.');
					o.EMAIL.focus();				
				}
				else
				if (!ValidEmail(o.EMAIL.value)) {
					alert('Please enter a valid email address.');
					o.EMAIL.focus();				
				}
				else
				if (!PhoneValidation(o.PHONE.value)) {
					o.PHONE.focus();				
				}
				else
				if (!o.terms.checked) {
					alert('Please check the box confirming you have read and agree to our terms and conditions.');		
				}
				else {
					o.submit();
				}				
			}
			
			

			
			function nextstep() {
			var o = document.FORDER;
			if (!validateCard(o.ACCOUNT_NUMBER.value,o.CARD_TYPE.value, o.EXPIRE_MONTH.options[o.EXPIRE_MONTH.options.selectedIndex].value , o.EXPIRE_YEAR.options[o.EXPIRE_YEAR.options.selectedIndex].value)) {				
				}
				else {
					o.submit();
				}
			}
			
			function newnextstep() {
    			var o = document.FORDER;


    			if(o.CCV2.value){
				    if( o.accept.checked ) {
				        if( o.CARD_TYPE.value ) {
				            if( o.ACCOUNT_NUMBER.value ) {
				                if( o.EXPIRE_MONTH.value ) {
                                    if( o.EXPIRE_YEAR.value ) {
                                        //do nothing, let them continue to the cc validate call below
                                    }
                                    else {
                                        alert('Please select the credit card expiration year.');
				                        return false;       
                                    }
				                }
				                else {
				                    alert('Please select the credit card expiration month.');
				                    return false;
				                }
				            }
    				        else {
    				            alert('Please enter a credit card number.');
				                return false;    
    				        } 
				        }
				        else {
				            alert('Please select a credit card type.');
				            return false;
				        }
				    
				    }
				    else {
				        alert('Please check the box confirming you have read and agree to our terms and conditions.');
				        return false;
				    }
				}
			    else {
				    alert("You must enter the 3 digit security code (CCV2) found on the back of your card");
				    return false;
				}
    			
    			if (!validateCard(o.ACCOUNT_NUMBER.value,o.CARD_TYPE.value, o.EXPIRE_MONTH.options[o.EXPIRE_MONTH.options.selectedIndex].value , o.EXPIRE_YEAR.options[o.EXPIRE_YEAR.options.selectedIndex].value)) {				
                    return false;
    		    }
    		    else {
    		        o.submit(); 
    		        o.complete.disabled=true;
    		        //document.getElementById("complete").disabled=true;
				    alert('Your order is being submitted. Please wait, do not click twice.');
                    return true;
    		    }
			}
			

				var AlreadySent = false;
				var sMessage = '';
				var sIDChars = "0123456789";
				
				function sendIt(theForm) {
					if (AlreadySent) {
						sMessage = 'Please wait while you order request is being processed'
						alert(sMessage);
						return false;
					} else {
						if (document.FORDER.FIRST_NAME.value=="")
							sMessage	= sMessage + "Please, enter your first name\n";
						if (document.FORDER.LAST_NAME.value=="")
							sMessage	= sMessage + "Please, enter your last name\n";
						if (document.FORDER.ACCOUNT_NUMBER.value=="") {
							sMessage	= sMessage + "Please, enter your Credit Card Number\n";
						}
						//else {
						//	for (i=0;i < document.FORDER.ACCOUNT_NUMBER.length;i++) {
						//		if 
						if (document.FORDER.EXPIRE_MONTH.options.selectedIndex < 1)
							sMessage	= sMessage + "Please, indicate the expiration month\n";
						if (document.FORDER.EXPIRE_YEAR.options.selectedIndex < 1)
							sMessage	= sMessage + "Please, indicate the expiration year\n";
						if (document.FORDER.ADDRESS.value=="" || document.FORDER.CITY.value=="" || document.FORDER.STATE.value==""  || document.FORDER.COUNTRY.value==""){
							sMessage	= sMessage + "Please, complete your address\n";
							}else
								if(document.FORDER.POSTAL_CODE.value.length != 5)
									sMessage	= sMessage + "Please, complete your address (Postal Code)\n"
						if (document.FORDER.EMAIL.value=="")
							sMessage	= sMessage + "Please, enter a valid email address\n";
						if (document.FORDER.PHONE.value=="")
							sMessage	= sMessage + "Please, enter a phone number\n";
						if (sMessage!="") {
							alert(sMessage);
							sMessage="";
							return false;
						} else {
							AlreadySent = true;
							theForm.securePurchase.disabled=true;
							return true;
						}
					}
				}
				
				function AcceptChars(specialChars) {  
					var LvChar = window.event.keyCode;  
					var index;  
					var LbAceptChar = false; 
					for (index = 0; index < specialChars.length; index++){  
						if ( specialChars.charCodeAt(index) == LvChar ) { 
							LbAceptChar = true; 
							break; 
						} 
					}  
					if (!LbAceptChar) window.event.keyCode = 0;  
				}

				function initialize(){
					
				}


