
$(document).ready(function() {
    $("#theStory").fancybox({
            'width'			: '75%',
            'height'			: '75%',
            'transitionIn'		: 'fade',
            'transitionOut'		: 'fade',
            'type'			: 'iframe'
    });
    $("#theBikes").fancybox({
            'width'			: '75%',
            'height'			: '75%',
            'transitionIn'		: 'fade',
            'transitionOut'		: 'fade',
            'type'			: 'iframe'
    });
    $("#theWorkshop").fancybox({
           'width'			: '75%',
            'height'			: '75%',
            'transitionIn'		: 'fade',
            'transitionOut'		: 'fade',
            'type'			: 'iframe'
    });
    $("#theTeam").fancybox({
            'width'			: '75%',
            'height'			: '75%',
            'transitionIn'		: 'fade',
            'transitionOut'		: 'fade',
            'type'			: 'iframe'
    });

    $("#terms").fancybox({
            'width'			: '75%',
            'height'			: '75%',
            'transitionIn'		: 'fade',
            'transitionOut'		: 'fade',
            'type'			: 'iframe'
    });



});



var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-3367778-15']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

function popUp(URL, WIDTH, HEIGHT) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width='+WIDTH+',height='+HEIGHT+',left = 490,top = 234');");
}

function rowOverEffect(object) {
  if (object.className == 'moduleRow') object.className = 'moduleRowOver';
}

function rowOutEffect(object) {
  if (object.className == 'moduleRowOver') object.className = 'moduleRow';
}

function checkBox(object) {
  document.account_newsletter.elements[object].checked = !document.account_newsletter.elements[object].checked;
}

function check_form() {
    var error_message = "<?php echo JS_ERROR; ?>";
    var error_found = false;
    var error_field;
    var keywords = document.advanced_search.keywords.value;
    var dfrom = document.advanced_search.dfrom.value;
    var dto = document.advanced_search.dto.value;
    var pfrom = document.advanced_search.pfrom.value;
    var pto = document.advanced_search.pto.value;
    var pfrom_float;
    var pto_float;

    if ( ((keywords == '') || (keywords.length < 1)) && ((dfrom == '') || (dfrom == '<?php echo DOB_FORMAT_STRING; ?>') || (dfrom.length < 1)) && ((dto == '') || (dto == '<?php echo DOB_FORMAT_STRING; ?>') || (dto.length < 1)) && ((pfrom == '') || (pfrom.length < 1)) && ((pto == '') || (pto.length < 1)) ) {
        error_message = error_message + "* <?php echo ERROR_AT_LEAST_ONE_INPUT; ?>\n";
        error_field = document.advanced_search.keywords;
        error_found = true;
    }

    if ((dfrom.length > 0) && (dfrom != '<?php echo DOB_FORMAT_STRING; ?>')) {
        if (!IsValidDate(dfrom, '<?php echo DOB_FORMAT_STRING; ?>')) {
            error_message = error_message + "* <?php echo ERROR_INVALID_FROM_DATE; ?>\n";
            error_field = document.advanced_search.dfrom;
            error_found = true;
        }
    }

    if ((dto.length > 0) && (dto != '<?php echo DOB_FORMAT_STRING; ?>')) {
        if (!IsValidDate(dto, '<?php echo DOB_FORMAT_STRING; ?>')) {
            error_message = error_message + "* <?php echo ERROR_INVALID_TO_DATE; ?>\n";
            error_field = document.advanced_search.dto;
            error_found = true;
        }
    }

    if ((dfrom.length > 0) && (dfrom != '<?php echo DOB_FORMAT_STRING; ?>') && (IsValidDate(dfrom, '<?php echo DOB_FORMAT_STRING; ?>')) && (dto.length > 0) && (dto != '<?php echo DOB_FORMAT_STRING; ?>') && (IsValidDate(dto, '<?php echo DOB_FORMAT_STRING; ?>'))) {
        if (!CheckDateRange(document.advanced_search.dfrom, document.advanced_search.dto)) {
            error_message = error_message + "* <?php echo ERROR_TO_DATE_LESS_THAN_FROM_DATE; ?>\n";
            error_field = document.advanced_search.dto;
            error_found = true;
        }
    }

    if (pfrom.length > 0) {
        pfrom_float = parseFloat(pfrom);
        if (isNaN(pfrom_float)) {
            error_message = error_message + "* <?php echo ERROR_PRICE_FROM_MUST_BE_NUM; ?>\n";
            error_field = document.advanced_search.pfrom;
            error_found = true;
        }
    } else {
        pfrom_float = 0;
    }

    if (pto.length > 0) {
        pto_float = parseFloat(pto);
        if (isNaN(pto_float)) {
            error_message = error_message + "* <?php echo ERROR_PRICE_TO_MUST_BE_NUM; ?>\n";
            error_field = document.advanced_search.pto;
            error_found = true;
        }
    } else {
        pto_float = 0;
    }

    if ( (pfrom.length > 0) && (pto.length > 0) ) {
        if ( (!isNaN(pfrom_float)) && (!isNaN(pto_float)) && (pto_float < pfrom_float) ) {
            error_message = error_message + "* <?php echo ERROR_PRICE_TO_LESS_THAN_PRICE_FROM; ?>\n";
            error_field = document.advanced_search.pto;
            error_found = true;
        }
    }

    if (error_found == true) {
        alert(error_message);
        error_field.focus();
        return false;
    } else {
        RemoveFormatString(document.advanced_search.dfrom, "<?php echo DOB_FORMAT_STRING; ?>");
        RemoveFormatString(document.advanced_search.dto, "<?php echo DOB_FORMAT_STRING; ?>");
        return true;
    }
}

function popupWindow(url) {
    window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=450,height=280,screenX=150,screenY=150,top=150,left=150')
}

var selected;

function selectRowEffect(object, buttonSelect) {
  if (!selected) {
    if (document.getElementById) {
      selected = document.getElementById('defaultSelected');
    } else {
      selected = document.all['defaultSelected'];
    }
  }

  if (selected) selected.className = 'moduleRow';
  object.className = 'moduleRowSelected';
  selected = object;

// one button is not an array
  if (document.checkout_payment.payment[0]) {
    document.checkout_payment.payment[buttonSelect].checked=true;
  } else {
    document.checkout_payment.payment.checked=true;
  }
}

function check_form_optional(form_name) {
  var form = form_name;

  var firstname = form.elements['firstname'].value;
  var lastname = form.elements['lastname'].value;
  var street_address = form.elements['street_address'].value;

  if (firstname == '' && lastname == '' && street_address == '') {
    return true;
  } else {
    return check_form(form_name);
  }
}

function session_win() {
  window.open("<?php echo tep_href_link(FILENAME_INFO_SHOPPING_CART);?>","info_shopping_cart","height=460,width=430,toolbar=no,statusbar=no,scrollbars=yes").focus();
}
