// Google Track Outbound Links
function recordOutboundLink(link, category) {
  action = getBaseURL(link.href);
  pageTracker._trackEvent(category, action);
}
function getBaseURL(url) {
    var baseURL = url.substring(0, url.indexOf('/', 14));
    if (baseURL.indexOf('http://localhost') != -1) {
        // Base Url for localhost
        var url = location.href;  // window.location.href;
        var pathname = location.pathname;  // window.location.pathname;
        var index1 = url.indexOf(pathname);
        var index2 = url.indexOf("/", index1 + 1);
        var baseLocalUrl = url.substr(0, index2);

        return baseLocalUrl.replace("http://", "");
    }
    else {
        // Root Url for domain name
        return baseURL.replace("http://", "");
    }
}

//Rightmouse Filter
IE4plus = (document.all) ? true : false;
NS4 = (document.layers) ? true : false;
function clickIE(){
		//return false;
}
function clickNS(e){
	if (e.which==2 || e.which==3) {
		//return false;
	}
}
if (!IE4plus) {
	document.captureEvents(Event.MOUSEDOWN || Event.MOUSEUP);
	document.onmousedown=clickNS;
	document.onmouseup= clickNS;
	document.oncontextmenu=clickIE; // For NS 6+
} else {
	document.onmouseup= clickIE;
	document.oncontextmenu=clickIE;
}

//Field clear
function doClear(theText) {
     if (theText.value == theText.defaultValue) {
         theText.value = ""
     }
}

//maten uitleg popup
function help(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=300');");
} 

//mail wachtwoord
function wachtwoord(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=150');");
} 

//show tabs
ns4 = (document.layers) ? true:false //required for Functions to work
ie4 = (document.all) ? true:false //required for Functions to work
ng5 = (document.getElementById) ? true:false //required for Functions to work

//cookies
function createCookie(name,value,days) {
  	if (days) {
  		var date = new Date();
  		date.setTime(date.getTime()+(days*24*60*60*1000));
  		var expires = "; expires="+date.toGMTString();
  	} else {
    var expires = "";
   }
 		var edomain = "; domain=.orangebag.nl";
  	document.cookie = name+"="+value+expires+edomain+"; path=/";
}

//Genereermenu using ajax
function SetmenuContent(vcount,geslacht_id,designer_id,categorie_id,kleur_id,maat_id,tijdstip,vstart) {

  var http = false;
   
  if(navigator.appName == "Microsoft Internet Explorer") {
     http = new ActiveXObject("Microsoft.XMLHTTP");
  } else {
     http = new XMLHttpRequest();
  } 

  var menudiv = 'subsearch'+vcount
  http.open("GET", '/content/includes/gen_pulldown.asp?geslacht_id='+geslacht_id+'&designer_id='+designer_id+'&categorie_id='+categorie_id+'&kleur_id='+kleur_id+'&maat_id='+maat_id+'&menu='+vcount+'&tijdstip='+tijdstip+'&start='+vstart, true);
  http.onreadystatechange=function() {
    if(http.readyState == 4) {
      if (document.getElementById(menudiv)) {
        document.getElementById(menudiv).innerHTML = http.responseText;
      }
    }
  }
  http.send(null);
}

//Start menu
function StartMenus(geslacht_id,designer_id,categorie_id,kleur_id,maat_id,skipmenu,tijdstip){
    if (skipmenu!='1'){
            SetmenuContent('1',geslacht_id,designer_id,categorie_id,kleur_id,maat_id,tijdstip,1);
    }
    if (skipmenu!='2'){
            SetmenuContent('2',geslacht_id,designer_id,categorie_id,kleur_id,maat_id,tijdstip,1);
    }
    if (skipmenu!='3'){
            SetmenuContent('3',geslacht_id,designer_id,categorie_id,kleur_id,maat_id,tijdstip,1);
    }
    if (skipmenu!='4'){
            SetmenuContent('4',geslacht_id,designer_id,categorie_id,kleur_id,maat_id,tijdstip,1);
    }
}

