/*
=================================================================================
 Copyright (c) 2008 Optimal Development
=================================================================================
 Данный код защищен авторскими правами
=================================================================================
 Файл: site_common.js
-------------------------------------------------------------------------------------------------------------------------
 Назначение: 
=================================================================================
*/
function _vcGetPosOffset(what,offsettype)
{
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while(parentEl!=null)
	{
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	};
	return totaloffset;
}

function _vcIeCompatTest()
{
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function _vcClearBrowserEdge(obj,whichedge)
{
	var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1;
	if(whichedge=="rightedge")
	{
		var windowedge=ie && !window.opera? _vcIeCompatTest().scrollLeft+_vcIeCompatTest().clientWidth-30 : window.pageXOffset+window.innerWidth-40;
		dropmenuobj.contentmeasure=dropmenuobj.offsetWidth;
		if(windowedge-dropmenuobj.x<dropmenuobj.contentmeasure)
		{
			edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset);
		};
	}
	else
	{
		var windowedge=ie && !window.opera? _vcIeCompatTest().scrollTop+_vcIeCompatTest().clientHeight-15 : window.pageYOffset+window.innerHeight-18;
		dropmenuobj.contentmeasure=dropmenuobj.offsetHeight;
		if(windowedge-dropmenuobj.y<dropmenuobj.contentmeasure)
		{
			edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight;
		};
	};
	return edgeoffset;
}

function _vcHideTip(e)
{
	dropmenuobj.style.visibility="hidden";
	dropmenuobj.style.left="-500px";
}

//function _vcCreateHintBox()
//{
//	var divblock=document.createElement("div");
//
//	divblock.setAttribute("id","hintbox");
//	document.body.appendChild(divblock);
//}




function vcGetElementRuntimeStyleProperty(elementId,propertyName)
{
	var element=document.getElementById(elementId);
	
	if(window.navigator.userAgent.indexOf('MSIE')!=-1)
	{
		return element.runtimeStyle.getAttribute(propertyName);
	}
	else
	{
		return getComputedStyle(element,'').height;
	};
}


function vcReloadCaptcha(target, subTarget)
{
	subTarget = subTarget || '';
    var newUrl="";
	var captcha=document.getElementById('captcha');
	
	if(target=='')
	{
		target='common';
	};
	newUrl="/antibot/captcha.php?target="+target;
	if(subTarget.length>0)
	{
		newUrl+="&subtarget="+subTarget;
	}
	newUrl+="&nocache="+Math.random();
	captcha.src=newUrl;
}

function vcAddComment(target)
{
	var form=document.getElementById('comments_form');
	var ajax=new vc_ajax();
	
	ajax.onShow('');
	
	ajax.setVar('target',target);
	ajax.setVar('action','addcomment');
	ajax.setVar('object_id',form.object_id.value);
	ajax.setVar('comment',form.comment.value);
	
	ajax.requestFile="/ajax.php";
	ajax.method='POST';
	ajax.execute=true;
	ajax.add_html=true;
	ajax.element='new-comment';
	ajax.sendAJAX();
}

function vcRemoveComment(target,commentId)
{
	if(confirm(vcCommonRemoveConfirm))
	{
		var form=document.getElementById('comments_form');
		var ajax=new vc_ajax();
		
		ajax.onShow('');
		
		ajax.setVar('target',target);
		ajax.setVar('action','removecomment');
		ajax.setVar('object_id',form.object_id.value);
		ajax.setVar('comment',commentId);
		
		ajax.onCompletion=function() {
			var div=document.getElementById('comment_'+commentId);
			if(this.response==1)
			{
				div.style.display='none';
			};
		}
		
		ajax.requestFile="/ajax.php";
		ajax.method='POST';
		ajax.execute=true;
		ajax.sendAJAX();
	};
}

function vcShowPmForm()
{
	var form=document.getElementById('pm_form');
	var formBlock=document.getElementById('block_pm_form');
	var resultBlock=document.getElementById('block_pm_send_result');
	
	form.reset();
	vcReloadCaptcha('send_pm',form.page_uid.value);
	formBlock.style.display='block';
	resultBlock.style.display='none';
}

function vcSendPm(pageUCH)
{
	var form=document.getElementById('pm_form');
	var ajax=new vc_ajax();
	
	ajax.onShow('');
	ajax.onCompletion=function() {
		var formBlock=document.getElementById('block_pm_form');
		var resultBlock=document.getElementById('block_pm_send_result');
		var resultTxt=document.getElementById('block_pm_send_result_text');
		
		formBlock.style.display='none';
		resultBlock.style.display='block';
		resultTxt.innerHTML=this.response;
	}
	
	
	ajax.setVar('target','profile');
	ajax.setVar('action','sendpm');
	ajax.setVar('object_id',form.object_id.value);
	ajax.setVar('page_uid',form.page_uid.value);
	ajax.setVar('page_uch',pageUCH);
	ajax.setVar('captcha',form.capcha_code.value);
	ajax.setVar('message',form.message.value);
	
	ajax.requestFile="/ajax.php";
	ajax.method='POST';
	ajax.sendAJAX();
}

function vcAddToFavorite(target,objectId)
{
	var ajax=new vc_ajax();
	
	ajax.onShow('');
	
	ajax.setVar('target',target);
	ajax.setVar('action','addfavorite');
	ajax.setVar('object_id',objectId);
	
	ajax.requestFile="/ajax.php";
	ajax.method='GET';
	ajax.execute=true;
	ajax.element='icon_favorite';
	ajax.sendAJAX();
	
}

function vcRemoveFromFavorite(target,objectId)
{
	var ajax=new vc_ajax();
	
	ajax.onShow('');
	
	ajax.setVar('target',target);
	ajax.setVar('action','removefavorite');
	ajax.setVar('object_id',objectId);
	
	ajax.requestFile="/ajax.php";
	ajax.method='GET';
	ajax.execute=true;
	ajax.element='icon_favorite';
	ajax.sendAJAX();
	
}

function vcShowHint(menucontents,obj,e,tipwidth)
{
	if((ie||ns6) && document.getElementById("hintbox"))
	{
		dropmenuobj=document.getElementById("hintbox")
		dropmenuobj.innerHTML=menucontents;
		dropmenuobj.style.left=dropmenuobj.style.top=-500;
		tipwidth='';
		if(tipwidth!="")
		{
			dropmenuobj.widthobj=dropmenuobj.style;
			dropmenuobj.widthobj.width=tipwidth;
		}
		dropmenuobj.x=_vcGetPosOffset(obj, "left");
		dropmenuobj.y=_vcGetPosOffset(obj, "top");
		dropmenuobj.style.left=dropmenuobj.x-_vcClearBrowserEdge(obj,"rightedge")+obj.offsetWidth+"px";
		dropmenuobj.style.top=dropmenuobj.y-_vcClearBrowserEdge(obj,"bottomedge")+"px";
		dropmenuobj.style.visibility="visible";
		obj.onmouseout=_vcHideTip;
	};
}

function vcGoHome()
{
    var href=location.href;
    if  (href.indexOf('confirm_code') = -1)
    {
        return;
    }
    else
        {
            user = document.getElementById('authlogin').value;
            pass = document.getElementById('authpass').value;
            
        }
    	location.href=newUrl;

    Url

}


