/*
 * General Javascript for PKL
 * http://ventutec.com
 *
*/

$(document).ready(
	function()
	{
		if( $("#cssdropdown li.headlink") )
		{
			$("#cssdropdown li.headlink").hover(
				function() { $("ul", this).css( "display", "block" ); },
				function() { $("ul", this).css( "display", "none" ); }
			);
		}
		if( $("#site-map") )
		{
			$("#site-map").hide();
		}
		if( $("#sitemap-link") )
		{
			$("#sitemap-link").click(
				function()
				{
					$("#site-map").slideToggle("slow");
					$(this).toggleClass("active");
				}
			);
		}
		if( $("a[rel=example_group]") )		{			$("a[rel=example_group]" ).fancybox(			{				'transitionIn'    : 'none',				'transitionOut'   : 'none',				'titlePosition'   : 'over',				'titleFormat'     : function(title, currentArray, currentIndex, currentOpts) {												return '<span id="fancybox-title-over" ) & ">'+((this.title=='')?'Image '+(currentIndex+1)+' / '+currentArray.length:this.title)+'</span>';									}			});		}		if( $("a[rel=favouredfootprint_group]") )		{			var hFFGroup = $("a[rel=favouredfootprint_group]");			for( var nItem = 0; nItem < hFFGroup.length; nItem++ )			{				$( hFFGroup[nItem] ).fancybox(				{					'transitionIn'    : 'fade',					'transitionOut'   : 'fade',					'titlePosition'   : 'over',					'type'            : 'iframe',					'href'            : hFFGroup[nItem].href.replace('.asp', '.asp?so=inline'),					'showNavArrows'   : false,					'autoDimensions'  : false,					'titleShow'       : false,					'padding'         : 5,					'margin'          : 5,					'height'          : 725,					'width'           : 675				});			}		}		if( $("a[rel=provenpackage_group]") )		{			var hPPGroup = $("a[rel=provenpackage_group]");			for( var nItem = 0; nItem < hPPGroup.length; nItem++ )			{				$( hPPGroup[nItem] ).fancybox(				{					'transitionIn'    : 'fade',					'transitionOut'   : 'fade',					'titlePosition'   : 'over',					'type'            : 'iframe',					'href'            : hPPGroup[nItem].href.replace('.asp', '.asp?so=inline'),					'showNavArrows'   : false,					'autoDimensions'  : false,					'titleShow'       : false,					'padding'         : 5,					'margin'          : 5,					'height'          : 725,					'width'           : 675				});			}		}		if( $("a[rel=kititem_group]") )		{			var hKitGroup = $("a[rel=kititem_group]");			for( var nItem = 0; nItem < hKitGroup.length; nItem++ )			{				$( hKitGroup[nItem] ).fancybox(				{					'transitionIn'    : 'fade',					'transitionOut'   : 'fade',					'titlePosition'   : 'over',					'type'            : 'iframe',					'href'            : hKitGroup[nItem].href.replace('.asp', '.asp?so=inline'),					'showNavArrows'   : false,					'autoDimensions'  : false,					'titleShow'       : false,					'padding'         : 5,					'margin'          : 5,					'height'          : 625,					'width'           : 650				});			}		}		if( document.getElementById( 'content' ) && document.getElementById( 'langcode' ) )
		{
			if( document.getElementById( 'langcode' ).value != 'en' )
			{
				var hDisclaimer = document.createElement( 'p' );
				hDisclaimer.setAttribute( 'id', 'google-disclaimer' );
				var hDisclaimerContent = document.createTextNode( 'This page has been generated using Google Translate' );
				hDisclaimer.appendChild( hDisclaimerContent );

				var hOverview = document.getElementById( 'overview' );
				var hParentDiv = hOverview.parentNode;
				hParentDiv.insertBefore( hDisclaimer, hOverview );

				var strCookieDisclaimer = GetCookie( 'pkl-foodservices-translate-disclaimer' );
				if( strCookieDisclaimer == 'declined' )
				{
					var strLocation = document.location.toString();
					strLocation = strLocation.replace( String( '/'+document.getElementById( 'langcode' ).value+'/' ), '/' );
					document.location = strLocation;
				}
				else if( strCookieDisclaimer == 'accepted' )
				{
					// OK
				}
				else
				{
					if( $("#google-disclaimer") )
					{
						$("#google-disclaimer").fancybox(						{							'transitionIn'			: 'fade',							'transitionOut'			: 'fade',							'titlePosition'			: 'over',							'enableEscapeButton'	: false,							'hideOnContentClick'	: false,							'hideOnOverlayClick'	: false,							'showCloseButton'		: false,							'href'					: '../../foodservices/accept-google-translations.asp',							'showNavArrows'			: false,							'autoDimensions'		: true,							'content'				: '<div id="google-disclaimer-popup"><p>The following pages have been translated by Google Translate so may contain errors and inaccuracies.</p><input type="button" id="ba" value="Accept" onclick="javascript: TermsAccepted(); " /><input type="button" value="Decline" onclick="javascript: TermsDeclined(); " /></div>',							'titleShow'				: false,							'padding'				: 15						});
						$("#google-disclaimer").click();
					}
				}
			}
		}
	}
);

