
//
//Panwebtech JavaScript functions include file
// (C) www.panwebtech.co.uk
//
var blnState=new Array(7);
blnState[0]=true;
for(var j=1;j<8;j++)
	{
	blnState[j]=false;
	}
var imgImages=new Array(15);
var strState="off";
var bytCount=0;
for(var i=0;i<16;i++)
	{
	bytCount=i;
	if(i>=8){strState="on";bytCount=i-8;}
	imgImages[i]=new Image;
	imgImages[i].src="../images/menu"+strState+"_"+bytCount+".gif";
	}
function fSwapImage(strId,intState)
{
var objThis=document.getElementById(strId);
var intId=parseInt(strId);
if(blnState[intId]){return true}
if(intState==1){intId+=8}
objThis.src=imgImages[intId].src;
}
function fForceImage(strId)
{
var intId=parseInt(strId);
for(var i=0;i<8;i++)
	{
	objThis=document.getElementById(i);
	if(i!=intId)
		{
		blnState[i]=false;
		objThis.src=imgImages[i].src;
		}
	else
		{
		blnState[i]=true;
		objThis.src=imgImages[i+8].src;
		}
	}
return true;
}
function fAutoCR()
{
if(window.event.keyCode==13)
	{
	fSearch();
	}
return false;
}
function fZoom(intCompanyId,strUrl,strTitle)
{
var strUrl="../zoom/zoom.asp?companyid="+intCompanyId+"&mode=2&url="+strUrl+"&imagefolder=user_images&title="+strTitle;
if(blnZoomOpen)
  {
  objZoom.close();
  }
if((!blnZoomOpen) || (objZoom.closed))
	{
	objZoom = window.open(strUrl, "zoom", "width=480,height=360,resizable=no");
	blnZoomOpen = true;
	}
objZoom.focus();
}
var blnMailOpen=false;
var objMail;
function fMail()
{
if(blnMailOpen){objMail.close()}
if((!blnMailOpen)||(objMail.closed))
	{
	objMail=window.open("../mailtofriend.asp?shopid="+fQueryString(window.location,"shopid")+"&mode=1","winMailToFriend","width=420,height=520");
	blnMailOpen=true;
	}
}
function fNavigate(intId,intContentId,intForceId)
{
var strUrl;
var strAdditional="";
switch(intId)
	{
	case 0:
		strUrl="pages/freeflowpages.asp";
		break;
	case 1:
		strUrl="pages/freeflowpages.asp";
		break;
	case 2:
		strUrl="products/products.asp";
		break;
	case 3:
		strUrl="locations/locations.asp";
		break;
	case 4:
		strUrl="pages/freeflowpages.asp";
		break;
	case 5:
		strUrl="news/news.asp";
		break;
	case 6:
		strUrl="contact/contact.asp";
		break;
	case 7:
		strUrl="service/login.asp";
		strAdditional="&mode=1";
		break;
	case 20:
		strUrl="privacy/privacy.asp";
		break;
	case 21:
		strUrl="terms/terms.asp";
		break;
	}
strUrl="../"+strUrl+"?companyid=1&contentid="+intContentId+"&forceid="+intForceId+strAdditional;
strUrl+="&changed="+fQueryString(window.location,"changed")+"&sid="+fQueryString(window.location,"sid");
window.location.href=strUrl;
return true;
}
function fRollover(blnRoll, objThis)
{
var bytIndex;
var strUrl;
if(blnRoll==1)
	{
	objThis.style.color="#3333ff";
	}
else
	{
	objThis.style.color="#f08d30";
	}
}
function fNoPipe(objThis)
{
var intLen=objThis.value.length;
var strString=objThis.value;
var bytReason=0;
var strReason="";
var intChar=0;
var strOutput="";
for(var i=0;i<=intLen;i++)
	{
	intChar=strString.charCodeAt(i);
	if(intChar==124)
		{
		bytReason=1;
		intChar=0;
		}
	if(intChar==34||intChar==39)
		{
		bytReason=2;
		intChar=96;
		}
	if(intChar==38)
		{
		bytReason=3;
		intChar=0;
		}
	if(intChar)
		{
		strOutput+=String.fromCharCode(intChar);
		}
	}
if(bytReason>0)
	{
	switch (bytReason)
		{
		case 1:
			strReason="The pipe character | is not allowed.";
			break;
		case 2:
			strReason="Quotes are not allowed, they will be replaced";
			break;
		case 3:
			strReason="The ampersand character '&', is not allowed";
			break;
		}
	alert("Please check the value you just entered.\n\nReason: "+strReason);
	objThis.value=strOutput;
	}
if(bytReason>0)
	{
	objThis.focus();
	objThis.select();
	return false;
	}
return true;
}
function fQueryString(objLocation, strName)
{
//Returns the value for the passed strName (Case insensitive)
var intIndex;
var strQueryLc;
var strQuery;

strQuery=objLocation.search;
strQueryLc=strQuery.toLowerCase();
strName=strName.toLowerCase()+"=";
intIndex=strQueryLc.indexOf(strName);
if(intIndex<0)
	{
	return "";
	}
intIndex=strQueryLc.indexOf("=",intIndex);
intIndex+=1;
strQuery=strQuery.slice(intIndex);
intIndex=strQuery.indexOf("&");
if(intIndex<0)
	{
	return strQuery;
	}
else
	{
	return strQuery.substring(0,strQuery.indexOf("&"));
	}
}
function fQueryStringMinus(blnObj,objLocation,strParm)
{
//Removes strParm from the QS passed if found, blnObj switches location object/text passed
var strQuery
blnObj?strQuery=objLocation.search:strQuery=objLocation;
if(strQuery==""){return strQuery}
strQuery=strQuery.substr(1);
var strBits=strQuery.split("&");
strQuery="";
for(var i=0;i<strBits.length;i++)
	{
	if(strBits[i].indexOf(strParm+"=")<0)
		{
		if(strQuery!=""){strQuery=strQuery+"&"}
		strQuery=strQuery+strBits[i];
		}
	}
strQuery="?"+strQuery;
return strQuery;	
}
function fQueryStringText(strLocation, strName)
{
//Returns the value for the passed strName (Case insensitive)
var intIndex;
var strQueryLc;
var strQuery;

strQuery=strLocation.substr(strLocation.indexOf("?"));
strQueryLc=strQuery.toLowerCase();
strName=strName.toLowerCase()+"=";
intIndex=strQueryLc.indexOf(strName);
if(intIndex<0)
	{
	return "";
	}
intIndex=strQueryLc.indexOf("=",intIndex);
intIndex+=1;
strQuery=strQuery.slice(intIndex);
intIndex=strQuery.indexOf("&");
if(intIndex<0)
	{
	return strQuery;
	}
else
	{
	return strQuery.substring(0,strQuery.indexOf("&"));
	}
}
function fInputEmailCheck(objThis)
{
var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
var intLen=objThis.value.length;
var strString=objThis.value;
var bytReason=0;
var strReason="";
var intChar=0;
var strOutput="";
if(intLen==0)
	{
	return true;
	}
for(var i=0;i<intLen;i++)
	{
	intChar=strString.charCodeAt(i);
	if((intChar>47 && intChar<58)||(intChar>63 && intChar<91)||(intChar>96 && intChar<123)||(intChar>44 && intChar<47)||(intChar==95))
		{
		//unused
		}
	else
		{
		bytReason=1;
		intChar=0;
		}
	if(intChar)
		{
		strOutput+=String.fromCharCode(intChar);
		}
	}
if(!reg1.test(strOutput) && reg2.test(strOutput)) 
	{
	//unused
	}
else
	{
	bytReason=2;
	}
if(bytReason>0)
	{
	switch (bytReason)
		{
		case 1:
			strReason="One or more illegal characters have been replaced.";
			break;
		case 2:
			strReason="Not a valid email address format";
			break;
		}
	alert("Please check the email address you just entered.\n\nReason: "+strReason);
	}
objThis.value=strOutput;
if(bytReason>0)
	{
	objThis.focus();
	objThis.select();
	}
return true;
}
function fInputDateCheck(objThis)
//Checks date format passed onChange event is dd/mm/yyyy
{
var strString=objThis.value;
var strBits=strString.split("/");
var strLimits="31|28|31|30|31|30|31|31|30|31|30|31".split("|");
var blnFailed;
if(strBits.length!=3){blnFailed=true}
if(!blnFailed)
	{
	for(var i=0;i<3;i++)
		{
		if(isNaN(strBits[i]))
			{
			blnFailed=true;
			break;
			}
		}
	}
if(!blnFailed)
	{
	if((strBits[0]<1)||(strBits[0]>31)||(strBits[1]<1)||(strBits[1]>12)||(strBits[2]<1900)||(strBits[2]>2020))
		{
		blnFailed=true;
		}
	}
if(!blnFailed)
	{
	for(i=0;i<12;i++)
		{
		if((strBits[1]==(i+1))&&(strBits[0]>strLimits[i])){blnFailed=true;break}
		}
	}
if(blnFailed)
	{
	alert("Please ensure that the date is correct and in the format (dd/mm/yyyy)");
	objThis.value="";
	objThis.focus();
	return false;
	}
return true;
}
function fInputNumberCheck(objThis,blnFloat,blnNeg,blnSpace)
{
var strString=objThis.value;
var bytReason=0;
var strReason;
if(objThis.value==""){return true}
if((strString.indexOf(" ")>=0)&&!blnSpace){bytReason=5}
if((strString.indexOf(".")>=0)&&!blnFloat){bytReason=2}
if((strString.indexOf("-")>=0)&&!blnNeg){bytReason=4}
if(isNaN(strString)){bytReason=6}
if(bytReason>0)
	{
	switch (bytReason)
		{
		case 1:
			strReason="Decimal point out of position or duplicated.";
			break;
		case 2:
			strReason="Decimal point is not allowed.";
			break;
		case 3:
			strReason="Minus sign out of position or duplicated.";
			break;
		case 4:
			strReason="Negative values are not allowed.";
			break;
		case 5:
			strReason="The space character is not allowed.";
			break;
		case 6:
			strReason="Non-numeric character found.";
			break;
		}
	alert("Please check the value you just entered.\n\nReason: "+strReason);
	}
if(bytReason>0)
	{
	objThis.focus();
	objThis.select();
	}
return true;
}
function fResize(intX, intY, objWindow)
{
//Resize the browser window to the passed parameters
var intCurrX;
var intCurrY;

objWindow.resizeTo(intX,intY);
if(self.innerWidth)
	{
	intCurrX=objWindow.self.innerWidth;
	intCurrY=objWindow.self.innerHeight;
	}
else
	{
	intCurrX=objWindow.document.body.clientWidth;
	intCurrY=objWindow.document.body.clientHeight;
	}
//Calculate sizing error based on amount of "Chrome"
intX=intX+(intX-intCurrX);
intY=intY+(intY-intCurrY);
//Resize correctly
objWindow.resizeTo(intX,intY);
return true;	
}

