/***************************************************************
 *                  Author: Ian Crossfield                     *
 * Copyright 2004 The DVD Forums & The Red T-Shirt Company Ltd *
 *         www.thedvdforums.com   www.redtshirt.co.uk          *
 ***************************************************************/

function insertMenu()
{
	var xpos = 38;
	document.write( "<div align='center'>\n" );
	document.write( "<div class='page' style='text-align:left;width:100%;'>\n" );
	document.write( "<div style='padding:10px 25px 0px 25px'>\n" );
	document.write( "<table class='tborder' cellpadding='0' cellspacing='0' border='0' align='center'><tr>\n" );

//	document.write( "<td class='vbmenu_control' rowspan='2' nowrap>&nbsp;&nbsp;" );
	//document.write( "<a href='#' onclick='ypSlideOutMenu.showMenu( \"menu" + ( categories.length - 1 ) + "\" );' onmouseout='ypSlideOutMenu.hideMenu( \"menu" + ( categories.length - 1 ) + "\" );'>Support The DVD Forums&nbsp;<img src='images/misc/menu_open.gif' border='0'></a>\n" );
	//document.write( "</td>\n" );

	for ( var h = 0; h < 2; h++ )
	{
		if ( h == 1 )
		{
			document.write( "<tr>" );
		}
		document.write( "<td class='vbmenu_control' width='100%'>\n" );
		//document.write(categories.length);
		if (h == 1 ) {
			var x = 0;
		} else { 
			var x = 1;
		}
		for ( var i = 0; i < ( ( ( categories.length) / 2) - x ); i++ )
		{
			var j = i + ( h * ( ( ( categories.length ) / 2 ) - 1) );
			j = Math.round(j);
			var category = categories[ j ];
			if (category) {
				document.write( "&nbsp;&nbsp;&nbsp;" );
				document.write( "<span id=\"span"+j+"\"><a href='#' onclick='ypSlideOutMenu.showMenu( \"menu" + j + "\" );' onmouseout='ypSlideOutMenu.hideMenu( \"menu" + j + "\" );'>" + category[ cName ] + " <img src='images/misc/menu_open.gif' border='0'></a></span>\n" );
			}
			//document.write(  j + "=" + category[ cName ]);
		}
		if ( h ==0 )
		{
			// insert kelkoo search box
			document.write( "</td><td class='vbmenu_control' rowspan='2' align='right'>" );

			document.write( '<form method="post" target="_blank" action="http://www.pricedemon.co.uk/searchaggrigator.php">');
			document.write( '<input class="kinput" name="searchterm"  type="text" onfocus="if(this.value==\'Price Devil Search\')this.value=\'\';" value="Price Search" style="width:130px; font-family:tahoma; font-size:10px; line-height:normal;" /> ' );
			document.write( '<br><select class="kinput" name="searchtype" style="width:110px;font-family:tahoma; font-size:10px; line-height:normal;" />');
			
			document.write( '<option value="dvd">UK DVD</option>');
			document.write( '<option value="bluray">UK Blu-ray</option>');
			document.write( '<option value="hddvd">UK HD DVD</option>');
			document.write( '<option value="usdvd">US DVD</option>');
			document.write( '<option value="music">Music</option>');
			document.write( '<option value="games">Games</option>');
			document.write( '<option value="books">Books</option>');
			document.write( '<option value="electronics">Electronics</option>');
			
			document.write( '</select>' );
			document.write( '<button type="submit" alt="Go!" style="width:27px; height:17px;margin-top:2px; background:#aa0000; color:white; font:bold 9px tahoma; text-align:center; line-height:normal;">GO!</button>' );			
			
			document.write( '</form>');

			//document.write( '<form method="post" onsubmit="checkQuery()" name="kksearch">' );
			//document.write( '<input name="td_partner" type="hidden" id="partner" value="kelkoo">' );
			//document.write( '<input name="td_kpartnerid" type="hidden" id="kpartnerid" value="8915060">' );
			//document.write( '<input name="td_popups" type="hidden" id="popups" value="no">' );
			//document.write( '<input class="kinput" name="td_siteSearchQuery"  type="text" onfocus="if(this.value==\'Price Search\')this.value=\'\';" value="Price Search" style="width:110px; height:17px; font-family:tahoma; font-size:10px; line-height:normal;" /> ' );
			//document.write( '<button type="submit" alt="Go!" style="width:27px; height:17px; background:#F94E17; color:white; font:bold 9px tahoma; text-align:center; line-height:normal;">GO!</button>' );
			//document.write( '<br>' );
			//document.write( '<a href="http://www.thedvdforums.com/jump2.php?url=http://clkuk.tradedoubler.com/click?p=3431&a=60823&g=1092092&url=http://www.kelkoo.co.uk/?partner=kelkoo&popups=no&kpartnerid=8915060" target="_blank"><img src="images/misc/powered_by_kelkoo.gif" width="93" height="15" border="0" /></a>' );
			//document.write( '</form>' );
		}
		document.write( "</td></tr>\n" );
	}

	document.write( "</table>\n" );
	document.write( "</div></div></div>\n" );
	var m=0;
	for ( var i=0; i < categories.length; i++ )
	{
		var category = categories[ i ];

		document.write( "<div id='menu" + i + "Container'>\n" );
		document.write( "<div id='menu" + i + "Content' class='vbmenu_popup'>\n" );
		document.write( "<table cellpadding='1' cellspacing='0' border='0' width='100%'>" );
		
		var catStores = getCatStores( category[cCat] );
		var longest = 0;
		var fs = false;

		for ( var j = 0; j < catStores.length; j++ )
		{
			document.write( "<tr><td class='vbmenu_option'>" );
	
			var store = catStores[ j ];
			var link = store[ sHome ];
			var name = store[ sName ];
			if ( name.indexOf( "#" ) == 0 || name.indexOf( "!" ) == 0 || name.indexOf( "$" ) == 0 )
			{
				name = name.substring( 1, name.length );
			}

			var fst = false;
			
			if (category[1] == "Forum Sponsor") {
				fs  = true;
				fst = true;
				document.write( "<b>" );
			}
//			if ( store.length > sType )
//			{
//				var ext = store[ sType ];
//				ext = ext.substring( ext.length - 2, ext.length );
//
//				if ( ext == "fs" )
//				{
//					fs  = true;
//					fst = true;
//					document.write( "<b>" );
//				}
//			}

			document.write( "<a href=\"" + track( link, store ) + "\" target=\"_blank\">" + name + "</a>" );
			
			if ( fst )
			{
				document.write( "</b>" );
			}

			if ( name.length > longest )
			{
				longest = name.length;
			}
			document.write( "</td></tr>" );
		}		
		
		document.write( "</tr></table>" );
		document.write( "</div></div>\n" );

		var width;
		if ( fs )
		{
			width = ( catStores * 14 ) + 4;
		}
		else
		{
			width = ( catStores * 13 ) + 4;
		}

		var top = cTop + cYOffset;
	
		var pm = i - 1;
		var pms = 0;
		var xy = Math.round((categories.length - 1 ) / 2);
		

		
		if (document.getElementById('span'+pm)) {
			if (i  == xy) {
				xpos = 38;	
				pms = 0;
				m=0;
			} else {
				pms = document.getElementById('span'+pm).offsetWidth;
			}
			
			xpos = xpos + pms;
			//alert(xpos+cXOffset);
			//i
		}
		
		var left = xpos+cXOffset+11+(m*12);

		if ( i > ( ( ( categories.length - 1 ) / 2 ) -1 ) && i < ( categories.length ) )
		{
			top += 22;
		}
		else if ( i == ( categories.length - 1 ) )
		{
			top += 9;
		}

		new ypSlideOutMenu( "menu" + i, "down", left, top, ( longest * 8 ) + 4, ( catStores.length * 15 ) + 2 );
		m++;
	}
}

