// JScript File

// Return element pointer
function getElById(el){
	//alert(el);
	return document.getElementById(el);
}
var lcolor,lobj=null;
function hlight(obj,color){
	if(lobj!=null){
		lobj.style.backgroundColor=lcolor;
	}
	lcolor=obj.style.backgroundColor;
	lobj=obj;
	obj.style.backgroundColor=color;
}
function setbg(obj,bg){
	if(obj!=null){
		if(bg=='')
			obj.style.backgroundColor='';
		else
			obj.style.backgroundColor=bg;
	}
}

//return code of preesed key
function EnterPressed(e){
	var keynum;
	if(window.event)//ie
		keynum=window.event.keyCode
	else if (e.which)//Netscape/Firefox/Opera
		keynum=e.which;
	
	return (keynum==13);
	//keychar = String.fromCharCode(keynum)
	//numcheck = /\d/
	//return !numcheck.test(keychar)

	//if (window.event.keyCode == 13 && window.event.srcElement.tagName!='TEXTAREA')
}
function fGetLeft(obj){
   return(obj.offsetParent==null ? obj.offsetLeft : obj.offsetLeft+fGetLeft(obj.offsetParent));
}
function fGetTop(obj){
   return(obj.offsetParent==null ? obj.offsetTop : obj.offsetTop+fGetTop(obj.offsetParent));
}
function getOffset(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 GetXPosition(item){
	var position = 0;
	if (item.offsetWidth != null){
		while (item != document.body && item != null){
			position += item.offsetLeft;
			item = item.offsetParent;
		}
	}
	return position;
}
function GetYPosition(item){
	var position = 0;
	if (item.offsetWidth != null){
		while (item != document.body && item != null){
			position += item.offsetTop;
			item = item.offsetParent;
        }
    }
	return position;
}

/***********			ARRAYS			*****************************/
function searcharr(arr,what) {
	var i;
	for(i=0;i<arr.length;i++)
		if(arr[i]==what)
			return i;
	return -1;
}
function RemoveBad(arr){
	if(arr){
		var arrlength=arr.length;
		for(var index=0;index < arrlength;index++)
			if(!getElById(arr[index])){
				arr.splice(index,1);
				index--;
				arrlength--;
			}
	}
	return arr;
}
function RemoveDuplicates(arr){
	if(arr){
		var newArr=new Array();
		var hash = new Object();
		for (var i=0; i<arr.length; i++){
			if (hash[arr[i]] != 1){
				newArr = newArr.concat(arr[i]);
				hash[arr[i]] = 1;
			}
		}
	}
	return newArr;
}
/***********			/ARRAYS			*****************************/

function openWindow(url) {
	popupWin = window.open(url,'new_page','width=400,height=400');
	
}
function openWindowCenter(url,name,width,height){
	var left = (screen.width - width) / 2;
	var top = (screen.height - height) / 2;
	var popupWin = window.open(url,name,'width='+width+',height='+height+',top='+top+',left='+left);
	return popupWin;
}




function RegReplace(text,patern,replacement){
	var re = new RegExp(patern, "g");
	//alert(text.replace(re,replacement));
	return text.replace(re,replacement);
}

function textCounter(field, countfield, maxlimit) {
	try{
		if (field.value.length > maxlimit) 
			field.value = field.value.substring(0, maxlimit-1);
		else 
			countfield.value = maxlimit - field.value.length;
	}
	catch(err){;}
}

function my_trim(s)
{
	while (s.substring(0, 1) == ' '){
		s = s.substring(1, s.length);
	}
	while (s.substring(s.length-1, s.length) == ' '){
		s = s.substring(0, s.length-1);
	}
	return s;
}

function xreplace(text,toberep,repwith){
	var temp = text;
	var i = temp.indexOf(toberep);
	while(i > -1){
		temp = temp.replace(toberep, repwith);
		i = temp.indexOf(toberep, i + repwith.length + 1);
	}
	return temp;
}
function DiffMSec(d1,d2){
	return d1.getTime()-d2.getTime();
	/*var d1s=now.getSeconds();
	var d1m=now.getMilliseconds();
	if(d1s<now.getSeconds())
		d1s.setSeconds(d1s+60);
	if(d1m<now.getMilliseconds())
		d1s.setMilliseconds(d1m+1000);*/
}
function addEvent(name,evf){
	try{
		if (window.addEventListener)
		{
			//alert("1");
			if(eval("window.addEventListener(name, evf, false);"))
				window.addEventListener(name, evf, false);
			else if(document.getElementById)
				eval("window."+name+"="+evf);
		}
		else if (window.attachEvent)
		{
			//alert("2");
			window.attachEvent(name, evf);
		}
		else if (document.getElementById)
		{
			//alert("3");
			eval("window."+name+"="+evf);
		}
	}catch(err){;}
}





////////////////////////////////////////////////////////////////////////////////////////////////////////
var stop = 0;
var	ittjar = 0;

function ss0(){
    var pontok = "";
    for (var i = 1; i < ittjar; i++ ){
        pontok += ".";
	}
    window.status = "Please wait" + pontok;
    ittjar++;
	if (stop == 0) {
		setTimeout("ss0();", 100);
	}
	if (ittjar > 10) { ittjar = 1; }
}
function sstop() {
    stop = 1;
    setTimeout("window.status = ''", 100);
}						
//ss0();

////////////////////////////////////////////////////////////////////////////////////////////////////////
function SetTitle(strTitle){
	window.document.title=strTitle;
}

function AddClick(iId){
	var objImage=new Image();
	objImage.src='XMLHttp/download.asp?rel_id=' + iId;
}	

function ChangeLanguage(sLang,iUserId){
	var objImage = new Image();
	objImage.src='XMLHttp/language.asp?UserId='+iUserId+'&lang=' + sLang;
	//alert(objImage.src);
	setTimeout("location.reload()",1500);
	//location.reload();
}	

function ss(w){window.status=w;return true;}
function cs(){window.status='';}	

function log_out(){
	ht = document.getElementsByTagName("html");
	ht[0].style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";
	if (confirm('Вы действительно хотите выйти?')){
		return true;
	}
	else{
		ht[0].style.filter = "";
		return false;
	}
}

function trim(s){
	while (s.substring(0, 1) == ' '){
			s = s.substring(1, s.length);
	}
	while (s.substring(s.length-1, s.length) == ' '){
		s = s.substring(0, s.length-1);
	}
	return s;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
//mouse over changes bgcolor
//finds the a tag and changes the text color
//changes the cursor to hand
function LmOver(elem, clr){
	elem.style.backgroundColor = clr;
	//elem.children.tags('A')[0].style.color = "DarkBlue";
	elem.style.cursor = 'hand';
	//elem.className = "MainMenuButtonOnMouseOver";
}

//mouse moved from changes bgcolor and text color to normal
function LmOut(elem, clr){
	elem.style.backgroundColor = clr;
	//elem.children.tags('A')[0].style.color = "DarkBlue";
	//elem.className = "MainMenuButtonOff";
}

//this is so the link
function LmUp(path){
	location.href = path;
}
// onmouseover="this.className='MainMenuButtonOnMouseOver'" onmouseout="this.className='MainMenuButtonOff'"

function LmOver_(elem, clsnm){
	elem.className = clsnm;
	elem.style.cursor = 'hand';
}

//mouse moved from changes bgcolor and text color to normal
function LmOut_(elem, clsnm){
	elem.className = clsnm;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
function UpdateSize(getObj,getWidth){
	for(i=0;i<getObj.all.length;i++){
		var Obj;
		if((getObj.all.item(i).tagName=='IMG')){//||(getObj.all.item(i).tagName=='TABLE')){
			Obj = getObj.all.item(i);
			if(Obj.offsetWidth>getWidth){
				ResizeObj(Obj,Obj.offsetWidth,Obj.offsetHeight,getWidth);
			}
		}
	}
}
//Changing size by the width value
function ResizeObj(Obj,ObjWidth,ObjHeight,intSize){
	intYSize=(intSize/ObjWidth) * ObjHeight;
	Obj.width = intSize;
	Obj.height = intYSize;
	Obj.style.width = intSize;
	Obj.style.height = intYSize;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(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 eraseCookie(name){
	createCookie(name,"",-1);
}

function lochref(url){
	location.href=url;
}

function wourl(url){
	window.open(url);
}

function hc(hach){
	wourl("http://stats.razorback2.com/ed2khistory?ed2k="+hach);
}
function dlcue(id){
	lochref("/XMLHttp/dlcue.asp?cue="+id);
}

function shrink(what)
{
	IE = (document.all)
	
	if (IE)
		displaystyle = "block";
	else
		displaystyle = "table-cell";
		
	var totalTDs = document.getElementsByTagName("TD").length;

	var what2 = what + "shrink"; // change DIV for code
	var what3 = what + "code"; // change TH for code
	
	if (document.getElementById(what2).innerHTML == "[-]")
	{
		document.getElementById(what2).innerHTML = "[+]";
		
		for(i=0; i < totalTDs; i++)
		{
			if (document.getElementsByTagName("TD")[i].className == what)
			{
				//document.getElementsByTagName("TD")[i].style.visibility='hidden';
				document.getElementsByTagName("TD")[i].style.display='none';
			}		
		}
		//document.getElementById("bbccol").width = "1";
		//document.getElementById("contable").width="50";
		document.getElementById(what3).style.display="none";
	}
	else
	{
		document.getElementById(what2).innerHTML = "[-]";

		for(i=0; i < totalTDs; i++)
		{
			if (document.getElementsByTagName("TD")[i].className == what)
			{
				//document.getElementsByTagName("TD")[i].style.visibility='visible';
				document.getElementsByTagName("TD")[i].style.display=displaystyle;
			}
			document.getElementById(what3).style.display=displaystyle;
		}
	}
		//document.getElementById("bbccol").width = "350";


}  // end function shrink()