function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0

  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function SelectAll(id)
{
    document.getElementById(id).focus();
    document.getElementById(id).select();
}

//disable all select options in checkout page
function clearSelect (){
    this.document.pay.proforma_cc[0].disabled=true;
    this.document.pay.proforma_cc[1].disabled=true;
    this.document.pay.proforma_cc[2].disabled=true;  
    this.document.pay.proforma_cc[0].checked=false;
    this.document.pay.proforma_cc[1].checked=false;
    this.document.pay.proforma_cc[2].checked=false; 
    this.document.pay.cardname.disabled=true;
    this.document.pay.cardtype.disabled=true;
    this.document.pay.cardnumber.disabled=true;
    this.document.pay.cardissue.disabled=true;
    this.document.pay.cardstartm.disabled=true;
    this.document.pay.cardstarty.disabled=true;
    this.document.pay.cardexpirem.disabled=true;
    this.document.pay.cardexpirey.disabled=true;
    this.document.pay.nostart.disabled=true;
    this.document.pay.terms.disabled=true;    
    this.document.pay.terms.checked=false;    
}


// disable items in cart check out page
function DisabCC (val) {
    
    //alert (document.getElementById('deloption').value);
    if (document.getElementById('deloption').value=="Own shipping account with ") {
        if ((document.getElementById('owncarrier').value == 'None') || (document.getElementById('accountname').value == '') || (document.getElementById('accountno').value == '')){
            alert("You have chosen to use your own carrier, please select a carrier and enter your selected carrier's account name and number.");
            clearSelect();
            return false;    
        }
    }
    
    if(val=="1" || val=="3") {
        this.document.pay.cardname.disabled=true;
        this.document.pay.cardtype.disabled=true;
        this.document.pay.cardnumber.disabled=true;
        this.document.pay.cardissue.disabled=true;
        this.document.pay.cardstartm.disabled=true;
        this.document.pay.cardstarty.disabled=true;
        this.document.pay.cardexpirem.disabled=true;
        this.document.pay.cardexpirey.disabled=true;
        this.document.pay.nostart.disabled=true;
        this.document.pay.terms.disabled=false;
        //this.document.pay.submitme.disabled=false;

    }    
    if(val=="2") {
        this.document.pay.cardname.disabled=false;
        this.document.pay.cardtype.disabled=false;
        this.document.pay.cardnumber.disabled=false;
        this.document.pay.cardissue.disabled=false;
        this.document.pay.cardstartm.disabled=false;
        this.document.pay.cardstarty.disabled=false;
        this.document.pay.cardexpirem.disabled=false;
        this.document.pay.cardexpirey.disabled=false;
        this.document.pay.cardcvv.disabled=false;
        this.document.pay.nostart.disabled=false;
        this.document.pay.terms.disabled=false;
        //this.document.pay.submitme.disabled=false;
    }
}

/*
function Terms()    {
        
    if(this.document.pay.termsanconditions.checked==true) {
        this.document.pay.submitme.disabled=false;
    }    
    else {
        this.document.pay.submitme.disabled=true;
    }
        
}
*/

function DisabSTART () {
    
    if(this.document.pay.nostart.checked==true) {
        this.document.pay.cardstartm.disabled=true;
        this.document.pay.cardstarty.disabled=true;
    }    
    else {
        this.document.pay.cardstartm.disabled=false;
        this.document.pay.cardstarty.disabled=false;
    }
}

