﻿// JScript File
var JoinJudgeDiffSeconds=60;

function DelThis(){
	return !confirm("Are you sure want delete item?");
}






//////////////////////////////////////////////////////////////////

function openWindow(url) {
	popupWin = window.open(url,'new_page','width=400,height=400');
	
}
function opench(url) {
	var name=location.href;
	name=xreplace(name,'/','');
	name=xreplace(name,'/','');
	name=xreplace(name,'.','');
	name=xreplace(name,',','');
	name=xreplace(name,':','');
	name=xreplace(name,'"','');
	name=xreplace(name,'?','');
	name=xreplace(name,'=','');
	name=xreplace(name,'*','');
	name=xreplace(name,'-','');
	name=xreplace(name,'+','');
	name=xreplace(name,'&','');
	name=xreplace(name,'#','');
	//alert(name);
	popupWin = window.open(url,name,'scrollbars,resizable=no,width=600,height=470');
	//return false;
}



function ValidateCheckBox(source, arguments){
	alert(source)
//	if (document.getElementById("valcheckBoxTemp").checked)
//		arguments.IsValid = true;
//	else
//		arguments.IsValid = false;                  
}

function ValidateDates(source, arguments){
	var isValid=true;

//	if(objDate1() && objDate1().value.length==0 || objDate2().value.length==0)
//		isValid=false;
//	else if(objDate1() && objDate2() && (!isDigit(objDate1().value.substring(0,1)) && objDate2().value.length>0 ||
//			objDate1().value.length>0 && !isDigit(objDate2().value.substring(0,1))))
//		isValid=true;
//	else{
//		var now=new Date();
//		var d1;
//		if(objDate1())
//			d1=MergeDate(objDate1().value.substr(0,11),
//				objDate1().value.substr(13,2),objDate1().value.substr(16,2));
//		else
//			d1=now;
//		var d2=MergeDate(objDate2().value.substr(0,11),
//				objDate2().value.substr(13,2),objDate2().value.substr(16,2));
//		//alert(d1+'\n'+d2+'\n'+now);
//		if(d1>=d2 || d1<now)
//			isValid=false;
//		else if(diffMSec(d2,d1)/1000<JoinJudgeDiffSeconds)
//				isValid=false;
//		/*else if(d1.getFullYear()==d2.getFullYear() && d1.getMonth()==d2.getMonth() && d1.getDay()==d2.getDay())
//				if(d1.getHours()>=d2.getHours())
//					isValid=false;
//				else if(d2.getHours()-d1.getHours()==1 && d2.getMinutes()<d1.getMinutes())
//					isValid=false;*/
//	}

	arguments.IsValid=isValid;
	return;
}

function ValidateDates2(source, arguments){
	var isValid=true;
	//alert(objJoin());
	if(objDate1() && objDate1().value.length==0 || 
		objDate2() && objDate2().value.length==0)
		isValid=false;
	else{
		var now=new Date();
		var d1=MergeDate(objDate1().value,0,0);
		var d2=MergeDate(objDate2().value,23,59);
		if(d1>=d2 || d2<now)
			isValid=false;
	}
	arguments.IsValid=isValid;
	return;
}


function MergeDate(sd,sh,sm){
	var d=new Date(sd.substr(7,4),getMonth(sd.substr(3,3))-1,sd.substr(0,2),sh,sm);
	return d;
}


function tag(text1, text2, id){
     if ((document.selection))
     {
       document.getElementById("text_"+id).focus();
       document.getElementById("text_"+id).document.selection.createRange().text = text1+document.getElementById("text_"+id).document.selection.createRange().text+text2;
     } else document.getElementById("text_"+id).value += text1+text2;
}
function intag(tag, id){
	var tid=$(id);
	tid.focus();
	if(document.all){
		document.selection.createRange().text=' '+tag+' ';
	}else{
		tid.value=tid.value.substring(0, tid.selectionStart)+' '+tag+' '+tid.value.substring(tid.selectionEnd, tid.value.length);
	//	text=text.value.substring(0, text.selectionStart)+'['+insert+']'+text.value.substring(text.selectionStart, text.selectionEnd)+'[/'+insert+']'+text.value.substring(text.selectionEnd, text.value.length);
	//	el.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0].value=text;
	}
	 /*if ((document.selection))
	 {
	   $(id).focus();
	   $(id).document.selection.createRange().text = 
	   $(id).document.selection.createRange().text+tag;//+text2;
	 } else $(id).value += tag;//+text2;*/
}

