﻿	
	
	//begin browser window
	var MM = MM || {};
	(function(window, document, undef){
	
		MM.window = {
		getInnerHeight : function(){
		return (window.innerHeight)? window.innerHeight : ((document.documentElement.clientHeight)? document.documentElement.clientHeight : document.body.clientHeight);
		},
		
		getDocumentHeight : function(){
		return Math.max(document.documentElement.scrollHeight, this.getInnerHeight());
		}
	
	};
	
	})(window, document);
	//end browser window
	
//Een nieuwe class declareren
function common(){

//declaring the array that will be used for preloading images
this.pre_img = new Array();
this.debug=false;
this.current_domain='http://www.amandasauerkraut.nl';

	this.console =function(msg) {
		if(this.debug){
		document.getElementById('console').innerHTML=document.getElementById('console').innerHTML+msg+'<br>';
		}
	}
	
	this.getElementsByClassName =function(element, tag, classes) {
	var arrElements = (tag == "*" && element.all)? element.all : element.getElementsByTagName(tag);
	var arrReturnElements = new Array();
	var arrRegExpClassNames = new Array();
		if(typeof classes == "object"){
			for(var i=0; i<classes.length; i++){
			arrRegExpClassNames.push(new RegExp("(^|\\s)" + classes[i].replace(/\-/g, "\\-") + "(\\s|$)"));
			}
		}
		else{
		arrRegExpClassNames.push(new RegExp("(^|\\s)" + classes.replace(/\-/g, "\\-") + "(\\s|$)"));
		}
		var oElement;
		var bMatchesAll;
		for(var j=0; j<arrElements.length; j++){
			oElement = arrElements[j];
			bMatchesAll = true;
			for(var k=0; k<arrRegExpClassNames.length; k++){
				if(!arrRegExpClassNames[k].test(oElement.className)){
					bMatchesAll = false;
					break;
				}
			}
			if(bMatchesAll){
				arrReturnElements.push(oElement);
			}
		}
	return (arrReturnElements)
	}

	this.preload_images = function(img) {
		if(document.images){
		var preload_image_object = new Image();	
		var i = 0;
			for(i=0; i<img.length; i++) {
			//alert('preloading '+img[i]);
			preload_image_object.src = img[i];
			}
		}
	}

	//called at 'window.onload';
	this.externallinks = function() {
	 if (!document.getElementsByTagName) return;
	 var anchors = document.getElementsByTagName('a');
	 for (var i=0; i<anchors.length; i++) {
	   var anchor = anchors[i];
	   if (anchor.getAttribute('href') && anchor.getAttribute('rel') == 'external')
		 anchor.target = '_blank';
		}
	}

	this.val_by_id = function(id){		
	var value = document.getElementById(id).value;
	return value;
	}
	
	this.val_by_name = function(form, name){
	var value = document.forms[form][name].value;
	return value;
	}
	
	this.getradiovalue=function(form, name){
	var radioObj = document.forms[form][name]; 
		if(!radioObj)
		return "";
	var radioLength = radioObj.length;
		if(radioLength == undefined)
			if(radioObj.checked)
			return radioObj.value;
			else
			return "";
		for(var i = 0; i < radioLength; i++) {
			if(radioObj[i].checked) {
			return radioObj[i].value;
			}
		}
	}
	
	this.setradiovalue=function(form, name, newvalue){
	var radioObj = document.forms[form][name]; 
		if(!radioObj)
		return;
		var radioLength = radioObj.length;
		if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
		}
		for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
			if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
			}
		}
	}
		
		
	this.get_content_from_object = function(id){
		if(document.getElementById(id)){
		return document.getElementById(id).innerHTML;
		}
	}
	
	this.sent_content_to_object = function(object, content){
		if(document.getElementById(object)){
		document.getElementById(object).innerHTML=content;
		}
	}

	this.change_class = function(id, newClass) { 
		if(document.getElementById(id)){
		document.getElementById(id).className=newClass; 
		}
	}
	
	this.string_only_spaces = function(string){
		//going to the num of chars of the string
		for(c=0; c<string.length; c++){
		var current_string_char=string.substring(c,c+1);
			if(current_string_char!=" "){
			return false
			}
		}
	return true;
	}
	
	this.valid_email = function(email) {
		if (email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1){
		return true;
		}
		else{
		return false;
		}
	}

	this.enableform = function(form, enable) {	
		if(form=='*'){
			for (formIndex=0; formIndex<document.forms.length; formIndex++){
				for(x=0;x<document.forms[formIndex].length;x++){
				document.forms[formIndex].elements[x].disabled=true;
				}
			}
		}
		else{
		var el = document.forms[form].elements;
			for(var i=0;i<el.length;i++){
				if(enable==false){
				el[i].setAttribute('disabled',true);
				}
				else{
				el[i].removeAttribute('disabled');
				}
			}
		}
	}
	
	
	this.getabsy = function(id){	
		if(document.getElementById(id)){
		var ret = 0;
		div=document.getElementById(id);
			while( div != null ){
			ret += div.offsetTop;
			div = div.offsetParent;
			}
		return ret;
		}
	}
	
	this.getabsx = function(id){	
		if(document.getElementById(id)){
		var ret = 0;
		div=document.getElementById(id);
			while( div != null ){
			ret += div.offsetLeft;
			div = div.offsetParent;
			}
		return ret;
		}
	}
	
	//to ammount label
	this.num2amountlabel = function(num, lan){
	var sep='.';
		if(lan=='nl'){
		sep=',';
		}
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + num.replace(',','.') + sep + cents);
	}

			
	this.goto_url = function(form, url, send_method){
		if(send_method=='submit'){
		//defining form action
		document.forms[form].action = url;
		//submitting the form
		document.forms[form].submit();
		}
		else{
		document.location = url;
		}
	}
	
	this.open_win = function(url){
	window.open(this.ptr+url, 'new_window');
	}
	
	this.scrollbarWidth=function() {
    var div = $('<div style="width:50px;height:50px;overflow:hidden;position:absolute;border:1px solid red;"><div style="height:100px; border:1px solid green;"></div>');
    // Append our div, do our calculation and then remove it
    $('body').append(div);
    var w1 = $('div', div).innerWidth();
    div.css('overflow-y', 'scroll');
    var w2 = $('div', div).innerWidth();
    $(div).remove();
    return (w1 - w2);
	}

	
	this.centerWrapByScrol=function(){
		if((MM.window.getInnerHeight() < MM.window.getDocumentHeight())==true){
		 $("#wrap").css("marginLeft", -325+Math.floor(this.scrollbarWidth/2)+"px");
		}
		else{
		$("#wrap").css("marginLeft", -325+"px");
		}
	}
	
	this.onResizeActions = function(){
	//layout actions on page change
	this.centerWrapByScrol();
	}
	
	
	this.onload_action = function(){
	this.scrollbarWidth=this.scrollbarWidth();
	this.pre_img[this.pre_img.length]=this.ptr+'CmWare/images/website/ajaxloader.gif';
	this.externallinks();
	this.preload_images(this.pre_img);
	this.setmainmenu();
	this.onResizeActions();
	}
	

	//CUSTOMER SPECIFIC METHODS
	
	this.setmainmenu = function(){
	if(document.getElementById('m211218519-1')){
	//width of all li's together
	var w = document.getElementById('m211218519-1').offsetWidth;
	//restating space
	var res=(600-w);
	//getting num of li's
	var num_of_childs=this.val_by_id('menu211218519_lev1_childs');
	//available padding for each li
	var free=res/(num_of_childs-1);
	var paddingLeft=Math.floor(free/2);
	var paddingRight=Math.floor(free/2);
	var marginLeft=Math.floor(free/2);
	var marginRight=Math.floor(free/2);
		//applying padding
		for(l=1; l<=num_of_childs; l++){
		var extraleft=0;
		var extraright=0;
			if(l==1){
			paddingLeft=0;
			marginLeft=0;
			}
			else if(l==num_of_childs){
			paddingRight=0;
			marginRight=0;
			}
		
		$("#m211218519-1 li:nth-child("+l+") a").css({
		'paddingLeft':paddingLeft+'px',
		'paddingRight':paddingRight+'px',
		'marginLeft':marginLeft+'px',
		'marginRight':marginRight+'px'
		});
		
		}
	//scething ul to full width
	var w = document.getElementById('m211218519-1').style.width=600+'px';
	document.getElementById('m211218519-1').style.visibility='visible';
	
	
	}
}
	

}