function Ship (val,type,deltext,liverate,vat_rate) { 
    
    //alert (val);
    clearSelect();
        
        if (type=='ship'){
            var shipamount=document.getElementById(val).innerHTML;
            this.document.pay.deloption.value='';            
        }
        else if (type=='other'){
            var shipamount="0.00";
            this.document.pay.deloption.value=deltext;    
        }
        else if (type=='own'){
            var shipamount="0.00";
            this.document.pay.deloption.value=deltext;        
            
            sub1 = document.ship.owncarrier.selectedIndex;
            sub2 = document.ship.owncarrier.options[sub1].value;
            this.document.pay.owncarrier.value=sub2;
            //alert (document.getElementById('accountno').value);

            var userInput = document.getElementById('accountname').value;
            this.document.pay.accountname.value = userInput;    
            var userInput = document.getElementById('accountno').value;
            this.document.pay.accountno.value = userInput;    
        }
        if (liverate!=1)liverate=0;
         
/* 
       dataship="act=saveshipping&shipamount="+shipamount+"&liverate="+liverate+"&liveratelog="+$("#liveratelog_"+val).val()+"";    
        $.ajax({
            type: "POST",
            url: "front_actions.php",
            data: dataship,
            success: function(msg){
            }
        });
*/
        $("#ship_to_save").val(shipamount);
        $("#liverate_used").val(liverate); 
        $("#liverate_log").val($("#liveratelog_"+val).val());                 

        
        var subtotalamount=document.getElementById('subtotalamount').innerHTML;
        var subtotalvatamount=parseFloat(subtotalamount);
        subtotalamount=Math.round(subtotalamount*100)/100;
    
        var shippingvatamount=parseFloat(shipamount);
        shippingvatamount=Math.round(shippingvatamount*100)/100;
            
        var vatamount="";
        var vat=document.getElementById('vatenabled').innerHTML;
        document.getElementById('cartvatdiv').innerHTML=vatamount;
        if (vat=='VAT:'){
            vatamount=(((subtotalvatamount+shippingvatamount)/100)*vat_rate); 
            vatamount=Math.round(vatamount*100)/100;

            document.getElementById('cartvatdiv').innerHTML=vatamount;
        }

        var totalamount=subtotalvatamount+shippingvatamount+vatamount;
        totalamount=Math.round(totalamount*100)/100;
        
        document.getElementById('cartshipdiv').innerHTML=shipamount;
                        
        document.getElementById('carttotaldiv').innerHTML=totalamount;
        
        //DisabPAY(2);
        this.document.pay.proforma_cc[0].disabled=false;
        if (type!='other'){
            this.document.pay.proforma_cc[1].disabled=false;
            this.document.pay.proforma_cc[2].disabled=false;  
        }

        var totalmessage="Select a payment method below";
        document.getElementById('totalmessage').innerHTML=totalmessage;
        
        var paymessage="Select a payment method";
        document.getElementById('paymessage').innerHTML=paymessage;
        
        this.document.pay.delid.value=val;
        document.getElementById('delid2').innerHTML=val;

        this.document.pay.orderno.disabled=false;
        this.document.pay.usernotes.disabled=false;

}

// credit card cheking
function isCreditCard( CC )
{  
        //document.getElementById('carttotaldiv').innerHTML=CC;
if (CC.length > 19) return (false);

sum = 0; mul = 1; l = CC.length;
for (i = 0; i < l; i++)
{
digit = CC.substring(l-i-1,l-i);
tproduct = parseInt(digit ,10)*mul;
if (tproduct >= 10)
sum += (tproduct % 10) + 1;
else
sum += tproduct;
if (mul == 1)
mul++;
else
mul--;
}
if ((sum % 10) == 0)
return (true);
else
return (false);
}

function isVisa( cc )
{
if( (cc.substring(0,1) == 4) && (cc.length == 16)
|| (cc.length == 13) )
{
return isCreditCard( cc );
}
return (false);
}
function isMC( cc )
{
if( (cc.length == 16) && (cc.substring(0,2) == 51)
|| (cc.substring(0,2) == 52) || (cc.substring(0,2) == 53)
|| (cc.substring(0,2) == 54) || (cc.substring(0,2) == 55) )
{
return isCreditCard( cc );
}
return (false);
}