function fCentre(objWindow)
{
//Centre the browser
var intWidth=objWindow.self.screen.availWidth;
var intHeight=objWindow.self.screen.availHeight;
var intBWidth;
var intBHeight;
if(self.outerWidth)
	{
	intBWidth=objWindow.self.outerWidth;
	intBHeight=objWindow.self.outerHeight;
	}
else
	{
	intBWidth=objWindow.document.body.clientWidth;
	intBHeight=objWindow.document.body.clientHeight;
	}
objWindow.moveTo((intWidth-intBWidth)/2,(intHeight-intBHeight)/2);
return false;
}

function fToProper(strString)
{
//Return the passed string with all first leters capitalised
//only works on space delimited strings
var strSentence=new Array;
var i;
var bytChar;

strString=strString.toLowerCase();
strSentence=strString.split(" ");
for(i=0;i<strSentence.length;i++)
	{
	bytChar=strSentence[i].charCodeAt(0);
	if((bytChar>96)&&(bytChar<123))
		{
		bytChar-=32;
		strSentence[i]=String.fromCharCode(bytChar)+strSentence[i].substr(1,(strSentence[i].length)-1);
		}
	}
return strSentence.join(" ");
}

function fAlphaNumOnly(strString)
{
//Return the passed string stripped of all symbols and any double spaces
var i;
var bytChar;
var blnSpace=false;
var strNewString="";
strString=strString.toLowerCase();
for(i=0;i<strString.length;i++)
	{
	bytChar=strString.charCodeAt(i);
	if(bytChar!=32)
		{
		blnSpace=false;
		}
	if(((bytChar==32)&&(blnSpace==false))||(bytChar!=32))
		{
		if((bytChar==32)||((bytChar>47)&&(bytChar<58))||((bytChar>96)&&(bytChar<123)))
			{
			if(bytChar==32)
				{
				blnSpace=true;
				}
			strNewString=strNewString+String.fromCharCode(bytChar);
			}
		else
			{
			blnSpace=true;
			}
		}
	}
var strSentence=strNewString.split(" ");
strNewString="";
for(i=0;i<strSentence.length;i++)
	{
	if(strSentence[i]!==" ")
		{
		strNewString=strNewString+strSentence[i];
		}
	if((i+1)<strNewString.length)
		{
		strNewString=strNewString+" ";
		}
	}
return strNewString;
}

