function init() {
centralise('main');
}
function focusForm(){
if(!document.forms){
return;
}
if(document.forms.length<1){
return;
}
document.forms[0].elements[0].focus();
}
function message(message){
alert(message);
}
function decision(message, url){
if(confirm(message)) location.href = url;
}
function navigateTo(url){
location.href = url;
}
function colourChooser(div_id, colour, formName){
var myElement = document.getElementById(div_id);
var myElementText = document.getElementById('colourHex');
myElementText.innerHTML = colour;
myElement.style.backgroundColor = colour;
eval("document." + formName+ ".hidden_colour.value = colour;");
}
function clearForm(formName){
var element;
var elementCount;
eval("elementCount=" + formName + ".length;")
for (var i = 0; i < elementCount; i++)
{
eval("element=" + formName + ".elements[i];")
if (element.type == "text" || element.type == "textarea")
{
element.value='';
}
}
}
function submitForm(formName,qString,actionURL,encType){
if (typeof(actionURL) != 'undefined')
{
eval("document." + formName + ".action = actionURL;")
}
if (typeof(encType) != 'undefined')
{
eval("document." + formName + ".encoding = encType;")
}
if (typeof(qString) == 'undefined')
{
eval("document." + formName+ ".submit();");
}
else
{
eval("document." + formName + ".action = document." + formName + ".action + qString;")
eval("document." + formName + ".submit();")
}
}
function addBookmark(url,title){
window.external.AddFavorite(url,title);
}
function placeValue(string,formField,formName){
eval("document." + formName+ "." + formField + ".value = string;");
}
function changeString(div_id,string){
var myElementText = document.getElementById(div_id);
myElementText.innerHTML = string;
}
function focusField(formName,formField){
eval("element=document." + formName + "." + formField +";")
element.focus();
}
function changeZIndex(div_id,zindex){
var myElement = document.getElementById(div_id);
myElement.style.zIndex = 10;
}
function focusForm(formName){
eval("element=document." + formName + ";")
element.focus();
}
function checkForm(formName,qString,actionURL,encType)
{
var boxesFound = 0;
var boxesChecked = 0;
var elementCount;
var element;
returnval=true;
eval("elementCount=" + formName + ".length;")
for (var j = 0; j < elementCount; j++)
{
eval("element=" + formName + ".elements[j];")
indx = element.name.indexOf('_required');
if (indx != -1)
{
fieldname=element.name.substring(0,indx);
eval("element2=" + formName + ".elements[fieldname];")
if (element2.value.length == 0)
{
alert(element.value);
j = (elementCount);
if (element2.type != "hidden"){
element2.focus();
}
returnval = false;
}
}
indx = element.name.indexOf('_checkbox');
if (indx != -1)
{
boxesFound ++;
if (element.checked)
{
boxesChecked ++;
}
}
indx = element.name.indexOf('_number');
if (indx != -1)
{
fieldname=element.name.substring(0,indx);
eval("element2=" + formName + ".elements[fieldname];")
if (isNaN(parseInt(element2.value))==true && element2.value.length!=0)
{
alert(element.value);
j = (elementCount);
if (element2.type != "hidden"){
element2.focus();
}
returnval = false;
}
}
indx = element.name.indexOf('_integer');
if (indx != -1)
{
fieldname=element.name.substring(0,indx);
eval("element2=" + formName + ".elements[fieldname];")
if (parseInt(element2.value) > 999)
{
alert(element.value);
j = (elementCount);
if (element2.type != "hidden"){
element2.focus();
}
returnval = false;
}
}
indx = element.name.indexOf('_postcode');
if (indx != -1)
{
fieldname=element.name.substring(0,indx);
eval("element2=" + formName + ".elements[fieldname];")
if (postcodeValidate(fieldname)==false && element2.value.length!=0)
{
alert(element.value);
j = (elementCount);
if (element2.type != "hidden"){
element2.focus();
}
returnval = false;
}
}
function postcodeValidate(strFieldName) {
var strInput;
eval ('strInput=' + formName + '.' + strFieldName + '.value')
if (strInput=='') {
return (true);
}
var j;
var blnOutPre = (false);
var blnOutSuf = (false);
var strOutPrefix = '';
var strOutSuffix = '';
var strInDigit = '';
var strInChars ='';
var blnValid = (true);
strInput = toAlNum(strInput);
for (j=0;j<strInput.length;j++) {
if (blnOutPre==false) {
if (j==0 && isNaN(strInput.charAt(j))==false) {
blnValid = (false);
}
if (j>1 && isNaN(strInput.charAt(j))) {
blnValid = (false);
}
if (isNaN(strInput.charAt(j))==false) {
blnOutPre = (true);
} else {
strOutPrefix = strOutPrefix + strInput.charAt(j);
}
}
if (blnOutPre && blnOutSuf==false) {
if (strOutSuffix.length > 2) blnValid = (false);
if (j < (strInput.length - 3)) {
strOutSuffix = strOutSuffix + strInput.charAt(j);
} else {
blnOutSuf = (true);
}
}
if (blnOutSuf) {
if (isNaN(strInput.charAt(j)) && strInput.charAt(j).toUpperCase()!='O') blnValid = (false);
if(strInput.charAt(j).toUpperCase()=='O') {
strInDigit = '0';
} else {
strInDigit = strInput.charAt(j);
}
if (isNaN(strInput.charAt(j+1))==false || isNaN(strInput.charAt(j+2))==false) blnValid = (false);
strInChars = strInput.charAt(j+1) + strInput.charAt(j+2);
if (blnValid) {
eval('document.' + formName + '.' + strFieldName + '.value="' + strOutPrefix.toUpperCase() + strOutSuffix.toUpperCase() + ' ' + strInDigit + strInChars.toUpperCase() + '";');
return (true);
}
}
}
return (false);
}
indx = element.name.indexOf('_hex');
if (indx != -1)
{
fieldname=element.name.substring(0,indx);
eval("element2=" + formName + ".elements[fieldname];")
if (isHex(element2.value)==false && element2.value.length!=0)
{
alert(element.value);
j = (elementCount);
if (element2.type != "hidden"){
element2.focus();
}
returnval = false;
}
}
}
if (boxesFound > 0 && boxesChecked < 1)
{
alert('You must choose at least one Check Box.'); returnval = false;
} 
if (returnval == true){
submitForm(formName,qString,actionURL,encType);indx = element.name.indexOf('submitButton');
if (indx != -1)
{
disableButton(formName);
}
}
}
function isHex(string){
var hexchars = "0123456789ABCDEFabcdef";
for (var i=0; i< string.length; i++){
if (hexchars.indexOf(string.charAt(i)) == -1) {
return false;
}
}
return true;
}
function dom_check(){
if (document.getElementById)
dom='yes'
//alert("DOM compliant!");
else
dom='no'
location.href='non_dom.asp';
}
function centralise(div_id) {
var innerWidth = window.innerWidth?1:0
var myElement = document.getElementById(div_id);
var box_left, box_top, schMarginHeight, schContentWidth, magic_offset, screen_width;
schContentWidth = 760;
schMarginHeight = 8;
if(innerWidth==1) {
screen_width = window.innerWidth
} else {
screen_width = document.body.clientWidth
}
if ((screen_width)-(schMarginHeight*2)<=schContentWidth){
box_left = schMarginHeight;
} else {
box_left = (screen_width-schContentWidth)/2;
}
myElement.style.left = box_left + "px";
myElement.style.top = schMarginHeight + "px";
myElement.style.width = schContentWidth +"px";
//myElement.style.height = box_height + "px";
}
function changecolor(div_id, action){
var myElement = document.getElementById(div_id);
if (action=='nav_on'){
myElement.style.backgroundColor = '#CCFFFF';
myElement.style.color = '#707070';
} else {
myElement.style.backgroundColor = '#FCFCFC';
myElement.style.color = '#707070';
}
}
function makevisible(div_id){
var myElement = document.getElementById(div_id);
myElement.style.visibility = 'visible';
}
function itemMouseOver(itemID, action) {
for(i=0;i<array.length;i++) {
if(array[i][0]==itemID) {
if(array[i][2]!='') {
changevisibility(action,array[i][2]);
}
if(array[i][1]!='idN0') {
if(action=='hide') {
changecolor(array[i][1],'nav_off');
} else {
changecolor(array[i][1],'nav_on');
}
itemMouseOver(array[i][1],action);
}
}
}
}
function changevisibility(status,values){
var value_array = values.split("~");
for (loop=0; loop < value_array.length;loop++)
{
var myElement = document.getElementById(value_array[loop]);
if (status == 'hide') {
myElement.style.visibility = 'hidden';
}
else {
myElement.style.visibility = 'visible';
}
}
}
function togglevisibility(div_id){
var myElement = document.getElementById(div_id);
if (myElement.style.visibility == 'visible' | myElement.style.visibility == '')
{
myElement.style.visibility = 'hidden';
}
else {
myElement.style.visibility = 'visible';
}
}
function openWindow(url,window_name,width,height){
width=400;
height=400;
var options='';
options='menubar=1,toolbar=1,location=1,statusbar=1,scrollbars=1,resizable=1,width='+ width +',height='+ height;
window.open(url,name,options);
}
function closeWindow(name){
window.close(name);}
function toggleHighLight(div_id){
var myElement = document.getElementById(div_id);
if (myElement.style.backgroundColor == '#eef3fc')
{
myElement.style.backgroundColor = '';
}
else {
myElement.style.backgroundColor = '#eef3fc';
}
}
function toggleHighLightMini(div_id){
var myElement = document.getElementById(div_id);
if (myElement.style.backgroundColor == '#1042ce')
{
myElement.style.backgroundColor = '#f0953f';
}
else {
myElement.style.backgroundColor = '#1042ce';
}
}
function check(div_id){
var myElement = document.getElementById(div_id);
var l = myElement.style.left;
var t = myElement.style.top;
var w = myElement.style.width;
var h = myElement.style.height;
alert("Position is: left " + l + ", top " + t + ", width " + w +", height "  + h);
}
function disableButton(formName){
var buttonLocation = eval(formName + ".submitButton");
buttonLocation.disabled = true;
buttonLocation.value = '... Please wait...';
}
function toAlNum(strInput) {
var strOutput;
strOutput = '';
for (j=0;j<strInput.length;j++) {
if((strInput.charCodeAt(j) > 47 && strInput.charCodeAt(j) < 58) || (strInput.charCodeAt(j) > 64 && strInput.charCodeAt(j) < 91) || (strInput.charCodeAt(j) > 96 && strInput.charCodeAt(j) < 123)) strOutput = strOutput + strInput.charAt(j);
}
return strOutput;
}
function radio_onMouseDown (formName,str_name) {
eval('blnChecked = ' + formName + '.' + str_name + '.checked;');
}
function radio_onClick (formName,str_name) {
if(blnChecked) {
eval(formName + '.' + str_name + '.checked=false;');
}
}
function getSelected(formName,selectName) {
var selected = eval(formName + '.' + selectName + '.value;');
if(selected =='') {
alert('You must choose an option from the drop down box');
return false;
}
else {
return selected;
}
}
function limitTextArea(formName,field,max) {
eval('textLen = ' + formName + '.' + field + '.value.length;');
eval('textValue = ' + formName + '.' + field + '.value;');
if (textLen > max)
{
alert('You may only use ' + max + ' characters in this text area.');
eval("document." + formName + "." + field + ".value = textValue.substring(0, max-1);");
return false;
}
else {
return true;
}
}

function stockAlert(stockAlertBool, secureserver, usrID) {
if(stockAlertBool == 1)
{
alert('Some or all of the products in your basket are out of stock and will be put on back order.\nYou will not be charged for the B/O items until they are sent.');
}
navigateTo(secureserver + 'check_out.asp?event=check_address&usrID=' + usrID);
}

function KeyDownHandler(btn)
{
// process only the Enter key
if (event.keyCode == 13)
{
// cancel the default submit
event.returnValue=false;
event.cancel = true;
// submit the form by programmatically clicking the specified button
btn.click();
}
}


