
function showLogin(e) {
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	
	document.getElementById('login').style.top = (posy+10)+"px";
	document.getElementById('login').style.left = (posx-150)+"px";
	document.getElementById('login').style.visibility = 'visible';
	return false;
}

function hideLogin() {
	document.getElementById('login').style.visibility = 'hidden';
	return false;
}
var ca;                                               
var timer = -1;
function cicle(a) {
	ca = a;
	id= a.id.substring(1);
	
	if (a.pippo == undefined) {
		pic1= new Image();
		pic1.onload = cicleT;
		pic1.src= loadB+"video/"+id+"-b.jpg";			  
		a.pippo = 1;
	} else {
		if (a.pippo > 7) a.pippo = 0;		
		if (a.pippo > 0) {
			var b = -(a.pippo-1)*120;
			a.style.background= "transparent url('"+loadB+"video/"+id+"-b.jpg') no-repeat "+b+"px 0px";
		} else {
			a.style.background= "transparent url('"+loadB+"video/"+id+"-a.jpg') no-repeat 0px 0px";
		}	
		a.pippo++;
		window.clearTimeout(timer);
		timer = window.setTimeout('cicleT()', 800);
	}
	
}
function cicleT() {
	a = ca;
	id= a.id;
	id= a.id.substring(1);	
	
	if (a.pippo == undefined) a.pippo = 1;
	if (a.pippo > 7) a.pippo = 0;
	
	if (a.pippo > 0) {
		var b = -(a.pippo-1)*120;
		a.style.background= "transparent url('"+loadB+"video/"+id+"-b.jpg') no-repeat "+b+"px 0px";
	} else {
		a.style.background= "transparent url('"+loadB+"video/"+id+"-a.jpg') no-repeat 0px 0px";
	}
	
	a.pippo++;
	window.clearTimeout(timer);
	timer=window.setTimeout('cicleT()', 800);
}

var BLOCKSEARCHFLAG = false;
function handleKeyPress(e,elem,style){
	var key=e.keyCode || e.which;
	if (key==13) {
		location.href='search.php?what='+elem.value+"&style="+style;
	} else {
		if (elem.value.toString().length < 1) {
			document.getElementById('shelp').style.visibility = 'hidden';
			return;
		}
		if (BLOCKSEARCHFLAG==true) return;
		BLOCKSEARCHFLAG = true;		
		window.setTimeout('ds()',300);
	}
}

function handleKeyPress2(e,elem,style,udtype){
	var key=e.keyCode || e.which;
	if (key==13) {
		location.href='userdet.php?what='+elem.value+"&style="+style+"&ud="+udtype;
	}
}

function ds() {
	
	elem = document.getElementById('s');
	
	getURL('searchAjax.php?what='+elem.value,searchCB);	
}

function getXY(obj)
{
	var curleft = 0;
	var curtop = 0;
	var border;
	var padding;
	if (obj.offsetParent)
	{
	do
	{
	// XXX: If the element is position: relative we have to add borderWidth
	if (getStyle(obj, 'position') != 'absolute')
	{
	if (border = getStyle(obj, 'border-top-width')) curtop += parseInt(border);
	if (border = getStyle(obj, 'border-left-width')) curleft += parseInt(border);
	
	if (padding = getStyle(obj, 'padding-top')) curtop += parseInt(padding);
	if (padding = getStyle(obj, 'padding-left')) curleft += parseInt(padding);
	}
	curleft += obj.offsetLeft;
	curtop += obj.offsetTop;
	}
	while (obj = obj.offsetParent)
	}
	else if (obj.x)
	{
	curleft += obj.x;
	curtop += obj.y;
	}
	return {'x': curleft, 'y': curtop};
}

	
function getStyle(obj, styleProp)
{
	if (obj.currentStyle)
		return obj.currentStyle[styleProp];
	else if (window.getComputedStyle)
		return window.getComputedStyle(obj,null).getPropertyValue(styleProp);
}