function fCreateBookmark() 
{
if ((navigator.appVersion.indexOf("MSIE") > 0)&&(parseInt(navigator.appVersion)>= 4))
  { 
  window.external.AddFavorite("http:/www.newarc.co.uk","Newarc Equipment Ltd.");
  }
else
  {
  alert('Sorry, your browser does not\nsupport automatic bookmarking.\n \n' + 
  'For Netscape Navigator or Firefox, press Ctrl-D\n(or Command-D on the Mac).');
  location.href = location.href;
  }
}
function fFormatCurrency(intVal)
{
//Returns a string for display as a currency value i.e 12.70 or 0.01 or 0.10
var strVal=intVal+"";
var intOffset=strVal.indexOf(".");
var strDecimal="0";
var strNumber;
if(intOffset>-1)
	{
	strDecimal=strVal.slice(intOffset+1,strVal.length);
	strNumber=strVal.slice(0,intOffset)
	switch(strDecimal.length)
		{
		case 1:
			strDecimal+="0";
			break;
		case 2:
			break;
		default:
			strDecimal=strDecimal.slice(0,2)+"."+strDecimal.slice(2,strDecimal.length-2);
			strDecimal=parseFloat(strDecimal);
			strDecimal=Math.ceil(strDecimal);
			strDecimal+="";
			if(strDecimal.length==1)
				{
				strDecimal="0"+strDecimal;
				}
		}
	}
else
	{
	strNumber=intVal+"";
	strDecimal="00"
	}
return strNumber+"."+strDecimal;
}

