$(document).ready(function(){
$('a[href^="http://"]').addClass('external').attr("target", "_blank");
$('a[href^="https://"]').addClass('external').attr("target", "_blank");
});

function openNewWindow(url) {
	window.open(url,'popup');
}

function clear_contact_form() {
	document.contact_form.form_your_name.value = "";	
	document.contact_form.form_your_email.value = "";	
	document.contact_form.form_your_message.value = "";
	document.contact_form.form_captcha.value = "";
	document.getElementById('form_your_name_marker').innerHTML = "";
	document.getElementById('form_your_email_marker').innerHTML = "";
	document.getElementById('form_your_message_marker').innerHTML = "";
	document.getElementById('form_captcha_marker').innerHTML = "";
	document.getElementById('form_your_name_error_message').innerHTML = "";
	document.getElementById('form_your_email_error_message').innerHTML = "";
	document.getElementById('form_your_message_error_message').innerHTML = "";
	document.getElementById('form_captcha_error_message').innerHTML = "";
}

function upperCase(form_id) {
	document.getElementById(form_id).value = document.getElementById(form_id).value.toUpperCase();
}

function add_to_cart(product_type,product_seo,type,id,option) {
	if (type == "cart") {
		if (document.getElementById('product_information_left_replaceable')) {
			$buy_button = document.getElementById('product_information_left_replaceable').innerHTML;
			$buy_button = $buy_button.replace(/<.*?>/g, '');
			document.getElementById('product_information_left_replaceable').innerHTML = "<div id=\"text_box_product_loader\"><!-- --></div>" + $buy_button;
		}
		if (document.getElementById('product_information_right_replaceable')) {
			$buy_button = document.getElementById('product_information_right_replaceable').innerHTML;
			$buy_button = $buy_button.replace(/<.*?>/g, '');
			document.getElementById('product_information_right_replaceable').innerHTML = "<div id=\"product_information_loader\"><!-- --></div>" + $buy_button;
		}
		if (document.getElementById('shopping_cart_replaceable_'+id)) {
			$inner_row = document.getElementById('shopping_cart_replaceable_'+id).innerHTML;
			document.getElementById('shopping_cart_replaceable_'+id).innerHTML = $inner_row + "<div class=\"shopping_cart_loader\"><!-- --></div>";
		}
	}
	if (type == "checkout") {
		replace_div_actual = "quantity_replaceable_" + id;
		document.getElementById(replace_div_actual).innerHTML = "<div class=\"shopping_cart_large_product_quantity_loader\"><!-- --></div>";
	}
	var xmlhttp=null;
	xmlhttp=getxmlhttp();
	var url = "/includes/interface/ajax/ajax_controler.php?&global_section=" + product_type + "&global_page=" + product_seo + "&id=" + option + "&global_action=ajax_buy";
	xmlhttp.open("GET", url, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			response = xmlhttp.responseText;
			if (type == "cart") {
				var replace_url = "/includes/interface/ajax/ajax_controler.php?&global_action=draw_shopping_cart&global_section=" + product_type + "&global_page=" + product_seo;
				var replace_div = "shopping_cart_replaceable";
				replace_content(replace_url, replace_div, 'flexcroll_shopping_cart');
				if (document.getElementById('product_information_left_replaceable')) { document.getElementById('product_information_left_replaceable').innerHTML = response; }
				if (document.getElementById('product_information_right_replaceable')) { document.getElementById('product_information_right_replaceable').innerHTML = response; }
			}
			if (type == "checkout") {
				var replace_url = "/includes/interface/ajax/ajax_controler.php?&global_action=draw_shopping_cart_large";
				var replace_div = "checkout_replaceable";
				replace_content(replace_url, replace_div, '');
				var replace_url = "/includes/interface/ajax/ajax_controler.php?&global_action=draw_shopping_cart_large_buttons";
				var replace_div = "buttons_replaceable";
				replace_content(replace_url, replace_div, '');
			}
		}
	}
	xmlhttp.send(null)
}

