function blog_comment_mark_inappr(comment_id) {
	if ($F('inappropriate_reason_' + comment_id) == '') {
		alert('Please select a reason');
	} else {
		request('blog.inappr.comment', 'action=inappr&comment_id=' + comment_id + '&reason_id=' + $F('inappropriate_reason_' + comment_id));
		alert('Your request has been sent');
		Element.toggle('div_comment_mark_inappr_' + comment_id);
	}
}

function blog_entry_mark_inappr(entry_id) {
	if ($F('inappropriate_reason_entry_' + entry_id) == '') {
		alert('Please select a reason');
	} else {
		request('blog.inappr.entry', 'action=inappr&entry_id=' + entry_id + '&reason_id=' + $F('inappropriate_reason_entry_' + entry_id));
		alert('Your request has been sent');
		Element.toggle('div_entry_mark_inappr_' + entry_id);
	}
}
var root_dir='http://www.mypetvideos.tv';
//var root_dir='http://localhost/mypetvideos';
function goto(){
    location.href=root_dir+'/videos/order/'+sort_by+'/period/'+period+''+'/category/'+category_id+'/kind/'+kind;
}

function change_state(elem,name,value){
    var fct='change_'+name+'('+elem+','+value+')'
    eval(fct)
}

function change_kind(elem,value){
    $$('#kind a').each(function(e){
        $(e).removeClassName('selected')
    })
    $(elem).addClassName('selected')
    kind=value
}

function change_period(elem,value){
    $$('#period a').each(function(e){
        $(e).removeClassName('selected')
    })
    $(elem).addClassName('selected')
    period=value;
}

function change_sort_by(elem,value){
    $$('#sort_by a').each(function(e){
        $(e).removeClassName('selected')
    })
    $(elem).addClassName('selected')
    sort_by=value;
}

function change_category(elem,value){
    $$('#category a').each(function(e){
        $(e).removeClassName('selected')
    })
    $(elem).addClassName('selected')
    category_id=value;
}var chat_request_inprogress = false;
var chat_request_lasttime = 0;

function Window_Size(param) {
    var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
	    myWidth = window.innerWidth;
    	myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
    	myWidth = document.documentElement.clientWidth;
    	myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    	//IE 4 compatible
        myWidth = document.body.clientWidth;
    	myHeight = document.body.clientHeight;
    }
    if (param=="W") {
    	return myWidth;
    } else {
        return myHeight;
    }
}

function getMouseXY(e) {
    if (IE) { // grab the x-y pos.s if browser is IE
        tempX = event.clientX + document.body.scrollLeft;
        tempY = event.clientY + document.body.scrollTop;
    }
    else {  // grab the x-y pos.s if browser is NS
        tempX = e.pageX;
        tempY = e.pageY;
    }
    if (tempX < 0){tempX = 0;}
    if (tempY < 0){tempY = 0;}
    mouse_coord[0]=tempX;
    mouse_coord[1]=tempY;
  return true
}

function Chat__UIC_Menu(idu) {

    $('chat__uic_menu').style.display='';
    $('chat__uic_menu').style.left=mouse_coord[0]+'px';
    $('chat__uic_menu').style.top=mouse_coord[1]+'px';
    //alert($('chat__uic_menu').style.display);
    private_chat_sel=idu;
    //$('chat__text_send').focus();
}

