/**************************************************************

  Created for Fletcher Aluminium by Shane Jenner
  
  Copyright (C) 2001-2003, 2007 by Fletcher Aluminium, Shane Jenner.
  All rights reserved.
  
**************************************************************/

//------------------------------------------------------------------------------------
function IsEmail(Email) 
{
	var a;
	var b;
	var c;
	var d;
	var p;
	var e;
	var f;
	var g;
	var h;
	var u;
	var k;
	var j;
	var l;
	var m;
	var n;
	var o;
	 
	a = Email.lastIndexOf("@");
	b = Email.lastIndexOf(".");
	c = Email.indexOf(":");
	d = Email.indexOf("/");
	p = Email.indexOf(" ");
	e = Email.substring(0, a);
	f = e.indexOf("@");
	g = Email.substring(a + 1, Email.length);
	h = g.indexOf("[");
	i = g.indexOf("]");
	j = g.indexOf("<");
	k = g.indexOf(">");
	l = Email.substring(a + 1, b);
	m = Email.substring(b + 1, Email.length);
	n = Email.substring(0, a);
	o = 0;
	
	if ( a > b || c != -1 || d != -1 || f != -1 || h != -1 || i != -1 || j != -1 || k != -1)
		o++;
	if (l.length < 3 || m.length < 2 || n.length < 1)
		o++;
	if (p >= 0 || o != 0)
	{
		return false;
	}
	return true;
}
//------------------------------------------------------------------------------------
function printContent(id)
{
	str=document.getElementById(id).innerHTML
	newwin=window.open('','printwin','scrollbars=auto,left=100,top=100,width=700,height=200')
	newwin.document.write('<link rel="stylesheet" type="text/css" href="include/stylesheet.css">')
	newwin.document.write('<HTML>\n<HEAD>\n')
	newwin.document.write('<TITLE>Print Page</TITLE>\n')
	newwin.document.write('<script>\n')
	newwin.document.write('function print_win(){\n')
	newwin.document.write('window.print();\n')
	newwin.document.write('}\n')
	newwin.document.write('<\/script>\n')
	newwin.document.write('</HEAD>\n')
	newwin.document.write('<BODY onload="print_win()">\n')
	newwin.document.write(str)
	newwin.document.write('</BODY>\n')
	newwin.document.write('</HTML>\n')
	newwin.document.close()
}

//used by function IsDate
function Strip_CharsInBag(s, bag)
{
	var i;
    var returnString = "";
    //search through string's characters one by one.
    //if character is not in bag, append to returnString.
    for (i=0; i<s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1)
			returnString += c;
    }
    return returnString;
}
//------------------------------------------------------------------------------------