// Flash Version Detector  v1.2.1
// documentation: http://www.dithered.com/javascript/flash_detect/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)
// with VBScript code from Alastair Hamilton (now somewhat modified)


function isDefined(property) {
  return (typeof property != 'undefined');
}

var flashVersion = 0;
function fGetFlashVersion() {
	var latestFlashVersion = 8;
   var agent = navigator.userAgent.toLowerCase(); 
	
   // NS3 needs flashVersion to be a local variable
   if (agent.indexOf("mozilla/3") != -1 && agent.indexOf("msie") == -1) {
      flashVersion = 0;
   }
   
	// NS3+, Opera3+, IE5+ Mac (support plugin array):  check for Flash plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		var flashPlugin = navigator.plugins['Shockwave Flash'];
		if (typeof flashPlugin == 'object') { 
			for (var i = latestFlashVersion; i >= 3; i--) {
            if (flashPlugin.description.indexOf(i + '.') != -1) {
               flashVersion = i;
               break;
            }
         }
		}
	}

	// IE4+ Win32:  attempt to create an ActiveX object using VBScript
	else if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && agent.indexOf("win")!=-1 && agent.indexOf("16bit")==-1) {
	   var doc = '<scr' + 'ipt language="VBScript"\> \n';
      doc += 'On Error Resume Next \n';
      doc += 'Dim obFlash \n';
      doc += 'For i = ' + latestFlashVersion + ' To 3 Step -1 \n';
      doc += '   Set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash." & i) \n';
      doc += '   If IsObject(obFlash) Then \n';
      doc += '      flashVersion = i \n';
      doc += '      Exit For \n';
      doc += '   End If \n';
      doc += 'Next \n';
      doc += '</scr' + 'ipt\> \n';
      document.write(doc);
   }
		
	// WebTV 2.5 supports flash 3
	else if (agent.indexOf("webtv/2.5") != -1) flashVersion = 3;

	// older WebTV supports flash 2
	else if (agent.indexOf("webtv") != -1) flashVersion = 2;

	// Can't detect in all other cases
	else {
		flashVersion = flashVersion_DONTKNOW;
	}

	return flashVersion;
}

flashVersion_DONTKNOW = -1;