function openComment(cmntWinName){
	if($(cmntWinName)){
		if($(cmntWinName).style.display=="none")
			$(cmntWinName).style.display='block';
		else
			$(cmntWinName).style.display='none';
	}
	return false;
}

function toogleObj(obj,evnt){
	evnt = evnt || window.event; 
	if($(obj)){
		if($(obj).style.display=="none"){
			$(obj).style.display='block';
			evnt.srcElement.className='btnTglCls';
		}
		else{
			$(obj).style.display='none';
			evnt.srcElement.className='btnTglOpn';
		}
	}
	return false;
}

function toogleObj2(obj,minHeight,evnt){
	evnt = evnt || window.event; 
	if($(obj)){
		if($(obj).style.height==minHeight || $(obj).style.height==''){
			$(obj).style.height='auto';
			evnt.srcElement.className='btnTglCls';
		}
		else{
			$(obj).style.height=minHeight;
			evnt.srcElement.className='btnTglOpn';
		}
	}
	return false;
}


function handle_button() {
    var parent = document.getElementById('myContainer');
    var newdiv = document.createElement('div');
    newdiv.className = 'myDivCSSClass';
    newdiv.id = 'myDivId';
    newdiv.style.width = '200px';
    newdiv.style.height = '250px';
    newdiv.style.background = '#3B9D00';
    newdiv.style.color = '#fff';
    var text = "текст текст текст текст текст текст текст текст";
    var textNode = document.createTextNode(text);
    newdiv.appendChild(textNode);
    parent.appendChild(newdiv);
}
function handle_button2() {
    var parent = document.getElementById('myContainer');
    parent.appendChild(elem('div',
      {'class': 'myDivCSSClass', 'id': 'myDivId'},
      {'width': '200px', 'height': '250px', 'background': '#3B9D00', 'color': '#fff'}, 
      'текст текст текст текст текст текст текст текст'));
}





//////////////////////////////////////////////////////////////////
/*						LOGIN									*/
//////////////////////////////////////////////////////////////////
function initLogout(){
	$addHandler(document.body, 'click',
		dd=function(){$('dvOnline').style.visibility="hidden";}
		);
}

function dispOnline(obj){
	$('dvOnline').style.left=(fGetLeft(obj)-34+_offset)+"px";
	$('dvOnline').style.top=(fGetTop(obj)+18)+"px";
	window.setTimeout("$('dvOnline').style.visibility='visible';",50);
	return false;
}
function dispEvents(obj,text){
	text=xreplace(text,"&lt;","<");
	text=xreplace(text,"&gt;",">");
	text=xreplace(text,"&quot;","\'");
	$('dvEvents').style.left=(fGetLeft(obj)-34+_offset)+"px";
	$('dvEvents').style.top=(fGetTop(obj)+18)+"px";
	//alert(text.substring(text.length-5));
	if(text.substring(text.length-5)=='<hr/>')
		text=text.substring(0,text.length-5);
	$('dvEvents_cont').innerHTML='<div style="width:130px;height:0px;"><!-- --></div>'+text;
	window.setTimeout("$('dvEvents').style.visibility='visible';",50);
	return false;
}
function dispError(obj,src){
	text=$(src).innerHTML;
	//text=xreplace(text,"&lt;","<");
	//text=xreplace(text,"&gt;",">");
	//text=xreplace(text,"&quot;","\'");
	//$('dvErrors').style.left=100;//(fGetLeft(obj)-34+_offset)+"px";
	$('dvErrors').style.top=(fGetTop(obj)+18)+"px";
	$('dvErrors').style.visibility="visible";
	$('dvErrors_cont').innerHTML=text;
	return false;
}

var _opened=false;
var _offset=(isIE7?2:0);
var _top_bottom=null;

function initLogin(objName){
	_top_bottom=$(objName);
	$('mmc_msg').style.display="none";
	$addHandler(document.body, 'click',
		__initLogin=function(){$('dvOnline').style.visibility="hidden";}
		);
}

function SubLogin(open){
	//try{
		var task=open?"visible":"hidden";
		_opened=open;
		if(!open)
			window.setTimeout("CloseSubLogin();",200);
		else{
			$('mmc_msg').style.display='inline';
		}
	//}catch(err){;}
	return false;
}
function CloseSubLogin(){
	if(!_opened)
		$('mmc_msg').style.display="none";
}