function searchCB(x) {
	var t = getXY(document.getElementById('search'));
	var tmp = document.getElementById('shelp');
	
	tmp.style.top = ((t.y)+24)+"px";
	tmp.style.left = ((t.x))+"px";
	BLOCKSEARCHFLAG = false;
	if (x.content.toString().length < 10) {
		document.getElementById('shelp').style.visibility = 'hidden';
		return;
	}
	document.getElementById('shelp').innerHTML = x.content;
	document.getElementById('shelp').style.visibility = 'visible';
}

function setOpacity(obj,opacity){
	op = opacity;
	opacity=(opacity==100) ? 99.999 : opacity;
	obj.style.filter = "alpha(opacity:"+opacity+")";  // IE/Win
	obj.style.KHTMLOpacity = opacity/100; // Safari<1.2, Konqueror
	obj.style.MozOpacity = opacity/100;   // Older Mozilla and Firefox
	obj.style.opacity = opacity/100;      // Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.ct = op;
}


var rsta;

function alertMSG(me) {	
	var a=0;
	var b=0;
	var r=/BackCompat/i;
	if (r.test(document.compatMode)){
		a=document.body.clientWidth;
		b=document.body.clientWidth;
	}
	else{
		a=document.documentElement.clientWidth;
		b=document.documentElement.clientHeight;
	}
		
	var el = document.getElementById('tooltip');
	document.getElementById('tooltiptxt').innerHTML = "You have received a new message!<br><br>"+
	"Click <a href='userdet.php?show="+me+"&amp;msg=1'>Here</a> to check it, or <a href='#'"+ 
	"onClick='hideTip(); return false;'>Here</a> to close this alert";

	
	//currentStyle = window.getComputedStyle(document.getElementById('tooltip'), null);
	
	//el.style.top = (a/2-parseInt(currentStyle.height)/2)+"px";
	//el.style.left = (b/2-parseInt(currentStyle.width)/2)+"px";
	t1  = getStyle2(document.getElementById('tooltip'),"height");
	t2 = getStyle2(document.getElementById('tooltip'),"width");
	
	el.style.top = (a/2-parseInt(t1)/2)+"px";
	el.style.left = (b/2-parseInt(t2)/2)+"px";
	
	
	el.style.visibility = 'visible';
	
	clearTimeout(rsta);
	
	el.co = 0;
	changeOpac(0,'tooltip');
	fadeIn('tooltip',20);
}	

function hideTip() {	
	var el = document.getElementById('tooltip');	
	clearTimeout(rsta);
	el.co = 100;
	changeOpac(100,'tooltip');
	fadeOut('tooltip',20);
}

function showTip(e,txt) {
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop	+ document.documentElement.scrollTop;
	}
	
	var el = document.getElementById('tooltip');
	document.getElementById('tooltiptxt').innerHTML = txt;
	
//	currentStyle = window.getComputedStyle(document.getElementById('tooltip'), null);
	
//	el.style.top = (posy-parseInt(currentStyle.height)-3)+"px";
//	el.style.left = (posx-parseInt(currentStyle.width)/2)+"px";

	t1  = getStyle2(document.getElementById('tooltip'),"height");
	t2 = getStyle2(document.getElementById('tooltip'),"width");
	
	el.style.top = (posy-parseInt(t1)-3)+"px";
	el.style.left = (posx-parseInt(t2)/2)+"px";
	
	el.style.visibility = 'visible';
	
	clearTimeout(rsta);
	
	el.co = 0;
	changeOpac(0,'tooltip');
	fadeIn('tooltip',20);
}
var last = null;
function sendMSG() {
	hideTip();
	var t = document.getElementById('msgTXT').value;
	getURL('priv.php?who='+last+"&descr="+t,sendMSGCB);	
}

var TMPX;
var TMPY;
document.onmousemove=getMouseCoordinates;
function getMouseCoordinates(event)
{
	TMPX = 0;
	TMPY = 0;
	try {
		e = event || window.event;
		if (e.pageX || e.pageY) {
			TMPX = e.pageX;
			TMPY = e.pageY;
		} else if (e.clientX || e.clientY) 	{
			TMPX = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
			TMPY = e.clientY + document.body.scrollTop	+ document.documentElement.scrollTop;
		}
	} catch(e) {
	}
}

function vote(what,rank,id,hideList) {		
	var el = document.getElementById('tooltip');
	el.style.visibility = 'hidden';
	getURL('vote.php?what='+what+"&rank="+rank+"&id="+id+"&hide="+hideList,voteCB);	
	return false;
}

