function ChangeDay()
{
	var day = document.getElementById('day_select').value;	
	this.location.href = './index.php?page=1&day=' + day;
}
function CodeEntered(input_id)
{
	var day = 1;
	if (document.getElementById('day_select') != null)
		day = document.getElementById('day_select').selectedIndex + 1;				
	var code = document.getElementById(input_id).value;	
	if 	(code != "")
		this.location.href = './index.php?page=1&day=' + day + "&code=" + code;
	
}

function ShowPopup(code, img_id, target)
{
	if (popup_window != null &&
		!popup_window.closed)
		popup_window.close();
			
		
	var win = window.open('./request.php?code='+code +'&img_id='+img_id+'&target='+target,
		"_blank",
		'width=500, height=180,' + 			
		'location=no, menubar=no, ' +
		'status=no, toolbar=no, scrollbars=no, resizable=no, locationbar=no, directories=no, personalbar=no, titlebar=no'); 
	if (win != null)
	{
		win.focus();
		if (win.opener == null)
			win.opener = self;		
	}
	popup_window = win;
}

function MakeOnlineLinks(code, img_id)
{
	this.opener.document.getElementById('download_link').href = 'show_image.php?typ=original&code=' +code;
}
function CloseSNPopup(cancel, code, target, img_id) // social network popup
{
	if (cancel)
	{
		window.close();
		return;
	}
	
	MakeOnlineLinks(code, img_id);
	location.href = "social_network.php?code="+code+"&target="+target;	
}
function CloseDownloadPopup(code, img_id)
{
	if (document.getElementById('check_online') != null &&
		document.getElementById('check_online').checked == true)	
	{
		MakeOnlineLinks(code, img_id);
		this.opener.location.href="show_image.php?online=true&typ=original&code="+code;
	}
	else
		this.opener.location.href="show_image.php?online=false&typ=original&code="+code;
	window.close();
}

var popup_window = null;
var social_networks_clicked = false;
function GoOnline(arguments, firsttry, img_id, social_network)
{	
	if (document.getElementById('check_online') != null &&
		document.getElementById('check_online').checked == true)		
	{			
		var loc = "show_image.php?" + arguments + "&online=true";
		if (firsttry)
		{		
			document.getElementById("request_text").style.visibility = 'hidden';
			document.getElementById('download_link').href = "show_image.php?"+arguments;
			document.getElementById('facebook_link').href = "javascript:PostTo('facebook', " + img_id + ")"
			document.getElementById('studivz_link').href = "javascript:PostTo('studivz', " + img_id + ")"
			document.getElementById('schuelervz_link').href = "javascript:PostTo('schuelervz', " + img_id + ")"
			document.getElementById('meinvz_link').href = "javascript:PostTo('meinvz', " + img_id + ")"
			document.getElementById('myspace_link').href = "javascript:PostTo('myspace', " + img_id + ")"
			if (social_network == 0 || 
				(social_network == -1 &&
				social_networks_clicked == false))
				location.href = loc;			
		}
		else
		{
			if (social_network == 0 || 
				(social_network == -1 &&
				social_networks_clicked == false))
				this.opener.location.href = loc;	
			this.opener.document.getElementById('download_link').href = "show_image.php?"+arguments;
			this.opener.document.getElementById('facebook_link').href = "javascript:PostTo('facebook', " + img_id + ")"
			this.opener.document.getElementById('studivz_link').href = "javascript:PostTo('studivz', " + img_id + ")"
			this.opener.document.getElementById('schuelervz_link').href = "javascript:PostTo('schuelervz', " + img_id + ")"
			this.opener.document.getElementById('meinvz_link').href = "javascript:PostTo('meinvz', " + img_id + ")"
			this.opener.document.getElementById('myspace_link').href = "javascript:PostTo('myspace', " + img_id + ")"
			this.opener.document.getElementById('request_text').style.visibility = 'hidden';
			window.close();
		}
	}	
	else if (firsttry == true)
	{		
		if (popup_window == null ||
			popup_window.closed)
		{
			 var win = window.open('./request.php?'+arguments +'&img_id='+img_id+'&sn='+social_networks_clicked,
				"_blank",
				'width=500, height=180,' + 			
				'location=no, menubar=no, ' +
				'status=no, toolbar=no, scrollbars=no, resizable=no, locationbar=no, directories=no, personalbar=no, titlebar=no'); 
			if (win != null)
			{
				win.focus();
				if (win.opener == null)
					win.opener = self;		
			}
			popup_window = win;
		
		}
		else
		{
			popup_window.focus();
		}
	}
	else
	{
		if (social_network == 0 || 
				(social_network == -1 &&
				social_networks_clicked == false))
				this.opener.location.href = "show_image.php?" + arguments;	
		window.close();
		popup_window = null;
		this.opener.document.getElementById("request_text").style.visibility = 'hidden';
	}
}


function PostTo(what, img_id)
{
	if (what == "facebook")
		loc = "redirect.php?ntw=fb&img_id="+img_id;
	else if (what == "studivz" || what == "schuelervz" || what == "meinvz" )
		loc = "redirect.php?ntw=vz&img_id="+img_id;
	else if (what == "myspace")
		loc = "redirect.php?ntw=ms&img_id="+img_id;	
	window.open(loc, "", "height=600, width=900");
}
function PostToAndClose(what, img_id)
{
	PostTo(what, img_id);
	window.close();
}

function MakeVisible(social_networks)
{
	social_networks_clicked = social_networks;
	document.getElementById("request_text").style.visibility = 'visible';
}


