var check_req;
function check_Initialize(){
	try{
		check_req=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e){
		try{
			check_req=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc){
			check_req=null;
		}
	}
	if(!check_req&&typeof XMLHttpRequest!="undefined"){
		check_req= new XMLHttpRequest();
	}
}

function showMenu(){
     if(this.childNodes[1].style.display=="none") {
          this.childNodes[1].style.display="";
          this.childNodes[1].style.visibility="visible";
     }
     else {
          this.childNodes[1].style.display="none";
          this.childNodes[1].style.visibility="hidden";          
     }
}
// variable for the image object we are throwing around
var objId = '';
//change the opacity for different browsers
function changeOpac(opacity, id) {
    var notObject = id;
    if(typeof(notObject) != "object") 
         notObject = document.getElementById(id);
    if(typeof(notObject) != "undefined"){
         notObject.style.opacity = (opacity / 100);
         notObject.style.MozOpacity = (opacity / 100);
         notObject.style.KhtmlOpacity = (opacity / 100);
         notObject.style.filter = "alpha(opacity=" + opacity + ")";
    }
} 

// pretty fade in and out
function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;
    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
             if(typeof(id) == "object"){
                  objId = id;
                  setTimeout("changeOpac(" + i + ", objId );",(timer * speed));
             }
             else
                  setTimeout("changeOpac(" + i + ",'" + id + "');",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++){
             if(typeof(id) == "object"){ 
                  objId = id;
                  setTimeout("changeOpac(" + i + ", objId );",(timer * speed));
             }
             else
                  setTimeout("changeOpac(" + i + ",'" + id + "');",(timer * speed));
            timer++;
        }
    }
}

 

function addThirdImage(node) {
     var imgWidth = node.width;
     var imgHeight = node.height;
     if(imgHeight == 0 || imgWidth == 0){
          imgHeight = node.scrollHeight;
          imgWidth = node.scrollWidth;
     }
     if(imgHeight > 0 && imgWidth > 0){
          var ratio = imgHeight/imgWidth;
          if((ratio*280) > 185){ // check if the image is too high
               node.height = 185;
               node.width = ((1/ratio)*185);
          } else {
               node.width = 280;
               node.height = (280*ratio);
          }
     }
     
     changeOpac("0",node);
     node.style.display = "";
     opacity(node,0,100,1500);
} 
               

/**
* function removeChildren()
*
*/

function removeChildren(id, type){
	
	var addClassFlag = false; // if we need to add a class list, set to true
	var children = document.getElementById("choose"+type).childNodes;
	for(node in children){
		// also need to remove choosetype && choosemlg
		if(children[node].tagName != "UL" && addClassFlag == false)
			addClassFlag = true;
		if((children[node].tagName == "UL") && (children[node].attributes['id'] != (type+id))){ 
			addClassFlag = true;
			document.getElementById("choose"+type).removeChild(children[node]);
		}
	}
	return addClassFlag;
}

/**
* function getElementsByClassName(classname, node)
* 
* returns an array of all elements with classname and belonging to node.
* if node is not specified, node = body
*/

function getElementsByClassName(classname, node) {
   if(!node) node = document.getElementsByTagName("body")[0];
   var a = [];
   var re = new RegExp('\\b' + classname + '\\b');
   var els = node.getElementsByTagName("*");
   for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))
        a.push(els[i]);
   return a;
}



