// JavaScript Document

function getCalendarDate()
{
   var months = new Array(13);
   months[0]  = "January";
   months[1]  = "February";
   months[2]  = "March";
   months[3]  = "April";
   months[4]  = "May";
   months[5]  = "June";
   months[6]  = "July";
   months[7]  = "August";
   months[8]  = "September";
   months[9]  = "October";
   months[10] = "November";
   months[11] = "December";
   var now         = new Date();
   var monthnumber = now.getMonth();
   var monthname   = months[monthnumber];
   var monthday    = now.getDate();
   var year        = now.getYear();
   if(year < 2000) { year = year + 1900; }
   var dateString = monthname +
                    ' ' +
                    monthday +
                    ', ' +
                    year;
   return dateString;
} 

function startTime()
{
var today=new Date()
var h=today.getHours()
var m=today.getMinutes()
var s=today.getSeconds()
// add a zero in front of numbers<10
m=checkTime(m)
s=checkTime(s)
document.getElementById('theTime').innerHTML=h+":"+m+":"+s
t=setTimeout('startTime()',500)
}

function checkTime(i)
{
if (i<10) 
  { 
  	i="0" + i
  }
  return i
}


function londonTime() 
{
	var today = new Date()
	var h = (today.getHours()  -10)
	var m = today.getMinutes()
	var s = today.getSeconds()
	//var london = ((today.getHours() - 10) + ":" + (today.getMinutes()) + ":" + (today.getSeconds()))
	//We need to add a zero to digits that are less than 10 to fill the space
	
	h = checkTime(h)
	m = checkTime(m)
	s = checkTime(s)

	document.getElementById('Time2').innerHTML = h + ":" + m + ":" + s
	t = setTimeout('londonTime()',500)
}
	
/* ------ 
	Developed by: Edward Chiofalo
	Dated: October 19, 2007
	For: T&amp;DC Pty Limited
	Description:
	
	The javascript functions featured below were adapted by myself from the w3schools.com website
	The functions include detect the users web browser and using the most appropriate stylesheet for 
	CSS layout and formatting and client-side form validation for forms to email submissions.
	
------*/

/* ------ The following javascript returns the appropriate stylesheet reference, based on the users browser ------ */
function detectBrowser()
{
	var browser = navigator.appName
	var theResult
	
	if (browser == "Netscape")
	{
		theResult = document.write('<link href=\"./stylesheets/tndc.css\" rel=\"stylesheet\" type=\"text/css\" />')
		return theResult
	}
	else
	{
		theResult =  document.write('<link href=\"./stylesheets/ie.css\" rel=\"stylesheet\" type=\"text/css\" />')
		return theResult
	}
}

/* ------ Form validation code below ------ */
function  validate_required(field, alerttxt)
{
	with (field)
	{
		if (value == null || value == "")
		{
			alert(alerttxt);
			return false
		}
		else
		{
			return true
		}
	} //End with
} // End validate_required

/* This javascript function validates that a field that requires a numeric input is in fact numeric 
This relates to the IFS SmartFreight validation */
function validate_numeric(field, alerttxt)
{
	with(field)
	{
		if (isNaN(value) == true)
		{
			alert(alerttxt);
			return false
		}		
	} // End With
} //End numeric function

/* This javascript functions validates that the required feilds requesting an email address is 
formatted correctly. */
function validate_email(field, alerttxt)
{
	with (field)
	{
		apos = value.indexOf("@")
		dotpos = value.lastIndexOf(".")
		
		if (apos <  1 || dotpos - apos < 2)
		{
			alert(alerttxt);
			return false
		}
		else
		{
			return true
		}
	} // End validate email with
}// End validate_email function

/* The following function checks that the phone number that is entered is 10 digits in length. */
function validate_pnumber(field, alerttxt)
{
	with (field)
	{
		var lengthtest = field.value
		if (lengthtest.length < 10)
		{
			alert(alerttxt)
			return false
		}
	} //End phoneNumber with
} // End phoneNumber function
			
function validate_form(thisform)
{
	with (thisform)
	{
		if (validate_required(companyname, " Company Name is required") == false)
		{
			companyname.focus();
			return false
		}
		
		if (validate_required(realname, "Your name is required") == false)
		{
			realname.focus();
			return false
		}
		
		if (validate_required(email, "Email is required") == false)
		{
			email.focus();
			return false
		}
		
		if (validate_email(email, "The email address you entered is not a valid email address") == false)
		{
			email.focus();
			return false
		}
		
		if (validate_required(phone, "Your contact number is required") == false)
		{
			phone.focus();
			return false
		}
		
		if (validate_numeric(phone, "The contact number must be numeric") == false)
		{
			phone.focus();
			return false
		}
		
		if (validate_pnumber(phone, "The contact number must include your area code and be 10 digits in length") == false)
		{
			phone.focus();
			return false
		}
	
		if (validate_required(comments, "A brief note about what area of assistance you require is necessary for this enquiry.") == false)
		{
			comments.focus();
			return false
		}

	} //End with
} // End validate form

