var FormFieldBlur = function(field){
	if(field.value == ""){
		field.value = field.defaultValue;
	}
	else if(field.value == field.defaultValue){
		field.value = "";
	}
}
var lngChng = function(id){
	if(id == "ln_bg"){
		document.getElementById("ln_en").style.display = "none";
	}
	else{
		document.getElementById("ln_bg").style.display = "none";
	}
	document.getElementById(id).style.display = "block";
}
//getting the size of working screen X and Y
function get_scr_size_x(){
	if (document.all) { // IE
		return(document.body.clientWidth);
	}
	else {  // NS
		return(window.innerWidth);
	}
}
function get_scr_size_y(){
	if (document.all) { // IE
		return(document.documentElement.clientHeight);
	}
	else {  // NS
		return(window.innerHeight);
	}
}
var load = function(){
	if(document.getElementById("main")){
		var x = get_scr_size_x();
		if(x < 1250){document.getElementById("main").style.width = 960+"px";}
		else if(x < 1580){document.getElementById("main").style.width = 1270+"px";}
		else{document.getElementById("main").style.width = 1580+"px";}
	}
}
window.onload = function(){load();}
window.onresize = function(){load();}

var checkUN = function(id){
	var oReq = zXmlHttp.createRequest();
	oReq.onreadystatechange = function () {
		if (oReq.readyState == 4) {
			if (oReq.status == 200) {
				var usercheck = oReq.responseText;
				if(id.value.length < 5){
					alert("Потребителското име трябва да е поне 5 символа");
					id.focus();
				}
				else if(usercheck == "false"){
					alert("Потребителското име съществува");
					id.focus();
					id.select();
				}
			}
		}
	};
	oReq.open("GET", "functions.php?checkUserName=true&user="+ id.value, true);
	oReq.send(null);
}
var textCounter = function(fieldID,cntfieldID,maxlimit){
	var field = document.getElementById(fieldID);
	var cntfield = document.getElementById(cntfieldID);
	if(field.value.length > maxlimit){
		field.value = field.value.substring(0, maxlimit);
	}
	else{
		cntfield.innerHTML = maxlimit - field.value.length;
	}
}
var font_size = function(cls){
	document.getElementById("text").className = cls;
}
function flash_posts(){
	var ld = document.getElementById("ld");
	if(ld){ld.style.display = "none";}
	var i = 1;
	var doSetTimeout = function(){
		if(document.getElementById("s_"+i)){
			var s_p = document.getElementById("s_"+i);
			opaci(s_p);
		}
		i++;
		var timer = setTimeout(doSetTimeout,300);
	}
	doSetTimeout();
}
function opaci(id){
	var c = 0;
	var doSetTimeout = function(){
		if(c < 100){
		if(document.all){c+=40;}
		else{c+=10;}
			id.style.filter = "alpha(opacity="+c+")";
			id.style.opacity = eval(c/100);
			var timer = setTimeout(doSetTimeout,30);
		}
	}
	doSetTimeout();
}
var timer = new Array();
function opa(ID,from,to){
	var id = document.getElementById(ID);
	var c = from;
	clearTimeout(timer[ID]);
	if(from < to){
		var doSetTimeout = function(){
			if(c < to){
				c+=10;
				id.style.filter = "alpha(opacity="+c+")";
				id.style.opacity = eval(c/100);
				timer[ID] = setTimeout(doSetTimeout,30);
			}
		}
	}
	else{
		var doSetTimeout = function(){
			if(c > to){
				c-=10;
				id.style.filter = "alpha(opacity="+c+")";
				id.style.opacity = eval(c/100);
				timer[ID] = setTimeout(doSetTimeout,30);
			}
		}
	}
	doSetTimeout();
}
function centerIt(){
	var ld = document.getElementById("ld");
	ld.style.top = (get_scr_size_y()-32)/2+"px";
	ld.style.left = (get_scr_size_x()-141)/2+"px";
}
