function removeSpaces(string) {
	var tstring = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
	tstring += splitstring[i];
	return tstring;
}

function setLanguage(url, lang) {
	var expiredays = 10;
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);

	test = 'language'+ '=' +escape(lang)+((expiredays==null) ? '' : '; expires='+exdate.toGMTString())+'; path=/;';
	document.cookie= test;
	window.location = url;
}

function getGalleryImages(objectid,current,page,fullscreen) {

	if(page == undefined) {
		page = "";
	}
	if(fullscreen == undefined) {
		fullscreen = "";
	}

		divid = "gallerycarousel";
		$.ajax({
		  url: "/inc/_ajax_gallery_images.php",
		  cache: false,
		  data: 'objectid=' + objectid + '&current=' + current + '&page=' + page + '&fullscreen=' + fullscreen,
		  beforeSend: function(){
		  	$("#"+divid).fadeTo("normal", 0);
		  },
		  success: function(html){
		    $("#"+divid).html(html).fadeTo("normal", 1);
		  }
		});
}

function getNowViewedVideos() {

	divid = "nowwatchedcotnent";
	$.ajax({
	  url: "/inc/_ajax_nowwatched.php",
	  cache: false,
	  data: '',
	  beforeSend: function(){
	  	$("#"+divid).fadeTo("normal", 0);
	  },
	  success: function(html){
	    $("#"+divid).html(html).fadeTo("normal", 1);
	  }
	});

}

function getObjectFavs(objectid, type, action) {

	if(type == undefined) {
		type = "";
	}
	if(action == undefined) {
		action = "";
	}

	divid = "objectfavorites";
	$.ajax({
	  url: "/inc/_ajax_object_favorites.php",
	  cache: false,
	  data: 'objectid=' + objectid + '&type=' + type + '&action=' + action,
	  beforeSend: function(){
	  	$("#"+divid).html('<img src="/images/ajax-loader.gif" alt="loader"> Loading ...');
	  },
	  success: function(html){
	    $("#"+divid).html(html);
	  }
	});

}

function getComments(objectid, type) {

	if(type == undefined) {
		type = "";
	}

	divid = "comments";
	$.ajax({
	  url: "/inc/_ajax_comments.php",
	  cache: false,
	  data: 'objectid=' + objectid + '&type=' + type,
	  beforeSend: function(){
	  	$("#"+divid).html('<img src="/images/ajax-loader.gif" alt="loader"> Loading ...');
	  },
	  success: function(html){
	    $("#"+divid).html(html);
	  }
	});

}

function sendcomment(objectid, type) {
	if(document.getElementById('commenttext').value=="") {
		alert("You must write your comment!");
		document.getElementById('commenttext').focus();
		return false;
	} else {

		comment = document.getElementById('commenttext').value;

		divid = "comments";

		$.ajax({
		  url: "/inc/_ajax_comments.php",
		  cache: false,
		  data: 'objectid=' + objectid + '&comment=' + comment + '&type=' + type,
		  success: function(html){
		    $("#"+divid).html(html);
		  }
		});

	}
}


function bookmark() {
	var title= document.title;
	try {
		if (window.sidebar) {
			window.sidebar.addPanel(title,window.location,'')
		} else {
			window.external.AddFavorite(window.location,title)
		}
	}

	catch(e) {
		alert('Sorry, your browser doesn\'t support this function. Try to press Ctrl+D to bookmark this page manually.')
	}

	return false
}

function thumbChange(thumbid, fileid) {

	var thumbObj = document.getElementById('editthumbs');
	var containedDivElements = thumbObj.getElementsByTagName("img");

	for (var i = 0; i < containedDivElements.length; i++) {
		var elem = containedDivElements[i];
		elem.className = "thumbnail";
	}

	var thumbObj = document.getElementById(thumbid);
	thumbObj.className = "thumbnail thumbselected";

	$.ajax({
	  url: "/inc/_update_thumbnail.php",
	  cache: false,
	  data: 'fileid=' + fileid + '&thumbid=' + thumbid,
	  success: function(html){
	    $("#thumbnailupdate").html(html);
	  }
	});
}

function changepic(id, p, img) {
	document.getElementById('img' + id).src = serverUrl + p + img;
}

function rotate(id, p) {
	if(stat[id]) {
		if(actualImg[id] == undefined) {
			actualImg[id] = 0;
		}

		actualImg[id]++;

		if(actualImg[id] > 9) {
			actualImg[id] = 0;
		}
		changepic(id, p, actualImg[id] + '.jpg');
		//setTimeout('changepic(\'' + id + '\', \'' + j + '.jpg\')', 20);
		setTimeout('rotate(\'' + id + '\', \'' + p + '\')', 600);
	}
}

function startR(id, p) {
	stat[id] = 1;
	rotate(id, p);
}

function endR(id) {
	stat[id] = 0;
}

var actualImg = new Array();
var stat = new Array();

var serverUrl = "http://data.mojeporno.sk/";

function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

		function deleteConfirmImage(id) {

			var confirmation = confirm("Are you sure you want to delete this image?");
			if(confirmation == true) {
				document.getElementById('imgdel' + id).submit();
			}

		}

		function deleteConfirmVideo(id) {

			var confirmation = confirm("Are you sure you want to delete this video?");
			if(confirmation == true) {
				document.getElementById('del' + id).submit();
			}

		}


/*
 * jQuery AntiLeak for IE
 *
 * Copyright (c) 2009 Barcode Computers Ltd.
 *
 */

(function($) { // hide the namespace

    function AntiLeak() { }
    $.preventLeaks = new AntiLeak();

    $.extend(AntiLeak.prototype, {
        _checkExternalClick: function(event) { }
    });

    $.fn.preventLeaks = function() {
        $(document).mousedown($.preventLeaks._checkExternalClick).
                            find('body').append($.preventLeaks.dpDiv);
    };

})(jQuery);

/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};