// JavaScript Document
var alpha_letters = ' ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzÊÔÛÈÉèéûîÎáçàêùú\'';
var alpha_num = ' ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzÊÔÛÈÉèéûîÎáçàêùú0123456789_-\'';
var alpha_numbers = '0123456789.';
var alpha_tel = '0123456789 ()+';
var alpha_special = '-';
var alpha_email='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@._-+';
function CompareDates(arrival, departure)
{
   var str1  = document.getElementById(arrival).value;
   var str2  = document.getElementById(departure).value;
   var dt1   = parseInt(str1.substring(0,2),10);
   var mon1  = parseInt(str1.substring(3,5),10);
   var yr1   = parseInt(str1.substring(6,10),10);
   var dt2   = parseInt(str2.substring(0,2),10);
   var mon2  = parseInt(str2.substring(3,5),10);
   var yr2   = parseInt(str2.substring(6,10),10);
   var date1 = new Date(yr1, mon1, dt1);
   var date2 = new Date(yr2, mon2, dt2);

   if(date2 <= date1)
   {
     // alert("To date cannot be greater than from date");
      return false;
   }
   else
   {
     return true
   }
} 
function clearValue(field,txt){
	if(document.getElementById(field).value == txt){
		document.getElementById(field).value = "";
	}
}
function checkValue(field, txt)
{
	if(document.getElementById(field).value == "")
	{
		document.getElementById(field).value = txt;
	}
}
function Trim(TRIM_VALUE)
{
  if(TRIM_VALUE.length < 1)
  {
    return'';
  }
  TRIM_VALUE = RTrim(TRIM_VALUE);
  TRIM_VALUE = LTrim(TRIM_VALUE);
  if(TRIM_VALUE=='')
  {
    return '';
  }
  else
  {
    return TRIM_VALUE;
  }
} //End Function

function RTrim(VALUE)
{
  var w_space = String.fromCharCode(32);
  var v_length = VALUE.length;
  var strTemp = '';
  if(v_length < 0)
  {
    return '';
  }
  var iTemp = v_length -1;

  while(iTemp > -1)
  {
    if(VALUE.charAt(iTemp) == w_space)
	{
    }
    else
	{
      strTemp = VALUE.substring(0,iTemp +1);
      break;
    }
    iTemp = iTemp-1;
  } //End While
  return strTemp;
} //End Function

function LTrim(VALUE)
{
  var w_space = String.fromCharCode(32);
  if(v_length < 1)
  {
    return'';
  }
  var v_length = VALUE.length;
  var strTemp = '';

  var iTemp = 0;

  while(iTemp < v_length)
  {
    if(VALUE.charAt(iTemp) == w_space)
	{
    }
    else
	{
      strTemp = VALUE.substring(iTemp,v_length);
      break;
    }
    iTemp = iTemp + 1;
  } //End While
  return strTemp;
} //End Function
function isEmpty(field)
{
	var obj = Trim(document.getElementById(field).value);
	if ((obj.length==0) || (obj==null))
	{
      //document.getElementById(field).style.borderColor = 'red';
	  return true;
   	}
   else { 
  // document.getElementById(field).style.borderColor = '#666666';
   return false; }
}
function chk(e, obj_previous, obj_current, obj_next) {
	
	var el = document.getElementById(obj_current);
	var unicode=e.keyCode? e.keyCode : e.charCode;
	/*alert(unicode);*/
	if (unicode == 8)
	{
		el.value = '';
		if (obj_previous != '')
		{
			var el2 = document.getElementById(obj_previous);
			el2.focus();
			el2.select()
		}
	}
	else if ((unicode == 38) || (unicode == 37))
	{
		if (obj_previous != '')
		{
			var el2 = document.getElementById(obj_previous);
			el2.focus();
			el2.select()
		}
	}
	else if ((unicode == 40) || (unicode == 39))
	{
		if (obj_next != '')
		{
			var el2 = document.getElementById(obj_next);
			el2.focus();
			el2.select()
		}
	}
	else if (unicode == 46)
	{
		el.value = '';
	}
	else 
	{
		if (obj_next != '')
		{
			var el2 = document.getElementById(obj_next);
			el2.focus();
			el2.select()
		}
	}
		
}


