function rollOver(element)
{
	for( var x = 0; element.childNodes[x]; x++ )
	{
		if( element.childNodes[x].tagName == 'UL' )
				element.childNodes[x].style.display = 'block';
	}
}

function rollOut(element)
{
	for( var x = 0; element.childNodes[x]; x++ )
	{
		if( element.childNodes[x].tagName == 'UL' )
				element.childNodes[x].style.display = 'none';
	}
}

function preloadImages()
{
	var imgList = preloadImages.arguments;
	var img = new Array();
	for(var i = 0; i < imgList.length; i++)
	{
		img[i] = new Image();
		img[i].src = imgList[i];
	}
}

function opennew(url)
{
	nw1=window.open(url,'nw1','scrollbars=1,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=1,width=650,height=650');
	nw1.focus();
}

PositionX = 100;
PositionY = 100;
defaultWidth  = 820;
defaultHeight = 620;
var AutoClose = true;
if (parseInt(navigator.appVersion.charAt(0))>=4)
{
  var isNN = (navigator.appName == "Netscape") ? 1 : 0;
  var isIE = (navigator.appName.indexOf("Microsoft") != -1) ? 1 : 0;
}
var optNN = 'scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE = 'scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;

function popImage(imageURL, imageTitle)
{
  if (isNN){imgWin=window.open('about:blank','',optNN);}
  if (isIE){imgWin=window.open('about:blank','',optIE);}
  with (imgWin.document)
  {
    writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');
    writeln('<sc'+'ript>');
    writeln('var isNN,isIE;');
    writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
    writeln('isNN=(navigator.appName=="Netscape")?1:0;');
    writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
    writeln('function reSizeToImage(){');
    writeln('if (isIE){');
    writeln('window.resizeTo(100,100);');
    writeln('width=123-(document.body.clientWidth-document.images[0].width);');
    writeln('height=100-(document.body.clientHeight-document.images[0].height);');
    writeln('window.resizeTo(width,height);}');
    writeln('if (isNN){');
    writeln('window.innerWidth=document.images["George"].width;');
    writeln('window.innerHeight=document.images["George"].height;}}');
    writeln('function doTitle(){document.title="'+imageTitle+'";}');
    writeln('</sc'+'ript>');
    if (!AutoClose)
      writeln('</head><body scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
    else
      writeln('</head><body scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
    writeln('<DIV align="center"><img name="George" src='+imageURL+' style="display:block"></DIV></body></html>');
    close();
  }
}


function go2(params, url, id) {
	if (params.comment.length==0)
	{
		alert ('Please enter some text');
		return false;
	}

	var thelist2 = $('thelist2_'+id);
	thelist2.update('<img src="http://img.informer.com/images/loading1.gif" border=0>');

	new Ajax.Request('/submit_comment.php',
		{
			method: 'post',
			parameters:params,
			onSuccess: function(transport)
			{
				if (transport.responseText=='OK')
				{
					if (url)
						top.location.href = url;
					else
						window.location.reload();
				} else {
					if (transport.responseText.length>=400)
					{
					//	alert(transport.responseText);
						thelist2.update('<span style="color:#aa0000;"><b>Unknown error</b></span>');
					}
					else
						thelist2.update(transport.responseText);
				}
			}
		}
	);
}

function go3(params, url, id) {

	if (params.comment.length==0)
	{
		alert ('Please enter some text');
		document.programm_qa_form2.comment.focus();
		return false;
	}

	var thelist2 = $('thelist2_'+id);
	thelist2.update('<img src="http://img.informer.com/images/loading1.gif" border=0>');
	new Ajax.Request('/submit_question.php',
		{
			method: 'post',
			parameters:params,
			onSuccess: function(transport)
			{
				if (transport.responseText=='OK')
				{
					if (url)
						top.location.href = url;
					else
						window.location.reload();
				} else {
					if (transport.responseText.length>=400)
					{
					//	alert(transport.responseText);
						thelist2.update('<span style="color:#aa0000;"><b>Unknown error</b></span>');
					}
					else
						thelist2.update(transport.responseText);
				}
			}
		}
	);
}

function go4(params)
{
	url = '';
	if (params.message.length==0)
	{
		alert ('Please enter some text');
		return false;
	}

	if (params.message_subject.length > 30)
	{
		alert ('Please, enter message subject less than 30 symbols length');
		return false;
	}

	var thelist2 = $('message_error');
	thelist2.update('<img src="http://img.informer.com/images/loading1.gif" border=0>');

	new Ajax.Request('/send_message.php',
		{
			method: 'post',
			parameters:params,
			onSuccess: function(transport)
			{
				if (transport.responseText=='OK')
				{
					var form = $('pm_sent_form');
					var message_error = $('message_error');
					message_error.innerHTML = '';
					form.parentNode.innerHTML = 'Your message was sent succesfully.&nbsp;&nbsp;&nbsp;<a href="#" onclick="close_sendmessage()">Close</a>';
				}
				else
				{
					var message_error = $('message_error');
					message_error.innerHTML = transport.responseText;
				}
			}
		}
	);
}

function adv_srch()
{
	var s = document.getElementById('block5');

	if (s.style.display=='none')
	{
		new Effect.Appear('block5',{duration:0.4});
		new Effect.Fade('adv_srch',{duration:0});}
	else
	{
		new Effect.Fade('block5',{duration:0.3});
	}
	return false;
}

function flagit(fld) // for settings page
{
	if (fld)
		cflag.src='/images/flags/' + fld.toLowerCase() + '.gif';
	else
		cflag.src='/images/flags/-.gif';
}

function rsearch() // related searches dropdown on index page
{
	var rs = document.getElementById('rs');
	var rs1= document.getElementById('rs1');//image below
	var rs2= document.getElementById('rs2');//image
	var pr = document.getElementById('profile');

	if (pr)
		pr.style.display='none'; // hide another div

	rs.style.display='block';
	rs2.src='http://img.informer.com/images/rs1_.gif';

	moretime_rs();
	return false;
}
function moretime_rs()
{
	try
	{
  		if (id2) clearTimeout(id2);
	}
	catch (exc)
	{

	}
}
function onout_rs()
{
  id2 = setTimeout( "hidediv_rs()", 500); // seconds delay to close div
}
function hidediv_rs()
{
  var rs  = document.getElementById('rs');
  var rs1 = document.getElementById('rs1');

  rs.style.display='none';
  rs1.src='http://img.informer.com/images/rs.png';
}


function muser() // dropdown on index page
{
	var pr = document.getElementById('profile');
	var rs = document.getElementById('rs');

	if (rs)
		rs.style.display='none'; // hide another div

	if (pr.style.display=='none')
	{
		pr.style.display='block';
		moretime();
	}
	else
		pr.style.display='none';

	return false;
}
function moretime()
{
	try
	{
  		if (id) clearTimeout(id);
	}
	catch (exc)
	{

	}

}

function onout()
{
  id = setTimeout( "hidediv()", 500); // seconds delay to close div
}

function hidediv()
{
  var d = document.getElementById('profile');
  d.style.display = 'none';
}


function ValidReg()
{
	var d = document.form;

	if (d.MailReg.value.length<5)
	{
		d.MailReg.style.border = '1px solid red';
		d.MailReg.focus();
		alert ('Please enter your e-mail');
		return false;
	}

	if (d.UserName2Reg.value.length<2)
	{
		d.UserName2Reg.style.border = '1px solid red';
		d.UserName2Reg.focus();
		alert ('Please enter your name');
		return false;
	}

	if (d.UserPassReg.value=='')
	{
		d.UserPassReg.style.border = '1px solid red';
		d.UserPassReg.focus();
		alert ('Please enter password');
		return false;
	}
	if (d.ConfirmPassReg.value=='')
	{
		d.ConfirmPassReg.style.border = '1px solid red';
		d.ConfirmPassReg.focus();
		alert ('Please confirm password');
		return false;
	}

	if (d.keystring && d.keystring.value.length<3)
	{
		d.keystring.style.border = '1px solid red';
		d.keystring.focus();
		alert ('Please enter code');
		return false;
	}
}






// change e-mail scripts

function change_myemail()
{
	var d = document.getElementById('renamese');
	load_changemailwin(d);
	d.style.display = 'block';
}

function submit_change_myemail(d)
{
	var email = d.parentNode.parentNode.getElementsByTagName('input')[0].value;
	if (email.length < 1)
	{
		alert("Please enter the e-mail address");
		return false;
	}
	if (update_myemail(email))
	{
		alert("An error occurred while saving the e-mail.");
		return false;
	}

//	hide_change_myemail();
	return true;
}

function hide_change_myemail()
{
    var d = document.getElementById('renamese');
	d.style.display = 'none';
}

function update_myemail(email)
{
	var d  = document.getElementById('merr');
	var d1 = document.getElementById('renamese1');
	d.innerHTML = '<br>Please wait...';// <img src="http://img.informer.com/images/loading1.gif" border="0" align="absmiddle" />';
	new Ajax.Request('/ajax/change_email.php?email='+email,
		{
			method: "GET",
			onSuccess: function(transport)
			{
				d.innerHTML = transport.responseText;
				d.style.display = 'block';

				if (transport.responseText.match(new RegExp("updated successfully", "i")) )
				{
					d1.innerHTML = email;
					hide_change_myemail();
				}
			}
		}
	);

	return false;
}

function load_changemailwin(id)
{
	id1 = id
	if (receiveReq.readyState == 4 || receiveReq.readyState == 0)
	{
		receiveReq.open("GET", '/ajax/change_email_win.php', true);
		receiveReq.onreadystatechange = handlePercent;
		receiveReq.send(null);
	}
}


function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest(); //Not IE
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP"); //IE
	} else {
		alert("Your browser doesn't support the XmlHttpRequest object.  Better upgrade to Firefox.");
	}
}
var receiveReq  = getXmlHttpRequestObject();
function handlePercent() {
	if (receiveReq.readyState == 4) {
//		document.getElementById(id1).innerHTML = receiveReq.responseText;
		id1.innerHTML = receiveReq.responseText;
	}
}

