// SHOW HIDE FORM ELEMENTS
function doClick(objcountry){
if (objcountry.value=="US"){
document.getElementById("textbox").style.display='none'; //hide textbox
document.getElementById("unitedstates").style.display='block'; //show other options
document.getElementById("canada").style.display='none'; //show other options
}
else if (objcountry.value=="CA"){
document.getElementById("textbox").style.display='none'; //hide textbox
document.getElementById("unitedstates").style.display='none'; //show other options
document.getElementById("canada").style.display='block'; //show other options
}

else{
document.getElementById("unitedstates").style.display='none'; //hide other options
document.getElementById("textbox").style.display='block'; //show textbox
document.getElementById("canada").style.display='none'; //show other options
}
}

// CART LOGIN CHECKING
function cartlogin(thisform) {
	if (!VF(thisform.first_name, "Please enter first name.")) {return(false);}
	if (!VF(thisform.last_name, "Please enter last name.")) {return(false);}
	if (!VF(thisform.email, "Please enter email.")) {return(false);}
	if (!isValidEmail(thisform.email.value)) { alert("Your email address appears to be in the wrong format."); thisform.email.focus(); return(false);}
}

// CART LOGIN CHECKING
function contact(thisform) {
	if (!VF(thisform.name, "Please enter your name.")) {return(false);}
	if (!VF(thisform.email, "Please enter your email.")) {return(false);}
	if (!isValidEmail(thisform.email.value)) { alert("Your email address appears to be in the wrong format."); thisform.email.focus(); return(false);}
	if (!VF(thisform.message, "You have not left us a message.")) {return(false);}
}

// FORGOT PASSWORD
function forgotpass(thisform) {
	if (!VF(thisform.email_address, "Please enter email.")) {return(false);}
	if (!isValidEmail(thisform.email_address.value)) { alert("Your email address appears to be in the wrong format."); thisform.email_address.focus(); return(false);}
}

// TRACK ORDER
function trackorder(thisform) {
	if (!VF(thisform.orderNum, "Please enter your Order Number.")) {return(false);}
	if (!VF(thisform.billingZip, "Please enter your Billing Zip Code.")) {return(false);}
}


//  NEWSLETTER FORM ON INDEX
function newsletter(thisform) {
	if (!VF(thisform.name, "Please enter first name.")) {return(false);}
	if (!VF(thisform.email, "Please enter email.")) {return(false);}
	if (!isValidEmail(thisform.email.value)) { alert("Your email address appears to be in the wrong format."); thisform.email.focus(); return(false);}
}

// ACCOUNT LOGIN CHECKING
function account(thisform) {
	if (!VF(thisform.uname, "Please enter your username...")) {return(false);}
	if (!VF(thisform.passwd, "Please enter your password...")) {return(false);}
}

function cancelAccount(thisform) {
	if (!SELECT(thisform.reason, "Sorry, but you didn't select a Reason.")) {return(false);}
	if (!VF(thisform.reasonDetails, "Details of your Cancellation are Required.")) {return(false);}
}

// CREATE ACCOUNT ERROR CHECKING
function createAccounts(thisform) {
	if (!VF(thisform.password, "Please enter a password.")) {return(false);}
	if (!VF(thisform.password2, "Please confirm password.")) {return(false);}
	if (thisform.password.value != thisform.password2.value) { alert("Passwords must match"); thisform.password.focus(); return(false); }
	if (!VF(thisform.first_name, "Please enter first name.")) {return(false);}
	if (!VF(thisform.last_name, "Please enter last name.")) {return(false);}
	if (!VF(thisform.email, "Please enter email.")) {return(false);}
	if (!isValidEmail(thisform.email.value)) { alert("Your email address appears to be in the wrong format."); thisform.email.focus(); return(false);}
    if (!VF(thisform.address, "Please enter your address")) {return(false);}
	if (!SELECT(thisform.country, "Please select your country")) {return(false);}
    if (document.thisform.state0.value == "" && document.thisform.state1.value == "" && document.thisform.state2.value.length == 0) {alert("Please Insert or Select Your State.\n");	return false;}	
	if (!VF(thisform.zip, "Please enter your zip")) {return(false);}
	if (!VF(thisform.city, "Please enter your city")) {return(false);}	
	if(!thisform.agree.checked) { alert('To become a Roaring Tiger Customer, you must agree to our Terms and Conditions'); return( false); }
}

// BROCHURE ERROR CHECKING
function brochure(thisform) {
	if (!VF(thisform.password, "Please enter a password.")) {return(false);}
	if (!VF(thisform.password2, "Please confirm password.")) {return(false);}
	if (thisform.password.value != thisform.password2.value) { alert("Passwords must match"); thisform.password.focus(); return(false); }
	if (!VF(thisform.first_name, "Please enter first name.")) {return(false);}
	if (!VF(thisform.last_name, "Please enter last name.")) {return(false);}
	if (!VF(thisform.email, "Please enter email.")) {return(false);}
	if (!isValidEmail(thisform.email.value)) { alert("Your email address appears to be in the wrong format."); thisform.email.focus(); return(false);}
	if (!SELECT(thisform.country, "Please select your country")) {return(false);}
    if (!VF(thisform.address, "Please enter your address")) {return(false);}
	if (!VF(thisform.city, "Please enter your city")) {return(false);}	
	if (document.thisform.state0.value == "" && document.thisform.state1.value == "") {alert("Please Select Your State.\n");	return false;}	
	if (!VF(thisform.zip, "Please enter your zip")) {return(false);}
}


