/* --- Regular expressions --- */
var telRegExp = /([0-9-]+){11}|([0-9]+){10}/; 
var timeRegExp = /^(\d{1,2}):(\d{2})$/;
var emailRegExp = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.([a-zA-Z]){2,4})$/;
var postcodeRegExp = /^([0-9]){4}([a-zA-Z]){2}$/;

/* --- Functions --- */
function confirm_goto(question, url) {
	var cbox = confirm(question);
	if(cbox == true) {
		window.location = url;
	}
}

function check_contact() {
	error = "";
	
	if($("#name").val() == ""){
		error += "- Geen naam ingevuld<br />";
	}
	if($("#email").val() == ""){
		error += "- Geen e-mail adres ingevuld<br />";
	} else if(!emailRegExp.test($("#email").val())){
		error += "- Onjuist e-mail adres ingevuld<br />";
	}
	/*if($("#phone").val() == ""){
		error += "- Geen telefoonnummer ingevuld<br />";
	}*/
	if($("#question").val() == ""){
		error += "- Geen vraag/opmerking ingevuld<br />";
	}
	
	if(error != ""){
		$("#contact_error").show();
		$("#contact_error_errors").html(error);
	} else {
		$("#form_contact").submit();
	}
}

/* --- Webshop functions --- */
shop_ajax = new AjaxHandler('shop');

function fill_cart_top(){
	fill_cart_top_items();
}
function fill_cart_top_price(){
	shop_ajax.setParser('cart');
	shop_ajax.setVar('cart_action','get_total');
	shop_ajax.setCallback('callback_fill_cart_top_price');
	shop_ajax.sendRequest();
}
function fill_cart_top_items(){
	shop_ajax.setParser('cart');
	// shop_ajax.setVar('cart_action','total_items');
	shop_ajax.setVar('cart_action','total_items_with_word');
	shop_ajax.setCallback('callback_fill_cart_top_items');
	shop_ajax.sendRequest();
}

function callback_fill_cart_top_price(content, type){
	document.getElementById('cart_price').innerHTML = content;
}
function callback_fill_cart_top_items(content, type){
	document.getElementById('cart_items').innerHTML = content;
	fill_cart_top_price();
}

function add_to_cart(cart_variant, cart_qty, callback_function) {
	
	shop_ajax.setParser('cart');
	shop_ajax.setVar('cart_action','add');
	shop_ajax.setVar('cart_variant', cart_variant);
	shop_ajax.setVar('cart_qty', cart_qty);
	if(callback_function != ""){
		shop_ajax.setCallback(callback_function);
	}
	shop_ajax.sendRequest();
}

function logout(){

	shop_ajax.setParser('customer');
	shop_ajax.setVar('customer_action','logout');
	shop_ajax.setCallback('callback_logout');
	shop_ajax.sendRequest();
}
function callback_logout(content, type){
	window.location.reload();
	/*document.getElementById('logged_in_as').innerHTML = "";
	$('#logged_in').removeClass("active");*/
}

/* --- Jquery --- */
$(document).ready(function() {
	$("#lookbook_slider_inner").easySlider({
		controlsShow:		true,
		numeric:			true
	});
});

/* --- Google maps --- */
function initialize() { 
	if (GBrowserIsCompatible()) { 
		
		var gm_icon = new GIcon(G_DEFAULT_ICON); 
		gm_icon.image = "http://www.jorisenjuul.nl/images/gm_icon.png"; 
		gm_icon.iconSize = new GSize(75, 26); 
		gm_icon.shadow = "";
		
		markerOptions = { icon:gm_icon }; 
	
		if(document.getElementById("contact_address_1_gm")){
			var map = new GMap2(document.getElementById("contact_address_1_gm")); 
			var point = new GLatLng(51.994141, 4.476597);
			map.setCenter(point, 13); 
			map.addOverlay(new GMarker(point, markerOptions)); 
			map.setUIToDefault(); 
		}
		
		if(document.getElementById("contact_address_2_gm")){
			var map2 = new GMap2(document.getElementById("contact_address_2_gm")); 
			var point2 = new GLatLng(51.957943, 4.494521);
			map2.setCenter(point2, 13); 
			map2.addOverlay(new GMarker(point2, markerOptions)); 
			map2.setUIToDefault();
		}
	} 
} 

/* --- Cufon --- */

// webshop
Cufon.replace('#webshop_header_bottom>h2', { fontFamily: 'Courier New' });
Cufon.replace('#product_info_top>h2', { fontFamily: 'Courier New' });
Cufon.replace('#product_info_top>#product_price', { fontFamily: 'Courier New' });
//Cufon.replace('#product_info_top>#old_product_price', { fontFamily: 'Courier New' });

// text template
Cufon.replace('#text_title>h2', { fontFamily: 'Courier New' });