//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////
/*						CATEGORIES								*/		
//////////////////////////////////////////////////////////////////
function  GetBounds(elt){
    
    // offsetParent (doc element if absolutely positioned or no offsetparent available)
    var offsetParent = elt.offsetParent || document.documentElement;

    // diff = difference in position between element's offsetParent and the element we will attach popup to.
    // this is basically so we can position the popup in the right spot even though it may not be absolutely positioned
    var diff;
    var parentBounds;
    if(offsetParent) {
        // we will be positioning the element against the assigned parent
        parentBounds = CommonToolkitScripts.getBounds(offsetParent);
        
        var offsetParentLocation = CommonToolkitScripts.getLocation(offsetParent);
        diff = {x: parentBounds.x - offsetParentLocation.x, y:parentBounds.y - offsetParentLocation.y};            
    }
    else {
        // we will be positioning the element against the offset parent by default, since no parent element given
        parentBounds = CommonToolkitScripts.getBounds(offsetParent);            
        diff = {x:0, y:0};
    }

    // width/height of the element, needed for calculations that involve width like centering
    var width = elt.offsetWidth - (elt.clientLeft ? elt.clientLeft * 2 : 0);
    var height = elt.offsetHeight - (elt.clientTop ? elt.clientTop * 2 : 0);
}

//////////////////////////////////////////////////////////////////
var animBox,offsetHeight,offsetWidth,animationOut,animationIn,startDate;
function InitCatAnim(){
	animBox=document.getElementById("dvCategories");
	offsetWidth=animBox.offsetWidth;
	animationOut;
	
	animationOut = new AjaxControlToolkit.Animation.ParallelAnimation(animBox,0.5,20);
	var action=new AjaxControlToolkit.Animation.ResizeAnimation(animBox,0.5,20,offsetWidth,27,'px');
	animationOut.add(action);
	//action=new AjaxControlToolkit.Animation.FadeOutAnimation(animBox,0.5,20,30,100,false);
	//animationOut.add(action);

}

function ResOut(){
	startDate=new Date();
	if(isIE && _version<7)
		return false;
	//alert(animBox.offsetHeight);
	if(animationIn)
		animationIn.stop();
	animationOut.play();
	return false;
}
function ResIn(offsetHeight){
	if(isIE && _version<7)
		return false;
	if(animationIn)
		animationIn.dispose();
	animationIn = new AjaxControlToolkit.Animation.ParallelAnimation(animBox,0.5,20);
	action=new AjaxControlToolkit.Animation.ResizeAnimation(animBox,0.5,20,offsetWidth,offsetHeight,'px');
	animationIn.add(action);
	//action=new AjaxControlToolkit.Animation.FadeOutAnimation(animBox,0.5,20,100,30,false);
	//animationIn.add(action);
	animationIn.play();
	return false;
}

function loadCats(a,b){
	BCats(a,b);
	ResOut();
}
function catUp(a,b){
	BCats(a,b);
	ResOut();
}
var _res="";
function catLoaded(res){
	_res=res;
	_catLoaded();
}
function _catLoaded(){
	if(diffMSec(new Date(),startDate)<700){
		window.setTimeout("_catLoaded()",50);
		return;
	}
	animationOut.stop();
	var ss=_res.split("#####",2);
	animBox.innerHTML=ss[1];
	ResIn(ss[0]);
}	
//////////////////////////////////////////////////
//////////////////////////////////////////////////


//var xxxx=new Object();
//xxxx.asd=new Object();
//xxxx.asd.qwe=function(dd){alert(dd)}
//alert(xxxx.asd);
//xxxx.asd.qwe(156);