// SHOP ERROR CHECKING
function formCheck(thisform) {
    if (!VF(thisform.shippingFirstName, "Please enter first name")) {return(false);}
	if (!VF(thisform.shippingLastName, "Please enter last name")) {return(false);}
	if (!VF(thisform.email, "Please enter your e-mail address")) {return(false);}
    if (!VF(thisform.shippingPhone, "Please enter your phone number")) {return(false);}
	if (!SELECT(thisform.shippingCountry, "Please select your country")) {return(false);}
	if (!VF(thisform.shippingAddress, "Please enter your address")) {return(false);}	
	if (!VF(thisform.shippingCity, "Please enter your city")) {return(false);}	
    if (document.thisform.shippingState0.value == "" && document.thisform.shippingState1.value == "" && document.thisform.shippingState2.value.length == 0) {alert("Please Insert or Select Your State.\n");	return false;}	
	if (!VF(thisform.shippingZip, "Please enter your zip")) {return(false);}
	if (!thisform.agree.checked) { alert('You must agree to the terms'); return( false); }	
}


// VALIDATE EMAIL
function isValidEmail(str) {
//return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
return (true);
}

// MY ACCOUNT >> CHANGE PASSWORD
function checkPass() {
if (!VF(pass.oldPass, "Please enter your old password.")) {return(false);}
if (!VF(pass.oldPass2, "Please confirm your old password.")) {return(false);}
if (pass.oldPass.value != pass.oldPass2.value) {alert("Your old passwords must match"); return false;}
if (!VF(pass.newPass, "Please enter your new password.")) {return(false);}
if (!VF(pass.newPass2, "Please confirm your new password.")) {return(false);}
if (pass.newPass.value != pass.newPass2.value) {alert("Your new passwords must match"); return false;}
}	
	
	
// FUNCTIONS FOR FORMS CHECKS
function VF(f, msg){
  if 
  (f.value == "" || f.value.length ==0)
  {alert(msg); f.focus(); return (false);}
	   
  else {for 
  (x=0;x<f.value.length;x++)
  
  {
  if 
  (f.value.charAt(x)!=" ")
  {return (true);}
  }
  
  alert(msg); f.select(); f.focus(); return (false);}
  return (true);
}

