function replaceSubstring(inputString, fromString, toString) {
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else {
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } 
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   }
   return temp;
}

function hifizine(){
	if(document.prijs.email.value.length<4){
		alert('U moet wel uw emailadres invullen.');
	}else{
		email=document.prijs.email.value;
		window.open('prehifizine.php?email='+email+'','window2','width=300, height=260');
	}
return(false);
}

function hifizinemenu(){
	if(document.prijs.email.value.length<4){
		alert('U moet wel uw emailadres invullen.');
	}else{
		email=document.prijs.email.value;
		window.open('prehifizine.php?email='+email+'','window2','width=300, height=260');
	}
return(false);
}

function hifizine2(){
	if(document.prijs2.email.value.length<4){
		alert('U moet wel uw emailadres invullen.');
	}else{
		email=document.prijs2.email.value;
		window.open('prehifizine.php?email='+email+'','window2','width=300, height=260');
	}
return(false);
}

function search_function(){
	document.adv_search.merk1.value=replaceSubstring(document.adv_search.merk1.value,"&","?");
	document.adv_search.merk2.value=replaceSubstring(document.adv_search.merk2.value,"&","?");
	document.adv_search.importeur.value=replaceSubstring(document.adv_search.importeur.value,"&","?");
}

function hifind(){
	return false;
}
function zoeken(){
	str=prompt("Waarop wilt u zoeken?","");
	if(str>""){
		self.location.href="zoek.php?str="+str;
	}
}
function showpicture(p){
	window.open('http://www.hifi.nl/zoomimage.php?id='+p+'','zoom','scrollbars=yes, toolbar=no, resizable=no, status=no, top=0, left=0, screenX=1, screenY=1, width=1015, height=760');
}

function showimage(p){
	window.open('http://www.hifi.nl/zoomimage.php?pict='+p+'','zoom','scrollbars=yes, toolbar=no, resizable=no, status=no, top=0, left=0, screenX=1, screenY=1, width=1015, height=760');
}

function selectsnelmenu(){
	self.location.href="http://www.hifi.nl/snelmenu.php?id="+document.snelform.snelmenu.value;
}

function FillSearchField() {
	if(document.hifindform.s.value==1) {
		document.hifindform.zoek.value="vul plaatsnaam in";
	}
	if(document.hifindform.s.value==4) {
		document.hifindform.zoek.value="vul winkelnaam in";
	}
	if(document.hifindform.s.value==2) {
		document.hifindform.zoek.value="vul merk in";
	}
	if(document.hifindform.s.value==6) {
		document.hifindform.zoek.value="vul merk in";
	}
	if(document.hifindform.s.value==5) {
		document.hifindform.zoek.value="vul importeursnaam in";
	}
	if(document.hifindform.s.value==3) {
		document.hifindform.zoek.value="vul merk in";
	}
	document.hifindform.zoek.focus();
}

function ClearSearchHelp() {
	if(document.hifindform.zoek.value=="vul plaatsnaam in") {
		document.hifindform.zoek.value="";
	}
	if(document.hifindform.zoek.value=="vul winkelnaam in") {
		document.hifindform.zoek.value="";
	}
	if(document.hifindform.zoek.value=="vul merk in") {
		document.hifindform.zoek.value="";
	}
	if(document.hifindform.zoek.value=="vul importeursnaam in") {
		document.hifindform.zoek.value="";
	}
}

function hivist1(){
	document.getElementById('hivisitbox1').style.display='block';
	document.getElementById('hivisitbox2').style.display='none';
	return false;
}
function hivist2(){
	document.getElementById('hivisitbox1').style.display='none';
	document.getElementById('hivisitbox2').style.display='block';
	return false;
}

function accepteer(){
	document.getElementById('reactietxt').style.display='none';
	document.getElementById('tekst').style.display='block';
	document.getElementById('tekst').focus();
	MM_showHideLayers('reageer','','hide');
	return false;
}

function removewords(id){
	document.getElementById(id).style.color='black';
	if(document.getElementById(id).value=="uw loginnaam"){document.getElementById(id).value="";	}
	if(document.getElementById(id).value=="jouw loginnaam"){document.getElementById(id).value="";	}
	if(document.getElementById(id).value=="Wachtwoord"){document.getElementById(id).value="";	}
	if(document.getElementById(id).value=="Webcode"){document.getElementById(id).value="";	}
	if(document.getElementById(id).value=="Zoeken op"){document.getElementById(id).value="";	}
	if(document.getElementById(id).value=="Vul trefwoord in"){document.getElementById(id).value="";	}
	if(document.getElementById(id).value=="zoek nu"){document.getElementById(id).value="";	}
	if(document.getElementById(id).value=="Zoek nu"){document.getElementById(id).value="";	}
	if(document.getElementById(id).value=="Vul 1 of 2 trefwoorden in"){document.getElementById(id).value="";	}
	if(document.getElementById(id).value=="Uw e-mail adres"){document.getElementById(id).value="";	}
}
function expandmenu(menu) {
	if(menu!='rec'){
	if(document.getElementById('menu_'+menu+'2').style.display=='block'){
		document.getElementById('menu_'+menu+'1').className='normal';
		document.getElementById('menu_'+menu+'2').style.display='none';
	}else{
		document.getElementById('menu_'+menu+'1').className='open';
		document.getElementById('menu_'+menu+'2').style.display='block';
	}}
}

function isCorrectEmail(argvalue) {

  if (argvalue.indexOf(" ") != -1)
    return false;
  else if (argvalue.indexOf("@") == -1)
    return false;
  else if (argvalue.indexOf("@") == 0)
    return false;
  else if (argvalue.indexOf("@") == (argvalue.length-1))
    return false;

  return true;

}

function subon(i){
	document.getElementById(i).style.display='block';
}
function suboff(){
	//document.getElementById('subnav2').style.display='none';
	//document.getElementById('subnav3').style.display='none';
	//document.getElementById('subnav5').style.display='none';
	//document.getElementById('subnav6').style.display='none';
	//document.getElementById('subnav9').style.display='none';
	//document.getElementById('subnav10').style.display='none';
}

var prevValue = '';

function RecursiveCheckIfNumber(iVal){
	if(isNaN(iVal)){
		var myRegExp = new RegExp("[^0-9.]");
		iVal = iVal.replace(myRegExp,""); 
		if(isNaN(iVal)){
			iVal=prevValue;
		}
	}
	prevValue=iVal;
	return iVal;
}

function CheckIfNumber(obj){
	obj.value=obj.value.replace(",",".");
	obj.value=RecursiveCheckIfNumber(obj.value);;
}

function checkAll(field){
	for (i = 0; i < field.length; i++)
		field[i].checked = true ;
}

function uncheckAll(field){
	for (i = 0; i < field.length; i++)
		field[i].checked = false ;
}

function showMoreContent(){
	if(document.getElementById('more_content').style.display=='block'){
		$('#more_content').hide("fast");
	}else{
		$('#more_content2').hide("fast");
		$('#more_content').show("fast");
	}
}

function showMoreContent2(){
	if(document.getElementById('more_content2').style.display=='block'){
		$('#more_content2').hide("fast");
	}else{
		$('#more_content').hide("fast");
		$('#more_content2').show("fast");
	}
}

function fontsize(i){
	self.location.href='http://www.hifi.nl/ChangeFontSize.php?size='+i;
}