//Determine menu updates
function FillMenus(geslacht_id,designer_id,categorie_id,kleur_id,maat_id,skipmenu,tijdstip){
    if (skipmenu!='1'){
        if (designer_id=='0'){
            SetmenuContent('1',geslacht_id,designer_id,categorie_id,kleur_id,maat_id,tijdstip,0);
        }
    }
    if (skipmenu!='2'){
        if (categorie_id=='0'){
            SetmenuContent('2',geslacht_id,designer_id,categorie_id,kleur_id,maat_id,tijdstip,0);
        }
    }
    if (skipmenu!='3'){
        if (kleur_id=='0'){
            SetmenuContent('3',geslacht_id,designer_id,categorie_id,kleur_id,maat_id,tijdstip,0);
        }
    }
    if (skipmenu!='4'){
        if (maat_id=='0'){
            SetmenuContent('4',geslacht_id,designer_id,categorie_id,kleur_id,maat_id,tijdstip,0);
        }
    }
}

//searchmarker
function searchmarker(actief,totaal,prefix){
		document.getElementById(prefix+'_'+actief).checked=true;
		for(i=0;i<totaal;i++){	
            document.getElementById('itum_'+prefix+'_'+i).style.display ='none';
            if(i==actief){
                document.getElementById('itum_'+prefix+'_'+i).style.display ='block';
            }
        }
}

//menu
function changeStyle(itemid,classpassed){
	document.getElementById(''+itemid+'').className=classpassed;
}

//search slide
function showsearch(){
	if (document.getElementById('search').className=='menu_search_open'){
		document.getElementById('search').className='menu_search_closed';
		document.getElementById('fsearch').style.display='none';
  if (IE4plus) { document.getElementById('main_container').style.width = '1014px'; }
  else { document.getElementById('main_container').style.width = '1020px'; }
  document.getElementById('footer').style.width = '1000px';
  document.getElementById('body').style.backgroundImage = 'url(/images/body.jpg)';
	}else{
		document.getElementById('search').className='menu_search_open';
		document.getElementById('fsearch').style.display='block';
  document.getElementById('main_container').style.width = '1400px';
  document.getElementById('footer').style.width = '1400px';
  document.getElementById('body').style.backgroundImage = 'url(/images/body_s.jpg)';
	}
}

//searchaction
function searchaction(url){	
    var urlpath=url;
    //retrieve values
    for(i=0;i<document.getElementById('zoeken').geslacht.length;i++){	
           if(document.getElementById('zoeken').geslacht[i].checked == true){
                urlpath = urlpath+"/"+document.getElementById('zoeken').geslacht[i].value;
            }
    }
    if (document.getElementById('zoeken').designer){    
        if (document.getElementById('zoeken').designer.length){    
            for(i=0;i<document.getElementById('zoeken').designer.length;i++){	
                   if(document.getElementById('zoeken').designer[i].checked == true){
                        urlpath = urlpath+"/"+document.getElementById('zoeken').designer[i].value;
                    }
            }
        }else{
           if(document.getElementById('zoeken').designer.checked == true){
                urlpath = urlpath+"/"+document.getElementById('zoeken').designer.value;
            }    
        }
    }
    if (document.getElementById('zoeken').categorie){    
        if (document.getElementById('zoeken').categorie.length){    
            for(i=0;i<document.getElementById('zoeken').categorie.length;i++){	
                    if(document.getElementById('zoeken').categorie[i].checked == true){
                        urlpath = urlpath+"/"+document.getElementById('zoeken').categorie[i].value;
                    }
            }        
        }else{
            if(document.getElementById('zoeken').categorie.checked == true){
                urlpath = urlpath+"/"+document.getElementById('zoeken').categorie.value;
            }    
        }
    }
    if (document.getElementById('zoeken').maat){    
        if (document.getElementById('zoeken').maat.length){
            for(i=0;i<document.getElementById('zoeken').maat.length;i++){	
                    if(document.getElementById('zoeken').maat[i].checked == true){
                        urlpath = urlpath+"/"+document.getElementById('zoeken').maat[i].value;
                    }
            }
        }else{
            if(document.getElementById('zoeken').maat.checked == true){
                urlpath = urlpath+"/"+document.getElementById('zoeken').maat.value;
            }    
        }
    }
    if (document.getElementById('zoeken').kleur){    
        if (document.getElementById('zoeken').kleur.length){
            for(i=0;i<document.getElementById('zoeken').kleur.length;i++){	
                   if(document.getElementById('zoeken').kleur[i].checked == true){
                        urlpath = urlpath+"/"+document.getElementById('zoeken').kleur[i].value;
                    }
            }
        }else{
           if(document.getElementById('zoeken').kleur.checked == true){
                urlpath = urlpath+"/"+document.getElementById('zoeken').kleur.value;
            }    
        }
    }

 //set action    
	// document.getElementById('zoeken').action = urlpath;
	// document.getElementById('zoeken').submit();
 document.location = urlpath;
}
		
