var browser_type = 'msie';
var W=navigator.userAgent.toLowerCase();
if(W.indexOf("opera")!=-1){browser_type='opera';}else
if(W.indexOf("msie")!=-1){browser_type='msie';} else
if(W.indexOf("mozilla")!=-1){browser_type='firefox';}




function changeColorTheme(theme, num) {
	color_theme = theme;
	//hideAllSubmenu();
	
	document.getElementById('css_color_theme').href = '/css_new/'+theme+'.css';
	
	document.getElementById('round_green').className = "style_1";
	document.getElementById('round_hard').className = "style_2";
	document.getElementById('round_grunt').className = "style_3";
	
	document.getElementById('round_'+theme).className = "style_"+num+" style_active";
	
	
	var url = base_url+"/ajax_request/change_theme.php?theme="+theme;
	var jsel = document.createElement('SCRIPT');
	jsel.type = 'text/javascript';
	jsel.src = url;
	document.getElementById('js').appendChild(jsel);

}



function showNotice() {
	document.getElementById('div_trans').style.height = document.body.scrollHeight+"px";
	document.getElementById('div_trans').style.display = "block";
	//alert(2);
	var width = "300";
	var height = "200";
	var left = (screen.width  - width)  / 2;
	var top = (screen.height - height) / 3 + document.body.scrollTop;

	document.getElementById('notice_div').style.left = left+"px";
	document.getElementById('notice_div').style.top = top+"px";
	
	document.getElementById('notice_div').style.display = "block";
	
	document.onkeypress = closeNoticeEscape;
}



function closeNotice() {
	document.getElementById('div_trans').style.display = "none";
	document.getElementById('notice_div').style.display = "none";
}



function closeNoticeEscape(e) {
	if (!e) e = window.event;
	var k = e.keyCode;
	
	if (k == 27) closeNotice();

}



function showRegistrationForm() {
	closeLogin();
	
	document.getElementById('div_trans').style.height = document.body.scrollHeight+"px";
	document.getElementById('div_trans').style.display = "block";
	//alert(2);
	var width = "330";
	var height = "205";
	var left = (screen.width  - width)  / 2;
	var top = (screen.height - height) / 3 + document.body.scrollTop;

	document.getElementById('registration_block_div').style.left = left+"px";
	document.getElementById('registration_block_div').style.top = top+"px";
	
	document.getElementById('registration_block_div').style.display = "block";
}



function closeRegistration() {
	document.getElementById('div_trans').style.display = "none";
	document.getElementById('registration_block_div').style.display = "none";
}




function showLogin() {
	document.getElementById('div_trans').style.height = document.body.scrollHeight+"px";
	document.getElementById('div_trans').style.display = "block";
	//alert(2);
	var width = "330";
	var height = "200";
	var left = (screen.width  - width)  / 2;
	var top = (screen.height - height) / 3 + document.body.scrollTop;

	document.getElementById('login_block_div').style.left = left+"px";
	document.getElementById('login_block_div').style.top = top+"px";
	
	document.getElementById('login_block_div').style.display = "block";
}





function closeLogin() {
	document.getElementById('div_trans').style.display = "none";
	document.getElementById('login_block_div').style.display = "none";
}



function showForgotPassword() {
	closeLogin()
	
	document.getElementById('div_trans').style.height = document.body.scrollHeight+"px";
	document.getElementById('div_trans').style.display = "block";
	//alert(2);
	var width = "330";
	var height = "200";
	var left = (screen.width  - width)  / 2;
	var top = (screen.height - height) / 3 + document.body.scrollTop;

	document.getElementById('forgot_password_block_div').style.left = left+"px";
	document.getElementById('forgot_password_block_div').style.top = top+"px";
	
	document.getElementById('forgot_password_block_div').style.display = "block";
}





function closeForgotPassword() {
	document.getElementById('div_trans').style.display = "none";
	document.getElementById('forgot_password_block_div').style.display = "none";
}


function changeHeight() {
	document.getElementById('main_tbl').style.height = (window.innerHeight - 55 - 114) + "px";
}



var switch_to_rte = 0;

function commentToPlain(id) {
	document.getElementById('td_commet_mark_plain').className = "selected";
	document.getElementById('td_commet_mark_editor').className = "";
	if (switch_to_rte == 1) toggleEditor(id);
	
	if (document.getElementById('div_comment_form_b1')) {
		document.getElementById('div_comment_form_b1').className = "or_block_tr";
		document.getElementById('div_comment_form_b2').className = "or_block_tl";
		document.getElementById('div_comment_form_b3').className = "or_block_tc";
		document.getElementById('div_comment_form_b4').className = "or_block_m";
		document.getElementById('div_comment_form_b5').className = "or_block_inner";
		document.getElementById('div_comment_form_b6').className = "or_block_br";
		document.getElementById('div_comment_form_b7').className = "or_block_bl";
		document.getElementById('div_comment_form_b8').className = "or_block_bc";
	}
}


function commentToEditor(id) {
	document.getElementById('td_commet_mark_plain').className = "";
	document.getElementById('td_commet_mark_editor').className = "selected";
	if (switch_to_rte == 0) toggleEditor(id);
	
	if (document.getElementById('div_comment_form_b1')) {
		document.getElementById('div_comment_form_b1').className = "";
		document.getElementById('div_comment_form_b2').className = "";
		document.getElementById('div_comment_form_b3').className = "";
		document.getElementById('div_comment_form_b4').className = "";
		document.getElementById('div_comment_form_b5').className = "";
		document.getElementById('div_comment_form_b6').className = "";
		document.getElementById('div_comment_form_b7').className = "";
		document.getElementById('div_comment_form_b8').className = "";
	}
}



