//jQuery Spinner for up/down on quantity box

			jQuery().ready(function($) {

				$('#qty').spinner({ min: 1, max: 1000, increment: 'fast' });

			});


//Cart calculation and shipping script

		$(document).ready(function(){
			$("#addr1").css("display","none");
			$("#addr2").css("display","none");
					
			$(".shiptyp").click(function(){
				if ($('input[name=shiptyp]:checked').val() == "No" ) {
					$("#addr1").hide();	
					$("#addr2").show();
				} else {
					$("#addr1").show();	
					$("#addr2").hide(); 
				}
			 });       
			 
   function recalc(){ 
                          
			 var stypeVal = $('input[name=shiptyp]:checked').val() ;

			  var ptypeVal = $("#ptype option:selected").text();

			 //console.log(ptypeVal);

              var ptypeChrg = 0;
			  if (ptypeVal.indexOf('(') != -1) {
						ptypeChrg = parseFloat(ptypeVal.substring(ptypeVal.indexOf('(')+1, ptypeVal.indexOf(')')));         
						//console.log(ptypeChrg);
			  }

             //alert(stypeVal);

             var stypeChrg = 0;
             if(stypeVal=="No"){
			         stypeChrg  = 3.95;
			 }else{
			         stypeChrg = 0;
			 }
                //console.log(stypeChrg);
      
	       //alert(stypeChrg);


            // run the calc() method on each of the "total" fields 
            $("[id^=totalPrice]").calc( 
                // the equation to use for the calculation 
                "(ptype * qty) + ship ", 
                // we now define the values for the variables defined in the equation above 
                { 
                   
				    ptype:  ptypeChrg,
					// instead of using a static value, we use a jQuery object which grabs all the quantities 
                    qty: $("input[name=qty]").val(),
                    // now we define the jQuery object which reads in the "price" from the table cell 
            		ship:  stypeChrg
                }, 
                // this function is execute after the calculation is completed, which allows us to 
                // add formatting to our value 
                function (s){ 
                    // return the number as a dollar amount 
                    return s.toFixed(2); 
                }
            ); 
        }


//Get dropdown box options

  $("#psize").jCombo("getPaperSize.php");
  $("#ptype").jCombo("getPaperType.php?id=", { parent: "#psize" } );


//jQuery recalculate form total value	

  $('#qty').bind('change keyup',recalc ); 
  $('#ptype').bind('change keyup',recalc ); 
  $('.shiptyp').bind('click',recalc );



	jQuery.validator.addMethod("zeroValue", function(value, element) {
		var result= true;
		
		if(value == '0'){
			result= false;
		}else{
		   result= true;
		}

		return result;

	}, "");

//Custom Validation script for making default value in input field invalid
// a custom method making the default value for companyurl ("http://") invalid, without displaying the "invalid url" message
	jQuery.validator.addMethod("defaultInvalid", function(value, element) {
		return value != element.defaultValue;
	}, "");


	jQuery.validator.addMethod("deliveryCheck", function(value, element) {
		var result= true;
		
		var shiptypval = $('input[name=shiptyp]:checked').val() ;

		if(shiptypval == 'No'){
			if(value == element.defaultValue){
				result= false;
			}
		}

		return result;

	}, "");


//Validation for delivery shipping method

  $("#paperForm").validate(
  {

    	rules: {

			email:{
				minlength: 9
			},
			phone:{
				minlength: 9,
				maxlength: 15
			},
			psize:{
				required: true,
				zeroValue: true
			},
			ptype:{
				required: true,
				zeroValue: true
			},
			addr1:{
				required: true,
                deliveryCheck: true
			},
			addr2:{
				required: true,
                deliveryCheck: true
			},
			town:{
				required: true,
                deliveryCheck: true
			},
			city:{
				required: true,
                deliveryCheck: true
			},
			region:{
				required: true,
                deliveryCheck: true
			},
			postcode:{
				required: true,
                deliveryCheck: true
			}
		}

  }


  
  );
  $.metadata.setType("attr", "validate");


		});


//Custom radio button scipt

var d = document;
var safari = (navigator.userAgent.toLowerCase().indexOf('safari') != -1) ? true : false;
var gebtn = function(parEl,child) { return parEl.getElementsByTagName(child); };
onload = function() {

    var body = gebtn(d,'body')[0];
    body.className = body.className && body.className != '' ? body.className + ' has-js' : 'has-js';

    if (!d.getElementById || !d.createTextNode) return;
    var ls = gebtn(d,'label');
    for (var i = 0; i < ls.length; i++) {
        var l = ls[i];
        if (l.className.indexOf('label_') == -1) continue;
        var inp = gebtn(l,'input')[0];
        if (l.className == 'label_check') {
            l.className = (safari && inp.checked == true || inp.checked) ? 'label_check c_on' : 'label_check c_off';
            l.onclick = check_it;
        };
        if (l.className == 'label_radio') {
            l.className = (safari && inp.checked == true || inp.checked) ? 'label_radio r_on' : 'label_radio r_off';
            l.onclick = turn_radio;
        };
    };
};
var check_it = function() {
    var inp = gebtn(this,'input')[0];
    if (this.className == 'label_check c_off' || (!safari && inp.checked)) {
        this.className = 'label_check c_on';
        if (safari) inp.click();
    } else {
        this.className = 'label_check c_off';
        if (safari) inp.click();
    };
};
var turn_radio = function() {
    var inp = gebtn(this,'input')[0];
    if (this.className == 'label_radio r_off' || inp.checked) {
        var ls = gebtn(this.parentNode,'label');
        for (var i = 0; i < ls.length; i++) {
            var l = ls[i];
            if (l.className.indexOf('label_radio') == -1)  continue;
            l.className = 'label_radio r_off';
        };
        this.className = 'label_radio r_on';
        if (safari) inp.click();
    } else {
        this.className = 'label_radio r_off';
        if (safari) inp.click();
    };
};


//Custom dropdown box script

$(document).ready(function(){
	$('select.inputdrop').customStyle();
});


//Image rollover script

$('#emailhover').hover(function () {
    $(span.easyposter).css('background-image', '../images/phonero.gif');
},
function(){
    $(span.easyposter).css('background-image', '../images/easy-poster.gif');
});

$("#phonehover").hover( //mouseover id
  function () {
  $("#easyposter").addClass('email') // this function is for mouse over
  }, 
  function () {
 // this is for mouse out
  }
);
