var bPageIsLoaded = false;
/***********************************************************************
*
* 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;
    }

/***********************************************************************
*
* saveReferrer -	Saves the referrer to a Cookie
*
* Input: 		nothing
*
* Returns:		null
*
************************************************************************/

function saveReferrer() 
    {
    var bSetCookie = false;
    if (parent.frames.length == 0)					// No FrameSet
		{
		bSetCookie = true;
		}
    else														// FrameSet in use
		{
		var bCatalogFrameSet = false;
		for (var nFrameId = parent.frames.length; nFrameId > 0; nFrameId--)
			{
			if (parent.frames[nFrameId - 1].name == 'CatalogBody')	// Catalog FrameSet used
				{
				bCatalogFrameSet = true;
				break;
				}
			}
		if (bCatalogFrameSet)							// Catalog FrameSet
			{
			if (window.name=='CatalogBody')			// and this is the CatalogBody frame
				{
				bSetCookie = true;
				}
			}
		else													// Not Catalog FrameSet
			{
			bSetCookie = true;
			}
		}
    if (bSetCookie)
		{
		var sUrl = document.URL;
		var nHashPos = sUrl.lastIndexOf("#");		// Look for URL anchor
		if (nHashPos > 0)									// if it exists
		    {
		    sUrl = sUrl.substring(0,nHashPos);		// then remove it
		    }
		setCookie("ACTINIC_REFERRER", sUrl);		// Emulates HTTP_REFERER
		}
	    return null;
	    }
    
saveReferrer();						// For v6 only, should be in templates for v7

/***********************************************************************
*
* CreateArray	creates an array with n elements
*
* Input: n	-	number of elements
*
* Returns:		the created array
*
************************************************************************/

function CreateArray(n)
	{
	this.length = n;
	for (var i=1; i <= n; i++)							// for all ns
		{
		this[i] = new Section();						// create a section structure
		}
	return this;											// return the created array
	}

/***********************************************************************
*
* Section	-	creates the section structure for raw section lists
*
* Input: 				nothing
*
* Returns:				nothing
************************************************************************/

function Section()
	{
	this.sURL = null;
	this.sName = null;
	this.sImage = null;
	this.nImageWidth = null;
	this.nImageHeight= null;
	this.nSectionId	= null;
	this.pChild = null;
	}
	
/***********************************************************************
*
* SwapImage			-	swaps an image to the alternative
*
* Input:	sName		-	name of the image
*
*			sAltImage	-	filename of the alternative image
*
************************************************************************/

function SwapImage(sName, sAltImage)
	{
	var nCount = 0;
	document.aSource = new Array;						// array for images
	if (document[sName] != null)						// if image name exists
		{
		document.aSource[nCount++] = document[sName];	// store image
		if(null == document[sName].sOldSrc)
			{
			document[sName].sOldSrc = document[sName].src;	// store image source
			}
		document[sName].src = sAltImage;				// change image source to alternative
		}
	}

/***********************************************************************
*
* RestoreImage		-	restores an image to the original
*
* Input: 				nothing
*
* Returns:				nothing
************************************************************************/

function RestoreImage()
	{
	var nCount, aSource = document.aSource;
	if (aSource != null)									// if array of images exists
		{
		for(nCount=0; nCount < aSource.length; nCount++)	// restore all images
			{
			if ((aSource[nCount] != null) &&
				(aSource[nCount].sOldSrc != null))	// if we stored something for this image
				{
				aSource[nCount].src = aSource[nCount].sOldSrc;	// restore the original image
				}
			}
		}
	}

/***********************************************************************
*
* PreloadImages		-	restores an image to the original
*
* Input: 				nothing
*
* Returns:				nothing
*
************************************************************************/

function PreloadImages()
	{
	bPageIsLoaded = true;
	if(document.images)
		{
		if(!document.Preloaded)							// preload array defined?
			{
			document.Preloaded = new Array();		// no, define it
			}
		var nCounter , nLen = document.Preloaded.length, saArguments = PreloadImages.arguments;
		for(nCounter = 0; nCounter < saArguments.length; nCounter++)	// iterate through arguments
			{
			document.Preloaded[nLen] = new Image;
			document.Preloaded[nLen++].src = saArguments[nCounter];
			}
   	}
	}
	
