var isOpera = (navigator.userAgent.toLowerCase().indexOf("opera") > -1 ? 1 : 0);
var isIE = (navigator.userAgent.toLowerCase().indexOf("msie") > -1 ? 1 : 0);

function $(name) {
	return document.getElementById(name);
}

function clock() {
	now= new Date();
	var arMonth=new Array('Января', 'Февраля', 'Марта', 'Апреля', 'Мая', 'Июня', 'Июля', 'Августа', 'Сентября', 'Октября', 'Ноября', 'Декабря');
	var arWeekDay={'Mon':'Понедельник', 'Tue':'Вторник', 'Wed':'Среда', 'Thu':'Четверг', 'Fri':'Пятница', 'Sat':'Суббота', 'Sub':'Воскресенье'};


	var date= now.getDate();
	var month= arMonth[now.getMonth()];
	var year= now.getYear();
	var hours= now.getHours();
	var minutes= now.getMinutes();
	var gmt=now.toGMTString();

	var weekDayStr=gmt.match(/^[^,]+/i);
	var weekDay=arWeekDay[weekDayStr];

	if(date<10)	date='0'+date;
	if(month<10)	month='0'+month;
	var str="Суббота, "+date+" "+month+", "+hours+":"+minutes;

	document.getElementById('date').innerHTML=str;
	//document.write=str;
	setTimeout("clock()",1000);

}






function wait(id) {
	$(id).innerHTML='<img src="http://www.realtors.com.ua/images/icon/wait.gif" width="16" height="16" align=absmiddle>';
}

function ready(id) {
	$(id).innerHTML='';
}


function getpass(id)
    {
    document.getElementById("userpswd"+id).style.display='';
    document.getElementById("psevdopass"+id).style.display='none';
    document.getElementById("userpswd"+id).focus();
    }


function makeStart(url) {
    if (isIE) document.write('<a href="" onClick="this.style.behavior=\'url(#default#homepage)\';this.setHomePage(\''+url+'\');return false;" >'+lang['make_start']+'</a>');
}

function show_media(file, vars, width, height, bgcolor) {
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+ width + '" height="' + height + '" id="test_draw" align="middle"><param name="allowScriptAccess" value="sameDomain" /><PARAM NAME=FlashVars VALUE="' + vars + '"><param name="movie" value="'+ file + '" /><param name="quality" value="high" /><param name="bgcolor" value="'+ bgcolor + '" /><embed src="'+ file + '" FlashVars="' + vars + '"  quality="high" bgcolor="' + bgcolor + '" width="' + width + '" height="' + height + '" name="test_draw" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>');
}


function star_out(rate) {
	for(i=1;i<=5;i++) {
		num=rate.substring(i-1,i);

		if (num==1) im='orange';
		else if (num==2) im='grey';
		else im='half_grey';
		document.getElementById('star'+i).src="/img/star_" + im + ".gif";
	}
}


function star_over(number) {
	for(i=1;i<=5;i++) {
		if(i<=number) im='star_orange.gif'; else im='star_grey.gif';
		document.getElementById('star'+i).src="/img/"+im;
	}
}

function star_fireup(id) {
	for ( var i=1; i<=id ;i++) {
		document.getElementById('star'+i).src="/img/star_orange.gif";
	}
	for ( true; i<=5 ;i++){
	document.getElementById('star'+i).src="/img/star_grey.gif";
	}
}


function gamesViewCount(id) {
    JsHttpRequest.query(
        '/view_count/',
        {id: id},
        function(responseJS, responseText) {},
        true
    );
	return false;
}

function gamesVoteCount(id, ball) {
    JsHttpRequest.query(
        '/vote_count/',
        {id: id, ball: ball},
        function(responseJS, responseText) {
			if (responseJS.error!='') {
				alert(responseJS.error)	;
			} else {
				//star_fireup(ball, 1);
				//alert(responseJS.rate);
				$('stars').innerHTML=responseJS.stars;
			}
		},
        true
    );
	return false;
}

function changeCapcha(num) {
	$('capcha'+num).src="http://www."+mainDomain+"/captcha33/?num="+num+"&t="+Math.random();
	return false;
}

function myonlineStat(moduleIdFrom, moduleIdTo) {
    JsHttpRequest.query(
        'http://www.'+mainDomain+'/myonline_stat/',
        {moduleIdFrom: moduleIdFrom, moduleIdTo: moduleIdTo},
        function(responseJS, responseText) {},
        true
    );
	return true;
}

function stat(id) {
    JsHttpRequest.query(
        'http://www.'+mainDomain+'/stat/',
        {id: id},
        function(responseJS, responseText) {},
        true
    );
	return true;
}

// stat, r0mk1n

function __mmad( dm ) {
	var is_exists = __rC( '__onmad' );
	if ( !is_exists || is_exists == null ) {
		__wC( '__onmad', __gMID(), 730, dm );
	} else {
		__wC( '__onmad', is_exists, 730, dm );
	}
}

function __gMID() {
	var date = new Date();
	return Math.ceil( Math.random() * 999999 * ( date.getTime() + ( date.getTime() * Math.random() * 999 ) + Math.random() * 99999 ) ).toString().substring(0, 8) + '' + Math.ceil( Math.random() * 999999 * ( date.getTime() + ( date.getTime() * Math.random() * 999 ) + Math.random() * 99999 ) ).toString().substring(0, 8)+ '' + Math.ceil( Math.random() * 999999 * ( date.getTime() + ( date.getTime() * Math.random() * 999 ) + Math.random() * 99999 ) ).toString().substring(0, 8);
}

function __wC( name, value, days, dm ) {
	var expires = "";
	if ( days ) {
		var date = new Date();
		date.setTime( date.getTime()+(days*24*60*60*1000) );
		expires = "; expires="+date.toGMTString();
	}
	document.cookie = name+"="+value+expires+"; path=/; domain="+dm;
}

function __rC( 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 __eC( name ) {
	writeCookie( name, "", -1 );
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}