var http_request = false;

function AsyncHttpRequest(url, arg ,stype, xml) {
	http_request = false;
	
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
			// See note below about this line
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}           
	}

	if (!http_request) {
		alert('Your browser badly enough doesnt support Ajax Scripting. Try ');
		return false;
	}
	// http_request.onreadystatechange = alertContents;		
	if (stype == 'POST') {
		http_request.open(stype, url, false);
		http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
		http_request.send(arg);
	} else {
		http_request.open(stype, url + "?" + arg, false);
		http_request.send(null);
	}	
	
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			if (xml == true) {
				if (!http_request.overrideMimeType) {						
					//if (http_request.responseXML == null) {						
						var xmlDocument = new ActiveXObject("Microsoft.XMLDOM");
						try {
							xmlDocument.loadXML(http_request.responseText);					
						} catch(e) { alert("Could not parse XML file.") }
						return xmlDocument;							
					// } else {
					//	return http_request.responseXML;
					// } 
				} else {
					return http_request.responseXML;
				}
			} else {
				return http_request.responseText;
			}
		} else {
			if (xml == true) {
			alert('Er is een probleem met het halen van gegevens. HTTP Error:' + http_request.status );
			} else {
				return http_request.status;
			}
		}
	}		
}


function AsyncHttpRequest2(url, arg ,stype) {
	http_request = false;
	
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
			// See note below about this line
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}           
	}

	if (!http_request) {
		alert('Your browser badly enough doesnt support Ajax Scripting. Try ');
		return false;
	}
	// http_request.onreadystatechange = alertContents;		
	if (stype == 'POST') {
		http_request.open(stype, url, false);
		http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
		http_request.send(arg);
	} else {
		http_request.open(stype, url + "?" + arg, false);
		http_request.send(null);
	}	
	
	if (http_request.readyState == 4) {
		return http_request;
	}		
}

function getItem(id, klasse){
 if (document.getElementById('div_item_1')) { document.getElementById('div_item_1').style.display = 'none' }
 if (document.getElementById('div_item_2')) { document.getElementById('div_item_2').style.display = 'none' }
 if (document.getElementById('div_item_3')) { document.getElementById('div_item_3').style.display = 'none' }
 
 if (document.getElementById('link_item_1')) { document.getElementById('link_item_1').className = 'left_producten_link' }
 if (document.getElementById('link_item_2')) { document.getElementById('link_item_2').className = 'left_producten_link' }

 if (document.getElementById('div_item_' + id)) document.getElementById('div_item_' + id).style.display = '';
 if (document.getElementById('td_item_' + id)) document.getElementById('td_item_' + id).className = klasse;
 if (document.getElementById('link_item_' + id)) document.getElementById('link_item_' + id).className = 'left_producten_link_active';

}

function getVergelijking(id){
 window.open('/vergelijk/item_select.asp?id=' + id,'Vergelijking','width=800, height=800, scrollbars=yes');
 return;
}

function getLocation(url){
 location.href = url;
}

function resizeSpacerImage(){
 if (document.getElementById('itemInfoTable')){
  if (document.getElementById('spacerImage')){
   img = document.getElementById('spacerImage');
   img.style.pixelHeight = document.getElementById('itemInfoTable').offsetHeight+100;
  }
 }
}

function getFiche(aantal,artikelid){
	URLPage = "/fiche_add.asp";
	URLarg = "aantal=" + aantal + "&artikelid=" + artikelid;
	ResponseText = AsyncHttpRequest(URLPage, URLarg, "POST", false);
}

function getAantalFiches(artikelid){
	if ($('fiche_checkbox_' + artikelid).checked == true) {
		aantal = document.getElementById("aantal_fiches" + artikelid).value;
	} else {
		aantal = "0";
	}
	getFiche(aantal,artikelid);
}

function popImage(image){
    newwindow2=window.open('','name','height=520,width=500, scrollbars=no');
	var nu = new Date();
	var tijd = nu.getHours() +":" +nu.getMinutes() +":" +nu.getSeconds()
	var strHTML = "<html><head><title>Imageview</title></head>";
	strHTML += "<body leftmargin=0 rightmargin=0 topmargin=0 onblur=\"window.top.close();\">";
	strHTML += "<img src=\"" + image + "\">";
	strHTML += "</body>";
	strHTML += "</html>";
	newwindow2.document.write(strHTML);
	newwindow2.document.close();
	if (window.focus) {newwindow2.focus()}
	return false;
}

