///Original Code Created Posted In The Ecwid Forum By Eugene

//Adapted by Andrew Leonard of EcwidMadeEasy.com to show the terms and conditions checkbox in the SHopping Cart

// On line 48 below YOU MUST REPLACE ************** with the url that contains your terms and conditions.


// Bind a change handler to the window location.
$j( window.location ).bind(
      "change",
      function(objEvent, objData){
	var page = {};
              hash = objData.currentHash.slice(6);  //trim the ecwid and the COLON leading.
  	      page.mode = getPageType(hash);
              page.category = getCategory(hash);
	      page.product = getProduct(hash);
	      runMods(page);  //If the window's changed, run the mods.
      	}
);

function runMods(page) {
	   //Call anything you want on every page here.
 	   functionComplete = false;  //They all retrun true if successful. false if not.
           if (window.t1 !== undefined) { clearInterval(t1); }

	   t1 = setInterval (function() {
              switch(page.mode) {
//	        case "checkoutPO":					//Original code for it to work after the checkout button is selected (eg if phone ordering has been selected) 					
		case "cart":    					// Change made by EcwidMadeEasy.com for it to work in Shopping Cart - decides which page it is displayed on
		      functionComplete = process_placeorder_button();
		      break;
      		default:
		//Nothing to do!
		functionComplete = true;
	      }
	      
	      if (functionComplete) { clearInterval(t1); }
          }, 100);
}

function process_placeorder_button() {
//var button = $j('div.ecwid-Checkout-placeOrderButton');		//Original code for it to work after the checkout button is selected (eg if phone ordering has been selected) 
var button = $j('div.ecwid-productBrowser-cart-checkoutButton'); 	// Change made by EcwidMadeEasy.com for it to work in Shopping Cart
var terms_checkbox = $j('input#ecwid_terms_checkbox');

if (button.length) {
if (!terms_checkbox.length) {
button.after('<br /><div style="width:168px;"><input type="checkbox" id="ecwid_terms_checkbox" onclick="ecwid_checkbox();">&nbsp;<label for="ecwid_terms_checkbox">Ich habe die <a href="http://www.carolinegrosskopf.de/agb.html" target="new">AGB</a>, die <a href="http://www.carolinegrosskopf.de/widerrufsbelehrung.html" target="new">Widerufsbelehrung</a> und die <a href="http://www.carolinegrosskopf.de/datenschutz.html" target="new">Datenschutzerklärung</a> gelesen und aktzeptiere diese. <br />( Der Bezahlvorgang wird fortgesetzt, sobald Sie allen Punkten zugestimmt haben. )</label></div>');
return false;
}
if ($j('#ecwid_terms_checkbox').attr('checked')) {
button.show();
return true;
} else {
button.hide();
return true;
}

} else {
return false;
}
      return false;
}

function ecwid_checkbox() {

//var button = $j('div.ecwid-Checkout-placeOrderButton'); //Original code for it to work after the checkout button is selected (eg phone ordering has been selected) 

var button = $j('div.ecwid-productBrowser-cart-checkoutButton');  // Change made by EcwidMadeEasy.com for it to work in Shopping Cart
if (button.length) {
if ($j('#ecwid_terms_checkbox').attr('checked')) {
button.show();
} else {
button.hide();
}

} else {
return false;
}
      return true;
}

$j(document).ready(function() {
           t2 = setInterval (function() {
          process_placeorder_button();
      }, 50);
});