/*************************************************************************\
CheckCardNumber(form)
function called when users click the "check" button.
\*************************************************************************/
// cart checkout validation
function CheckCardNumber(formname,site) {
//return true;
    //var form=pay;
    var formname=formname;
    //var scott=form.proforma_cc.value;
    //document.getElementById('carttotaldiv').innerHTML=scott;
if(document.getElementById("ccradio").checked) {
    
//    alert("your dad");
    if (formname.cardname.value.length == 0) {
        alert("Please enter a Card name.");
        formname.cardname.focus();
        return false;
    }
    if (formname.cardnumber.value.length == 0) {
        alert("Please enter a Card Number.");
        formname.cardnumber.focus();
        return false;
    }
    if (formname.cardexpirey.value.length == 0) {
        alert("Please enter the Expiration Year.");
        formname.cardexpirey.focus();
        return false;
    }    
    if (formname.cardtype.value.length == 0) {
        alert("Please select a Card type.");
        formname.cardtype.focus();
        return false;
    }
    if (formname.cardcvv.value.length == 0) {
        alert("Please enter a Card CVV.");
        formname.cardcvv.focus();
        return false;
    }    
    if (formname.cardtype.value=="mastercard"){
        if (!isMC(trim(formname.cardnumber.value))) {
            alert('Mastercard number is invalid');
            return false;
        } 
    }
    if (formname.cardtype.value=="visa"){
        if (!isVisa(trim(formname.cardnumber.value))) {
            alert('VISA number is invalid');
            return false;
        }
    }
    if (!isCreditCard(trim(formname.cardnumber.value))) {
            alert('Credit card number is invalid');
            return false;
    } 
    
    if(this.document.pay.nostart.checked==false)
    {
        if (formname.cardstarty.value > formname.cardexpirey.value)
        {
            alert('Start date can not be the same or greater than expiry date');    
            return false;
        }
        
        if (formname.cardstarty.value == formname.cardexpirey.value)
        {
            if (formname.cardstartm.value >= formname.cardexpirem.value)
            {
                alert('Start date can not be the same or greater than expiry date');
                return false;    
            }
        }    
    }
    
//    if (formname.cardexpirey.value == formname.todayy.value)
//    {
//        alert ('todays year');
//        var x=formname.cardexpirem.value;
//        var y=formname.todaym.value;
        
        //if (formname.todaym.value >= formname.cardexpirem.value )
//        if (formname.todaym.value >= 2 )
//        {
//        alert ('Expiry date can not be less than todays date');
//        return false;
//        }
//    }

    if (formname.ce.value == 1){
        alert('An item in your cart is preventing completion of this order. Further information is contained at the top of this page.');
        return false;
    }
    
    if (this.document.pay.termsanconditions.checked==false && site!='modules'){
        alert('You have not checked our Terms and Conditions');
    }
    else if (site=='modules' && this.document.getElementById("ccradio").checked==false) {
            alert('Please select your payment option');
            return false;            
        }
        else {
            //alert('submit form');
            $("#loading").css("visibility","visible");  
            $("#loading").show();    
            this.document.pay.submit();    
        }

}
else{
    if (formname.ce.value == 1){
        alert('An item in your cart is preventing completion of this order. Further information is contained at the top of this page.');
        return false;
    }

    if (this.document.pay.termsanconditions.checked==false && site!='modules'){
        alert('You have not checked our Terms and Conditions');
        //alert(this.document.pay.termsanconditions.checked);
    }
    else if (site=='modules' && this.document.getElementById("proformaradio").checked==false) {
                alert('Please select your payment option');
                return false;            
        }
        else {
            //alert('submit form');    
            $("#loading").css("visibility","visible"); 
             $("#loading").show();   
            this.document.pay.submit();    
        }
    }

//    alert("your mum");
//    return true;
}


/**********************************************************************************************
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function checkemail(str) {

        var at="@"
        var dot="."
        var lat=str.indexOf(at)
        var lstr=str.length
        var ldot=str.indexOf(dot)
        if (str.indexOf(at)==-1){
           alert("Invalid Email address")
           return false
        }

        if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
           alert("Invalid Email address")
           return false
        }

        if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
            alert("Invalid Email address")
            return false
        }

         if (str.indexOf(at,(lat+1))!=-1){
            alert("Invalid Email address")
            return false
         }

         if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
            alert("Invalid Email address")
            return false
         }

         if (str.indexOf(dot,(lat+2))==-1){
            alert("Invalid Email address")
            return false
         }
        
         if (str.indexOf(" ")!=-1){
            alert("Invalid Email address")
            return false
         }

          return true                    
}

/****************************
* checking for numeric values
*/

function IsNumeric(sText)

{
   var ValidChars = "0123456789.+-() ";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}

function stationname(form)
{
     var formName=form;
     
    if(formName.business.value=='Radio Station') {
        formName.station1.disabled=false;
    }    
    else {
        formName.station1.disabled=true;
    }    
}