function getStyle2(obj,name) {
	if (window.getComputedStyle) return window.getComputedStyle(obj,null).getPropertyValue(name);	
	else return IE_computedStyle.get(obj,name);
}
var rstb = -1;
function voteCB(x) {
	var array = x.content.split("#");
	var id = array[0].split(",");
	var score = array[1]*125/5;
	var finish = array[2];
	var msg = array[3];
	var t1=0;
	var t2=0;
	if (finish == 1) {
		for (i=0;i<id.length;i++) {
			try {
				var el = document.getElementById("voteBox"+id[i]);
				el.innerHTML = "<li class='my-rating' style='width:"+score+"px;'></li>";
			} catch (e) {
				
			}
		}
	}	
	var el = document.getElementById('tooltip');
	
	document.getElementById('tooltiptxt').innerHTML = msg;

	t1  = getStyle2(el,"height");
	t2  = getStyle2(el,"width");

	el.style.top = (TMPY-parseInt(t1)-3)+"px";
	el.style.left = (TMPX-parseInt(t2)/2)+"px";


	el.style.visibility = 'visible';
	
	clearTimeout(rsta);
	clearTimeout(rstb);
	
	el.co = 0;
	changeOpac(0,'tooltip');
	fadeIn('tooltip',20);
	rstb = window.setTimeout('hideTip()', 5000);

}


var IE_computedStyle = function () {
    var isIE = /*@cc_on!@*/0;
    var borderRegex = /thin|medium|thick/i; /* Regex for css border width keywords */
    var styleEl;
    
    /* GET POS */
    var getPos = function (which) {
        var curStyle = styleEl.currentStyle[which];
        return (/auto/i.test(curStyle)) ? "auto" : grabLength(curStyle) + "px";
    };
    
    /* GET MARGIN */
    var getMargin = function (which) {
        var curStyle = styleEl.currentStyle["margin" + which];
        return (/auto/i.test(curStyle)) ? "0px" : grabLength(curStyle) + "px";
    };
    
    /* GET BORDER WIDTH */
    var getBorderWidth = function (which) {
        var borderWidth = styleEl.currentStyle["border" + which + "Width"];
        if (styleEl.currentStyle["border" + which + "Style"] !== "none" && 
                ((/Top|Bottom/i.test(which) && styleEl.offsetHeight > styleEl.clientHeight) || 
                (/Right|Left/i.test(which) && styleEl.offsetWidth > styleEl.clientWidth))) {
            if (!borderRegex.test(borderWidth)) {
                return grabLength(borderWidth) + "px";
            } else if (borderRegex.test(borderWidth)) {
                var temp = document.createElement("DIV");
                temp.style.width = "10px";
                temp.style.border = borderWidth + " " + styleEl.currentStyle["border" + which + "Style"] + " #000000";
                styleEl.parentNode.appendChild(temp);
                borderWidth = Math.round((temp.offsetWidth-10)/2);
                styleEl.parentNode.removeChild(temp);
                return borderWidth + "px";
            }
        } else {
            return "0px";
        }
    };
    
    /* GET PADDING */
    var getPadding = function (which) {
        return grabLength(styleEl.currentStyle["padding" + which]) + "px";
    };
    
    /* GET WIDTH */
    var getWidth = function () {
        var width = styleEl.offsetWidth; /* Currently the width including padding + border */
        width -= parseInt(getPadding("Right"));
        width -= parseInt(getPadding("Left"));
        width -= parseInt(getBorderWidth("Right"));
        width -= parseInt(getBorderWidth("Left"));
        return width + "px";
    };
    
    /* GET HEIGHT */    
    var getHeight = function () {
        var height = styleEl.offsetHeight; /* Currently the height including padding + border */
        height -= parseInt(getPadding("Top"));
        height -= parseInt(getPadding("Bottom"));
        height -= parseInt(getBorderWidth("Top"));
        height -= parseInt(getBorderWidth("Bottom"));
        return height + "px";
    };
    
    /* GRAB LENGTH */
    var grabLength = function (length) {
        var temp = document.createElement("DIV");
        temp.style.width = length;
        styleEl.parentNode.appendChild(temp);
        length = Math.round(temp.offsetWidth);
        styleEl.parentNode.removeChild(temp);
        return length;
    };
    
    return {
        /* GET */
        get : function (el, styleProp) {   
            var rValue;
            styleEl = (typeof(el) === "string") ? document.getElementById(el) : el;	
            var styleProp = (typeof(styleProp) === "string") ? styleProp.toLowerCase() : "";
            styleProp = styleProp.replace(/\-/g, "");
            
            if (!isIE || !/block/i.test(styleEl.currentStyle["display"]))
                return;
            
            switch (styleProp) { /* Run through the valid css properties, return undefined if none match */
                case "top": rValue = getPos("top"); break;
                case "right": rValue = getPos("right"); break;
                case "bottom": rValue = getPos("bottom"); break;
                case "left": rValue = getPos("left"); break;
                case "margintop": rValue = getMargin("Top"); break;
                case "marginright": rValue = getMargin("Right"); break;
                case "marginbottom": rValue = getMargin("Bottom"); break;
                case "marginleft": rValue = getMargin("Left"); break;
                case "bordertopwidth": rValue = getBorderWidth("Top"); break;
                case "borderrightwidth": rValue = getBorderWidth("Right"); break;
                case "borderbottomwidth": rValue = getBorderWidth("Bottom"); break;
                case "borderleftwidth": rValue = getBorderWidth("Left"); break;
                case "paddingtop": rValue = getPadding("Top"); break;
                case "paddingright": rValue = getPadding("Right"); break;
                case "paddingbottom": rValue = getPadding("Bottom"); break;
                case "paddingleft": rValue = getPadding("Left"); break;
                case "width": rValue = getWidth(); break;
                case "height": rValue = getHeight(); break;
            }
            
            return rValue;
        }
    };
}();
 

