

// whitespace characters

var whitespace = " \t\n\r";


var Country = {
"al":"Albania",
"ad":"Andorra",
"ar":"Argentina",
"_i":"East Asia",
"au":"Australia",
"at":"Austria",
"_t":"Baltic states",
"by":"Belarus Republic",
"be":"Belgium",
"_b":"Benelux",
"ba":"Bosnia Herzegowina",
"br":"Brazil",
"bg":"Bulgaria",
"ca":"Canada",
"cf":"Central African Republic",
"cl":"Chile",
"cn":"China",
"co":"Colombia",
"cz":"Czech Republic",
"hr":"Croatia",
"cy":"Cyprus",
"dk":"Denmark",
"_c":"Eastern Europe",
"ee":"Estonia",
"_e":"Europe",
"fi":"Finland",
"fo":"Faroe Islands",
"fr":"France",
"de":"Germany",
"gr":"Greece",
"hu":"Hungary",
"is":"Iceland",
"id":"Indonesia",
"ie":"Ireland",
"iq":"Iraq",
"ir":"Iran",
"il":"Israel",
"it":"Italy",
"jp":"Japan",
"kz":"Kazakhstan",
"kr":"Korea",
"lv":"Latvia",
"lt":"Lithuania",
"lu":"Luxemburg",
"my":"Malaysia",
"mt":"Malta",
"nl":"Netherlands",
"mx":"Mexico",
"md":"Moldova",
"mn":"Mongolia",
"ma":"Morocco",
"nz":"New Zealand",
"_a":"N.America",
"no":"Norway",
"pe":"Peru",
"ph":"Philippines",
"pl":"Poland",
"pt":"Portugal",
"ro":"Romania",
"ru":"Russian Federation",
"sc":"Seychelles",
"sg":"Singapore",
"_s":"Skandinavia",
"sk":"Slovak Republic",
"si":"Slovenia",
"tw":"Taiwan",
"za":"South Africa",
"es":"Spain",
"se":"Sweden",
"sy":"Syria",
"ch":"Switzerland",
"ti":"Tibet",
"tn":"Tunisia",
"tr":"Turkey",
"ua":"Ukraine",
"uk":"United Kingdom",
"uy":"Uruguay",
"us":"USA",
"ve":"Venezuela",
"yu":"Yugoslavia"
};



function Img(i)
{
	return "http://images.clanbase.com/" + i;
}

function CheckFilled(field, prompt)
{
  if(isWhitespace(field.value))
    {
    FieldError(field, prompt)
    return false;
    }
  return true;
}

function CheckURL(field, prompt)
{
  if(isURL(field.value))
    return true;
  else
    {
    FieldError(field, prompt)
    return false;
    }
}

function FieldError(field, prompt)
{
  alert(prompt);
  field.focus();
  return
}

// Check whether string s is empty.
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}




// Returns true if string s is empty or 
// whitespace characters only.
function isWhitespace (s)

