isDOM=document.getElementById?true:false
isOpera=isOpera5=window.opera && isDOM
isOpera6=isOpera && window.print
isOpera7=isOpera && document.readyState
isMSIE=isIE=document.all && document.all.item && !isOpera
isStrict=document.compatMode=='CSS1Compat'
isNN=isNC=navigator.appName=="Netscape"
isNN4=isNC4=isNN && !isDOM
isMozilla=isNN6=isNN && isDOM
var pageLeft=0
var pageTop=0
var root = window.addEventListener || window.attachEvent ? window : document.addEventListener ? document : null;
if (root.addEventListener) root.addEventListener("load", onPageLoad, false);
else if (root.attachEvent) root.attachEvent("onload", onPageLoad);





function $$(sId){
	if(document.getElementById(sId))
		return document.getElementById(sId)
	else
		return false
}

function onPageLoad(){	
	//alert('esfesf');
	createInvMnenieBox();
	
	if (root.addEventListener)
		root.addEventListener("click", closeUsersBox, false);
	else if (root.attachEvent){
		//alert('ok');
		document.attachEvent("onclick", closeUsersBox);
		
	}
}


function closeUsersBox(){
	//alert('esf')
	if($$('users_list_box')){
		$$('users_list_box').innerHTML = '';
	}
	
	if($$('users_list_box1')){
		$$('users_list_box1').innerHTML = '';
	}
	
	if($$('users_list_box2')){
		$$('users_list_box2').innerHTML = '';
	}
	
	//document.getElementById('users_list_box').innerHTML = ''
}

function setBigPhoto(sId, sUrl, sWidth, sHeight, sAlt, sTitle){
	$$(sId).src = sUrl
	$$(sId).alt = sAlt
	$$(sId).title = sTitle
	$$(sId).style.width = sWidth + 'px'
	$$(sId).style.height = sHeight + 'px'
	
	return true;
}

function orderBezNal(){
	document.getElementById('order_nal').style.display = 'none';
	document.getElementById('order_beznal').style.display = 'block';
	
	document.getElementById('order_nal_a').style.fontWeight = 'normal';
	document.getElementById('order_beznal_a').style.fontWeight = 'bold';
	
	
}

function orderNal(){
	document.getElementById('order_beznal').style.display = 'none';
	document.getElementById('order_nal').style.display = 'block';
	
	document.getElementById('order_beznal_a').style.fontWeight = 'normal';
	document.getElementById('order_nal_a').style.fontWeight = 'bold';
}


function getUsersSelectBox(sStringSearch) {
	
	$$('users_box_td').left = _getAbsoluteLeft($('input_USER_ID'))
	$$('users_box_td').top = _getAbsoluteTop($('input_USER_ID'))
	JsHttpRequest.query(
		'/pimax/ajax.get_users_select.php', 
		{
			'string': sStringSearch
		},		
		function(result, errors) {
			closeUsersBox();
			$$("users_list_box").innerHTML = result["res"];
		}, 
		true,
		"users_list_box"
	);      
}

function getUsersSelectBoxAdd(sStringSearch, sOrder, nFil) {
	if($$("users_list_box" + nFil).innerHTML == ''){
		$$('users_box_td').left = _getAbsoluteLeft($('USER' + nFil + '_TEXT'))
		$$('users_box_td').top = _getAbsoluteTop($('USER' + nFil + '_TEXT'))
		JsHttpRequest.query(
			'/pimax/ajax.get_users_select_spor.php', 
			{
				'string': sStringSearch,
				'order': sOrder,
				'fil': nFil
			},		
			function(result, errors) {
				closeUsersBox();
				$$("users_list_box" + nFil).innerHTML = result["res"];
			}, 
			true
			
		);     
	}else{
		closeUsersBox();
	}
}
function setUserForSpor(sLogin, nId, nFil){
	//closeUsersBox();
	document.getElementById('USER' + nFil + '_TEXT').value = sLogin
	document.getElementById('USER' + nFil + '_ID').value = nId
	document.getElementById('users_list_box' + nFil).innerHTML = ''
}
function setUserName(sLogin, nId){
	//closeUsersBox();
	document.getElementById('input_USER_ID').value = sLogin
	document.getElementById('USER_ID').value = nId
	document.getElementById('users_list_box').innerHTML = ''
}


function _getAbsoluteLeft(o){
	return _getPageOffset(o)[0]-pageLeft
}

function _getAbsoluteTop(o){
	return _getPageOffset(o)[1]-pageTop
}


function getWidth(o){
  //var o=this.object
  if(isMSIE || isMozilla || isOpera7) return o.offsetWidth
 // if(isOpera) return this.css.pixelWidth
  //if(isNN4) return o.document.width
}

function getHeight(o){
	if(isMSIE || isMozilla || isOpera7) return o.offsetHeight
}