function updateSelection(id, type, baseurl){
     
     // get the correct items from the event listeners
     var node = document.getElementById(type+id);
     if(type == 'type'){
		if(typeof(chosenType) != "undefined" && chosenType != id && chosenType != ''){
               if(null != document.getElementById("type"+chosenType)){
                    document.getElementById("type"+chosenType).style.backgroundColor = "transparent";
               }
          }
          
          chosenType = id;
          node.className = node.className + " selecteditem";
          node.parentNode.parentNode.firstChild.childNodes[1].innerHTML = "Geselecteerd: " + node.innerHTML; // set button innerhtml
          var typeDiv = document.getElementById('choosetype').firstChild;
          typeDiv.className = typeDiv.className + " selected";
          
          var mlgDiv = document.getElementById("choosemlg");
          mlgDiv.firstChild.childNodes[1].innerHTML = "KIES HET AANTAL KILOMETERS"; // reset mlg button inner html
          
          var choice = document.getElementById("yourchoice");
          var removeFlag = true;
          if(choice.hasChildNodes()){
               for(choices in choice.childNodes){
                    if(typeof(choice.childNodes[choices]) != "undefined"){
                         if(choice.childNodes[choices].id == "selecteer_uw_shortlease")
                              removeFlag = false
                   }
               }
               if(removeFlag){
               while(choice.hasChildNodes()){
                    choice.removeChild(choice.firstChild);
               }
                    var br = document.createElement("br");
                    var newH2 = document.createElement("h2");
                    newH2.innerHTML = "Uw shortlease in 3 stappen";
                    choice.appendChild(br);
                    choice.appendChild(newH2);
                    var br2 = document.createElement("br");
                    choice.appendChild(br2);
                    var newImage = new Image();
                    newImage.id = "selecteer_uw_shortlease";
                    choice.appendChild(newImage);
                    newImage.onload = new Function("opacity('selecteer_uw_shortlease',0,100,1500)"); 
                    newImage.src = baseurl + "/templates/alg/images/selecteer_uw_shortlease.jpg";
                    newImage.alt = "Uw shortlease in 3 stappen";
                    
                    changeOpac(0, "selecteer_uw_shortlease");
               }
          }
          // add old image back in
          
          
          // remove stylings for mlg
          document.getElementById('choosemlg').firstChild.className = "selbutton selbuttonActive";
          
          var children = document.getElementById("mlgul");
          if(typeof(chosenMLG) != "undefined"){
               for(node in children.childNodes){
                    if(typeof(children.childNodes[node]) != "undefined" && typeof(children.childNodes[node].style) != "undefined")
                         children.childNodes[node].style.backgroundColor = "transparent";
               }
               
          }
          chosenMLG = '';
          var mlgDiv = document.getElementById("choosemlg");
         
         mlgDiv.onclick = showMenu;
          
     } else if(type == 'mlg'){

          if(typeof(chosenMLG) != "undefined" && chosenMLG != id && chosenMLG != ''){
               document.getElementById("mlg"+chosenMLG).style.backgroundColor = "transparent";
          }
          chosenMLG = id;

          node.className = node.className + " selecteditem";
          node.parentNode.parentNode.firstChild.childNodes[1].innerHTML = "Geselecteerd: " + node.innerHTML; // set button innerhtml
          if(typeof(node.style) != "undefined")
               node.removeAttribute("style");
          var mlgDiv = document.getElementById('choosemlg').firstChild;
          mlgDiv.className = mlgDiv.className + " selected";
     } 
}


// this function sets the content for the page, whether it is div info
// or if it is iframe info
function set_content(type, target, content){
	if(type == 'div'){
		document.getElementById(target).innerHTML = content.replace(/\r|\n|\r\n/g,"");;
	} else if(type == 'iframe'){
		var div = document.getElementById(target);
		div.setAttribute('src', content);
		div.setAttribute('height', div.attributes['height'].value);
		div.setAttribute('width', div.attributes['width'].value);
          div.style.display = '';
	}
}

// add function to resize the fixed scroll table

function changeHeight(){
     var myHeight = 0;
     if( typeof( window.innerHeight ) == 'number' ) {
         //Non-IE
         myHeight = window.innerHeight;
     } else if(document.documentElement && document.documentElement.clientHeight) {
         //IE 6+ in 'standards compliant mode'
         myHeight = document.documentElement.clientHeight;
     } else if( document.body && document.body.clientHeight ) {
         //IE 4 compatible
         myHeight = document.body.clientHeight;
     }
     var scTable = document.getElementById("scrollContentContainer");
     var prcTable = document.getElementById("prices");
     var conHeight = document.getElementById("container").clientHeight;
     if(conHeight < myHeight) {
         // need to subtract 83px for the footer
         prcTable.style.height = (prcTable.clientHeight + (myHeight - conHeight)) - 83 + "px";
         scTable.style.height = (scTable.clientHeight + (myHeight - conHeight)) - 83 + "px";
     }
}