function enquiry_selection()
{
	switch (location.search)
	{
		case "&enquiry=IFS SmartFreight":
		document.write("Supply Chain: <input name=\"product\" type=\"radio\" value=\"SupplyChain\"  /><br/>")
		document.write("Third Party Warehousing: <input name=\"product\" type=\"radio\" value=\"3PL\" /><br/>")
		document.write("IFS SmartFreight: <input name=\"product\" type=\"radio\" value=\"IFS SmartFreight\" checked /><br/>")
		document.write("FreightWise: <input name=\"product\" type=\"radio\" value=\"FreightWise\" /><br/>")
		document.write("General Enquiry: <input name=\"product\" type=\"radio\" value=\"general\"  />")
		break
		
		//FreightWise was added to the enquiry form on March 13, 2008 
		case "&enquiry=FreightWise":
		document.write("Supply Chain: <input name=\"product\" type=\"radio\" value=\"SupplyChain\"  /><br/>")
		document.write("Third Party Warehousing: <input name=\"product\" type=\"radio\" value=\"3PL\" /><br/>")
		document.write("IFS SmartFreight: <input name=\"product\" type=\"radio\" value=\"IFS SmartFreight\" /><br/>")
		document.write("FreightWise: <input name=\"product\" type=\"radio\" value=\"FreightWise\" checked/><br/>")
		document.write("General Enquiry: <input name=\"product\" type=\"radio\" value=\"general\"  />")
		break		
		
		case "?enquiry=3pl":	
		document.write("Supply Chain: <input name=\"product\" type=\"radio\" value=\"SupplyChain\"  /><br/>")
		document.write("Third Party Warehousing: <input name=\"product\" type=\"radio\" value=\"3PL\" checked /><br/>")
		document.write("IFS SmartFreight: <input name=\"product\" type=\"radio\" value=\"IFS SmartFreight\"  /><br/>")
		document.write("FreightWise: <input name=\"product\" type=\"radio\" value=\"FreightWise\" /><br/>")
		document.write("General Enquiry: <input name=\"product\" type=\"radio\" value=\"general\"  />")
		break

		case "?enquiry=analysis":	
		document.write("Supply Chain: <input name=\"product\" type=\"radio\" value=\"SupplyChain\" checked /><br/>")
		document.write("Third Party Warehousing: <input name=\"product\" type=\"radio\" value=\"3PL\" /><br/>")
		document.write("IFS SmartFreight: <input name=\"product\" type=\"radio\" value=\"IFS SmartFreight\" /><br/>")
		document.write("FreightWise: <input name=\"product\" type=\"radio\" value=\"FreightWise\" /><br/>")
		document.write("General Enquiry: <input name=\"product\" type=\"radio\" value=\"general\"  />")
		break

		default :
		document.write("Supply Chain: <input name=\"product\" type=\"radio\" value=\"SupplyChain\"  /><br/>")
		document.write("Third Party Warehousing: <input name=\"product\" type=\"radio\" value=\"3PL\" /><br/>")
		document.write("IFS SmartFreight: <input name=\"product\" type=\"radio\" value=\"IFS SmartFreight\" /><br/>")
		document.write("FreightWise: <input name=\"product\" type=\"radio\" value=\"FreightWise\" /><br/>")
		document.write("General Enquiry: <input name=\"product\" type=\"radio\" value=\"general\" checked />")
		break

	} // End enquiry selection switch
} //End function


/*
	The following javscript code allows users to modify the size of the font displayed on the web page.
	This is defined to the user as small, medium(default) and large.
*/
function changeFontSize(element)
{

	if (element == 'small')
	{
		document.getElementById("SideBar").style.fontSize = "8pt";		
		document.getElementById("Content").style.fontSize = "8pt";		
	}
	else if (element == "medium")
	{
		document.getElementById("SideBar").style.fontSize = "10pt";
		document.getElementById("Content").style.fontSize = "10pt";
	}
	else
	{
		document.getElementById("SideBar").style.fontSize = "11pt";
		document.getElementById("Content").style.fontSize = "11pt";		
	}

}