function validateObj(id)
{
	var vval = 0;
	obj = document.getElementById(id);
		if (obj.value=='')
			{
				obj.style.backgroundColor="#ffb4b4";
				obj.style.border="1px solid #DD0000";
				vval++;
			}
			else
			{
				obj.style.backgroundColor="";
				obj.style.border="";
			}
			
	return vval;
}

function getObj(id)
{
	return document.getElementById(id);
}

function validateMail(obj)
{
	var vval = 0;
	var obj = document.getElementById(obj);
	
	if (obj.value.length<6 && obj.value.length>128) { vval++; }
	else
	{
		try { window.frames['mail_fr'].location.href = 'mod/ad_item.php?opt=email&vl='+obj.value; }
		catch(error) { }
		
		var chars = Array();
		var q=0;
		
		var msg='';

		for (i=97;i<123;i++)
		{
			chars[q] = String.fromCharCode(i);
			q++;
			}
		
		for (i=65;i<91;i++)
		{
			chars[q] = String.fromCharCode(i);
			q++;
			}
		
		for (i=0;i<10;i++)
		{
			chars[q] = i;
			q++;
			}
		
		var chFind=0;
		
		var tmp = new Array();
		tmp = obj.value;
		tmp = tmp.split('@');
		if (tmp.length!=2) { vval++; }
		else
		{
			for (x=0;x<2;x++)
			{
				for (i=0;i<chars.length;i++)
				{
					tmp = obj.value;
					tmp = tmp.split('@');
					tmp = tmp[x];
					if (tmp.substr(0,1)==chars[i]) { chFind++; }
				}
				if (chFind==0) { vval++; } else { chFind = 0; }
				
				for (i=0;i<chars.length;i++)
				{
					tmp = obj.value;
					tmp = tmp.split('@');
					tmp = tmp[x];
					if (tmp.substr(tmp.length-1,1)==chars[i]) { chFind++; }
				}
				if (chFind==0) { vval++; } else { chFind = 0; }
			}
		}
		
		for (i=0;i<10;i++)
		{
			chars[q] = i;
			q++;
		}
		
		chars[q] = String.fromCharCode(64);
		chars[q+1] = String.fromCharCode(95);
		chars[q+2] = String.fromCharCode(46);
		chars[q+3] = String.fromCharCode(45);
		q+= 3;
		
		var x=0;
		for (i=0;i<obj.value.length;i++)
		{
			var tmp = obj.value;
			tmp = tmp.substr(i,1)
			for (x=0;x<chars.length;x++)
			{
				if (tmp==chars[x]) { chFind++; x = chars.length; }
				}
			if (chFind==0) { vval++; i = obj.value.length; } else { chFind = 0; }
			}
		}
		
		tmp = obj.value;
		tmp = tmp.substr(tmp.length-1,1);
		if (tmp=='.') { vval++; }
		
		tmp = obj.value;
		tmp = tmp.substr(0,1);
		if (tmp=='.') { vval++; }
		
		tmp = obj.value;
		tmp = tmp.split('.');
		for (i=0;i<tmp.length;i++)
		{
			var tmp2 = tmp[i];
			if (tmp2.substr(0,1)=='@' || tmp2.substr(tmp2.length,1)=='@') { vval++; }
			if (tmp[i]=='' || tmp[i]=='@') { vval++; }
		}
		
		if (vval>0) { obj.style.backgroundColor="#ffb4b4"; obj.style.border="1px solid #DD0000"; }
		else { obj.style.backgroundColor=""; obj.style.border=""; }
	
	return vval;
}

function hide_big_photo_frame()
{
	big_photo_frame.style.visibility = "hidden";
	document.images.big_photo_img.src = "images/loading.jpg";
}

function big_photo(img_src)
{
	document.images.big_photo_img.src = img_src;
	big_photo_frame.style.visibility = "visible";
}

function send_msg()
{
	var err = 0;
	
	if (getObj('TCaptcha_bool').value==0)
	{
		getObj('TCaptcha').style.backgroundColor = "#ffb4b4";
		err++;
	}
	else
	{
		getObj('TCaptcha').style.backgroundColor = "";
	}
	
	err+= validateObj('a');
	err+= validateObj('b');
	err+= validateObj('c');

	if (err>0)
	{ alert('Proszę poprawnie wypełnić formularz! Na czerwono zostały zaznaczone pola niewypełnione.'); return false; }
	else { return true; }
}

function selectTh(id,p)
{
	getObj(id).style.filter = 'Alpha(Opacity=' + p + ')';
	getObj(id).style.opacity = (p/100);
}

var bid_global_s = '';
var bid_global_us = '';
var a_global_s = 100;
var a_global_us = 0;
var counter_global_s = '';
var counter_global_us = '';

function selectIt(id)
{
	var bid = 'TCMS'+id;
	bid_global_s = bid;
	
	if (a_global_s>100) { a_global_s = 100; }
	if (a_global_s>=10)
	{
		clearInterval(counter_global_s);
		counter_global_s = setInterval("a_global_s = a_global_s - 10; selectTh(bid_global_s,a_global_s); if (a_global_s<=0) { a_global_s = 100; clearInterval(counter_global_s); }",12);
	}
}
function unSelectIt(id)
{
	var bid = 'TCMS'+id;
	bid_global_us = bid;
	
	if (a_global_us<0) { a_global_us = 0; }
	if (a_global_us<=90)
	{
		clearInterval(counter_global_us);
		counter_global_us = setInterval("a_global_us = a_global_us + 10; selectTh(bid_global_us,a_global_us); if (a_global_us>=100) { a_global_us = 0; clearInterval(counter_global_us); }",12);
	}
}
