/*
$Id: func.js,v 1.2 2008/11/25 12:58:09 max Exp $
vim: set ts=2 sw=2 sts=2 et:
*/

function check_gc_form() {
  if ($('#recipient').val() == "") {
    $('#recipient').focus();
    alert (txt_recipient_invalid);
    return false;
  }


 if ($('#purchaser').val() == "") {
    $('#purchaser').focus();
    alert (txt_gc_purchaser_invalid);
    return false;
  }
 

  var num = convert_number($('#amount').val());
  if (!check_is_number($('#amount').val()) || (num < min_gc_amount || (max_gc_amount > 0 && num > max_gc_amount))) {
    $('#amount').focus();
    alert (txt_gc_amount_invalid);
    return false;
  }
  
  if (null==$('input:radio[name=send_via]:checked').val()){
  	 alert (txt_versandart_invalid);
	 return false;
  }
 // Versand per mail
 if ($('input:radio[name=send_via]:checked').val()=="E"){
	 
	 if ($('#recipient_email').val() == '') {
        alert (txt_gc_enter_mail_address);
        $('#recipient_email').focus();
        return false;

      } else if (!checkEmailAddress2('recipient_email')) {
        $('#recipient_email').focus();
        return false;
      }
	 
	 
 }
 
 if ($('input:radio[name=send_via]:checked').val()=="P"){
	 
	 
      if ($('#recipient_firstname').val() == "") {
         alert(txt_gc_recipient_firstname);
		 $('#recipient_firstname').focus()
		 return false;


      } else if ($('#recipient_lastname').val() == "") {
        alert(txt_gc_recipient_lastname);
        $('#recipient_lastname').focus();
		return false;

      } else if ($('#recipient_address').val() == "") {
        alert(txt_gc_recipient_address);
        $('#recipient_address').focus();
		return false;
		

      } else if ($('#recipient_city').val() == "") {
        alert(txt_gc_recipient_city);
        $('#recipient_city').focus();
		return false;

      } else if ($('#recipient_zipcode').val() == "") {
         alert(txt_gc_recipient_zipcode);
        $('#recipient_zipcode').focus();
		return false;
      }
	  return true;
	 
 }

  
 
return true;

}


function checkEmailAddress2(field, empty_err) {
 var err = false;

if ($('#'+field).val == ""){
	 if (empty_err != 'Y') {
 return true;
 } else {
 err = true;
 }
}

if (null==$('#'+field).val()){
	 if (empty_err != 'Y') {
 return true;
 } else {
 err = true;
 }
}


 if (!err && $('#'+field).val().replace(/^\s+/g, '').replace(/\s+$/g, '').search(email_validation_regexp) == -1) {
 err = true;
 }

 if (err) {
 alert(txt_email_invalid);
 $('#'+field).focus();
 $('#'+field).select();
 }

 return !err;
} 

function preview_gc(){

	if (check_gc_form()	== true){
	$.fancybox.showActivity();
	var vorschauvars= {recipient:$('#recipient').val(), purchaser:$('#purchaser').val(), message:$('#message').val(), amount:$('#amount').val(),gc_template:$('#gc_template').val(),type:$('input:radio[name=send_via]:checked').val()  }

	$.ajax({

		type		: "POST",
		cache	: false,
		url		: "giftcert_preview.php",
		data		: vorschauvars,
		success: function(data) {
			$.fancybox(data,
					   {
						  
        		'autoDimensions'	: false,
				'width'         		: 830,
				'height'        		: 'auto',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
		}

					   );
		}
	});


	
	}else{
return false;
	}
}