//used by function IsDate
function DaysInFebruary (year)
{
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
//------------------------------------------------------------------------------------

//used by function IsDate
function DaysArray(n) 
{
	for (var i = 1; i <= n; i++) 
	{
		this[i] = 31;
		if (i == 4 || i == 6 || i == 9 || i == 11)
			this[i] = 30;
		if (i == 2) 
			this[i] = 29;
	} 
	return this;
}
//------------------------------------------------------------------------------------

function IsDate(dtStr)
{
	//constants
	var dtCh= "/";
	var minYear=1990;
	var maxYear=2010;

	var daysInMonth = DaysArray(12);
	var pos1 = dtStr.indexOf(dtCh);
	var pos2 = dtStr.indexOf(dtCh, pos1 + 1);
	var strDay = dtStr.substring(0, pos1);
	var strMonth = dtStr.substring(pos1 + 1, pos2);
	var strYear = dtStr.substring(pos2 + 1);
	
	strYr = strYear;
	
	if (strDay.charAt(0) == "0" && strDay.length > 1) 
		strDay = strDay.substring(1);
	if (strMonth.charAt(0) == "0" && strMonth.length > 1) 
		strMonth = strMonth.substring(1);
	for (var i = 1; i <= 3; i++)
	{
		if (strYr.charAt(0) == "0" && strYr.length > 1) strYr = strYr.substring(1);
	}
	
	month = parseInt(strMonth);
	day = parseInt(strDay);
	year = parseInt(strYr);
	
	if (pos1 == -1 || pos2 == -1)
		return false;
	if (strMonth.length < 1 || month < 1 || month > 12)
		return false;
	if (strDay.length < 1 || day < 1 || day > 31 || (month == 2 && day > DaysInFebruary(year)) || day > daysInMonth[month])
		return false;
	if (strYear.length != 4 || year == 0 || year < minYear || year > maxYear)
		return false;
	if (dtStr.indexOf(dtCh, pos2 + 1)!= -1 || !IsNotOtherThan(Strip_CharsInBag(dtStr, dtCh), "0123456789"))
		return false;
	return true;
}
//------------------------------------------------------------------------------------

//performs validation of numbers
function IsNotOtherThan(String1, String2)
{
	for(i = 0; i < String1.length; i++)
	{
		if (String2.indexOf(String1.charAt(i)) == -1)
			return false;
	}   
	return true;	
}
//------------------------------------------------------------------------------------

function FMRCreate_Submit_Click()
{
	if (document.frmFMRCreate_3.realFMRPartCount.value == 0)
	{
		alert("The FMR can't be submitted at this time as it contains zero (0) faulty parts.");
		return false;
	}
	return (confirm("Have you completed everything on the FMR, checked it and are ready to submit to Customer Services?"))
}
//------------------------------------------------------------------------------------

//load the parts information, such as colour, on select from 'fmr.add.part.asp'
function FMRAddPart_PartNoList_Change() 
{
	var partNo;
	
	partNo = document.frmFMRAddPart.partNoList.value;
	
	document.location = "fmr.add.part.asp?" + partNo;
}
//------------------------------------------------------------------------------------

//validate conditions to add or remove a part from an FMR, 'fmr.create.asp'
function FMRCreate_AddDelete_Click(Button) 
{
	var entirePartCount;
	var realFMRPartCount;
	var checked;
	var i;
	var err;
	
	entirePartCount = document.frmFMRCreate_3.entirePartCount.value;
	realFMRPartCount = document.frmFMRCreate_3.realFMRPartCount.value;
	err = "";
	
	if (Button == "Add")
	{
		if (realFMRPartCount == entirePartCount)
			err += ("\n* All of the available items have already been added.")
	}
	else if (Button == "Remove")
	{
		if (realFMRPartCount == 0)
			err += ("\n* There are no items on this FMR to remove.");
		else
		{
			if (realFMRPartCount == 1)
			{
				if (document.frmFMRCreate_2.fmrPartList.checked)
					checked = true;
			}
			else
			{
				for(i=0; i<realFMRPartCount; i++)
				{
				
					if (document.frmFMRCreate_2.fmrPartList[i].checked)
						checked = true;
				}
			}
			if (checked != true) 
				err += ("\n* You have not selected an item to remove.");
		}
	}
	return ErrResult(err);
}
//------------------------------------------------------------------------------------

function FMRCreate_Cancel_Click() 
{
	return confirm("Do you really want to cancel this FMR?");
}
//------------------------------------------------------------------------------------

//make sure all fields are filled out correctly on 'fmr.add.part.asp'
function FMRAddPart_Submit_Click()
{
	var numbers;
	var quantityOrdered;
	var quantityCredited;
	var Add_Zero_Count;
	var faultCount;
	var i;
	var transitSelected;
	var packMethodChecked;
	var packDamageChecked;
	var faultNo;
	var err;
	
	numbers = "1234567890";
	quantityCredited = document.frmFMRAddPart_2.quantityCredited.value;
	quantityOrdered = document.frmFMRAddPart_2.quantityOrdered.value;
	faultCount = document.frmFMRAddPart_2.faultCount.value;
	err = "";
	
	if (document.frmFMRAddPart.partNoList.selectedIndex == 0)
		err += ("\n* You must select the faulty item no.");
	if (quantityCredited.length == 0)
		err += ("\n* Please enter the faulty quantity.")
	//if (quantityCredited.indexOf(" ") != -1)
	//	err += ("\n* The faulty quantity cannot contain spaces.");
	for(i = 0; i < quantityCredited.length; i++)
	{
		if (numbers.indexOf(quantityCredited.charAt(i))==-1)
		{
			err += ("\n* The faulty quantity can only contain numeric digits.");
			break;
		}
	}
	//make the ordered and replacement lengths the same for comparison
	addZeroCount = quantityOrdered.length - quantityCredited.length;
	for(i = 0; i < addZeroCount; i++)
		quantityCredited = "0" + quantityCredited;
	addZeroCount = quantityCredited.length - quantityOrdered.length;
	for(i = 0; i < addZeroCount; i++)
		quantityOrdered = "0" + quantityOrdered;
	if (quantityCredited > quantityOrdered)
		err += ("\n* The faulty quantity cannot be greater than the quantity delivered.");
	if (gblFaultCount == 0)
		err += ("\n* You must indicate at least one fault with the item.")
	//find out if any transit faults are selected
	for(i=1; i<=faultCount; i++)
	{
		faultNo = "Fault" + i;
		if (document.frmFMRAddPart_2[faultNo].value.substring(5, 6) == 'T' && document.frmFMRAddPart_2[faultNo].checked)
			transitSelected = true;
	}
	//require at least one radio button from each packing error be selected if there is a transit fault
	if (transitSelected)
	{
		if (document.frmFMRAddPart_2.packMethod[0].checked || document.frmFMRAddPart_2.packMethod[1].checked || document.frmFMRAddPart_2.packMethod[2].checked)
			packMethodChecked = true;
		if (document.frmFMRAddPart_2.packDamage[0].checked || document.frmFMRAddPart_2.packDamage[1].checked)
			packDamageChecked = true;
		if (packMethodChecked != true || packDamageChecked != true)
			err += ("\n* As this item has a transit fault you must indicate the packaging and if the damage was recorded on the P.O.D.");	
	}
	if (ErrResult(err))
		document.frmFMRAddPart_2.submit();
}
//------------------------------------------------------------------------------------

//globals for counting faults
var gblFaultCount;
gblFaultCount = 0;

//restict the maximum number of faults that can be selected on 'fmr.add.part.asp'
function FMRAddPart_Fault_Click(faultNo, maxFaults)
{
	var transitSelected;
	var faultCount;
	var i;
	
	if (document.frmFMRAddPart_2[faultNo].checked)
		gblFaultCount = gblFaultCount + 1;
	else if (!document.frmFMRAddPart_2[faultNo].checked)
		gblFaultCount = gblFaultCount - 1;
	if (gblFaultCount > maxFaults)
	{
		alert("The number of maximum faults per item is " + maxFaults + ". The last fault will be unchecked.")
		document.frmFMRAddPart_2[faultNo].checked=false;
		gblFaultCount = gblFaultCount - 1;
	}
	faultCount = document.getElementById("faultCount").value;
	
	//find out if any transit faults are checked
	for(i=1; i<=faultCount; i++)
	{
		if (document.getElementById("fault" + i).value.substring(5, 6) == 'T' && document.getElementById("fault" + i).checked)
			transitSelected = true;
	}
	if (transitSelected)
		document.getElementById("transitClaim").style.display = 'block';
	else
		document.getElementById("transitClaim").style.display = 'none';
}
//------------------------------------------------------------------------------------

//make sure that only certain options are selected if there is a transit fault, 'fmr.add.part.asp'
/*
function FMRAddPart_Packing_Click()
{
	var faultCount;
	var faultNo;
	
	faultCount = document.frmFMRAddPart_2.faultCount.value;
	for(i=1; i<=faultCount; i++)
	{
		faultNo = "Fault" + i;
		if (document.frmFMRAddPart_2[faultNo].value.substring(5, 6) == 'T' && document.frmFMRAddPart_2[faultNo].checked)
			return true;
	}
	alert("You can only select this option of your part has a transit fault.\nThis option will be removed.")
	return false;
}
*/
//------------------------------------------------------------------------------------

function ProcessFMR(action)
{
	var newOrderNo;
	var fmrNo;
	var err;
	var reason;
	var fmrValue
	
	fmrNo = document.frmFMRView.fmrNo.value;
	
	if (action == 'qaAccept')
	{
	    if (confirm("Are you sure you want to accept the FMR?"))
    	    document.location = "fmr.process.asp?fmrNo=" + fmrNo + "&qaAccept=1";
	}
	else if (action == 'qaDecline')
	{
    	if (confirm("Are you sure you want to decline? You will be prompted to enter a reason."))
		{
			do
			{
			    err = "";
			    reason = prompt("Enter a brief reason for declining :-", "");
			    if (reason == "")
					err += ("\n* You must enter the reason for declining the FMR.");
			    else if (reason != null)
					document.location = "fmr.process.asp?fmrNo=" + fmrNo + "&qaDecline=1&reason=" + reason;
			}
			while(!ErrResult(err))
	    }
	}
	else if (action == 'acceptC')
	{
		fmrValue = document.getElementById('totalNetFMRValue').value
		if (confirm("Are you sure you want to accept the FMR and issue a credit of $ " + fmrValue + "?"))
			document.location = "fmr.process.asp?fmrNo=" + fmrNo + "&acceptC=1&fmrValue=" + fmrValue;
	}
	else if (action == 'acceptR')
	{
		do
	    {
		    err = "";
		    newOrderNo = prompt("Enter the replacement order number or enter \'0\' if it is for components :-", "");
		    if (newOrderNo == null)
			    return false;
		    if (newOrderNo != "")
		    {
			    if (newOrderNo != 0 && newOrderNo.length != 10)
			    {
				    err += ("\n* The order no. must be either the number 0 (for components) or 10 digits.");
			    }
			    else if (IsNotOtherThan(newOrderNo, "0123456789"))
			    {
				    document.location = "fmr.process.asp?fmrNo=" + fmrNo + "&acceptR=1&newOrderNo=" + newOrderNo;
			    }
			    else
				    err += ("\n* The order no. can only contain numeric digits.");
		    }
		    else
			    err += ("\n* You must enter the replacement order number in order to accept the FMR.");
	    }
	    while(!ErrResult(err))
    }
    else if (action == 'decline')
	{
	    if (confirm("Are you sure you want to decline the FMR?"))
    	    document.location = "fmr.process.asp?fmrNo=" + fmrNo + "&decline=1";
	}
	else if (action == 'check')
	{
	    if (confirm("Are you sure you want to mark the FMR as processing?"))
		    document.location = "fmr.process.asp?fmrNo=" + fmrNo + "&check=1";
	}
//	else if (action == 'cancel')
//	{
//	    if (confirm("Are you sure you want to DELETE this FMR? Please note this is NOT the same as DECLINE."))
//    		document.location = "fmr.process.asp?fmrNo=" + fmrNo + "&cancel=True";
//	}
	else if (action == 'generateOrder')
	{
		if (confirm("This will create a replacement order in Movex. Do you want to continue?"))
		    document.location = "fmr.process.asp?fmrNo=" + fmrNo + "&generateOrder=1";
	}
	else if (action == 'reopen')
	{
		if (confirm("This will escalate the FMR to the appropriate business unit manager. Do you want to continue?"))
		{
			do
			{
			    err = "";
			    reason = prompt("Enter a brief reason for escalating :-", "");	    
			    if (reason == "")
					err += ("\n* You must enter the reason to escalate this FMR.");
				if (reason != null)
				    document.location = "fmr.process.asp?fmrNo=" + fmrNo + "&reopen=1&reason=" + reason;
			}
			while(!ErrResult(err))
	    }
	}	
}
//------------------------------------------------------------------------------------

//performs validation on the 'message.create.asp' page
function MessageCreate_Submit_Click()
{
	var contactName;
	var subject;
	var message;
	var err;
	
	contactName = document.frmMessageCreate.contactName.value;
	subject = document.frmMessageCreate.subject.value;
	message = document.frmMessageCreate.enquiry.value;
	err = "";
	
	if (contactName == "")
		err += ("\n* You must enter a contact name.");
	if (subject == "")
		err += ("\n* You must enter a subject for this message.")
	if (message == "")
		err += ("\n* The message cannot be blank.");
	
	return ErrResult(err);
}
//------------------------------------------------------------------------------------

//performs validation on the 'personal.info.asp' page
function PersonalInfo_Submit_Click()
{
	var name;
	var deliveryAddress;
	var postalAddress;
	var location;
	var email;
	var phone;
	var err;
		
	name = document.frmPersonalInfo.name.value;
	deliveryAddress = document.frmPersonalInfo.deliveryAddress.value;
	postalAddress = document.frmPersonalInfo.postalAddress.value;
	location = document.frmPersonalInfo.location.value;
	email = document.frmPersonalInfo.email.value;
	phone = document.frmPersonalInfo.phone.value;
	err = "";

	if (name == "")
		err += ("\n* Your company name cannot be blank.");
	if (deliveryAddress == "")
		err += ("\n* Your delivery address cannot be blank.");
	if (postalAddress == "")
		err += ("\n* Your postal address cannot be blank.");
	if (location == "")
		err += ("\n* Your location cannot be blank.");
	if (email != "")
	{
		if (!IsEmail(email))
		err += ("\n* Invalid email address.");
	}
	if (phone != "")
	{
		if (!IsNotOtherThan(phone, "1234567890 -()"))
			err += ("\n* The phone number can only contain numeric digits.");
	}
	return ErrResult(err);
}
//------------------------------------------------------------------------------------

//perform validation on the 'manage.software.asp' page
function ManageSoftware_Update(Button)
{
	var response;
	var softwareName;
	var version;
	var downloadY;
	var downloadN;
	var path;
	var pathHidden;
	var err;
	var cat;
	
	path = document.frmManageSoftware.path.value;
	softwareName = document.frmManageSoftware.softwareName.value;
	version = document.frmManageSoftware.version.value;
	downloadY = document.frmManageSoftware.download[0];
	downloadN = document.frmManageSoftware.download[1];
	pathHidden = document.frmManageSoftware.pathHidden.value;
	cat = document.frmManageSoftware.softwareCat.value;
	err = "";
	
	if (Button != "A")
	{
		if (document.frmManageSoftware.softwareList.selectedIndex == 0)
			err += ("\n* You must select an item of software first.");
	}
	if ((Button == "A" || Button == "U") && (document.frmManageSoftware.specific.value == false))
	{
		if (softwareName == "")
			err += ("\n* The name of the software cannot be blank.");
		if (version == "")
			err += ("\n* The software version cannot be blank.");
		if (!IsNotOtherThan(version, "0123456789.-/"))
			err += ("\n* This is an invalid software version.");
		if (cat == "")
			err += ("\n* Please indicate the software category.");
		if (!downloadY.checked && !downloadN.checked)
			err += ("\n* Please select if the file is available for download.");
	}
	if (Button == "A")
	{
		response = confirm("This will add information entered as a new item of software.\n\nDo you want to continue?");	
		if (document.frmManageSoftware.specific.value == true && document.frmManageSoftware.customerNo.selectedIndex == 0)
			err += ("\n* You must select which customer the file is for.");
		if ((downloadY.checked && path == "") || (document.frmManageSoftware.specific.value == true && path == ""))
			err += ("\n* You must select a file for uploading.");
	}
	else if (Button == "U")
	{
		response = confirm("This will update the information for this item of software.\n\nDo you want to continue?")
		{
			if (response && (downloadY.checked && pathHidden != "N/A") && path == "")
			{
				if (!confirm("Do you want to continue using the existing specified file for download, \'" + pathHidden + "\'? \nIf you want to update or change the file, click Cancel."))
				{
					if (path == "" && downloadY.checked)
					{
						alert ("Please click Browse, then select the file you want to upload.");
						return false;
					}
				}
			}
		}
	}
	else if (Button == "R")
		response = confirm("This will permanently remove this item of software.\n\nDo you want to continue?");
	if (response)
		return ErrResult(err);
	else
		return false;
}
//------------------------------------------------------------------------------------

function FMRAddPart_Credit_Click()
{	
	if (confirm("Are you sure want to apply for a credit on this item?"))
		return true;
	else
		document.frmFMRAddPart_2.creditOption[0].checked = true;
}
//------------------------------------------------------------------------------------

//makes sure that the maximum number of characters in textareas is not overrun causing sql errors
function CharsLeft(Form, MaxLength)
{	
    if (Form.enquiry.value.length > MaxLength) 
    { 
        Form.enquiry.value = Form.enquiry.value.substring(0, MaxLength);
	}
    Form.charsLeft.value = MaxLength - Form.enquiry.value.length;
}
//------------------------------------------------------------------------------------

//load the software information when the combo box is selected in 'manage.software.asp'
function ManageSoftware_SoftwareList_Change()
{
	var softwareNo;

	softwareNo = document.frmManageSoftware.softwareList.value;
	
	document.location = "manage.software.asp?softwareNo=" + softwareNo;
}
//------------------------------------------------------------------------------------

function ManageSoftware_Download_Click()
{
	if (document.frmManageSoftware.download[0].checked)
		document.frmManageSoftware.path.disabled = false;
	else
		document.frmManageSoftware.path.disabled = true;
}
//------------------------------------------------------------------------------------

function ManageHome_Submit_Click()
{
	var heading;
	var content;
	var err;
	
	heading = document.frmManageHome.heading.value;
	content = document.frmManageHome.content.value;
	err = "";
	
	if (content == "" && heading != "")
		err += ("\n* You must enter some content if you are entering a heading on the home page.");
	
	return ErrResult(err);
}
//------------------------------------------------------------------------------------

function ChangePassword_Submit_Click() 
{
	var oldPassword;
	var newPassword;
	var confirmPassword;
	var err;
	
	oldPassword = document.frmChangePassword.oldPassword.value.toLowerCase();
	newPassword = document.frmChangePassword.newPassword.value.toLowerCase();
	confirmPassword = document.frmChangePassword.confirmPassword.value.toLowerCase();
	err = "";
	
	if (oldPassword == "" || newPassword == ""|| confirmPassword == "")
		err += ("\n* You must enter your current password and a new password twice.");
	if (newPassword.length < 6)
		err += ("\n* Passwords must be a minimum of six (6) characters.");
	if (newPassword != confirmPassword)
		err += ("\n* Your new password and confirmation password do not match.");
	
	return ErrResult(err);
}
//------------------------------------------------------------------------------------

function Swap_ImageRestore() 
{ 
	var i;
	var x;
	var a;
	
	a = document.sr;
	
	for(i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++)
		x.src = x.oSrc;
}
//------------------------------------------------------------------------------------

function Preload_Images() 
{ 
	var d;
	var i;
	var j;
	var a;
	
	d = document;
	a = Preload_Images.arguments;
	
	if (d.images)
	{ 
		if (!d.p)
			d.p = new Array();
		j = d.p.length;
		for(i = 0; i < a.length; i++)
		{
			if (a[i].indexOf("#") != 0)
			{
				d.p[j] = new Image;
				d.p[j++].src = a[i];
			}
		}
	}
}
//------------------------------------------------------------------------------------

function Swap_Image()
{
	var i;
	var j;
	var x;
	var a;
	
	j = 0;
	a = Swap_Image.arguments;
	document.sr = new Array;
	
	for(i = 0; i < (a.length-2); i += 3)
	if ((x = Find_Obj(a[i])) != null)
	{
		document.sr[j++] = x;
		if (!x.oSrc)
			x.oSrc = x.src;
		x.src = a[i+2];
	}
}
//------------------------------------------------------------------------------------

function Find_Obj(n, d) 
{
	var p;
	var i;
	var x;
	
	d = document;
	
	if ((p = n.indexOf("?")) > 0 && parent.frames.length)
	{
		d=parent.frames[n.substring(p+1)].document;
		n=n.substring(0,p);
	}
	if (!(x = d[n]) && d.all)
		x = d.all[n]; 
	for (i = 0; !x && i < d.forms.length; i++)
		x = d.forms[i][n];
	for(i = 0; !x && d.layers && i < d.layers.length; i++)
		x = FindObj(n, d.layers[i].document); 
	return x;
}
//------------------------------------------------------------------------------------

function ErrResult(err)
{
	if (err != "")
	{
		err = ("The following error(s) occured:") + err;
		alert(err);
		return false;
	}
	else
		return true;
}
//------------------------------------------------------------------------------------

function Permission_Err()
{
	alert("You do not have permission to view this page. If you believe you are viewing this message in error, please contact Fletcher Aluminium Systems Support.");
	document.location = "home.asp";
}
//------------------------------------------------------------------------------------

function Check_UserSettings()
{
	//check screen settings
	if (screen.height < 600 && screen.width < 800)
		alert("Due to your screen settings, the Fletcher Aluminium Franchisee Website will not be displayed correctly.\n\nPlease refer to the Franchisee Website User Manual on how to adjust your screen settings or contact Fletcher Aluminium Systems Support.");
	
	//check for valid browser
	if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion < "4.0")
		alert("You appear to be using an older or incorrect version of Internet browser.\nYou should be using Microsoft Internet Explorer 4.0 or above.\n\nPlease contact Fletcher Aluminium Systems Support for assistance.");
	
	//check to see if cookies are enabled
	document.cookie = 'Validation_Cookie'
	if (document.cookie == "")
		alert("It appears that you have cookies disabled on this computer.\n\nIn order to use this site correctly you must have cookies enabled.\n\nPlease contact Fletcher Aluminium Systems Support on how to enable cookies or refer to your Franchisee Website User Manual.");
}
//------------------------------------------------------------------------------------

