var isRequestCalled=false;
function toggleVisibility(id) {
	$("#"+id).toggle();
}

function showDiv() {
	var displayDiv = document.getElementById("email_in_stock_div").style;
	if(displayDiv.display != "block")
		displayDiv.display = "block";
}
function getFormElement(img_path)
  {
   	var img_tag;
  	var img_name;
    $(".prev_toNameDiv").html($("#to_name").val());
    $(".prev_fromNameDiv").html($("#from_name").val());
	var comm = ($("#comments").val());
	var divComm = "";
	var line=0
	for(var i=0;i<comm.length;)
		{	
			divComm = divComm + comm.substr(i,35);
			i=i+35;
			if(line<=6)
				line=line+1;
			else
				break;
		}
	if(line>=6)		
		{ 	divComm = divComm + "..."; }	 
    $(".prev_gcMessageDiv").html(divComm);
    $(".prev_gcAmountDiv").html("$" + $( "#amount").val());
    img_name = $('input[@name=giftCertificate]:checked').val();
    imp_tag = "<img alt='' src='"+img_path+img_name+"'/>";
  	document.getElementById('giftCertificateDiv').innerHTML = imp_tag;

  }
  
function submitForm()
	{
	document.getElementById('giftCertificates').submit();
	}  
   
function toggleList(id1,id2) {
	$("#"+id1).toggle();
	$("#"+id1).children().toggle();
	$("#"+id2).toggle();	
	$("#"+id2).children().toggle();
}
function toggleBlocks(id1,id2) {
	$("#"+id1).toggle();
	$("#"+id2).toggle();
}

$(document).ready(function() {
	    $("#giftReview").toggle();
 });
 
function sortedList(url,delimiter)
{   
	var sortopt=document.getElementById("sortitems").value;
	url=url + delimiter + "sort" + delimiter + sortopt + delimiter;
    window.location=url;
}

function sortedSearchList(url,delimiter)
{   
	var sortopt=document.getElementById("sortitems").value;
	var perpage=document.getElementById("perpage").value;
	url=url + delimiter + "sort" + delimiter + sortopt + delimiter + "perpage" + delimiter + perpage + delimiter;
    window.location=url;
}

function  showShippingOptions(delimiter){
	var url="get-shipping-options/nolayout"+ delimiter + "1" + delimiter +
	 "ship_to_zip" + delimiter +$("#zip").val() + delimiter;
	$("#shippingOptionsContent").load(url);
	return url;
}

/*function show_shipping_options(url,form,div_id){
	start_spinner($("#" + div_id).offset().left+100,$("#" + div_id).offset().top);
	  $.ajax({  
            //this is the php file that processes the data and send mail  
             url: url,
             //GET method is used  -- NOT!
             type: "POST",
             //pass the data           
             data: $(form).serialize( ),
             //Do not cache the page  
             cache: false,
             //success  
             success: function (html) {                
               //hide the form  
               end_spinner();
               //$("#"+div_id).html(html);
			   $('#zipCodeLabel').text(zip);
             }
         });  
           
         //cancel the submit button default behaviours  
         return false;  
}*/

function show_shipping_options(url,form,div_id){
	start_spinner($("#" + div_id).offset().left+100,$("#" + div_id).offset().top);
	  $.ajax({  
            //this is the php file that processes the data and send mail  
             url: url,   
               
             //GET method is used  
             type: "POST",  
   
             //pass the data           
             data: $(form).serialize( ),       
               
             //Do not cache the page  
             cache: false,  
               
             //success  
             success: function (html) {                
                     //hide the form  
                   end_spinner();  
                   $("#"+div_id).html(html);
				   //$('#zipCodeLabel').text(zip);
             }         
         });  
           
         //cancel the submit button default behaviours  
         return false;  
}

var visiblediv =null;

function makeVisible(id) {
	$("."+id).toggle();
	$(".paymentMode").css("display","none");
	$("."+id).toggle();
}

function cart_item_update(url,form,div_id){
	  $.ajax({  
            //this is the php file that processes the data and send mail  
             url: url,   
               
             //GET method is used  
             type: "POST",  
   
             //pass the data           
             data: $(form).serialize( ),       
               
             //Do not cache the page  
             cache: false,
               
             //success  
             success: function (html) {                
                     //hide the form  
                     $("#" + div_id).html(html);      
             }         
         });  
           
         //cancel the submit button default behaviours  
         return false;  
}