function Chat__Send_Msg() {
    var msg=$('chat__text_send').value.replace(/'/g,"[ampe]");
    msg=msg.replace(/"/g,'[quot]');
    msg=msg.replace(/\?/g,'[intreb]');
    msg=msg.replace(/</g,'[lt]');
    msg=msg.replace(/>/g,'[gt]');
    if (msg!='') {
        $('chat__text_send').value='';
        Ajax_Call('chat__send_msg.php','get','&msg_text='+msg+"&user_dest="+chat__selected_room+"&tip_send="+chat__visible_container,'');
    }
}

function MouseClickAnywhere() {
    $('chat__uic_menu').style.display='none';
}

function Chat__Select_Room(user) {
    clearTimeout(chat__time_blink[0][user]);
    clearTimeout(chat__time_blink[1][user]);
    chat__blockSendForm('block');
    if (user==0) {
        $('chat_close_convers_button').style.visibility='hidden';
    } else {
        $('chat_close_convers_button').style.visibility='visible';
    }

    $('chat__chat_container').innerHTML=chat__img_loader+' loading...';
    if (chat__selected_room!=0) {
        $('chat__select_room_'+chat__selected_room).className='';
    }
    $('chat__select_room_'+user).className='selected';
    chat__selected_room=user;
    clearInterval(obj_chek_conversation);
    obj_chek_conversation=setInterval("Ajax_Call('chat__display_conversation.php','get','&user="+user+"&tip_chat="+chat__visible_container+"&sec_valid_conference="+sec_valid_conference+"&sec_send_warning_msg="+sec_send_warning_msg+"&sec_to_check="+sec_to_check+"','chat__chat_container')",sec_to_check_convers);
}

function Chat__PrivateChat(user_id,user_name,just_open) {
    $('chat__select_room_'+user_id).innerHTML=user_name;
    if (just_open==0) {
        Chat__Select_Room(user_id);
    }
    chat__CalculateTabLat();
}

function chat__CalculateTabLat()
{
    var tablat=0;
    var old_name = new Array();
    //alert(chat__all_private_convers);
    for(var i=0; i<chat__all_private_convers.length; i++) {
        tablat=tablat+$('chat__select_room_'+chat__all_private_convers[i]).offsetWidth;
        old_name[i]=$('chat__select_room_'+chat__all_private_convers[i]).innerHTML;
    }

    if (tablat>($('chat__chat_tab_bar').offsetWidth-20) && chat__tablat!=tablat) {
        for(var i=1; i<chat__all_private_convers.length; i++) {
            //tablat=tablat+$('chat__select_room_'+chat__all_private_convers[i]).offsetWidth;
            if (old_name[i].length>2) {
                $('chat__select_room_'+chat__all_private_convers[i]).innerHTML=old_name[i].substring(0,old_name[i].length-2)+'.';
            }
        }
        chat__tablat=tablat;
        obj_tablat=setTimeout("chat__CalculateTabLat()",100);
    } else {
        //alert(chat__tablat+'...'+tablat);
        if (chat__tablat==tablat) {
            if ($('chat__chat_container').offsetWidth<150) {
                /*if (confirm('An error has occurred. This page must be reloaded.')) {
                    self.location.reload();
                }*/
                chat_ResizeWindowAll(500);
            } else {
                alert('Too many Private Chat Rooms are open. Please close some of them.');
            }
        }
    }
}

function chat__ClosePrivateChat() {
    $('chat__chat_container').innerHTML='';
    $('chat_close_convers_button').style.visibility='hidden';
    $('chat__select_room_'+chat__selected_room).innerHTML=chat__img_loader;
    Ajax_Call('chat__close_convers.php','get','&user_id='+chat__selected_room+'&tip_send='+chat__visible_container,'')
}

function chat__OpenNewPrivateChat(user_id,just_open) {
    exist=0;
    for (var i=0; i<chat__all_private_convers.length; i++) {
        if (chat__all_private_convers[i]==user_id) exist=1;
    }
    if (exist==0) {
        $('chat__chat_tab_bar').innerHTML+='<a title="" id="chat__select_room_'+user_id+'" href="javascript: void(Chat__Select_Room('+user_id+'))">'+chat__img_loader+'</a>';
        chat__all_private_convers[chat__all_private_convers.length]=user_id;
        Ajax_Call('chat__init_priv_convers.php','get','&user_id='+user_id+'&just_open='+just_open+'&tip_chat='+chat__visible_container,'');
    } else {
        Chat__Select_Room(user_id);
    }
}



function chat__Invitation_AcceptDeny(user_id,tip)
{
    try {
        Element.hide('the_invitation_div');
    } catch(e) {};
    Ajax_Call('chat__invit_acceptdeny.php','get','&user_id='+user_id+'&tip='+tip,'');
}

function chat__OpenChatFromConfMembersLnk(user_id)
{
    chat__DisplayThis(3);
    setTimeout('Chat__Select_Room(parseInt(3'+user_id+'));',1000);
}


function chat__MenuClickOnUser(user_id,tip)
{
    if (tip==0) {
        chat__DisplayThis(3);
        setTimeout("chat__checkifexistchatopened("+user_id+")",2000);
    } else {
        var str=chat__selected_room+"z";
        var fc=str.substring(0,1);
        if (fc=="1") {
            chat__InvitationRequest(user_id);
        } else {
            if (fc=="2") {
                alert("You dont have permision to invite friends in this Conference.\n\n Select one of your conferences and than invite friends.");
            } else {
                alert('Select Conference and than invite friends.');
            }
        }
    }
}

function chat__checkifexistchatopened(user)
{
    exist=0;
    user_id=parseInt("3"+user);
    for (var i=0; i<chat__all_private_convers.length; i++) {
        if (chat__all_private_convers[i]==user_id) exist=1;
    }
    if (exist==0) {
        $('chat__chat_tab_bar').innerHTML+='<a title="" id="chat__select_room_'+user_id+'" href="javascript: void(Chat__Select_Room('+user_id+'))">'+chat__img_loader+'</a>';
        chat__all_private_convers[chat__all_private_convers.length]=user_id;
        Ajax_Call('chat__init_priv_convers.php','get','&user_id='+user_id+'&just_open=0&tip_chat='+chat__visible_container,'');
        Ajax_Call('chat__invit_request.php','get','&user_id='+user+'&chat_room='+chat__selected_room,'');
    } else {
        Chat__Select_Room(user_id);
    }
}

function chat__InvitationRequest()
{
    var user_id=arguments[0];
    if (chat__visible_container!=2) {
        private_chat_sel=user_id;
        $('chat__request_chat_with_container').style.display='none';
        $('chat__request_chat_with_msg').style.display='';
        if (chat__visible_container==3) {
            chat__OpenNewPrivateChat(parseInt("3"+user_id),0);
        }
        Ajax_Call('chat__invit_request.php','get','&user_id='+user_id+'&chat_room='+chat__selected_room,'');
    }
}

var chat__time_blink = new Array();
chat__time_blink[0] = new Array();
chat__time_blink[1] = new Array();

function chat__BlinkBlink(user_id,cls)
{
    chat__time_blink[0][user_id] = setTimeout("chat__BlinkEfectiv("+user_id+",'')",500);
    chat__time_blink[1][user_id] = setTimeout("chat__BlinkEfectiv("+user_id+",'new_msg')",1000);
}

function chat__BlinkEfectiv(user_id,cls)
{
    $('chat__select_room_'+user_id).className=cls;
}

function chat__RequestCustomWith() {

    if (chat__visible_container==3 || (chat__visible_container==1 && chat__selected_room>0)) {
        Ajax_Call('chat__request_custom_with.php','get','&user_login='+$('input_request_chat_with').value,'');
    }
}

function chat__restoreRequestForm() {
    chat__invitation_sent_sw=0;
    $('chat__request_chat_with_container').style.display='';
    $('chat__request_chat_with_msg').style.display='none';
}

function chat__ViewFullArchive() {
    $('chat__chat_container').innerHTML=chat__img_loader;
    $('chat__chat_tab_bar').style.display='none';
    $('chat__view_full_archive_close').style.display='';
    $('chat__view_full_archive').style.display='none';
    $('chat_close_convers_button').style.display='none';
    $('chat__chat_tab_bar_on_archive').style.display='';
    clearInterval(obj_chek_conversation);
    Ajax_Call('chat__display_full_archive.php','get','&user_id='+chat__selected_room,'chat__chat_container');

}

function chat__CloseFullArchive() {
    $('chat__chat_container').innerHTML='';
    $('chat__chat_tab_bar').style.display='';
    $('chat__view_full_archive_close').style.display='none';
    $('chat__view_full_archive').style.display='';
    $('chat_close_convers_button').style.display='';
    $('chat__chat_tab_bar_on_archive').style.display='none';
    Chat__Select_Room(chat__selected_room);
}

function chat__displayArchiveFor(datt) {
    $('chat__vfa_container').innerHTML=chat__img_loader;
    $('chat__view_full_archive_close').blur();
    Ajax_Call('chat__display_archive_for.php','get','&user_id='+chat__selected_room+'&datt='+datt,'chat__vfa_container');
}

function chat__NoLogin()
{
    $('chat__friends_list_area').innerHTML='';
    $('chat__users_in_chat_area').style.display='none';
    $('chat__chat_area').innerHTML='<br />&nbsp;&nbsp;&nbsp;&nbsp;<h1>You are not logged in.</h1><br />&nbsp;&nbsp;&nbsp;&nbsp;<a href="'+root_address+'login.now/"><b>Click here to login.</b></a>';
    clearInterval(obj_chek_conversation);
    clearInterval(obj_chek_online);
    clearInterval(obj_chek_friends);
}

function chat__CheckScroll()
{
    chat__scroll=1;
    if (($('chat__chat_container').scrollHeight + 2) == ($('chat__chat_container').scrollTop + $('chat__chat_container').offsetHeight)) {
        chat__scroll=0;
    }

}















function chat_start_timer(suite_started_at) {
	chat_request_lasttime = suite_started_at;
	chat_interval_timer = window.setInterval(
		function () {
			if (chat_request_inprogress == false) { //only perform request after the previous has finished
				chat_request_inprogress = true;

				request(
					'chat.timer',
					'last=' + chat_request_lasttime,
					''
				);
			}
		},
		1000
	);
}

function chat_send_chatline() {
	if ($('chat_input').value != '') {
		request(
			'chat.send',
			Form.serialize('form_chat_input'),
			'',
			true,
			'post'
		);
	}

	$('chat_input').value = '';
	$('chat_input').focus();
}

function chat_addtext(html) {
	$('div_chat_area').innerHTML += html;
	$('div_chat_area').scrollTop = $('div_chat_area').scrollHeight;
}

function chat__DisplayThis() {
    var tip,ing;
    ing=arguments[0]; // tipul chatului

    $('chat__chat_container').innerHTML='';
    if (chat__visible_container>0) {
        $('lnk_for_title_'+chat__visible_container).className='';
    }
    chat__visible_container=ing;
    chat__blockSendForm("block");
    $('chat_rooms_title').innerHTML=$('lnk_for_title_'+ing).innerHTML;
    $('lnk_for_title_'+ing).className='selected';
    $('lnk_for_title_1_1').style.display='none';

    if (ing==1) {
        Ajax_Call('chat__display_conference.php','get','&tip_chat=1','');
        $('lnk_for_title_1_1').style.display='';
        $('chat__request_chat_form').innerHTML='Invite To Conference';
    } else if (ing==2) {
        Ajax_Call('chat__display_conference.php','get','&tip_chat=2','');
        $('chat__request_chat_form').innerHTML='';
    } else { // ing==3
        Ajax_Call('chat__display_conference.php','get','&tip_chat=3','');
        $('chat__request_chat_form').innerHTML='Invite To Chat';
    }

}

function chat__StartConference() {
    chat__DisplayThis(1);
    setTimeout("Ajax_Call('chat__start_new_conference.php','get','','')",500);
}

function chat__blockSendForm(tip) {
    var sw=true;
    if (tip=="block") {
        sw=true;
        $('chat__request_chat_with_container').style.display='none';
        $('chat__uic_container').style.display='none';
    } else {
        sw=false;
        if (chat__invitation_sent_sw==0) {
            chat__restoreRequestForm();
        }
        $('chat__uic_container').style.display='';
    }
    $('chat__text_send').disabled=sw;
    $('chat__button_send_msg').disabled=sw;
    if (chat__selected_room==0) {
        $('chat__request_chat_with_container').style.display='none';
        $('chat__uic_container').style.display='none';
    }
    if (chat__visible_container==3) {
        chat__restoreRequestForm();
        $('chat__uic_container').style.display='none';
    } else if (chat__visible_container==2) {
        $('chat__request_chat_with_container').style.display='none';
    }
}

function chat_ResizeWindowAll(brd)
{
    try {

        $('chat__container').style.height=ch__window_h+'px';
    	$('chat__logo_area').style.height=ch__logo_area+'px';
    	$('chat__users_in_chat_area').style.height=ch__window_h - ch__logo_area - $('chat__menu_left').offsetHeight + 'px';
    	$('chat__friends_list').style.height=ch__window_h-50+'px';
    	$('chat__uic_container').style.height=ch__window_h - ch__logo_area - 50 - $('chat__menu_left').offsetHeight +'px';
        if (brd!=0) {
            ch__chat_area_w=brd;
        } else {
            ch__chat_area_w=ch__window_w - $('chat__users_in_chat_area').style.width.replace('px','') -
    		    $('chat__friends_list_area').style.width.replace('px','') - 20;
            if (ch__chat_area_w<300) {
                ch__chat_area_w=300;
            }
        }
        $('chat__chat_container').style.width=ch__chat_area_w + 'px';
        $('chat__chat_send_butt').style.width=ch__chat_area_w + 'px';
        $('chat__chat_tab_bar').style.width=ch__chat_area_w + 'px';
        $('chat__chat_close_tab').style.width=ch__chat_area_w + 'px';
    	$('chat__chat_container').style.height = ch__window_h - ch__logo_area - 50 - $('chat__chat_send_butt').style.height.replace("px","")
    		- $('chat__chat_tab_bar').offsetHeight - $('chat__chat_close_tab').offsetHeight +'px';
        $('chat__chat_area').style.width=ch__chat_area_w - 20 + 'px';
    	$('chat__chat_area').style.height=ch__window_h-ch__logo_area+'px';
    	$('chat__chat_tab_bar_on_archive').style.height=$('chat__chat_tab_bar').offsetHeight+'px';
    	$('chat__chat_tab_bar_on_archive').style.width=$('chat__chat_tab_bar').style.width;
    } catch(e) {
        //alert(e);
    }
}
function open_watch_full(fullscreen_link) {
	var fs = window.open(
		fullscreen_link,
		"FullScreenVideo",
		"toolbar=no,width=" + screen.availWidth  + ",height=" + screen.availHeight + ",status=no,resizable=yes,fullscreen=yes,scrollbars=no");
	fs.focus();
}
function flashUploader(status, filename, id) {
	document.location.href = root_address + '?w=upload/finished';
}
function show_flash(id) {
	document.getElementById(id).outerHTML = document.getElementById(id).outerHTML;
}
/*
 * FlashObject embed
 * by Geoff Stearns (geoff@deconcept.com, http://www.deconcept.com/)
 *
 * v1.1.1 - 05-17-2005
 *
 * writes the embed code for a flash movie, includes plugin detection
 *
 * Usage:
 *
 *	myFlash = new FlashObject("path/to/swf.swf", "swfid", "width", "height", flashversion, "backgroundcolor");
 *	myFlash.write("objId");
 *
 * for best practices, see:
 *  http://blog.deconcept.com/2005/03/31/proper-flash-embedding-flashobject-best-practices/
 *
 */

var FlashObject = function(swf, id, w, h, ver, c) {
	this.swf = swf;
	this.id = id;
	this.width = w;
	this.height = h;
	this.version = ver;
	this.align = "middle";

	this.params = new Object();
	this.variables = new Object();

	this.redirect = "";
	this.sq = document.location.search.split("?")[1] || "";
	this.bypassTxt = "<p>Already have Macromedia Flash Player? <a href='?detectflash=false&"+ this.sq +"'>Click here if you have Flash Player "+ this.version +" installed</a>.</p>";
	
	if (c) this.color = this.addParam('bgcolor', c);
	this.addParam('quality', 'high'); // default to high
	this.doDetect = getQueryParamValue('detectflash');
}

var FOP = FlashObject.prototype;

FOP.addParam = function(name, value) { this.params[name] = value; }

FOP.getParams = function() { return this.params; }

FOP.getParam = function(name) { return this.params[name]; }

FOP.addVariable = function(name, value) { this.variables[name] = value; }

FOP.getVariable = function(name) { return this.variables[name]; }

FOP.getVariables = function() { return this.variables; }

FOP.getParamTags = function() {
    var paramTags = "";
    for (var param in this.getParams()) {
        paramTags += '<param name="' + param + '" value="' + this.getParam(param) + '" />';
    }
    return (paramTags == "") ? false:paramTags;
}

FOP.getHTML = function() {
    var flashHTML = "";
    if (navigator.plugins && navigator.mimeTypes.length) { // netscape plugin architecture
        flashHTML += '<embed type="application/x-shockwave-flash" src="' + this.swf + '" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '" align="' + this.align + '"';
        for (var param in this.getParams()) {
            flashHTML += ' ' + param + '="' + this.getParam(param) + '"';
        }
        if (this.getVariablePairs()) {
            flashHTML += ' flashVars="' + this.getVariablePairs() + '"';
        }

		flashHTML += ' allowScriptAccess="sameDomain"';
        flashHTML += '></embed>';
    } else { // PC IE
        flashHTML += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '" name="' + this.id + '" align="' + this.align + '">';
        flashHTML += '<param name="movie" value="' + this.swf + '" />';
		flashHTML += '<param name="allowScriptAccess" value="sameDomain" />'
        if (this.getParamTags()) {
            flashHTML += this.getParamTags();
        }
        if (this.getVariablePairs() != null) {
            flashHTML += '<param name="flashVars" value="' + this.getVariablePairs() + '" />';
        }
        flashHTML += '</object>';
    }
    return flashHTML;	
}

FOP.getVariablePairs = function() {
    var variablePairs = new Array();
    for (var name in this.getVariables()) { 
    	variablePairs.push(name + "=" + escape(this.getVariable(name))); 
    }
    return (variablePairs.length > 0) ? variablePairs.join("&"):false;
}

FOP.write = function(elementId) {
	if(detectFlash(this.version) || this.doDetect=='false') {
		if (elementId) {
			document.getElementById(elementId).innerHTML = this.getHTML();
		} else {
			document.write(this.getHTML());
		}
	} else {
		if (this.redirect != "") {
			document.location.replace(this.redirect);
		} else if (this.altTxt) {
			if (elementId) {
				document.getElementById(elementId).innerHTML = this.altTxt +""+ this.bypassTxt;
			} else {
				document.write(this.altTxt +""+ this.bypassTxt);
			}
		}
	}		
}

/* ---- detection functions ---- */
function getFlashVersion() {
	var flashversion = 0;
	if (navigator.plugins && navigator.mimeTypes.length) {
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			var y = x.description;
   			flashversion = y.charAt(y.indexOf('.')-1);
		}
	} else {
		result = false;
	    for(var i = 15; i >= 3 && result != true; i--){
   			execScript('on error resume next: result = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+i+'"))','VBScript');
   			flashversion = i;
   		}
	}
	return flashversion;
}

function detectFlash(ver) {	return (getFlashVersion() >= ver) ? true:false; }

// get value of query string param
function getQueryParamValue(param) {
	var q = document.location.search || document.location.href.split("#")[1];
	if (q) {
		var detectIndex = q.indexOf(param +"=");
		var endIndex = (q.indexOf("&", detectIndex) > -1) ? q.indexOf("&", detectIndex) : q.length;
		if (q.length > 1 && detectIndex > -1) {
			return q.substring(q.indexOf("=", detectIndex)+1, endIndex);
		} else {
			return "";
		}
	}
}

/* add Array.push if needed */
if(Array.prototype.push == null){
	Array.prototype.push = function(item) { this[this.length] = item; return this.length; }
}
function save_friend_emailable(friend_id, noemail) {
	request(
		'friends.emailable',
		'friend_id=' + friend_id + '&noemail=' + noemail,
		'',
		true,
		'post'
	);
}
//ajax requests
var ajax_is_done=1;
var sec_to_check=30000;

function error_filler(t, where, url) {
	$(where).innerHTML = '<div style="font-family:lucida console,courier new;font-size:12px;color:#990000;background-color:#ffcccc;margin:0px;padding:10px;border:1px solid #660000;">Error <b>' + t.status + '</b> in <b>' + url + '</b>: <b>' + t.statusText + '</b></div>';
}

function ajax_load(config) { //url, pars, where, evalonsuccess, hideloading
	if ((config.where != '') && (typeof(config.where) != 'undefined')) {
		if ($(config.where) != null) {
			if (config.hideloading == true) {
				//do nothing
			} else {
				if (config.where == 'all_page_content') {
					the_loading_div = {
						offsetWidth: 700,
						offsetHeight: 470
					};
				} else {
					the_loading_div = $(config.where);
				}
				temp_toinsert = '<table '+
									'class="transparent_overlay" '+
									'border="0" '+
									'cellspacing="0" '+
									'cellpadding="0" '+
									'width="' + the_loading_div.offsetWidth + '" '+
									'height="' + the_loading_div.offsetHeight + '">'+
									'<tr>'+
										'<td valign="middle" align="center">'+
											ajax_loading_toinsert+
										'</td>'+
									'</tr>'+
								'</table>';
				$(config.where).innerHTML = temp_toinsert + $(config.where).innerHTML;
			}
		} else {
			alert('id="' + config.where + '" not found. cannot load "' + config.url + '"');
		}
	}
	
	if (!config.method) {
		config.method = 'get';
	}
	
	var myAjax = new Ajax.Request(
		config.url,
		{
			method: config.method,
			parameters: 'ajax=true&random=' + Math.random() + '&' + config.pars,
			onSuccess: function(t) {
                //alert(chat__stop_ajax+"..."+chat__ajax_response[0]+"=="+chat__selected_room);
                try {
                    var chat__stop_ajax=0;
                    var raspuns_ajax=t.responseText;
                    var chat__ajax_response = new Array();
                    if (raspuns_ajax.indexOf('[chat_delimitator]')!=-1) {
                        chat__ajax_response=raspuns_ajax.split('[chat_delimitator]');
                        raspuns_ajax=chat__ajax_response[1];
                        chat__stop_ajax=1;
                    }

                    if (chat__stop_ajax==0 || (chat__ajax_response[0]==chat__selected_room && chat__selected_room!=0) ) {
                        if ((config.where) && (config.where != '')) {
        					$(config.where).innerHTML = raspuns_ajax;
        				}
                        if (t.responseText.indexOf('WebServerX')==-1) { // nu e ceva eroare ... inca nedetectata
                            //alert(t.responseText);
                            eval(config.onsuccess);
        				    raspuns_ajax.evalScripts();
                        } else {
                            alert('An Error Occurred. Please try again');
                        }
                    }
                    ajax_is_done=1;
                } catch(e) {
                    //alert(e);
                    ajax_is_done=1;
                }

				//window.scrollTo(0, 0);
			},
			onFailure: function(t) {
                error_filler(t, config.where, config.url);
			}
		}
	);
}

function request(requrl, pars, where, hideloading, method) {
	if (pars) {
		pars = '&' + pars;
	} else {
		pars = '';
	}
	ajax_load({
		url: root_address + 'request.php',
		pars: query_string + '&request=' + requrl + pars,
		where: where,
		hideloading: true,
		method: method
	});
}

function request_submit(pars) { //url, form, pars, history, where
	if (pars.form) {
		request(pars.url, Form.serialize(pars.form), pars.where, pars.hideloading, pars.method);
	} else if (pars.pars) {
		request(pars.url, pars.pars, pars.where, pars.hideloading, pars.method);
	} else {
		alert('Please provide .form or .pars');
	}
	if (pars.history) htmlhistory_add(pars.history);
}

function Ajax_Call(php_file,ajax_method,all_vars_sent,where) {
    //alert(ajax_is_done);
    if (ajax_is_done==1) {
        ajax_is_done=0;
        var pars = 'random=' + Math.random()+all_vars_sent;
    	var config=Array();
    	config.url = root_address + php_file;
    	config.pars=pars;
    	config.where=where;
        config.method=ajax_method;
    	config.hideloading=true;
    	ajax_load(config);
    } else {
        var new_ajax_time=setTimeout("Ajax_Call('"+php_file+"','"+ajax_method+"','"+all_vars_sent+"','"+where+"')",100);
    }
}

function paginateAjax(page, session_hash) {
    var pars = 'random=' + Math.random()+'&page='+page+'&session_hash='+session_hash;
    where='pagination_ajax_response';
    var config=Array();
    config.url = root_address + 'ajax.pagination.php';
    config.pars=pars;
    config.where=where;
    config.hideloading=true;
    ajax_load(config);
}

function Comics__ViewComic(cmc_number) {
	var pars = 'random=' + Math.random()+'&comic_number='+cmc_number;
    where='comments_rating_views';
    var config=Array();
    config.url = root_address + 'ajax.comicsCommRatViews.php';
    config.pars=pars;
    config.where=where;
    config.hideloading=true;
    ajax_load(config);
}

function Comics__Anonymous(cmc_number) {
	var pars = 'random=' + Math.random()+'&comic_number='+cmc_number;
    where='comments_rating_views';
    var config=Array();
    config.url = root_address + 'ajax.comicsCommAnonymous.php';
    config.pars=pars;
    config.where=where;
    config.hideloading=true;
    ajax_load(config);
}

function goValidateAnoComment() {
	var form_val = Form.serialize('form_comment_anonymus')
	the_call = Ajax_Call('ajax.ValidateAnonymousComment.php','post', form_val,'comments_rating_views');
	
	return false;	
}function MM_preloadImages() {
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function preload_selected_images() {
	MM_preloadImages(root_address + 'images/star_zero.gif');
	MM_preloadImages(root_address + 'images/star_half.gif');
	MM_preloadImages(root_address + 'images/star_one.gif');
	MM_preloadImages(root_address + 'images/video_save_add.gif');
	MM_preloadImages(root_address + 'images/video_save_done.gif');
	MM_preloadImages(root_address + 'images/video_save_over.gif');
}
function slideshow_drop_photo(photo_id, amount, text, fore, back, iscover) {
	slideshow_unloadwarn(true);
	
	//remove the initial info text
	Element.hide('div_sshold_info_text');
	
	rnd = Math.round(Math.random() * 1000000);
	
	img = document.createElement('img');
	img.id = 'ssdst_' + photo_id + '_' + rnd;
	img._amount = amount ? amount : 5; //todo unhardcode
	img.onmouseover = function() {
		slideshow_display_controls(this);
	};
	
	if (photo_id == 0) { //text slide
		img._type = 'text';
		img._text = text ? text : 'Blank Slide';
		img._fore = fore ? fore : 'ffffff';
		img._back = back ? back : '000000';
		if (text) {
			img.src = slideshow_img_text_url(img._text, img._fore, img._back);
		} else {
			img.src = $('slideshow_source_' + photo_id).src;
		}
	} else { //img slide
		img._type = 'img';
		if (srcimg = $('slideshow_source_' + photo_id)) {
			img.src = srcimg.src;
		} else {
			img.src = root_address + 'getimage.php?id=' + photo_id + '&fitw=110&fith=85&source=videos&random=0';
		}
	}
	
	$('sshold').appendChild(img);
	
	slideshow_create_sortable_film();
	
	if (iscover && iscover == '1') { //cover image?
		$('cover_dom_id').value = img.id;
	} else if (Sortable.serialize('sshold').split('&').length == 1) { //first image? set as cover :)
		$('cover_dom_id').value = img.id;
	}
}

function slideshow_create_sortable_film() {
	Sortable.create(
		'sshold',
		{
			tag			: 'img',
			overlap		: 'horizontal',
			constraint	: false,
			format		: /^(.*)$/,
			containment	: ['sshold', 'slideshow_trash'],
			onUpdate	: function() {
				slideshow_unloadwarn(true);
			}
		}
	);
}

function func_add_id_to_slide() {
	request_submit({
		url:	'my.slideshows.add',
		pars:	'nr=' + encodeURIComponent($F('add_id_to_slide'))
	});
}

function slideshow_img_text_url(text, fore, back) {
	return root_address +
			'drawtext.php?textcolor=' + encodeURIComponent(fore) +
			'&backcolor=' + encodeURIComponent(back) +
			'&text=' + encodeURIComponent(text);
}

var controls_last_displayed_for = '';

function slideshow_refresh_last_text() {
	if ((controls_last_displayed_for) && (controls_last_displayed_for._type) && (controls_last_displayed_for._type == 'text')) {
		controls_last_displayed_for.src = slideshow_img_text_url(
			controls_last_displayed_for._text,
			controls_last_displayed_for._fore,
			controls_last_displayed_for._back
		);
	}
}

function slideshow_display_controls(img) {
	Element.hide('ColourMod');
	
	slideshow_refresh_last_text();
	
	s = $('slideshow_controls');
	
	Element.show('slideshow_controls');
	
	Position.prepare();
	
	var offsets = Position.cumulativeOffset(img);
	var top     = offsets[1];
	var left    = offsets[0];
	var width   = img.clientWidth;
	var height  = img.clientHeight;
	
	s.style.left = (left) + 'px';
	s.style.top = (top + height) + 'px';
	
	try {
		//data
		$('slideshow_controls_amount').value = img._amount;
		$('slideshow_controls_text').value = img._text;
		$('slideshow_controls_fore').value = img._fore;		$('div_slideshow_controls_text_fore').style.backgroundColor = '#' + img._fore;
		$('slideshow_controls_back').value = img._back;		$('div_slideshow_controls_text_back').style.backgroundColor = '#' + img._back;
		$('slideshow_controls_cover').checked = (img.id == $F('cover_dom_id'));
		$('slideshow_controls_cover').disabled = $('slideshow_controls_cover').checked ? 'disabled' : '';
		
		$('slideshow_controls_amount').blur();
		$('slideshow_controls_text').blur();
		$('slideshow_controls_fore').blur();
		$('slideshow_controls_back').blur();
	} catch (e) {
	}
	
	if (img._type == 'text') {
		Element.show('div_slideshow_controls_text');
	} else {
		Element.hide('div_slideshow_controls_text');
	}
	
	s._img = img;
	
	controls_last_displayed_for = img;
}

function slideshow_save() {
	$('button_slideshow_save').disabled = 'disabled';
	$('button_slideshow_save').value = 'Saving...';
	request_submit({
		url:	'my.slideshows.save',
		method:	'post',
		pars:
			Form.serialize('form_slideshow_info') +
			'&action=slideshow.save&' +
			Sortable.serialize('sshold').split('&').map(
				function(item) {
					arr = [];
					imgid = item.split('[]=')[1];
					img = $(imgid);
					if (img) {
						id = /^ssdst_(([0-9]+)_([0-9]+))$/.exec(imgid)[1];
						arr.push('a_' + id + '=' + encodeURIComponent(img._amount));
						if (img._type == 'text') {
							arr.push('t_' + id + '=' + encodeURIComponent(img._text));
							arr.push('f_' + id + '=' + encodeURIComponent(img._fore));
							arr.push('b_' + id + '=' + encodeURIComponent(img._back));
						}
					}
					return arr.join('&');
				}
			).join('&')
	});
}

function slideshow_unloadwarn(yesno) {
	if (yesno) {
		$('button_slideshow_save').disabled = '';
		$('button_slideshow_save').value = 'Save Changes';
		window.onbeforeunload = function() {
			return 'Your SlideShow is not saved. If you click OK, you will loose any unsaved changes.'
		}
	} else {
		window.onbeforeunload = null;
	}
}
var slideshow_last_elapsed = 0;
var slideshow_last_index = 0;
var slideshow_status = 'stopped';
var slideshow_frames = [];

function slideshow_play(frms) {
	slideshow_frames = frms;
	slideshow_status = 'playing';
	
	function slideshow_play_callback() {
		slideshow_last_elapsed += .200;
		if (slideshow_last_elapsed >= frms[slideshow_last_index][1]) { //change slide
			if (slideshow_status == 'playing') {
				if ($('div_ss_' + frms[(slideshow_last_index + 1) % frms.length][0]).is_gata == 'true') { //advance if photo is loaded
					//Element.hide('div_ss_' + frms[slideshow_last_index][0]);
					Effect.Fade(
						'div_ss_' + frms[slideshow_last_index][0],
						{
							duration: 0.5,
							afterFinishInternal: function() {
								//Element.hide('div_ss_' + (frms[slideshow_last_index][0] - 1));
								if (slideshow_last_index == 0) {
									x = document.getElementsByClassName('class_div_ss_all');
									for (i = 0; i < x.length; i++) {
										Effect.Appear(x[i], {duration: 0});
									}
								}
							}
						}
					);
					
					slideshow_last_index = (slideshow_last_index + 1) % frms.length;
					
					//Element.show('div_ss_' + frms[slideshow_last_index][0]);
					slideshow_last_elapsed = 0;
					
				} else { //photo not loaded... wait a bit more (until it loads)
					slideshow_last_elapsed -= .200;
					//maybe todo show loading icon
				}
			}
		}
	}
	
	setInterval(slideshow_play_callback, 200);
	
	slideshow_refresh_buttons();
}

function slideshow_refresh_buttons() {
	switch (slideshow_status) {
		case 'stopped':
			Element.removeClassName('slideshow_button_play', 'disabled');
			Element.addClassName('slideshow_button_stop', 'disabled');
			Element.removeClassName('slideshow_button_next', 'disabled');
			Element.removeClassName('slideshow_button_prev', 'disabled');
		break;
		case 'playing':
			Element.addClassName('slideshow_button_play', 'disabled');
			Element.removeClassName('slideshow_button_stop', 'disabled');
			Element.removeClassName('slideshow_button_next', 'disabled');
			Element.removeClassName('slideshow_button_prev', 'disabled');
		break;
	}
}

function slideshow_control_play() {
	slideshow_status = 'playing';
	slideshow_refresh_buttons();
	slideshow_last_elapsed = 99999;
}

function slideshow_control_stop() {
	slideshow_status = 'stopped';
	slideshow_refresh_buttons();
}

function slideshow_control_next() {
	slideshow_control_stop();
	
	Effect.Fade(
		'div_ss_' + slideshow_frames[slideshow_last_index][0],
		{
			duration: 0.1,
			afterFinishInternal: function() {
				if (slideshow_last_index == 0) {
					x = document.getElementsByClassName('class_div_ss_all');
					for (i = 0; i < x.length; i++) {
						Effect.Appear(x[i], {duration: 0});
					}
				}
			}
		}
	);
	slideshow_last_index = (slideshow_last_index + 1) % slideshow_frames.length;
}

function slideshow_control_prev() {
	slideshow_control_stop();
	
	slideshow_last_index = (slideshow_last_index + slideshow_frames.length - 1) % slideshow_frames.length;
	
	Effect.Appear(
		'div_ss_' + slideshow_frames[slideshow_last_index][0],
		{
			duration: 0.1,
			afterFinishInternal: function() {
				if (slideshow_last_index == 0) {
					x = document.getElementsByClassName('class_div_ss_all');
					for (i = 0; i < x.length; i++) {
						Effect.Fade(x[i], {duration: 0});
					}
				}
			}
		}
	);
}
var stars_rate_msg = [];

stars_rate_msg[0] = ''; // is defined in  stars_rate_mouseover function ... see bellow
stars_rate_msg[1] = 'Poor';
stars_rate_msg[2] = 'Nothing special';
stars_rate_msg[3] = 'Good-Average';
stars_rate_msg[4] = 'Very Good';
stars_rate_msg[5] = 'Awesome';
stars_rate_msg[6] = 'Thanks for rating!';

function stars_rate_mouseover(prefix, x, tip_rating) {
    stars_rate_msg[0]='Rate this '+tip_rating;
    for (i = 1; i <= x; i++) {
		$(prefix + 'img_' + i).src = root_address + 'images/star_one.gif';
	}

	$(prefix + 'infodiv').innerHTML = stars_rate_msg[x];
}

function stars_rate_mouseout(prefix, x) {
	for (i = 1; i <= x; i++) {
		$(prefix + 'img_' + i).src = root_address + 'images/star_zero.gif';
	}
	
	$(prefix + 'infodiv').innerHTML = stars_rate_msg[0];
}

function stars_rate_click(prefix, x, tip_rating) {
	for (i = 1; i <= 5; i++) {
		$(prefix + 'img_' + i).onmouseover = '';
		$(prefix + 'img_' + i).onmouseout = '';
		$(prefix + 'img_' + i).onclick = '';
		$(prefix + 'img_' + i).style.cursor = '';
	}
	$(prefix + 'infodiv').innerHTML = stars_rate_msg[6];
	
	request('watch.rate', 'rating=' + x + '&what_rating='+tip_rating+'&prefix=' + prefix, prefix + 'starsdiv');
}
function photos_upload_start(file) {
	$("div_photos_upload").style.display = '';
	
	if ($('photo_' + file.name) == null) {
		div = document.createElement('div');
		div.id = 'photo_' + file.name;
		div.innerHTML = '<span id="photo_' + file.name + '_progress" class="upload_progress_bar"></span> Uploading <strong>' + file.name + '</strong> <span id="photo_' + file.name + '_progress_txt"></span>';
		
		$("div_photos_upload").appendChild(div);
	}
	
	Element.show('div_photos_uploading');
	Element.hide('div_photos_uploading_done');
}

function photos_upload_progress(file, bytes) {
	percent = Math.ceil((bytes / file.size) * 100);
	
	progress = $('photo_' + file.name + '_progress');
	progress.style.background = 'url(' + root_address + 'images/uploadprogressbar.png) no-repeat -' + (100 - percent) + 'px 0';
	
	progress = $('photo_' + file.name + '_progress_txt');
	progress.innerHTML = '(' + percent + '%)';
	
	Element.show('div_photos_uploading');
	Element.hide('div_photos_uploading_done');
}

function photos_upload_complete(file) {
	div = $('photo_' + file.name);
	div.innerHTML = 'Finished <strong>' + file.name + '</strong> (' + Math.ceil(file.size / 1024) + ' kb)';
}

function photos_upload_error(file) {
}

function photos_upload_cancel(file) {
}

function photos_upload_queuecomplete(file) {
	Element.hide('div_photos_uploading');
	Element.show('div_photos_uploading_done');
}
function watch_comment_save(parent_id) {
	request('watch.comment', 'action=comment&' + Form.serialize('form_add_video_comment_' + parent_id), 'div_btn_post_after_' + parent_id);
}
function faved_list_add(video_id) {
	request('watch.fave', 'action=fave&video_id=' + video_id);
}
function watch_mark_inappr(video_id) {
	if ($F('inappropriate_reason') == '') {
		alert('Please select a reason');
	} else {
		request('watch.inappr', 'action=inappr&video_id=' + video_id + '&reason_id=' + $F('inappropriate_reason'));
		alert('Your request has been sent');
		Element.toggle('div_watch_mark_inappr');
	}
}
function saved_list_add(video_id) {
	request('saved.action', 'action=save&video_id=' + video_id);
}

function saved_list_remove(video_id) {
	Effect.BlindUp('div_for_saved_list_' + video_id);
	request('saved.action', 'action=remove&video_id=' + video_id);
}
function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