// preset the variable
function showhide(divid){
 thediv = document.getElementById(divid);
 if(thediv.style.display== 'none' ){
  thediv.style.display='block'
 }else{
  thediv.style.display='none'
 }
}

  function getMouseXY(e) {
    if (IE) {
      mouseX = event.clientX + document.body.scrollLeft;
      mouseY = event.clientY + document.body.scrollTop;
    } else {
      mouseX = e.pageX;
      mouseY = e.pageY;
    }
    if (mouseX < 0){mouseX = 0;}
    if (mouseY < 0){mouseY = 0;}  
    return true;
  }

//Genereermenu using ajax
function SetBezorgLand(bezorgland) {
  var http = false;
  if(navigator.appName == "Microsoft Internet Explorer") {
     http = new ActiveXObject("Microsoft.XMLHTTP");
  } else {
     http = new XMLHttpRequest();
  } 
  http.open("GET", '/content/includes/gen_bezorgland.asp?bezorgland='+bezorgland, true);
  http.onreadystatechange=function() {
    if(http.readyState == 4) {
      if (document.getElementById('flt_korting_12')) {
        document.getElementById('flt_korting_12').innerHTML = '-' + http.responseText;
      }

      document.getElementById('shippingcost').innerHTML = http.responseText;
      document.getElementById('inputbezorgKosten').value = http.responseText;

      var newtotaal = parseFloat(document.getElementById('totalWithoutShipping').value.replace(',','.')) + parseFloat(http.responseText.replace(',','.'));
      var kortingsc;
      if (document.getElementById('totalflt_korting_12').value != '') {
        kortingsc = parseFloat(document.getElementById('totalflt_korting_12').value.replace(',','.'));
      } else {
        kortingsc = 0;
      }
      if (kortingsc != 0) {
        newtotaal = parseFloat(newtotaal-parseFloat(http.responseText.replace(',','.')));
        newtotaal = ''+newtotaal.toFixed(2)+'';
      } else {
        newtotaal = ''+parseFloat(newtotaal)+'';
      }
      document.getElementById('display_totaal').innerHTML = newtotaal.replace('.',',');
    }
  }
  http.send(null);
}




function doCheckComma(Etje, Obj) {
  var keyCode = Etje.keyCode ? Etje.keyCode : Etje.which ? Etje.which : Etje.charCode;
  if (keyCode == 44) {
    return (Etje.keyCode = 46);
  } else {
    return true;
  }
}
function doCheckIntOnly(Etje, Obj) {
  var keyCode = Etje.keyCode ? Etje.keyCode : Etje.which ? Etje.which : Etje.charCode;
  if ((keyCode >= 46 && keyCode <= 57 && Etje.ctrlKey == false && Obj.value.length < 3) || (keyCode == 8)) {
    return true;
  } else {
    return false;
  }
}