function FeaturedItem(instanceName,ItemCount,TimerTime){
	this.instanceName=instanceName;
	this.ItemCount=ItemCount;
	this.currBoaIndex=0;
	this.Timer;
	this.TimerState=1;
	this.Animating=false;
	this.TimerTime=TimerTime;
	
	this.finishFade = function() {
		var el = this.getEl();
		YAHOO.util.Dom.setStyle(el, 'display', 'none');
		YAHOO.util.Dom.setStyle(el, 'opacity', 1);
		this.Animating = false;
	}

	this.displayFeaturedItem =function(index, forward) {
		if(index != this.currBoaIndex && !this.Animating) {
			this.Animating=true;
			if(forward == null) {
				forward = (index - this.currBoaIndex > 0);
			}

			this.Content = $(this.instanceName+"-content");
			currItem = $(this.instanceName+"-"+this.currBoaIndex);
			newItem = $(this.instanceName+"-"+index);

			YAHOO.util.Dom.setStyle(newItem, 'position', 'absolute');

			startPos = 260;
			if(!forward) {
				startPos *= -1;
			}
			YAHOO.util.Dom.setStyle(newItem, 'top', '0px');
			YAHOO.util.Dom.setStyle(newItem, 'left', startPos+'px');
			YAHOO.util.Dom.setStyle(newItem, 'display', 'block');


			if(this.Content && currItem && newItem) {

				YAHOO.util.Dom.setStyle(currItem, 'opacity', 1);
				YAHOO.util.Dom.setStyle(currItem, 'background-color', '#F6F8F8');
				YAHOO.util.Dom.setStyle(newItem, 'background-color', '#F6F8F8');
				var fadeAnim = new YAHOO.util.Anim(currItem, { opacity: { to: 0 }}, 0.6, YAHOO.util.Easing.easeOut);
				fadeAnim.onComplete.subscribe(this.finishFade); 
				fadeAnim.animate();
				var flyAnim = new YAHOO.util.Anim(newItem, { left: { from: startPos, to: 0 } }, 0.5, YAHOO.util.Easing.easeBoth); 
				flyAnim.animate(); 

				this.currBoaIndex = index;
	//			for(i = 0 ; i < fcItemCount ; i++) {
	//				p = $("bp-"+i);
	//				if(i != index) {
	//					p.className = '';
	//				} else {
	//					p.className = 'active';
	//				}
	//			}
				this.Animating=false;
				this.updateBoaAttributes(index);
				this.resetBoaTimer();
			}
		}
	}
	this.go_nextFeaturedItem=function(){
		//this.Timer = setTimeout("nextFeaturedItem()", fci.TimerTime);
		//nextFeaturedItem(this);
	}

	this.previousFeaturedItem =function() {
		if(this.currBoaIndex > 0) {
			this.displayFeaturedItem(this.currBoaIndex - 1, false);
		} else {
			this.displayFeaturedItem(this.ItemCount - 1, false);
		}
	}

	this.nextFeaturedItem =function() {
		if(this.currBoaIndex < this.ItemCount - 1) {
			this.displayFeaturedItem(this.currBoaIndex + 1, true);
		} else {
			this.displayFeaturedItem(0, true);
		}
	}

	this.updateBoaAttributes=function(index){
		var newLink = $(this.instanceName+"-link-"+index);
		if(newLink) {
			;//$("hlGroupMore").href = newLink.value;
		}
	//	var newTitle = $("fc-title-"+index);
	//	if(newTitle) {
	//		var title = $("fc-title");
	//		title.innerHTML = newTitle.value;
	//	}
	}

	this.stopBoaTimer= function() {
		if(this.Timer) {
			clearTimeout(this.Timer);
		}
		this.TimerState = 0;
	}

	this.resetBoaTimer =function() {
		if(this.TimerState) {
			this.stopBoaTimer();
			this.startBoaTimer(this.instanceName);
		}
	}

	this.toggleBoaTimer= function() {
		button = $(this.instanceName+'-ctrl-pause');
		if(this.TimerState) {
			button.className = "btnHPBpause2";
			this.stopBoaTimer();
		} else {
			button.className = "btnHPBpause";
			this.startBoaTimer(this.instanceName);
		}
	}

	this.startBoaTimer=function() {
		//return;
		this.stopBoaTimer();
		//fci.Timer = setTimeout("nextFeaturedItem()", fci.TimerTime);
		this.Timer = setTimeout(this.instanceName+".nextFeaturedItem()", this.TimerTime);
		//var ddd=this.nextFeaturedItem;
		//this.Timer = setTimeout("ddd", this.TimerTime);
		//this.Timer = this.go_nextFeaturedItem();
		this.TimerState = 1;
	}

}

//var fc=new FeaturedItem(5,5000);

//alert(fc.TimerState)

//	var fcItemCount=5;
//	var currBoaIndex=0;
//	var fcTimer;
//	var fcTimerState=1;
//	var fcAnimating=false;
//	var fcTimerTime=5000;


