
function printDiv()
{
  var printer = window.open('','','width=400,height=400');
	printer.document.open("text/html");
	printer.document.write(document.getElementById('reciept').innerHTML);
	//printer.document.close();
	//printer.window.close();
	printer.print();
	//alert("Printing the reciept...");
}


$(document).ready(function(){

		jQuery('input.checkout_input_digit').autotab();

		//Hide div w/id extra
		/*
	   <?
	   if(empty($_GET)) echo '$("#errmsg").css("display","none");';
	   ?>

        <?
        //if (!isset($_GET['payment']) || !($_GET['payment'] == "visa" || $_GET['payment'] == "mastercard"))
            //echo '$("#cc_details").css("display","none");';
        ?>
        */
        //if (document.getElementsByName('payment') == '')   $("#errmsg").css("display","none");
        if (jQuery.trim($("#errmsg").html()) == "")   $("#errmsg").css("display","none");
		var rad_val = $('input[name=payment]:checked').val();
        //if (document.getElementsByName('payment') == '' || ! (rad_val == "visa" || rad_val == "mastercard")) $("#cc_details").css("display","none");
        if ( ! (rad_val == "visa" || rad_val == "mastercard")) $("#cc_details").css("display","none");

    $(".radioP").click(function() {
		if($(this).val()=="visa" ||$(this).val()=="mastercard"){
			$("#cc_details").slideDown("slow");
		}
		else{
			$("#cc_details").slideUp("slow");
		}
	});

	$("form").submit(function() {
        return;
		var err="";
		$("#errmsg").html("");

		var obj= {first_name: "First Name", last_name: "Last Name", street_address: "Street Address", countries: "Countries", province_state: "Province/State", city: "City", postal_zip_code: "Postal/Zip Code"};
		$.each(obj, function(i, n){
			if($("#" + i).val()==""){
				if(err!="") err = err + " is required<br />";
				err = err + n;
			}
		});
		$('#payment_table').each(function(){
		     //make sure at least one radio is checked
		     //do not use @ symbol if using jQuery 1.1.4, it's deprecated
		     if (! $('input:radio:checked',this).length > 0){
		             err = err + " - Select Payment Option<br />";
		     }
		});
		$.post("check_email.php", { email: $('#email').val()}, function(response, v){
			//$('#emailResult').fadeOut();
			//setTimeout("finishAjax('emailResult', '"+escape(response)+"')", 200);
			if(response != "Correct Email"){
				$("#errmsg").css("display","block");
				$("#errmsg").append(response);
			}

		});

		if(err!=""){
			$("#errmsg").css("display","block");
			$("#errmsg").css("text-align","center");
			$("#errmsg").append(err);
			return false;
		}


	    });

		// Add onclick handler to checkbox w/id checkme
	   $(".check").change(function(){

			// If checked
			/*if ($(this).is(":checked")){
				//alert($(this).val());
				var pid = $(this).name();
				var val = $(this).val();
				$("#total").load("price_cal.php", {pid: pid, act: "add"});


			}
			else{*/
				//alert($(this).attr('name'));
                var val = $(this).val();
				var pid = $(this).attr('name');
				$("#total").load("price_cal.php", {pid: pid, val: val});
			//}
	  });
    //called when key is pressed in textbox
    	$(".checkout_input_text").keypress(function (e){
		  //if the letter is not digit then display error and don't type anything
		  if( (e.which<65 || (e.which>90 && e.which<97) || e.which>122) && e.which!=8 && e.which!=0){
			//display error message
			$("#errmsg").css("display","block");
			$("#errmsg").html("Letters Only").show().fadeOut("slow");
		    return false;
		  }
		});

		$(".checkout_input_digit").keypress(function (e){
			//alert(e.which);
		  //if the letter is not digit then display error and don't type anything
		  if( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57)){

			//display error message
			$("#errmsg").css("display","block");
			$("#errmsg").html("Digits Only").show().fadeOut("slow");
		    return false;
		  }
		});
		$(".checkout_input_card").keypress(function (e){

		  //if the letter is not digit then display error and don't type anything
		  if( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57))
		  {
			//display error message
			$("#errmsg").html("Digits Only").show().fadeOut("slow");
		    return false;
		  }
		});
		////////////////////////////////////////////////////////////countries
		$("#countries").change(function () {

			var country_id=$(this).val();
			if(country_id==38 || country_id==226 ){
				//alert($(this).val());
				$("#state").load("view_states.php", {country_id: country_id});
			}
		////////////////////////////////////////////////////////////check email


		});
			$('#emailLoading').hide();

			$('#email').blur(function(){
				$('#emailLoading').show();
				$.post("check_email.php", {
					email: $('#email').val()
					}, function(response){
					$('#emailResult').fadeOut();
					setTimeout("finishAjax('emailResult', '"+escape(response)+"')", 200);
				});
				return false;
			});
		});

		function finishAjax(id, response) {
			$('#emailLoading').hide();
			$('#'+id).html(unescape(response));
			$('#'+id).fadeIn();
		} //finishAjax

