// JavaScript Document

// js file for classic innoreative shopping cart template by innoreative

function showCart(){

	if(document.getElementById("mini_cart").style.display){

		document.getElementById("mini_cart").style.display="";

	}else{

		document.getElementById("mini_cart").style.display="none";

	}

}



function showDiv(id){

	if(document.getElementById(id).style.display){

		document.getElementById(id).style.display="";

	}else{

		document.getElementById(id).style.display="none";

	}

}

function addToMailingList() {

		   dojo.xhrPost ({

                        // The page that parses the POST request

                        url: 'functions/fnc_add_email.php?email_address='+dojo.byId('email_address').value,

               

                        // Name of the Form we want to submit

                        //form: 'login',

                

                        // Loads this function if everything went ok

                        load: function (data) {

                                // Put the data into the appropriate <div>

                                dojo.byId('mailing_list_msg').innerHTML = data;

								dojo.byId('email_address').value = "";

								

                        },

                        // Call this function if an error happened

                        error: function (error) {

                                console.error ('Error: ', error);

                        }

            });

			

}



//product page

function changeProductImage(filename){

			document.getElementById("main_product_image").src = "../product_images/"+filename;

}

		

function openImageViewer(current_image, product_id, product_name){

		current_image = document.getElementById("product_image_name").value;

			window.open("image_viewer.php?current_image="+current_image+"&product_id="+product_id+'&product_name='+product_name, 'location=0, status=0, titlebar=0');

}



//end product page



//cart page

function updateProductQty(id, product_id, cid, max_qty) {

			//alert(document.getElementById(id).value);

			product_qty = document.getElementById(id).value;

			//product_qty = parseInt(product_qty);

			if (!Number(product_qty))

				{

					alert( "Please enter a valid quantity" );

				}else{

					

					if(product_qty>0){



		            dojo.xhrPost ({

                        // The page that parses the POST request

                        url: 'update_cart.php?mode=update_qty&product_id='+product_id+'&id='+cid+'&product_qty='+product_qty+'&max_qty='+max_qty,

               

                        // Name of the Form we want to submit

                        //form: 'login',

                

                        // Loads this function if everything went ok

                        load: function (data) {

                                // Put the data into the appropriate <div>

								//document.getElementById('loader2').style.display="";

                                dojo.byId('cart_items').innerHTML = data;

								//document.getElementById('loader2').style.display="none";

								

								

                        },

                        // Call this function if an error happened

                        error: function (error) {

                                console.error ('Error: ', error);

                        }

            });

					}else{

						alert("Please enter quantity greater then zero (0)");}

				}

			

        }

		

		function deleteCartProduct(product_id, cid) {

			

			

			

		            dojo.xhrPost ({

                        // The page that parses the POST request

                        url: 'update_cart.php?mode=delete&product_id='+product_id+'&id='+cid,

               

                        // Name of the Form we want to submit

                        //form: 'login',

                

                        // Loads this function if everything went ok

                        load: function (data) {

                                // Put the data into the appropriate <div>

								//document.getElementById('loader2').style.display="";

                                dojo.byId('cart_items').innerHTML = data;

								//document.getElementById('loader2').style.display="none";

								

								

                        },

                        // Call this function if an error happened

                        error: function (error) {

                                console.error ('Error: ', error);

                        }

            });

			

        }

		

		

//end cart page



//checkout

function copyPPaddress(){

			document.getElementById("b_customer_country").value = document.getElementById("customer_country").value;

			document.getElementById("b_customer_city").value = document.getElementById("customer_city").value;

			document.getElementById("b_customer_suburb").value = document.getElementById("customer_suburb").value;

			document.getElementById("b_customer_state").value = document.getElementById("customer_state").value;

			document.getElementById("b_customer_postcode").value = document.getElementById("customer_postcode").value;

			document.getElementById("b_customer_address").value = document.getElementById("customer_address").value;

}

		

function copyPostalAddress(){

			document.getElementById("s_customer_country").value = document.getElementById("customer_country").value;

			document.getElementById("s_customer_city").value = document.getElementById("customer_city").value;

			document.getElementById("s_customer_suburb").value = document.getElementById("customer_suburb").value;

			document.getElementById("s_customer_state").value = document.getElementById("customer_state").value;

			document.getElementById("s_customer_postcode").value = document.getElementById("customer_postcode").value;

			document.getElementById("s_customer_address").value = document.getElementById("customer_address").value;

}





function selectPaymentOption(option){

	if(option=="paypal"){

		document.placeOrder.action = "paypal.php";

	}else{

		document.placeOrder.action = "receipt.php";

	}

	//alert(document.placeOrder.action);

	

}

//end check out