// =============================================================================
//
// File:	GLOBAL.JS
//
// Purpose:	1) General utility functions
//			2) Define screen lay-out and design
//
// =============================================================================

function checkUserJumpLocation(userID, passWord, okForm, notokForm) 
{
	location=checkUserLocation(userID, passWord, okForm, notokForm);
}

function checkUserLocation(userID, passWord, okForm, notokForm) 
{
	var logVal=checkUserLogon( userID, passWord)

	if (logVal=="true") 
	{ 
		nextLocation=okForm;
	} 
	else 
	{
		nextLocation=notokForm;
	}
	return nextLocation;
}

function checkUserLogon()
{
	var myUserID = document.getElementById('userID');
	var myPassWord = document.getElementById('passWord');
	var myButton = document.getElementById('btnLogin');

	if ((myUserID.value==MY_USERID) && (myPassWord.value==MY_PASSWORD))
	{    
		myUserID.disabled=true;
		myPassWord.disabled=true;
		myButton.disabled=true;		
		writeSessionCookie( MY_DOMAIN + "_" + "USERID", MY_USERID);
    	writeSessionCookie( MY_DOMAIN + "_" + "PASSWORD", MY_PASSWORD);
		return (true);
	} 
	else
	{
		alert("Invalid credentials. Please check your input.");
		return (false);
	}
}

function checkUserLogonCookie()
{
	var logonValue;
	var myUID;
	var myPWD;
	var myAuth;

	logomValue=false;
	myUID=getCookieValue (MY_DOMAIN + "_" + "USERID");
	myPWD=getCookieValue (MY_DOMAIN + "_" + "PASSWORD");
	myAuth=getCookieValue ("SESSION_AUTH");
	if ((myAuth == "Y") || ((myUID==MY_USERID) && (myPWD==MY_PASSWORD)))
	{    
		logonValue=true;
	} 
	return logonValue;
}

function checkUserLoggedOn()
{
	if (checkUserLogonCookie())
	{
		return true;
	}
	else
	{
		alert('You can only follow this link if you are logged on as a user.');
		return false;
	}
}
	
function jumpIfLoggedOn(url)
{
	if (checkUserLogonCookie())
	{
		location=url;
		return true;
	}
	else
	{
		alert('You can only follow this link if you are logged on as a member.');
	}
}

function SetLogonState()
{
	if (checkUserLogonCookie())
	{
		document.getElementById('userID').disabled=true;
		document.getElementById('passWord').disabled=true;
		document.getElementById('btnLogin').disabled=true;
	}
	else
	{
		document.getElementById('userID').disabled=false;
		document.getElementById('passWord').disabled=false;
		document.getElementById('btnLogin').disabled=false;
	}
}

function doTooltip(e, msg) 
{
	if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
	Tooltip.show(e, msg);
}

function hideTip() 
{
	if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
	Tooltip.hide();
}