function save_credit_card(url,form,div){
	start_spinner($("#" + div).offset().left+50,$("#" + div).offset().top+300);
	if(isRequestCalled==false){
	 isRequestCalled=true;  
	  $.ajax({  
            //this is the php file that processes the data and send mail  
             url: url,   
               
             //GET method is used  
             type: "POST",  
   
             //pass the data           
             data: $(form).serialize( ),       
               
             //Do not cache the page  
             cache: false,  
               
             //success  
             success: function (html) { 
                     //hide the form  
                    /*$("#" + div).html(html); 
                    isRequestCalled=false;  
                     end_spinner();*/
             }         
         });
       }
         //cancel the submit button default behaviours  
        
}

function seleState(state){
	var selstate=document.getElementById("state");
	for (var i=0; i<selstate.length; i++){
		if(selstate.options[i].value==state){
			selstate.options[i].selected=true;
		}else{
			selstate.options[i].selected=false;
		}
	}
	
}
function edit_credit_card(url,form,div,parent,delimiter){
	  $.ajax({  
            //this is the php file that processes the data and send mail  
             url: url,   
               
             //GET method is used  
             type: "POST",  
   
             //pass the data           
             data: $(form).serialize( ),       
               
             //Do not cache the page  
             cache: false,  
               
             //success  
             success: function (html) {                
                     //hide the form  
					 /*$('#jqmPopup').jqmHide();
                     $("#" + div).html(html);*/
					 
					 
					 if(parent=="billing")
                       	location.href = ("/account/billing.html");
                      else
                        location.href = ("/cart/checkout-step3.html");
					 
                      /*if(parent=="billing")
                       	$("#billing_creditCardList").load("../components/credit-cards-list/nolayout"+delimiter+"1"+delimiter+"rnd"+delimiter+Math.round(20*Math.random())+delimiter,function(){tb_init('a.thickbox, area.thickbox, input.thickbox');$("#business_card").html("Credit Card Updated Successfully"); });
                      else if (parent=="checkout-step4")
                      	$("#checkout_details").load("../cart/final-cart-items/nolayout"+delimiter+"1"+delimiter+"rnd"+delimiter+Math.round(20*Math.random())+delimiter,function(){tb_init('a.thickbox, area.thickbox, input.thickbox');$("#business_card").html("Credit Card Updated Successfully"); });
                      else if (parent=="payment-resubmission")
                        $("#checkout_creditCardList").load("../../components/credit-cards-list/nolayout"+delimiter+"1"+delimiter+"rnd"+delimiter+Math.round(20*Math.random())+delimiter,function(){tb_init('a.thickbox, area.thickbox, input.thickbox');$("#business_card").html("Credit Card Updated Successfully"); });
                      else
                        $("#checkout_creditCardList").load("../components/credit-cards-list/nolayout"+delimiter+"1"+delimiter+"rnd"+delimiter+Math.round(20*Math.random())+delimiter,function(){tb_init('a.thickbox, area.thickbox, input.thickbox');$("#business_card").html("Credit Card Updated Successfully"); });*/
                      
             }         
         });  
           
         //cancel the submit button default behaviours  
        
}

function out_of_stock(url,form,div){
	  $.ajax({  
            //this is the php file that processes the data and send mail  
             url: url,   
               
             //GET method is used  
             type: "POST",  
   
             //pass the data           
             data: $(form).serialize( ),       
               
             //Do not cache the page  
             cache: false,  
               
             //success  
             success: function (html) {                
                     //hide the form  
                   $("#" + div).html(html);
                      
             }         
         });  
           
         //cancel the submit button default behaviours  
        
}

function save_verification_id(url,form,div)
{
	$.ajax({  
            //this is the php file that processes the data and send mail  
             url: url,   
               
             //GET method is used  
             type: "POST",  
   
             //pass the data           
             data: $(form).serialize( ),       
               
             //Do not cache the page  
             cache: false,  
               
             //success  
             success: function (html) {                
                     //hide the form  
                   $("#" + div).html(html);
             }         
         });  
           
         //cancel the submit button default behaviours  
}

function submitVerificationIDIfEnter(e)
{
   var keycode;
   if (window.event)
   {
      keycode = window.event.keyCode;
   }
   else if (e)
   {
      keycode = e.which;
   }
   else
   {
      return true;
   }

   if (keycode == 13)
   {
   	  save_verification_id(document.getElementById('cvv_form').action,document.getElementById('cvv_form'),'cvv_id');
      return false;
   }
   else
   {
      return true;
   }
}
function display_div(pg)
{
	$("#business_card").html("Credit Card Updated Successfully");
}

function delete_credit_card(url,pg){
		var div_name;
		
		if(pg=="billing") {
			div_name="billing_creditCardList";
		} else {
			div_name="checkout_creditCardList";$('#jqmPopup').jqmHide();
		}
		$("#" + div_name).load(url,function(data){} );
		
}

