defaultStep=480;
step=defaultStep;  

$(document).keypress(function(e) {
    if(e.keyCode == 13) 
    {
	return false;
    }
  });





function stopMe(){ 
clearTimeout(timerDown);  
clearTimeout(timerUp); 
} 

function scrollDivDown(id){ 
clearTimeout(timerDown);  
document.getElementById(id).scrollTop+=step;  
timerDown=setTimeout("scrollDivDown('"+id+"')",1);
stopMe();
}  

function scrollDivUp(id){ 
clearTimeout(timerUp);
document.getElementById(id).scrollTop-=step;
timerUp=setTimeout("scrollDivUp('"+id+"')",10);
}  

timerDown=""; 
timerUp="";



document.onmousemove=function(){stopMe();}

;	    
		function DoSelects(action){
			document.getElementById('numitems').value=action;
			document.getElementById('step1').submit();
						}

// Get the HTTP Object
function getHTTPObject(){
   if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
   else if (window.XMLHttpRequest) return new XMLHttpRequest();
   else {
      alert("Your browser does not support AJAX.");
      return null;
   }
}

// Change the value of the outputText field
function setOutput(){
    if(httpObject.readyState == 4){
        document.getElementById('outputText').value = httpObject.responseText;
    }

}

// Implement business logic
function doWork(){
    httpObject = getHTTPObject();
    if (httpObject != null) {
        httpObject.open("GET", "ccnumck.php?inputText="
                        +document.getElementById('inputText').value, true);
        httpObject.send(null);
        httpObject.onreadystatechange = setOutput;
    }
}

var httpObject = null;

function validateFormOnSubmit(theForm) {
var reason = "";


  // reason += isValidCreditCard(theForm.CCNumber);
  reason += validateStatus(theForm.Status,theForm.ReferralS,theForm.Referral);
 // reason += newCCcheck(document.getElementById('outputText').value);

  if (reason != "") {
    alert("The following fields need correction:\n" + reason);
    return false;
  }

  reason += validateEmpty(theForm.Email);
  if (reason != "") {
  var boo="test";
  } else {
        document.getElementById('fields_email').value=theForm.Email;
        document.getElementById('fields_fname').value=theForm.Name;
        document.getElementById('fields_phone').value=theForm.Telephone;
        document.getElementById('fields_address1').value=theForm.Address;
        document.getElementById('fields_city').value=theForm.City;
        document.getElementById('fields_state').value=theForm.State;
        document.getElementById('fields_zip').value=theForm.Zip_Code;
        document.getElementById('fields_dj').value=theForm.Referral;
       
  }
  return true;
}

function newCCcheck(ccvalue){
    if (ccvalue !="valid ") {
      var reason="The credit card entered seems to be invalid\n";
    } else reason="";
return reason;
}

function isValidCreditCard(ccnum){  

var type = typeOfCard(ccnum);
alert(type);
var re;  

if (type == "VISA") {// Visa: length 16, prefix 4, dashes optional.  
re = /^4\d{3}-?\d{4}-?\d{4}-?\d{4}$/;  
} else if (type == "MASTERCARD") {// Mastercard: length 16, prefix 51-55, dashes optional.  
re = /^5[1-5]\d{2}-?\d{4}-?\d{4}-?\d{4}$/;  
} else if (type == "DISCOVER") {// Discover: length 16, prefix 6011, dashes optional.  
re = /^6011-?\d{4}-?\d{4}-?\d{4}$/;  
} else if (type == "AMEX") {// American Express: length 15, prefix 34 or 37.  
re = /^3[4,7]\d{13}$/;  
}  

if (!re.test(ccnum)) {error="Invalid Card Number"; return error;};  

// Validate the credit card checksum  
// Remove all dashes for the checksum checks to eliminate negative numbers  
ccnum = ccnum.split("-").join("");  

// Checksum ("Mod 10")  
// Add even digits in even length strings or odd digits in odd length strings.  
var checksum = 0;  
for (i=(2-(ccnum.length % 2)); i<=ccnum.length; i+=2) {  
checksum += parseInt(ccnum.charAt(i-1));  
}  

// Analyze odd digits in even length strings or even digits in odd length strings.  
for (i=(ccnum.length % 2) + 1; i < ccnum.length; i+=2) {  
var digit = parseInt(ccnum.charAt(i-1)) * 2;  
if (digit < 10) { checksum += digit; } else { checksum += (digit-9); }  
     }  

if ((checksum % 10) == 0) error=""; else error="Please Check The Credit Card Number"; return error;  
}  


function validateContest(theForm) {
var reason = "";

  reason += validateEmpty(theForm.name);
  reason += validateEmpty(theForm.addy);
  reason += validateEmpty(theForm.city);
  reason += validateEmpty(theForm.state);
  reason += validateEmpty(theForm.zip);
  reason += validateEmail(theForm.email,theForm.cemail);
  reason += validateEmpty(theForm.email);
  reason += validateEmpty(theForm.cemail);
  
        
  if (reason != "") {
    alert("The following fields need correction:\n" + reason);
    return false;
  }

  return true;
}

function validateContact(theForm) {
var reason = "";

  reason += validateEmail(theForm.email,theForm.cemail);
  reason += validateEmpty(theForm.email);
  reason += validateEmpty(theForm.cemail);
  reason += validateEmpty(theForm.message);
  
  
        
  if (reason != "") {
    alert("The following fields need correction:\n" + reason);
    return false;
  }

  return true;
}


