//==========================================
// Set up
//==========================================

// Sniffer based on http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
var uagent    = navigator.userAgent.toLowerCase();
var is_safari = ( (uagent.indexOf('safari') != -1) || (navigator.vendor == "Apple Computer, Inc.") );
var is_ie     = ( (uagent.indexOf('msie') != -1) && (!is_opera) && (!is_safari) && (!is_webtv) );
var is_ie4    = ( (is_ie) && (uagent.indexOf("msie 4.") != -1) );
var is_moz    = (navigator.product == 'Gecko');
var is_ns     = ( (uagent.indexOf('compatible') == -1) && (uagent.indexOf('mozilla') != -1) && (!is_opera) && (!is_webtv) && (!is_safari) );
var is_ns4    = ( (is_ns) && (parseInt(navigator.appVersion) == 4) );
var is_opera  = (uagent.indexOf('opera') != -1);
var is_kon    = (uagent.indexOf('konqueror') != -1);
var is_webtv  = (uagent.indexOf('webtv') != -1);

var is_win    =  ( (uagent.indexOf("win") != -1) || (uagent.indexOf("16bit") !=- 1) );
var is_mac    = ( (uagent.indexOf("mac") != -1) || (navigator.vendor == "Apple Computer, Inc.") );
var ua_vers   = parseInt(navigator.appVersion);
var movie_w = 500;
var movie_h = 400;

//==========================================
// Get cookie
//==========================================

function my_getcookie( name )
{
	cname = var_cookieid + name + '=';
	cpos  = document.cookie.indexOf( cname );

	if ( cpos != -1 )
	{
		cstart = cpos + cname.length;
		cend   = document.cookie.indexOf(";", cstart);

		if (cend == -1)
		{
			cend = document.cookie.length;
		}

		return unescape( document.cookie.substring(cstart, cend) );
	}

	return null;
}

//==========================================
// Set cookie
//==========================================

function my_setcookie( name, value, sticky )
{
	expire = "";
	domain = "";
	path   = "/";

	if ( sticky )
	{
		expire = "; expires=Wed, 1 Jan 2020 00:00:00 GMT";
	}

	if ( var_cookie_domain != "" )
	{
		domain = '; domain=' + var_cookie_domain;
	}

	if ( var_cookie_path != "" )
	{
		path = var_cookie_path;
	}

	document.cookie = var_cookieid + name + "=" + value + "; path=" + path + expire + domain + ';';
}

//==========================================
// Multi Page jumps
//==========================================

function multi_page_jump( url_bit, current, total_posts )
{
	msg = lang_tpl_q1 + " " + total_posts;

	userPage = prompt( msg, '' );

	if ( userPage > 0  && userPage < total_posts + 1 && userPage != current)
	{
		window.location = url_bit + userPage + ".html";
	}
}

//==========================================
// Hide / Unhide menu elements
//==========================================

function ShowHide(id1, id2)
{
	if (id1 != '') toggleview(id1);
	if (id2 != '') toggleview(id2);
}

//==========================================
// Get element by id
//==========================================

function my_getbyid(id)
{
	itm = null;

	if (document.getElementById)
	{
		itm = document.getElementById(id);
	}
	else if (document.all)
	{
		itm = document.all[id];
	}
	else if (document.layers)
	{
		itm = document.layers[id];
	}

	return itm;
}

//==========================================
// Show/hide toggle
//==========================================

function toggleview(id)
{
	if ( ! id ) return;

	if ( itm = my_getbyid(id) )
	{
		if (itm.style.display == "none")
		{
			my_show_div(itm);
		}
		else
		{
			my_hide_div(itm);
		}
	}
}

//==========================================
// Set DIV ID to hide
//==========================================

function my_hide_div(itm)
{
	if ( ! itm ) return;

	itm.style.display = "none";
}

//==========================================
// Set DIV ID to show
//==========================================

function my_show_div(itm)
{
	if ( ! itm ) return;

	itm.style.display = "";
}

//==========================================
// pop up window
//==========================================