function NewWindow(mypage, myname, w, h, scroll) {
	var winl = 1;
	var wint = 1;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+','
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function ShowTooltipHtml(url, tip, obj) {
	content = '';

	if (url == '') {
		content += '<div onmouseover="this.style.cursor=\'pointer\';doTooltip(event,\'';
	} else {
		content += '<a href="' + url + '" target="ext" onmouseover="doTooltip(event,\'';
	}
	switch (tip) {
		case 'capa':
			content += 'Canadian Association of Photographic Art';
			break;
		case 'gtccc':
			content += 'Greater Toronto Council of Camera Clubs';
			break;
		case 'pa-openyouth':
			content += '<center><b><u>Open (Youth)</u></b>';
			content += '<p>This category allows for any subject matter.';
			content += '<p>Images of people would be better suited in the People category.';
			content += '<p>Colour or monochrome prints allowed and will be judged together.</center>';
			break;
		case 'pa-peopleyouth':
			content += '<center><b><u>People</u></b>';
			content += '<p>This category is inclusive of all humans.';
			content += '<p>Images of statuary, figurines, or other representations of people';
			content += '<br>would be better suited in the Open category.';
			content += '<p>Colour or monochrome prints allowed and will be judged together.</center>';
			break;
		case 'pa-openchild':
			content += '<center><b><u>Open (Cild)</u></b>';
			content += '<p>This category allows for any subject matter.';
			content += '<p>Colour or monochrome prints allowed and will be judged together.</center>';
			break;
		case 'pa-people':
			content += '<center><b><u>People</u></b>';
			content += '<p>This category is inclusive of all humans.';
			content += '<p>Images of statuary, figurines, or other representations of people';
			content += '<br>would be better suited in the Objects and Abstracts category.';
			content += '<p>Colour or monochrome prints allowed and will be judged together.</center>';
			break;
		case 'pa-cc':
			content += '<center><b><u>Creatures & Critters</u></b>';
			content += '<p>This category is inclusive of all non-human living beings; animals, and insects.';
			content += '<p>Images of statuary, figurines, or other representations of creatures or';
			content += '<br>critters would be better suited in the Objects and Abstracts category.';
			content += '<p>Colour or monochrome prints allowed and will be judged together.</center>';
			break;
		case 'pa-pcc':
			content += '<center><b><u>People, Creatures & Critters</u></b>';
			content += '<p>This category is inclusive of all living beings; humans, animals, and insects.';
			content += '<p>Images of statuary, figurines, or other representations of people, creatures or';
			content += '<br>critters would be better suited in the Objects and Abstracts category.';
			content += '<p>Colour or monochrome prints allowed and will be judged together.</center>';
			break;
		case 'pa-ff':
			content += '<center><b><u>Flowers & Foliage</u></b>';
			content += '<p>This category includes both domestic and non-domestic plants showing flowers,';
			content += '<br>leaves, vines, etc.';
			content += '<p>Images depicting a wider view where the flowers or foliage only play an incidental';
			content += '<br>role may be better suited in the Scenery category.';
			content += '<p>Colour or monochrome prints allowed and will be judged together.</center>';
			break;
		case 'pa-oa':
			content += '<center><b><u>Objects and Abstracts</u></b>';
			content += '<p>This category includes the depiction of non natural things for objects. Abstract are images';
			content += '<br>captured through the lens from an unusual angle or with fish-eye lens or using extreme';
			content += '<br>close-ups or lens distortion.';
			content += '<p>Colour or monochrome prints allowed and will be judged together.</center>';
			break;
		case 'pa-scenery':
			content += '<center><b><u>Scenery</u></b>';
			content += '<p>This category includes landscapes and cityscapes.';
			content += '<p>Colour or monochrome prints allowed and will be judged together.</center>';
			break;
		case 'pa-architecture':
			content += '<center><b><u>Architecture</u></b>';
			content += '<p>Architecture includes complete or partial depiction of buildings.'; 
			content += '<p>Close-up images of architecture detail such as relief engraving would be better'; 
			content += '<br>suited in the Objects category.';
			content += '<p>Colour or monochrome prints allowed and will be judged together.</center>';
			break;
		case 'pa-sa':
			content += '<center><b><u>Scenery & Architecture</u></b>';
			content += '<p>This category includes landscapes and cityscapes for scenery. Architecture includes'; 
			content += '<br>complete or partial depiction of buildings.'; 
			content += '<p>Close-up images of architecture detail such as relief engraving would be better'; 
			content += '<br>suited in the Objects category.';
			content += '<p>Colour or monochrome prints allowed and will be judged together.</center>';
			break;
		case 'pa-cr':
			content += '<center><b><u>Creative</u></b>';
			content += '<p>Creative images, for the purposes of this competition, are images that reflect an'; 
			content += '<br>altered reality. The image must begin as the photograph of a real subject, whether'; 
			content += '<br>captured digitally or scanned from a negative or slide. However in this competition you'; 
			content += '<br>are encouraged to exercise your imagination and stray as far from that real subject as you like,'; 
			content += '<br>using design elements, colour and light in non-traditional ways to produce abstract,'; 
			content += '<br>impressionistic and experimental effects not achievable by standard photographic means.'; 
			content += '<br>You may do this with in-camera techniques and/or also by manipulating your images afterwards'; 
			content += '<br>using digital post-processing software.  Artwork and computer graphics created by the member can be'; 
			content += '<br>incorporated as long as the photographic content predominates.  Merely using these techniques'; 
			content += '<br>is not enough, however; they must (be) used artfully to produce an effective image.  Therefore';
			content += '<br>creative photography has these elements - new composition, altered reality, and emphasized alteration.';
			content += '<p>Examples of creative techniques include:  panning, zooming, lens distortion, special effects'; 
			content += '<br>filters, montages, collages, ortons, multiple exposures, posterization, diffraction, black light,'; 
			content += '<br>bas relief and unusual/unrealistic colorization.';
			content += '<p><b>Monochrome prints are not allowed.</b></center>';
			break;
		case 'pa-om':
			content += '<center><b><u>Open Monochrome</u></b>';
			content += '<p>This is an open category limited to monochrome only.</center>';
			break;
		case 'pa-ch':
			content += '<center><b><u>Children Category</u></b>';
			content += '<p>This an open category where any picture subject is allowed,';
			content += '<br>limited only to 4x6 inches unmounted.</center>';
			break;
		case 'heading':
//			content += headerAcknowledgement;
			break;
	}
	if (url == '') {
		content += '\')" onmouseout="hideTip();this.style.cursor=\'auto\'">' + obj + '</div>';
	} else {
		content += '\')" onmouseout="hideTip()">' + obj + '</a>';
	}

	return content;
}

function ShowTooltip(url, tip, obj) {

	toolTip = ShowTooltipHtml(url, tip, obj);

	document.write (toolTip);
}

function pop(url, h, w, l, t, des, title) {
	poph = + h + 70
	popw = + w + 30
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
		
	disp = window.open("","pop","height=" + poph + ",width=" + popw + ",left=" + l + ",top=" + t + "");
	content = '<HTML>';
	content += '<TITLE>' + title + '</TITLE>';
	content += '</HEAD>';
	content += '<BODY BGCOLOR="#FFFFFF" onBlur="self.close()">';
	content += '<FONT SIZE="2" FACE="arial,helvet">';
	content += '<CENTER><img src="' + url + '" height="' + h + '" width="' + w + '"></CENTER>';
	content += '<CENTER>' + des + '</CENTER>';
	content += '<CENTER><P ALIGN="RIGHT"><A HREF="#" onClick="self.close()"><FONT SIZE="1" FACE="verdana,geneva,arial,helvet"><B>close</B></A></CENTER>';
	content += '</FONT>';
	content += '</BODY></HTML>';
	disp.document.write(content);
	disp.document.close();
}

function popGallery(url, w, h, photog, title) 
{
	popw = + w + 120
	poph = + h + 150
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;

	if (title != "") {
		poph = + h + 180;
	}
	disp = window.open("","pop","height=" + poph + ",width=" + popw + ",left=0,top=0");
	content = '<HTML>';
	content += '</HEAD>';
	content += '<body bgcolor="#000000" text="#FFFFFF" link="#FFFFFF" vlink="#CCCCCC" alink="#006666" onBlur="self.close()">';
	content += '<FONT SIZE="2" FACE="arial,helvet">';
	content += '<CENTER>';
	content += '<table border="0" cellpadding="30" vspace="20" hspace="20" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#000000">';
	content += '<tr><td><center>';
	content += '<table align="center" background="' + url + '" border="0" cellpadding="0" cellspacing="0">';
	content += '<tr><td>';
	content += '<img src="images/sp.gif" width="' + w + '" height="' + h + '" border="0" align="middle">';
	content += '</td></tr>';
	content += '</table>';
	content += '</center></td></tr>';
	content += '</table>';
	if (title != "") {
		content += '<font face="Arial, Helvetica, sans-serif"><b><font color="#FFFFFF">&quot;' + title + '&quot;</font><br><br>';
	}
	content += '<font face="Arial, Helvetica, sans-serif" size="-1" color="#CCCCCC">Photo by: </font>';
	content += '<font face="Arial, Helvetica, sans-serif"><b><font color="#FFFFFF">' + photog + '</font><br>';
	content += '<center>';
	content += '</BODY></HTML>';
	disp.document.write(content);
	disp.document.close();
}

function showGallery(url, w, h, photog, title, subnet) 
{
	thisTn = new Image();
	thisImg = new Image();
	img = 'gallery/' + subnet + '/images/' + url + '.jpg';
	tn  = 'gallery/' + subnet + '/thumbnails/' + url + '-tn.jpg';
	thisTn.src=tn;
	thisImg.src=img;
	thisImg.width = w;
	thisImg.height = h;
	thisTn.width = w/4.5;
	thisTn.height = h/4.5
	content = '';
	content += '<td align="center"><font size="2" face="Arial, Helvetica, sans-serif">';
	content += '<table align="center" background="' + thisTn.src + '" border="1" cellpadding="0" cellspacing="0">';
	content += '<tr><td>';
	if (title != "") {
		content += '<A HREF="javascript:popGallery(\'' + img + '\', \'' + thisImg.width + '\', \'' + thisImg.height + '\', \'' + photog + '\', \'' + title + '\')";><img src="images/sp.gif" width="' + thisTn.width + '" height="' + thisTn.height + '" border="0" align="middle" onmouseover="doTooltip(event,\'' + title + '\')" onmouseout="hideTip()"></a>';
	} 
	else {
		content += '<A HREF="javascript:popGallery(\'' + img + '\', \'' + thisImg.width + '\', \'' + thisImg.height + '\', \'' + photog + '\', \'' + title + '\')";><img src="images/sp.gif" width="' + thisTn.width + '" height="' + thisTn.height + '" border="0" align="middle"></a>';
	}
	content += '</td></tr>';
	content += '</table>';
	content += '</font></td>';
	document.write(content);
}

function popCompetition(url, w, h, photog, title, ranking) 
{
	popw = + w + 120
	poph = + h + 150
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;

	if (title != "") {
		poph = + h + 180;
	}
	disp = window.open("","pop","height=" + poph + ",width=" + popw + ",left=0,top=0");
	content = '<HTML>';
	content += '</HEAD>';
	content += '<body bgcolor="#000000" text="#FFFFFF" link="#FFFFFF" vlink="#CCCCCC" alink="#006666" onBlur="self.close()">';
	content += '<FONT SIZE="2" FACE="arial,helvet">';
	content += '<CENTER>';
	content += '<table border="0" cellpadding="30" vspace="20" hspace="20" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#ffffff">';
	content += '<tr><td><center>';
	content += '<table align="center" background="' + url + '" border="0" cellpadding="0" cellspacing="0">';
	content += '<tr><td>';
	content += '<img src="images/sp.gif" width="' + w + '" height="' + h + '" border="0" align="middle">';
	content += '</td></tr>';
	content += '</table>';
	content += '</center></td></tr>';
	content += '</table>';
	if (title != "") {
		content += '<font face="Arial, Helvetica, sans-serif"><b><font color="#FFFFFF">&quot;' + title + '&quot; (' + ranking + ')</font><br><br>';
	}
	content += '<font face="Arial, Helvetica, sans-serif" size="-1" color="#CCCCCC">Photo by: </font>';
	content += '<font face="Arial, Helvetica, sans-serif"><b><font color="#FFFFFF">' + photog + '</font><br>';
	content += '<center>';
	content += '</BODY></HTML>';
	disp.document.write(content);
	disp.document.close();
}

function showCompetition(url, w, h, photog, title, rating) 
{
	thisTn = new Image();
	thisImg = new Image();
	img = 'events/pa2011/results/' + url + '.jpg';
	tn  = 'events/pa2011/results/' + url + 'tn.jpg';
	thisTn.src=tn;
	thisImg.src=img;
	thisImg.width = w;
	thisImg.height = h;
	thisTn.width = w/4;
	thisTn.height = h/4;
//	if (thisTn.width < thisTn.height) thisTn.width = 150;
//	if (thisTn.height < thisTn.width) thisTn.height = 150;
	content = '';
	content += '<td align="center" valign="bottom"><font size="2" face="Arial, Helvetica, sans-serif">';
	content += '<table align="center" background="' + thisTn.src + '" border="0" cellpadding="0" cellspacing="0" style="background-repeat:no-repeat;">';
	content += '<tr><td>';
	content += '<A HREF="javascript:popCompetition(\'' + img + '\', \'' + thisImg.width + '\', \'' + thisImg.height + '\', \'' + photog + '\', \'' + title + '\', \'' + rating + '\')";><img src="images/sp.gif" width="' + thisTn.width + '" height="' + thisTn.height + '" border="0" align="middle"></a>';
	content += '</td></tr>';
	content += '<tr><td>&nbsp;</td></tr>';
	content += '<tr><td align="center"><font size="2px" face="Arial, Helvetica, sans-serif"><b>' + title + '</b><br>' + photog + '<br><b>' + rating + '</b></font></td></tr>';
	content += '</table>';
	content += '</font></td>';
	document.write(content);
}

function showHeader( pageHeader )
{
	var content = '';

	content += '<table width="800" border="0" cellspacing="0" cellpadding="0" id="maintable">';
	content += getMainMenu();
	content += '<tr><td>';
	content += '<table border="0" width="100%" style="font-size:12px;" cellspacing="0" cellpadding="0"><tr>';
	content += '<td width="16" valign="top">&nbsp;</td>';
	content += getSidePanel();
	content += '<td width="16" valign="top">&nbsp;</td>';
	content += '<td width="500" valign="top">';
	content += '<div id="maincontent">';
	if (pageHeader == '')
	{
		content += '';
	}
	else
	{
		content += '<img src="' + pageHeader +'"><br><br>';
	}

	document.write (content);
}

function getMainMenu()
{
	var content='';

	content += '<tr><td>';

	content += ShowTooltipHtml('mailto:mkuypers@hhcc.ca','heading','<img src="images/heading-background.jpg" border="0">');

	content += '</td></tr>';
	content += '<tr><td height="41" style="background-image:url(images/mainmenu.jpg);background-repeat:repeat-x;">';
	content += '<center>';

	content += showMainMenu();

	content += '</center>';
	content += '</td></tr>';

	return (content);
}

function getSidePanel()
{
	var content='';

	content += '<td width="252" valign="top">';
	content += '<table width="100%" border="0" cellspacing="0" cellpadding="0">';

// START OF HOT-OFF-THE-PRESS
//	content += '<tr><td valign="top" align="center">';
//	content += '<br><br><a href="javascript:jumpIfLoggedOn(\'threeclub.html\')"><img src="events/3Club2010/logothreeclub.gif"></a>';
//	content += '</td></tr>';
//	content += '<tr><td align="center"><p><h4><font face="Arial, Helvetica, sans-serif" color="red">3 CLUB 2010 </font></h4></td></tr>';
//	content += '<tr><td align="center"><hr size="1" width="100%" color="#3e6709" noshade></td></tr>';
// END OF HOT-OFF-THE-PRESS

// START OF CALENDAR
	content += '<tr><td background="images/calendararea.jpg" height="333" valign="middle">';
	content += '<center>';
	content += '<table border="0" width="200" cellspacing="0" cellpadding="0">';
	content += '<tr><td>&nbsp;</td></tr>';
	content += '<tr><td align="center" valign="middle">';
	content += '<div id="calendar-container"><script type="text/javascript">';
	content += 'function dateChanged(calendar) {';
	content += 'if (calendar.dateClicked) {';
	content += 'var y = calendar.date.getFullYear();';
	content += 'var m = calendar.date.getMonth();';
	content += 'var d = calendar.date.getDate();';
	content += 'document.getElementById(\'mainevent\').innerHTML=DateToEventEntry(y,m+1,d);';
	content += '}';
	content += '};';
	content += 'Calendar.setup(';
	content += '{';
	content += 'flat : "calendar-container",',
	content += 'flatCallback : dateChanged,';
	content += 'weekNumbers : false';
	content += '}';
	content += ');';
	content += '</script></div>';
	content += '</td></tr>';
	content += '<tr><td>&nbsp;</td></tr>';
	content += '<tr><td align="center" valign="middle" width="209" height="80" background="images/event-background.jpg"><div id="mainevent">';
	content += '&nbsp;';
	content += '</div></td></tr>';
	content += '</table>';
	content += '</center>';
	content += '</td></tr>';
	content += '<tr><td>&nbsp;</td></tr>';
// END OF CALENDAR

// START OF LOGON+NEWSFLASH SECTION
	content += '<tr><td background="images/membersarea-1.jpg" height="149" align="center" valign="middle">';
	content += '<table width="80%" border="0" cellspacing="0" cellpadding="0">';
	if (checkUserLogonCookie())
	{
		content += '<tr><td align="center" valign="middle"><center><div align="center"><font face="Arial, Helvetica, sans-serif" style="font-size:12px;"><strong>';
		if (currentNewsFlash == '' )
		{
			content += 'This is where you can come to get your up-to-the-minute news flashes and reminders.';
		}
		else
		{
			content += '<center><marquee align="middle" scrollamount="2" direction="up" loop="true" width="150" height="75">';
			content += currentNewsFlash;
			content += '</marquee></center>';
		}
		content += '</strong></font></div></center></td></tr>';
	}
	else
	{
		content += '<form name="frmLogin">';
		content += '<tr><td>&nbsp;</td></tr>';
		content += '<tr>';
		content += '<td width="25%" align="right"><font face="Arial, Helvetica, sans-serif" style="font-size:12px;">Username&nbsp;&nbsp;</td>';
		content += '<td width="25%" align="left"><input id="userID" type="text" style="background-color:#c8d08e; border:none;"></td>';
		content += '</tr>';
		content += '<tr><td>&nbsp;</td></tr>';
		content += '<tr>';
		content += '<td width="25%" align="right"><font face="Arial, Helvetica, sans-serif" style="font-size:12px;">Password&nbsp;&nbsp;</td>';
		content += '<td width="25%" align="left"><input id="passWord" type="password" style="background-color:#c8d08e; border:none;"></td>';
		content += '</tr>';
		content += '<tr><td>&nbsp;</td></tr>';
		content += '<tr><td colspan="2" align="center">';
		content += '<input type="button" id="btnLogin" value="Login" onClick="checkUserLogon()">';
		content += '</td></tr>';
//		content += '<script>SetLogonState()</script>';
		content += '</form>';
	}
	content += '</table>';
	content += '</td></tr>';
// END OF LOGON+NEWSFLASH SECTION

// START OF MEMBERS MENU
	content += '<tr><td background="images/membersarea-3.jpg" height="76">';
	content += '<br>';

	content += showMembersMenu();

	content += '<br>';
	content += '</td></tr>';
// END OF MEMBERS

// START OF CURRENT NEWSLETTER
	content += '<tr><td background="images/membersarea-4.jpg" height="305" align="center" valign="middle">';
	content += currentNewsletter();
	content += '</td></tr>';
// END OF CURRENT NEWSLETTER

	content += '</table>';
	content += '</td>';

	return (content);
}

function showFooter()
{
	var content='';

	content += '</div>';
	content += '</td>';
	content += '<td width="16" valign="top">&nbsp;</td>';
	content += '</tr></table>';
	content += '</td></tr>';
	content += '<tr><td height="41" align="center" style="background-image:url(images/footer.jpg);background-repeat:repeat-x;">';
	content += '<table border="0" width="98%" style="font-size:12px;"><tr>';
	content += '<td align="left" valign="middle" width="33%">&copy; Halton Hills Camera Club, 2009</td>';
	content += '<td align="center" valign="middle" width="33%">&nbsp;</td>';
	content += '<td align="right" valign="middle" width="33%">Contact our <a href="mailto:webmaster@hhcc.ca">webmaster</a></td>';
	content += '</tr></table>';
	content += '</td></tr>';
	content += '</table>';
	
	document.write (content);
}
