jQuery.fn.center = function (absolute) {
    return this.each(function () {
        var t = jQuery(this);

        t.css({
            position:    absolute ? 'absolute' : 'fixed', 
            left:        '50%', 
            top:        '50%', 
            zIndex:        '99'
        }).css({
            marginLeft:    '-' + (t.outerWidth() / 2) + 'px', 
            marginTop:    '-' + (t.outerHeight() / 2) + 'px'
        });

        if (absolute) {
            t.css({
                marginTop:    parseInt(t.css('marginTop'), 10) + jQuery(window).scrollTop(), 
                marginLeft:    parseInt(t.css('marginLeft'), 10) + jQuery(window).scrollLeft()
            });
        }
    });
};

(function($) {
  $.fn.vCenter = function(options) {
    var pos = {
      sTop : function() {
      return window.pageYOffset
        || document.documentElement && document.documentElement.scrollTop
        ||  document.body.scrollTop;
      },
      wHeight : function() {
      return window.innerHeight
        || document.documentElement && document.documentElement.clientHeight
        || document.body.clientHeight;
      }
    };
    return this.each(function(index) {
      if (index == 0) {
        var $this = $(this);
        var elHeight = $this.height();
        var elTop = pos.sTop() + (pos.wHeight() / 2) - (elHeight / 2);
        $this.css({
          position: 'absolute',
          marginTop: '0',
          top: elTop
        });
      }
    });
  };
})(jQuery); // end plugin

    jQuery(document).ready(function() {
        jQuery('div#confirm a').click(function() {
            jQuery('div#confirm').hide().children('.data').html('&nbsp;');  
        }); 
                        
        jQuery('#form1 img.submit').click(function () {
            pay_online(jQuery('#form1').get(0));
        });
            
        jQuery('div#confirm input').click(function() {
            jQuery('form#form1').submit();
        });
    });
    
    function do_popup()
    {    
        //jQuery('div#confirm').center(true).fadeIn();
        jQuery('div#confirm').vCenter().center(true).fadeIn();

        jQuery('div#confirm div.data').html(
              '<div><label>Invoice Number</label> <span>' + jQuery('#invoice').val() + '</span></div>'
                + '<div><label>Amount</label> <span>' + jQuery('#amount').val() + '</span></div>'
                + '<div><label>Name</label> <span>' + jQuery('#name').val() + '</span></div>'
                + '<div><label>Billing Address 1</label> <span>' + jQuery('#billadd1').val() + '</span></div>'
                + '<div><label>Billing Address 2</label> <span>' + jQuery('#billadd2').val() + '</span></div>'
                + '<div><label>City</label> <span>' + jQuery('#city').val() + '</span></div>'
                + '<div><label>State</label> <span>' + jQuery('#state').val() + '</span></div>'
                + '<div><label>Zip Code</label> <span>' + jQuery('#zip').val() + '</span></div>'
                + '<div><label>Card Type</label> <span>' + jQuery('#cardtype').val() + '</span></div>'
                + '<div><label>Card Number</label> <span>' + jQuery('#cardnum').val() + '</span></div>'
                + '<div><label>CVV2</label> <span>' + jQuery('#cvvnum').val() + '</span></div>'
                + '<div><label>Expires</label> <span>' 
                    + jQuery('#expiration_month').val() + '/' 
                    + jQuery('#expiration_year').val()
                    + '</span></div>'
                
                + '<div><label>Phone</label> <span>' 
                    + jQuery('#phone1').val() + '-' 
                    + jQuery('#phone2').val() + '-'
                    + jQuery('#phone3').val() + ' '
                    + jQuery('#phone4').val()
                    + '</span></div>'
                + '<div><label>Email</label> <span>' + jQuery('#email').val() + '</span></div>'
                + '<div><label>Comments</label> <span>' + jQuery('input#comments').val() + '</span></div>'
        );
    }
      
      
