var var_array1 = ['/','|','\\','@','!','`','~','#','$','%','^','&','*','(',')','=',';',',','?','\'',' ','++','+++','++++','+++++','  ','"'];
var var_array2 = ['','','','','','','','','','','','','','','','','',' ','','','+','+','+','+','+','+',''];
function str_replace (search, replace, subject, count) {
	var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
		f = [].concat(search),
		r = [].concat(replace),
		s = subject,
		ra = r instanceof Array, sa = s instanceof Array;
	s = [].concat(s);
	if (count) {
		this.window[count] = 0;
	}
	for (i=0, sl=s.length; i < sl; i++) {
		if (s[i] === '') {
			continue;
		}
		for (j=0, fl=f.length; j < fl; j++) {
			temp = s[i]+'';
			repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
			s[i] = (temp).split(f[j]).join(repl);
			if (count && s[i] !== temp) {
				this.window[count] += (temp.length-s[i].length)/f[j].length;
			}
		}
	}
	return sa ? s : s[0];
}


function getHttpTransporter(){
	var xmlHttp = null;
	try{xmlHttp = new XMLHttpRequest(); return xmlHttp;} //opera
	catch (e){try{xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.5.0"); return xmlHttp;}
	catch (e){try{xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); return xmlHttp;}
	catch (e){alert("Browser-ul dumneavoastra nu suporta AJAX!"); return xmlHttp;}}}
}

var httpTransporter = null;

function $(x){
	return document.getElementById(x);
} // end func


function body_me(){
	$('worst').onclick = function(){$('star').className='selectReplacement worst'; $('review-rating').selectedIndex=1;};
	$('bad').onclick = function(){$('star').className='selectReplacement bad';$('review-rating').selectedIndex=2;};
	$('fair').onclick = function(){$('star').className='selectReplacement fair';$('review-rating').selectedIndex=3;};
	$('good').onclick = function(){$('star').className='selectReplacement good';$('review-rating').selectedIndex=4;};
	$('best').onclick = function(){$('star').className='selectReplacement best';$('review-rating').selectedIndex=5;};
}

function doAjax_DONE(){
	if(httpTransporter.readyState != 4) return;
	httpTransporter.onreadystatechange = function(){ return false; };
	if(httpTransporter.readyState == 4 && httpTransporter.status == 200){
		//$("raspuns").innerHTML = 'Va rugam asteptati...';
		readBack(httpTransporter.responseText);
	}else if(httpTransporter.status == 404){
		//$("raspuns").innerHTML = 'Serverul este inaccesibil.';
		return;
	}else if(httpTransporter.status != 200){
		//$("raspuns").innerHTML = 'Nu s-a detectat nici o conexiune.';
		return;
	}
}

var ids = 0;

function doAjax(id){
	// Get transporter
	ids = id;
	if ($('sc_'+id)){
		$('sc_'+id).innerHTML = '<img src="http://www.dc-hubs.ro/img/r.gif" alt="Loading..." border="0" style="vertical-align:bottom"/>';
	}
	httpTransporter = getHttpTransporter();
	// Send request
	var ddata = new Date().getTime();
	var dwAddress = "http://www.dc-hubs.ro/check_hub.php?id="+id+"&now="+ddata;
	httpTransporter.open("GET", dwAddress, true);
	httpTransporter.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	httpTransporter.send(null);
	httpTransporter.onreadystatechange = doAjax_DONE;
}

function readBack(responseText) {
	// Parse JSON
	try{
		//alert(responseText);
		//var jsonObject = eval('(' + responseText + ')');
		//$('box').innerHTML = responseText;
		var r = responseText.split('|');
			$('share_' + ids).innerHTML = r[0];
			$('users_' + ids).innerHTML = r[1];
			$('ping_' + ids).innerHTML = r[2];
			$('time_' + ids).innerHTML = r[3];

		if ($('sc_'+ids)){
			$('sc_'+ids).innerHTML = 'Scanare';
		}
		
	}catch(e){
		alert(dump(e));
		alert("Raspuns Server invalid! Va rugam reincercati.");
	}
}

function doAjax_vot_DONE(){
	if(httpTransporter.readyState != 4) return;
	httpTransporter.onreadystatechange = function(){ return false; };
	if(httpTransporter.readyState == 4 && httpTransporter.status == 200){
		//$("raspuns").innerHTML = 'Va rugam asteptati...';
		readBack_vot(httpTransporter.responseText);
	}else if(httpTransporter.status == 404){
		//$("raspuns").innerHTML = 'Serverul este inaccesibil.';
		return;
	}else if(httpTransporter.status != 200){
		//$("raspuns").innerHTML = 'Nu s-a detectat nici o conexiune.';
		return;
	}
}

