﻿/* 
NAME:		Core JavaScript Tools v1.00
PURPOSE:	JavaScript routines that are common to multiple projects (copyright cannot be given to client)
AUTHOR:		Julian Madle for Future Shock
MODIFIED:	06 July 2006, copyright 2005 (c) Future Shock Ltd

This file is property of Future Shock, it is NOT public code - unauthorised use is breach of copyright.
*/

function XMLHTTP(TransferMode,URL,POSTdata) {
	if (window.ActiveXObject) {xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")}
	else if (window.XMLHttpRequest) {xmlhttp=new XMLHttpRequest()}
	if (xmlhttp) {
		//alert(URL);
		xmlhttp.open(TransferMode,URL,false);
		xmlhttp.send(POSTdata);
		return xmlhttp.responseXML;
		}
	}

function CheckString(FormField,AllowBlank,MaxLength) {
	// MaxLength is optional, when not provided the string is only checked for being blank.
	if ((AllowBlank==false) && (FormField.value=="")) {alert(FormField.title + " cannot be blank"); FormField.focus(); return false}
	if ((MaxLength!="") && (FormField.value.length>MaxLength)) {alert(FormField.title + " must be no more than " + MaxLength + " characters long"); FormField.focus(); return false}
	return true;
	}

function CheckNumber(FormField,AllowBlank,PositiveOnly,IntegerOnly) {
	// AllowBlank, PositiveOnly, and IntegerOnly are optional
	if (isNaN(FormField.value)) {alert(FormField.title + " must be a number"); FormField.focus(); return false}
	if ((AllowBlank==false) && (FormField.value=="")) {alert(FormField.title + " cannot be blank"); FormField.focus(); return false}
	if ((PositiveOnly) && (FormField.value<0)) {alert(FormField.title + " cannot be negative"); FormField.focus(); return false}
	if ((IntegerOnly) && (FormField.value.indexOf(".")>-1)) {alert(FormField.title + " cannot contain a decimal point"); FormField.focus(); return false}
	return true;
	}

function PopUp(NextPage,width,height,resizable,scrollbars,status) {
	// resizable,scrollbars, and status are optional, when not provided these default to no.
	if (resizable=="") {resizable="no"}
	if (scrollbars=="") {scrollbars="no"}
	if (status=="") {status="no"}
	x=self.screenLeft + 10;
	y=self.screenTop + 10;
	if (navigator.appVersion.indexOf("AOL")>0) {winName="A" + (Math.round(Math.random() * 1000))} else {winName="FSpopUpWindow"}
	FSpopUp=window.open(NextPage,winName,'toolbar=no,width=' + width + ',height=' + height + ',left=' + x + ',screenX=' + x + ',top=' + y + ',screenY=' + y + ',status=' + status + ',scrollbars=' + scrollbars + ',resizable=' + resizable + ',menubar=no,directories=no');
	}

function setChanged(FormRef,TID) {if (FormRef.Changedlist.value.indexOf("," + TID + ",")==-1) {FormRef.Changedlist.value+=TID + ","}}

function removeOptions(SelectRef) {SelectRef.options.length=0}

function addOption(SelectRef,TheText,TheValue) {SelectRef.options[SelectRef.options.length] = new Option(TheText,TheValue)}

function makeID(AssetType,AssetID) {
	var PaddedID=AssetID;
	while (PaddedID.length<7) {PaddedID="0" + PaddedID}
	return AssetType + PaddedID;
	}
