function BrowserSniff() {
   var ua = navigator.userAgent.toLowerCase();
   this.isIE = (ua.indexOf('msie') != -1 ); 
   this.isMac = (ua.indexOf('mac') != -1);
   this.versionMinor = parseFloat(navigator.appVersion);  
   if (this.isIE && this.versionMinor >= 4) this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );   
   this.versionMajor = parseInt(this.versionMinor);
   this.isIE6up = (this.isIE && this.versionMajor >= 6);  
}
var browser = new BrowserSniff();
if ((browser.isIE) && !(browser.isIE6up) && !(browser.isMac)) { document.write("<link rel='stylesheet' href='css/ie5.css' type='text/css'>"); }

var mTimer;


function showLayer(id){
	if(document.getElementById)document.getElementById(id).style.visibility = 'visible';
	if(!document.getElementById && document.all)document.all[id].style.visibility = 'visible';
}

function hideLayer(id){
	if(document.getElementById)document.getElementById(id).style.visibility = 'hidden'
	if(!document.getElementById && document.all)document.all[id].style.visibility = 'hidden';
}




function displayLayer(id, action){
	// action= 'block' || 'none'
	if(document.getElementById)document.getElementById(id).style.display = action;
	if(!document.getElementById && document.all)document.all[id].style.display = action;
}

function startTimer(val){
	if(val != '')mTimer = setTimeout('hideLayer(\'snelNaar\')',val);
}

function stopTimer(){
	clearTimeout(mTimer);
}

function clearDefault(id,defaultVal){
	if(document.getElementById)if (document.getElementById(id).value == defaultVal)document.getElementById(id).value = '';
	if(!document.getElementById && document.all)if(document.all[id].value == defaultVal)document.all[id].value = ''
}

