/* --------------------------------------------------------------
   functions.js 2008-08-10 gambio
   Gambio OHG
   http://www.gambio.de
   Copyright (c) 2008 Gambio OHG
   --------------------------------------------------------------
   Released under the GNU General Public License
   --------------------------------------------------------------
*/

function gm_calc_prices_listing(pID){
	var gm_attr_calc= new GMAttributesCalculator(); 
	gm_calc_prices_listing.calculate_listing(pID);	
}

function gm_calc_prices(){
	var gm_attr_calc= new GMAttributesCalculator(); 
	gm_attr_calc.calculate();	
}

function gm_quantity_check_listing(pID){
	var gm_quantity_checker = new GMOrderQuantityChecker(); 
	return gm_quantity_checker.check_listing(pID);
}

function gm_quantity_check(){
	var gm_quantity_checker = new GMOrderQuantityChecker(); 
	return gm_quantity_checker.check();
}

function submit_to_wishlist() {
	document.cart_quantity.submit_target.value = "wishlist";
	document.cart_quantity.submit();
}

function submit_wishlist_to_cart() {
	var gm_quantity_checker = new GMOrderQuantityChecker(); 
	var no_error = gm_quantity_checker.check_cart();
	if(no_error){
		var no_error2 = false;
		$('.wishlist_checkbox').each(function() {  
				if( $(this).attr('checked') == true){
					no_error2 = true;
				}
			});
		if(no_error2 == false){
			alert('<?php echo GM_WISHLIST_NOTHING_CHECKED; ?>');
		}
	}
	
	if(no_error && no_error2){
		document.cart_quantity.submit_target.value = "wishlist";
		var target = document.cart_quantity.action;
		target = target.replace(/update_product/, "wishlist_to_cart");
		document.cart_quantity.action = target;
		document.cart_quantity.submit();
	}
}

function update_wishlist() {
	document.cart_quantity.submit_target.value = "wishlist";
	var target = document.cart_quantity.action;
	target = target.replace(/update_product/, "update_wishlist");
	document.cart_quantity.action = target;
	document.cart_quantity.submit();
}

function check_paypal_form(){
	var error = '';
	var check = true;
	$('.accept_box_checkbox input').each(function(){
		if($(this).attr('type') == 'checkbox'){
			if($(this).attr('checked') != true){
				if($(this).attr('name') == 'withdrawal') error = error + '<?php echo JS_ERROR_CONDITIONS_NOT_ACCEPTED_AGB; ?>';
				else if($(this).attr('name') == 'conditions') error = error + '<?php echo JS_ERROR_CONDITIONS_NOT_ACCEPTED_WITHDRAWAL; ?>';
				check = false;
			} 
		}		
	});
	
	if(error != '') alert(error);
	return check;
}

function add_opensearch(opensearch_link, message) {

	if (navigator.userAgent.match(/MSIE [7]\./) || navigator.userAgent.match(/Firefox/)) {
		window.external.AddSearchProvider(opensearch_link);
	} else {
		alert(message);
	}
}

function gm_link_box_cart(gm_cart_link, box) {
	$(box).css({"cursor":"pointer"});
	$(box).click(function() {
		document.location=gm_cart_link;	 
	});
}