function pay_online(form1)
{
var $ = jQuery;
var invoicenum=$('#invoice').val();
var amount=$('#amount').val();
var name=$('#name').val();
var billadd1=$('#billadd1').val();
var billadd2=$('#billadd2').val();
var city=$('#city').val();
var email=$('#email').val();
var state=$('#state').val();
var zip=$('#zip').val();
var cardtype=$('#cardtype').val();
var cardnum=$('#cardnum').val();
var expiration_month=$('#expiration_month').val();
var expiration_year=$('#expiration_year').val();
var cvvnum=$('#cvvnum').val();
var phone1=$('#phone1').val();
var phone2=$('#phone2').val();
var verificationcode=$('#verificationcode').val();

if(alltrim(invoicenum)=='')
{
alert("Please enter invoice number");
document.getElementById('invoice').focus();
return false;
}
if(alltrim(amount)=='')
{
alert("Please enter amount to be charged");
document.getElementById('amount').focus();
return false;
}
if(isNaN(amount))
	{
alert("Please enter a valid amount");
document.getElementById('amount').focus();
return false;
	}
if(alltrim(name)=='')
{
alert("Please enter name as it appears on your card");
document.getElementById('name').focus();
return false;
}

if(alltrim(billadd1)=='')
{
alert("Please enter your billing address");
document.getElementById('billadd1').focus();
return false;
}
/*if(alltrim(billadd2)=='')
{
alert("Please enter second billing address");
document.getElementById('billadd2').focus();
return false;
}*/
if(alltrim(email)=='')
{
alert("Please enter your email address");
document.getElementById('email').focus();
return false;
}


if(alltrim(city)=='')
{
alert("Please enter city");
document.getElementById('city').focus();
return false;
}
if(alltrim(state)=='')
{
alert("Please enter state");
document.getElementById('state').focus();
return false;
}
if(alltrim(zip)=='')
{
alert("Please enter zip code");
document.getElementById('zip').focus();
return false;
}
if(isNaN(zip))
	{
alert("Please enter a valid zip code");
document.getElementById('zip').focus();
return false;
	}
if(alltrim(cardtype)=='')
{
alert("Please choose a card type");
document.getElementById('cardtype').focus();
return false;
}
if(alltrim(cardnum)=='')
{
alert("Please enter card number");
document.getElementById('cardnum').focus();
return false;
}
if(isNaN(cardnum))
	{
alert("Please enter a valid card number");
document.getElementById('cardnum').focus();
return false;
	}
if(alltrim(expiration_month)=='')
{
alert("Please select card expiration month");
document.getElementById('expiration_month').focus();
return false;
}
if(alltrim(expiration_year)=='')
{
alert("Please select card expiration year");
document.getElementById('expiration_year').focus();
return false;
}
if(alltrim(cvvnum)=='')
{
alert("Please enter the three digit code located on the back of your card ");
document.getElementById('cvvnum').focus();
return false;
}
if(isNaN(cvvnum))
	{
alert("Please enter a valid CVV Number");
document.getElementById('cvvnum').focus();
return false;
	}
if(alltrim(phone1)=='')
{
alert("Please enter the phone number ");
document.getElementById('phone1').focus();
return false;
}
if(isNaN(phone1))
	{
alert("Please enter a valid phone number code");
document.getElementById('phone1').focus();
return false;
	}
if(alltrim(phone2)=='')
{
alert("Please enter the phone number  ");
document.getElementById('phone2').focus();
return false;
}
if(isNaN(phone2))
	{
alert("Please enter a valid phone number");
document.getElementById('phone2').focus();
return false;
	}
if(alltrim(verificationcode)=='')
{
alert("Please enter verification code as shown");
document.getElementById('verificationcode').focus();
return false;
}


        
        
        var url = 'check.php';
        var pars = "mode=ajax&start="+verificationcode;
        
/*		
        var myAjax = new Ajax.Request(
        url,
        {
                method: 'get',
                parameters: pars,
                onComplete:showDataList
        });
       
*/

    jQuery.ajax({ url: url, data: pars, success: showDataList })






//return false;
return true;
}
function showDataList(data){
        
        //var response = originalRequest.responseText;
		
       if(data == 'Incorrect verification Code')
	   {
		alert(data);
	   }
	   else
	   {
            do_popup();
	   }
        
        
}