function alpha(e,allow) {

var k;
//var evtobj=window.event? event : e;
k=document.all?parseInt(e.keyCode): parseInt(e.which);
//alert(k);
      if (k!=13 && k!=8 && k!=0){
            //alert(allow.indexOf(String.fromCharCode(k))!=-1);
            if ((e.ctrlKey==false) && (e.altKey==false)) {
                  return (allow.indexOf(String.fromCharCode(k).toUpperCase())!=-1);
            } else {
                  return true;
            }
      } else {
            return true;
      }
}

function isNumberKey(evt)
{
 var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57)) return false;
    return true;
}

function validateEmail(emailStr) 
{
	/* The following variable tells the rest of the function whether or not
	to verify that the address ends in a two-letter country or well-known
	TLD.  1 means check it, 0 means don't. */
	var checkTLD=1;
	/* The following is the list of known TLDs that an e-mail address must end with. */
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.  It also is used to separate the username
	from the domain. */
	var emailPat=/^(.+)@(.+)$/;
	/* The following string represents the pattern for matching all special
	characters.  We don't want to allow special characters in the address. 
	These characters include ( ) < > @ , ; : \ " . [ ] */
	var specialChars="\\(\\)><@,;:'\\\\\\\"\\.\\[\\]";
	/* The following string represents the range of characters allowed in a 
	username or domainname.  It really states which chars aren't allowed.*/
	var validChars="\[^\\s" + specialChars + "\]";
	/* The following pattern applies if the "user" is a quoted string (in
	which case, there are no rules about which characters are allowed
	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	is a legal e-mail address. */
	var quotedUser="(\"[^\"]*\")";
	/* The following pattern applies for domains that are IP addresses,
	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	e-mail address. NOTE: The square brackets are required. */
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	/* The following string represents an atom (basically a series of non-special characters.) */
	var atom=validChars + '+';
	/* The following string represents one word in the typical username.
	For example, in john.doe@somewhere.com, john and doe are words.
	Basically, a word is either an atom or quoted string. */
	var word="(" + atom + "|" + quotedUser + ")";
	// The following pattern describes the structure of the user
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	/* The following pattern describes the structure of a normal symbolic
	domain, as opposed to ipDomainPat, shown above. */
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	/* Finally, let's start trying to figure out if the supplied address is valid. */
	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) 
	{
		/* Too many/few @'s or something; basically, this address doesn't
		even fit the general mould of a valid e-mail address. */
		
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	// Start by checking that only basic ASCII characters are in the strings (0-127).
	for (i=0; i<user.length; i++) 
	{
		if (user.charCodeAt(i)>127) 
		{
			return false;
		}
	}
	for (i=0; i<domain.length; i++) 
	{
		if (domain.charCodeAt(i)>127) 
		{
			return false;
		}
	}
	// See if "user" is valid 
	if (user.match(userPat)==null) 
	{
		// user is not valid
		return false;
	}
	/* if the e-mail address is at an IP address (as opposed to a symbolic
	host name) make sure the IP address is valid. */
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) 
	{
		// this is an IP address
	
		for (var i=1;i<=4;i++) 
		{
			if (IPArray[i]>255) 
			{
				return false;
	   		}
		}

		return true;
	}
	// Domain is symbolic name.  Check if it's valid.
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) 
	{
		if (domArr[i].search(atomPat)==-1) 
		{
			return false;
	   	}
	}
	/* domain name seems valid, but now make sure that it ends in a
	known top-level domain (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding 
	the domain or country. */
	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].search(knownDomsPat)==-1) 
	{
		return false;
	}
	// Make sure there's a host name preceding the domain.
	if (len<2) 
	{
		return false;
	}
	// If we've gotten this far, everything's valid!
	return true;
}
function YesNo(yes, no)
{
	document.getElementById(yes).checked = true;
	document.getElementById(no).checked  = false;
}
