﻿<!--
//The above syntax prevents old browsers from displaying the javascript as page content

//Code developed and designed by w3presence, for more information goto www.w3presence.co.uk
//No authorisation is given to copy, edit or delete these functions or comments contained herein.
//W3Presence (SDS Ltd) Copyright 2004

//The syntax to include the services supplied in this module is;
//<script language="javascript" src="/skelapp/_include/_javascript/JSInclude_StandardSupport.js"></script>

//Example Calls:

//Notes:
//	Link information
//	<a href="download.zip" onClick="return confirm('Are you sure?')">Download</a> //This can be used to confirm an operation using an alert box
//	<a href="http://www.yahoo.com/"  onClick="return false">Yahoo</a> //The use of return false cancels the link even if the users clicks the link
//
//	Submit information
//	<form name=form1 method=post action="javascript:alert('The form is submitted.')" onSubmit="return jsf_ValidateForm()">	//Returning a false status in the onSubmit event causes the form submit to be cancelled
//
//	Javascript update a form element 	document.form2.S2.value = result;

var jsf_sRestricted_Message = "Sorry, this function is disabled";	//Restricted access warning message
var jsf_bSuppressRightButton=0	// 0 is false (right mouse available), 1 is true (right mouse not available)

function jsf_Alert(sMessage) {
//This is a test function

	alert(sMessage);

}

function jsf_Add2Basket(sSKU, lSKUQty) {
//This function adds an item to the shopping cart
	location.href="./mybasket.asp?sku=" + sSKU + "&skuquantity=" + lSKUQty;
}

function jsf_EmbedFlashObject(sFlashPath, sFlashID, lWidth, lHeight, sAlignment, sBackgroundColor, sFlashVariables) {
//This function creates an external reference to a flash object - fixes the 'click to active' in IE
var sBaseURL="";
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="' + lWidth + '" height="' + lHeight + '" id="' + sFlashID + '" name="' + sFlashID + '"> '
		+ '<param name="movie" value="' + sFlashPath + '">'
		+ '<param name="allowscriptaccess" value="always">'
		+ '<param name="salign" value="' + sAlignment + '">'
		+ '<param name="play" value="true">'
		+ '<param name="loop" value="false">'
		+ '<param name="menu" value="false">'
		+ '<param name="quality" value="autohigh">'
		+ '<param name="scale" value="noscale">'
		+ '<param name="bgcolor" value="' + sBackgroundColor + '"> '
		+ '<param name="wmode" value="transparent">'
		+ '<param name="base" value="' + sBaseURL + '">'
		+ '<param name="flashvars" value="' + sFlashVariables + '">'
		+ '<param name="type" value="application/x-shockwave-flash"> '
			+ '<embed width="' + lWidth + '" height="' + lHeight + '" src="' + sFlashPath + '" pluginspace="https://www.macromedia.com/go/getflashplayer" ' 
				+ 'id="' + sFlashID + '" name="' + sFlashID + '" allowscriptaccess="always" salign="' + sAlignment + '" play="true" loop="false" menu="false" '
				+ 'quality="autohigh" scale="exactfit" bgcolor="' + sBackgroundColor + '" wmode="transparent" base="' + sBaseURL + '" flashvars="' + sFlashVariables + '" '
				+ 'type="application/x-shockwave-flash" '
			+ '</embed> '
		+ '</object>') ;
}

function jsf_URLEncode(sString) {
//This function applies url encoded to the specified string
var sEncoded = "";
	
	for (i = 0; i < sString.length; i++) {
		if (sString.charAt(i) == " ") {
			sEncoded += "+";
		}
		else {
			sEncoded += sString.charAt(i);
		}
	}
	
	return escape(sEncoded);
}

function jsf_URLDecode(sString) {
//This function reverses existing url encoding 
var sDecoded = sString.replace(/\+/g, " ");
	
	return unescape(sDecoded);
}

function jsf_LimitText(sTextArea, lLimitNum) {
		
	if (document.getElementById(sTextArea).value.length > lLimitNum) {
		document.getElementById(sTextArea).value = document.getElementById(sTextArea).value.substring(0, lLimitNum);
	} 
}


function jsf_GetSelectBoxOption_Description(sSelectBox)
{	//This function returns the description aspect of the specified selectbox
	return document.getElementById(sSelectBox).options(document.getElementById(sSelectBox).selectedIndex).text;
}

function jsf_GetSelectBoxOption_Value(sSelectBox)
{	//This function returns the value aspect of the specified selectbox
	return document.getElementById(sSelectBox).options(document.getElementById(sSelectBox).selectedIndex).value;
}