// Alertbox:
if(document.getElementById) {
  window.alert = function(txt) {
    createCustomAlert(txt);
  }
}
function createCustomAlert(txt) {
  d = document;
  if(d.getElementById("modalContainer")) return;
  mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
  mObj.id = "modalContainer";
  mObj.style.height = document.documentElement.scrollHeight + "px";
  alertObj = mObj.appendChild(d.createElement("div"));
  alertObj.id = "alertBox";
  if(d.all && !window.opera) alertObj.style.top = document.documentElement.scrollTop + "px";
  alertObj.style.left = (d.documentElement.scrollWidth - alertObj.offsetWidth)/2 + "px";
  h1 = alertObj.appendChild(d.createElement("h1"));
  h1.appendChild(d.createTextNode(ALERT_TITLE));
  msg = alertObj.appendChild(d.createElement("p"));
  msg.innerHTML = txt;
  btn = alertObj.appendChild(d.createElement("a"));
  btn.id = "closeBtn";
  btn.appendChild(d.createTextNode(ALERT_BUTTON_TEXT));
  btn.href = "#";
  btn.onclick = function() { removeCustomAlert();return false; }
}
function removeCustomAlert() {
  document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer"));
}


// Ticker:
var Ticker = Class.create({
    initialize: function(tempHolder, tempTarget, tempSource, tempClass) {
    	this.interval = 0;	
        this.target = $(tempTarget);
		this.source = $(tempSource);
		this.className = tempClass;
    	this.titles = $$('.'+this.className+' li');
        this.options = Object.extend({
			updateRate: 4
		});
		width = 0;
		this.titles.each(function(el){
			width+= el.getWidth();
		});
    	if(width > $(tempHolder).getWidth()){
			this.start();
    	}
    },
    start: function() {
    	this.effect();
		this.interval = new PeriodicalExecuter(function() {
	    	this.effect();
		}.bind(this), this.options.updateRate);
    },
    effect: function() {
    	var options = Object.extend({
    		style: 'left: -' + this.titles[0].getWidth() + 'px',
    		duration: 2,
    		afterFinish: function(){
    			var li = new Element("li");
    			li.innerHTML = this.titles[0].innerHTML;
    			$(this.source).insert(li);
				$(this.target).setStyle('left: 0px');
				$(this.titles[0]).remove();
    			this.titles = $$('.'+this.className+' li');
	    	}.bind(this)
    	});
    	new Effect.Morph(this.target,options);
    }
});