function restoreDefault(id,defaultVal){
	if(document.getElementById)if (document.getElementById(id).value == '')document.getElementById(id).value = defaultVal;
	if(!document.getElementById && document.all)if(document.all[id].value == '')document.all[id].value = defaultVal;
}
function validateDefault(id,defaultVal){
	if(document.getElementById)if (document.getElementById(id).value == '' || document.getElementById(id).value == defaultVal){alert('U heeft de volgende velden nog niet ingevuld: \n\n' + '-' + id);return false;}
	if(!document.getElementById && document.all)if(document.all[id].value == '' || document.all[id].value == defaultVal){alert('U heeft de volgende velden nog niet ingevuld: \n\n' + '-' + id);return false;}
	return true;
}
function openWindow(url){
	window.open(url);
	return;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function selectMerk()
{
	var oldValue=document.getElementById('merkstring').value;
	var newValue=document.getElementById('merk').value;
	//'cartridges
	if ((newValue!='') && (oldValue!=newValue))
	{
		document.getElementById('cartridges').submit();
	}
	
}

function selectSoort()
{
	var oldValue=document.getElementById('soortstring').value;
	var newValue=document.getElementById('soort').value;
	//'cartridges
	if ((newValue!='') && (oldValue!=newValue))
	{
		document.getElementById('selectsoortform').submit();
	}
	
}

function selectType()
{
	var newValue=document.getElementById('keyword').value;
	if (newValue!='')
	{	
		showLayer('divSelectSubmit');
		//showLayer('divNoCartridge');
	
	}
	else
	{
		
		hideLayer('divSelectSubmit');
		//hideLayer('divNoCartridge');
	}
}

function submitType()
{

	var newValue=document.getElementById('keyword').value;
	if (newValue!='')
	{	
		var submiturl = document.getElementById('selecttypeform').action;
		var sel = document.getElementById('keyword');
		var selectedvalue = sel.options[sel.selectedIndex].value;
		var do_zz = document.getElementById('do_zz').value;
		var contentcode = document.getElementsByName('contentcode')[0].value;
		if(top != null) 
		{
			submiturl = submiturl + "?do_zz=" + do_zz + "&contentcode=" + contentcode + "&keyword=" + selectedvalue
			top.location = submiturl;
		}
	}
}

function selectCamera()
{
var merkValue=document.getElementById('merk').value;
var resolutieValue=document.getElementById('resolutie').value;

	if ((merkValue!='') || (resolutieValue!=''))
	{	
		showLayer('divSelectSubmit');
		//showLayer('divNoCartridge');
	
	}
	else
	{
		
		hideLayer('divSelectSubmit');
		//hideLayer('divNoCartridge');
	}
}

function submitCamera()
{

var merkValue=document.getElementById('merk').value;
var resolutieValue=document.getElementById('resolutie').value;

	if ((merkValue!='') || (resolutieValue!=''))
	{	
		document.getElementById('cameraSearchform').submit();
	}
}



function selectZoek()
{
	var newValue=document.getElementById('keyword2').value;
	if (newValue!='')
	{	
		showLayer('divSelectSearch');
	}
	else
	{
		
	//	hideLayer('divSelectSearch');
	}
}

function submitZoek()
{
var newValue=document.getElementById('keyword2').value;
	if (newValue!='')
	{	
		// Check keyword length for Cartridge Search (keyword must be > 1) - KVNL-999
		if(newValue.length > 1 )
		{
			document.getElementById('cartridgeSearchform').submit();
		}
	}
}

function gegevensAanpassen(){
	displayLayer('profileaddress_profileaddressreadonly', 'none');
	displayLayer('profileaddress_profileaddress', 'block');

}
function gegevensAnnuleren(){
	displayLayer('profileaddress_profileaddress', 'none')
	displayLayer('profileaddress_profileaddressreadonly', 'block')
}

function checkNotEmpty(me)
{
	theID=me.id + 'Label';
	if (me.value !='')
	{document.getElementById(theID).className='';
	}
	else
	{document.getElementById(theID).className='error';}
}

function updateprijsfixedprice(id,innerHTMLid,startprice,price) {
	var theText=id.value;
	var theLength=0;
	if (theText!='') 
		{
		theText=xreplace(theText,' ','');
		theLength=theText.length
		}
	var thePrice= Round2Dec(Number(startprice) + Number((theLength * price)));
	
	
	//alert(startprice + " + " + (theLength * price) + "=" + (startprice + (theLength * price)) );
	var mResult=thePrice + '';
	mResult=mResult.replace('.',',')

	document.getElementById(innerHTMLid).innerHTML = mResult;
}


function updateprijs(id,innerHTMLid,idpricehidden,price) {
	var theText=id.value;
	var theLength=0;
	if (theText!='') 
		{
		theText=xreplace(theText,' ','');
		theLength=theText.length
		}
	var thePrice=Round2Dec(theLength * price);
	var mResult=thePrice + '';
	mResult=mResult.replace('.',',')

	document.getElementById(innerHTMLid).innerHTML = mResult;
}


function checkproduct() {

	var theText = document.getElementById('opschrift').value;
	var theLength = 0;
	
	theText=xreplace(theText,' ','');
	theLength = theText.length;
	
	if (theLength > 0) {
		return true;
	} else {
		alert('Voer minimaal een karakter in.');
		return false;
	}
	
}


function calculateTotal()
{
 var TotalPrice=0;
 var meP = document.getElementsByName("price");
 var tempPrice;
 for(var i=0;i<meP.length;i++)
 {	
	tempPrice=meP[i].value;
	tempPrice=tempPrice.replace(',','.');
	TotalPrice=TotalPrice+parseFloat(tempPrice);

 }
 
 TotalPrice=Round2Dec(TotalPrice)
 var mResult=TotalPrice + '';
 mResult=mResult.replace('.',',')
 document.getElementById('totalprice').innerHTML = mResult;
 

}

function Round2Dec(amountvalue) {
// returns the amount in the .99 format 
    var amount 
    var result
    amount = (Math.round(amountvalue*100))/100;
    result=amount;
    if (amount == Math.floor(amount))
	    {
			 result=amount + '.00';
			
			}
		else
		{
		if (amount*10 == Math.floor(amount*10)) 
		{
			result=amount + '0';
		}
		}	
		//ObjForm.value=result;
		
		return result;
}


function xreplace(checkMe,toberep,repwith){

var temp = checkMe;

var i = temp.indexOf(toberep);

while(i > -1)

{

temp = temp.replace(toberep, repwith);

i = temp.indexOf(toberep);

}

return temp;

}


function openHTMLClientHttpMMS(url, width, height, title)
{
	previewWindow = open( url, title, "width=" + width + ", height=" + height + ",screenX=0,screenY=0,resizable=no");
}