//declating the first instance
var sw = new common();

	//declaring the 'all_labels' class
	function language_labels(){
	//emty class (only declared for creating 'label-instance')
	}

//declaring the 'label-instance' (this will be extended epending on the modules)
var label = new language_labels();


    function create_http_object(){
	var ActiveXTypes = [
		"Microsoft.XMLHTTP",
		"MSXML2.XMLHTTP.5.0",
		"MSXML2.XMLHTTP.4.0",
		"MSXML2.XMLHTTP.3.0",
		"MSXML2.XMLHTTP"
	];
	for( var i = 0; i < ActiveXTypes.length; i++ ){
		try
		{
			return new ActiveXObject( ActiveXTypes[i] );
		}
		catch( e )
		{ }
	}
	try{
		return new XMLHttpRequest();
	}
	catch( e ){ }
	return false;
    }

    function make_request(url, callback_function, http_method, post_values, return_xml){
	http = create_http_object();
        if(!http){
        alert('This browser doesnt support ajax requests.');
        return false;
        }
		http.onreadystatechange = function(){
			if(http.readyState == 4){
				if(http.status == 200){
					if(callback_function){
						if(return_xml){
						eval(callback_function + '(http.responseXML)');
						}
						else{
						eval(callback_function + '(http.responseText)');
						}
					}
				}
				else{
				alert('Error! (' + http.status + ')');
				}
			}
		}
        if(!post_values){
        post_values = null;
        }
        if(!http_method){
        http_method = "GET";
        }
        http.open(http_method, url, true);
        if(http_method == "POST"){
        http.setRequestHeader('Content-Type', 'application/x-www-form-URLencoded');
		http.setRequestHeader("Content-length", post_values.length);
		http.setRequestHeader("Accept-Charset","UTF-8");
        }
    http.send(post_values);
    }

//
window.onload = function(){
sw.onload_action();
}

window.onresize = function (){
sw.onResizeActions();
}