function Validate_Login(seed)
{
	var username;
	var password;
	var err;
	
	username = document.frmDefault.username.value;
	password = document.frmDefault.password.value;
	err = "";
	
	if (username == "")
		err += ("\n* You must enter a username.");
	if (password == "")
		err += ("\n* You must enter a password.");
	if (err == "")
	{
		document.getElementById("Login").disabled = true;
		document.getElementById("Login").value = "Processing...";
		MD5Auth(seed);
	}
	return ErrResult(err)
}
//------------------------------------------------------------------------------------

// no longer required
/*
function Prompt_Login(customerNo)
{
	var loginAs;
	
	if (customerNo == "")
	{
		do
		{
			loginAs = prompt("Please enter a TRANSACT User ID to login:", "");
			if (loginAs == "")
				alert ("Please enter a valid TRANSACT User ID.");
			//null is evaluated first
			else if (loginAs != null && !IsNotOtherThan(loginAs, "0123456789"))
			{
				alert ("TRANSACT User ID's do not contain alphabetic characters.");
				//force loop to continue
				loginAs = "";
			}
		}
		while (loginAs == "")
	}
	else
	{
		loginAs = customerNo;
	}
	if (loginAs != "" && loginAs != null)
		document.location = "order.search.asp?customerNo=" + loginAs;
}
*/
//------------------------------------------------------------------------------------

