// go to a page
function reloadpage(month,year)
{
	if (month == '0')
	{
	pagelink = "https://www.farmerschoice.co.uk/Salesman/SalesHome.php?year="+year;
	}
	else
	{
	pagelink = "https://www.farmerschoice.co.uk/Salesman/SalesHome.php?month="+month;
	}
	window.open(pagelink,'_top')
}

///////////////////////////////////////////////////////////////
//	make sure page is secure
///////////////////////////////////////////////////////////////
function secure(sURL)
{
	if (location.protocol == "http:")
	{
		location.replace(sURL);
	}
}
/***********************************************************************
*
* link to page - 
*
************************************************************************/
function bounceto(value)
{
	var sURL = value;
	location.replace(sURL);
	return true;
}
/***********************************************************************
*
* submit poll vote - 
*
************************************************************************/
function sub_poll(value)
{
	var str = value;
	setCookie('FC_POLL', str, '');
	return true;
}
/***********************************************************************
*
* submit discount submition - 
*
************************************************************************/
function sub_dis_rst(result,date,online,rate,end,type,newdis)
{
	var str = result + '&!' + date + '&!' + online + '&!' + rate + '&!' + end + '&!' + type + '&!' + newdis;	
	setCookie('FC_DIS_RST', str, '', '/', '', '');
	return true;
}

/***********************************************************************
*
* setCookie -	Generic Set Cookie routine
*
* Input: sName	 -	Name of cookie to create
*	 sValue	 -	Value to assign to the cookie
*	 sExpire -	Cookie expiry date/time (optional)
*
* Returns: null
*
************************************************************************/

function setCookie(sName, sValue, sExpire) 
    {
    var sCookie = sName + "=" + escape(sValue) +"; path=/";	// construct the cookie
    if (sExpire)
    	{
    	sCookie += "; expires=" + sExpire.toGMTString();	// add expiry date if present
    	}
    document.cookie = sCookie;					// store the cookie
    return null;
    }

/***********************************************************************
*
* getCookie	-	Generic Get Cookie routine
*
* Input: sName	-	Name of cookie to retrieve
*
* Returns:		Requested cookie or null if not found
*
************************************************************************/

function getCookie(sName) 
    {
    var sCookiecrumbs = document.cookie.split("; "); 	// break cookie into crumbs array
    var sNextcrumb
    for (var i=0; i < sCookiecrumbs.length; i++) 
	{
	sNextcrumb = sCookiecrumbs[i].split("=");	// break into name and value
	if (sNextcrumb[0] == sName)			// if name matches
	    {
	     return unescape(sNextcrumb[1]); 		// return value
	    }
	}
	return null;
    }
/***********************************************************************
*
* delCookie	-	Generic Delete Cookie routine
*
* Input: sName	-	Name of cookie to retrieve
*
* Returns:		Deletes cookie if it is present
*
************************************************************************/

function delCookie(sName) 
    {
		if (getCookie(sName))
		{
			//sCookie += "; expires=" + sExpire.toGMTString();
			document.cookie = sName + "=" + ";expires=Thu, 01-Jan-70 00:00:01 GMT";
		}
    }
/********************************************
**
********************************************/
function delregcookie()
{
	setCookie('FC_REG', '-', '', '/', '', ''); 
	setCookie('FC_REG_ADDRESS', '-', '', '/', '', ''); 
	setCookie('FC_REG_MARKETING', '-', '', '/', '', ''); 	
var cookie = getCookie('FC_SALE');	
if (cookie == null)
	{
		return;
	}
	else if (cookie == "")
	{
		return;
	}
	else
	{
		var value = "https://www.farmerschoice.co.uk/Salesman/SalesAddCustomer.php";
		bounceto(value);
	}
}
/********************************************
**
********************************************/
function delsalregcookie()
{
	setCookie('FC_REG', '-', '', '/', '', ''); 
	setCookie('FC_REG_ADDRESS', '-', '', '/', '', ''); 
	setCookie('FC_REG_MARKETING', '-', '', '/', '', ''); 
}
/***********************************************************************
*
* ShowPopUp		-	creates pop up window
*
* Input: sUrl		-	URL o page to display
*			nWidth	-	Width of window
*			nHeight	-	Height of window
*
* Returns:				nothing
*
************************************************************************/

function ShowPopUp(sUrl, nWidth, nHeight)
  	{  
	window.open(sUrl, 'ActPopup', 'width=' + nWidth + ',height=' + nHeight + ',scrollbars, resizable');
	if (!bPageIsLoaded)
		{
		window.location.reload(true);
		}
	}