function sendMSG2() {
	hideTip();
	var t = document.getElementById('msgTXT2').value;
	getURL('priv.php?who='+last+"&friend=1&descr="+t,sendMSGCB);	
}

function sendMSGCB(x) {
	alert(x.content);	
}
function getFocusRemoveKey(el,key) {
	if (el.value == key) el.value = '';
}

var chatPOP = null;
function openCHAT()
{
	if (chatPOP == null || chatPOP.closed) {
		chatPOP= window.open('chat.php', "PornHub4UCHAT","width=755,height=495,scrollbars=no,menubar=no");
		chatPOP.focus();
	}
	else {
		chatPOP.focus();	
	}
	
}

function showMSG(e,txt) {
	var posx = 0;
	var posy = 0;
	last = txt;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop	+ document.documentElement.scrollTop;
	}
	
	var el = document.getElementById('tooltip');
	document.getElementById('tooltiptxt').innerHTML = 
	"<center>Send Private Msg To <b>"+txt+"</b><br/>"+
	"<textarea class='popuptxt'  id='msgTXT' onfocus='getFocusRemoveKey(this,\"Write Message Here\")'>Write Message Here</textarea><br>"+
	"<input class='button'  type='submit' value='Ok' onClick='sendMSG();'></center>";
	
//	currentStyle = window.getComputedStyle(document.getElementById('tooltip'), null);
	
//	el.style.top = (posy-parseInt(currentStyle.height)-3)+"px";
//	el.style.left = (posx-parseInt(currentStyle.width)/2)+"px";

	t1  = getStyle2(document.getElementById('tooltip'),"height");
	t2 = getStyle2(document.getElementById('tooltip'),"width");
	
	el.style.top = (posy-parseInt(t1)-3)+"px";
	el.style.left = (posx-parseInt(t2)/2)+"px";

	
	el.style.visibility = 'visible';
	
	clearTimeout(rsta);
	
	el.co = 0;
	changeOpac(0,'tooltip');
	fadeIn('tooltip',20);
}

