var ns = (document.layers); 
var ie = (document.all);

var EenUur = new Date();
EenUur.setTime(EenUur.getTime() + 3600000);

var DrieMaands = new Date();
DrieMaands.setTime(DrieMaands.getTime() + 7776000000 );


//////////////////////////////////////////////////

function ContentDyn(text,id) {
	if (document.getElementById) {
		x = document.getElementById(id);
		x.innerHTML = text;
	}
	else if (document.all) {
		x = document.all[id];
		x.innerHTML = text;
	}
	else if (document.layers) {
		x = document.layers[id];
		x.document.open();
		x.document.write(text);
		x.document.close();
	}
}


//////////////////////////////////////////////////

function ZoekInSuperlijst(date) {
	product = document.getElementById('productveld').value;
	if (!date) {
		dag = document.getElementById('selDag').options[document.getElementById('selDag').selectedIndex].value;
		maand = document.getElementById('selMaand').options[document.getElementById('selMaand').selectedIndex].value;
		jaar = document.getElementById('selJaar').options[document.getElementById('selJaar').selectedIndex].text;
		location="index.pl?Todo=ZoekInSuperlijst&product="+product+'&date='+jaar+''+maand+''+dag ;
	}
	else {
		location="index.pl?Todo=ZoekInSuperlijst&product="+product+'&date='+date;
		return false;
	}
}


//////////////////////////////////////////////////

function toevoegenSuperlijst(product, punten, date) {
	aantal = prompt("Hoeveel '" + product + "' wilt u toevoegen?","1");
	aantal=aantal.replace(/[^\d\,\.]/,'');
	location = 'index.pl?Todo=Toevoegen&product='+product+'&punten='+punten+'&date='+date+'&aantal='+aantal ;
}

//////////////////////////////////////////////////
// 

function VerwijderGewicht(idgewicht) {   
	if (confirm("Wilt u deze balk echt verwijderen?\n\n(u kunt deze actie niet ongedaan maken en\nalleen uw gewicht van vandaag toevoegen)")) {
		location = 'index.pl?Todo=GewichtVerwijder&delete=' + idgewicht
	}
}


//////////////////////////////////////////////////

function toevoegenZelf() {
	productzelf = document.getElementById('productveld').value;
	dag = document.getElementById('selDag').options[document.getElementById('selDag').selectedIndex].value;
	maand = document.getElementById('selMaand').options[document.getElementById('selMaand').selectedIndex].value;
	jaar = document.getElementById('selJaar').options[document.getElementById('selJaar').selectedIndex].text;
	location = 'index.pl?Todo=Eigenproduct&zelf='+productzelf+'&date='+jaar+''+maand+''+dag ;
}

//////////////////////////////////////////////////

function toevoegenLijst(product,punten) {
	document.getElementById('productveld').style.background="#fce69f";
	document.getElementById('productveld').value = product;
	document.getElementById('puntenveld').value = punten;
	document.getElementById('aantalveld').focus();
}


//////////////////////////////////////////////////

function LogIn(aantal) {
	Maak('u', document.topform.u.value, aantal);
	Maak('p', document.topform.p.value, aantal);
}


//////////////////////////////////////////////////

function LogUit() {
	Maak('u', '', EenUur);
	Maak('p', '', EenUur);
}


//////////////////////////////////////////////////

function Haal(name) {
  var cname = name + "=";
  var dc = document.cookie;
  if (dc.length > 0) {
    begin = dc.indexOf(cname);
    if (begin != -1) {
      begin += cname.length;
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
        return unescape(dc.substring(begin, end));
    } 
  }
  return null;
}


//////////////////////////////////////////////////

function Maak(name, value, expires) {
  document.cookie = name + "=" + escape(value) + 
  ((expires == null) ? "" : "; expires=" + expires.toGMTString());
}


//////////////////////////////////////////////////

function Verschoon (name) {
  if (Haal(name)) {
    document.cookie = name + "=" +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}


//////////////////////////////////////////////////
// Forum Textarea Opmaak

function plaatje(obj) {   
	txt=prompt("Vul hieronder het adres van het plaatje in.\n(niet de pagina waarop het plaatje staat, maar het adres van het plaatje zelf)","http://");
	if (txt && txt.length > 7) {
		wrapText(obj, '[PLAATJE='+txt+']', ' ');
	}
}
function linken(obj) {   
	txt=prompt("Vul hieronder het adres in waarnaar de link moet verwijzen.","http://");
	if (txt && txt.length > 7) {
		wrapText(obj, '[LINK='+txt+']', ' ');
	}
}

function applyTag(obj, tag) {
	wrapText(obj, '['+tag+']', '[/'+tag+']');
}

function wrapText(obj, beginTag, endTag) {
	if(typeof obj.selectionStart == 'number') {
		// Mozilla, Opera, and other browsers
		var start = obj.selectionStart;
		var end   = obj.selectionEnd;
		
		obj.value = obj.value.substring(0, start) + beginTag + obj.value.substring(start, end) + endTag + obj.value.substring(end, obj.value.length);
	}
	else if(document.selection) {
		// Internet Explorer
		// make sure it's the textarea's selection
		obj.focus();
		var range = document.selection.createRange();
		if(range.parentElement() != obj) return false;

	    if(typeof range.text == 'string')
	        document.selection.createRange().text = beginTag + range.text + endTag;
	}
	else obj.value += text;
}



//////////////////////////////////////////////////
// Image Resize start

var maxImageWidth = 500;

function unscaleImage() {
	if(maxImageWidth > 0)
	this.width = this.width == maxImageWidth? this.orgwidth:maxImageWidth;
}

function scaleImage(im) {
	if (maxImageWidth > 0 && im.width > maxImageWidth) {
		im.orgwidth = im.width;
		im.width = maxImageWidth;
		im.onclick = unscaleImage;
	}
}


//////////////////////////////////////////////////
// Preview Bekijkonderwerpen start

function Previewtoon(deze) {
	document.getElementById(deze).style.visibility = "visible";
}
function Previewweg(deze) {
	document.getElementById(deze).style.visibility = "hidden";
}