/********************************************
* Check Cookie for Customer Number 
*******************************************/
/*function getcustomernumber()
{
	var cookie = getCookie('FC_CUST');
	if (cookie == null)
	{
		return ('');
	}
	else
	{
	    return (cookie);
	}
}
*/
/********************************************
* Check Cookie for Customer Number 
*******************************************/
function getcustomernumber()
{
	var cookie = getCookie('ACTINIC_BUSINESS');
	if (cookie == null)
	{return ('');}
	else if (cookie == "-")
		{
			return ('');
		}
	else
		{	
		var findcookie = "USERNAME";
		var location = cookie.indexOf(findcookie);
		//alert (location)
		if (location > 0)
		{
			return (cookie);
		}
		else
		{
			return ('');
		}
	}
}
/********************************************
* Check Cookie for Ref Number 
*******************************************/
function getsalesman()
{
	var str = getCookie('FC_SALE')
	{
	if (str == null)
		{
			return ('No');
		}
	else
	 	{
		  if (str == "-")
		  	{
				return 'No';
			}
		  else
		  	{
				return 'Yes';
			}
		 }
	}
}
/********************************************
* Check Cookie for Ref Number 
*******************************************/
function getrefnumber()
{
	var str = getCookie('ACTINIC_BUSINESS')
	{
	if (str == null)
		{
			return ('No Account');
		}
	else
	 	{
		  if (str == "-")
		  	{
				return 'No Account';
			}
		  else
		  	{
				return 'Account';
			}
		 }
	}
}
////////////////////////////////////////////////
// Check to see if customer is logged in or Registered 
// If NOT bounce page to the login page
////////////////////////////////////////////////
function actNotRegistered()
{
var reg_cus = getCookie("FC_REG");
var customer = getrefnumber();
if (customer == 'No Account')
	{
	if(!reg_cus)
		{
		setCookie('LoginPage', 'not_reg', '');
		location.replace ('https://www.farmerschoice.co.uk/cgi-bin/ss000001.pl?ACTION=LOGIN');
		}	
	else {return;}	
	}
else
	{return;}
}

/*
function gotosection(section)
{
//var cust = getcustomernumber();
var sectionlink =section;	
//sectionlink = "http://www.farmerschoicefreerange.co.uk/farm_shop/"+section+".html";
sectionlink = "http://www.farmerschoicefreerange.co.uk/Products.php?term="+section+"";
window.open(sectionlink,'_top')
}
*/
/* functions for information menu */

<!-- Logged in customers only -->
function custinfodisplay()
{
cust = getcustomernumber();
	if (!cust)
	{
document.write('<div class="infoheader">My Account</div>');
document.write('<div class="infobody"><span class="textsmall">Please <b><a href="https://www.farmerschoice.co.uk/cgi-bin/ss000001.pl?ACTION=LOGIN">login</a></b> to view this service</span></div>');

document.write('<div class="infoheader">Track My Order</div>');
document.write('<div class="infobody"><span class="textsmall">Please <b><a href="https://www.farmerschoice.co.uk/cgi-bin/ss000001.pl?ACTION=LOGIN">login</a></b> to view this service</span></div>');

document.write('<div class="infoheader">My Details</div>');
document.write('<div class="infobody"><span class="textsmall">Please <b><a href="https://www.farmerschoice.co.uk/cgi-bin/ss000001.pl?ACTION=LOGIN">login</a></b> to view this service</span></div>');
	}
	else
	{
document.write('<div class="infoheader">');
document.write('My Account');
document.write('</div>');
document.write('<div class="infobody">');
document.write('<span class="textsmall">');
document.write('<div id="s_my_acc"></div>');
document.write('<input name="s_my_account" id="s_my_account" type="hidden" value="sum">');
ajaxGetPage('../ActSQL/MyAccount/MyAccount.php?type='+document.getElementById('s_my_account').value,'s_my_acc');
document.write('</span></div>');

document.write('<div class="infoheader">');
document.write('Track My Order');
document.write('</div>');
document.write('<div class="infobody">');
document.write('<span class="textsmall">');
document.write('<div id="get_tur_date"></div>');
document.write('<input name="s_track" id="s_track" type="hidden" value="cust_last">');
ajaxGetPage('../ActSQL/TrackOrder/trackorder.php?type='+document.getElementById('s_track').value,'get_tur_date');
document.write('</span></div>');

document.write('<div class="infoheader">');
document.write('My Details');
document.write('</div>');
document.write('<div class="infobody">');
document.write('<span class="textsmall">');
document.write('You can now edit your details online. Use the below link to edit your email address, password & contact methods.<br><br>');
document.write('<a href="http://www.farmerschoice.co.uk/my_details.php">Edit My Details -></a>');
//document.write('<div id="get_tur_date"></div>');
//document.write('<input name="s_track" id="s_track" type="hidden" value="cust_last">');
//ajaxGetPage('../ActSQL/TrackOrder/trackorder.php?type='+document.getElementById('s_track').value,'get_tur_date');
document.write('</span></div>');
/*
document.write('<div class="infoheader">');
document.write('Rate My Last Order');
document.write('</div>');
document.write('<div class="infobody">');
document.write('<span class="textsmall">');
document.write('<a name="rate"></a>');
document.write('<div id="s_rate"></div>');
document.write('<input name="s_order_rate" id="s_order_rate" type="hidden" value="last">');
ajaxGetPage('../ActSQL/OrderRater/RateMyOrder.php?rate='+document.getElementById('s_order_rate').value,'s_rate');
document.write('</span></div>');

document.write('<div class="infoheader">');
document.write('My Order History');
document.write('</div>');
document.write('<div class="infobody">');
document.write('<span class="textsmall">');
document.write('<div id="s_orders"></div>');
document.write('<input name="s_order" id="s_order" type="hidden" value="history">');
ajaxGetPage('../ActSQL/OrderHistory/MyOrderHistory.php?order='+document.getElementById('s_order').value,'s_orders');
document.write('</span></div>');

document.write('<div class="infoheader">');
document.write('My Web Settings');
document.write('</div>');
document.write('<div class="infobody">');
document.write('<span class="textsmall">');
document.write('<div id="s_web_set"></div>');
document.write('<input name="s_web_s" id="s_web_s" type="hidden" value="web">');
ajaxGetPage('../ActSQL/MySettings/MySettings.php?type='+document.getElementById('s_web_s').value,'s_web_set');
document.write('</span></div>');*/
	}
}
<!-- Logged in customers only -->
/* functions for information menu */

