
function sendemail()
	{
		var emailfield=$('email')
		if(isEmailAddress(emailfield))
		{
		var email=$('email').value;
		var question=$('question').value;
		new Ajax.Request('../php/sendmail.php',	
				{			
				method:'post',
				parameters:{email:email,question:question,index:index},
				onComplete: function(transport)
					{
					var response = transport.responseText || "no response text";
					$('email').value='';
					$('question').value='';
					alert(response);
					},
				onFailure:function()
					{
					alert('email could not be send !');
					}
				}); 
		}
		else
		{
		}
	}

function goNext(menu)
	{
	var menus=$('menuitems').getElementsByTagName('li');
		for(i=0;i<menus.length;i++)
			{
			menus[i].style.color='black';
			}
	menu.style.color='yellow';
	$('midden').innerHTML='';
	var url=menu.id+'.php';
	var data=$('pagelanguage').innerHTML;
	if (url=='contactemail.php')
		{
		url='contact.php';
		}
	if (url=='index.php')
		{
		var languagepath='index/';
		}
	else
		{
		var languagepath=data +'/';
		} 
	url='http://www.belgiansweets.com/'+languagepath+url;
	location.href=url+"?"+encodeURIComponent(data);
	}


/* this function is called in the onload event of each page to initialize the language & show the shop if necessary */
function initialize()
	{
	/* check if data was passed through URL */
	var srchString=decodeURIComponent(location.search.substring(1,location.search.length));
	if (srchString.length > 0)
		/* data was passed through URL (language or from OGONE) */
		{
		/* extract language from url string passed */
		language=srchString;
		
		/* save language to hidden field on page */
		$('pagelanguage').innerHTML=language;

		initializelanguage(language);

		/* don't retieve shop when page is not index or when page is from OGONE*/
		if (location.href.indexOf('index')==-1 || location.href.indexOf('order')>-1 || location.href.indexOf('Order')>-1)
			{
			/* do nothing */
			}
		else
			{
			retrieveproducts();
			}
		}
	else
		{
		/* first time - no url data passed - show shop en initialize page in language of browser */
		var lang;
		if (typeof navigator.userLanguage !='undefined')
			{
			lang=navigator.userLanguage.toUpperCase();
			}
		else if (typeof navigator.language !='undefined')
			{	
			lang=navigator.language.toUpperCase();
			}
		lang=lang.substr(0,2);
		if (lang=='EN' || lang=='NL' || lang=='FR' || lang=='GE' || lang=='ES')
			{
			switch (lang)
				{
				case 'EN' :
					initializelanguage('english');
					break;
				case 'NL' :
					initializelanguage('dutch');
					break;
				case 'FR' :
					initializelanguage('french');
					break;
				case 'GE' :
					initializelanguage('german');
					break;
				case 'ES' :
					initializelanguage('spanish');
					break;
				}
			}
		else
			{
			initializelanguage('english');
			}
		/* only retrieve shop when page is not from OGONE */
		if (location.href.indexOf('order')==-1 && location.href.indexOf('Order')==-1)
			{
			retrieveproducts();
			}
		else
			{
			}
		}
	showcartsummary();
	if(holiday)
		{
		alert('Belgiansweets is closed');
		}
	}

function isNotEmpty(elem)
	{
	var str=elem.value;
	var re=/.+/;
	if (!str.match(re))
		{
		elem.style.backgroundImage='none';
		elem.style.backgroundColor="yellow";
		alert(errorlanguages[0][index]);
		return false;
		}
	else
		{
		return true;
		}
	}

function isEmailAddress(elem)
	{
	var str=elem.value;
	var re=/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
	if(!str.match(re))
		{
		elem.style.backgroundColor="yellow";
		alert(errorlanguages[1][index]);
		return false;
		}
	else
		{
		return true;
		}
	}

function scrollposition()
	{
	var verticalscroll=0;
	if (window.scrollY)
		{

		verticalscroll=window.scrollY;
		}
	else
		{
		if (document.body.scrollTop)
			{
			/* IE7 & FF */
			verticalscroll=document.body.scrollTop;
			}
		else
			{
			/* IE6 */
			verticalscroll=document.documentElement.scrollTop;
			}
		}

	return verticalscroll;
	}


/* function to select option of select where text equals certain value) */
function setselectvalue(selectobject,valuestring)
	{
        	 for(i=0;i<selectobject.length; i++)
            		{
            		if(selectobject[i].text==valuestring)
			{
              		 selectobject.selectedIndex = i;
           			 }
         		}
	}

/* function that checks if image is fully loaded or not (used in showdetail) */
function IsImageOk(img) 
	{
	// During the onload event, IE correctly identifies any images that
	// weren’t downloaded as not complete. Others should too. Gecko-based
	// browsers act like NS4 in that they report this incorrectly.
	if (!img.complete) 
		{
		return false;
		}
	// However, they do have two very useful properties:naturalWidth and
	// naturalHeight. These give the true size of the image. If it failed
	// to load, either of these should be zero.
	if (typeof img.naturalWidth != 'undefined' && img.naturalWidth== 0) 
		{
		return false;
		}
	// No other way of checking: assume it’s ok.
	return true;
	}


function grayOut(vis, options) {
  // Pass true to gray out screen, false to ungray
  // options are optional.  This is a JSON object with the following (optional) properties
  // opacity:0-100         // Lower number = less grayout higher = more of a blackout 
  // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
  // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
  // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
  // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
  // in any order.  Pass only the properties you need to set.
  var options = options || {}; 
  var zindex = options.zindex || 50;
  var opacity = options.opacity || 70;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || '#000000';
  var dark=document.getElementById('darkenScreenObject');
  if (!dark) {
    // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top='0px';                           // In the top
        tnode.style.left='0px';                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
        tnode.id='darkenScreenObject';                   // Name it so we can find it later
    tbody.appendChild(tnode);                            // Add it to the web page
    dark=document.getElementById('darkenScreenObject');  // Get the object.
  }
  if (vis) {
    // Calculate the page width and height 
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        var pageWidth = document.body.scrollWidth+'px';
        var pageHeight = document.body.scrollHeight+'px';
    } else if( document.body.offsetWidth ) {
      var pageWidth = document.body.offsetWidth+'px';
      var pageHeight = document.body.offsetHeight+'px';
    } else {
       var pageWidth='100%';
       var pageHeight='100%';
    }   
    //set the shader to cover the entire page and make it visible.
    dark.style.opacity=opaque;                      
    dark.style.MozOpacity=opaque;                   
    dark.style.filter='alpha(opacity='+opacity+')'; 
    dark.style.zIndex=zindex;        
    dark.style.backgroundColor=bgcolor;  
    dark.style.width= pageWidth;
    dark.style.height= pageHeight;
    dark.style.display='block';				 
  } else {
     dark.style.display='none';
  }
}


/* -------------------OVERBLIJVENDE LETTERS FUNKTIES--------------------------------------------*/

/**
 * DHTML textbox character counter script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

/* maxL=40; */
function taLimit(taObj,maxL) 
	{
	if (taObj.value.length==maxL) return false;
	return true;
	}

function taCount(taObj,Cnt,maxL) 
	{ 
	objCnt=createObject(Cnt);
	objVal=taObj.value;
	if (objVal.length>maxL) objVal=objVal.substring(0,maxL);
	if (objCnt) objCnt.innerText=maxL-objVal.length;
	return true;
	}

function createObject(objId) 
	{
	if (document.getElementById) return document.getElementById(objId);
	else if (document.layers) return eval("document." + objId);
	else if (document.all) return eval("document.all." + objId);
	else return eval("document." + objId);
	}