function toggleEditor(id) {
	
	if (!tinyMCE.get(id)) {
		tinyMCE.execCommand('mceAddControl', false, id);
		switch_to_rte = 1;
	}
	else {
		tinyMCE.execCommand('mceRemoveControl', false, id);
		switch_to_rte = 0;
	}
	
}



function makeEditor(id){
	tinyMCE.execCommand('mceAddControl', false, id);
}


function unmakeEditor(id) {
	tinyMCE.execCommand('mceRemoveControl', false, id);
}



function matchSms(match_id) {
	document.getElementById('match_sms_id').value=match_id;
	//document.getElementById('match_sms_phone').value="";
	if (document.getElementById('img_sec_code')) document.getElementById('img_sec_code').src = "/images/security_code.php";
	
	document.getElementById('div_trans').style.height = document.body.scrollHeight+"px";
	document.getElementById('div_trans').style.display = "block";
	//alert(2);
	var width = "450";
	var height = "200";
	var left = (screen.width  - width)  / 2;
	var top = (screen.height - height) / 3 + document.body.scrollTop;

	document.getElementById('div_match_sms').style.left = left+"px";
	document.getElementById('div_match_sms').style.top = top+"px";
	
	document.getElementById('div_match_sms').style.display = "block";
}


function closeMatchSms() {
	document.getElementById('match_sms_id').value="";
	//document.getElementById('match_sms_phone').value="";
	if (document.getElementById('img_sec_code')) document.getElementById('img_sec_code').src = "/images/spacer.gif";
	
	document.getElementById('div_trans').style.display = "none";
	document.getElementById('div_match_sms').style.display = "none";
	//document.getElementById('match_sms_phone').value = "";
}


function saveMatchSms() {
	if (document.getElementById('match_sms_phone').value) {
		var sec_code = "";
		if (document.getElementById('sms_sec_code')) sec_code = document.getElementById('sms_sec_code').value;
		
		var url = base_url+"/ajax_request/save_match_sms.php?match_id="+document.getElementById('match_sms_id').value+"&phone="+document.getElementById('match_sms_phone').value+"&sec_code="+sec_code;
		var jsel = document.createElement('SCRIPT');
		jsel.type = 'text/javascript';
		jsel.src = url;
		document.getElementById('js').appendChild(jsel);
	}
	else {
		alert("Введите номер мобильного телефона");
	}
}


function blockMatchSms(match_id) {
	document.getElementById('td_match_sms_link_'+match_id).innerHTML = 'Вы получите результат';
}



function confirmdel(url) {
	message = 'Вы уверены что хотите удалить?';
	
	if (confirm(message)) {
		if (browser_type == "firefox") {
			self.location.href = url;
		}
		else {
			document.getElementById('link').href = url;
			document.getElementById('link').click();
		}
	}
}



function changeBlockForumList(mark) {
	
	if (mark == "popular") {
		document.getElementById('td_forum_block_popular').className = "selected";
		document.getElementById('td_forum_block_new').className = "";
	}
	
	else {
		document.getElementById('td_forum_block_popular').className = "";
		document.getElementById('td_forum_block_new').className = "selected";
	}
	
	document.getElementById('div_form_block').innerHTML = '<img src="/images/loading.gif" width="36" height="36" alt="" style="padding-left:92px; padding-top:90px; padding-bottom:90px;">';
	
	
	var url = base_url+"/ajax_request/load_forum_block.php?mark="+mark;
	var jsel = document.createElement('SCRIPT');
	jsel.type = 'text/javascript';
	jsel.src = url;
	document.getElementById('js').appendChild(jsel);
	
}



// VOTING

function showVotingArchive(voting_id) {
	document.getElementById('div_voting_btn').style.display = 'none';
	document.getElementById('div_voting_data').innerHTML = '<img src="/images/loading.gif" width="50" height="50" alt="" style="padding:70px 0px 70px 85px;">';
	document.getElementById('voting_result_btn').innerHTML = '<a href="/voting/">Архив</a>';
	
	var url = base_url+"/ajax_request/load_voting_results.php?voting_id="+voting_id;
	var jsel = document.createElement('SCRIPT');
	jsel.type = 'text/javascript';
	jsel.src = url;
	document.getElementById('js').appendChild(jsel);
}



function votingMakeVote(voting_id) {
	
	var var_href = "";
	
	if (voting_type == 'o') {
		var_href = "&answer_id[]="+votingRadioBox.obj.find("input").val();
	}
	
	else {
	
		for (i = 0; i < answer_qty; i++) {
			if (votingCheckBox[i].checked == true) {
				var_href += "&answer_id[]="+votingCheckBox[i].value;
			}
		}
	
	}
	
	
	
	document.getElementById('div_voting_btn').style.display = 'none';
	document.getElementById('div_voting_data').innerHTML = '<img src="/images/loading.gif" width="50" height="50" alt="" style="padding:70px 0px 70px 85px;">';
	
	
	var url = base_url+"/ajax_request/make_voting_vote.php?voting_id="+voting_id+var_href;
	var jsel = document.createElement('SCRIPT');
	jsel.type = 'text/javascript';
	jsel.src = url;
	document.getElementById('js').appendChild(jsel);
	
}


function tr_over(tr) {
	tr.className = 'tr_over';
}


function tr_out(tr) {
	tr.className = '';
}



function getNextFact(type, item_id, module_id) {
	var url = base_url+"/ajax_request/show_fact.php?type="+type+"&item_id="+item_id+"&module_id="+module_id;
	var jsel = document.createElement('SCRIPT');
	jsel.type = 'text/javascript';
	jsel.src = url;
	document.getElementById('js').appendChild(jsel);
}