function Open_SpecificDownloads(lines)
{
	window.open("specific.download.asp?print=1", "littleWindow", "location=no, width=540, height=" + (130 + (15 * lines)));
}
//------------------------------------------------------------------------------------

function Close_SpecificDownloads()
{
	window.close();
	//refresh the parent window (in case no. of downloads as changed)
	window.opener.location.reload();
}
//------------------------------------------------------------------------------------

function Prompt_RemoveDl(fileName)
{
	if (confirm("This will remove this file from your waiting list, only proceed once you have already downloaded the file.\n\nDo you wish to remove the file from your waiting list?"))
	{
		document.location = "specific.download.asp?swName=" + fileName + "&delete=1&print=1";
	}
	//Once the file has successfully been downloaded, click \'OK\' to remove the file from your waiting list, or if you wish to download the file at a later stage select \'Cancel\'."))
}
//------------------------------------------------------------------------------------

function RemoveDl_Reminder()
{
	alert("Please remember to remove this file and/or any other files from your waiting list once successfully downloaded by clicking the \'X\' in the popup window.");
}
//------------------------------------------------------------------------------------

function Transact_LoginErr()
{
	alert ("You have entered an invalid TRANSACT User ID.");
	history.go (-1);
}
//------------------------------------------------------------------------------------