// selectMenu check
function SELECT(s, message){
	if (s.options[s.selectedIndex].value == "") {
		alert(message);
		s.focus();
		return (false);
	}
	return (true);
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// credit card validation

var ccErrorNo = 0;
var ccErrors = new Array ()

ccErrors [0] = "Unknown card type";
ccErrors [1] = "No card number provided";
ccErrors [2] = "Credit card number is in invalid format";
ccErrors [3] = "Credit card number is invalid";
ccErrors [4] = "Credit card number has an inappropriate number of digits";

function checkCreditCard (cardnumber, cardname) {

     
  // Array to hold the permitted card characteristics
  var cards = new Array();

  // Define the cards we support. You may add addtional card types.
  
  //  Name:      As in the selection box of the form - must be same as user's
  //  Length:    List of possible valid lengths of the card number for the card
  //  prefixes:  List of possible prefixes for the card
  //  checkdigit Boolean to say whether there is a check digit
  
  cards [0] = {name: "Visa", 
               length: "13,16", 
               prefixes: "4",
               checkdigit: true};
  cards [1] = {name: "MasterCard", 
               length: "16", 
               prefixes: "51,52,53,54,55",
               checkdigit: true};
  cards [2] = {name: "DinersClub", 
               length: "14,", 
               prefixes: "300,301,302,303,304,305,36,38",
               checkdigit: true};
  cards [3] = {name: "CarteBlanche", 
               length: "14", 
               prefixes: "300,301,302,303,304,305,36,38",
               checkdigit: true};
  cards [4] = {name: "AmEx", 
               length: "15", 
               prefixes: "34,37",
               checkdigit: true};
  cards [5] = {name: "Discover", 
               length: "16", 
               prefixes: "6011",
               checkdigit: true};
  cards [6] = {name: "JCB", 
               length: "15,16", 
               prefixes: "3,1800,2131",
               checkdigit: true};
  cards [7] = {name: "Enroute", 
               length: "15", 
               prefixes: "2014,2149",
               checkdigit: true};
               
  // Establish card type
  var cardType = -1;
  for (var i=0; i<cards.length; i++) {

    // See if it is this card (ignoring the case of the string)
    if (cardname.toLowerCase () == cards[i].name.toLowerCase()) {
      cardType = i;
      break;
    }
  }
  
  // If card type not found, report an error
  if (cardType == -1) {
     ccErrorNo = 0;
     return false; 
  }
   
  // Ensure that the user has provided a credit card number
  if (cardnumber.length == 0)  {
     ccErrorNo = 1;
     return false; 
  }
  
  // Check that the number is numeric, although we do permit a space to occur  
  // every four digits. 
  var cardNo = cardnumber
  var cardexp = /^([0-9]{4})\s?([0-9]{4})\s?([0-9]{4})\s?([0-9]{1,4})$/;
  if (!cardexp.exec(cardNo))  {
     ccErrorNo = 2;
     return false; 
  }
    
  // Now remove any spaces from the credit card number
  cardexp.exec(cardNo);
  cardNo = RegExp.$1 + RegExp.$2 + RegExp.$3 + RegExp.$4;
       
  // Now check the modulus 10 check digit - if required
  if (cards[cardType].checkdigit) {
    var checksum = 0;                                  // running checksum total
    var mychar = "";                                   // next char to process
    var j = 1;                                         // takes value of 1 or 2
  
    // Process each digit one by one starting at the right
    var calc;
    for (i = cardNo.length - 1; i >= 0; i--) {
    
      // Extract the next digit and multiply by 1 or 2 on alternative digits.
      calc = Number(cardNo.charAt(i)) * j;
    
      // If the result is in two digits add 1 to the checksum total
      if (calc > 9) {
        checksum = checksum + 1;
        calc = calc - 10;
      }
    
      // Add the units element to the checksum total
      checksum = checksum + calc;
    
      // Switch the value of j
      if (j ==1) {j = 2} else {j = 1};
    } 
  
    // All done - if checksum is divisible by 10, it is a valid modulus 10.
    // If not, report an error.
    if (checksum % 10 != 0)  {
     ccErrorNo = 3;
     return false; 
    }
  }  

  // The following are the card-specific checks we undertake.
  var LengthValid = false;
  var PrefixValid = false; 
  var undefined; 

  // We use these for holding the valid lengths and prefixes of a card type
  var prefix = new Array ();
  var lengths = new Array ();
    
  // Load an array with the valid prefixes for this card
  prefix = cards[cardType].prefixes.split(",");
      
  // Now see if any of them match what we have in the card number
  for (i=0; i<prefix.length; i++) {
    var exp = new RegExp ("^" + prefix[i]);
    if (exp.test (cardNo)) PrefixValid = true;
  }
      
  // If it isn't a valid prefix there's no point at looking at the length
  if (!PrefixValid) {
     ccErrorNo = 3;
     return false; 
  }
    
  // See if the length is valid for this card
  lengths = cards[cardType].length.split(",");
  for (j=0; j<lengths.length; j++) {
    if (cardNo.length == lengths[j]) LengthValid = true;
  }
  
  // See if all is OK by seeing if the length was valid. We only check the 
  // length if all else was hunky dory.
  if (!LengthValid) {
     ccErrorNo = 4;
     return false; 
  };   
  
  // The credit card is in the required format.
  return true;
}




<!-- Begin
function compare(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width=600,height=600,left=0,top=0');");
}
// End -->

<!-- Begin
function spareParts(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=0,width=590,height=605,left=0,top=0');");
}
// End -->


/* Modified to support Opera */
function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(document.title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',document.title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, document.title);
}

/* SHOW HIDE ON CART-LOGIN */
function part2() {
var part2 = document.getElementById('part2');
if ( part2.className == 'hidden' ) {
part2.className = 'visible';
} else {
part2.className = 'hidden';
}
}



function imageReplace(divid,tagnames){

    if(!document.getElementById) return false;
    if(!document.getElementsByTagName) return false;
    images = document.getElementById(divid).getElementsByTagName(tagnames);
	
    for(i = 0; i < images.length + 0; i++){
		
		var index = i;
		
        images[index].onmouseover = function(){
			this.style.border="1px solid #a3a3a3";
			this.style.color="#000000";
			this.style.cursor = 'pointer';
        }
        images[index].onmouseout = function(){
			this.style.border="1px solid #ccc";
			this.style.color="#666666";
        }
		
		
		var textbox1 = document.getElementsByTagName('label')[0];
		var textbox2 = document.getElementsByTagName('label')[1];
		var textbox3 = document.getElementsByTagName('label')[2];
		
		
		textbox1.onclick = function() {
			this.style.background="#fff9c3";
			textbox2.style.background="#f9f9f9";
			textbox3.style.background="#f9f9f9";
		}
		textbox2.onclick = function() {
			this.style.background="#fff9c3";
			textbox3.style.background="#f9f9f9";
			textbox1.style.background="#f9f9f9";
		}
		textbox3.onclick = function() {
			this.style.background="#fff9c3";
			textbox1.style.background="#f9f9f9";
			textbox2.style.background="#f9f9f9";
		}

	
}
}

