<?php
/*
Template Name: Checkout Point Page
*/
?>

<?php get_header(); ?>
<?php 
$aOptions = SofaShoppr::initOptions( false );
$entrycurrency = $aOptions[ 'entrycurrency' ];
$taxpercentage = $aOptions[ 'taxpercentage' ];
if( $taxpercentage < 0 ) $taxpercentage = 0;

$enable_paypal = $aOptions[ 'enable_paypal' ];
$enable_authorize = $aOptions[ 'enable_authorize' ];
$enable_checkout = $aOptions[ 'enable_checkout' ];
$enable_email = $aOptions[ 'enable_email' ];
$use_stock_inventory = $aOptions[ 'use_stock_inventory' ];

include( TEMPLATEPATH . '/shipping_list.php' );
?>

<?php if( have_posts() ) : while( have_posts() ) : the_post(); ?>


<div id="content">
    
    <div class="article">

        <h1><?php the_title(); ?></h1>
        <?php edit_post_link( 'EDIT', '<div class="post-info"><span class="date">', '</span></div>' ); ?>
        <?php the_content(); ?>
        
        <div id="finalfeedback"><span>&nbsp;</span></div>
        
        <div class="chckoutcontainer">
		
		<?php
		$form_items_individual = '';
		$form_items_tax_shipping = '';
		$global_counter = 1;
		$items_sum = 0;
		$ppal_custom = '';
		if( isset( $_COOKIE[ 'sofashoppr' ] ) ) {
			
			echo '<ul class="entries recentposts co">';
			foreach( $_COOKIE[ 'sofashoppr' ] as $name => $value ) {
				
				$ppal_custom .= intval( $name ) . ':' . $value . ',';
				// $value may contain additional item info
				$item_info_extra_array = explode( ':', $value );
				$item_size = '';
				$item_color = '';
				if( $item_info_extra_array[ 2 ] != NULL ) $item_size  = $item_info_extra_array[ 2 ];
				if( $item_info_extra_array[ 3 ] != NULL ) $item_color = $item_info_extra_array[ 3 ];
				$p_o = get_post( intval( $name ) );
				$custom_fields = get_post_custom( intval( $name ) );
				$item_price = ( $item_info_extra_array[ 4 ] != NULL ) ? $item_info_extra_array[ 4 ] : $custom_fields[ 'price' ][ 0 ];
				// get image
				$postImages =& get_children( 'post_type=attachment&post_mime_type=image&orderby=menu_order&order=ASC&post_parent=' . intval( $name ) );
				if( $postImages ) {
					$arrK = array_keys( $postImages );
					$thumb_path = wp_get_attachment_thumb_url( $arrK[ 0 ] );
				}
				// end get image
				$item_append = '?itemid=' . $name . '&amp;itemq=' . $item_info_extra_array[ 1 ] . '&amp;size=' . str_replace( ' ', '%20', $item_size ) . '&amp;color=' . str_replace( ' ', '%20', $item_color ) . '&amp;itemp=' . $item_price;
				$delete_link = '<a class="nyroModal" href="' . get_bloginfo( 'template_directory' ) . '/del_item_screen.php' . $item_append . '"><img src="' . get_bloginfo( 'template_directory' ) . '/images/cancel.png' . '" title="' . __( "Delete from basket", "sofa_shoppr" ) . '" /></a>';
				$edit_link = '<a class="nyroModal" href="' . get_bloginfo( 'template_directory' ) . '/edit_item_screen.php' . $item_append . '"><img src="' . get_bloginfo( 'template_directory' ) . '/images/pencil.png' . '" title="' . __( "Edit item", "sofa_shoppr" ) . '" /></a>';
				$perma_item = get_permalink( $p_o->ID );
				echo '<li class="basketit">';
				echo '<div class="deleteitem width8">' . $delete_link . '</div>';
				echo '<div class="deleteitem width8">' . $edit_link . '</div>';
				echo '<p class="pcell width69">';
				echo '<img src="' . $thumb_path . '" alt="" class="basketitemsmall" />';
				echo '<a href="' . $perma_item . '" title="' . __( "Item details", "sofa_shoppr" ) . '">' . $item_info_extra_array[ 1 ] . 'x ' . stripslashes( strip_tags( $p_o->post_title ) ) . '</a>';
				if( $item_size != '' ) echo '<br />' . __( "Size", "sofa_shoppr" ) . ': ' . $item_size;
				if( $item_color != '' ) echo '<br />' . __( "Color", "sofa_shoppr" ) . ': ' . $item_color;
				echo '</p>';
				echo '<p class="pcell width15 aright">' . $entrycurrency . ' ' . number_format( $item_price * $item_info_extra_array[ 1 ], 2, '.', ',' ) . '</p>';
				echo '</li>';
				
				$items_sum = $items_sum + ( $item_price * $item_info_extra_array[ 1 ] );
				
				$global_counter ++;
			}
			
			echo '<li class="basketit">';
			echo '<p class="pcell width40">&nbsp;</p>';
			echo '<p class="pcell width30 aright">' . __( "Subotal", "sofa_shoppr" ) . ': </p>';
			echo '<p class="pcell width30 aright">' . $entrycurrency . ' ' . number_format( $items_sum, 2, '.', ',' ) . '</p>';
			echo '</li>';
			
			if( $taxpercentage > 0 ) echo '<li class="basketit">';
			
			// now it's safe to prepare the rest of data
			if( $taxpercentage > 0 ) {
				$bare_tax = ( $items_sum * $taxpercentage ) / 100;
				$form_items_tax_shipping = '<input type="hidden" name="tax_cart" value="' . number_format( $bare_tax, 2, '.', ',' ) . '" />';
				$items_sum = $items_sum + $bare_tax;
			}
			
			if( $taxpercentage > 0 ) {
				echo '<p class="pcell width40">&nbsp;</p>';
				echo '<p class="pcell width30 aright">' . __( "Tax", "sofa_shoppr" ) . '(' . $taxpercentage . '%): </p>';
				echo '<p class="pcell width30 aright">' . $entrycurrency . ' ' . number_format( $bare_tax, 2, '.', ',' ) . '</p>';
			}
			
			if( $taxpercentage > 0 ) echo '</li>';
			
			echo '<li class="basketit">';
			echo '<p class="pcell width40">&nbsp;</p>';
			echo '<p class="pcell width30 aright">' . __( "Total", "sofa_shoppr" ) . ': </p>';
			echo '<p class="pcell width30 aright" id="appendshipping">' . $entrycurrency . ' ' . number_format( $items_sum, 2, '.', ',' ) . '</p>';
			echo '</li>';
			
			echo '<li class="basketit" id="lissc">';
			echo '<p id="countryselector">';
			echo '<select id="ssc" name="ssc" size="1">';
			foreach( $shipping_countries_and_fees_list as $ssck => $sscv ) {
				$option = '<option value="' . $sscv . '" title="' . $ssck . '"> - ';
				if( $sscv > 0 ) {
					$option .= $ssck . ' ( ' . $entrycurrency . ' ' . number_format( $sscv, 2, '.', ',' ) . ' )';
				} else $option .= $ssck;
				$option .= ' - </option>';
				echo $option;
			}
			echo '</select>';
			echo '</p>';
			echo '</li>';
		
			echo '</ul>';

		?>

    <p id="submittr">
    	<?php if( $enable_paypal == 'yes' ) { ?>
        <a href="#" id="submitPP" title="<?php _e( "Checkout with Paypal", "sofa_shoppr" ); ?>">
        	<img src="<?php echo get_bloginfo( 'template_directory' ) . ( '/images/paypalbutton.gif' ); ?>" alt="" />
        </a>
		<?php } ?>
        <?php if( $enable_authorize == 'yes' ) { ?>
        <a href="#" id="submitAN" title="<?php _e( "Checkout with Authorize.net", "sofa_shoppr" ); ?>">
        	<img src="<?php echo get_bloginfo( 'template_directory' ) . ( '/images/authorizebutton.gif' ); ?>" alt="" />
        </a>
        <?php } ?>
        <?php if( $enable_checkout == 'yes' ) { ?>
        <a href="#" id="submitCO" title="<?php _e( "Checkout with 2CheckOut", "sofa_shoppr" ); ?>">
        	<img src="<?php echo get_bloginfo( 'template_directory' ) . ( '/images/2CObutton.gif' ); ?>" alt="" />
        </a>
        <?php } ?>
        <?php if( $enable_email == 'yes' ) { ?>
        <a href="#" id="submitAB" title="<?php _e( "E-mail order", "sofa_shoppr" ); ?>">
        	<img src="<?php echo get_bloginfo( 'template_directory' ) . ( '/images/emailbutton.gif' ); ?>" alt="" />
        </a>
        <?php } ?>
    </p>
    
      <div id="bankxxx">
      
      	<h3><?php _e( "Please provide shipping details", "sofa_shoppr" ); ?></h3>
        
        <div id="feedback">
            <span><?php _e( "Be sure all fields marked with * (asterisk) are filled. Otherwise your Order will not be accepted!", "sofa_shoppr" ); ?></span>
        </div>
        
        <form id="ppform" name="ppform" method="post" action="">
        
        <div class="toleftblock">
        
            <p>
                <label for="ab_firstname">* <?php _e( "First Name", "sofa_shoppr" ); ?></label>
                <input type="text" size="50" id="ab_firstname" name="ab_firstname" />
            </p>
            <p>
                <label for="ab_lastname">* <?php _e( "Last Name", "sofa_shoppr" ); ?></label>
                <input type="text" size="50" id="ab_lastname" name="ab_lastname" />
            </p>
            <p>
                <label for="ab_cellphone"><?php _e( "Cell Phone", "sofa_shoppr" ); ?></label>
                <input type="text" size="50" id="ab_cellphone" name="ab_cellphone" />
            </p>
            <p>
                <label for="ab_phone"><?php _e( "Phone Number", "sofa_shoppr" ); ?></label>
                <input type="text" size="50" id="ab_phone" name="ab_phone" />
            </p>
            <p>
                <label for="ab_email">* <?php _e( "E-mail Address", "sofa_shoppr" ); ?></label>
                <input type="text" size="50" id="ab_email" name="ab_email" />
            </p>
        
        </div>
        
        <div class="toleftblock last">
        
            <p>
                <label for="ab_address">* <?php _e( "Shipping Address", "sofa_shoppr" ); ?></label>
                <input type="text" size="50" id="ab_address" name="ab_address" />
            </p>
            <p>
                <label for="ab_address2"><?php _e( "Shipping Address 2", "sofa_shoppr" ); ?></label>
                <input type="text" size="50" id="ab_address2" name="ab_address2" />
            </p>
            <p>
                <label for="ab_city">* <?php _e( "City", "sofa_shoppr" ); ?></label>
                <input type="text" size="50" id="ab_city" name="ab_city" />
            </p>
            <p>
                <label for="ab_zipcode">* <?php _e( "ZIP Code", "sofa_shoppr" ); ?></label>
                <input type="text" size="30" id="ab_zipcode" name="ab_zipcode" />
            </p>
            <p>
                <label for="ab_country_quasi">* <?php _e( "Country", "sofa_shoppr" ); ?></label>
                <input type="text" disabled="disabled" size="50" id="ab_country_quasi" name="ab_country_quasi" value="" />
            </p>
            <input type="hidden" size="50" id="ab_shipping_cost" name="ab_shipping_cost" value="" />
            <input type="hidden" size="50" id="ab_country" name="ab_country" value="" />
        
        </div>

        
        <p id="confirmr">
            <button type="submit" value="" id="confirmorder" name="submit" class="ppalbutton"><img src="<?php echo bloginfo( 'template_directory' ) . ( '/images/submitbutton.gif' ); ?>" alt="" /></button>
            <button type="submit" value="" id="cancelorder" name="submit" class="ppalbutton"><img src="<?php echo bloginfo( 'template_directory' ) . ( '/images/cancelbutton.gif' ); ?>" alt="" /></button>
        </p>
        
        </form>
        
    </div>
    
    <div id="coxxx">
    
        <h3><?php _e( "Please provide shipping details", "sofa_shoppr" ); ?></h3>
        
        <div id="cofeedback">
            <span><?php _e( "Be sure all fields marked with * (asterisk) are filled. Otherwise your Order will not be accepted!", "sofa_shoppr" ); ?></span>
        </div>
        
        <form id="coform" name="coform" method="post" action="">
        
        <div class="toleftblock">

            <p>
                <label for="ship_name">* <?php _e( "Full Name", "sofa_shoppr" ); ?></label>
                <input type="text" size="50" id="ship_name" name="ship_name" />
            </p>
            <p>
                <label for="ship_street_address">* <?php _e( "Shipping Address", "sofa_shoppr" ); ?></label>
                <input type="text" size="50" id="ship_street_address" name="ship_street_address" />
            </p>
            <p>
                <label for="ship_state"><?php _e( "Shipping State", "sofa_shoppr" ); ?></label>
                <input type="text" size="50" id="ship_state" name="ship_state" />
            </p>
        
        </div>
        
        <div class="toleftblock last">
        
            <p>
                <label for="ship_city">* <?php _e( "City", "sofa_shoppr" ); ?></label>
                <input type="text" size="50" id="ship_city" name="ship_city" />
            </p>
            <p>
                <label for="ship_zip">* <?php _e( "ZIP Code", "sofa_shoppr" ); ?></label>
                <input type="text" size="50" id="ship_zip" name="ship_zip" />
            </p>
            <p>
                <label for="ship_country_quasi">* <?php _e( "Country", "sofa_shoppr" ); ?></label>
                <input type="text" disabled="disabled" size="50" id="ship_country_quasi" name="ship_country_quasi" value="" />
            </p>
            <input type="hidden" size="50" id="co_shipping_cost" name="co_shipping_cost" value="" />
            <input type="hidden" size="50" id="ship_country" name="ship_country" value="" />
        
        </div>

        
        <p id="coconfirmr">
            <button type="submit" value="" id="coconfirmorder" name="submit" class="ppalbutton"><img src="<?php echo bloginfo( 'template_directory' ) . ( '/images/submitbutton.gif' ); ?>" alt="" /></button>
            <button type="submit" value="" id="cocancelorder" name="submit" class="ppalbutton"><img src="<?php echo bloginfo( 'template_directory' ) . ( '/images/cancelbutton.gif' ); ?>" alt="" /></button>
        </p>
        
        </form>
        
    </div>

<?php 
$ppal_custom = urlencode( $ppal_custom );

$stock_product_missing = urlencode( __( "Items missing in stock!", "sofa_shoppr" ) . '<br />' . __( "Please correct quantity for the following products:", "sofa_shoppr" ) . '<br /><br />' );
$currently_available_q = urlencode( ' | ' . __( "Currently available quantity:", "sofa_shoppr" ) . ' ' );
$shipping_country_sel  = urlencode( __( "Shipping country must be selected!", "sofa_shoppr" ) );
?>
           
<script language="javascript" type="text/javascript">

var action_PP = "<?php echo get_bloginfo( 'template_directory' ) . ( '/gateways/paypal_start.php' ); ?>";
var action_AN = "<?php echo get_bloginfo( 'template_directory' ) . ( '/gateways/authorize_start.php' ); ?>";
var action_CO = "<?php echo get_bloginfo( 'template_directory' ) . ( '/gateways/2co_start.php' ); ?>";
var action_AB = "<?php echo get_bloginfo( 'template_directory' ) . ( '/gateways/manual_handler.php' ); ?>";

jQuery( document ).ready( function() {
	// appendshipping : handle shipping
	var old_value_txt = jQuery( '#appendshipping' ).text();
	var old_value_arr = old_value_txt.split( ' ' );
	var old_value_val = old_value_arr[ 1 ].split( ',' ).join( '' );
	// primal call
	var obey_elem_default = jQuery( '#ssc option:selected' ).attr( 'value' );
	watchChanges( obey_elem_default, old_value_val );
	jQuery( '#ssc' ).change( function() {
		var obey_this_elem = jQuery( 'option:selected', this ).attr( 'value' );
		watchChanges( obey_this_elem, old_value_val );
	} );
	// prevent automatic/Enter press form submission
	// handle cases
	var opened_plus = false;
	var coopened_plus = false;
	jQuery( '#submitPP, #submitAN, #submitCO, #submitAB' ).click( function( event ) {
		// use SI feature?
		var use_stock = decodeURIComponent( "<?php echo $use_stock_inventory; ?>" );
		// who's clicked?
		var my_routine = jQuery( this ).attr( 'id' );
		if( my_routine == 'submitPP' ) {
			// check for stock availability
			if( use_stock == "yes" ) {
				
				var decoded_ppal_custom = decodeURIComponent( "<?php echo $ppal_custom; ?>" );
				decoded_ppal_custom = decoded_ppal_custom.replace( /\+/g, ' ' );
				var decoded_referer = encodeURIComponent( "<?php echo $_SERVER[ 'HTTP_REFERER' ]; ?>" );
				jQuery.post( "<?php echo get_bloginfo( 'template_directory' ); ?>/stock_chck.php", { "serialdata": decoded_ppal_custom, "referr": decoded_referer }, 
					function( data ) {
						
						data = decodeURIComponent( data );
						data = data.replace( /\+/g, ' ' );
						if( data == "" ) {
							
							// country appendix
							var obey_elem = jQuery( '#ssc option:selected' ).attr( 'value' );
							if( obey_elem > 0 ) {
								jQuery( '#finalfeedback' ).fadeOut( 'fast' );
								window.location.replace( action_PP + '?hc=' + number_format( obey_elem, 2, '.', '' ) );
							} else {
								var bodyelem = '';
								if( jQuery.browser.safari ) bodyelem = jQuery( 'body' ); // only Opera specific
								else bodyelem = jQuery( 'html' );
								jQuery( bodyelem ).animate( { scrollTop: jQuery( '#content' ).offset().top }, 'slow' );
								var decoded_scs = decodeURIComponent( "<?php echo $shipping_country_sel; ?>" );
								decoded_scs = decoded_scs.replace( /\+/g, ' ' );
								jQuery( '#finalfeedback' ).html( '<span>' + decoded_scs + '</span>' );
								jQuery( '#finalfeedback' ).fadeIn( 'fast' );
							}
							
						} else {
							
							var notice_str = decodeURIComponent( "<?php echo $stock_product_missing; ?>" );
							notice_str = notice_str.replace( /\+/g, ' ' );
							var arr_data = data.split( "^" );
							var kkk = 0;
							var adl = arr_data.length - 1;
							while( kkk < adl ) {
								var arr_temp = arr_data[ kkk ].split( "~" );
								var decoded_caq = decodeURIComponent( "<?php echo $currently_available_q; ?>" );
								decoded_caq = decoded_caq.replace( /\+/g, ' ' );
								var positive_q = 0;
								if( parseInt( arr_temp[ 1 ] ) < 0 ) positive_q = 0;
								else positive_q = arr_temp[ 1 ];
								notice_str += arr_temp[ 0 ] + decoded_caq + positive_q + "<br />";
								kkk ++;
							}
							
							var bodyelem = '';
							if( jQuery.browser.safari ) bodyelem = jQuery( 'body' ); // only Opera specific
							else bodyelem = jQuery( 'html' );
							jQuery( bodyelem ).animate( { scrollTop: jQuery( '#content' ).offset().top }, 'slow' );
							
							jQuery( '#finalfeedback' ).html( '<span>' + notice_str + '</span>' );
							jQuery( '#finalfeedback' ).fadeIn( 'fast' );
							
						}
					} );
					
			} else {
				
				// country appendix
				var obey_elem = jQuery( '#ssc option:selected' ).attr( 'value' );
				if( obey_elem > 0 ) {
					jQuery( '#finalfeedback' ).fadeOut( 'fast' );
					window.location.replace( action_PP + '?hc=' + number_format( obey_elem, 2, '.', '' ) );
				} else {
					var bodyelem = '';
					if( jQuery.browser.safari ) bodyelem = jQuery( 'body' ); // only Opera specific
					else bodyelem = jQuery( 'html' );
					jQuery( bodyelem ).animate( { scrollTop: jQuery( '#content' ).offset().top }, 'slow' );
					var decoded_scs = decodeURIComponent( "<?php echo $shipping_country_sel; ?>" );
					decoded_scs = decoded_scs.replace( /\+/g, ' ' );
					jQuery( '#finalfeedback' ).html( '<span>' + decoded_scs + '</span>' );
					jQuery( '#finalfeedback' ).fadeIn( 'fast' );
				}
				
			}
						
		} else if( my_routine == 'submitAN' ) {
			// check for stock availability
			if( use_stock == "yes" ) {
				
				var decoded_ppal_custom = decodeURIComponent( "<?php echo $ppal_custom; ?>" );
				decoded_ppal_custom = decoded_ppal_custom.replace( /\+/g, ' ' );
				var decoded_referer = encodeURIComponent( "<?php echo $_SERVER[ 'HTTP_REFERER' ]; ?>" );
				jQuery.post( "<?php echo get_bloginfo( 'template_directory' ); ?>/stock_chck.php", { "serialdata": decoded_ppal_custom, "referr": decoded_referer }, 
					function( data ) {
						
						data = decodeURIComponent( data );
						data = data.replace( /\+/g, ' ' );
						if( data == "" ) {

							// country appendix
							var obey_elem = jQuery( '#ssc option:selected' ).attr( 'value' );
							if( obey_elem > 0 ) {
								jQuery( '#finalfeedback' ).fadeOut( 'fast' );
								window.location.replace( action_AN + '?hc=' + number_format( obey_elem, 2, '.', '' ) );
							} else {
								var bodyelem = '';
								if( jQuery.browser.safari ) bodyelem = jQuery( 'body' ); // only Opera specific
								else bodyelem = jQuery( 'html' );
								jQuery( bodyelem ).animate( { scrollTop: jQuery( '#content' ).offset().top }, 'slow' );
								var decoded_scs = decodeURIComponent( "<?php echo $shipping_country_sel; ?>" );
								decoded_scs = decoded_scs.replace( /\+/g, ' ' );
								jQuery( '#finalfeedback' ).html( '<span>' + decoded_scs + '</span>' );
								jQuery( '#finalfeedback' ).fadeIn( 'fast' );
							}
							
						} else {
							
							var notice_str = decodeURIComponent( "<?php echo $stock_product_missing; ?>" );
							notice_str = notice_str.replace( /\+/g, ' ' );
							var arr_data = data.split( "^" );
							var kkk = 0;
							var adl = arr_data.length - 1;
							while( kkk < adl ) {
								var arr_temp = arr_data[ kkk ].split( "~" );
								var decoded_caq = decodeURIComponent( "<?php echo $currently_available_q; ?>" );
								decoded_caq = decoded_caq.replace( /\+/g, ' ' );
								var positive_q = 0;
								if( parseInt( arr_temp[ 1 ] ) < 0 ) positive_q = 0;
								else positive_q = arr_temp[ 1 ];
								notice_str += arr_temp[ 0 ] + decoded_caq + positive_q + "<br />";
								kkk ++;
							}
							
							var bodyelem = '';
							if( jQuery.browser.safari ) bodyelem = jQuery( 'body' ); // only Opera specific
							else bodyelem = jQuery( 'html' );
							jQuery( bodyelem ).animate( { scrollTop: jQuery( '#content' ).offset().top }, 'slow' );
							
							jQuery( '#finalfeedback' ).html( '<span>' + notice_str + '</span>' );
							jQuery( '#finalfeedback' ).fadeIn( 'fast' );
							
						}
					} );
					
			} else {
				
				// country appendix
				var obey_elem = jQuery( '#ssc option:selected' ).attr( 'value' );
				if( obey_elem > 0 ) {
					jQuery( '#finalfeedback' ).fadeOut( 'fast' );
					window.location.replace( action_AN + '?hc=' + number_format( obey_elem, 2, '.', '' ) );
				} else {
					var bodyelem = '';
					if( jQuery.browser.safari ) bodyelem = jQuery( 'body' ); // only Opera specific
					else bodyelem = jQuery( 'html' );
					jQuery( bodyelem ).animate( { scrollTop: jQuery( '#content' ).offset().top }, 'slow' );
					var decoded_scs = decodeURIComponent( "<?php echo $shipping_country_sel; ?>" );
					decoded_scs = decoded_scs.replace( /\+/g, ' ' );
					jQuery( '#finalfeedback' ).html( '<span>' + decoded_scs + '</span>' );
					jQuery( '#finalfeedback' ).fadeIn( 'fast' );
				}
				
			}
		
		} else if( my_routine == 'submitCO' ) {
			// check for stock availability
			if( use_stock == "yes" ) {
				
				var decoded_ppal_custom = decodeURIComponent( "<?php echo $ppal_custom; ?>" );
				decoded_ppal_custom = decoded_ppal_custom.replace( /\+/g, ' ' );
				var decoded_referer = encodeURIComponent( "<?php echo $_SERVER[ 'HTTP_REFERER' ]; ?>" );
				
				jQuery.post( "<?php echo get_bloginfo( 'template_directory' ); ?>/stock_chck.php", { "serialdata": decoded_ppal_custom, "referr": decoded_referer }, 
					function( data ) {

						data = decodeURIComponent( data );
						data = data.replace( /\+/g, ' ' );
						if( data == "" ) {
							
							// country appendix
							var obey_elem = jQuery( '#ssc option:selected' ).attr( 'value' );
							if( obey_elem > 0 ) {
								
								coopened_plus = true;
								jQuery( '#finalfeedback' ).fadeOut( 'fast' );
								jQuery( '#submittr' ).fadeOut( 'fast' );
								jQuery( '#lissc' ).fadeOut( 'fast' );
								var obey_elem_html_co = jQuery( '#ssc option:selected' ).attr( 'title' );
								jQuery( '#ship_country' ).val( obey_elem_html_co );
								jQuery( '#ship_country_quasi' ).val( obey_elem_html_co );
								var obey_elem_value_co = jQuery( '#ssc option:selected' ).attr( 'value' );
								jQuery( '#co_shipping_cost' ).val( obey_elem_value_co );
								jQuery( '#coxxx' ).delay( 350 ).fadeIn( 'fast', function() { jQuery( this ).css( { 'display' : 'block' } ) } );
								
							} else {
								var bodyelem = '';
								if( jQuery.browser.safari ) bodyelem = jQuery( 'body' ); // only Opera specific
								else bodyelem = jQuery( 'html' );
								jQuery( bodyelem ).animate( { scrollTop: jQuery( '#content' ).offset().top }, 'slow' );
								var decoded_scs = decodeURIComponent( "<?php echo $shipping_country_sel; ?>" );
								decoded_scs = decoded_scs.replace( /\+/g, ' ' );
								jQuery( '#finalfeedback' ).html( '<span>' + decoded_scs + '</span>' );
								jQuery( '#finalfeedback' ).fadeIn( 'fast' );
							}
							
						} else {
							
							var notice_str = decodeURIComponent( "<?php echo $stock_product_missing; ?>" );
							notice_str = notice_str.replace( /\+/g, ' ' );
							var arr_data = data.split( "^" );
							var kkk = 0;
							var adl = arr_data.length - 1;
							while( kkk < adl ) {
								var arr_temp = arr_data[ kkk ].split( "~" );
								var decoded_caq = decodeURIComponent( "<?php echo $currently_available_q; ?>" );
								decoded_caq = decoded_caq.replace( /\+/g, ' ' );
								var positive_q = 0;
								if( parseInt( arr_temp[ 1 ] ) < 0 ) positive_q = 0;
								else positive_q = arr_temp[ 1 ];
								notice_str += arr_temp[ 0 ] + decoded_caq + positive_q + "<br />";
								kkk ++;
							}
							
							var bodyelem = '';
							if( jQuery.browser.safari ) bodyelem = jQuery( 'body' ); // only Opera specific
							else bodyelem = jQuery( 'html' );
							jQuery( bodyelem ).animate( { scrollTop: jQuery( '#content' ).offset().top }, 'slow' );
							
							jQuery( '#finalfeedback' ).html( '<span>' + notice_str + '</span>' );
							jQuery( '#finalfeedback' ).fadeIn( 'fast' );
							
						}
					} );
					
			} else {
				
				coopened_plus = true;
				jQuery( '#submittr' ).fadeOut( 'fast' );
				jQuery( '#coxxx' ).delay( 350 ).fadeIn( 'fast', function() { jQuery( this ).css( { 'display' : 'block' } ) } );
				
			}
		
		} else if( my_routine == 'submitAB' ) {
	
			// country appendix
			var obey_elem = jQuery( '#ssc option:selected' ).attr( 'value' );
			if( obey_elem > 0 ) {
				
				opened_plus = true;
				jQuery( '#finalfeedback' ).fadeOut( 'fast' );
				jQuery( '#submittr' ).fadeOut( 'fast' );
				jQuery( '#lissc' ).fadeOut( 'fast' );
				var obey_elem_html_ab = jQuery( '#ssc option:selected' ).attr( 'title' );
				jQuery( '#ab_country' ).val( obey_elem_html_ab );
				jQuery( '#ab_country_quasi' ).val( obey_elem_html_ab );
				var obey_elem_value_ab = jQuery( '#ssc option:selected' ).attr( 'value' );
				jQuery( '#ab_shipping_cost' ).val( obey_elem_value_ab );
				jQuery( '#bankxxx' ).delay( 350 ).fadeIn( 'fast', function() { jQuery( this ).css( { 'display' : 'block' } ) } );
				
			} else {
				var bodyelem = '';
				if( jQuery.browser.safari ) bodyelem = jQuery( 'body' ); // only Opera specific
				else bodyelem = jQuery( 'html' );
				jQuery( bodyelem ).animate( { scrollTop: jQuery( '#content' ).offset().top }, 'slow' );
				var decoded_scs = decodeURIComponent( "<?php echo $shipping_country_sel; ?>" );
				decoded_scs = decoded_scs.replace( /\+/g, ' ' );
				jQuery( '#finalfeedback' ).html( '<span>' + decoded_scs + '</span>' );
				jQuery( '#finalfeedback' ).fadeIn( 'fast' );
			}

		}
		
		return false;
	} );
	// cancel?
	jQuery( '#cancelorder' ).click( function( event ) {
		
		if( opened_plus ) {
			opened_plus = false;
			jQuery( '#bankxxx' ).fadeOut( 'fast', function() { jQuery( this ).css( { 'display' : 'none' } ) } );
			jQuery( '#lissc' ).delay( 350 ).fadeIn( 'fast' );
			jQuery( '#submittr' ).delay( 350 ).fadeIn( 'fast' );
			return false;
		}
		
	} );
	// confirm
	jQuery( '#confirmorder' ).click( function( event ) { 
			   
		jQuery( '#ppform' ).ajaxForm( {
			type: "POST", 
			url: action_AB, 
			cache: false,                  
			beforeSubmit: ShowRequest,
			success: SubmitSuccesful,
			error: AjaxError                               
		} );
											
	} );
	// cancel 2co?
	jQuery( '#cocancelorder' ).click( function( event ) {
		
		if( coopened_plus ) {
			coopened_plus = false;
			jQuery( '#coxxx' ).fadeOut( 'fast', function() { jQuery( this ).css( { 'display' : 'none' } ) } );
			jQuery( '#lissc' ).delay( 350 ).fadeIn( 'fast' );
			jQuery( '#submittr' ).delay( 350 ).fadeIn( 'fast' );
			return false;
		}
		
	} );
	// confirm
	jQuery( '#coconfirmorder' ).click( function( event ) { 

		// make required fields validation
		var err_string = '';
		
		var ship_name = jQuery( "#ship_name" ).val();
		var ship_address  = jQuery( "#ship_street_address" ).val();
		var ship_city  = jQuery( "#ship_city" ).val();
		var ship_zip  = jQuery( "#ship_zip" ).val();
		var ship_country  = jQuery( "#ship_country" ).val();
	
		if( ship_name.length < 4 ) err_string += "&raquo; " + "<?php _e( "Full Name field is mandatory!", "sofa_shoppr" ); ?>" + "<br />";
		if( ship_address.length < 5 ) err_string += "&raquo; " + "<?php _e( "Shipping Address field is mandatory!", "sofa_shoppr" ); ?>" + "<br />";
		if( ship_city.length < 5 ) err_string += "&raquo; " + "<?php _e( "City field is mandatory!", "sofa_shoppr" ); ?>" + "<br />";
		if( isNaN( ship_zip ) || ship_zip.length < 5 ) err_string += "&raquo; " + "<?php _e( "ZIP code field is mandatory (NNNNN)!", "sofa_shoppr" ); ?>" + "<br />";
		if( ship_country.length < 2 ) err_string += "&raquo; " + "<?php _e( "Country field is mandatory!", "sofa_shoppr" ); ?>" + "<br />";
		
		if( err_string == '' ) {
			
			var bodyelem = '';
			if( jQuery.browser.safari ) bodyelem = jQuery( 'body' ); // only Opera specific
			else bodyelem = jQuery( 'html' );
			jQuery( bodyelem ).animate( { scrollTop: jQuery( '#content' ).offset().top }, 'slow' );
			
			jQuery( '.chckoutcontainer' ).fadeOut();
			jQuery( '#finalfeedback' ).fadeIn( 'fast' );
			jQuery( '#finalfeedback' ).html( '<span><?php _e( "Processing Order...", "sofa_shoppr" ); ?></span>' );
			
			jQuery( '#coform' ).attr( 'action', action_CO );
			setTimeout( function () { jQuery( '#coform' ).submit() }, 1000 );

			
		} else {
			
			jQuery( '#cofeedback' ).fadeIn( 'fast' );
			jQuery( '#cofeedback' ).html( "<span>" + err_string + "</span>" );
			return false;
			
		}
											
	} );
	
} );           

function ShowRequest( formData, jqForm, options ) {
	// make required fields validation
	var err_string = '';

	var ab_first_name = jQuery( "#ab_firstname" ).val();
	var ab_last_name  = jQuery( "#ab_lastname" ).val();
	//var ab_cell_phone = jQuery( "#ab_cellphone" ).val();
	var ab_email  = jQuery( "#ab_email" ).val();
	var ab_address  = jQuery( "#ab_address" ).val();
	var ab_city  = jQuery( "#ab_city" ).val();
	var ab_zipcode  = jQuery( "#ab_zipcode" ).val();
	var ab_country  = jQuery( "#ab_country" ).val();
	
	if( ab_first_name.length < 3 ) err_string += "&raquo; " + "<?php _e( "First Name field is mandatory!", "sofa_shoppr" ); ?>" + "<br />";
	if( ab_last_name.length < 3 ) err_string += "&raquo; " + "<?php _e( "Last Name field is mandatory!", "sofa_shoppr" ); ?>" + "<br />";
	if( !validateEmail( ab_email ) ) err_string += "&raquo; " + "<?php _e( "Email field is mandatory or e-mail address not acceptable.", "sofa_shoppr" ); ?>" + "<br />";
	//if( !ab_cell_phone.match( /(\+\d)*\s*(\(\d{3}\)\s*)*\d{3}(-{0,1}|\s{0,1})\d{2}(-{0,1}|\s{0,1})\d{2}/ ) ) err_string += "&raquo; " + "<?php //_e( "Cell Phone Number field is mandatory! Must use +NN-1234-1234... or 1234-1234... format!", "sofa_shoppr" ); ?>" + "<br />";
	if( ab_address.length < 5 ) err_string += "&raquo; " + "<?php _e( "Shipping Address field is mandatory!", "sofa_shoppr" ); ?>" + "<br />";
	if( ab_city.length < 5 ) err_string += "&raquo; " + "<?php _e( "City field is mandatory!", "sofa_shoppr" ); ?>" + "<br />";
	if( isNaN( ab_zipcode ) || ab_zipcode.length < 5 ) err_string += "&raquo; " + "<?php _e( "ZIP code field is mandatory (NNNNN)!", "sofa_shoppr" ); ?>" + "<br />";
	if( ab_country.length < 2 ) err_string += "&raquo; " + "<?php _e( "Country field is mandatory!", "sofa_shoppr" ); ?>" + "<br />";
	
	if( err_string == '' ) {
		
		var bodyelem = '';
		if( jQuery.browser.safari ) bodyelem = jQuery( 'body' ); // only Opera specific
		else bodyelem = jQuery( 'html' );
		jQuery( bodyelem ).animate( { scrollTop: jQuery( '#content' ).offset().top }, 'slow' );
		
		jQuery( '.chckoutcontainer' ).fadeOut();
		jQuery( '#finalfeedback' ).fadeIn( 'fast' );
		jQuery( '#finalfeedback' ).html( '<span><?php _e( "Processing Order...", "sofa_shoppr" ); ?></span>' );
		return true;
		
	} else {
		
		jQuery( '#feedback' ).fadeIn( 'fast' );
		jQuery( '#feedback' ).html( "<span>" + err_string + "</span>" );
		return false;
		
	}
}

function AjaxError( responseText, statusText ) {
	jQuery( '#finalfeedback' ).html( '<span><?php _e( "We were unable to process your Order! The system responded with error.", "sofa_shoppr" ); ?>' + responseText + ', ' + statusText + '</span>' );
}

function SubmitSuccesful( responseText, statusText ) {
	jQuery( '#finalfeedback' ).fadeIn( 'fast' );
	jQuery( '#finalfeedback' ).html( "<span>" + responseText + "</span>" );
	jQuery( '#ppform' ).resetForm();
}
	
function validateEmail( email ) {  
	return email.match( /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/ );
}

function number_format( number, decimals, dec_point, thousands_sep ) {
	var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
	var d = dec_point == undefined ? "," : dec_point;
	var t = thousands_sep == undefined ? "." : thousands_sep, s = n < 0 ? "-" : "";
	var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
	return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
}

function watchChanges( elem, old_value_val ) {  
	if( elem > 0 ) {
		if( !isNaN( old_value_val ) && parseFloat( old_value_val ) > 0 ) {
			var new_val = parseFloat( old_value_val ) + parseFloat( elem );
			var new_val_and_curr = decodeURIComponent( "<?php echo $entrycurrency; ?>" ) + ' ' + number_format( new_val, 2, '.', ',' );
			jQuery( '#appendshipping' ).text( new_val_and_curr );
		}
	} else {
		jQuery( '#appendshipping' ).text( decodeURIComponent( "<?php echo $entrycurrency; ?>" ) + ' ' + number_format( old_value_val, 2, '.', ',' ) );
	}
}

</script>

    
    <?php
	// end if cookie exist
	} else { echo '<p><i>' . __( "No items in shopping basket!", "sofa_shoppr" ) . '</i></p>'; }
	?>
    
    </div><!-- END CHCKOUTCONTAINER -->
    
    </div><!-- END ARTICLE -->

</div><!-- END CONTENT -->

<?php endwhile; endif; ?>

<?php include( TEMPLATEPATH . '/sidebar_checkout.php' ); ?> 

<?php get_footer(); ?>