// framebuster, if you need to run our site in a frame please contact us first
//if (top != self) top.location = location;

function sp() {
	var ul = Cookie.get('_ul');
	var ctime = Cookie.get("_ctime");
	if (ul) $('txt_login').innerHTML = ul;
	else $('txt_login').innerHTML = 'anonymous';
}
function hideWarning18() {
	if($('flv_player'))
		$('flv_player').setStyle('display', 'show');
	$('warning_18').setStyle('display', 'none');
   	Cookie.set('warning_18', 'yes', { path: '/' });
}
function showWarning18() {
	return;
    //if(Cookie.get('warning_18')) return;
	//alert(Cookie.get('warning_18'));
    
    if(window.location.search.indexOf('w18=off') > 0) {
        Cookie.set('warning_18', 'yes', {domain: '.' + hostName, path: '/' })
        return;
    }

	if($('flv_player'))
		$('flv_player').setStyle('display', 'none');

    document.write("<div id='warning_18'><div id='warning_18_msg'>"
           + "<div align='center'><img id='site_logo' src='/img/logo-" + siteId + ".png?" + siteRev + "' width='250' height='105' /></div>"
            + "<h1 class='center'>WARNING: This website contains explicit adult material</h1>"
            + "<h3>You may only enter this Website if you are at least " 
            + "18 years of age, or at least the age of majority in the jurisdiction "
            + "where you reside or from which you access this Website.  If you do not "
            + "meet these requirements, then you do not have permission to use the "
            + "Website.</h3> "
            + "<h1 class='center'><a href='/' onclick=\"hideWarning18(); return false;\">Enter</a> or <a href='http://www.google.com/'>Leave</a></h1>"
            + "</div></div>"
    );
}

function ShowRating(obj, action) {
	if (action == 'over') {
		obj.style.cursor = "pointer";
		var num = obj.id;
		num = parseInt(num.replace('r',''));
		$('rate_st_0').style.display = 'none';
		for (var i = 1; i <= num; i++) {
			$('r' + i).src = '/img/rating_over.gif';
			$('rate_st_' + i).style.display = 'none';
		}
		switch (obj.id) {
			case 'r1': $('rate_st_1').style.display = ''; break;
			case 'r2': $('rate_st_2').style.display = ''; break;
			case 'r3': $('rate_st_3').style.display = ''; break;
			case 'r4': $('rate_st_4').style.display = ''; break;
			case 'r5': $('rate_st_5').style.display = ''; break;
		}
	} else {
		$('rate_st_0').style.display = '';
		for (var i = 1; i <= 5; i++) {
			$('r' + i).src = '/img/rating_out.gif';
			$('rate_st_' + i).style.display = 'none';
		}
	}
}

function ActivateTab(name) {
	if ($(name + '_a').className == 'selected') return;

	if(name == 'tb')
		for(var i = 1; i <= sCnt; i++)
			$('s' + i).src = sPath + i;

	var arrA = $('content').getElementsByTagName('a');
	var arrDiv = $('content').getElementsByTagName('div');
	for (var i = 0; i < arrA.length; i++)
		if (arrA[i].className == 'selected') arrA[i].className = '';
	for (var i = 0; i < arrDiv.length; i++)
		if (String(arrDiv[i].id).indexOf('_tab_body') != -1) arrDiv[i].style.display = 'none';
	$(name + '_a').className = 'selected';
	$(name + '_tab_body').style.display = '';
	
	return;
}

function PostComment() {
	$('btn_post_comment').value = 'Saving';
	$('btn_post_comment').disabled = true;
	$('frm_post_comment').send({
			onComplete: function (res) {
				$('btn_post_comment').value = 'Post new comment';
				$('btn_post_comment').disabled = false;
				var arrData = res.split('#separator#');
				var error = arrData[0];
				var message = arrData[1];
				var result = arrData[2];
				var ctime = arrData[3];
				var users = arrData[4];
				var txt = arrData[5];

				if (error == '' && message == '') $('msg').innerHTML = '';
				if (error != '') $('msg').innerHTML = error;
				if (message != '') $('msg').innerHTML = message;

				if (result == 'ok') {
					$('cnt_comments').innerHTML = parseInt($('cnt_comments').innerHTML) + 1
					var HTML = '<ol class="comments"><li value="' + $('cnt_comments').innerHTML + '"><b>' + users + '</b> at <i>' + ctime + '</i>:<br />';
					HTML += txt + '</li>';
					$('td_comments').innerHTML = String($('td_comments').innerHTML).replace('<ol class="comments">', HTML);
					if ($('login')) {
						$('login').value = '';
						$('email').value = '';
					}
					$('txt').value = '';
				}
			},
			onFailure: function (res) {
				$('msg').innerHTML = '<div class="warning_box">There was a problem retrieving the XML data : ' + res.statusText + '</div>';
				$('btn_post_comment').value = 'Post new comment';
				$('btn_post_comment').disabled = false;
			}
		}
	);
}

function SaveRating(name, rating) {
	for (var i = 1; i <= 5; i++) {
		$('r' + i).src = '/img/rating_out.gif';
		$('rate_st_' + i).style.display = 'none';
	}
	$('rate_st_0').style.display = '';
	new Ajax('/watch/rate?filename=' + name + '&rating=' + rating, {
		method: 'get',
		update: $('rate_st_0'),
		evalScripts: true
	}).request();
}

