
function identifyProduct(product)
{
    var x = showloading();
    var p_id = $("input[name='"+product+"']:checked").attr('id');
    var p_code = $('input[name='+product+']:checked').val();
    var p_title = $('#'+product+'_title').html();
    var p_subs = $('#'+p_id+'_subscription').html();
    $('#msg_title').html(p_title);
    $('#msg_subscription').html(p_subs);
    callAjax(p_code,x);
}
function identifyPrimeProduct(productKey,id)
{
    var x = showloading();
    var tmp = "#product_title_"+id+"";
    var p_title = $(tmp).html();
    //alert(p_title);
    tmp = "#product_text_"+id+"";
    var p_text = $(tmp).html();
    $('#msg_title').html(p_title);
    $('#msg_subscription').html(p_text);
    callAjax(productKey,x);
}
function callAjax(product,x)
{
    $.ajax({
    url: '/payment/jsp/AddToCart.jsp',
    type: 'POST',
    dataType: 'xml',
    data: 'itemAdded='+product+'&ajax=true',
    timeout: 30*1000,
    cache: false,
    success: function(xml){
        var temp = '';
        
        temp = $(xml).find("error");
         //alert(temp.text());
        if(temp.text() == null || temp.text() == "")
        {
            $(xml).find('result').each(function()
            {
                if($(xml).find('added').text().toString() == 'true')
                {
                    x.close();
                    $('#basic-modal-content').modal({containerCss:{
                            backgroundColor:'#fff',
                            height:220,
                            width:470
                            },
                            close:true,
                            overlayClose:true,
                            opacity:80,
                            overlay:true
                        });
                    $('#cartItemsCount').html(''+$(xml).find('count').text());
                    $('#cartSubtotal').html(''+$(xml).find('subtotal').text());
                }
                else if($(xml).find('currencymismatch').text() == "true")
                {
                   var err_msg = "<div style='padding:10px;color:#f00'>"+
                                    "<img src='/main/products/images/alert.gif' style='float:left;display:block;'>"+
                                    "<div style='float:left;margin:0 0 0 10px;'>"+
                                    "Please complete your current purchase(s)<br/>"+
                                    "in your cart before adding products<br/>"+
                                    "that are in another currency.<br/>"+
                                    "</div>"+
                                    "<div style='clear:both;'>"+
                                    "<a href='/payment/jsp/Cart.jsp'><img src='/payment/jsp/images/cart/cart_green.gif' class='checkoutButton' border='0'/></a>"+
                                  "</div>"
                   x.close();
                   $.modal(err_msg,{containerCss:{
                            backgroundColor:'#fff',
                            height:120,
                            padding:0,
                            width:320
                            },
                            close:true,
                            overlayClose:true
                        });
                }
                else
                {
                    errMethod(x);
                }
            })
        }
        else
        {
            errMethod(x);
        }
    },
    error: function(request, errorType, errorThrown)
    {
        x.close();
        if(errorType == 'timeout')
        {
            alert("Your request has been timed out. Please try again.");
        }
    }
    });
    return;
}
function errMethod(x)
{
    x.close();
    $.modal('<div>Sorry, there was an error processing your request. Please try again.</div>',{containerCss:{
                            backgroundColor:'#fff',
                            height:40,
                            padding:20,
                            width:320,
                            textalign:'center',
                            color:'#f00'
                            },
                            close:true,
                            overlayClose:true
                        });
}
function loadjscssfile(filename, filetype)
{
  if (filetype=="js"){ //if filename is a external JavaScript file
     var fileref=document.createElement('script')
     fileref.setAttribute("type","text/javascript")
     fileref.setAttribute("src", filename)
  }
  else if (filetype=="css"){ //if filename is an external CSS file
     fileref=document.createElement("link")
     fileref.setAttribute("rel", "stylesheet")
     fileref.setAttribute("type", "text/css")
     fileref.setAttribute("href", filename)
  }
  if (typeof fileref!="undefined")
     document.getElementsByTagName("head")[0].appendChild(fileref)
}
function showloading()
{
    var img = '<img src="/main/products/images/loading.gif" style="margin:0 12px;"/>';
    var x = $.modal(img,{containerCss:{
                            backgroundColor:'#fff',
                            height:100,
                            width:150,
                            textalign:'center',
                            color:'#f00'
                            },
                            close:false
                        });
   return x;
}

