if(!document.getElementById)
{
	if(document.all)
	{
		accessObj = function()
		{
			if(typeof document.all[arguments[0]]!="undefined")
				return document.all[arguments[0]];
			else
				return null;
		}
	}
	else if(document.layers)
	{
		accessObj = function()
		{
			if(typeof document[arguments[0]]!="undefined")
				return document[arguments[0]];
			else
				return null;
		}
	}
}
else
{
	accessObj = function()
	{
		return document.getElementById(arguments[0]);
	}
}

var dir_fix;

function set_dirfix(fix)
{
	dir_fix = fix;
}

function listened(tar)
{
	$("#ref_"+tar).addClass("listened");
}

function synopsis(show, hide, tab, tab_off)
{
	$("#"+show).removeClass("no_display");
	$("#"+show).addClass("display");
	$("#"+hide).removeClass("display");
	$("#"+hide).addClass("no_display");
	$("#"+tab).removeClass(tab);
	$("#"+tab).addClass(tab+"_active");
	$("#"+tab_off).removeClass(tab_off+"_active");
	$("#"+tab_off).addClass(tab_off);

}

function set_content(div, data)
{
	var obj = accessObj(div);
	if (!isNull(obj))
		obj.innerHTML = data;
}

function a_call(script, values, callback_div)
{
	var xmlHttpReq = false;
	var self = this;
	var callback = callback_div;
	self.xmlHttpReq = (typeof(XMLHttpRequest) != "undefined") ? new XMLHttpRequest() : new ActiveXObject("Msxml2.XMLHTTP");
	self.xmlHttpReq.open('POST', script, true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function()
	{
		var response;
		if (self.xmlHttpReq.readyState == 4)
		{
			set_content(callback, self.xmlHttpReq.responseText);
		}
	}
	self.xmlHttpReq.send(values);
}

function switch_form_elements(original, switch_over)
{
	var new_status = true;
	var i;
	var obj;

	if (original.checked)
		new_status = false;

	for(i=0; i<switch_over.length; i++)
	{
		obj = accessObj(switch_over[i]);
		obj.disabled = new_status;
	}
}

function switch_form_elements_select(original, switch_over)
{
	var new_status = true;
	var i;
	var obj;

	if (original == 'Y')
		new_status = false;

	for(i=0; i<switch_over.length; i++)
	{
		obj = accessObj(switch_over[i]);
		obj.disabled = new_status;
	}
}

var first_check = true;
var randid = "";
function upload_check_title(val, types, type_format, random_id, uploader_location, flash_location)
{
	if (first_check)
	{
		if (val != "")
		{
			randid = random_id;

			var flashvars = {};
			flashvars.filetypes = types;
			flashvars.mactypes = types;
			flashvars.filetypeformat = type_format;
			flashvars.uploader = uploader_location+"?id="+random_id;
			flashvars.maxsize = "268435456";
			var params = {};
			params.menu = false;
			params.swLiveConnect = true;
			params.allowFullScreen = true;
			params.wmode = "transparent";
			var attributes = {};
			attributes.id = "uploaderholder_swf";
			attributes.name = "uploaderholder_swf";
			swfobject.embedSWF(flash_location, "uploaderholder", "350", "22", "8.0.0", null, flashvars, params, attributes);

			first_check = false;
		}
	}
}

function set_file(file_name, temp)
{
	if (file_name != "")
	{
		var obj = accessObj("uploadfrm");		
		obj.flmf_file_name.value = file_name;
		obj.flmf_file_temp_name.value = randid;
		obj.submitbutton.disabled = false;
	}
}

var film_title = "";
function toggle_search_button(title)
{
	film_title = title;
	film_title = film_title.replace(" ", "+");
	var obj = accessObj("button_search_imdb");
	obj.disabled = (title != "") ? false : true;
}

function search_imdb()
{
	window.open("http://www.imdb.com/find?s=tt&q="+film_title,"imdbsearch");
}

function add_admin()
{
	var obj = accessObj("add_admins");
	var index = obj.selectedIndex;
	if (index != -1)
	{
		var selected_option_value = obj.options[index].value;
		var selected_option_text = obj.options[index].text;

		// remove option
		obj.remove(index);

		// add option
		var elOptNew = document.createElement('option');
		elOptNew.text = selected_option_text;
		elOptNew.value = selected_option_value;
		
		var obj2 = accessObj("current_admins");
		try 
		{
			obj2.add(elOptNew, null); // standards compliant; doesn't work in IE
		}
		catch(ex) 
		{
			obj2.add(elOptNew); // IE only
		}
		var obj = accessObj("admins");
		if (obj.value != "")
			obj.value += ","+selected_option_value;
		else
			obj.value = selected_option_value;
	}
}

function remove_admin()
{
	var obj = accessObj("current_admins");
	var obj2 = accessObj("add_admins");
	var index, selected_option_value, selected_option_text, elOptNew, admins_str;
	admins_str = "";
	for (index = obj.length - 1; index>=0; index--) 
	{
		if (obj.options[index].selected)
		{
			selected_option_value = obj.options[index].value;
			selected_option_text = obj.options[index].text;
			
			obj.remove(index);

			elOptNew = document.createElement('option');
			elOptNew.text = selected_option_text;
			elOptNew.value = selected_option_value;			
			
			try 
			{
				obj2.add(elOptNew, null); // standards compliant; doesn't work in IE
			}
			catch(ex) 
			{
				obj2.add(elOptNew); // IE only
			}
		}
		else
		{
			selected_option_value = obj.options[index].value;
			if (admins_str != "")
				admins_str += ","+selected_option_value;
			else
				admins_str = selected_option_value;
		}
	}
	var obj = accessObj("admins");
	obj.value = admins_str;
}

function openDiv(name)
{
	var obj = accessObj(name);
	if (!isNull(obj))
		obj.style.display = "block";
}

function closeDiv(name)
{
	var obj = accessObj(name);
	if (!isNull(obj))
		obj.style.display = "none";
}

function setOpacity(objname, o)
{
	var obj = accessObj(objname);
	var per = o / 100;
	if (o < 0)
	{
		o = 0;
		per = 0;
	}
	if (o>100)
	{
		o = 100;
		per = 1;
	}
    obj.style.opacity = (per);
    obj.style.MozOpacity = (per);
    obj.style.KhtmlOpacity = (per);
    obj.style.filter = 'alpha(opacity=' + o + ');';
}

function isNull(val)
{
	return(val==null);
}

function open_tab(tab)
{
	var obj;
	if (c_item != "")
	{
		if (c_item != "upholder")
			closeDiv("items_"+c_item);
		else
			closeDiv(c_item);
		if (tab != "upholder" && c_tab != "")
		{
			obj = accessObj("change_me_"+c_tab);
			obj.className = "normaltab";
		}
	}
	if (tab != "upholder")
		openDiv("items_"+tab);
	else
		openDiv(tab);
	if (tab != "upholder")
	{
		obj = accessObj("change_me_"+tab);
		obj.className = "activetab";
		c_tab = tab;
	}
	c_item = tab;
}

function submit_file(script)
{
	openDiv("popupholder");

	var xmlHttpReq2 = false;
	var self = this;
	var values = "";
	var obj = accessObj("uploadfrm");
	values = "flmf_file_temp_name="+obj.flmf_file_temp_name.value+"&flmf_film_id="+obj.flmf_film_id.value+"&flmf_fcat_id="+obj.flmf_fcat_id.value+"&flmf_fsub_id="+obj.flmf_fsub_id.value+"&flmf_title="+obj.flmf_title.value+"&flmf_description="+obj.flmf_description.value+"&flmf_file_name="+obj.flmf_file_name.value;

	self.xmlHttpReq2 = (typeof(XMLHttpRequest) != "undefined") ? new XMLHttpRequest() : new ActiveXObject("Msxml2.XMLHTTP");
	self.xmlHttpReq2.open('POST', script, true);
	self.xmlHttpReq2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq2.onreadystatechange = function()
	{
		var response;
		if (self.xmlHttpReq2.readyState == 4)
		{
			// set_content("popupholder", self.xmlHttpReq2.responseText);
			// alert(self.xmlHttpReq2.responseText);
			window_refresh();
		}
	}
	self.xmlHttpReq2.send(values);
}

function c_link(link, text)
{
	var userinput;
	if (text != "")
		userinput = confirm(text);
	else
		userinput = true;
	if (userinput)
		window.location = link;
	return false;
}

function window_refresh()
{
	window.location.reload(true);
}

function set_type(index, value)
{
	selected_types[index] = value;
}

function c_download(item)
{
	var link = download_links[item][selected_types[item]];
	window.location = link;
}

var basket_download_timer = false;

function download_basket(script, update_location)
{
	a_call(update_location, '', 'basket_content');
	basket_download_timer = setInterval("basket_update('"+update_location+"', '', 'basket_content')", 5000);

	var xmlHttpReq3 = false;
	var self = this;
	var values = "";

	self.xmlHttpReq3 = (typeof(XMLHttpRequest) != "undefined") ? new XMLHttpRequest() : new ActiveXObject("Msxml2.XMLHTTP");
	self.xmlHttpReq3.open('POST', script, true);
	self.xmlHttpReq3.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq3.onreadystatechange = function()
	{
		var response;
		if (self.xmlHttpReq3.readyState == 4)
		{
			clearInterval(basket_download_timer);
			basket_download_timer = false;
			set_content("basket_content", self.xmlHttpReq3.responseText);
		}
	}
	self.xmlHttpReq3.send("");

    $("#basket_popup").dialog('option', 'position', 'center');
	$("#basket_popup").dialog('option', 'title', 'Your basket');
	$("#basket_popup").dialog('open');
}


function basket_update(script, values, callback_div)
{
	var xmlHttpReq = false;
	var self = this;
	var callback = callback_div;
	self.xmlHttpReq = (typeof(XMLHttpRequest) != "undefined") ? new XMLHttpRequest() : new ActiveXObject("Msxml2.XMLHTTP");
	self.xmlHttpReq.open('POST', script, true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function()
	{
		var response;
		if (self.xmlHttpReq.readyState == 4)
		{
			if (basket_download_timer != false)
				set_content(callback, self.xmlHttpReq.responseText);
		}
	}
	self.xmlHttpReq.send(values);
}

var basket_set = 0;
var basket_timeout = "";

function c_basket(item)
{
	if (basket_set == 0)
	{
		basket_set = 1;
		$("#basketnotice").dialog('open');
		basket_timeout = setTimeout("close_basket()", 4000);
	}
	var link = basket_links[item][selected_types[item]];
	a_call(link, "", "pm_2");
}

function close_basket()
{
		basket_set = 0;
		$('#basketnotice').dialog('close');
}

function show_clip(file, player, holder)
{
	alert("this is where we pop up video player");
}

function set_bg_color(item, color)
{
	var obj = accessObj(item);
	if (!isNull(obj))
		obj.style.background = color;
}

function reset_bg_color(item, type)
{
	var obj = accessObj(item);
	if (!isNull(obj))
		{
			if(type == 1)
			{
				obj.style.background = "#e9e9e9";
				obj.style.color = "#000";
			}
			else
			{
				obj.style.background = "#fafafa";
				obj.style.color = "#000";
			}
		}
}


function set_action(form_obj, link, target)
{
	var obj = accessObj(form_obj);
	if (!isNull(obj))
	{
		obj.action = link;
		if (target != "")
			obj.target = "_blank";
		obj.submit();
		if (target != "")
			window.location = target;
	}
}

function open_player(type, dir_assets, medialocation, image_location, statslocation)
{
	switch(type)
	{
		case "audio":
			var flashvars = {};
			flashvars.medialocation = medialocation;
			if (statslocation)
				flashvars.statslocation = statslocation;
			var params = {};
			params.menu = false;
			params.swLiveConnect = true;
			params.allowFullScreen = true;
			params.wmode = "transparent";
			var attributes = {};
			attributes.id = "mediaplayer_swf";
			attributes.name = "mediaplayer_swf";
			swfobject.embedSWF(dir_assets+"flash/mp3player.swf", "mediaplayer_holder2", "170", "20", "8.0.0", null, flashvars, params, attributes);
		break;
		case "video":
			var flashvars = {};
			flashvars.medialocation = medialocation; // "{dir_fix}assets/uploads/flv/{flmf_id}.flv";
			flashvars.imagelocation = image_location; // "{dir_fix}assets/posters/{flmf_film_id}.jpg";
			if (statslocation)
				flashvars.statslocation = statslocation;
			var params = {};
			params.menu = false;
			params.swLiveConnect = true;
			params.allowFullScreen = true;
			params.wmode = "transparent";
			var attributes = {};
			attributes.id = "mediaplayer_swf";
			attributes.name = "mediaplayer_swf";
			swfobject.embedSWF(dir_assets+"flash/videoplayer.swf", "mediaplayer_holder2", "360", "270", "8.0.0", null, flashvars, params, attributes);
		break;
	}
	openDiv("player_holder");
}

function close_player()
{
	/*var obj = accessObj("mediaplayer_holder2");
	alert(obj);
	obj.innerHTML = "";*/
	closeDiv("player_holder");
}

function searchUsers(nltr_id)
{
	set_content("searchResult", "Searching...");
	a_call(dir_fix+"calls/find-newsletter-users.php", "nltr_id="+nltr_id, "searchResult");
}

function nl_add_everyone(nltr_id)
{
	a_call("add-everyone/", "", "");
	a_call("../../../calls/data.php?p=_QndJlmdlh0d61DTuFWZLdXWzdEbaVGd0FEd0VWdyJXLEJnblJ3YZVmcp9mdnVWVyB3cMZycuFGbnRHRyN1XslGUkZUPXFTSmoHby9WajtWPK5yQuY1LB5yYu00Ls5CeuQ2L", "", "dataholder");
}

function nl_remove_user(user_id)
{
	var userinput = confirm("Are you sure you don't want this user to recieve this newsletter?");
	if (userinput)
	{
		a_call("remove/"+user_id+"/", "", "");
		a_call("../../../calls/data.php?p=_QndJlmdlh0d61DTuFWZLdXWzdEbaVGd0FEd0VWdyJXLEJnblJ3YZVmcp9mdnVWVyB3cMZycuFGbnRHRyN1XslGUkZUPXFTSmoHby9WajtWPK5yQuY1LB5yYu00Ls5CeuQ2L", "", "dataholder");
	}
}

function nl_add_users()
{
	alert("I'm over here now");
}

function open_image_preview(img_url, title, width, height)
{
	$("#imgpreviewcontent").html("<img id=\"preview_image\" src=\""+img_url+"\" alt=\""+title+"\">");
	$("#imgpreview").dialog('option', 'title', title);
    $("#preview_image").load(function() {
    $("#imgpreview").dialog('option', 'position', 'center');
	$("#imgpreview").dialog('option', 'width', width + 45);
	$("#imgpreview").dialog('option', 'height', height + 68);	
	$("#imgpreview").dialog('open');
	$('.ui-widget-overlay').click(function() { $("#imgpreview").dialog("close"); });
    });
}

var closing_vid = "";
var vid_playing = "";
var current_vid = "";

function on_vid()
{
	clearTimeout(closing_vid);
}

function close_dialog()
{
	closing_vid = setTimeout('close_vid()', 100);
}

function close_vid()
{
	vid_playing = false;
	$("#videopreview").dialog('close');
	$("#videopreview").html("<div id=\"");
}

function open_video_approve(dir_assets, medialocation, image_location, statslocation, title, which)
{
	$("#videopreview").html("<div id=\"videopreviewcontent\"></div>");

	var flashvars = {};
	flashvars.medialocation = medialocation;
	flashvars.imagelocation = image_location;
	flashvars.playing = "true";
	if (statslocation != "")
		flashvars.statslocation = statslocation;
	var params = {};
	params.menu = false;
	params.swLiveConnect = true;
	params.allowFullScreen = true;
	params.wmode = "solid";
	var attributes = {};
	var currentTime = new Date()
	var unique_key = currentTime.getHours()+""+currentTime.getMinutes()+""+currentTime.getSeconds();
	attributes.id = "mediaplayer_swf"+unique_key;
	attributes.name = "mediaplayer_swf"+unique_key;
	swfobject.embedSWF(dir_assets+"flash/videoplayer.swf", "videopreviewcontent", "360", "270", "8.0.0", null, flashvars, params, attributes);	

	$("#videopreview").dialog('option', 'position','center');
	$("#videopreview").dialog('option', 'title', title);
	$("#videopreview").dialog('open');
}

function remove_vid()
{
	current_vid = "";
	vid_playing = false;
}

function off_vid()
{
}

function open_video_preview(dir_assets, medialocation, image_location, statslocation, title, which)
{
	if(vid_playing && current_vid == medialocation)
	{
		close_vid()
		current_vid = "";
	}else
	{
		if(current_vid == medialocation)
		{
			close_vid()
			current_vid = "";
		}else
		{
			$("#videopreview").html("<div onmouseover=\"on_vid();\" onmouseout=\"off_vid();\" ><div id=\"videopreviewcontent\"></div></div>");
			var scrollPosition = $(window).height() + $(window).scrollTop();
			var pos = $("#film_"+which).offset();
		
			if (scrollPosition == $(window).height())
			{
				var top_pos = (pos.top - 330);
			}
			else
			{
				var top_pos = (pos.top - (330 + $(window).scrollTop()));		
			}
			
			var left_pos = (pos.left - 0);
				
			var flashvars = {};
			flashvars.medialocation = medialocation;
			flashvars.imagelocation = image_location;
			flashvars.playing = "true";
			if (statslocation != "")
				flashvars.statslocation = statslocation;
			var params = {};
			params.menu = false;
			params.swLiveConnect = true;
			params.allowFullScreen = true;
			params.wmode = "solid";
			var attributes = {};
			var currentTime = new Date()
			var unique_key = currentTime.getHours()+""+currentTime.getMinutes()+""+currentTime.getSeconds();
			attributes.id = "mediaplayer_swf"+unique_key;
			attributes.name = "mediaplayer_swf"+unique_key;
			swfobject.embedSWF(dir_assets+"flash/videoplayer.swf", "videopreviewcontent", "360", "270", "8.0.0", null, flashvars, params, attributes);	
		
			$("#videopreview").dialog('option', 'position',[left_pos,top_pos]);
			$("#videopreview").dialog('option', 'title', title);
			$("#videopreview").dialog('open');
			$('.ui-icon-closethick').click(function() { remove_vid()});
			vid_playing = true;
			current_vid = medialocation;
		}
	}
}

function update_merchandise()
{
	$("#merchform").submit();
}

function calc_dead_date(livedate, object)
{
	var newdate = '';
	var tmp = livedate.split('/');
	tmp[0] = parseInt(tmp[0]);
	tmp[1] = parseInt(tmp[1]);
	tmp[2] = parseInt(tmp[2]);

	tmp[1] += 3;
	if (tmp[1] > 12)
	{
		tmp[1] -= 12;
		tmp[2]++;
	}

	if (tmp[0] < 10)
		tmp[0] = '0'+tmp[0]+'';

	if (tmp[1] < 10)
		tmp[1] = '0'+tmp[1]+'';

	newdate = tmp[0]+'/'+tmp[1]+'/'+tmp[2];

	$('#'+object).val(newdate);
}

function init_convert_message()
{
	$(function() {
		$("#convertmessage").dialog({ autoOpen: false, bgiframe: true, draggable: false, modal: true, width: 388, height: 121, resizable: false });
	});
}

function show_convert_message()
{
	$("#convertmessage").dialog('open');
}

var typesopen = new Object;
function toggle_ftype(parent_id, type)
{
	if (typesopen[parent_id] == "undefined" || typesopen[parent_id] == undefined)
	{
		typesopen[parent_id] = "all";
	}

	$("#button_"+parent_id+typesopen[parent_id]).removeClass().addClass("tab_button");
	typesopen[parent_id] = type;
	$("#button_"+parent_id+type).removeClass().addClass("active_tab_button");

	if (type == "all")
	{
		$("#fitems"+parent_id+" .row_1").show();
		$("#fitems"+parent_id+" .row_2").show();
	}
	else
	{
		$("#fitems"+parent_id+" .row_1").hide();
		$("#fitems"+parent_id+" .row_2").hide();
		$("."+type).show();
	}
}

function move_file_up(file_id, type)
{
	a_call(dir_fix+'films/move-file-up/'+file_id+'/', '', 'fitems'+type);
}

function move_file_down(file_id, type)
{
	a_call(dir_fix+'films/move-file-down/'+file_id+'/', '', 'fitems'+type);
}

function df_check(field, value)
{
	var obj = accessObj(field);
	if (value == "on")
		obj.disabled = false;
	else
		obj.disabled = true;
}

function formUpdated(id)
{
	var $inputs = $('#'+id+' :input');
	$inputs.each(function()
	{
		$(this).removeAttr("disabled");
	});
}

function add_location(id, html_id, dir_fix)
{
	lctn_id = $('#'+html_id).val();
	$.ajax({url: dir_fix+'calls/add-location.php', data: {id: id, lctn_id: lctn_id}, type: "post", success: function(data) { 
		refresh_locations(id, html_id, dir_fix);
	}});
}

function remove_location(id, rmv_id, html_id, dir_fix)
{
	var input = confirm('Are you sure you want to remove this location?');	
	if (input)
	{
		$.ajax({url: dir_fix+'calls/remove-location.php', data: {id: rmv_id}, type: "post", success: function(data) { 
			refresh_locations(id, html_id, dir_fix);
		}});
	}
}

function refresh_locations(user_id, html_id, dir_fix)
{
	$.ajax({url: dir_fix+'calls/locations.php', data: {id: user_id, dir_fix: dir_fix, html_id: html_id}, cache: false, dataType: "html", type: "post", success: function(data) { $("#"+html_id+"_locations").html(data); }});
}

$(document).ready(function() {
	       var theDivs=  $('.bulletin_item');
           var  numOfLines= theDivs.length;

            for (i=0; i< numOfLines; i=i+2){
                  theDivs.eq(i).add(theDivs.eq(i+1)).wrapAll('<div class="elem_wrapper" />') ;
            }

});