// Zoom functie detail
var largeImageShown;
var hideInterval;
var isZoomOn = false;
var zoomInterval = 0;
var	mouseX = 0;
var	mouseY = 0;
var productImageMarginTop = 10;
var productImageMarginSides = 10;
var productImageMarginBottom = 10;
var bigWidth, smallWidth, bigHeight, bigX = 0, bigY = 0;
var	smallHeight;
var	bigBoxWidth;
var	bigBoxHeight;
var easing = 0.50;
var zoomRatio = 0.29;
var zoomWindowBoxWidth = 0;
var zoomWindowBoxHeight = 0;
function loadBig(img) {
  document.getElementById("medium-image").src = '/viewdbimg.asp?id=' + img + '&maxbreedte=273&maxhoogte=363';
  document.getElementById("zoom-image").src   = '/viewdbimg.asp?id=' + img + '&maxbreedte=1120&maxhoogte=1491';
	 smallWidth = 334;
	 smallHeight = 429;
	 bigBoxWidth = document.getElementById('zoom-box').offsetWidth;
	 bigBoxHeight = document.getElementById('zoom-box').offsetHeight;
	 bigWidth = 1119;
	 bigHeight = 1491;
 	zoomWindowBoxWidth = 85;
 	zoomWindowBoxHeight = 130;
	 document.getElementById('zoomWindowBox').style.width = zoomWindowBoxWidth + 'px';
	 document.getElementById('zoomWindowBox').style.height = zoomWindowBoxHeight + 'px';
}
function showBig() {
	 largeImageShown = true;
  clearIntrv();
  document.getElementById("zoom-box").style.display = 'block';
  document.getElementById("zoom-image").style.display = 'block';
  document.getElementById("zoomWindowBox").style.display = 'block';
  document.getElementById("detail_omschrijving").style.visibility = 'hidden';
 	zoomInterval = setInterval(animateBigImage, 10);
  isZoomOn = true;
}
function clearIntrv() {
 	clearTimeout(hideInterval);
}
function animateBigImage() {
	var xPos = mouseX;
	var yPos = mouseY;
	var	bigXPos = offsetLeft(document.getElementById("zoom-image"));
	var	bigYPos = offsetTop(document.getElementById("zoom-image"));
	var largeXOffset = offsetLeft(document.getElementById("medium-image"));
	var	largeYOffset = offsetTop(document.getElementById("medium-image"));
 var mediumImageWidth = smallWidth;
 var	mediumImageHeight = smallHeight;
    if(xPos < (largeXOffset - productImageMarginSides) ||
       xPos > (largeXOffset + mediumImageWidth + productImageMarginSides) ||
       yPos < (largeYOffset - productImageMarginTop) ||
       yPos > (largeYOffset + mediumImageHeight + productImageMarginBottom))
    {
        hideBig();
        return;
    }
	factorX = (bigWidth- bigBoxWidth)/smallWidth;
	factorY = (bigHeight-bigBoxHeight)/smallHeight;
	var targetX = 0 - (factorX * (xPos-largeXOffset - 42));
 var targetY = 0 - (factorY * (yPos-largeYOffset - 65));
	targetX = Math.round(targetX);
	targetY = Math.round(targetY);
	bigX +=  ((targetX-bigX)*easing);
	bigY +=  ((targetY-bigY)*easing);
	bigY = Math.round(bigY);
	bigX = Math.round(bigX);
	document.getElementById("zoom-image").style.left = bigX + 'px';
	document.getElementById("zoom-image").style.top = bigY + 'px';
	var bigBoxXOffset = offsetLeft(document.getElementById("zoom-box")), bigBoxYOffset = offsetTop(document.getElementById("zoom-box"));
	var zoomImageXOffset = offsetLeft(document.getElementById("zoom-image")), zoomImageYOffset = offsetTop(document.getElementById("zoom-image"));
	var windowBoxXOffset = (bigBoxXOffset - zoomImageXOffset) * zoomRatio, windowBoxYOffset = (bigBoxYOffset - zoomImageYOffset) * zoomRatio;
	windowBoxXOffset = Math.round(windowBoxXOffset);
	windowBoxYOffset = Math.round(windowBoxYOffset);
	document.getElementById('zoomWindowBox').style.left  = windowBoxXOffset + 'px';
	document.getElementById('zoomWindowBox').style.top  = windowBoxYOffset + 'px';
}
function offsetLeft(obj) {  
  var curleft = 0;
  if (obj.offsetParent) {  
    do {  
      curleft += obj.offsetLeft;  
    } while (obj = obj.offsetParent);  
  }  
  return curleft;  
}
function offsetTop(obj) {  
  var curtop = 0;
  if (obj.offsetParent) {  
    do {  
      curtop += obj.offsetTop;  
    } while (obj = obj.offsetParent);  
  }  
  return curtop;  
}
function hideBig() {
	hideInterval = setTimeout("hideDelay()", 250);
}
function hideDelay() {
	if (isZoomOn) {
  document.getElementById("zoom-box").style.display = 'none';
  document.getElementById("zoom-image").style.display = 'none';
  document.getElementById("zoomWindowBox").style.display = 'none';
  document.getElementById("detail_omschrijving").style.visibility = 'visible';
  clearInterval (zoomInterval);
  isZoomOn = false;
	}
}