// Functie bestand Catalogus module

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');
	a.src = afbeelding;
	
	if (a.width > 200) a.width = 200;
	if (a.Height > 200) a.Height = 200;
}

function numbersonly(){
 if (event.keyCode<48||event.keyCode>57)
  return false
}

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;
	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();
}

function checkFormPrive(id){
	a = document['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/objecten/prive/item_to_bag.asp';
	document['itmFrm' + id].submit();
}
/* Einde Formulier check functies */


function bagDelete(txt,f_siteREF,f_siteID){
	if (confirm(txt)){
	 location.href = '/cat/front/bag_item_delete.asp?id=all&siteREF='+f_siteREF+'&siteID='+f_siteID;
	}
	return;
}

function bagDeletePrive(txt,f_siteREF,f_siteID){
	if (confirm(txt)){
	 location.href = '/cat/front/objecten/prive/bag_item_delete.asp?id=all&siteREF='+f_siteREF+'&siteID='+f_siteID;
	}
	return;
}

function bagRecalc(f_siteREF){
 document.frmCheck.action = '/cat/front/bag_recalc.asp?siteREF='+f_siteREF;
 document.frmCheck.submit();
 return;
}

function bagRecalcPrive(f_siteREF){
 document.frmCheck.action = '/cat/front/objecten/prive/bag_recalc.asp?siteREF='+f_siteREF;
 document.frmCheck.submit();
 return;
}

function bagStep(page){
 location.href = page;
 return;
}

function bagNextStep(page){
 //document.frmCheck.action = page;
 if (document.frmCheck.onsubmit() == true){
	 document.frmCheck.action = page;
	 document.frmCheck.submit();
 }
}

function bagSend(){
	document.frmCheck.submit();
	return;
}

function capsError( capsEngaged ) {
	if( capsEngaged ) {
		document.getElementById('caps_error').style.visibility = 'visible';
	} else {
		document.getElementById('caps_error').style.visibility = 'hidden';
	}
}

function capsDetect( e ) {
	if( !e ) { e = window.event; } if( !e ) { MWJ_say_Caps( false ); return; }
	var theKey = e.which ? e.which : ( e.keyCode ? e.keyCode : ( e.charCode ? e.charCode : 0 ) );
	var theShift = e.shiftKey || ( e.modifiers && ( e.modifiers & 4 ) );
	MWJ_say_Caps( ( theKey > 64 && theKey < 91 && !theShift ) || ( theKey > 96 && theKey < 123 && theShift ) );
}

function MWJ_say_Caps( oC ) {
	if( typeof( capsError ) == 'string' ) { if( oC ) { alert( capsError ); } } else { capsError( oC ); }
}

function getActiveClass(id,mode){
	if (mode == 'show') {
		document.getElementById('menu_left'+id+'1').className='left_menu_item_mouseover';
		document.getElementById('menu_center'+id+'2').className='center_menu_item_mouseover';
		document.getElementById('menu_right'+id+'3').className='right_menu_item_mouseover';
	} else {
		document.getElementById('menu_left'+id+'1').className='left_menu_item';
		document.getElementById('menu_center'+id+'2').className='center_menu_item';
		document.getElementById('menu_right'+id+'3').className='right_menu_item';							
	}	
	if (mode == 'opvallend_show') {
		document.getElementById('menu_left'+id+'1').className='opvallend_left_menu_item_mouseover';
		document.getElementById('menu_center'+id+'2').className='opvallend_center_menu_item_mouseover';
		document.getElementById('menu_right'+id+'3').className='opvallend_right_menu_item_mouseover';
	}
	
}

function validateEmail(field, msg)
{
	if (field.value != '')
	{
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(field.value))
		{
			return true;
		}
		alert(msg);
		field.focus();
		field.select();
		return false;
	}
	return true;
}


function validateNotEmpty(field, msg)
{
if(trimAll(field.value).length > 0)
	{
  return true;
  }  
  alert(msg);
  field.focus();
  return false;
}

function trimAll(strValue)
{
var objRegExp = /^(\s*)$/;

//check for all spaces
if(objRegExp.test(strValue)) {
	strValue = strValue.replace(objRegExp, '');
  if( strValue.length == 0)
  	return strValue;
	}

	//check for leading & trailing spaces
	objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
	if(objRegExp.test(strValue)) {
	//remove leading and trailing whitespace characters
  strValue = strValue.replace(objRegExp, '$2');
  }
return strValue;
}