function checkQuery(){
	if (document.kksearch.td_siteSearchQuery.value=='Price Search' || document.kksearch.td_siteSearchQuery.value==''){
		alert('Please, type in a Keyword !');
		return false;
	}
	else
	{
		document.kksearch.action="http://clkuk.tradedoubler.com/click?p=3431&a=60823&g=1092092&url=http://www.kelkoo.co.uk/ctl/do/search";
		document.kksearch.target="kelkoo";
		document.kksearch.submit();
	}
}

function checkBlocker()
{
	if ( typeof SymError == "function" )
	{
		if ( document.cookie.indexOf( "affwarn" ) == -1 )
		{
			var expiry = new Date( 2050, 12, 31 );
			document.cookie = "affwarn=true; expires=" + expiry.toGMTString();

			var msg = "It appears that you are using Norton Internet Security.  We have discovered that a small\n";
			msg += "minority of users that use such software also have ad-blocking enabled, and that this may\n";
			msg += "cause problems viewing the forums - specifically white links on white backgrounds.  If you\n";
			msg += "are experiencing this problem, all we can advise is that you must:\n\n";

			msg += "1. Disable ad-blocking (but not your firewall, check out toolbar.google.co.uk for a good free\n";
			msg += "pop-up blocker).\n";
			msg += "2. Close all browser windows.\n";
			msg += "3. Open a new browser window, visit the forums and press CTRL+F5.\n\n";

			msg += "To view the thread on this issue, press the OK button, otherwise press Cancel to return to\n";
			msg += "the page you were viewing.  You will not see this pop-up again.\n\n";

			msg += "Regards\n\n";

			msg += "The DVD Forums Team";

			if ( confirm( msg ) )
			{
				self.location = "/forums/showthread.php?t=302939";
			}
		}
	}
}

// change these to move menu on page:
var cXOffset = 0;
var cYOffset = 72;

// do it:
insertMenu();
checkBlocker();