/* ****************************
       form checker
***************************** */
function cardSwap( string ){
  var opt_key = string.selectedIndex;
  var ccimage = string.options[opt_key].value;
  document.creditcard.src="/secure/images/" + ccimage + ".jpg";
  return true;
}

function isEmail( string ) {
  if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) return true;
  else return false;
} 

function isName( string ) {
  if (string.search(/^([A-Za-z0-9]?\W?\'?[A-Za-z0-9]+\W?)+$/) != -1 ) return true;
  else return false;
}

function isPassword( string ) {
  if (string.search(/^\w+$/) != -1 ) return true;
  else return false;
}

// checking for numeric & 5 chars
function isZipcode( string )
{
	if (string.search(/^\d{5}$/) != -1)
	{
		return true;
	} else {
		return false;
	}
}

//check the answer to the security question.
// can't contain "a", "an" or "the"
function checkSecurityAnswer(string)
{
	problems = 0;
	string = string.toLowerCase();
	commonWordsArray = new Array ('a', 'an', 'the');
	//check for spaces or common words at the beginning of the string
	if (string.charAt(0) == " ") problems++; //starts with a space
	msg = "";
	for (ansX = 0; ansX < commonWordsArray.length; ansX++)
	{
		//starts with the word
		str = commonWordsArray[ansX] + " ";
		if (string.indexOf(str) == 0) problems++;
		
		//ends with the word (with a space preceding the word)
		str = " " + commonWordsArray[ansX];
		checkPlace = string.length - str.length;
		if (string.indexOf(str, checkPlace) >= 0) problems++; 
		
		//contains the word (with spaces on either side)
		str = " " + commonWordsArray[ansX] + " ";
		if (string.indexOf(str) >0) problems++;
	}

	if (problems > 0) return false;
	else return true;
	}



// for the "why not" form popup
function noFormPopup()
{
  var winUrl = "/signup/why_not_popup.php";
  var winName = "why_not"; 
  window.open(winUrl, winName, "height=540, width=540, location=0, menubar=0, resizable=0, scrollbars=auto, status=0, toolbar=0");
}

// when a country other than USA is selected, hide zipcode
// called onchange for the country select menu
function hideZipcodeNonUS(country)
{
  if ((country == "USA") | (country == ""))
  {
    document.getElementById('zipcodeRow').style.display = "block";
  } else {
    document.getElementById('zipcodeRow').style.display = "none";
  }
}