function Confirm_MsgDelete()
{
	return confirm ("Please note this will permanentely delete this message and all its replies.\n\nDo you want to continue?");
}
//------------------------------------------------------------------------------------

function MD5Auth(seed) 
{
	var password = document.frmDefault.password.value.toLowerCase();
	var hash = MD5(seed + password);
	//don't submit the real password over the Internet
	document.frmDefault.password.value = '';
	document.frmDefault.hashPassword.value = hash;
}
//------------------------------------------------------------------------------------

function ShowHideDiv(theDiv, theImg)
{
	if (document.getElementById(theDiv).style.display == 'none')
	{
		document.getElementById(theDiv).style.display = 'block';
		if (theImg != '')
			document.getElementById(theImg).src='images/collapse.gif';
	}
	else
	{
		document.getElementById(theDiv).style.display = 'none';
		if (theImg != '')
			document.getElementById(theImg).src='images/expand.gif';
	}
}
//------------------------------------------------------------------------------------

function CreateSpecificDownload_Click()
{
	ShowHideDiv('div1', 'img1');
	ShowHideDiv('div2', '');
	document.frmManageSoftware.button[1].disabled = !document.frmManageSoftware.button[1].disabled;
	document.frmManageSoftware.button[2].disabled = !document.frmManageSoftware.button[2].disabled;
	document.frmManageSoftware.path.disabled = !document.frmManageSoftware.button[1].disabled;
	if (document.frmManageSoftware.specific.value == '0')
		document.frmManageSoftware.specific.value = '1'
	else
		document.frmManageSoftware.specific.value = '0'
}
//------------------------------------------------------------------------------------