//oo check user details on quote request form ***********
function checkUserDetails(form)
{
    var formName=form;
    
    if (formName.firstName.value.length == 0) {
        alert("Please enter your name.");
        formName.firstName.focus();
        return false;
    }
    
    if (formName.lastName.value.length == 0) {
        alert("Please enter your last name.");
        formName.lastName.focus();
        return false;
    }    
    if ((formName.emailAdr.value==null)||(formName.emailAdr.value=="")){
        alert("Please Enter your Email address")
        formName.emailAdr.focus()
        return false
    }
    if (checkemail(formName.emailAdr.value)==false){
        formName.emailAdr.value=""
        formName.emailAdr.focus()
        return false
    }
    if (formName.addr1.value.length == 0) {
        alert("Please enter your street address.");
        formName.addr1.focus();
        return false;
    }    
    if (formName.city.value.length == 0) {
        alert("Please enter the name of your city.");
        formName.city.focus();
        return false;
    }    
    if (formName.postalcode.value.length == 0) {
        alert("Please enter your postal code.");
        formName.postalcode.focus();
        return false;
    }
    if (formName.phone.value.length == 0) {
        alert("Please enter your phone number.");
        formName.phone.focus();
        return false;
    }
    if (!IsNumeric(formName.phone.value))   {
        alert("Phone: only numeric values allowed .");
        formName.phone.focus();
        return false;
    }    
    if (!IsNumeric(formName.fax.value))   {
        alert("Fax: only numeric values allowed .");
        formName.fax.focus();
        return false;
    }    
    if (formName.countryTLD.value == '') {
        alert("Please select a country.");
        formName.countryTLD.focus();
        return false;
    }
    //alert ("submit form");
    this.document.getquote.submit();    

}

/*********************************************************
* Notify user that if no item was selected to add to cart
*/
/*function checkItem(form) {
    alert ('here');
    if (this.document.productoptions.productItem.checked==false){
        alert('Please select an item to add to your shopping cart.');
    }
    else{
        //alert('submit form');    
    //    this.document.productoptions.submit();    
    }
}*/

//oo validating that user has to select an item before adding to cart
function checkItem(numitems)
{
    c=0;
     for (x=0;x<numitems;x++)
     {
        
        el='psid'+x+'a'
        //el=productItem[x];
        if (this.document.productoptions.elements [el].checked == 1)
        {
            c++
        }
    }    
    if (c==0)
    {alert ('Please select a product option');
    return false;}
    
    else
    {this.document.productoptions.submit();}
    
}

/**********************************************************************************************
//oo get subproduct price
*/

function subprodPrice() {
    
    var sub = document.productoptions.mod_sid.value;
    //alert (sub); 
    var word=sub.split(" ");    
    var subid=word[0];
    var price=word[1]; 
    
    //document.getElementById('sid').innerHTML=val[0];
    document.getElementById('price').innerHTML=price;
    this.document.productoptions.sid.value=subid;

}

//oo product rating pop up window
var newwindow;
function poptastic(url)
{
    //newwindow=window.open(url,'comments','height=400,width=400,scrollbars=1');
     newwindow=window.open (url,"comments","scrollbars=1,width=500,height=450"); 
    if (window.focus) {newwindow.focus()}
}

function popemail(url)
{
     newwindow=window.open (url,"comments","scrollbars=1,width=500,height=250"); 
    if (window.focus) {newwindow.focus()}
}

function popquote(url)
{
     newwindow=window.open (url,"quote","scrollbars=1,width=520,height=600"); 
    if (window.focus) {newwindow.focus()}
}


//oo validating that user must select a product rating 
function valbutton(formRate) 
{
    // validate product ratings
    myOption = -1;
    for (i=formRate.rating.length-1; i > -1; i--) {
        if (formRate.rating[i].checked) {
            myOption = i; i = -1;
        }
    }
    if (myOption == -1) {
    alert("You must select a rating out of five");
    return false;
    }
    
    if (formRate.comment.value.length == 0) {
        alert("Please add your comment.");
        formRate.comment.focus();
        return false;
    }    

//alert("You selected button number " + myOption
//+ " which has a value of "
//+ formRate.rating[myOption].value);

formRate.submit(); // this line submits the form after validation
}


function gotourl(sel)
{
  window.location = sel.options[sel.options.selectedIndex].value;

}
/*
$(document).ready(function(){
  // $("#loading").slideUp();   
   
}  );
 */