function typeOfCard(number) {
	/* 
	//	Card Prefixes
	//
	//	Mastercard	51-55
	//	Visa		4
	//	AmEx		34,37
	//	Discover	6011
	*/

	var firstNumber = number.substring(0,1);
	var firstThreeNumbers = number.substring(0,3);

	if (firstNumber == 4) {
		return "VISA";
	} 

	var firstTwoNumbers = number.substring(0,2);
	if (firstTwoNumbers > 50 && firstTwoNumbers < 56) {
		return "MASTERCARD";
	}

	if (firstTwoNumbers == 34 || firstTwoNumbers == 37) {
		return "AMEX";
	}

	var firstFourNumbers = number.substring(0,4);
	if (firstFourNumbers == 6011) {
		return "DISCOVER";
	}
}

// Function that determines whether a credit card number is valid
// Please note that a valid credit card number is not essentially a
// credit card in good standing.

function validateReferral(theForm) {
var reason = "";

  reason += validateEmpty(theForm.ToName);
  reason += validateEmpty(theForm.ToEmail);
  reason += validateEmpty(theForm.FromName);
  reason += validateEmpty(theForm.FromEmail);
        
  if (reason != "") {
    alert("The following fields need correction:\n" + reason);
    return false;
  }

  return true;
}




function validateEmpty(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = 'Yellow'; 
        error = "The required field "+fld.name+" has not been filled in.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;  
}

function validateEmail(fld,fld2) {
    var error = "";
 
    if (!(fld.value == fld2.value)) {
        fld.style.background = 'Yellow'; 
		fld2.style.background = 'Yellow'; 
        error = "The required fields "+fld.name+" and "+fld2.name+" must be the same.\n";
    } else {
        fld.style.background = 'White';
		fld2.style.background = 'White';
    }
    return error;  
}

function validateCC(fld) {
    var error = "";
    
   if (fld.value == "") {
        error = "You didn't enter any numbers in "+fld.name+".\n";
        fld.style.background = 'Yellow';
    } else if (isNaN(fld.value)) {
        error = "The "+fld.name+" field contains illegal characters.\n";
        fld.style.background = 'Yellow';
    } else if (!(fld.name=="CCard_Number4")) {
		if (fld.value.length < 4) {
		error = "The "+fld.name+" field is the wrong length. Make sure you included 4 numbers.\n";
        fld.style.background = 'Yellow'; }
	} else if (fld.name=="CCard_Number4") {
	    if (fld.value.length < 3) {
        error = "The "+fld.name+" field is the wrong length. Make sure you included at least 3 numbers.\n";
        fld.style.background = 'Yellow'; 
	}
	} else {
	fld.style.background = 'White';
    }
    return error;
}

function validateExpiry(fld) {
    var error = "";
    if (fld.value == "") {
        error = "You didn't enter any numbers in "+fld.name+".\n";
        fld.style.background = 'Yellow';
    } else if (isNaN(fld.value)) {
        error = "The "+fld.name+" field contains illegal characters.(numbers only)\n";
        fld.style.background = 'Yellow';
    } else if (fld.value.length < 2) {
		error = "The "+fld.name+" field is the wrong length. Make sure you included 2 numbers.\n";
        fld.style.background = 'Yellow'; 
	} else {
	fld.style.background = 'White';
    }
    return error;
}

function validateStatus(fld,fld2,fld3) {
  var error = "";
  var radioSelected2 = false;
  var nym = -1;
  for (i = 0;  i < fld.length;  i++)
  {
    if (fld[i].checked)
        {radioSelected2 = true;
		nym=i;}
  }

  var ssq1=-1;
  //alert(nym);
 if (nym==0)
  { 
            
	  var ssq1=fld2.selectedIndex;
	  //alert(ssq1);
        if (ssq1==0)
        {
        error="Please choose the DJ's name from the dropdown.\n";
		}
		else {
    fld3.value=fld2.value;
	}
  }
     
	 if (nym==1)
  { 
          
        if (fld3.value=='Name of who referred you')
        {
        error="Please enter the name of the friend who referred you.\n";
	    
    }
  }
  return error;
}


function handleEnter (field, event) {
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			var i;
			for (i = 0; i < field.form.elements.length; i++)
				if (field == field.form.elements[i])
					break;
			i = (i + 1) % field.form.elements.length;
			field.form.elements[i].focus();
			return false;
		} 
		else
		return true;
	} 


  
	function openindex()
      { 
OpenWindow=window.open("", "newwin", "height=200, width=350,toolbar=no,scrollbars="+scroll+",menubar=no");
OpenWindow.document.write("<TITLE>NoDiet.com: Wholesale Membership</TITLE>");
OpenWindow.document.write("<BODY BGCOLOR=#FFFFFF>");
OpenWindow.document.write("<h2>Wholesale Membership</h2>");
OpenWindow.document.write("Your Free Wholesale Membership means anytime in the future you may Reorder Online or Call to Reorder at Wholesale Price of $42 per month! <br>  <br> We DO NOT Auto-Ship.");
OpenWindow.document.write("</BODY>");
OpenWindow.document.write("</HTML>");

OpenWindow.document.close();
self.name="main";
     }	
	 
	 	function openfaq()
      {
window.open('http://nodiet.com/faq_print.htm','mywindow','width=400,height=200,toolbar=no, location=no,directories=no,status=no,menubar=yes,scrollbars=yes,copyhistory=yes, resizable=yes');	  
     }	