function addEvent(elm, evType, fn, useCapture)
{
  if (elm.addEventListener){
    elm.addEventListener(evType, fn, useCapture);
    return true;
  } else if (elm.attachEvent){
    var r = elm.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Please upgrade your browser to use full functionality on this page");
  }
}

// end for change e-mail scripts


function shtab(i)
{
	try
	{
		$('tab_'+i).className = 'select_tab';
		if (i!=1)
		{
			$('ibox_1').style.display = 'none';
		//	new Effect.Fade('ibox_1',{duration:0.0});
			$('tab_1').className = '';
		}
		if (i!=2)
		{
			$('ibox_2').style.display = 'none';
		//	new Effect.Fade('ibox_2',{duration:0.0});
			$('tab_2').className = '';
		}
		if (i!=3)
		{
			$('ibox_3').style.display = 'none';
		//	new Effect.Fade('ibox_3',{duration:0.0});
			$('tab_3').className = '';
		}
		if (i!=4)
		{
			$('ibox_4').style.display = 'none';
		//	new Effect.Fade('ibox_4',{duration:0.0});
			$('tab_4').className = '';
		}
		if (i!=5)
		{
			$('ibox_5').style.display = 'none';
		//	new Effect.Fade('ibox_5',{duration:0.0});
			$('tab_5').className = '';
		}
		new Effect.Appear('ibox_'+i,{duration:0.2});
		createCookie('shtab', i, 365);
	}catch(exc){}
}