function remove_from_cart(global_section,global_page,product_type,product_seo,type,id,option) {
	if (type == "cart") {
		if (global_page == product_seo) {
			if (document.getElementById('product_information_left_replaceable')) {
				$buy_button = document.getElementById('product_information_left_replaceable').innerHTML;
				$buy_button = $buy_button.replace(/<.*?>/g, '');
				document.getElementById('product_information_left_replaceable').innerHTML = "<div id=\"text_box_product_loader\"><!-- --></div>" + $buy_button;
			}
			if (document.getElementById('product_information_right_replaceable')) {
				$buy_button = document.getElementById('product_information_right_replaceable').innerHTML;
				$buy_button = $buy_button.replace(/<.*?>/g, '');
				document.getElementById('product_information_right_replaceable').innerHTML = "<div id=\"product_information_loader\"><!-- --></div>" + $buy_button;
			}
		}
		if (document.getElementById('shopping_cart_replaceable_'+id)) {
			$inner_row = document.getElementById('shopping_cart_replaceable_'+id).innerHTML;
			document.getElementById('shopping_cart_replaceable_'+id).innerHTML = $inner_row + "<div class=\"shopping_cart_loader\"><!-- --></div>";
		}
	}
	if (type == "checkout") {
		replace_div_actual = "quantity_replaceable_" + id;
		document.getElementById(replace_div_actual).innerHTML = "<div class=\"shopping_cart_large_product_quantity_loader\"><!-- --></div>";
	}
	var xmlhttp=null;
	xmlhttp=getxmlhttp();
	var url = "/includes/interface/ajax/ajax_controler.php?&global_section=" + product_type + "&global_page=" + product_seo + "&id=" + option + "&global_action=ajax_remove";
	xmlhttp.open("GET", url, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			response = xmlhttp.responseText;
			if (type == "cart") {
				var replace_url = "/includes/interface/ajax/ajax_controler.php?&global_action=draw_shopping_cart&global_section=" + global_section + "&global_page=" + global_page;
				var replace_div = "shopping_cart_replaceable";
				replace_content(replace_url, replace_div, 'flexcroll_shopping_cart');
				if (global_page == product_seo) {
					//Only For Current Page
					if (document.getElementById('product_information_left_replaceable')) { document.getElementById('product_information_left_replaceable').innerHTML = response; }
					if (document.getElementById('product_information_right_replaceable')) { document.getElementById('product_information_right_replaceable').innerHTML = response; }
					//End
				}
			}
			if (type == "checkout") {
				var replace_url = "/includes/interface/ajax/ajax_controler.php?&global_action=draw_shopping_cart_large";
				var replace_div = "checkout_replaceable";
				replace_content(replace_url, replace_div, '');
				var replace_url = "/includes/interface/ajax/ajax_controler.php?&global_action=draw_shopping_cart_large_buttons";
				var replace_div = "buttons_replaceable";
				replace_content(replace_url, replace_div, '');
			}
		}
	}
	xmlhttp.send(null)
}

function remove_from_checkout(product_type,product_seo,id,option) {
	replace_div_actual = "bin_replaceable_" + id;
	document.getElementById(replace_div_actual).innerHTML = "<div class=\"shopping_cart_large_product_bin_loader\"><!-- --></div>";
	var xmlhttp=null;
	xmlhttp=getxmlhttp();
	var url = "/includes/interface/ajax/ajax_controler.php?&global_section=" + product_type + "&global_page=" + product_seo + "&id=" + option + "&global_action=ajax_remove_all";
	xmlhttp.open("GET", url, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			response = xmlhttp.responseText;
			var replace_url = "/includes/interface/ajax/ajax_controler.php?&global_action=draw_shopping_cart_large";
			var replace_div = "checkout_replaceable";
			replace_content(replace_url, replace_div, '');
			var replace_url = "/includes/interface/ajax/ajax_controler.php?&global_action=draw_shopping_cart_large_buttons";
			var replace_div = "buttons_replaceable";
			replace_content(replace_url, replace_div, '');
		}
	}
	xmlhttp.send(null)
}

function empty_cart() {
	document.getElementById('checkout_replaceable').innerHTML = "";
	var xmlhttp=null;
	xmlhttp=getxmlhttp();
	var url = "/includes/interface/ajax/ajax_controler.php?&global_action=ajax_empty_cart&global_section=checkout";
	xmlhttp.open("GET", url, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			response = xmlhttp.responseText;
			var replace_url = "/includes/interface/ajax/ajax_controler.php?&global_action=draw_shopping_cart_large";
			var replace_div = "checkout_replaceable";
			replace_content(replace_url, replace_div, '');
			var replace_url = "/includes/interface/ajax/ajax_controler.php?&global_action=draw_shopping_cart_large_buttons";
			var replace_div = "buttons_replaceable";
			replace_content(replace_url, replace_div, '');
		}
	}
	xmlhttp.send(null)
}

function get_reviews(global_section,global_page,global_action,id) {
	if (document.getElementById('user_reviews')) {
		$replacement = document.getElementById('user_reviews').innerHTML;
		document.getElementById('user_reviews').innerHTML = $replacement + "<div id=\"review_loader_top\"><!-- --></div><div id=\"review_loader_bot\"><!-- --></div>";	
	}
	var xmlhttp=null;
	xmlhttp=getxmlhttp();
	var url = "/includes/interface/ajax/ajax_controler.php?&global_section=" + global_section + "&global_page=" + global_page + "&global_action=" + global_action + "&id=" + id + "&internal_action=draw_reviews";
	xmlhttp.open("GET", url, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			response = xmlhttp.responseText;
			document.getElementById('user_reviews').innerHTML = response;
		}
	}
	xmlhttp.send(null)
}