function edit_shipping_address(url,form,div,pg,parent,delimiter){
	$.ajax({  
		//this is the php file that processes the data and send mail
		url: url,
		//GET method is used
		type: "POST",
		//pass the data
		data: $(form).serialize(),
		//Do not cache the page  
		cache: false,
		//success  
		success: function (html) {
			$('#jqmPopup').jqmHide();
			//hide the form  
			//$("#"+div).html(html);
			//location.href = parent;
			//$("#" + div).html(html);
			if(parent=="shipping")
				//$("#billing_creditCardList").load("../components/shipping-or-checkout-address-list/nolayout"+delimiter+"1"+delimiter+"rnd"+delimiter+Math.round(20*Math.random())+delimiter,function(){tb_init('a.thickbox, area.thickbox, input.thickbox'); });
				window.location="/account/shippingAddresses.html";
			else if (parent == "checkout-step1")
				window.location="/cart/checkout-step1.html";
			else if (parent=="checkout-step4")
				$("#checkout_details").load("../cart/final-cart-items/nolayout"+delimiter+"1"+delimiter+"rnd"+delimiter+Math.round(20*Math.random())+delimiter,function(){tb_init('a.thickbox, area.thickbox, input.thickbox'); });
			/*else
				$("#checkout_creditCardList").load("../components/shipping-or-checkout-address-list/nolayout"+delimiter+"1"+delimiter+"rnd"+delimiter+Math.round(20*Math.random())+delimiter,function(){tb_init('a.thickbox, area.thickbox, input.thickbox') });
				window.location="/cart/checkout-step1.html";*/
		}
		
	});
}
function send_friend_email(url,form,div,delimiter){
	
	  $.ajax({  
            //this is the php file that processes the data and send mail  
             url: url,   
               
             //GET method is used  
             type: "POST",  
   
             //pass the data           
             data: $(form).serialize( ),       
               
             //Do not cache the page  
             cache: false,  
               
             //success  
             success: function (html) {     
                     //hide the form  
              		$("#" + div).html(html);	
                   //$("#emailFriendPopContainer").load("/category/popup-email-friend/nolayout"+delimiter+"1"+delimiter,function(){tb_init('a.thickbox, area.thickbox, input.thickbox');});                   
                   	
             }         
         }); 
}
function show_success_message(div_name,msg)
{
        	$("#"+div_name).html(msg);
                $("#"+div_name).css("display","block");
}
function delete_shipping_address(url,pg){
	/*
var div_name;
	if(pg=="shipping")
		{div_name="billing_creditCardList";}
	else
		{div_name="checkout_creditCardList";}
		$("#" + div_name).load(url,function(data){tb_init('a.thickbox, area.thickbox, input.thickbox'); } );
			//tb_remove();
*/
//location.href = ("/cart/checkout-step1.html");
}


function toggle_visibility(id) 	
{
	$(".helpContainer > div").css("display" ,"none");
	$("#" + id).toggle();
	
}

function remove_selected_payment_mode(url){
	$("#checkout_details").load(url,function(data){tb_init('a.thickbox, area.thickbox, input.thickbox'); } );
}
function changeLink(id){
	if($("#" + id ).html().indexOf('View Details',0)>0) {
		 $("#" + id).html('[Hide Details]');
	}else {
		 $("#" + id).html('[View Details]');
	}
}

function display_subcart(qty_id,url){
	start_spinner(document.body.clientWidth/2,document.body.clientHeight/2);
    window.open(url,"mywindow","top=0,left=0,toolbar=0,status=0,menubar=0,copyhistory=0,resizable=0,width=550,height=420");
    end_spinner();
}

function disply_items_grid(delim,url,div,thisClass){
		var thisSelector = '#add_to_cart' + div + ' th.' + thisClass;
       /*if($("#itemsGrid").length!=0){
			$(thisSelector).html('<img src="/static/images/loading.gif" height="20" width="20" />');
       	}else{
			$(thisSelector).html('<img src="/static/images/loading.gif" height="20" width="20" />');
       	}*/
		$(thisSelector).html('<img src="/static/images/loading.gif" style="height: 18px; width: 18px; padding-bottom: 4px;" />');
        if (document.getElementById("gridLimit"+ div) != null) {
                url = url + "gridLimit" + delim + $("#gridLimit"+ div).val() + delim;
        }
          if ($("#query").val() != "") {
                  if ($("#query").val() != 'Search') {
                          var encQry = encodeURIComponent(encodeURIComponent($("#query").val()));
                          url = url + 'query' + delim + encQry + delim;
                  }
          }
          if($("#itemsGrid").length!=0){
                    	 $("#itemsGrid").load(url,function(){end_spinner();} );
                    }else{
                    	 $("#Grid" + div).load(url,function(){end_spinner();} );
                    }
}