function SearchBoxFocus(hSearchBox, bFocus)
{
	if( bFocus )
	{
//		User Focus on Search Box
		if( hSearchBox.alt.toUpperCase() == hSearchBox.value.toUpperCase() )
		{
			hSearchBox.value = '';
		}
	}
	else
	{
//		Focus lost on Search Box
		if( hSearchBox.value == '' )
		{
			hSearchBox.value = hSearchBox.alt;
		}
	}
}

function SubmitRequest()
{
	if( document.brochurerequestform )
	{
		if( document.brochurerequestform.brname.value == '' )
			alert( document.brochurerequestform.brname.title );
		else if( document.brochurerequestform.brcompany.value == '' )
			alert( document.brochurerequestform.brcompany.title );
		else if( document.brochurerequestform.brtel.value == '' )
			alert( document.brochurerequestform.brtel.title );
		else if( document.brochurerequestform.bremail.value == '' )
			alert( document.brochurerequestform.bremail.title );
		else if( document.brochurerequestform.braddr.value == '' )
			alert( document.brochurerequestform.braddr.title );
		else
			document.brochurerequestform.submit();
	}
}

function SubmitContactUs()
{
	if( document.contactusform )
	{
		if( document.contactusform.ctname.value == '' )
			alert( document.contactusform.ctname.title );
		else if( document.contactusform.ctcompany.value == '' )
			alert( document.contactusform.ctcompany.title );
		else if( document.contactusform.cttel.value == '' )
			alert( document.contactusform.cttel.title );
		else if( document.contactusform.ctemail.value == '' )
			alert( document.contactusform.ctemail.title );
		else
			document.contactusform.submit();
	}
}

/************************************************************************************************************************************
*	
************************************************************************************************************************************/
function TermsTicked(hElement)
{
	if( document.getElementById( 'ba' ) )
	{
		document.getElementById( 'ba' ).disabled = !hElement.checked;
	}
}
/************************************************************************************************************************************
*	
************************************************************************************************************************************/
function TermsAccepted()
{
	SetCookie( 'pkl-foodservices-translate-disclaimer', 'accepted', 30 );
	parent.document.location = parent.document.location;
}
/************************************************************************************************************************************
*	
************************************************************************************************************************************/
function TermsDeclined()
{
	SetCookie( 'pkl-foodservices-translate-disclaimer', 'declined', 30 );
	parent.document.location = parent.document.location;
}
/************************************************************************************************************************************
*	Get Cookie
************************************************************************************************************************************/
function GetCookie(strName)
{
	if( document.cookie.length > 0 )
	{
		var chStart = document.cookie.indexOf( strName + '=' );
		if( chStart != -1 )
		{
			chStart = chStart + ( strName.length + 1 );
			var chEnd = document.cookie.indexOf( ';', chStart );
			if( chEnd == -1 )
				chEnd = document.cookie.length;

			return( unescape( document.cookie.substring( chStart, chEnd ) ) );
		}
	}
	return( '' );
}
/************************************************************************************************************************************
*	Set Cookie
************************************************************************************************************************************/
function SetCookie(strName, strValue, nExpireDays)
{
	var hExpireDate = new Date();
	hExpireDate.setDate( hExpireDate.getDate() + nExpireDays );
	document.cookie = strName+'='+escape( strValue )+( ( hExpireDate == null ) ? '' : ';expires='+hExpireDate.toGMTString() );
}
/************************************************************************************************************************************
*	Set Cookie
************************************************************************************************************************************/
function SFBR(strID)
{
	if( $('input[rel="'+strID+'"]') )	{		var hFBGroup = $('input[rel="'+strID+'"]');		for( var nItem = 0; nItem < hFBGroup.length; nItem++ )		{			$( hFBGroup[nItem] ).click();		}	}}

