function check_reg_form()
{
     if ($('#favoritegems1_input').css('display') == 'block'){$('#favoritegems1').val($('#favoritegems1_input').val());};
	 if ($('#favoritegems2_input').css('display') == 'block'){$('#favoritegems2').val($('#favoritegems2_input').val());};
	 if ($('#favoritemetals1_input').css('display') == 'block'){$('#favoritemetals1').val($('#favoritemetals1_input').val());};
	 if ($('#favoritemetals2_input').css('display') == 'block'){$('#favoritemetals2').val($('#favoritemetals2_input').val());};
   
    $('#favoritegems1_input').remove();
	$('#favoritegems2_input').remove();
	$('#favoritemetals1_input').remove();
	$('#favoritemetals2_input').remove();
	
     $.post('/lib.php?mode=checkregform', $("#reg_form_post").serialize(),

          function(data)
          {

              if(data=="ok")
              {
                 document.getElementById("reg_form_post").submit();
              } else {
                  // alert(data);
				  
				  if ($('#reg_emailpopup').length > 0) {
					$('.popup-shadow, #reg_emailpopup').show();
				  }
				  else {
					$('body').append('<div class="popup os" id="reg_emailpopup"><div class="header"><h2></h2><a href="javascript:void(0);"><img class="close_popup" src="templates/deluxe/img/os-icon_close.png" alt="CLOSE"></a></div><div class="body" id="wishlistpopupbody"><p>' + data + '</p><input class="btn_ok" type="button" value="OK" /></div></div>');
					$('#reg_emailpopup .close_popup, #reg_emailpopup .btn_ok').click(function(){
						$('.popup-shadow, #reg_emailpopup').hide();
					});
					$('.popup-shadow').show();
				  }
				  
                }

          }

         );


     return false;

}

function add_product_to_wish()
{

     $.post('/lib.php?mode=savegiftreg', $("#addproducttowishlist").serialize(),

          function(data)
          {

               document.location.href = data;

          }

         );


     return false;

}

function show_gift_div(productid)
{

     $.post('/lib.php?mode=getgiftreg&productid='+productid,

          function(data)
          {

               if(data.indexOf("index.php")!=-1 && data.indexOf("To create a wishlist, you need")==-1)
               {
                  document.location.href = data;
               } else {
                    $("#wishlistpopupbody").html(data);
                    $("#wishlistpopup").fadeIn(500);
					
					var params = {
						changedEl: ".custom_select3 select",
						visRows: 5,
						scrollArrows: true
					};
					cuSel(params);
					
                 }

          }

         );


     return false;



}

function post_cart_to_db()
{

     $.post('/index.php?xlspg=cart', $("#cartform").serialize(),

          function(data)
          {

                if(data.indexOf("all_right")!=-1)
                {

			$('.cart-step-5').css({'position':'absolute'}).fadeOut(500);
			$('.cart-step-6').css({'position':'relative'}).fadeIn(500);

		} else {

		     alert(data);

                  }

          }

         );


     return false;


}

function check_pdf_popup(productid)
{

     $.post('/lib.php?mode=checkpdflink&productid='+productid,

          function(data)
          {

               if(data=="mode1")
               {
				   setTimeout( function(){
						$('#div_popup_log').fadeIn();
				   }, 300);

               } else {
                      window.open(data);
                   }

          }

         );

}

function check_cart_popup(productid)
{

     $.post('/lib.php?mode=checklink&productid='+productid,

          function(data)
          {

               if(data=="mode1")
               {
				   setTimeout( function(){
						$('#div_popup_os').fadeIn();
				   }, 300);
                   document.getElementById("cartlink").href = "index.php?xlspg=cart&ordertype=2&addcart="+productid;
                   document.getElementById("cartimg").src="templates/deluxe/img/buy_now.png";
               } else if(data=="mode2")
                 {
					setTimeout( function(){
						$('#div_popup_so').fadeIn();
					}, 300);
                    document.getElementById("cartlink").href = "index.php?xlspg=cart&ordertype=3&addcart="+productid;
                    document.getElementById("cartimg").src="templates/deluxe/img/txt_so.png";
                 } else {
                      document.getElementById("cartimg").src="templates/deluxe/img/buy_now.png";
                      document.location.href = "index.php?xlspg=cart&addcart="+productid;
                   }

          }

         );

}
/*
$(document).ready(function(){

    //var remover = $('.custom_select.custom_wishlist #c42_ctl #cuselFrame-c42').detach();
    $('#c42_ctl').remove();
    //remover.appendTo('.custom_select.custom_wishlist');
}
*/
