/* ----------------------------------------
      GREETING_CARD.JS
	
  functions for traversing the card selection and personalization process
  screen2.php and screen3.php
 
  FORM NAME must be card_personalize

  ------------------------------------------ */

// when user clicks on new thumbnail in edit screen
// will set card_personalize.card_no.value
function set_card_selection(new_card){
	// see what is set
	//alert("document.card_personalize.card_no.value = " + document.card_personalize.card_no.value);
	//alert("new_card = " + new_card);
	document.card_personalize.card_no.value = new_card;
}

//takes user to screen 3 to preview the card
//form action must be set and then form submitted
function preview_card(){
    var errstring = verify(document.card_personalize);

	// set action
	document.card_personalize.action = "screen3.php";

    if(errstring){
        alert(errstring);
    }else{
        document.card_personalize.submit();
    }
}

//takes user to screen 4 to have card sent
//form action must be set and then form submitted
function send_card(){
    var errstring = verify(document.card_personalize);

	// set form action
	document.card_personalize.action = "screen4.php";

    if(errstring){
        alert(errstring);
    }else{
        document.card_personalize.submit();
    }
}

//takes user to screen 2 to edit card sent
//form action must be set and then form submitted
function edit_card(){
	// set form action
	document.card_personalize.action = "new_card_edit.php";
	document.card_personalize.submit();
}

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 verify(this_form){

  //var err = false;
  //errstring = "this has been called";
  var errstring = "";

  if(this_form.recipient_email.value == ""){
	errstring = "You must enter an email address for recipient.\n";
	//err = true;
  } else {
		if(!isEmail(this_form.recipient_email.value)){
		  errstring = "You must enter a valid email address for recipient.\n";
		  //err = true;
		}
  }

  //if(err) alert(errstring);
  //return (!err);
  return(errstring);
}

function open_window(url){
	if(url){
		if(screen){
			var left=screen.width-425;
		}else var left=0;
		var enlarged_daily=window.open(url, 'Meaning_of_GCard', 'resizable=1,scrollbars=1,top=0,left='+left+',height=400,width=400');
		enlarged_daily.focus();
	}
}
