/**
* @param	Powered by PBBoard© 2011
*/

// detect alphanumeric keys
var ns6=document.getElementById&&!document.all;
function restrictinput(maxlength,e,placeholder){
if (window.event&&event.srcElement.value.length>=maxlength)
return false
else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
var pressedkey=/[a-zA-Z0-9.,/]/ //detect alphanumeric keys
if (pressedkey.test(String.fromCharCode(e.which)))
e.stopPropagation()
}
}
function countlimit(maxlength,e,placeholder){
var theform=eval(placeholder);
var lengthleft=maxlength-theform.value.length;
var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder);
if (window.event||e.target && e.target==eval(placeholder)){
if (lengthleft<0)
theform.value=theform.value.substring(0,maxlength)
placeholderobj.innerHTML=lengthleft
}
}

function textCounter(field,counter,maxlimit,linecounter) {
    // text width//
    var fieldWidth =  parseInt(field.offsetWidth);
    var charcnt = field.value.length;
    // trim the extra text
    if (charcnt > maxlimit) {
        field.value = field.value.substring(0, maxlimit);
    }
    else {
    // progress bar percentage
    var percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/maxlimit) ;
    document.getElementById(counter).style.width =  parseInt((fieldWidth*percentage)/100)+"px";
    document.getElementById(counter).innerHTML="Text size: "+percentage+"%"
    // color correction on style from CCFFF -> CC0000
    setcolor(document.getElementById(counter),percentage,"background-color");
    }
}
function setcolor(obj,percentage,prop){
    obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
}

/**
* Function to resize an image used with the [IMG] bbcode tag
*/
function resize_image(obj, link, maxwidth)
{
	if (obj.width > maxwidth)
	{
		obj.style.cursor = 'pointer';
		obj.style.width = maxwidth + 'px';
		obj.style.height = parseInt(obj.height * maxwidth / obj.width) + 'px';
		obj.onclick = function()
		{
			window.location.href = link;
			return false;
		};
	}
}

/**
* Function to replace input type="text" to input type="password" To login via JavaScript
*/
	function replace_password(password_input)
    {
	var originalBtn=document.createElement('input');
	originalBtn.setAttribute('type','password');
	originalBtn.setAttribute('name',obj.getAttribute('name'));
	password_input.parentNode.replaceChild(originalBtn,password_input);
	originalBtn.focus();
    }

	function replace_username(obj)
    {
	var newO=document.createElement('input');
	newO.setAttribute('type','text');
	newO.setAttribute('name',obj.getAttribute('name'));
	obj.parentNode.replaceChild(newO,obj);
	newO.focus();
	}