var ids = 0;

function doAjax_vot(id){
	// Get transporter
	//ids = id;
	httpTransporter = getHttpTransporter();
	// Send request
	var ddata = new Date().getTime();
	var dwAddress = "http://www.dc-hubs.ro/voteaza.php?hub="+id+"&now="+ddata;
	httpTransporter.open("GET", dwAddress, true);
	httpTransporter.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	httpTransporter.send(null);
	httpTransporter.onreadystatechange = doAjax_vot_DONE;
}

function doAjax_votes(id){
	// Get transporter
	//ids = id;
	httpTransporter = getHttpTransporter();
	// Send request
	var ddata = new Date().getTime();
	var dwAddress = "http://www.dc-hubs.ro/voteaza.php?id="+id+"&now="+ddata;
	httpTransporter.open("GET", dwAddress, true);
	httpTransporter.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	httpTransporter.send(null);
	httpTransporter.onreadystatechange = doAjax_vot_DONE;
}

function readBack_vot(responseText) {
	// Parse JSON
	try{
		var r = responseText.split('|');
		if (r[2]=='Error' || r[2]=='Votat'){
			$('vot_a_' + r[0]).onclick = '';
			$('vot_a_' + r[0]).className = 'buton_votat';
			alert('Hubul a fost deja votat astazi de la acest IP.');
		}else if(r[0]!='Error'){
			$('vot_' + r[0]).innerHTML = r[1];
			$('vot_a_' + r[0]).onclick = '';
			$('vot_a_' + r[0]).className = 'buton_votat';
		}else{
			alert('Hubul a fost deja votat astazi de la acest IP.');
		}
	}catch(e){
		alert(dump(e));
		alert("Raspuns Server invalid! Va rugam reincercati.");
	}
}

function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;

	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";

	if(typeof(arr) == 'object') { //Array/Hashes/Objects
		for(var item in arr) {
			var value = arr[item];
			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}

function popUp(name) {
	var URL = 'index.php?path='+name+'&popup=yes';
	var day = new Date();
	var id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=500,height=450,left = 390,top = 362');");
}

function show_key (the_key){
	if (!the_key) the_key = event.keyCode;
	if (the_key==13) if($('search_text').value != '') document.location='http://www.dc-hubs.ro/huburi/'+$('search_text').value;
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}



/***********************************************
* Cool DHTML tooltip script II- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var offsetfromcursorX=12; //Customize x offset of tooltip
var offsetfromcursorY=10; //Customize y offset of tooltip

var offsetdivfrompointerX=10; //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=14; //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

document.write('<div id="dhtmltooltip"></div>'); //write out tooltip DIV
document.write('<img id="dhtmlpointer" src="http://www.dc-hubs.ro/img/arrow2.gif">'); //write out pointer image

var ie=document.all;
var ns6=document.getElementById && !document.all;
var enabletip=false;
if (ie||ns6)
	var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : "";

var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : "";

function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function ddrivetip(thetext, thewidth, thecolor){
	if (ns6||ie){
		if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px";
		if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor;
		tipobj.innerHTML=thetext;
		enabletip=true;
		return false;
	}
}

function positiontip(e){
	if (enabletip){
		var nondefaultpos=false;
		var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
		var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
		//Find out how close the mouse is to the corner of the window
		var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20;
		var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20;

		var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX;
		var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY;

		var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000;

		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge<tipobj.offsetWidth){
			//move the horizontal position of the menu to the left by it's width
			tipobj.style.left=curX-tipobj.offsetWidth+"px";
			nondefaultpos=true;
		}else if (curX<leftedge){
			tipobj.style.left="5px";
		}else{
			//position the horizontal position of the menu where the mouse is positioned
			tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px";
			pointerobj.style.left=curX+offsetfromcursorX+"px";
		}

		//same concept with the vertical position
		if (bottomedge<tipobj.offsetHeight){
			tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px";
			nondefaultpos=true;
		}else{
			tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px";
			pointerobj.style.top=curY+offsetfromcursorY+"px";
		}
		tipobj.style.visibility="visible";
		if (!nondefaultpos)
			pointerobj.style.visibility="visible";
		else
			pointerobj.style.visibility="hidden";
	}
}

function hideddrivetip(){
	if (ns6||ie){
		enabletip=false;
		tipobj.style.visibility="hidden";
		pointerobj.style.visibility="hidden";
		tipobj.style.left="-1000px";
		tipobj.style.backgroundColor='';
		tipobj.style.width='';
	}
}

document.onmousemove=positiontip;

