var ie=document.all && !window.opera;
//var IE6=navigator.appVersion.indexOf("MSIE 6")!=-1;
var IE6=navigator.appVersion.indexOf("MSIE 6")!=-1 && navigator.appVersion.indexOf("MSIE 6")<10;
var Chrome=navigator.appVersion.indexOf("Chrome")!=-1;


var _=function(obj,route){
	if(!obj) return null;
	if(typeof obj=="string" && document.getElementById) obj=document.getElementById(obj);
	if(obj) return route?_DOM(obj,route):obj;
	else return null;
};


function _DOM(obj,route){
	route=route.replace(/[^<>\^$\/~a-z0-9_@.:# ]/gi,""); //clear uncorrect instructions
	route=route.replace(/(^[a-z@.:#].*)/i,"^$1"); //normalize inctructions (start with firstChild)
	route=route.replace(/((\<+)|(\>+)|(\^)|(\$)|(\/)|(\~)|(\@))/g,"$1*").replace(/\*([a-z0-9_@.:# ])/gi,"$1"); //add "any tag" (*) pointer
	var tags=route.toUpperCase().match(/([a-z0-9_*.:# ]+)/gi) || []; //create tags array
	var pointer=route.replace(/[^<>\^$\/~@]+/g,"+"); //split inctructions
	
	//alert(route+" ||| "+tags+" ||| "+pointer+" ||| ")
	var fit={
		">":"nextSibling",
		"<":"previousSibling",
		"^":"firstChild",
		"$":"lastChild",
		"/":"parentNode",
		".":ie?"className":"class",
		":":"id",
		"#":"name"
	};
	var tagPos=0, childPos=0;
	var char, tag, tagName, propKey, propValue, found, childNodes;
	var matches=[];

	while((char=pointer.charAt(0))){
		if(char=="+"){//change filter by "tag"
			if(tags[tagPos+1]) tagPos++;
			pointer=pointer.substr(1);
			continue;
		}
		
		tagName=tags[tagPos];
		propKey="";
		
		//if property exist
		if(tagName && (/[.:#]/.test(tagName))){
			propKey=fit[tagName.replace(/[^.:#]/g,"")];
			tag=tagName.match(/([a-z1-6_]*)[.:#]([a-z0-9_ ]*)/i);
			tagName=tag[1] || "*";
			propValue=tag[2];
			//alert(tagName+" "+propKey+" "+propValue)
		}
		
		//search in child nodes
		if(char=="~"){
			if(!childNodes) childNodes=obj.getElementsByTagName(tagName);
			else childPos++;
		}
		else if(childNodes){
			childNodes=null;
			childPos=0;
		}
		
		if(!(obj=obj[fit[char]] || (childNodes && childNodes[childPos]))) return matches.length?matches:null; //set next object
		found=!(obj.nodeType!=1 || (tagName!="*" && obj.tagName!=tagName) || (propKey && (!obj.getAttribute(propKey) || typeof obj.getAttribute(propKey)!="string" || obj.getAttribute(propKey).toUpperCase()!=propValue)));
		if(found) pointer=pointer.substr(1);
		
		//if first/last child not found in first step
		if((char=="^" || char=="$") && !found){
			pointer=pointer.replace(/./,(char=="^"?">":"<"));
		}
		
		//if matches symbol was found (return array of matches)
		if(pointer.charAt(0)=="@"){
			if(char=="^" && found) char=">";
			pointer=char+pointer;
			matches[matches.length]=obj;
		}
	}
	return obj;
};




function addEvent(el, evname, func) {
	if(!el["on"+evname] && el!=window && el!=document) return el["on"+evname]=func;
	if(el.attachEvent) el.attachEvent("on"+evname, func); // IE
	else if(el.addEventListener) el.addEventListener(evname, func, true); // Gecko / W3C
	else el["on"+evname]=func;
};



//get tag Attribute
function _ATTR(obj,attr){
	obj=_(obj);
	if(!obj || !attr) return null;
	return obj.getAttribute && obj.getAttribute(attr)!=undefined ? obj.getAttribute(attr) : (obj[attr]!=undefined ? obj[attr] : null);
};

//get tag Event
function _EV(obj,attr,args){
	var _prop_=_ATTR(obj,attr);
	if(_prop_ && /^on[a-z]+/.test(attr))
		return  typeof _prop_=="function" ? _prop_ : (new Function(args,_prop_)).$this(obj);
	else 
		return function(){};
};



function Coord(e){
	if(window.event){
		this.x=window.event.clientX;
		this.y=window.event.clientY;
	}
	else{
		this.x=e.pageX;
		this.y=e.pageY;
	}
	return this;
};

//debug output for Array & Hash objects (crusial in Chrome)
if(!Chrome)
Array.prototype.toString =
Object.prototype.toString = function() {
	var cont = [];
	var addslashes=function(s){return s.split('\\').join('\\\\').split('"').join('\\"');};
	for (var k in this) { 
		if (cont.length) cont[cont.length-1] += ",";
		var v = this[k];
		var vs = ''; 
		if (v.constructor == String) vs = '"' + addslashes(v) + '"';
		else vs=v.toString();
		cont[cont.length]=k + ": " + vs;
	}
	cont = "	" + cont.join("\n").split("\n").join("\n	");
	var s = cont;
	if (this.constructor == Object) s = "{\n"+cont+"\n}";
	if (this.constructor == Array) s = "[\n"+cont+"\n]";
	return s;
};








//--------------------------------------    data of alert.js        --------------------------------------//

var _popup, ALERT_STACK;
document.alert=function(mess,syswin){
	var dialog_name="dialog_sys";
	if(!_popup){ 
	
		addEvent(document, "keydown", function(e){
			if(_popup.block[dialog_name].isOpen && (Key(e).isEscape() || Key(e).isEnter())) _popup.close(dialog_name);
		});
		_popup=Popup(document.body);
		_popup.create(dialog_name);
	
		_popup.block[dialog_name].onopen=function(name){
			_sys_modal=new Modal({opacity:10});
			window.focus();
		};
		_popup.block[dialog_name].onclose=function(name){
			_sys_modal.remove();
		};
		
	}
	_popup.write(dialog_name,mess);
	
	//open & vertical centering
	_popup.block[dialog_name].style["visibility"]="hidden";
	_popup.open(dialog_name);
	_popup.block[dialog_name].style["marginTop"]=-Math.round(_popup.block[dialog_name].content.offsetHeight/2)-16+"px";
	_popup.block[dialog_name].style["visibility"]="visible";
	
	//_popup.block[dialog_name].move=new Move(_popup.block[dialog_name]);
	
	if(_popup.block[dialog_name].but_ok) _popup.block[dialog_name].but_ok.focus();
	return false;
};



var Key=function(event){
	return {
		code:function(){return window.event?window.event.keyCode:event.which;},
		is:function(num){return this.code()==num},
		isEnter:function(){return this.code()==13},
		isEscape:function(){return this.code()==27}
	}
};


// Popup class ----------------------------------------------------------------------
function Popup(root){
	var _this=this;
	this.block=[];
	//<init>
	this.initOne=function(box){
		box.name=box.id;
		this.block[box.name]=box;
		return box;
	};
	this.initBlock=function(block){
			block.root=this;
			block.type=""; //{news,user}
			block.lock=0;
			block.disabled=0;
			Box(block);
			block.but_close.block=block;
			block.but_close.onclick=function(){return _this.close(this.block.name)};
			return block;
	};
	//</init>
	this.create=function(name, before){
		if(_(name)) return false;
		var box=document.createElement("div");
		box.id=name;
		box.className="box";
		box.content=box.appendChild(document.createElement("div"));
		box.content.className="content";
		box.but_ok=makeHTML({tag:"a", className:"button1", innerHTML:'OK', onclick:function(){return _popup.close(name)}}, box);
		if(before) _(root).insertBefore(box, before);
		else _(root).appendChild(box);
		return this.initOne(box);
	};
	this.display=function(name,display){
		if(this.block[name].disabled) return false;
		this.cur=name;
		this.block[name].style.display=(display?"block":"none");
		this.block[name].isOpen=display;
		return true;
	};
	this.open=function(name){
		if(!this.block[name].root) this.initBlock(this.block[name]); //init on first call
		this.onopen();
		if(this.display(name,1) && this.block[name].onopen) this.block[name].onopen(name);
		return false;
	};
	this.close=function(name){
		if(!name){ //closeAll
			for(var name in this.block)
				if(this.block[name].isOpen)
					this.close(name);
			return false;
		}
		this.onclose();
		if(this.block[name].isOpen && this.display(name,0) && this.block[name].onclose) this.block[name].onclose(name);
		return false;
	};

	this.write=function(name,txt){
		this.block[name].content.innerHTML=txt;
		return false;
	};

	this.onopen=function(){};
	this.onclose=function(){};
	
	return this;
};



function Modal(opt){
	var opt=opt || {};
	this.is=true;
	var win=document.createElement("div");
	win.className="modal";
	if(opt.zi) win.style.zIndex=opt.zi;
	var span=document.createElement("span");
	if(opt.opacity){
		span.style.opacity="0."+opt.opacity;
		span.style.filter="Alpha(opacity:"+opt.opacity+")";
	}
	win.appendChild(span);
	win.style.height="100%";
	document.body.appendChild(win);
	this.remove=function(){
		this.is=false;
		win.parentNode.removeChild(win);
	};
	
	return this;
};


function Box(obj){
	var el_1,el_2,el_3;
	var ask=[];
	var firstChild=obj.firstChild;
	
	/*base*/
	(el_1=obj.insertBefore(document.createElement("div"),firstChild)).className="top_";
	(el_2=el_1.appendChild(document.createElement("div")));
	(el_2.appendChild(document.createElement("b")));
	(el_3=el_2.appendChild(document.createElement("div")));
	(el_3.appendChild(document.createElement("div")));
	(obj.appendChild(el_1.cloneNode(true))).className="bot_";

	(el_1=obj.insertBefore(document.createElement("div"),firstChild)).className="shl_";
	(el_1.appendChild(document.createElement("div")));
	(el_1=obj.insertBefore(document.createElement("div"),firstChild)).className="shr_";
	(el_1.appendChild(document.createElement("div")));
	
	/*other*/
	
	(obj.insertBefore(obj.but_close=document.createElement("a"),firstChild)).className="close_button";
	
	if(IE6) initPNG(obj);

	return obj;
};


// universal HTML creator
function makeHTML(OBJ,root,before){
	var tag=root;
	for(var i in OBJ){
		if(i=="tag") tag=document.createElement(OBJ[i]);
		else if(i=="append") 
			for(var j in OBJ[i]){ 
				if(OBJ[i][j].tag) 
					tag.appendChild(makeHTML(OBJ[i][j]));
			}
		else if(tag) tag[i]=OBJ[i];
	}
	if(root && root!=tag){
		if(before) root.insertBefore(tag, before);
		else root.appendChild(tag);
	}
	return tag;
};





//
//					 richrank.com
//

baseURL = ("https:" == document.location.protocol) ?"https://richrank.com/" :"http://richrank.com/";

function counter_request(id,url){
    var pars = $H({rank_id:id}).toQueryString();
    new Ajax.Request(baseURL + "vote", {method:"post", parameters:pars});
	if (url) window.open(url);
		
}

function show_hide_select(obj) {
        
    if (obj.opened) {
        obj.className = "but_select";
        document.getElementById('but_select_list').style.display = 'none';
        obj.opened = false;
    } else {
        obj.className = "but_select_opened";
        document.getElementById('but_select_list').style.display = 'block';
        obj.opened = true;
    }
    
    return true;
    
}