function jsf_OpenImageWindow_TypeSpecific(lObjImageID, lImgTypeID) {
//This opens the view image page and forces the specified image type
var sfeatures, surl;

	sfeatures="'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=900, height=600";
	surl="./imgobj_viewimage.asp?ObjImageID="+lObjImageID + "&ImgTypeID=" + lImgTypeID;	
	window.open(surl, 'ViewImage', sfeatures).focus();

}

function jsf_DownloadImageWindow(lImgID) {
//This function opens the download image window based on the specified lIMGID
var sfeatures, surl;

	sfeatures="'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=900, height=600";
	surl="./imgobj_downloadresource.asp?ImgID="+lImgID;

	window.location.href=surl;

}

function jsf_OpenImageWindow(lImgID) {
//This function opens the image view window based on the specified lIMGID
var sfeatures, surl;

	sfeatures="'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=900, height=600";
	surl="./imgobj_viewimage.asp?ImgID="+lImgID;
	window.open(surl, 'ViewImage', sfeatures).focus();

}

function jsf_OpenShockwaveWindow(lImgID) {
//This function opens the shockwave view window based on the specified lIMGID
var sfeatures, surl;

	sfeatures="'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=900, height=600";
	surl="./imgobj_viewshockwave.asp?ImgID="+lImgID;
	window.open(surl, 'PreviewShockwave', sfeatures).focus();

}

function jsf_OpenCalendarWindow(oObjectID) {
//This function opens the calendar view window
var sfeatures, surl;

	sfeatures="'toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=200, height=200";
	surl="./cal_displaycalendar.asp?objectid="+ oObjectID;
	window.open(surl, 'Calendar', sfeatures).focus();

}

function jsf_LibraryObjectQuickView(lObjID) {
//This function opens a library item quick view window
var sfeatures, surl;

	sfeatures="'toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=620, height=480";
	surl="./libobj_viewobject.asp?objid="+lObjID;
	window.open(surl, 'ItemViewer', sfeatures).focus();
}

function jsf_LibraryObjectPopUp(oPostbackID) {
//This function opens a library item picker window
var sfeatures, surl;

	sfeatures="'toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=620, height=480";
	surl="./libobj_popup.asp?postbackid="+oPostbackID;
	window.open(surl, 'ItemPopup', sfeatures).focus();
}

function jsf_PopStandardImageWindow(sWindowTitle, sURLAddress) {
//This function opens a standard image window
var sfeatures, surl;

	sfeatures="'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=510, height=530";
	surl=sURLAddress;
	window.open(surl, sWindowTitle, sfeatures).focus();
	
	//*another method
	//var moviewin = window.open(trailer, name, "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=" + width + ",height="+height);
	//moviewin.focus();
	
}

function jsf_PopContactPaymentWindow(sWindowTitle, sURLAddress) {
//This function opens a standard credit card payment window
var sfeatures, surl;

	sfeatures="'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=400, height=300";
	surl=sURLAddress;
	window.open(surl, sWindowTitle, sfeatures).focus();
}

function jsf_PopDispatchNoteWindow(lDispatchID) {
//This function opens a printable dispatch note window
var sfeatures, surl;

	sfeatures="'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=800, height=600";
	surl="../ctord_popdispatchnote.asp?dispatchid="+lDispatchID;
	window.open(surl, 'WarehouseDispatchNote', sfeatures).focus();
}

function jsf_GetBackgroundColour() {
//This function returns the current document background colour
	return document.bgColor;
}

function jsf_FocusObject(sObjID) {
//This function sets the specified HTML item as the one with focus
	
	document.getElementById(sObjID).select();	//Select the item
	document.getElementById(sObjID).focus();	//Set the focus on the item
	
}

function jsf_SetObjectColour(sObjID, sHexBGColour, sHexForeColour) {
//This function sets the specified HTML item using the colours specified (ensure colours start with #)

	document.getElementById(sObjID).style.backgroundColor=sHexBGColour;
	document.getElementById(sObjID).style.color=sHexForeColour;
	
}

function jsf_SetObjectBorder(sObjID, sHexBorderColour, sBorderWidth) {
//This function sets the specified HTML item to indicate a warning regarding it, the sHexColour should start with a (#)

	document.getElementById(sObjID).style.borderColor=sHexBorderColour;
	document.getElementById(sObjID).style.borderWidth=sBorderWidth
}

function jsf_IsNumeric(vValue) {
var ValidChars = "0123456789.";
var jsf_IsNumeric=true;
var Char;

	for (i = 0; i < vValue.length && jsf_IsNumeric == true; i++) { 
		Char = vValue.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) {
			jsf_IsNumeric = false;
		}
	}
   return jsf_IsNumeric;   
}