function selShippionOpt(selShippingOpt,delim){
	$('#jqmPopup').jqmHide();
	var randomnumber=Math.floor(Math.random()*11)
	var url="/cart/selectShippingOpt/nolayout" + delim + "1" + delim + "selshippingOpt" + delim + selShippingOpt + delim+ "?rnd=" + randomnumber;
	//alert(url);
	$("#shippingEstDetail").load(url,'', function(){
		
	end_spinner();  
  });
  
}

function selShippionOptConfirm(selShippingOpt,delim){
	$('#jqmPopup').jqmHide();
	var randomnumber=Math.floor(Math.random()*11)
	var url="/cart/selectShippingOpt/nolayout" + delim + "1" + delim + "confirmation" + delim + "1" + delim + "selshippingOpt" + delim + selShippingOpt + delim+ "?rnd=" + randomnumber;
	//alert(url);
	$("#shippingEstDetail").load(url,'', function(){
		
	end_spinner();  
  });
  
}

function selShippionOptStep(selShippingOpt,delim){
	var randomnumber=Math.floor(Math.random()*11)
	var url="/cart/selectShippingOpt/nolayout" + delim + "1" + delim + "selshippingOpt" + delim + selShippingOpt + delim+ "?rnd=" + randomnumber;
	$("#shippingEstDetail").load(url,'', function(){
		window.location="/cart/cart.html";
  });
  
}

function setdialogBox(){
		var h = $("#shippingEstDetail").height();
                if (h != null) {
                        h = h + 50;
                        $("#TB_ajaxContent").css("height", h);
                }
	};

function validate_coupon(url,form){

	  $.ajax({  
             url: url,   
               
             //GET method is used  
             type: "POST",
   
             //pass the data           
             data: $(form).serialize(),       
               
             //Do not cache the page  
             cache: false,  
               
             //success  
             success: function (html) { 
                     
					 $('#jqmPopup').jqmHide();
					  //hide the form 
                  //$("#redeem_div").html(html);
				  //$('#formResponse').show();
				  window.location="/cart/cart.html";
             }
         });
}

function remove(delim){
	//var url="/cart/remove-coupon/nolayout" + delim + "1" + delim + "delcoupon" + delim + "1" + delim;
	var url="/static/popups/removeCoupon.cfm?removeCoupon";
	 $.get(url, function(data){
		$("#coupon_div").html("");
		//tb_remove();
		//window.location="/cart/cart.html";
		$('#jqmPopup').jqmHide();
		window.location="/cart/cart.html";
	});
}


function display_coupon(url,form ){
	  $.ajax({  
             //this is the php file that processes the data and send mail  
             url: url,   
               
             //GET method is used  
             type: "POST",  
   
             //pass the data           
             data: $(form).serialize(),       
               
             //Do not cache the page  
             cache: false,  
               
             //success  
             success: function (html) {                
                     //hide the form  
                     $("#coupon_div").html(html);
                     window.location.reload(); 
                     tb_remove();
             }         
         });  
}
 function passHelpsubmit(url,form){
 	//var url=form.action + "";
 	  $.ajax({  
             //this is the php file that processes the data and send mail  
             url: url,   
               
             //GET method is used  
             type: "POST",  
   
             //pass the data           
             data: $(form).serialize(),       
               
             //Do not cache the page  
             cache: false,  
               
             //success  
             success: function (html) {                
                     //hide the form  
                     //$("#ajaxContent").html(html);
					 $('#jqmPopup').jqmHide();
					 window.location="/account/login.html";
             }         
         });  
 
 }
 function backGCForm(form,delim){
	document.getElementById(form).action="/account/giftcard/noPreview" + delim + "1" + delim;
 	document.getElementById(form).submit();
 }
 function refreshParent() {
  window.opener.location.href = window.opener.location.href;

  if (window.opener.progressWindow)
		
 {
    window.opener.progressWindow.close()
  }
  window.close();
}

function addToCart(form){

	if(isValidQty)
	{
		form.submit();
	}

}
var isValidQty = false;
   function validatePosInt(fieldId)
   {
      var isPositiveInt=isPositiveInteger($("#" + fieldId).val());
     if(isPositiveInt)
      {     isValidQty = true;
   			$("#" + fieldId).css("border-color","#999999");
   			$(".floatingMessage").css("display","none");
   			$("#" + fieldId).focus(function(){return true;});
       }else{
       		  isValidQty = false;	
              display_floating_message(fieldId);
      }
   }
   
function reLoadCartSummary (cost,type,delimiter) {
	//$('#jqmPopup').jqmHide();
	var url="/components/cartSummary/noLayout"+ delimiter + "1" + delimiter +"shipcost" + delimiter + cost + delimiter + "shiptype" + delimiter + type + delimiter;
	$("#cartPreview").load(url);
}