function _getPageOffset(o){ 
  var _left=0
  var _top=0
  do{
    _left+= o.offsetLeft
    _top+= o.offsetTop
  }while(o = o.offsetParent)
  return [_left, _top]
}

function getUserIdByLogin(sInElementId, sOutElementId){
	//alert(document.getElementById(sInElementId).value)
	//alert(document.getElementById(sOutElementId).value)
	var sInValue = document.getElementById(sInElementId).value;
	//var nOutValue = 
	JsHttpRequest.query(
		'http://sporshiki.ru/pimax/ajax.getUserId.php', 
		{
			'sUserLogin': sInValue
			
		},		
		function(result, errors) {
			document.getElementById(sOutElementId).value = result["res"];
		}, 
		true
	);   
}


function checkSporsAddForm(nUserId){
	JsHttpRequest.query(
		'/pimax/ajax.add_spor_check.php', 
		{
			'nUserId': nUserId,
			'TemaSpora': $$('TemaSpora').value,
			'CategorySpor': $$('CategorySpor').value,
			'DescrSpor': $$('DescrSpor').value,
			'TypeSpor': $$('TypeSpor').value,
			'VozSpor': $$('VozSpor').value,
			'SizeVozSpor': $$('SizeVozSpor').value,
			'DateEndSpor': $$('f_date_PROPERTY_7').value,
			'USER1_ID': $$('USER1_ID').value,
			'USER2_ID': $$('USER2_ID').value,
			'CaptchaSpor': $$('CaptchaSpor').value,
			'CaptchaSid': $$('CaptchaSid').value
			
		},		
		function(result, errors) {
			$$("spors_status_div").innerHTML = '';
			if(result["res"] == ''){
				$$("spors_error_div").innerHTML = '';
				//alert('ok');
				$$('spor_add_form_id').submit();
			}else{
				//location.href = '#spors_error_div';
				scroll(0,0);
				$$("spors_error_div").innerHTML = result["res"];
			}
			//$("users_list_box" + nFil).innerHTML = result["res"];
		}, 
		true
	);      
	
	//alert('good')
}

function checkOutMoney(nUserId){
	JsHttpRequest.query(
		'/pimax/ajax.out_money_check.php', 
		{
			'nUserId': nUserId,
			'TYPE_TEXT': $$('TYPE_TEXT').value,
			'NUMBER_TEXT': $$('NUMBER_TEXT').value,
			'SUMM_TEXT': $$('SUMM_TEXT').value			
		},		
		function(result, errors) {
			$$("spors_status_div").innerHTML = '';
			if(result["res"] == ''){
				$$("spors_error_div").innerHTML = '';
				//alert('ok');
				$$('spor_add_form_id').submit();
			}else{
				$$("spors_error_div").innerHTML = result["res"];
			}
			//$("users_list_box" + nFil).innerHTML = result["res"];
		}, 
		true,
		"spors_status_div"
	);      
	
	//alert('good')
}


function showHideCommentAddForm(sId){
	$("#" + sId).slideToggle("slow", function () { 	} );
}


function showHideHelping(oObj, sId){
	if($$(sId).style.display == 'none')
		oObj.innerHtml = 'Скрыть подробности'
	else
		oObj.innerHTML = 'Подробности';
	$("#" + sId).slideToggle("slow", function () { 	} );
}

/*
function delInvit(nId){
	//alert('111');
	if(confirm("Вы действительно хотите удалить это приглашение?")){
		location.href = '/personal/invitations/index.php?ID=' + nId + '&action=delete';
	}
}
*/
function showHideBlockUser(sId){
	$$('BlockUser1Div').style.display = 'none';
	$$('BlockUser2Div').style.display = 'none';
	$$('BlockUser3Div').style.display = 'none';
	$$('BlockUser4Div').style.display = 'none';
	$$('BlockUser5Div').style.display = 'none';
	
	$("#" + sId).slideToggle("slow", function () { 	} );
}

function showHideBlockDisputes(sId){
	$("#" + sId).slideToggle("slow", function () { 	} );
}


function sporAddVozSelect(nValue){
	if(nValue == 1){
		$$('VozCountTitle').innerHTML = 'баллов';
		$$('StavkaRazmer').innerHTML = 'Укажите размер ставки. <span style="color: red;">Ставка может быть от 1 до 10 баллов.</span>';
	}else{
		$$('VozCountTitle').innerHTML = 'рублей';
		$$('StavkaRazmer').innerHTML = 'Укажите размер ставки.';
	}
}

function sporAddTypeSelect(nValue){
	if(nValue == 3){
		//открытый
		$$('UserHelpTd').innerHTML = 'Вы можете пригласить Оппонента или ожидать самовыдвижения из числа зарегистрированных участников.';
		$$('RefHelpTd').innerHTML = 'Вы можете пригласить Судью или ожидать самовыдвижения из числа зарегистрированных участников.';
		
	}else{
		// приватный
		$$('UserHelpTd').innerHTML = 'Выберите Оппонента спора из числа зарегистрированных участников.';
		$$('RefHelpTd').innerHTML = 'Выберите Судью спора из числа зарегистрированных участников.';
	}
}