/////////////////////////////////////////
//	email Function below
/////////////////////////////////////////
// email functions
function setEmailAddress(subject)
{
   var _r = "enquiries"
   var _b = "farm";
   var _t = "erschoice";
   var _jet = "o.uk";
   var _ea = _r + "@" + _b + _t + ".c" + _jet;
   if (!subject)
	{
		return "<a href='mailto:" + _ea + "'>" + _ea + "</a>"
	}
	else
	{
		return "<a href='mailto:" + _ea + "?subject="+ subject +"'>Email us</a>"
	}
   
}
function emailaFriend()
{
   var pageName = window.location;
   window.location.href = 'mailto:?subject=Take%20a%20look%20at%20Farmers Choice Free Range Shop&body=I%20saw%20this%20page%20' + pageName + '%20and%20thought%20you%20would%20be%20interested.';
}

function emailrequeststate(cust)
{
   var str = 'I would like to request a statement';
   var _r = "enquiries"
   var _b = "farm";
   var _t = "erschoice";
   var _jet = "o.uk";
   var _ea = _r + "@" + _b + _t + ".c" + _jet;
   return "<a href='mailto:" + _ea + "?subject=Statement%20request%20for%20customer%20number%20"+cust +"&body=Please%20send%20me%20a%20copy%20of%20my%20statement'>"+ str +"</a>"
}
function emailwebproblem(seq)
{
   var pageName = window.location;
   var str = 'email';
   var _r = "enquiries"
   var _b = "farm";
   var _t = "erschoice";
   var _jet = "o.uk";
   var _ea = _r + "@" + _b + _t + ".c" + _jet;
   return "<a href='mailto:" + _ea + "?subject=Web%20Problem%20&body=I%20would%20like%20to%20report%20a%20web%20problem%20with%20page%20" + pageName + " ( " + seq + ")'>"+ str +"</a>"
}
function emailrecipesuggest()
{
   var str = 'I would like to suggest a recipe';
   var _r = "enquiries"
   var _b = "farm";
   var _t = "erschoice";
   var _jet = "o,uk";
   var _ea = _r + "@" + _b + _t + ".c" + _jet;
   return "<a href='mailto:" + _ea + "?subject=Suggest%20A%20recipe&body=I%20would%20like%20to%20suggest%20the%20below%20recipe'>"+ str +"</a>"
}
/*****************************************************
* Format Post Code
********************************************************/
function formatpost(el)
{
	if (!el.value)
	{
	return false;
	}
	else
	{
	el.value=(el.value.split(" ")).join("");
	el.value=el.value.toUpperCase();
	a=(el.value.length);
		if (a==7)	
				{	
					el.value=el.value.substring(0,4)+" "+el.value.substring(4,7);
					return el.value;
				}
		else if (a==6)
				{
					el.value=el.value.substring(0,3)+" "+el.value.substring(3,6);
					return el.value;
				}
		else 
				{
					el.value=el.value.substring(0,2)+" "+el.value.substring(2,5);
					return el.value;
				}
	}
}