function changeSearchField(status){
 field = document.getElementById('input_searchfield');
 if (status == 'focus'){
  field.className = 'inputfield_search_focus';
  field.value = '';
 }
}

function checkSearch(){
 searchfield_str = document.search.searchfield_str.value
 search_error1 = document.search.search_error1.value
 search_error2 = document.search.search_error2.value
 searchfield = document.search.searchfield.value
 strOrderByField = document.search.strOrderByField.value
 strTable = document.search.strTable.value
 zoekwoord = document.search.SValue.value
 if (zoekwoord == '' || zoekwoord == searchfield_str){
  alert(search_error1);
 }else{
   if (zoekwoord.length <= 2){
    alert(search_error2);
    return;
   }
  document.search.action = '/page.asp';
  document.search.submit();
 }
}

function changeClass(id, klasse){
 if (document.getElementById(id)){
  document.getElementById(id).className = klasse;
 }
}

function showDiv(id){
 if (document.getElementById(id)){
  if (document.getElementById(id).style.display == 'none'){
   document.getElementById(id).style.display = '';
  }else{
   document.getElementById(id).style.display = 'none';
  }
 }
 return;
}

function getInfo(title, content){
 info_div = document.getElementById('div_symbol_info');
 if (title == '' && content == ''){
 	info_div.innerHTML = '';
	info_div.style.display = 'none';
 }else{
	info_div.style.display = '';
	info_div.innerHTML = '<div class="symbol_info_title">' + title + '</div><div class="symbol_info_text">' + content + '</div>';
 }
}



function changeSearchFieldGroups(status){
 field = document.getElementById('input_searchfield_groups');
 if (status == 'focus'){
  field.value = '';
 }
}

function checkSearchGroups(){
 searchfield = document.searchgroups.s1.value
 strOrderByField = document.searchgroups.s2.value
 strTable = document.searchgroups.s3.value
 zoekwoord = document.searchgroups.SValue.value
 if (zoekwoord == '' || zoekwoord == 'trefwoord/modelnummer'){
  alert('U dient een zoekcriteria op te geven');
 }else{
  document.searchgroups.action = '/page.asp';
  document.searchgroups.submit();
 }
}

function setLocation(url){
 window.top.location.href = url;
}


function getPosition(e) {
    e = e || window.event;    
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = e.clientX + 
            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY + 
            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
    return cursor;
}

function getPictureInfo(actie, path, defaultpath, teller){
	// cursor = getPosition();	
	
	if (actie == 'show'){
		box = document.getElementById('picture_info_box' + teller);
		content = document.getElementById('iframecontent' + teller);
		// box.style.left = cursor.x + 'px';
		// box.style.top = cursor.y + 'px';
		content.src = defaultpath + '/getfileinfo.asp?path=' + path;
		box.style.display = "block";		
	}

	if (actie == 'hide'){
		box = document.getElementById('picture_info_box' + teller);
		box.style.display = 'none';
	}
	
}
function getPictureInfo2(actie, path, defaultpath){
	cursor = getPosition();
	
	if (actie == 'show'){		
		contentpos = document.getElementById('content_pos');
			
		pos = findPos(contentpos);
		if (pos) {
			offsetx = pos[0];
		} else {
			offsetx = 500;
		}
		
		box = document.getElementById('picture_info_box');
		content = document.getElementById('iframecontent');
		box.style.left = cursor.x - offsetx + 'px';
		box.style.top = cursor.y - 225 + 'px';
		content.src = defaultpath + '/getfileinfo.asp?path=' + path;
		box.style.display = "block";		
	}

	if (actie == 'hide'){
		box = document.getElementById('picture_info_box');
		box.style.display = 'none';
	}
	
}

function checkSearchGroupsac() {
	searchfield_str = document.searchgroups.searchfield_str.value
	search_error1 = document.searchgroups.search_error1.value
	searchfield = document.searchgroups.searchfield.value
	strOrderByField = document.searchgroups.strOrderByField.value
	strTable = document.searchgroups.strTable.value
	zoekwoord = document.searchgroups.SValue.value
	if (zoekwoord == '' || zoekwoord == searchfield_str){
		alert(search_error1);
	}else{
		document.searchgroups.action = '/accessoires.asp';
		document.searchgroups.submit();
	}
}