// DEFINE VARIABLES

// whitespace characters
var whitespace = " \t\n\r";

function enableField(whichField, flag)
{
	if (document.getElementById) // DOM3 = IE5, NS6 
		var fld = eval(document.getElementById(whichField));
	else
		if (document.layers) // Netscape 4 
			var fld = eval(document.layers[whichField])
	
	if (fld != null)
		fld.enabled = flag;
}

function setFocus(whichField){
	var fld = document.getElementById(whichField);
	if (fld) {
		switch(fld.type)
		{
			// for text boxes, set the focus AND select the text, just like a Windows app
			case 'text':
			case 'password':
				fld.select();
				break;
		}
		fld.focus();
	}
}

function checkFieldValue(whichField, whichValue)
{
	if (document.getElementById) // DOM3 = IE5, NS6 
		var fld = eval(document.getElementById(whichField));
	else
		if (document.layers) // Netscape 4 
			var fld = eval(document.layers[whichField])
	
	if (fld != null) 
		if (fld.value == whichValue)
			return true;
		else
			return false;	
}

function displayField(whichField, flag)
{
	if (document.getElementById) // DOM3 = IE5, NS6 
	{
		var fld = eval(document.getElementById(whichField));
		if (fld != null)
			if (flag == false)
				fld.style.display	= "none";
			else
				fld.style.display	= "block";	
	}
	else
	{
		if (document.layers) // Netscape 4 
			var fld = eval(document.layers[whichField])
			if (fld != null)
			if (flag == false)
				fld.style.display	= "hidden";
			else
				fld.style.display	= "visible";
	}
	
}

/****************************************************************/

// Sets a value for a form field.
function setField(whichField, whatValue)
{
	if (document.getElementById) // DOM3 = IE5, NS6 
	{
		var fld = eval(document.getElementById(whichField));
		if (fld != null) fld.innerHTML	= whatValue;
	}
	else
	{
		if (document.layers) // Netscape 4 
			var fld = eval(document.layers[whichField])
			if (fld != null)
			if (flag == false) fld.innerHTML	= whatValue;
	}
	
}

/****************************************************************/

// Gets a value for a form field.
function getValue(whichField)
{
	if (document.getElementById) // DOM3 = IE5, NS6 
	{
		var fld = eval(document.getElementById(whichField));
		if (fld != null) return fld.value;
	}
	else
	{
		if (document.layers) // Netscape 4 
			var fld = eval(document.layers[whichField])
			if (fld != null)
			 return fld.value;
	}
	
}

/****************************************************************/

// Gets a value for a form field.
function getReference(whichField)
{
	if (document.getElementById) // DOM3 = IE5, NS6 
	{
		var fld = eval(document.getElementById(whichField));
		if (fld != null) return fld;
	}
	else
	{
		if (document.layers) // Netscape 4 
			var fld = eval(document.layers[whichField])
			if (fld != null)
			 return fld;
	}
	
}

/****************************************************************/

// Check whether string s is empty.

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

/******************************************************************************
 //Makes sure the user entered a valid e-mail address. Supports the
 //          extensions .com, .org, .gov, .net, .edu
 *****************************************************************************/
function validateEmailAddr(emailAddress){
  var atSymbol = emailAddress.indexOf("@");			// Get the index of the '@'
  var period = emailAddress.lastIndexOf(".");		// Get the value of the last '.'
  var suffix = emailAddress.substring(period + 1, emailAddress.length);
  
  if (suffix.length > 0) suffix = suffix.toLowerCase(); '' // For lower case check below.
   	
  // Make sure the '@' symbol and '.' is in a valid location
  if (((atSymbol != 0) && (atSymbol != -1)) && (suffix.length == 3) && (atSymbol < period) && (atSymbol != period - 1)) { 
	if ((suffix == "com") || (suffix == "org") || (suffix == "gov") || (suffix == "net") || (suffix == "edu")) 
      return true;
  }
	return false;
}


/****************************************************************/

// Returns true if string s is empty or 
// whitespace characters only.

function isWhitespace (s)

{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
	// Check that current character isn't whitespace.
	var c = s.charAt(i);

	if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}
/****************************************************************/

function textCounter(field, countfield, maxlimit) {
/*
* The input parameters are: the field name;
* field that holds the number of characters remaining;
* the max. numb. of characters.
*/ 
if (field.value.length > maxlimit) // if the current length is more than allowed
field.value =field.value.substring(0, maxlimit); // don't allow further input
else
countfield.value = maxlimit - field.value.length;} // set the display field to remaining number

/****************************************************************/
function getKeyCode(e)
{
 if (window.event)
    return window.event.keyCode;
 else if (e)
    return e.which;
 else
    return null;
}

/****************************************************************/

function keyRestrict(e, validchars) {
 var key='', keychar='';
 key = getKeyCode(e);
 if (key == null) return true;
 keychar = String.fromCharCode(key);
 keychar = keychar.toLowerCase();
 validchars = validchars.toLowerCase();
 if (validchars.indexOf(keychar) != -1)
  return true;
 if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
  return true;
 return false;
}


/****************************************************************/

function isDate (day,month,year) {
	// checks if date passed is valid

	var today = new Date();
    
    today.setFullYear(year, month-1,day);
    //alert(today)
    //alert(today.getMonth());
    //alert(month);
    if (today.getMonth()+1 == month)
		return true;
	else
		return false;	
        
}

//Print page calls this function
function getPrint(print_area)
{	
	//Creating new page
	var pp = window.open();
	//Adding HTML opening tag with <head> . </head> portion 
	pp.document.writeln('<html><head><title>Print Preview</title>')
	pp.document.writeln('<base target="_self"></head>')
	//Adding Body Tag
	pp.document.writeln('<body MS_POSITIONING="GridLayout" bottomMargin="0" leftMargin="0" topMargin="0" rightMargin="0">');
	//Writing print area of the calling page
	var strHTML = document.getElementById(print_area).innerHTML;
	strHTML = strHTML.replace(/overflow: auto/gi, "overflow: visible");
	strHTML = strHTML.replace(/overflow: hidden/gi, "overflow: visible");
	strHTML = strHTML.replace(/border=1/gi, "border=0");
	
	//strHTML = strHTML.replace(/id=origin/gi, "id=origin disabled");
	//strHTML = strHTML.replace(/id=destination/gi, "id=destination disabled");
	
	pp.document.writeln(strHTML);
							
	//Ending Tag of </form>, </body> and </html>
	pp.document.writeln('</body></html>');
	
}
		

/****************************************************************/

//Use this JS to hide int stops on Booking pickup and quote request.
/*function showHideIntStop(whichObj)
{	
	//alert(getReference(whichObj + "rdoHaveIntStops_0"));	
	if (getReference(whichObj + "rdoHaveIntStops_0") != null)
	{
		if (getReference(whichObj + "rdoHaveIntStops_0").checked)
		{	
			displayField(whichObj + "divIntStopsDetails", true);
		}
		else
		{
			displayField(whichObj + "divIntStopsDetails", false);
		}
	}
}*/