function SaveToFavorites(obj, name, login) {
	if (login) {
		new Ajax('/users/favorites?add=' + name, {method: 'get'}).request();
	} else {
		if (document.all) window.external.AddFavorite(document.location.href, document.title)
		else window.sidebar.addPanel( document.title, document.location.href, '' );		
	}
	obj.value = 'Saved';
	obj.disabled = true;
}

function animateThumb(tnpath, id, num) {
	var obj = $('i' + id);
	if (!obj.animate) return;
	if (obj.running) return;
    
    obj.running = true;
    if (!obj.images) {
        obj.images = new Array();
        for (i = 0; i < 6; i++) {
            obj.images[i] = new Image();
            obj.images[i].src = tnpath + (i + 1);
        }
    }

	obj.src = tnpath + num;
	setTimeout('animateThumb("' + tnpath + '",' + id + ',' + (num == 6 ? 1 : num + 1) + ')', 500);
    obj.running = false;
}


function point2rect(point, rect) {
	if (point.x < rect.left + 3) return false;
	if (point.x > rect.left + rect.width - 3) return false;
	if (point.y < rect.top + 3) return false;
	if (point.y > rect.top + rect.height - 3) return false;
	return true;
}

function search() {
	document.location.href = '/search/' + $('stype').value + '/' + $('query').value;
	return false;
}

function verifyFields() {
	$('res').style.display = 'none';
	$('btn_send').disabled = true;
	$('frm_data').send({
			onComplete: function (res) {
				var arrData = res.split('#separator#');
				var error = arrData[0];
				var message = arrData[1];
				var result = arrData[2];
				var fuid = arrData[3];
				$('btn_send').value = (result == 'ok' ? 'Upload' : 'Next >>>');
				$('btn_send').disabled = false;
				$('upload').style.display = (result == 'ok' ? '' : 'none');
				$('res').innerHTML = (result == 'ok' ? message : error);
				$('res').style.display = (message || error ? '' : 'none');
				if (result == 'ok') {
					$('frm_upload').action += '?X-Progress-ID=' + fuid;
					$('btn_send').onclick = function () {
						$('res').style.display = '';
						$('res').innerHTML = '';
						$('frms').style.display = 'none';
						$('frm_upload').submit();
						uploadVideo(fuid, $time())
					};
					for(var i=0;i<$('frm_data').elements.length;i++)
						$('frm_data').elements[i].disabled = true;
					$('cb_terms').disabled = true;
				}
			},
			onFailure: function (res) {
				$('res').innerHTML = '<div class="warning_box">There was a problem retrieving the XML data : ' + res.statusText + '</div>';
				$('res').style.display = '';
				$('btn_send').disabled = false;
			}
		}
	);
}

function uploadVideo(fuid, time) {
	var ajax = new Ajax('/upload/stats', {
			update: $('res'),
			method: 'get',
			data: 'stime=' + time + '&fuid=' + fuid + '&rnd=' + Math.floor(Math.random()*999999999999999) + '&sname=' + ServerName,
			evalScripts: true,
			onComplete: function(res) {
				if ($('waiting').style.display == 'none') $('waiting').style.display = '';
				if (res.indexOf('<div class="warning_box">') != -1 || res.indexOf('<script>') != -1) {
					$('waiting').style.display = 'none';
					return;
				}
			},
			onFailure: function(res) {
				$('res').innerHTML = '<div class="warning_box">There was a problem retrieving the XML data : ' + res.statusText + '</div>';
				$('res').style.display = '';
				$('waiting').style.display = 'none';
			}
	});
	ajax.request();
	setTimeout('uploadVideo(' + fuid + ',' + time + ')', 3 * 1000);
}

function ResendActivate() {
	$('frm_login').action = '/register/resend';
	$('frm_login').submit();
}

function EditVideo(id) {
	$('edit_video').setStyle('display', '');
	$('id').value = id;
	$('name').value = $('name_' + id).value;
	$('tags').value = $('tags_' + id).value;
	$('name').onchange = $('tags').onchange = function () {
		$('btn_ev').value = $('name_' + id).value == $('name').value && $('tags_' + id).value == $('tags').value ? 'Saved' : 'Save';
		$('btn_ev').disabled = $('name_' + id).value == $('name').value && $('tags_' + id).value == $('tags').value ? true : false;
	};
	$('btn_ev').onclick = function () {
		$('edit_video').send({
				onComplete: function (res) {
					if (res == 'ok') {
						$('video' + id + 'name').innerHTML = $('name').value;
						$('name_' + id).value == $('name').value;
						$('tags_' + id).value == $('tags').value;
						$('edit_video').setStyle('display', 'none');
						$('res').setStyle('display', 'none');
						$('btn_ev').value = 'Saved';
						$('btn_ev').disabled = true;
						document.location.href = '#video_' + id;
					} else {
						$('res').innerHTML = '<div class="warning_box">There was a problem retrieving the XML data</div>';
						$('res').style.display = '';
						$('btn_ev').disabled = false;				
					}
				},
				onFailure: function (res) {
					$('res').innerHTML = '<div class="warning_box">There was a problem retrieving the XML data : ' + res.statusText + '</div>';
					$('res').style.display = '';
					$('btn_ev').disabled = false;
				}
			}
		);
	};
}