function PopUp(url, name, width,height,center,resize,scroll,posleft,postop)
{
	showx = "";
	showy = "";

	if (posleft != 0) { X = posleft }
	if (postop  != 0) { Y = postop  }

	if (!scroll) { scroll = 1 }
	if (!resize) { resize = 1 }

	if ((parseInt (navigator.appVersion) >= 4 ) && (center))
	{
		X = (screen.width  - width ) / 2;
		Y = (screen.height - height) / 2;
	}

	if ( X > 0 )
	{
		showx = ',left='+X;
	}

	if ( Y > 0 )
	{
		showy = ',top='+Y;
	}

	if (scroll != 0) { scroll = 1 }

	var Win = window.open( url, name, 'width='+width+',height='+height+ showx + showy + ',resizable='+resize+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no');
}

function emo_pop()
{
  window.open( var_base_url + '/legends.html','Legends','width=250,height=500,resizable=yes,scrollbars=yes');
}

function CheckAll()
{
	var fmobj = document.forms['mutliact'];
	for (var i=0; i<fmobj.elements.length; i++)
	{
		var e = fmobj.elements[i];
		if ((e.name != 'allbox') && (e.type == 'checkbox') && (!e.disabled) && (e.value))
		{
			e.checked = fmobj.elements['allbox'].checked;
		}
	}
}

function ConfirmAction(url, msg)
{
	if ( ! msg )
	{
		msg = 'PLEASE CONFIRM:\nOK to proceed with delete?';
	}

	if (confirm( msg ))
	{
		window.location.href = url;
	}
	else
	{
		alert ( 'OK, action cancelled!' );
	}
}

function fullscreen(id,size)
{
	var c = document.getElementById("Movie" + id);
	if(c) {
		if(size == 1) {
			movie_w += 100;
			movie_h += 100;
			c.style.width = movie_w+"px";
			c.style.height = movie_h+"px";
		} else {
			if(movie_w < 300) return;
			movie_w -= 100;
			movie_h -= 100;
			c.style.width = movie_w+"px";
			c.style.height = movie_h+"px";
		}
	}
}

function ShowFlash(url,width,height,target) {
	var ids = unescape(url);
	ids = ids.replace("veoh.com/fullscreen_single.html?", "veoh.com/static/flash/players/fullscreen_single.swf?inVeoh=true&id=&player=fullscreen&version=4&");
	ids = ids.replace("megavideo.com/ep_gr.swf?v", "megavideo.com/ep_gr.swf?v");
	ids = ids.replace("megavideo.com/?v", "megavideo.com/ep_gr.swf?v");
	ids = ids.replace("/videoplay", "/googleplayer.swf");
	ids = ids.replace("veoh.com/videos/", "veoh.com/static/flash/players/videodetails2.swf?permalinkId=");
	ids = ids.replace("youtube.com/watch?v=", "youtube.com/v/");
	if(ids.match(/megavideo.com\/v/g)) {
		var vid = ids.split("/v/");
		ids = "http://megavideo.com/ep_gr.swf?v="+vid[1].substr(0,8);
	}
	if(ids.match(/dailymotion.com/g)) {
        var qrstr = list_value;
        httpRequest('/external.php','hiddenPlayer','GoPlay','url=' + qrstr);
		return;
	}
	var fo = new FlashObject(ids, '', width, height, 8, "");
	fo.addParam("menu", "false");
	if(target) {
		fo.write(target);
	} else {
		fo.write();
	}
}

function ShowMedia(url,width,height,target) {
    url = unescape(url);
    var Fhtml = "";
    Fhtml += "<object width="+width+" height="+height+" classid=clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6>";
    Fhtml += "<param name=URL value='"+url+"'>";
    Fhtml += "<param name=playCount value=1>";
    Fhtml += "<param name=autoStart value=-1>";
    Fhtml += "<param name=uiMode value=full>";
    Fhtml += "<param name=stretchToFit value=1>";
    Fhtml += "<param name=enabled value=-1>";
    Fhtml += "<embed width="+width+" height="+height+" src='"+url+"' playCount=1 AutoStart=True uiMode=full stretchToFit=1 enabled=1></embed>";
    Fhtml += "</object>";

    if(document.getElementById( target )) {
        document.getElementById( target ).innerHTML = Fhtml;
    } else {
        document.write( Fhtml );
    }
}