function createInvMnenieBox(){
	var oDiv = document.createElement("div");
	oDiv.id='divInvMain';
	document.body.appendChild(oDiv);
	oDiv = $$('divInvMain');
	oDiv.style.position = 'absolute';
	oDiv.style.width = getWidth($$('main')) + 'px';
	oDiv.style.height = getHeight($$('main')) + 'px';
	oDiv.style.left = _getAbsoluteLeft($$('main')) + 'px';
	oDiv.style.top = _getAbsoluteTop($$('main')) + 'px';
	oDiv.style.fontFamily='arial';
	oDiv.style.fontSize='11';
	oDiv.style.padding='3';
	oDiv.style.color='#1B4966';
	oDiv.style.background='#FFFFFF';
	oDiv.style.filter='alpha(opacity=75)'; // IE
	oDiv.style.opacity='0.75'; // FF
	oDiv.style.zIndex = '1000';	
	oDiv.style.textAlign = 'center';
	oDiv.style.display = 'none';
	
	
	var oDivIn = document.createElement("div");
	oDivIn.id='divInvInner';
	document.body.appendChild(oDivIn);
	oDivIn = $$('divInvInner');
	oDivIn.style.position = 'absolute';
	oDivIn.style.left = _getAbsoluteLeft($$('main')) + (getWidth($$('main')) / 2 - 150) + 'px';
	oDivIn.style.top = _getAbsoluteTop($$('main')) + (getHeight($$('main')) / 2 - 150) + 'px';
	oDivIn.style.width = '300px';
	oDivIn.style.height = '300px';
	oDivIn.style.zIndex = '10000';
	oDivIn.style.fontFamily='arial';
	oDivIn.style.fontSize='13';
	oDivIn.style.padding='3';
	oDivIn.style.border = '1px solid black';
	oDivIn.style.background='#F2F2F2';
	oDivIn.style.filter='alpha(opacity=99)'; // IE
	oDivIn.style.opacity='1.0'; // FF
	oDivIn.style.textAlign = 'center';
	oDivIn.style.display = 'none';
		
}












function showInvMnenieBox(sDisputeName, nDisputeId, sType, sURL){
	var sData = '';
	sData = '<div style="font-size:0.8em; font-weight: bold; padding-top: 3px;">Введите ваше мнение по спору "' + sDisputeName + '"</div>';
	sData += '<br />';
	sData += '<table style="width: 100%"><tr><td align="center">';
	sData += '<textarea name="divInvInnerText" id="divInvInnerText" style="width: 280px; border:1px solid #48A6CE; height: 235px;"></textarea>';
	sData += '</td></tr><tr><td style="padding-top: 5px;"><table style="width: 100%;"><tr><td align="center" style="width: 50%;">';
	sData += '<div class="button_div" style="width: 90px;"><div class="left"><div class="right"><div class="center"><button type="button" onclick="saveInvMnenieBox(' + nDisputeId + ', \'' + sType + '\', \'' + sURL + '\')">Сохранить</button></div></div></div></div>';	
	sData += '</td><td align="center" style="width: 50%;">';
	sData += '<div class="button_div" style="width: 90px;"><div class="left"><div class="right"><div class="center"><button type="button" onclick="closeInvMnenieBox();">Отменить</button></div></div></div></div>';	
	sData += '</td></tr></table>';
	//$$('divInvInner').innerHTML += '<input type="button" value="Сохранить" onclick="saveInvMnenieBox(' + nDisputeId + ', \'' + sType + '\', \'' + sURL + '\')" /> <input type="button" value="Отменить" onclick="closeInvMnenieBox()" />';
	sData += '</td></tr></table>';
	//alert($$('divInvMain').style.display) 
	$$('divInvInner').innerHTML = sData;
	$$('divInvMain').style.display = 'block';
	$$('divInvInner').style.display = 'block';
//alert($$('divInvInner').innerHTML);
}

function closeInvMnenieBox(){
	$$('divInvMain').style.display = 'none';
	$$('divInvInner').style.display = 'none';
}

function saveInvMnenieBox(nInvId, sType, sURL){
	//alert(sURL)
	//alert($$('divInvInnerText').value)
	//alert(sURL)
	if($$('divInvInnerText').value == '' || $$('divInvInnerText').value == ' '){
		alert('Введите Ваше мнение.');
	}else{
		if(sURL!=''){
			location.href = sURL + '&Text=' + $$('divInvInnerText').value;
		}else{
			location.href = '/personal/invitations/index.php?ID=' + nInvId + '&action=agree&Text=' + $$('divInvInnerText').value;
		}
	}
}


function reloadCaptcha(sId, sUrl){
	var dt = new Date();
	document.getElementById(sId).src = sUrl + '&' + dt.getTime()
}