function set_shtab()
{
	var i=readCookie('shtab');
	if (i) shtab(i);
}

function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";

	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');

	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}

	return null;
}

function bundle(id)
{
	var bundle = document.getElementById('bundle'+id);
	var plus = document.getElementById('plus'+id);

	if (bundle.style.display=='none' || bundle.style.display=="")
	{
		plus.src = 'http://img.informer.com/images/minus1.gif';

		if (isIE2())
			bundle.style.display = 'block';
		else
			bundle.style.display = 'table-cell';
	}
	else
	{
		plus.src = 'http://img.informer.com/images/plus1.gif';
		bundle.style.display = 'none';
	}
}

function isIE2()
{
//	alert("Browser: " + navigator.appName + "\nVersion: " + navigator.userAgent);
//	����������� ��������� ������ ������ ��� IE
//	var ua = navigator.userAgent;
//	var IEoffset = ua.indexOf("MSIE ");
//	var MSIEVersionNumber = parseFloat(ua.substring(IEoffset+5, ua.indexOf(";", IEoffset)));
//	alert("MSIE version: " + MSIEVersionNumber);

	if (navigator.appName=='Microsoft Internet Explorer')
		return true;
	else
		return false;
}


var tooltip=function(){
	var id = 'tt';
	var top = 3;
	var left = 3;
	var maxw = 300;
	var speed = 10;
	var timer = 20;
	var endalpha = 95;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	return{
		show:function(v,w){

			// v = id
			var t1 = document.getElementById('desc_'+v).innerHTML;
			var t2 = fDesc[v];

			t1 = t1.replace(/<\/?[^>]+>/gi, ''); // strip tags

			v = t1 +' '+ t2;

			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				t = document.createElement('div');
				t.setAttribute('id',id + 'top');
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				b = document.createElement('div');
				b.setAttribute('id',id + 'bot');
				tt.appendChild(t);
				tt.appendChild(c);
				tt.appendChild(b);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';
			c.innerHTML = v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				t.style.display = 'none';
				b.style.display = 'none';
				tt.style.width = tt.offsetWidth;
				t.style.display = 'block';
				b.style.display = 'block';
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(e){
			var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
			var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
			tt.style.top = (u - h) + 'px';
			tt.style.left = (l + left) + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();

function openChat(d)
{
	try
	{
		var swidth = screen.width;
		var sheight = screen.height;

		var top = 0;
		var left = 0;


		if (swidth < 1250)
		{
			if (d.href.indexOf('uid') != -1)
				var popupWin = window.open(d.href+'&w='+swidth, 'SI Chat', 'width='+swidth+', height='+sheight);
			else
				var popupWin = window.open(d.href+'?w='+swidth, 'SI Chat', 'width='+swidth+', height='+sheight);
		}
		else
		{
			left = (swidth - 1250) / 2;
			top = (sheight - 650) / 2;
			var popupWin = window.open(d.href, 'SI Chat', 'width=1250, height=650, left='+left+',top='+top);
		}


		popupWin.focus();
		return false;
	} catch (exc) {
		return false;
	}
}