function trim(stringToTrim) {

    var newString = "";
    for (j=0; j<stringToTrim.length; j++) {
        if (stringToTrim.charAt(j)!=" ") {
            newString += stringToTrim.charAt(j);
            }
    }
    stringToTrim= newString;

    return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function addprodirect(sid,pid)
{
//alert(sid);
//alert(pid);
this.document.addproform.pid.value=pid;
this.document.addproform.s_id.value=sid;
//alert(this.document.addproform.pid.value);

this.document.addproform.submit();

}

function useinvadd()
{
    if (this.document.register.invoice_address.checked == 1){
      $("#deladd1").val($("#invadd1").val());
      $("#deladd2").val($("#invadd2").val());
      $("#delcity").val($("#invcity").val());
      $("#delstate").val($("#invstate").val());
      $("#delpostcode").val($("#invpostcode").val());
      $("#deltld").val($("OPTION:selected", "#invtld").val()) ;
    }
    else{
      $("#deladd1").val('');
      $("#deladd2").val('');
      $("#delcity").val('');
      $("#delstate").val('');
      $("#delpostcode").val('');
      $("#deltld").val("SELECT A COUNTRY");
    }
      
 
}

function showNewsletterForm() {
    if ($.browser.msie && $.browser.version < 7) {
        $('html, body').animate({scrollTop:0}, 'slow'); 
    }

    if ($('#email').val() != 'Email address here') {
        $('#txtEmail').val($('#email').val());
    }
    $('#newsletter_form_surround, #newsletter_form_background').fadeIn(500);
}

function cancelNewsletterForm() {
    $('#newsletter_form_surround, #newsletter_form_background').fadeOut(500, function() {
        $('#txtEmail').val('');
    });
}

function rollDownNewsletterForm() {
    if ($('#email').val() == 'Email address here') {
        $('#email').val('');
        $('#roll_down_newsletter_form_surround').slideDown(500);
    }
}

function rollUpNewsletterForm() {
    if ($('#email').val() == '') {
        $('#email').val('Email address here');
        $('#roll_down_newsletter_form_surround').slideUp(500);
    }
}

function checkNewsletterForm() {
    var focusField = null;
    var errors = [];

    if ($('#txtEmail').val().length <= 0) {
        focusField = 'txtEmail';
        errors.push('You need to supply your email address.');
    } else if (!$('#txtEmail').val().match(/^[a-zA-Z0-9\.\'-_]+@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)+$/)) {
        if (!focusField) focusField = 'txtEmail';
        errors.push('Please check that your email address has been typed correctly.');
    }

    if ($('#txtFirstname').val().length <= 0) {
        if (!focusField) focusField = 'txtFirstname';
        errors.push('You need to supply your name.');
    }

    if ($('#txtLastname').val().length <= 0) {
        if (!focusField) focusField = 'txtLastname';
        errors.push('You need to supply your family name.');
    }

    if (focusField) {
        $('#' + focusField).focus();

        var message = 'Please correct the following errors before submitting your subscription:\n';
        for (var i = 0; i < errors.length; i++) {
            message += '\n\t-- ' + errors[i];
        }
        alert(message);

        return false;
    } else {
        return true;
    }
}

function showPageTab(tab, panel) {
    $('#' + panel + '_tabs .page-tab').removeClass('selected');
    $('#tab_' + tab).addClass('selected');
    $('#' + panel + '_tabs_panes .page-tab-pane-inner').hide();
    $('#tab_' + tab + '_pane').show();

    return false;
}

String.prototype.reverse = function() {
    return this.split("").reverse().join("");
}

String.prototype.numberFormat = function(decimals, decimalCharacter, thousandsCharacter) {
    decimals = decimals || 0;
    decimalCharacter = decimalCharacter || ".";
    thousandsCharacter = thousandsCharacter || ",";

    var integer = this.split(decimalCharacter)[0];
    var fraction = (this.split(decimalCharacter)[1] || "").slice(0, decimals);
    while (fraction.length < decimals) {
        fraction += '0';
    }

    if ("" != fraction)
        fraction = decimalCharacter + fraction;
    
    return integer.reverse().match(/(\d{1,3})/g).join(thousandsCharacter).reverse() + fraction;
}

function recalculateAddToCartTotals() {
    var newPrice = 0.0;

    if ($('input.product-option-checkbox:checked').length == 1) {
        //$('#add_to_cart_items').html($('#product_option_' + $('input.product-option-checkbox:checked').val() + '_title').html());
        $('#add_to_cart_items').html('1 option selected');
    } else if ($('input.product-option-checkbox:checked').length > 1) {
        $('#add_to_cart_items').html($('input.product-option-checkbox:checked').length + ' options selected');
    } else {
        $('#add_to_cart_items').html('Choose your option(s)');
    }
    $('input.product-option-checkbox').each(function() {
        if (this.checked) {
            newPrice += parseFloat($('#' + this.id + '_price').html().replace(/[^0-9\.]+/g, ''));
        }
    });

    $('#add_to_cart_price, #add_to_cart_price_shadow').html(newPrice.toString().numberFormat(2));

    $('#add_to_cart_box_middle').html('Calculating approximate shipping costs...');
    subIds = [];
    $('input.product-option-checkbox:checked').each(function() {
        subIds.push(this.id.replace(/[^0-9]+/g, ''));
    });
    postData = 'sub_ids=' + subIds.join(',');
    $.ajax({
        url:siteUri + '/ajax.php?mode=calculate_add_to_cart_shipping',
        data:postData,
        type:'POST',
        dataType:'json',
        success:function(data, statusCode) {
            if (!data.success) {
                $('#add_to_cart_box_middle').html(data.error);
            } else {
                $('#add_to_cart_box_middle').html('Estimated shipping from <span>' + data.symbol + data.cost.numberFormat(2) + '</span> to your location.');
            }
        },
        error:function(data, statusCode) {
            if ($('input.product-option-checkbox:checked').length == 1) {
                $('#add_to_cart_box_middle').html('Add this item to your cart to get your shipping costs.');
            } else {
                $('#add_to_cart_box_middle').html('Add these items to your cart to get your shipping costs.');
            }
        }
    });
}

function checkAddToCartForm() {
    if ($('input.product-option-checkbox:checked').length <= 0) {
        alert('You must choose at least one product option in order to add this product to your cart!');
        return false;
    } else {
        return true;
    }
}

function submitReviewForm(productId) {
    var errors = [];
    var focusField = false;

    if (!$('#comment').val().length) {
        errors.push('You must enter a comment');
        focusField = 'comment';
    }
    if ($('input[id^=rating_]:checked').length <= 0) {
        errors.push('You must choose a rating');
    }

    if (errors.length) {
        var output = 'Please correct the following errors before submitting your review:\n';
        if (focusField) {
            $('#' + focusField).focus();
        }

        for (var i = 0; i < errors.length; i++) {
            output += '\n\t--- ' + errors[i];
        }

        alert(output);
    } else {
        $.ajax({
            url:siteUri + '/ajax.php?mode=post_review',
            data:'product_id=' + escape(productId) + '&rating=' + escape(parseInt($('input[id^=rating_]:checked').val())) + '&comment=' + escape($('#comment').val()),
            dataType:'json',
            type:'POST',
            success:function(data, statusCode) {
                if (data.success) {
                    alert('Thank you for your review.');

                    document.getElementById('review_form').reset();
                } else {
                    alert('Sorry, but your review could not be added at this time.  Please try again later.');
                }
            },
            error:function(data, statusCode) {
                alert('Sorry, but your review could not be added at this time.  Please try again later.');
            }
        });
    }

    return false;
}

function submitReviewForm2(groupId) {
    var errors = [];
    var focusField = false;

    if (!$('#comment').val().length) {
        errors.push('You must enter a comment');
        focusField = 'comment';
    }
    if ($('input[id^=rating_]:checked').length <= 0) {
        errors.push('You must choose a rating');
    }

    if (errors.length) {
        var output = 'Please correct the following errors before submitting your review:\n';
        if (focusField) {
            $('#' + focusField).focus();
        }

        for (var i = 0; i < errors.length; i++) {
            output += '\n\t--- ' + errors[i];
        }

        alert(output);
    } else {
        $.ajax({
            url:siteUri + '/ajax.php?mode=post_review',
            data:'group_id=' + escape(groupId) + '&rating=' + escape(parseInt($('input[id^=rating_]:checked').val())) + '&comment=' + escape($('#comment').val()),
            dataType:'json',
            type:'POST',
            success:function(data, statusCode) {
                if (data.success) {
                    alert('Thank you for your review.');

                    document.getElementById('review_form').reset();
                } else {
                    alert('Sorry, but your review could not be added at this time.  Please try again later.');
                }
            },
            error:function(data, statusCode) {
                alert('Sorry, but your review could not be added at this time.  Please try again later.');
            }
        });
    }

    return false;
}


function show_loading(){
            $("#loading").css("visibility","visible");  
            $("#loading").show();    
            }

