function responsOnClick(functionId, selectId, fieldId) {
	var req = null;
	if(window.XMLHttpRequest) req = new XMLHttpRequest(); 
	else if (window.ActiveXObject) req  = new ActiveXObject('Microsoft.XMLHTTP');
	
	var url = 'image.php?functionId=' + functionId + '&selectId=' + selectId;
	req.open('GET', url, false);
	req.send(null);
	if(req.status == 200) {
		var response_array = req.responseText.split("!!!<<<>>>!!!");
		var codeToInsert = response_array[0];
		var jsCode = response_array[1];
		if(fieldId) document.getElementById(fieldId).innerHTML = codeToInsert;
		eval(jsCode);
	} else {
		alert('Error, cant get folder list.');
	}
}

function actOnClick(functionId, selectId, fieldId, params) {
	var req = null;
	if(window.XMLHttpRequest) req = new XMLHttpRequest(); 
	else if (window.ActiveXObject) req  = new ActiveXObject('Microsoft.XMLHTTP');
	
	var url = 'index.php?functionId=' + functionId + '&selectId=' + selectId + params;
	req.open('GET', url, false);
	req.send(null);
	if(req.status == 200) {
		var response_array = req.responseText.split("!!!<<<>>>!!!");
		var codeToInsert = response_array[0];
		var jsCode = response_array[1];
		if(fieldId) document.getElementById(fieldId).innerHTML = codeToInsert;
		eval(jsCode);
	} else {
		alert('Error, no server respons');
	}
}

function eSolidGallery(timed) {
	if(timed) {
		var myGallery = new gallery($('myGalleryHome'), {
			showArrows: false,
			showCarousel: false,
			showInfopane: false,
			embedLinks: false,
			timed: true,
			delay: 4500,
			lightbox: 0
		});
	} else {
		var myGallery = new gallery($('myGallery'), {
				showCarousel: 1, 
				timed: false,
				lightbox: 1,
				thumbHeight: 60,
				thumbWidth: 80,
				thumbSpacing: 5,
				textShowCarousel: 'Foto`s',
				showCarouselLabel: true,
				thumbCloseCarousel: false,
				useExternalCarousel: true,
				carouselElement: $('myCarousel')
		});
	}
}

function eSolidMceInit() {
	var elmsmall = document.getElementById("mcesmall");
	var elmlarge = document.getElementById("mcelarge");
	if(!elmsmall && !elmlarge) {
		/*alert('No edit field'); */
		$('flipcontrol').style.display="none";
	} else {
		if(elmsmall) {
			tinyMCE.init({
				mode : "none",
				theme : "advanced",
				elements : "mcesmall",
				width : '235',
				content_css : "css/style_mce.css",
				plugins : "save,iwimg",
				theme_advanced_buttons1 : "save,|,bold,italic,underline,|,outdent,indent,|,iwimg,|,code",
				theme_advanced_buttons2 : "justifyleft,justifycenter,justifyright,|,bullist,numlist,|,link,unlink,|,charmap,hr",
				theme_advanced_buttons3 : "formatselect,forecolor,backcolor,|,undo,redo",
				theme_advanced_toolbar_location : "top",
				theme_advanced_toolbar_align : "left",
				save_onsavecallback : "eSolidMceSave"
			});
		} else {
			tinyMCE.init({
				mode : "none",
				theme : "advanced",
				elements : "mcelarge",
				width : '100%',
				height : '480',
				content_css : "css/style_mce.css",
				plugins : "save,iwimg",
				theme_advanced_buttons1 : "save,|,formatselect,forecolor,backcolor,|,bold,italic,underline,|,justifyleft,justifycenter,justifyright,|,outdent,indent,|,bullist,numlist,|,link,unlink,|,charmap,hr,|,iwimg,|,code,|,undo,redo",
				theme_advanced_buttons2 : "",
				theme_advanced_buttons3 : "",
				theme_advanced_toolbar_location : "top",
				theme_advanced_toolbar_align : "left",
				save_onsavecallback : "eSolidMceSave"
			});
		}
	}
}

function eSolidMceFlipControl() {
	var id = null;
	if(document.getElementById('mcesmall')) id = 'mcesmall';
	else id = 'mcelarge';
	var elm = document.getElementById(id);
	if (tinyMCE.getInstanceById(id) == null) {
		$('flipcontrol').value = 'Hide Cms';
		tinyMCE.execCommand('mceAddControl', false, id);
	} else {
		$('flipcontrol').value = 'Show Cms';
		tinyMCE.execCommand('mceRemoveControl', false, id);
	}
}
/*
function eSolidMceFlipControl() {
	var editfields = getElementsByClassName('editor', 'div');
	for(var i=0; i<editfields.length; i++) {
		var elm = document.getElementById(editfields[i]);
		if (tinyMCE.getInstanceById(editfields[i]) == null) {
			$('flipcontrol').value = 'Hide Cms';
			tinyMCE.execCommand('mceAddControl', false, editfields[i]);
		} else {
			$('flipcontrol').value = 'Show Cms';
			tinyMCE.execCommand('mceRemoveControl', false, editfields[i]);
		}
	}
}
*/