function IsNumeric(sText)
{
	var ValidChars = "0123456789.";
	var IsNumber = true;
	var Char;

	for (i = 0; i < sText.length && IsNumber == true; i++) 
    { 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
        {
			IsNumber = false;
        }
	}
	return IsNumber;
}
//------------------------------------------------------------------------------------

var myArray;

// filter a listbox
function FindCustomers()
{
    var list;
    var i;
    
    list = document.getElementById("customerNo");

    // take a copy of the listbox contents
    if (myArray == null)
    {
        myArray = new Array();
        for(i = 0; i < list.options.length; i++)
        {
            myArray[i] = new Option(list.options[i].text, list.options[i].value);
        }
    }
    // clear the list
    list.options.length = 0;
	
	// filter the copied list and repopulate the on page listbox
	for(i = 0; i < myArray.length; i++) 
    {   
		if (myArray[i].text.toUpperCase().indexOf(document.getElementById("txtSearch").value.toUpperCase()) >= 0 || document.getElementById("txtSearch").value == "") 
        {
            list.options.add(myArray[i]);
            //list.options.add(new Option(myArray[i].text, myArray[i].value));
        }
	}
	if (list.options.length > 0)
    {
        list.selectedIndex = 0;
    }
}
//------------------------------------------------------------------------------------