function showMSG2(e,txt) {
	var posx = 0;
	var posy = 0;
	last = txt;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop	+ document.documentElement.scrollTop;
	}
	
	var el = document.getElementById('tooltip');
	document.getElementById('tooltiptxt').innerHTML = 
	"<center>Add <b>"+txt+"</b> to your friends!<br/>"+
	"<textarea class='popuptxt' id='msgTXT2' onfocus='getFocusRemoveKey(this,\"Write Message Here\")'>Write Message Here</textarea><br>"+
	"<input class='button'  type='submit' value='Ok' onClick='sendMSG2();'></center>";
	
	t1  = getStyle2(document.getElementById('tooltip'),"height");
	t2 = getStyle2(document.getElementById('tooltip'),"width");
	
	el.style.top = (posy-parseInt(t1)-3)+"px";
	el.style.left = (posx-parseInt(t2)/2)+"px";

	
	el.style.visibility = 'visible';
	
	clearTimeout(rsta);
	
	el.co = 0;
	changeOpac(0,'tooltip');
	fadeIn('tooltip',20);
}

function fadeOut(id,spd) {
	  var el = document.getElementById(id);
		el.co = Math.max(0,el.co-5);			
		changeOpac(el.co,id);
		if (el.co <= 0) {
			el.style.visibility = "hidden";
			return;
		}
		el.style.top = (parseInt(el.style.top)-1)+"px";
		rsta = setTimeout("fadeOut('"+id+"',"+spd+")",spd);
}
	
function fadeIn(id,spd) {
	  var el = document.getElementById(id);
	  
			el.style.visibility = "visible";
		el.co = Math.min(100,el.co+5);			
		changeOpac(el.co,id);
		if (el.co >= 100) return;
		if (el.co%5==0)
			el.style.top = (parseInt(el.style.top)-1)+"px";		
		rsta = setTimeout("fadeIn('"+id+"',"+spd+")",spd);
}

function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 

function styleME(el,styleName) {
	el.className=styleName;
}

function shareVID(id) {
    a = window.open('shareVID.php?id='+id,'embedVID','width=380, height=200, scrollbars=yes, resizable=yes');
    a.focus();
    return false;
}

function embedVID(id) {
    a = window.open('embedVID.php?id='+id,'embedVID','width=380, height=200, scrollbars=yes, resizable=yes')
    a.focus();
    return false;
}

function blogEdit(id) {
    a = window.open('postblog.php?edit='+id,'postblog','width=765px, height=680px, scrollbars=yes, resizable=yes')
    a.focus();
    return false;
}

function photoPost(id) {
    a = window.open('postpic.php?album='+id,'postpics','width=330px, height=200px, scrollbars=yes, resizable=yes')
    a.focus();
    return false;
}

if (typeof getURL == 'undefined') {
	getURL = function(url, callback) {
		if (!url)
			throw 'No URL for getURL';
		try {
			if (typeof callback.operationComplete == 'function')
				callback = callback.operationComplete;
		} catch (e) {}
			if (typeof callback != 'function')
				throw 'No callback function for getURL';
		var http_request = null;
		if (typeof XMLHttpRequest != 'undefined') {
		    http_request = new XMLHttpRequest();
		}
		else if (typeof ActiveXObject != 'undefined') {
			try {
				http_request = new ActiveXObject('Msxml2.XMLHTTP');
			} catch (e) {
				try {
					http_request = new ActiveXObject('Microsoft.XMLHTTP');
				} catch (e) {}
			}
		}
		if (!http_request)
			throw 'Both getURL and XMLHttpRequest are undefined';		
		http_request.onreadystatechange = function() {
			if (http_request.readyState == 4) {
				callback( { success : true,
				  content : http_request.responseText,
				  contentType : http_request.getResponseHeader("Content-Type") } );
			}
		}
		http_request.open('GET', url, true);
		http_request.send(null);
	}
}

function tst(t,b) {
	document.getElementById(b).src=t;
}
function turnOn(qty) {
	if (qty > 0) {
		document.getElementById('comment').innerHTML ='Awful';
	}
	if (qty > 1) {
		document.getElementById('comment').innerHTML ='Bad';
	}
	
	if (qty > 2) {
		document.getElementById('comment').innerHTML ='Average';
	}
	if (qty > 3) {
		document.getElementById('comment').innerHTML ='Good';
	}
	
	if (qty > 4) {
		document.getElementById('comment').innerHTML ='Excellent';
	}
}


	