function eSolidMceGetContent() {
	var ed = null;
	if(document.getElementById('mcesmall')) ed = tinyMCE.get('mcesmall');
	else ed = tinyMCE.get('mcelarge');
	// Do you ajax call here, window.setTimeout fakes ajax call
	ed.setProgressState(1); // Show progress
	window.setTimeout(function() {
		ed.setProgressState(0); // Hide progress
	}, 1000);
	var content = ed.getContent().replace(/\+/g, "&#43");
	content = content.replace(/\\/g, "&#92");
	content = escape(content);
	return content;
}

function eSolidMceSave() {
	var req = null;
	if(window.XMLHttpRequest) req = new XMLHttpRequest(); 
	else if (window.ActiveXObject) req  = new ActiveXObject('Microsoft.XMLHTTP');

	var content = eSolidMceGetContent();
	var getUrlVars = window.location.href.slice(window.location.href.indexOf('?') + 1);
	var params = '&functionId=MceSave&content='+content+'&'+getUrlVars;
	var url = 'index.php';
	req.open('POST', url, false);
	
	//Send the proper header information along with the request
	req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	req.setRequestHeader("Content-length", params.length);
	req.setRequestHeader("Connection", "close");
	
	req.onreadystatechange = function() {	// Call a function when the state changes.
		if (req.readyState == 4) {			// only if "OK"
			if (req.status == 200) {		// ...processing statements go here...
				if(req.responseText.substring(0,5) == 'Error') alert(req.responseText);
				else $('status').innerHTML=req.responseText;
			} else {
				alert("There was a problem retrieving the XML data:\n" + req.statusText);
			}
		}
	}
	req.send(params);
}

function getUrlVars() {	// Read a page's GET URL variables and return them as an associative array.
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	for(var i = 0; i < hashes.length; i++) {
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	}
	return vars;
}

function getElementsByClassName(className, tag, elm){
	var testClass = new RegExp("(^|\\\\s)" + className + "(\\\\s|$)");
	var tag = tag || "*";
	var elm = elm || document;
	var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
	var returnElements = [];
	var current;
	var length = elements.length;
	for(var i=0; i<length; i++){
		current = elements[i];
		if(testClass.test(current.className)){
			returnElements.push(current);
		}
	}
	return returnElements;
}

function clickMenu(id) {
	var smenus = getElementsByClassName('smenu');
	for(var i=0; i<smenus.length; i++){
		smenus[i].style.display='none';
	}
	var d = document.getElementById(id);
	if (d) {d.style.display='block';}
}

function mountmenu(id) {
	for (var i = 1; i<=50; i++) {
		if (document.getElementById('smenu_top'+i)) {document.getElementById('smenu_top'+i).style.display='none';}
		if (document.getElementById('smenu_home'+i)) {document.getElementById('smenu_home'+i).style.display='none';}
		if (document.getElementById('smenu_left'+i)) {document.getElementById('smenu_left'+i).style.display='none';}
		if (document.getElementById('smenu_right'+i)) {document.getElementById('smenu_right'+i).style.display='none';}
	}
	var d = document.getElementById(id);
	if (d) {d.style.display='block';}
}

function showthegallery() {
	if($('myGallery')) $('myGallery').style.display="block";
}

function shop_article_amount(id, a_min, a_max, former) {
	var amount = document.getElementById('amount_id_'+id).value;
	var a = eval(amount);
	var amin = eval(a_min);
	var amax = eval(a_max);
	if(!amax) amax = amin;
	if (a < amin || a > amax) { 
		if(amax != amin) alert(a+' is no valid quantity! Should be between '+a_min+' and '+a_max);
		else alert(a+' is no valid quantity!');
		document.getElementById('amount_id_'+id).value=former;
		document.getElementById('amount_id_'+id).focus();
		return false;
	} else {
		document.getElementById('h_amount').value=id;
		document.getElementById('h_valid').value=true;
		return true;
	}
}

function shop_article_remove(id) {
	document.getElementById('h_remove').value=id;
	document.shoppingcard.submit();
}

function shop_article_validate() {
	if(document.getElementById('h_valid').value) return true;
	else return false;
}

function activate(id) {
	if(document.getElementById('b_conditions').checked) document.getElementById(id).disabled=false;
	else document.getElementById(id).disabled=true;
}

function purchase_delivery() {
	for (var i = 1; i<=4; i++) {
		if(document.getElementById('delivery_active').checked) {
			document.getElementById('delivery_id_'+i).style.display='';
			document.getElementById('delivery_input_'+i).style.display='none';
		} else {
			document.getElementById('delivery_id_'+i).style.display='none';
			document.getElementById('delivery_input_'+i).style.display='';
		}
	}
}
