//This function will close the review popup
function closeReviewPopup(tdClicked) {
	Effect.toggle(tdClicked, 'appear', { duration: 0.5, queue: 'review' });
}
//This function will open the review popup
function openReviewPopup(elClicked, expert, customer, xPad, yPad) {
	var popupDivs = elClicked.parentNode.getElementsByTagName('div');
	var popupDiv = null;
	for (var i = 0; i < popupDivs.length; i++) {
		if (popupDivs[i].id == 'reviewDiv') {
			popupDiv = popupDivs[i];
		}
	}
	if (popupDiv) {
		var xCoord = getXCoord(elClicked);
		var yCoord = getYCoord(elClicked);
		popupDiv.style.top = (yCoord + yPad) + 'px'; 
		popupDiv.style.left = (xCoord - xPad) + 'px';
		/*if (navigator.appName.match('Microsoft')) {
			popupDiv.style.left = (xCoord - 152) + 'px';
			popupDiv.style.top = (yCoord + 18) + 'px'; 
		}*/
		var reviewTable = popupDiv.firstChild;
		if (!expert || !customer) {
			if (!expert) {
				reviewTable.rows[0].cells[0].style.visibility = 'hidden';
				reviewTable.rows[0].cells[1].style.visibility = 'hidden';
				reviewTable.rows[1].cells[0].style.visibility = 'hidden';
				reviewTable.rows[1].cells[1].style.visibility = 'hidden';
				reviewTable.rows[2].cells[0].style.visibility = 'hidden';
				reviewTable.rows[3].cells[0].style.visibility = 'hidden';

				reviewTable.rows[2].cells[1].colSpan = '1';
				reviewTable.rows[3].cells[1].colSpan = '1';

				reviewTable.rows[2].cells[0].colSpan = '2';
				reviewTable.rows[3].cells[0].colSpan = '2';
				
				reviewTable.rows[0].cells[2].style.borderLeft = '1px solid #C3BFB8';
				reviewTable.rows[1].cells[2].style.borderLeft = '1px solid #C3BFB8';
				reviewTable.rows[2].cells[1].style.borderLeft = '1px solid #6181BA';
				
				reviewTable.rows[3].cells[1].style.textAlign = 'left';
				reviewTable.rows[3].cells[1].innerHTML = '<img src="' + $('jsLabels:extImages').value + '/review_popup/border_fix.png" style="position: relative; bottom: 7px;">'
				if (navigator.appName.match('Microsoft')) {
					reviewTable.rows[3].cells[1].innerHTML = '<img src="' + $('jsLabels:extImages').value + '/review_popup/border_fix.png" style="position: relative; bottom: 6px;">'
				}
			}
			if (!customer) {
				reviewTable.rows[0].cells[2].style.visibility = 'hidden';
				reviewTable.rows[0].cells[3].style.visibility = 'hidden';
				reviewTable.rows[1].cells[2].style.visibility = 'hidden';
				reviewTable.rows[1].cells[3].style.visibility = 'hidden';
				reviewTable.rows[2].cells[2].style.visibility = 'hidden';
				reviewTable.rows[3].cells[2].style.visibility = 'hidden';
				
				reviewTable.rows[0].cells[1].style.borderRight = '1px solid #C3BFB8';
				reviewTable.rows[1].cells[1].style.borderRight = '1px solid #C3BFB8';
				reviewTable.rows[2].cells[1].style.borderRight = '1px solid #6181BA';
				
				reviewTable.rows[2].cells[1].colSpan = '1';
				reviewTable.rows[3].cells[1].colSpan = '1';
				
				reviewTable.rows[3].cells[1].style.textAlign = 'right';
				reviewTable.rows[3].cells[1].innerHTML = '<img src="' + $('jsLabels:extImages').value + '/review_popup/border_fix.png" style="position: relative; bottom: 7px;">'
				if (navigator.appName.match('Microsoft')) {
					reviewTable.rows[3].cells[1].innerHTML = '<img src="' + $('jsLabels:extImages').value + '/review_popup/border_fix.png" style="position: relative; bottom: 6px;">'
				}
			}
		}
		Effect.toggle(popupDiv, 'appear', { duration: 0.5, queue: 'review' });
		closeAllReview();
	}
}
//Function will close all open review poups
function closeAllReview() {
	var reviewDivs = document.getElementsByTagName('div');
	for (var i = 0; i < reviewDivs.length; i++) {
		if (reviewDivs[i].id == 'reviewDiv' && reviewDivs[i].style.display != 'none') {
			closeReviewPopup(reviewDivs[i]);
		}
	}
}
//Function will return the absolute Y coordinate of an element
function getYCoord( oElement ) {
	var iReturnValue = 0;
	while (oElement != null) {
		iReturnValue += oElement.offsetTop;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}
//Function will return the absolute X coordinate of an element
function getXCoord( oElement ) {
	var iReturnValue = 0;
	while (oElement != null) {
		iReturnValue += oElement.offsetLeft;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}
function klikPadFix() {
	var allDivs = document.getElementsByTagName('div');
	var contentDiv = null;
	var rightMenuDiv = null;
	for (i = 0; i < allDivs.length; i++) {
		if (allDivs[i].className == 'content') {
			contentDiv = allDivs[i];
		}
	}
	for (i = 0; i < allDivs.length; i++) {
		if (allDivs[i].className == 'right_menu') {
			rightMenuDiv = allDivs[i];
		}
	}
	rightMenuDiv.style.height = contentDiv.clientHeight + 'px';
}
function loadResults() {
	var divRows = getElementsByClass('containerClass',null,'div');
	if (divRows!=null){
		for(counter=0;counter<divRows.length; counter++){
			divRows[counter].id = counter+'_container';
		}
	}
	var rows = document.getElementsByTagName('h3');
	if(rows!=null){
		for(counter=0;counter<rows.length; counter++){
			var header = rows[counter];
			header.id = counter+'_header';
			header.onclick = function changeListRow2 () {
									  var rowId = this.id.substr(0,1);	  									 
									  if (this.className == 'selected') {
									    this.className = '';
									    new Effect.toggle(rowId+"_container",'blind', { duration: 0.3 });
									  } else {
									    this.className = 'selected';
									    new Effect.toggle(rowId+"_container",'blind', { duration: 0.3 });
									  }
									}
		}
	}
  }  
  
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\\\s)"+searchClass+"(\\\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}  
  
  
function toggleAllRowsResultsPage (linkElement, rowList) {
	if(rowList == 'LocationsInfo'){
		if (linkElement.firstChild.innerHTML.substr(0,4) == 'Toon') {
		    linkElement.innerHTML = '<span>' + $('jsLabels:hideAllInfo').value + '</span><img src="' + $('jsLabels:extImages').value +'/orangeRArrow.gif" alt="" />';
		   	var rows = document.getElementsByTagName('h3');
			if(rows!=null){
				for(counter=0;counter<rows.length; counter++){
					if (rows[counter].className != 'selected') {
        				 var rowId = rows[counter].id.substr(0,1);
        				 rows[counter].className = 'selected';
         				 new Effect.toggle(rowId+'_container','blind', { duration: 0.3 });
        			}
				}
    		}
		    
	   }else{
	   		 linkElement.innerHTML = '<span>' + $('jsLabels:showAllInfo').value + '</span><img src="' + $('jsLabels:extImages').value +'/orangeRArrow.gif" alt="" />';
	   		
		    	var rows = document.getElementsByTagName('h3');
					if(rows!=null){
						for(counter=0;counter<rows.length; counter++){
							if (rows[counter].className == 'selected') {
		        				 var rowId = rows[counter].id.substr(0,1);
		        				 rows[counter].className = '';
		         				 new Effect.toggle(rowId+'_container','blind', { duration: 0.3 });
		        			}
						}
		    		}
		}		  
	
	}
}   
    
function submitRedirection(formId)  {
	if(formId!=null){
		link = document.getElementById(formId+':clearRefine');
		if(link!=null){
			link.onclick();
		}
	}
}

function submitRedirectionHeader(formId)  {
	if(formId!=null){
		link = document.getElementById(formId+':clearRefineHeader');
		if(link!=null){
			link.onclick();
		}
	}
}

function setFakeFocus()  {
	var refineButton = document.getElementById('checkAvailability:refineButton');
	if(refineButton!=null){
		refineButton.focus();	
	}
}


function adjustPageNumbers() {
	var zeroPage = 'pag.0';
	
	try{
		var zeroPage = 'pag.0';
		var replaceWith = 'alleen in prijsbijlage';
		var pageNumberLabels = getElementsByClass('pageNumberLabel', null, null);
		var pageNumberLabelsLength = pageNumberLabels.length;
		
		if(pageNumberLabels != null){
			for (k = 0; k < pageNumberLabelsLength; k++) {
				var pageNumberLabel = pageNumberLabels[k];
				if(pageNumberLabel != null){
					var pageNumberLabelString = pageNumberLabel.textContent;
					var pageNumberLabelInnerString = pageNumberLabel.innerText;
					
					if( (pageNumberLabelString != null && pageNumberLabelString == zeroPage) || (pageNumberLabelInnerString != null && pageNumberLabelInnerString == zeroPage)){
						pageNumberLabel.innerText = replaceWith;
						pageNumberLabel.textContent = replaceWith;
					} 
				}	
			}	
		}	
		
		return false;
	}
	catch(err){
		return false;
	}
}

function submitDirectSearchRefineForm(formId){
	try{
		form = document.getElementById(formId);
		if(form != null){
			form.submit();
		}
		
		return false;
	}
	catch(err){
		return false;
	}
}


