// Functie bestand Catalogus module
var sliderWidth	=	0;
function resizeMain() {
if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    var FF='1';
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }

if(FF == '1'){var Breedte	=	450;} else {var Breedte	=	440;}
	if((myWidth-Breedte) > 500) {
		sliderWidth	=	(myWidth-Breedte);
		document.getElementById('MiddleHome').style.width=(myWidth-Breedte)+'px';
		document.getElementById('product_slider').style.width=(myWidth-60)+'px'
		document.getElementById('SliderBar').style.width=(myWidth-62)+'px'
		document.getElementById('SliderHolder').style.width=(myWidth-60)+'px'
	}
}

function changeborder(color, id){
	a = document.getElementById(id);
	a.style.borderColor = color;
	return;
}

function getItem(id){
 location.href = '/cat/front/item_info.asp' + id;
}

function getimage(afbeelding){
	a = document.getElementById('img_big');	
	if (afbeelding.substr(0,7) == 'http://') {
		a.src = afbeelding;	
	} else {
		a.src = "/cat/front/show_picture.asp?path=" + afbeelding + "&width=255&height=255&raster=5&thumb=1";
	}
	
	if (a.width > 200) a.width = 255;
	if (a.Height > 200) a.Height = 255;
}

function numbersonly(){
 if (event.keyCode < 48 || event.keyCode > 57)
  return false
}

function checkMBH(mbh, obj)
{
	if(obj.value < mbh )
	{ 
		obj.value=mbh; 
		alert('Minimale bestelhoeveel van '+ mbh + ' verplicht');
	}	
	return; 
}

function changeClass(id, klasse){
 document.getElementById(id).className = klasse;
}

function submitForm(formulier){
	document[formulier].submit();
}

/* Formulier check functies */

// Controleren van alleen getallen die ingevoerd mogen worden
function checkInteger(FormObject,melding){
	var checkOK = "0123456789";	
	var FieldFilled = true;
	for(var c=0; c <= FormObject.value.length -1; c++) {
		if (checkOK.indexOf(FormObject.value.charAt(c)) == -1) {
			FieldFilled = false;				
		}
	}
	if (FieldFilled == false){ 
		alert(melding);
		FormObject.select();
		FormObject.focus();
		return false;
	}
}


// Controleren van alleen prijzen die ingevoerd mogen worden
function checkPrice(FormObject,melding){
	var checkOK = "0123456789,";	
	var FieldFilled = true;
	for(var c=0; c <= FormObject.value.length -1; c++) {
		if (checkOK.indexOf(FormObject.value.charAt(c)) == -1) {
			FieldFilled = false;				
		}
	}
	if (FieldFilled == false){ 
		alert(melding);
		FormObject.select();
		FormObject.focus();
		return false;
	}
}

function setVerplicht(){
	td = document.getElementsByTagName('td');
	for (i = 0; i <= td.length-1; i++){
		if (td[i].id){
			if (td[i].id == 'form_verplicht'){
					td[i].className = 'form_verplicht_red';
			}
		}
	}
	
	return false;
}

function checkForm(id){
	// a = document['itmFrm' + id].aantal;
	a = document.getElementById('itmFrm' + id + '_aantal');
	if (a.value == '' || parseInt(a.value) == 0){
	 alert('U dient een geldig aantal op te geven');
	 a.focus();
	 return;
	}
	
	document['itmFrm' + id].action = '/cat/front/item_to_bag.asp';
	document['itmFrm' + id].submit();
}
/* Einde Formulier check functies */


function bagDelete(txt){
	if (confirm(txt)){
	 location.href = '/cat/front/bag_item_delete.asp?id=all';
	}
	return;
}

function bagRecalc(){
 document.frmCheck.action = '/cat/front/bag_recalc.asp';
 document.frmCheck.submit();
 return;
}

function bagStep(page){
 location.href = page;
 return;
}

function bagNextStep(page){
 // document.frmCheck.action = page;
 /* document.frmCheck.onsubmit=function(){return true;};
 if (document.frmCheck.onsubmit() == true){
	 document.frmCheck.action = page;
	 document.frmCheck.submit();
 } */
 
 
	checkReturn = false;
 	if (document.frmCheck.onsubmit) {
		checkReturn = document.frmCheck.onsubmit();
	} else {
		checkReturn = true;
	}
	if (checkReturn) {	
		document.frmCheck.action = page;
		document.frmCheck.submit();
	}
 
 
 
}

function bagSend(){
	document.getElementById('knopdiv').style.display = "none";
	document.getElementById('tekstdiv').style.display = "";
	document.frmCheck.submit();
	return;
}

function switchDiv(id){
	span = document.getElementById('div_vt_gerelateerd');
	
	if (document.getElementById(id)){
		div = document.getElementById(id);
		if (div.className == 'vt'){
			div.className = 'vt_show';
			span.innerHTML = '&ndash;';
		}
		else {
			div.className = 'vt';
			span.innerHTML = '+';
		}
	}
}

function playMedia(bestand){
	div = document.getElementById('mediaplayer');
	div.innerHTML	='<object classid="clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95"'
								+'type="application/x-oleobject" width="0" height="0"><param name="fileName" value="'+bestand+'">'
								+'<embed type="application/x-mplayer2" src="'+bestand+'" width="0" height="0"><\/embed><\/object>'
}


function changeURL(id) {
	var item = document.getElementById(id);
	if (item.value != '') {
		document.location = item.value;
	}
}

function createHttpRequest() {
  var xmlHttp = null;

  try
  {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  }
  catch (e)
  {
    // Internet Explorer 6+
    try
    {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
      //For IE 5.5 Users
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }	
  return xmlHttp;
}

var myMenu=new Array();

function loadSubMenuItems(f_groupID, f_level) {
	if(myMenu[f_groupID] != '1'){
		var httpRequest = createHttpRequest()
		var subDiv	=	document.getElementById('sub_'+f_groupID)
		//subDiv.innerHTML	=	'<img src="/images/ajax-loader.gif">';
		httpRequest.open('GET', '/cat/front/getSubMenuitems.asp?level='+f_level+'&groupID=' + f_groupID); //+'&rand='+Math.random() * 10000000000000
		httpRequest.onreadystatechange = function() {showSubMenu(httpRequest, subDiv, f_groupID); };
		httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
		httpRequest.send('');
	}
}

function showSubMenu(httpRequest, subDiv, f_groupID) {	
	if(httpRequest.readyState == 4) {
		if(httpRequest.status == 200) {
			myMenu[f_groupID] = '1';
			var node = document.createElement('div');
	    node.innerHTML = httpRequest.responseText;
	    subDiv.innerHTML	='';
	    subDiv.appendChild(node);       
			subDiv.style.display	=	'block';
		} else {
			alert('Er is een fout opgetreden. Neem contact op met de webbeheerder')
		}
	}
}