onload = function(){
	pageHit();
	sizeContent();
    setMaxLength();
}
onresize = function(){
	sizeContent();
}

function pageHit(){

  p = escape(document.location.href);
  rfr = escape(document.referrer);
  if (rfr == "undefined"){ rfr = "";}
  sx = screen.width;
  sy = screen.height;
  sc = (navigator.appName.indexOf("Microsoft") > -1) ? screen.colorDepth : screen.pixelDepth;
  src = 'stats.php?p=' + p + '&rfr=' + rfr + '&sx=' + sx + '&sy=' + sy + '&sc=' + sc;
  src = '<img style="position:absolute;left:-10px;top:-10px;" src="' + src + '" width="1" height="1" border="0" alt="" />';
  document.getElementById('counter').innerHTML = src;  
  
}

function headPopup(show, Num)
{
	if(show == 1)
	{
		 document.getElementById('rightcolumnpopup_1').style.display = 'none';
		 document.getElementById('rightcolumnpopup_2').style.display = 'none';
		 document.getElementById('rightcolumnpopup_3').style.display = 'none';
		 document.getElementById('rightcolumnpopup_4').style.display = 'none';
		 document.getElementById('rightcolumnpopup_' + Num + '').style.display = 'block';

	} else {

		 document.getElementById('rightcolumnpopup_1').style.display = 'none';
		 document.getElementById('rightcolumnpopup_2').style.display = 'none';
		 document.getElementById('rightcolumnpopup_3').style.display = 'none';
		 document.getElementById('rightcolumnpopup_4').style.display = 'none';

	}
}

function sizeContent(){

	var bottomFiller = document.getElementById('bottomFiller');
	var mainHeight = document.getElementById('main').offsetHeight;
	var innerHeight = document.documentElement.clientHeight;
	
	if(mainHeight < innerHeight){
		

		var fill = innerHeight - mainHeight;
		
		bottomFiller.style.height = fill +"px";
	}
	
}

function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
		thisfield.value = "";
		thisfield.style.color = "#000000";
	
	}
}

function setMaxLength() {
    var x = document.getElementsByTagName('textarea');
    var counter = document.createElement('div');
    counter.className = 'charcounter';
    for (var i=0;i<x.length;i++) {
        if (x[i].getAttribute('maxlength')) {
            var counterClone = counter.cloneNode(true);
            counterClone.relatedElement = x[i];
            counterClone.innerHTML = '<span>0</span>/'+x[i].getAttribute('maxlength');
            x[i].parentNode.insertBefore(counterClone,x[i].nextSibling);
            x[i].relatedElement = counterClone.getElementsByTagName('span')[0];

            x[i].onkeyup = x[i].onchange = checkMaxLength;
            x[i].onkeyup();
        }
    }
}

function checkMaxLength() {
    var maxLength = this.getAttribute('maxlength');
    var currentLength = this.value.length;
    if (currentLength > maxLength)
        this.relatedElement.className = 'toomuch';
    else
        this.relatedElement.className = '';
    this.relatedElement.firstChild.nodeValue = currentLength;
    // not innerHTML
}