function jsf_RefreshPage(sFormName) {
//This function refreshes the current page and automatically reposts all the imformation specified by form	
var oForm, lObject, sAddr;

	sAddr=location.pathname;	//Create base address
	oForm=document.forms[sFormName];	//Create a link to the specified form based on the form specified
	
	if(oForm.elements.length>=0) {
		sAddr=sAddr + "?";	//Create initial element marker
	
		for(lObject=0; lObject<oForm.elements.length; lObject++) {	//Loop each element in the form
			sAddr=sAddr + oForm[lObject].name + "=" + jsf_URLEncode(oForm[lObject].value);
			
			//I have upgraded this function to encode the form value as I found an error when refreshing element containing & chars
			
			//Append the next html object
			if(lObject<((oForm.elements.length)-1)) {sAddr=sAddr + "&";}
		}
		
	}

	sAddr=sAddr + "&Refreshed=1";	//Add the refresh flag to the end of the compiled info	
	location.href=sAddr;	//Reload the page	
}

function jsf_CheckboxONOFFSwitch(oObject) {
//This is a function dynamically switches the specified checkbox value depending on the user clicking

	switch(oObject.checked) {
		case true:	
			oObject.value="on";
			break;
		case false:
			oObject.value="off";
			break;
	}		
}

function jsf_DisableElementSwitchFromCheckbox(sCheckboxID, sElementID) {
//This function sets the element disabled based on the checkbox
	
	switch(document.getElementById(sCheckboxID).value) {
		case "on":
			document.getElementById(sElementID).disabled=false;
			break;
			
		case "off":
			document.getElementById(sElementID).disabled=true;
			break;
	}

}

function jsf_DisableElementFromCheckbox(oCheckbox, sElementID) {
//This function sets the disabled value of the element specified
	switch(oCheckbox.value) {
		case 'on':	
			document.getElementById(sElementID).disabled="";
			break;
			
		case 'off':	
			document.getElementById(sElementID).disabled="true";
			break;
	}
}

function jsf_DisplayConfirmation(sMessage) {
//This function displays an confirmation box if the sMessage contains string data

	if(sMessage.length>0) {
		if(confirm(sMessage)==true) {
		}
		else {
			//Go back to the previous page
			history.back();
		}
	}
}

function jsf_RightClick_IE() {
//This function is used to suppress the right mouse click in an IE browser window
	if (event.button == 2) {
		alert(message);
		return false;
	}
}

function jsf_RightClick_NS(e) {
//This function is used to suppress the right mouse click in an Netscape browser window
	if (document.layers || document.getElementById&&!document.all) {
		if (e.which == 2 || e.which == 3) {
			alert(message);
			return false;
		}
	}
}

//These are automatic functions execute during the page load event

if(jsf_bSuppressRightButton == 1) {
	if (document.layers) {
		document.captureEvents(Event.MOUSEDOWN);
		document.onmousedown = jsf_RightClick_NS;
	}
	else if (document.all && !document.getElementById) {
		document.onmousedown = jsf_RightClick_IE;
	}

	//Set the function handle
	document.oncontextmenu = new Function("alert(jsf_sRestricted_Message); return false")
}

function jsf_DeleteCookie(sName) {
//Remove a cookie by setting its expiry date to the passed

	jsf_SetCookie(sName,"-1", -1);

}

function jsf_SetCookie(sName, vValue, lDays) {
//Set a cookie that will expire in lDays
var dToday = new Date();
var dExpire = new Date();

	if (lDays==null || lDays==0) {
		lDays=1;
	}

	dExpire.setTime(dToday.getTime() + 3600000*24 * lDays);
	document.cookie = sName+"="+escape(vValue) + ";expires="+dExpire.toGMTString();
}

function jsf_ReadCookie(sName) {
//To read a cookie
var sCookie=""+document.cookie;
var ind=sCookie.indexOf(sName);
var ind1=sCookie.indexOf(';',ind);

	if (ind==-1 || sName=="") {
		return "";
	}
	
	if (ind1==-1) {
		ind1=sCookie.length;
	}

	return unescape(sCookie.substring(ind+sName.length+1,ind1));
}

function jsf_CookiesActive() {
//This tests whether cookies are active on the users browser, returns 0 if disabled
var lStatus=0;

	jsf_SetCookie('ActiveTest', 1);
	if(jsf_ReadCookie('ActiveTest')==1) {
		lStatus=1;
		
		jsf_DeleteCookie('ActiveTest');	//Delete the test
	}
	
	return lStatus;
}

function jsf_CopyElementContent(sSourceElement, sDestinationElement) {
//This function copies the content of the source element into the destination element
var sContent;

	sContent=document.getElementById(sSourceElement).value;

	if(sContent.length>0) {
		document.getElementById(sDestinationElement).value=sContent;
	} else {
		alert('Sorry, no previous information entered');
	}
}

function jsf_SetElementContent(sElement, vValue) {
//This function sets the specified element to the value

	document.getElementById(sElement).value=vValue;

}

//-->