/***********************************************************************
*
* 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);
		}
	}

/**************************************************************************

Following functions added by Cetechuk.

formchecker - check e-mail address and phone number, terms & conditions client side

AddBookmark - add bookmark  link for IE5x/6

***************************************************************************/
var PhoneOK;
var TermsAgreed;

function formChecker(){

var emailregexp=/^[^@ ]+@[^@ ]+\.[^@ ]+$/;
var eMail=document.forms[0].INVOICEEMAIL.value;
if (emailregexp.test(eMail)==true)
        {
        phoneChecker();
                if (PhoneOK==1 && TermsAgreed==1)
                        {
                        document.forms[0].INVOICESALUTATION.value=document.forms[0].INVOICESALUTATION.value.toUpperCase();
                        document.forms[0].INVOICENAME.value=document.forms[0].INVOICENAME.value.toUpperCase();
                        document.forms[0].INVOICEADDRESS1.value=document.forms[0].INVOICEADDRESS1.value.toUpperCase();
                        document.forms[0].INVOICEADDRESS2.value=document.forms[0].INVOICEADDRESS2.value.toUpperCase();
                        document.forms[0].INVOICEADDRESS3.value=document.forms[0].INVOICEADDRESS3.value.toUpperCase();
                        document.forms[0].INVOICEADDRESS4.value=document.forms[0].INVOICEADDRESS4.value.toUpperCase();
                        document.forms[0].INVOICEPOSTALCODE.value=document.forms[0].INVOICEPOSTALCODE.value.toUpperCase();
                        return true;
                        }
                else
                {
                return false;
                }
        }
                        else
                            {
                                alert("Your e-mail address doesn\'t appear to be in the correct format\ne.g.myname@myserver.com. Please check your entry.");
                                document.forms[0].INVOICEEMAIL.focus();
                                return false;	
                            }
}

function regTest(numb){
var phoneExp = /[^()\d -]/i;
return !(phoneExp.test(numb));
}

function phoneChecker(){
var PhoneNumber=document.forms[0].INVOICEPHONE.value;
        if (regTest(PhoneNumber) == true && PhoneNumber != "")
                {
                TandC();
                PhoneOK=1;
                return PhoneOK;
                }
        else
                {
                alert("Please enter a valid phone number.\nYour phone number is NEVER disclosed to any third party.\nWe do not cold call!\nThank you.");
                document.forms[0].INVOICEPHONE.focus();
                PhoneOK=0;
                return PhoneOK;
                }
}

function TandC(){
        if(document.forms[0].AGREETERMSCONDITIONS.checked==false)
                {
                alert("You must agree to our Terms and Conditions\nby checking the box.\nThank you.");
                TermsAgreed=0;
                document.forms[0].AGREETERMSCONDITIONS.focus();
                return TermsAgreed;
                }
                        else
                                {
                                TermsAgreed=1;
                                return TermsAgreed;
                                }
}


window.defaultStatus="Welcome to Love2knit";

function addBookmark() 
    { 
	if (window.external)
	{
        external.AddFavorite('http://www.love2knit.co.uk','Love2knit')
        }
        else 
        {
        alert("Sorry, this feature only works with Internet Explorer.\nNetscape and Konqueror users: hit CTRL+D\nOpera users: hit CTRL+T");
        } 
    }

function doDate(){
var m_names = new Array("January", "February", "March", 
"April", "May", "June", "July", "August", "September", 
"October", "November", "December");

var d = new Date();
var curr_date = d.getDate();
var sup = "";
if (curr_date == 1 || curr_date == 21 || curr_date ==31)
   {
   sup = "st";
   }
else if (curr_date == 2 || curr_date == 22)
   {
   sup = "nd";
   }
else if (curr_date == 3 || curr_date == 23)
   {
   sup = "rd";
   }
else
   {
   sup = "th";
   }

var curr_month = d.getMonth();
var curr_year = d.getFullYear();

document.write("<span class=\"actxsmall\"><b>" +curr_date + " <sup>" + sup + "<\/sup> " 
+ m_names[curr_month] + " " + curr_year+"<\/b><\/span>");
}

function doformfocus(){
if(document.getElementById("fullsearch")){
        document.getElementById("fullsearch").focus();
    }
        else
                {
                document.getElementById("simple").focus();
                }
}
                