function FMREdit_Fault_Click()
{
	var transitSelected;
	var faultCount;
	var i;
	
	faultCount = document.getElementById("faultCount").value;
	
	//find out if any transit faults are checked
	for(i=1; i<=faultCount; i++)
	{
		if (document.getElementById("fault" + i).value.substring(5, 6) == 'T' && document.getElementById("fault" + i).checked)
			transitSelected = true;
	}
	if (transitSelected)
		document.getElementById("transitClaim").style.display = 'block';
	else
		document.getElementById("transitClaim").style.display = 'none';	
}
//------------------------------------------------------------------------------------

// Shaun Sharples - 18/11/2010
// Modified to make sure all conditions were handled.
function FMRView_ReturnOption_Click(index)
{
	if (index == 0) 
	{
		if (document.getElementsByName("returnOption")[0].checked == true)
		{
			document.getElementsByName("returnOption")[1].checked = false;
			document.getElementById("scrapValue").value = "";
			document.getElementById("scrapValue").disabled = true	
			document.getElementById("contactPerson").disabled = false
		}
		else
		{
			document.getElementById("contactPerson").disabled = true
		}
	}
	else if (index == 1)
	{
		if (document.getElementsByName("returnOption")[1].checked == true)
		{
			document.getElementsByName("returnOption")[0].checked = false;
			document.getElementById("contactPerson").value = "";
			document.getElementById("contactPerson").disabled = true
			document.getElementById("scrapValue").disabled = false		
		}
		else
		{
			document.getElementById("scrapValue").disabled = true	
		}
	}
}
//------------------------------------------------------------------------------------

function Check_Authorization()
{
	if (parseFloat(document.getElementById("authorizationLevel").value) < parseFloat(document.getElementById("totalNetFMRValue").value))
	{
		document.getElementById("acceptC").value = "Insufficient Authorization";
		document.getElementById("acceptC").disabled = true;
	}
}
//------------------------------------------------------------------------------------

function Change_CreditValue_Click()
{
}
//------------------------------------------------------------------------------------