{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

function isURL(s)
{
  if(isEmpty(s)) 
    return (isURL.arguments[1] == true);
  // is s whitespace?
  if(isWhitespace(s))
    return false;
  if(s.indexOf(".") == -1)
    return false;
  return true;
}


// isEmail (STRING s [, BOOLEAN emptyOK])
// 
// Email address must be of form a@b.c -- in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
function isEmail (s)
{
    if (isEmpty(s)) 
       return (isEmail.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}




// daysInFebruary (INTEGER year)
// 
// Given integer argument year,
// returns number of days in February of that year.

function daysInFebruary (year)
{   // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}



// isDate (STRING year, STRING month, STRING day)
//
// isDate returns true if string arguments year, month, and day 
// form a valid date.
// 

function isDate (year, month, day)
{   // catch invalid years (not 2- or 4-digit) and invalid months and days.
  daysInMonth = new Array(0,31,29,31,30,31,30,31,31,30,31,30,31);

  // Explicitly change type to integer to make code work in both
  // JavaScript 1.1 and JavaScript 1.2.
  var intYear = parseInt(year);
  var intMonth = parseInt(month);
  var intDay = parseInt(day);

  // catch invalid days, except for February
  if (intDay > daysInMonth[intMonth]) return false; 

  if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;
  return true;
}


function ValidateLogin(form)
{
  if(!CheckFilled(form.elements["formid"], "Try entering a ID number...."))
    return false;
  if(isNaN(parseInt(form.elements["formid"].value)))
    {
    FieldError(form.elements["formid"], "ID is a number...");
    return false;
    }
  return true;
}

//function ClanLink(url)
//{
//  window.open("http://"+url);
//}


function Toggle(item, button, on_image, off_image)
{
  NS4 =(document.layers)?true:false;
  IE4 =(document.all)?true:false;
  if(IE4)
		{
  	body = document.all(item );
  	button = document.all(button);
  	if(body.style.display == "none")
			{
  		body.style.display = "";
			if(on_image)
				button.innerHTML = "<img src='"+on_image+"' border=\'0\' alt=\'Less\'>";
 			}
		else
			{
  		body.style.display = "none";
			if(off_image)
				button.innerHTML = "<img src='"+off_image+"' border=\'0\' alt=\'More\'>";
  		}
  	}
  else
    {
    if(body.visibility == "hide")
      {
      body.visibility = "show";
      }
    else
      {
      body.visibility = "hide";
      }
    }
}



function Show(item)
{
	document.getElementById(item).style.display = 'block';
}


function Hide(item)
{
	document.getElementById(item).style.display = 'none';
}


function ILink(page, label, param, title, clss, target, extra)
{
  url = IUrl(page, param);
	if(clss=='')
		clss='slink';
	if(target=='')
		target='_top';
  link = "<a class='"+clss+"' href='"+url+"'";
  if(title)
    link = link + " title='"+title+"'";
  link = link + " target='"+target+"'";
  link = link + extra + ">" + label + "</a>";
  return link;
}

function ILinkPopup(page, label, param, title, clss, target, width, height)
{
  if(param)
    param = param + "&";
  param = param + "frame=1";
  url = "http://www.clanbase.com/" + IUrl(page, param);
	t = parseInt((screen.height - height)/2);
	l = parseInt((screen.width - width)/2);
	str = "a"+'"'+"b";
  str = "<a href=" + '"' + "javascript:window_url='" + url + "';x=window.open(window_url,'" + target + "','width=" + width + ",height=" + height + ",left="+l+",top="+t+",scrollbars=1,resizable=1');x.focus()" + '"' + " class='" + clss + "'";
  if(title)
    str = str + " title='"+title+"'";
  str = str + ">" +label+ "</a>";
  return str;
}

function DontSpam(me)
{
	i = "<img src='" + Img("mail.gif") + "' alt='Click to send mail' width='14' height='11' border='0' align='absbottom'>";
	str = "<a class='slink' href='mailto:" + me.replace(/\|/g,"@") +"'>" + i + "</a>";
  return str;
}

function Flag(code, grey)
{
	if(code)
		flag = "<img src='" + Img("flags/" +code + ".gif") + "' border='0' width='18' height='12' alt='"+Country[code]+"' align='baseline'";
	else
		flag = "<img src='" + Img("flags/europe.gif") + "' border='0' width='13' height='13' alt='International' align='baseline'";
  if(grey)
		flag = flag + " style='filter:progid:DXImageTransform.Microsoft.alpha(opacity=50)'";
	flag = flag + ">";
	return flag;
}

function CupCard(t,lid)
{
	i = "<img src='" + Img("cupcard_" + (t == 0 ? "yellow" : "red") + ".gif") + "' border='0' hspace='2' width='5' height='7' align=top title='" + (t == 0 ? "yellow" : "red") + " card'>";
	return ILink("cupcard", i, "lid="+lid, "", "", "", "");
}

function fc(rank, cid,nshort,nfull,co,deleted,playoff,wc,card,lid)
{
	flag = Flag(co,deleted);
  if(playoff)
		{
    nshort = "<b>"+nshort+"</b>";
		if(rank)
			rank = "<b>"+rank+"</b>";
		}
	clan = ILink('claninfo', nshort, 'cid='+cid, nfull, 'slink', '', '');
  if(card && !playoff)
    clan = clan + CupCard(card-1, lid);
  if(wc && !playoff)
    clan = clan + " <span style='font-size: 5pt;' title='Wildcard used'><sup>*</sup></span>";
	if(rank)
		rank = rank + " ";
	document.write(rank + flag + " " + clan + "<br>");
}

function w(col,wid,cid1,nshort1,tt1,cup1,cid2,nshort2,tt2,cup2,date,score,numdemo,rep,cid_nr1)
{
	tri = "<img src='" + Img("details_" + col + ".gif") + "' width='5' height='9' border='0' hspace='2'>";
	str = ILink('warinfo', tri, "wid="+wid, 'Click to view match details', '', '', '');
	if(date)
		str = str + date + ": ";
	else
		str = str + "&nbsp;";
	if(cid1 == cid_nr1)
    nshort1 = "<b>" + nshort1 + "</b>";
	if(cid1 == _cid)
    nshort1 = "<font color=yellow>" + nshort1 + "</font>";
	if(cup1)
		nshort1 = nshort1 + "&nbsp;<img src='" + Img(cup1) + "' border='0' align=absbottom>";
	if(cid2 == cid_nr1)
    nshort2 = "<b>" + nshort2 + "</b>";
	if(cid2 == _cid)
    nshort2 = "<font color=yellow>" + nshort2 + "</font>";
	if(cup2)
		nshort2 = nshort2 + "&nbsp;<img src='" + Img(cup2) + "' border='0' align=absbottom>";
	str = str + ILink('claninfo', nshort1, "cid="+cid1, tt1 ? tt1 : 'Click to view clan details', '', '', '');
	str = str + " - ";
	str = str + ILink('claninfo', nshort2, "cid="+cid2, tt2 ? tt2 : 'Click to view clan details', '', '', '');
	if(score)
		str = str + ": " + score;
	if(numdemo)
		str += DemoLink(wid,numdemo);
	if(rep)
		str += UserReportLink(wid,cid1);
	document.write(str+"<br>");
}


function ciw(cid2,nshort,tt,icon,cls,wid,date,time,numplayers,level1,level2,score1,score2,type,status,deltarate,hasreport,numdemo,confirmable,reportable,tourney,lid,cid,nr1,new_nr1,specialflag)
{
	str = "";
	wl = WarLink(wid,wid);
	str += "<td class='"+cls+"' align=right>" + wl + "</td>";
	if(type != 0)
		date = "<span style='color: #c0c0c0' title='Friendly/practice'>" + date + "</span>";
	str += "<td class='"+cls+"'>" + date + "</td>";
	str += "<td class='"+cls+"'>" + time + "</td>";
	if(icon)
		nshort += "&nbsp;<img src='" + Img(icon) + "' border='0'>";
	if(specialflag == 1)
		cls2 = "valuecellloss";
	else
		cls2 = cls;
	str += "<td class='"+cls+"'>" + ILink('claninfo', nshort, 'cid='+cid2, tt ? tt: 'Click for clan info', 'slink', '', '') + "</td>";
	if(numplayers != -1)
	{
		if(type != 0)
			numplayers = "<font color='#c0c0c0'>" + numplayers + "</font>";
		str += "<td class='"+cls+"' align=right>" + numplayers + "</td>";
	}
	l = level1;
	if(level2)
		if(l)
			l = l + "/" + level2;
		else
			l = level2;
	if(type)
		l = "<font color='#c0c0c0'>" + l + "</font>";
	str += "<td class='"+cls+"'>" + l + "</td>";
	clsus = (score1 > score2) ? "valuecellwin" : ((score2 > score1) ? "valuecellloss" : "valuecell");
	if(type)
	{
		score1 = "<font color='#c0c0c0'>" + score1 + "</font>";
		score2 = "<font color='#c0c0c0'>" + score2 + "</font>";
	}
	str += "<td class='"+clsus+"' align=right>" + score1 + "</td>";
	str += "<td class='"+cls+"'   align=right>" + score2 + "</td>";
	delta = "";
	if(type == 0)
		if(status != 24)
			delta = "<small>waiting...</small>";
		else
			{
			if(cid == new_nr1)
				{
				if(cid == nr1)
					delta = "none <img src='" + Img("nonerate.gif") + "' width='7' height='6' hspace='2' border='0'>";
				else
				if(nr1)
					delta = "<img src='" + Img("ladder1.gif") + "' border='0' title = 'New number 1 !'> <img src='" + Img("uprate.gif") + "' width='11' height='6' border='0' align='center'>";
				}
			else
			if(cid == nr1)
				{
				if(new_nr1)
					{
					delta = "<img src='" + Img("ladder1.gif") + "' border='0' title = 'Lost number 1 position !'> <img src='" + Img("downrate.gif") + "' width='11' height='6' border='0'>";
					}
				else
					delta = "none <img src='" + Img("nonerate.gif") + "' width='7' height='6' hspace='2' border='0'>";
				}
			if(delta == '')
				{
				if(deltarate > 0)
					delta = "+ " + deltarate + " <img src='" + Img("uprate.gif") + "' width='11' height='6' border='0' align='center'>";
				else
				if(deltarate < 0)
					delta = "- " + (-deltarate) + " <img src='" + Img("downrate.gif") + "' width='11' height='6' border='0'>";
				else
					delta = "none <img src='" + Img("nonerate.gif") + "' width='7' height='6' hspace='2' border='0'>";
				}
			}
	str += "<td class='"+cls+"' align=right>" + delta + "</td>";

	link = "";
	if(tourney)
	  link += ReportLink(wid,lid);
	else
	if(hasreport)
	  link += UserReportLink(wid,cid2);

	if(reportable)
		{
		if(link)
			link += "&nbsp;";
		img = "<img src='" + Img("prop.gif") + "' border='0' width='16' height='11'>"
		link += ILink("warrep_prop", img, 'wid='+wid, 'Click to enter warreport','','','');
		}
	str += "<td class='"+cls+"' align=center>" + link + "</td>";

	if(confirmable == 1)
		{
		img = "<img src='" + Img("prop.gif") + "' border='0' WIDTH='16' HEIGHT='11'>";
		link = ILink("warresult2", img, 'wid='+wid, 'Click to confirm results','','','');
		str += "<td class='"+cls+"' align=center>" + link + "</td>";
		}
	else
	if(confirmable == 0)
		str += "<td class='"+cls+"' align=center>" + "" + "</td>";

	if(numdemo)
		link = DemoLink(wid,numdemo);
	else
		link = "";
	str += "<td class='"+cls+"' align=center>" + link + "</td>";

	if((cid == new_nr1)&&nr1&&(cid != nr1))
		document.write("<tr style='font-weight: bolder;' title='New number 1 !'>" + str + "</tr>");
	else
		document.write("<tr>" + str + "</tr>");
}

function WarLink(wid, label)
{
	return ILink('warinfo', label, 'wid='+wid, 'Click for details (wid='+wid+')', 'slink', '', '');
}

function WL(wid, label)
{
	document.write(WarLink(wid, label));
}

function ClanLink(cid, label)
{
	return ILink('claninfo', label, 'cid='+cid, 'Click for clan info', 'slink', '', '');
}

function CL(cid, label)
{
	document.write(ClanLink(cid, label));
}

function PL(pid, label)
{
	document.write(ILink('personinfo', label, 'pid='+pid, 'Click for player info', 'slink', '', ''));
}

function DemoLink(wid,numdemo)
{
	dem = "<img src='" + Img("demo.gif") + "' width='12' height='11' border='0' hspace='2' align='absbottom'>";
	return ILink('demolist', dem, 'post=1&wid='+wid, numdemo + " demos available",'','','');
}

function ReportLink(wid,lid)
{
	img = "<img src='" + Img("report.gif") + "' width='8' height='11' border='0' hspace='2' align='absbottom'>";
	return ILink("news_league", img, 'wid='+wid+'&lid='+lid, 'Click to view matchreport','','','');
}

function UserReportLink(wid,cid)
{
	img = "<img src='" + Img("report.gif") + "' width='8' height='11' border='0' hspace='2' align='absbottom'>";
	return ILink("warinfo", img, 'wid='+wid+'&cid='+cid, 'Click to view matchreport','','','');
}

function IL(page, label, param)
{
	document.write(ILink(page, label, param, '', 'slink', '_top', ''));
}

function ML(user, domain)
{
	document.write(MailLink(user, domain));
}

function Bullet()
{
	img = "<img src='" + Img("details_" + _color + ".gif") + "' WIDTH='5' HEIGHT='9' border='0' hspace='2' >";
	document.write(img);
}

function del(mid, fid)
{
	url = IUrl('forum_delete', "fid="+fid+"&mid="+mid+"&frame=1");
	x = window.open(url,'blaat','width=500,height=350,resizable=1');
	x.focus();
}



function f(subject,date,sender,pid,id,fid,frame,level,table, d, flags, urlsubject)
{
	document.write("<br><nobr>");
	if (level == 0)
		{
		document.write("<img src='" + Img("blanc.gif") + "' height='5'><br>");
		}
	while(level > 0)
		{
		document.write(" &nbsp; &nbsp;");
		level=level-1;
		}
	line = "";
	if(frame)
		target = "message";
	else
		target = "";
	if(d)
		extra = "ondragstart='del("+id+","+fid+")'";
	else
		extra = '';
		
	if(flags & 2)
		{
		appendlink = "&notext=1&urlsub="+urlsubject;
		}
	else
		appendlink = "";
		
	if(flags & 4)
		{
		subject = "<b>" + subject + "</b>";
		tt = "Sticky message !";
		}
	else
		tt = "Click to see message";
		
	
	line = ILink("zforummsg", subject, "mid="+id+"&fid="+fid+"&frame="+frame+"&table="+table+appendlink, tt, "forum", target, extra);
		
	line = line + " - ";
	if(pid)
		{
		line = line + PlayerLink(pid,sender);
		if(flags & 1)
			line = line + "&nbsp;<img src='" + Img("cbico.gif") + "' border='0' width='22' height='10'  align='absbottom' hspace='1' alt='ClanBase Crew member'>";
		}
	else
		line = line + sender;
	line = line + "<font color='#808080'> - "+date+"</font>";


	document.write(line);
}



function ThumbJS(file_, subsmall_, toptitle_, subtitle_, align, tooltip, popup)
{
	if(align == "")
		align = "right";
	tooltip = "Click to enlarge";
	popup=1;
  document.write("<table border='0' cellspacing='1' cellpadding='1'");
	if(align != '-')
	  document.write(" align="+align);
  document.write("><tr>");
	file_a = file_.split(";")
	subsmall_a = subsmall_.split(";")
	toptitle_a = toptitle_.split(";")
	subtitle_a = subtitle_.split(";")
	for(i=0; i < file_a.length; i++)
		{
		subsmall = subsmall_a[i];
		subtitle = subtitle_a[i];
		toptitle = toptitle_a[i];
		file = file_a[i];
	  document.write("<td class='small' valign=bottom align='center'>");
	  document.write("<div class='th'>");
		fti = file.lastIndexOf("/");
		if(fti != -1)
			thumb = file.substring(0, fti+1) + "tn_" +  file.substring(fti+1, thumb.length);
		else
			thumb = "tn_" + file;
		label = "<img src='" + Img(thumb) + "' border='0' vspace='0' hspace='0'";
		label = label + ">";
		if(popup)
			str = ILinkPopup("displaypic", label, "file=/miscfiles/"+file+"&toptitle="+toptitle+"&subtitle="+subtitle, tooltip, "slink");
		else
			str = ILink("displaypic", label, "file=/miscfiles/"+file+"&toptitle="+toptitle+"&subtitle="+subtitle, tooltip, "slink");
		document.write(str);
		document.write("</div>");
		if(subsmall)
			document.write(subsmall);
	  document.write("</td>");
		}
  document.write("</tr></table>");
}

function ThumbExt(file_, subsmall_, align, extra_)
{
	if(align == "")
		align = "right";
  document.write("<table border='0' cellspacing='1' cellpadding='1'");
	if(align != '-')
	  document.write(" align="+align);
  document.write("><tr>");
	file_a = file_.split(";")
	subsmall_a = subsmall_.split(";")

	width=600;
	height=600;
	tn_height = 0;
	tn_width = 0;
	tooltip = "Click to enlarge";
	popup=1;
	extra_a = extra_.split(";")
	for(i=0; i < extra_a.length; i++)
		{
		if(extra_a[i].substring(0,6) == "width=")
			width = parseInt(extra_a[i].substring(6,100));
		if(extra_a[i].substring(0,7) == "height=")
			height = parseInt(extra_a[i].substring(7,100));
		if(extra_a[i].substring(0,9) == "tn_width=")
			tn_width = parseInt(extra_a[i].substring(9,100));
		if(extra_a[i].substring(0,10) == "tn_height=")
			tn_height = parseInt(extra_a[i].substring(10,100));
		if(extra_a[i].substring(0,6) == "popup=")
			popup = (extra_a[i].substring(6,7) == '1');
		}
	for(i=0; i < file_a.length; i++)
		{
		subsmall = subsmall_a[i];
		file = file_a[i];
	  document.write("<td class='small' valign=bottom align='center'>");
	  document.write("<div class='th'>");
		fti = file.lastIndexOf("/");
		if(fti != -1)
			thumb = file.substring(0, fti+1) + "tn_" +  file.substring(fti+1, thumb.length);
		else
			thumb = "tn_" + file;
		label = "<img src='http://images.clanbase.com/"+thumb+"' border='0' vspace='0' hspace='0'";
		if(tn_width)
			label += " width=" + tn_width;
		if(tn_height)
			label += " height=" + tn_height;
		label = label + ">";
		if(popup)
			str = ILinkPopup("displaypic", label, "width="+width+"&height="+height+"&file=/"+file, tooltip, "slink", "", width+40, height+100);
		else
			str = ILink("displaypic", label, "file=/"+file, tooltip, "slink");
		document.write(str);
		document.write("</div>");
		if(subsmall)
			document.write(subsmall);
	  document.write("</td>");
		}
  document.write("</tr></table>");
}

function urlEncode(inStr)
{
	outStr=' '; //not '' for a NS bug!
	for (i=0; i < inStr.length; i++)
		{
		aChar=inStr.substring (i, i+1);
		switch(aChar)
			{
			case '%': outStr += "%25"; break; case ',': outStr += "%2C"; break;
			case '/': outStr += "%2F"; break; case ':': outStr += "%3A"; break;
			case '~': outStr += "%7E"; break; case '!': outStr += "%21"; break;
			case '"': outStr += "%22"; break; case '#': outStr += "%23"; break;
			case '$': outStr += "%24"; break; case "'": outStr += "%27"; break;
			case '`': outStr += "%60"; break; case '^': outStr += "%5E"; break;
			case '&': outStr += "%26"; break; case '(': outStr += "%28"; break;
			case ')': outStr += "%29"; break; case '+': outStr += "%2B"; break;
			case '{': outStr += "%7B"; break; case '|': outStr += "%7C"; break;
			case '}': outStr += "%7D"; break; case ';': outStr += "%3B"; break;
			case '<': outStr += "%3C"; break; case '=': outStr += "%3D"; break;
			case '>': outStr += "%3E"; break; case '?': outStr += "%3F"; break;
			case '[': outStr += "%5B"; break; case '\\': outStr += "%5C"; break;
			case ']': outStr += "%5D"; break; case ' ': outStr += "+"; break;
			default: outStr += aChar;
			}
		}
	return outStr.substring(1, outStr.length);
}

function setCookie(name, value, expire)
{
	var s, now = new Date(2020,11,31);
	s = name + "=" + escape(value) + "; path=/; expires=" + ((expire != null) ? expire.toGMTString() : now.toGMTString());
	document.cookie = s;
}

function getCookie(Name)
{
	var search = Name + "="
  if (document.cookie.length > 0)
		{ // if there are any cookies
    offset = document.cookie.indexOf(search) 
    if (offset != -1)
			{ // if cookie exists 
      offset += search.length 
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset) 
      // set index of end of cookie value
      if (end == -1) 
				end = document.cookie.length
      return unescape(document.cookie.substring(offset, end))
      } 
		}
	return "";
}

function TopicImage(fgid, lastpost)
{
	lastvisit = getCookie("fgid"+fgid);
	if(lastvisit < lastpost)
		{
		img = "qfnew.gif";
		t = "New messages since last visit";
		}
	else
		{
		img = "qfnotnew.gif";
		t = "No new messages";
		}
	document.write("<img src='" + Img(img) + "' border='0' title='" + t + "'>");
}


//
//	Menu by Nico (nico@clanbase.com)
//
var hidemenutimer = 0;
var menudelta = -30;
var menumargin = 10;
var menutimerdelay = 350;

function menushow(id) {
	window.clearTimeout(hidemenutimer);
	oBody = document.body;
	oMenu = document.getElementsByName("cbcupmenu");
	pob = document.getElementById('popupmenu_'+id);
	pobc = 0;
	menuoffset = 0;

	while(pob != oBody)
	{
		menuoffset += pob.offsetTop;
		pob = pob.offsetParent;
		pobc++;
	}

	hideSelect();
	
	for(i=0; i<oMenu.length; i++) {
		if( i != id ) {
			oMenu[i].style.visibility = 'hidden';
		} else {
			if(oMenu[i].clientHeight) {
				menuheight = oMenu[i].clientHeight;
			} else {
				menuheight = oMenu[i].offsetHeight;
			}

			clipheight = oBody.clientHeight;
			if(oBody.clientHeight > screen.availHeight) {
				clipheight = screen.availHeight - 150;
			}

			if( (menuoffset + menudelta) < (oBody.scrollTop + menumargin) ) {
				oMenu[i].style.top = oBody.scrollTop + menumargin;
			} else if( (menuoffset + menuheight + menudelta) > (clipheight + oBody.scrollTop - menumargin) ) {
				oMenu[i].style.top = oBody.scrollTop + clipheight - menuheight - menumargin;
			} else {
				oMenu[i].style.top = menuoffset + menudelta;
			}
			oMenu[i].style.visibility = 'visible';
		}
	}
}

function menuunhide(id) {
	window.clearTimeout(hidemenutimer);
}

function menuhide() {
	hidemenutimer = window.setTimeout("menuhide2();",menutimerdelay);
}

function menuhide2() {
	oMenu = document.getElementsByName("cbcupmenu");
	for(i=0; i<oMenu.length; i++) {
		oMenu[i].style.visibility = 'hidden';
	}
	if(document.all){ unhideSelect(); }
}

// KLUDGE: Hide SELECT elements for IE4/5/6 since they don't respect z-index and show through menus, etc

function hideSelect(){
	if(navigator.appName=='Microsoft Internet Explorer'){
		for (j=0; j<document.forms.length; j++) {
			var theForm = document.forms[j]
			for(i=0; i<theForm.elements.length; i++){
				if(theForm.elements[i].type == "select-one") {
					theForm.elements[i].style.visibility = "hidden";
				}
			}
		}
	}
}

function unhideSelect(){
	if(navigator.appName=='Microsoft Internet Explorer'){
		for (j=0; j<document.forms.length; j++) {
			var theForm = document.forms[j]
			for(i=0; i<theForm.elements.length; i++){
				if(theForm.elements[i].type == "select-one") {
					theForm.elements[i].style.visibility = "visible";
				}
			}
		}
	}
}

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizeable=0,width=980,height=575');");

}

function imageSizeCap(img, maxWidth, maxHeight)
{
	if(document.all) // Too hard for IE to do math on hidden images
		img.style.display = 'inline';

	if((img.height > maxHeight || img.width > maxWidth) && (maxWidth>0 && maxHeight>0))
	{
		img.oldHeight = img.height;
		img.oldWidth = img.width;
		ratio=img.width/img.height;
		if ((maxHeight*ratio)>maxWidth)
		{
			img.width = maxWidth;
			img.height=(maxWidth/ratio);
		} else {
			img.width=(maxHeight*ratio);
			img.height=maxHeight;
		}
		img.newHeight = img.height;
		img.newWidth = img.width;
		if(img.parentNode.nodeName != 'A')
		{
			img.title='Click to view full size image';
			img.onclick=Function ("imageSizeSwap(this)");
			img.style.cursor='pointer';
		}
	}
	img.style.display = 'inline';
}

function imageSizeSwap(img)
{
	if(img.oldHeight && img.oldWidth && img.newHeight && img.newWidth)
	{
		if((img.oldHeight==img.height) && (img.oldWidth==img.width))
		{
			img.height = img.newHeight;
			img.width = img.newWidth;
			img.title = 'Click to view full size image';
		} else {
			img.height = img.oldHeight;
			img.width = img.oldWidth;
			img.title = 'Click to reduce image size';
		}
	}
}