var isNav;
var isIE;
var blnSwapImage = true;

if (navigator.appName == "Netscape") {
	isNav = 0;
	document.captureEvents(Event.KEYPRESS);
} else if (navigator.appName == "Microsoft Internet Explorer") {
	isIE = 1;
} else {
	isIE = 1;
}

function checkKey1(e) {
	var keyChar;

	if (isNav == 0)	{
		if(e.which < 48 || e.which > 57) e.RETURNVALUE = false;
		//alert("e.which=" + e.which);
	} else {
		if(e.keyCode <48 || e.keyCode > 57) e.returnValue = false;
	}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}


function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
	 document.MM_returnValue = (errors == '');
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  if(blnSwapImage) {
	  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
  }
}

function MM_swapImage() { //v3.0
  if(blnSwapImage) {
	  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	  if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
  }
}

function doRollover(el, src){
    el.src = src;
}

function togglePopup(divID){
    var eld = document.getElementById(divID);    
    eld.style.display = (eld.style.display == "none" || eld.style.display == "") ? "block" : "none";
}


/* Page Functions */
/*function checkDropDown()
{
	
	if (document.getElementById("Country").value == "US") 
	{
		document.getElementById("RollingStoneDiv").style.display = ''; 
	}
	else
	{
	 	document.getElementById("RollingStoneDiv").style.display = 'none'; 
	}
	
}*/
function submitFrm(frmName)
{

document.Register_1.submit();
return true;
}

function testForm()
{
	//MM_validateForm('FirstName','','R','LastName','','R','Address1','','R','City','','R','ZipCode','','R','Birth_Year','','RinRange1800:2010','PhoneNbr','','R');
	MM_validateForm('FirstName','','R','LastName','','R','Address1','','R','City','','R','ZipCode','','R','PhoneNbr','','R');
	if (document.MM_returnValue) {
		document.Register_1.submit();
	}
	return document.MM_returnValue;
}




function checkUsername(elName, submitForm, frm){

   //var username = $F(elName);
   loadComplete = false;
   if(submitForm == null) submitForm = false;
 
 if(!$(elName)) return false;
 
 if($(elName).value == ""){
    $('usernameAvailable').style.display = "none";
    return true;
 }
   
 if($('usernameAvailable')){  
	new Ajax.Updater('usernameAvailable', '/Estore/services/customer/AllAccessRegistration/checkusername2.asp', {
		asynchronous: true,
		parameters: { checkusername: $(elName).value },
		onComplete: function (){
			var blnIsTaken = true;	
				//check if the message came back that it is available	
				if($('usernameAvailable').innerHTML == "available"){
					blnIsTaken = false;
				}    
				
				// if its available and submitform is true then lets call the submit function
				//otherwise just show the message 			
				if(submitForm){
					if(blnIsTaken){
						showUserNameResult(blnIsTaken);
					}else{					
						$('usernameAvailable').style.display = 'none';
					}				
					doSubmit(blnIsTaken);					
				}else{ 				
					showUserNameResult(blnIsTaken);
				}
			}
	});  
   
   }  
 return false;
   //new Effect.Appear($('usernameAvailable'), {to:1.0, duration: .5 });   
}

function showUserNameResult(blnIsTaken){
	 var startColor = "ffcc00";
     var endColor = "CC0000";
     if(!blnIsTaken){
        endColor = "#009900";        
    }
    
    $('usernameAvailable').innerHTML = (!blnIsTaken)? "The username is available. Please continue" : "Username already taken. Please try again";
        try{
            new Effect.Appear($('usernameAvailable'), { duration: .1 });
            new Effect.Highlight($('usernameAvailable'),{duration:2.0, startcolor: startColor, endcolor: endColor, restorecolor: endColor });
		    new Effect.Opacity($('usernameAvailable'), {to:1.0, duration: .5 });
        }catch(e){
            $('usernameAvailable').style.display = 'block';
        }
}

//loads url with argument 'url' into div with argument 'divID' using get method
function getHTML(divID, url)
	{	
	var myAjax = new Ajax.Updater(divID, url, {method: 'get', evalScripts: true});
	}	

function getRequest(url, callbackFunction)
	{   
    var myAjax = new Ajax.Request( url, {method: 'post',onComplete: eval(callBackFunction)} );
	}


function chkNum(){
check = document.frmRegistration.strPIN0.value + document.frmRegistration.strPIN1.value +document.frmRegistration.strPIN2.value + document.frmRegistration.strPIN3.value;

if (check == '') {
	//alert('Please enter your All Access card number, which can be found on the back of your All Access card.')
	return false;
	}
var digit = 1;
var weight = 2;
var check_digit = 1;
var i = 0;
var j = 0;
var product = 0;
var sum = 0;
var remainder = 0;
var digit_passed = check.substr(15,1);

for (i=0;i<15;i++) {
	digit = check.substr(i,1);
	product = digit * weight;
	if (product > 9)
		product = product - 9;
	sum = sum + product;
	if (weight == 2)
		weight = 1;
	else
		weight = 2;
	}
remainder = sum % 10;
check_digit = 10 - remainder;
if (check_digit == 10)
	check_digit = 0;
if (check_digit != digit_passed) {
	//alert('The number you entered is not correct. Please verify that you are entering the number on the back of your Membership card.')
	document.getElementById("jsvalidator_strPIN3").innerHTML = "The number you entered is not correct. Please verify that you are entering the number on the back of your Membership card.";
	new Effect.Opacity('jsvalidator_strPIN3', {to:1.0, duration: .5 });
	document.frmRegistration.strPIN0.focus();
	return false;
	}
//document.frmRegistration.submit();
return true;
}

window.onload = function(){
//Startup functions go here
    MM_preloadImages('submit_over.gif','register_button_over.gif');
}



function goBack(){
    //window.history.go(-1);
   window.history.back();
}